Skip to content

Commit c361616

Browse files
committed
Auto merge of #106432 - compiler-errors:rollup-lzj0lnp, r=compiler-errors
Rollup of 8 pull requests Successful merges: - #104748 (Ensure `lld` is supported with `download-ci-llvm`) - #105541 (Simplify some iterator combinators) - #106045 (default OOM handler: use non-unwinding panic, to match std handler) - #106157 (Don't trim path for `unsafe_op_in_unsafe_fn` lints) - #106353 (Reduce spans for `unsafe impl` errors) - #106381 (Jsondoclint: Add `--verbose` and `--json-output` options) - #106411 (rustdoc: remove legacy font-feature-settings CSS) - #106414 (Add cuviper to the review rotation for libs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents fbe8292 + 1a98443 commit c361616

File tree

37 files changed

+328
-302
lines changed

37 files changed

+328
-302
lines changed

Cargo.lock

+18-1
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ checksum = "23b71c3ce99b7611011217b366d923f1d0a7e07a92bb2dbf1e84508c673ca3bd"
597597
dependencies = [
598598
"atty",
599599
"bitflags",
600-
"clap_derive",
600+
"clap_derive 3.2.18",
601601
"clap_lex 0.2.2",
602602
"indexmap",
603603
"once_cell",
@@ -614,7 +614,9 @@ checksum = "6bf8832993da70a4c6d13c581f4463c2bdda27b9bf1c5498dc4365543abe6d6f"
614614
dependencies = [
615615
"atty",
616616
"bitflags",
617+
"clap_derive 4.0.13",
617618
"clap_lex 0.3.0",
619+
"once_cell",
618620
"strsim",
619621
"termcolor",
620622
]
@@ -641,6 +643,19 @@ dependencies = [
641643
"syn",
642644
]
643645

646+
[[package]]
647+
name = "clap_derive"
648+
version = "4.0.13"
649+
source = "registry+https://github.com/rust-lang/crates.io-index"
650+
checksum = "c42f169caba89a7d512b5418b09864543eeb4d497416c917d7137863bd2076ad"
651+
dependencies = [
652+
"heck",
653+
"proc-macro-error",
654+
"proc-macro2",
655+
"quote",
656+
"syn",
657+
]
658+
644659
[[package]]
645660
name = "clap_lex"
646661
version = "0.2.2"
@@ -2097,8 +2112,10 @@ name = "jsondoclint"
20972112
version = "0.1.0"
20982113
dependencies = [
20992114
"anyhow",
2115+
"clap 4.0.15",
21002116
"fs-err",
21012117
"rustdoc-json-types",
2118+
"serde",
21022119
"serde_json",
21032120
]
21042121

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+15-20
Original file line numberDiff line numberDiff line change
@@ -527,26 +527,21 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
527527
// that are *partially* initialized by assigning to a field of an uninitialized
528528
// binding. We differentiate between them for more accurate wording here.
529529
"isn't fully initialized"
530-
} else if spans
531-
.iter()
532-
.filter(|i| {
533-
// We filter these to avoid misleading wording in cases like the following,
534-
// where `x` has an `init`, but it is in the same place we're looking at:
535-
// ```
536-
// let x;
537-
// x += 1;
538-
// ```
539-
!i.contains(span)
540-
// We filter these to avoid incorrect main message on `match-cfg-fake-edges.rs`
541-
&& !visitor
542-
.errors
543-
.iter()
544-
.map(|(sp, _)| *sp)
545-
.any(|sp| span < sp && !sp.contains(span))
546-
})
547-
.count()
548-
== 0
549-
{
530+
} else if !spans.iter().any(|i| {
531+
// We filter these to avoid misleading wording in cases like the following,
532+
// where `x` has an `init`, but it is in the same place we're looking at:
533+
// ```
534+
// let x;
535+
// x += 1;
536+
// ```
537+
!i.contains(span)
538+
// We filter these to avoid incorrect main message on `match-cfg-fake-edges.rs`
539+
&& !visitor
540+
.errors
541+
.iter()
542+
.map(|(sp, _)| *sp)
543+
.any(|sp| span < sp && !sp.contains(span))
544+
}) {
550545
show_assign_sugg = true;
551546
"isn't initialized"
552547
} else {

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+2-67
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
55
use rustc_data_structures::fx::FxIndexSet;
66
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan};
7+
use rustc_hir as hir;
78
use rustc_hir::def_id::DefId;
89
use rustc_hir::intravisit::Visitor;
9-
use rustc_hir::{self as hir, Item, ItemKind, Node};
1010
use rustc_infer::infer::{
1111
error_reporting::nice_region_error::{
1212
self, find_anon_type, find_param_with_region, suggest_adding_lifetime_params,
@@ -291,71 +291,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
291291
outlives_suggestion.add_suggestion(self);
292292
}
293293

294-
fn get_impl_ident_and_self_ty_from_trait(
295-
&self,
296-
def_id: DefId,
297-
trait_objects: &FxIndexSet<DefId>,
298-
) -> Option<(Ident, &'tcx hir::Ty<'tcx>)> {
299-
let tcx = self.infcx.tcx;
300-
match tcx.hir().get_if_local(def_id) {
301-
Some(Node::ImplItem(impl_item)) => {
302-
match tcx.hir().find_by_def_id(tcx.hir().get_parent_item(impl_item.hir_id()).def_id)
303-
{
304-
Some(Node::Item(Item {
305-
kind: ItemKind::Impl(hir::Impl { self_ty, .. }),
306-
..
307-
})) => Some((impl_item.ident, self_ty)),
308-
_ => None,
309-
}
310-
}
311-
Some(Node::TraitItem(trait_item)) => {
312-
let trait_did = tcx.hir().get_parent_item(trait_item.hir_id());
313-
match tcx.hir().find_by_def_id(trait_did.def_id) {
314-
Some(Node::Item(Item { kind: ItemKind::Trait(..), .. })) => {
315-
// The method being called is defined in the `trait`, but the `'static`
316-
// obligation comes from the `impl`. Find that `impl` so that we can point
317-
// at it in the suggestion.
318-
let trait_did = trait_did.to_def_id();
319-
match tcx
320-
.hir()
321-
.trait_impls(trait_did)
322-
.iter()
323-
.filter_map(|&impl_did| {
324-
match tcx.hir().get_if_local(impl_did.to_def_id()) {
325-
Some(Node::Item(Item {
326-
kind: ItemKind::Impl(hir::Impl { self_ty, .. }),
327-
..
328-
})) if trait_objects.iter().all(|did| {
329-
// FIXME: we should check `self_ty` against the receiver
330-
// type in the `UnifyReceiver` context, but for now, use
331-
// this imperfect proxy. This will fail if there are
332-
// multiple `impl`s for the same trait like
333-
// `impl Foo for Box<dyn Bar>` and `impl Foo for dyn Bar`.
334-
// In that case, only the first one will get suggestions.
335-
let mut traits = vec![];
336-
let mut hir_v = HirTraitObjectVisitor(&mut traits, *did);
337-
hir_v.visit_ty(self_ty);
338-
!traits.is_empty()
339-
}) =>
340-
{
341-
Some(self_ty)
342-
}
343-
_ => None,
344-
}
345-
})
346-
.next()
347-
{
348-
Some(self_ty) => Some((trait_item.ident, self_ty)),
349-
_ => None,
350-
}
351-
}
352-
_ => None,
353-
}
354-
}
355-
_ => None,
356-
}
357-
}
358-
359294
/// Report an error because the universal region `fr` was required to outlive
360295
/// `outlived_fr` but it is not known to do so. For example:
361296
///
@@ -850,7 +785,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
850785
visitor.visit_ty(param.param_ty);
851786

852787
let Some((ident, self_ty)) =
853-
self.get_impl_ident_and_self_ty_from_trait(instance.def_id(), &visitor.0) else {return};
788+
NiceRegionError::get_impl_ident_and_self_ty_from_trait(tcx, instance.def_id(), &visitor.0) else { return; };
854789

855790
self.suggest_constrain_dyn_trait_in_impl(diag, &visitor.0, ident, self_ty);
856791
}

