Skip to content

Commit 575c15a

Browse files
Use Autoderef::silence_errors more liberally throughout diagnostics code
1 parent f95059b commit 575c15a

File tree

5 files changed

+23
-28
lines changed

5 files changed

+23
-28
lines changed

Diff for: compiler/rustc_hir_typeck/src/coercion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10491049
/// trait or region sub-obligations. (presumably we could, but it's not
10501050
/// particularly important for diagnostics...)
10511051
pub(crate) fn deref_once_mutably_for_diagnostic(&self, expr_ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
1052-
self.autoderef(DUMMY_SP, expr_ty).nth(1).and_then(|(deref_ty, _)| {
1052+
self.autoderef(DUMMY_SP, expr_ty).silence_errors().nth(1).and_then(|(deref_ty, _)| {
10531053
self.infcx
10541054
.type_implements_trait(
10551055
self.tcx.lang_items().deref_mut_trait()?,

Diff for: compiler/rustc_hir_typeck/src/method/suggest.rs

+20-16
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
6262
// It might seem that we can use `predicate_must_hold_modulo_regions`,
6363
// but since a Dummy binder is used to fill in the FnOnce trait's arguments,
6464
// type resolution always gives a "maybe" here.
65-
if self.autoderef(span, ty).any(|(ty, _)| {
65+
if self.autoderef(span, ty).silence_errors().any(|(ty, _)| {
6666
info!("check deref {:?} error", ty);
6767
matches!(ty.kind(), ty::Error(_) | ty::Infer(_))
6868
}) {
6969
return false;
7070
}
7171

72-
self.autoderef(span, ty).any(|(ty, _)| {
72+
self.autoderef(span, ty).silence_errors().any(|(ty, _)| {
7373
info!("check deref {:?} impl FnOnce", ty);
7474
self.probe(|_| {
7575
let trait_ref =
@@ -90,7 +90,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9090
}
9191

9292
fn is_slice_ty(&self, ty: Ty<'tcx>, span: Span) -> bool {
93-
self.autoderef(span, ty).any(|(ty, _)| matches!(ty.kind(), ty::Slice(..) | ty::Array(..)))
93+
self.autoderef(span, ty)
94+
.silence_errors()
95+
.any(|(ty, _)| matches!(ty.kind(), ty::Slice(..) | ty::Array(..)))
9496
}
9597

9698
fn impl_into_iterator_should_be_iterator(
@@ -2237,6 +2239,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22372239
let impl_ty = self.tcx.type_of(*impl_did).instantiate_identity();
22382240
let target_ty = self
22392241
.autoderef(sugg_span, rcvr_ty)
2242+
.silence_errors()
22402243
.find(|(rcvr_ty, _)| {
22412244
DeepRejectCtxt::relate_rigid_infer(self.tcx).types_may_unify(*rcvr_ty, impl_ty)
22422245
})
@@ -2352,17 +2355,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23522355
err: &mut Diag<'_>,
23532356
) -> bool {
23542357
let tcx = self.tcx;
2355-
let field_receiver = self.autoderef(span, rcvr_ty).find_map(|(ty, _)| match ty.kind() {
2356-
ty::Adt(def, args) if !def.is_enum() => {
2357-
let variant = &def.non_enum_variant();
2358-
tcx.find_field_index(item_name, variant).map(|index| {
2359-
let field = &variant.fields[index];
2360-
let field_ty = field.ty(tcx, args);
2361-
(field, field_ty)
2362-
})
2363-
}
2364-
_ => None,
2365-
});
2358+
let field_receiver =
2359+
self.autoderef(span, rcvr_ty).silence_errors().find_map(|(ty, _)| match ty.kind() {
2360+
ty::Adt(def, args) if !def.is_enum() => {
2361+
let variant = &def.non_enum_variant();
2362+
tcx.find_field_index(item_name, variant).map(|index| {
2363+
let field = &variant.fields[index];
2364+
let field_ty = field.ty(tcx, args);
2365+
(field, field_ty)
2366+
})
2367+
}
2368+
_ => None,
2369+
});
23662370
if let Some((field, field_ty)) = field_receiver {
23672371
let scope = tcx.parent_module_from_def_id(self.body_id);
23682372
let is_accessible = field.vis.is_accessible_from(scope, tcx);
@@ -3198,7 +3202,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31983202
let SelfSource::QPath(ty) = self_source else {
31993203
return;
32003204
};
3201-
for (deref_ty, _) in self.autoderef(DUMMY_SP, rcvr_ty).skip(1) {
3205+
for (deref_ty, _) in self.autoderef(DUMMY_SP, rcvr_ty).silence_errors().skip(1) {
32023206
if let Ok(pick) = self.probe_for_name(
32033207
Mode::Path,
32043208
item_name,
@@ -4224,7 +4228,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
42244228
return is_local(rcvr_ty);
42254229
}
42264230

4227-
self.autoderef(span, rcvr_ty).any(|(ty, _)| is_local(ty))
4231+
self.autoderef(span, rcvr_ty).silence_errors().any(|(ty, _)| is_local(ty))
42284232
}
42294233
}
42304234

Diff for: compiler/rustc_hir_typeck/src/pat.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2533,6 +2533,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25332533
err.help("the semantics of slice patterns changed recently; see issue #62254");
25342534
} else if self
25352535
.autoderef(span, expected_ty)
2536+
.silence_errors()
25362537
.any(|(ty, _)| matches!(ty.kind(), ty::Slice(..) | ty::Array(..)))
25372538
&& let Some(span) = ti.span
25382539
&& let Some(_) = ti.origin_expr

Diff for: tests/ui/methods/probe-error-on-infinite-deref.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ impl<T> Deref for Wrap<T> {
1212
fn main() {
1313
Wrap(1).lmao();
1414
//~^ ERROR reached the recursion limit
15-
//~| ERROR reached the recursion limit
1615
//~| ERROR no method named `lmao`
1716
}

Diff for: tests/ui/methods/probe-error-on-infinite-deref.stderr

+1-10
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ LL | Wrap(1).lmao();
66
|
77
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`probe_error_on_infinite_deref`)
88

9-
error[E0055]: reached the recursion limit while auto-dereferencing `Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<Wrap<{integer}>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`
10-
--> $DIR/probe-error-on-infinite-deref.rs:13:13
11-
|
12-
LL | Wrap(1).lmao();
13-
| ^^^^ deref recursion limit reached
14-
|
15-
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`probe_error_on_infinite_deref`)
16-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
17-
189
error[E0599]: no method named `lmao` found for struct `Wrap<{integer}>` in the current scope
1910
--> $DIR/probe-error-on-infinite-deref.rs:13:13
2011
|
@@ -24,7 +15,7 @@ LL | struct Wrap<T>(T);
2415
LL | Wrap(1).lmao();
2516
| ^^^^ method not found in `Wrap<{integer}>`
2617

27-
error: aborting due to 3 previous errors
18+
error: aborting due to 2 previous errors
2819

2920
Some errors have detailed explanations: E0055, E0599.
3021
For more information about an error, try `rustc --explain E0055`.

0 commit comments

Comments
 (0)