compiler/rustc_codegen_gcc/src/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
12441244
) -> RValue<'gcc> {
12451245
// FIXME(antoyo): remove when having a proper API.
12461246
let gcc_func = unsafe { std::mem::transmute(func) };
1247-
let call = if self.functions.borrow().values().find(|value| **value == gcc_func).is_some() {
1247+
let call = if self.functions.borrow().values().any(|value| *value == gcc_func) {
12481248
self.function_call(func, args, funclet)
12491249
}
12501250
else {

compiler/rustc_codegen_gcc/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
253253

254254
pub fn rvalue_as_function(&self, value: RValue<'gcc>) -> Function<'gcc> {
255255
let function: Function<'gcc> = unsafe { std::mem::transmute(value) };
256-
debug_assert!(self.functions.borrow().values().find(|value| **value == function).is_some(),
256+
debug_assert!(self.functions.borrow().values().any(|value| *value == function),
257257
"{:?} ({:?}) is not a function", value, value.get_type());
258258
function
259259
}

compiler/rustc_hir_analysis/src/coherence/unsafety.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
2121
(Unsafety::Normal, None, Unsafety::Unsafe, hir::ImplPolarity::Positive) => {
2222
struct_span_err!(
2323
tcx.sess,
24-
item.span,
24+
tcx.def_span(def_id),
2525
E0199,
2626
"implementing the trait `{}` is not unsafe",
2727
trait_ref.print_only_trait_path()
@@ -38,7 +38,7 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
3838
(Unsafety::Unsafe, _, Unsafety::Normal, hir::ImplPolarity::Positive) => {
3939
struct_span_err!(
4040
tcx.sess,
41-
item.span,
41+
tcx.def_span(def_id),
4242
E0200,
4343
"the trait `{}` requires an `unsafe impl` declaration",
4444
trait_ref.print_only_trait_path()
@@ -61,7 +61,7 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
6161
(Unsafety::Normal, Some(attr_name), Unsafety::Normal, hir::ImplPolarity::Positive) => {
6262
struct_span_err!(
6363
tcx.sess,
64-
item.span,
64+
tcx.def_span(def_id),
6565
E0569,
6666
"requires an `unsafe impl` declaration due to `#[{}]` attribute",
6767
attr_name

compiler/rustc_hir_typeck/src/lib.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,8 @@ fn typeck_with_fallback<'tcx>(
240240
}),
241241
Node::Expr(&hir::Expr { kind: hir::ExprKind::InlineAsm(asm), .. })
242242
| Node::Item(&hir::Item { kind: hir::ItemKind::GlobalAsm(asm), .. }) => {
243-
let operand_ty = asm
244-
.operands
245-
.iter()
246-
.filter_map(|(op, _op_sp)| match op {
243+
let operand_ty =
244+
asm.operands.iter().find_map(|(op, _op_sp)| match op {
247245
hir::InlineAsmOperand::Const { anon_const }
248246
if anon_const.hir_id == id =>
249247
{
@@ -259,8 +257,7 @@ fn typeck_with_fallback<'tcx>(
259257
}))
260258
}
261259
_ => None,
262-
})
263-
.next();
260+
});
264261
operand_ty.unwrap_or_else(fallback)
265262
}
266263
_ => fallback(),

compiler/rustc_hir_typeck/src/method/prelude2021.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
341341
// Find an identifier with which this trait was imported (note that `_` doesn't count).
342342
let any_id = import_items
343343
.iter()
344-
.filter_map(|item| if item.ident.name != Underscore { Some(item.ident) } else { None })
345-
.next();
344+
.find_map(|item| if item.ident.name != Underscore { Some(item.ident) } else { None });
346345
if let Some(any_id) = any_id {
347346
if any_id.name == Empty {
348347
// Glob import, so just use its name.

compiler/rustc_hir_typeck/src/method/probe.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
11111111
// a raw pointer
11121112
!step.self_ty.references_error() && !step.from_unsafe_deref
11131113
})
1114-
.flat_map(|step| {
1114+
.find_map(|step| {
11151115
let InferOk { value: self_ty, obligations: _ } = self
11161116
.fcx
11171117
.probe_instantiate_query_response(
@@ -1147,7 +1147,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
11471147
})
11481148
})
11491149
})
1150-
.next()
11511150
}
11521151

11531152
/// For each type `T` in the step list, this attempts to find a method where

compiler/rustc_hir_typeck/src/method/suggest.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
257257
self.tcx
258258
.inherent_impls(adt_def.did())
259259
.iter()
260-
.filter_map(|def_id| self.associated_value(*def_id, item_name))
261-
.count()
262-
>= 1
260+
.any(|def_id| self.associated_value(*def_id, item_name).is_some())
263261
} else {
264262
false
265263
}

0 commit comments

Comments
 (0)