diff options
Diffstat (limited to 'compiler/rustc_infer/src/infer/error_reporting')
12 files changed, 190 insertions, 226 deletions
diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 26d071a01..d396c4100 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -131,13 +131,13 @@ pub struct TypeErrCtxt<'a, 'tcx> { impl Drop for TypeErrCtxt<'_, '_> { fn drop(&mut self) { - if let Some(_) = self.infcx.tcx.sess.has_errors_or_delayed_span_bugs() { + if let Some(_) = self.infcx.tcx.sess.has_errors_or_span_delayed_bugs() { // ok, emitted an error. } else { self.infcx .tcx .sess - .delay_good_path_bug("used a `TypeErrCtxt` without raising an error or lint"); + .good_path_delayed_bug("used a `TypeErrCtxt` without raising an error or lint"); } } } @@ -155,7 +155,7 @@ impl TypeErrCtxt<'_, '_> { impl<'tcx> Deref for TypeErrCtxt<'_, 'tcx> { type Target = InferCtxt<'tcx>; fn deref(&self) -> &InferCtxt<'tcx> { - &self.infcx + self.infcx } } @@ -168,17 +168,17 @@ pub(super) fn note_and_explain_region<'tcx>( alt_span: Option<Span>, ) { let (description, span) = match *region { - ty::ReEarlyBound(_) | ty::ReFree(_) | ty::RePlaceholder(_) | ty::ReStatic => { + ty::ReEarlyParam(_) | ty::ReLateParam(_) | ty::RePlaceholder(_) | ty::ReStatic => { msg_span_from_named_region(tcx, region, alt_span) } ty::ReError(_) => return, // We shouldn't really be having unification failures with ReVar - // and ReLateBound though. - ty::ReVar(_) | ty::ReLateBound(..) | ty::ReErased => { - (format!("lifetime `{region}`"), alt_span) - } + // and ReBound though. + // + // FIXME(@lcnr): Figure out whether this is reachable and if so, why. + ty::ReVar(_) | ty::ReBound(..) | ty::ReErased => (format!("lifetime `{region}`"), alt_span), }; emit_msg_span(err, prefix, description, span, suffix); @@ -202,7 +202,7 @@ fn msg_span_from_named_region<'tcx>( alt_span: Option<Span>, ) -> (String, Option<Span>) { match *region { - ty::ReEarlyBound(ref br) => { + ty::ReEarlyParam(ref br) => { let scope = region.free_region_binding_scope(tcx).expect_local(); let span = if let Some(param) = tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(br.name)) @@ -218,7 +218,7 @@ fn msg_span_from_named_region<'tcx>( }; (text, Some(span)) } - ty::ReFree(ref fr) => { + ty::ReLateParam(ref fr) => { if !fr.bound_region.is_named() && let Some((ty, _)) = find_anon_type(tcx, region, &fr.bound_region) { @@ -315,7 +315,7 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>( // Explain the region we are capturing. match *hidden_region { - ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic => { + ty::ReEarlyParam(_) | ty::ReLateParam(_) | ty::ReStatic => { // Assuming regionck succeeded (*), we ought to always be // capturing *some* region from the fn header, and hence it // ought to be free. So under normal circumstances, we will go @@ -517,7 +517,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { self.tcx .sess - .delay_span_bug(self.tcx.def_span(generic_param_scope), "expected region errors") + .span_delayed_bug(self.tcx.def_span(generic_param_scope), "expected region errors") } // This method goes through all the errors and try to group certain types @@ -860,7 +860,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { self.suggest_boxing_for_return_impl_trait( err, ret_sp, - prior_arms.iter().chain(std::iter::once(&arm_span)).map(|s| *s), + prior_arms.iter().chain(std::iter::once(&arm_span)).copied(), ); } } @@ -891,7 +891,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { } // don't suggest wrapping either blocks in `if .. {} else {}` let is_empty_arm = |id| { - let hir::Node::Block(blk) = self.tcx.hir().get(id) else { + let hir::Node::Block(blk) = self.tcx.hir_node(id) else { return false; }; if blk.expr.is_some() || !blk.stmts.is_empty() { @@ -1019,8 +1019,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { /// ``` fn cmp_type_arg( &self, - mut t1_out: &mut DiagnosticStyledString, - mut t2_out: &mut DiagnosticStyledString, + t1_out: &mut DiagnosticStyledString, + t2_out: &mut DiagnosticStyledString, path: String, sub: &'tcx [ty::GenericArg<'tcx>], other_path: String, @@ -1031,13 +1031,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let sub = self.tcx.mk_args(sub); for (i, ta) in sub.types().enumerate() { if ta == other_ty { - self.highlight_outer(&mut t1_out, &mut t2_out, path, sub, i, other_ty); + self.highlight_outer(t1_out, t2_out, path, sub, i, other_ty); return Some(()); } if let ty::Adt(def, _) = ta.kind() { let path_ = self.tcx.def_path_str(def.did()); if path_ == other_path { - self.highlight_outer(&mut t1_out, &mut t2_out, path, sub, i, other_ty); + self.highlight_outer(t1_out, t2_out, path, sub, i, other_ty); return Some(()); } } @@ -1181,37 +1181,54 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { debug!("cmp(t1={}, t1.kind={:?}, t2={}, t2.kind={:?})", t1, t1.kind(), t2, t2.kind()); // helper functions - fn equals<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool { - match (a.kind(), b.kind()) { - (a, b) if *a == *b => true, - (&ty::Int(_), &ty::Infer(ty::InferTy::IntVar(_))) - | ( - &ty::Infer(ty::InferTy::IntVar(_)), - &ty::Int(_) | &ty::Infer(ty::InferTy::IntVar(_)), - ) - | (&ty::Float(_), &ty::Infer(ty::InferTy::FloatVar(_))) - | ( - &ty::Infer(ty::InferTy::FloatVar(_)), - &ty::Float(_) | &ty::Infer(ty::InferTy::FloatVar(_)), - ) => true, - _ => false, + let recurse = |t1, t2, values: &mut (DiagnosticStyledString, DiagnosticStyledString)| { + let (x1, x2) = self.cmp(t1, t2); + (values.0).0.extend(x1.0); + (values.1).0.extend(x2.0); + }; + + fn fmt_region<'tcx>(region: ty::Region<'tcx>) -> String { + let mut r = region.to_string(); + if r == "'_" { + r.clear(); + } else { + r.push(' '); } + format!("&{r}") } - fn push_ty_ref<'tcx>( + fn push_ref<'tcx>( region: ty::Region<'tcx>, - ty: Ty<'tcx>, mutbl: hir::Mutability, s: &mut DiagnosticStyledString, ) { - let mut r = region.to_string(); - if r == "'_" { - r.clear(); + s.push_highlighted(fmt_region(region)); + s.push_highlighted(mutbl.prefix_str()); + } + + fn cmp_ty_refs<'tcx>( + r1: ty::Region<'tcx>, + mut1: hir::Mutability, + r2: ty::Region<'tcx>, + mut2: hir::Mutability, + ss: &mut (DiagnosticStyledString, DiagnosticStyledString), + ) { + let (r1, r2) = (fmt_region(r1), fmt_region(r2)); + if r1 != r2 { + ss.0.push_highlighted(r1); + ss.1.push_highlighted(r2); } else { - r.push(' '); + ss.0.push_normal(r1); + ss.1.push_normal(r2); + } + + if mut1 != mut2 { + ss.0.push_highlighted(mut1.prefix_str()); + ss.1.push_highlighted(mut2.prefix_str()); + } else { + ss.0.push_normal(mut1.prefix_str()); + ss.1.push_normal(mut2.prefix_str()); } - s.push_highlighted(format!("&{}{}", r, mutbl.prefix_str())); - s.push_normal(ty.to_string()); } // process starts here @@ -1285,7 +1302,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { if lifetimes.0 != lifetimes.1 { values.0.push_highlighted(l1); values.1.push_highlighted(l2); - } else if lifetimes.0.is_late_bound() { + } else if lifetimes.0.is_bound() { values.0.push_normal(l1); values.1.push_normal(l2); } else { @@ -1310,9 +1327,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { values.0.push_normal("_"); values.1.push_normal("_"); } else { - let (x1, x2) = self.cmp(ta1, ta2); - (values.0).0.extend(x1.0); - (values.1).0.extend(x2.0); + recurse(ta1, ta2, &mut values); } self.push_comma(&mut values.0, &mut values.1, len, i); } @@ -1418,27 +1433,24 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { } } - // When finding T != &T, highlight only the borrow - (&ty::Ref(r1, ref_ty1, mutbl1), _) if equals(ref_ty1, t2) => { + // When finding `&T != &T`, compare the references, then recurse into pointee type + (&ty::Ref(r1, ref_ty1, mutbl1), &ty::Ref(r2, ref_ty2, mutbl2)) => { let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new()); - push_ty_ref(r1, ref_ty1, mutbl1, &mut values.0); - values.1.push_normal(t2.to_string()); + cmp_ty_refs(r1, mutbl1, r2, mutbl2, &mut values); + recurse(ref_ty1, ref_ty2, &mut values); values } - (_, &ty::Ref(r2, ref_ty2, mutbl2)) if equals(t1, ref_ty2) => { + // When finding T != &T, highlight the borrow + (&ty::Ref(r1, ref_ty1, mutbl1), _) => { let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new()); - values.0.push_normal(t1.to_string()); - push_ty_ref(r2, ref_ty2, mutbl2, &mut values.1); + push_ref(r1, mutbl1, &mut values.0); + recurse(ref_ty1, t2, &mut values); values } - - // When encountering &T != &mut T, highlight only the borrow - (&ty::Ref(r1, ref_ty1, mutbl1), &ty::Ref(r2, ref_ty2, mutbl2)) - if equals(ref_ty1, ref_ty2) => - { + (_, &ty::Ref(r2, ref_ty2, mutbl2)) => { let mut values = (DiagnosticStyledString::new(), DiagnosticStyledString::new()); - push_ty_ref(r1, ref_ty1, mutbl1, &mut values.0); - push_ty_ref(r2, ref_ty2, mutbl2, &mut values.1); + push_ref(r2, mutbl2, &mut values.1); + recurse(t1, ref_ty2, &mut values); values } @@ -1448,9 +1460,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { (DiagnosticStyledString::normal("("), DiagnosticStyledString::normal("(")); let len = args1.len(); for (i, (left, right)) in args1.iter().zip(args2).enumerate() { - let (x1, x2) = self.cmp(left, right); - (values.0).0.extend(x1.0); - (values.1).0.extend(x2.0); + recurse(left, right, &mut values); self.push_comma(&mut values.0, &mut values.1, len, i); } if len == 1 { @@ -1667,9 +1677,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { .report(diag); (false, Mismatch::Fixed("signature")) } - ValuePairs::TraitRefs(_) | ValuePairs::PolyTraitRefs(_) => { - (false, Mismatch::Fixed("trait")) - } + ValuePairs::PolyTraitRefs(_) => (false, Mismatch::Fixed("trait")), ValuePairs::Aliases(infer::ExpectedFound { expected, .. }) => { (false, Mismatch::Fixed(self.tcx.def_descr(expected.def_id))) } @@ -1735,7 +1743,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { } } - if let Some((expected, found, exp_p, found_p)) = expected_found { + if let Some((expected, found, path)) = expected_found { let (expected_label, found_label, exp_found) = match exp_found { Mismatch::Variable(ef) => ( ef.expected.prefix_string(self.tcx), @@ -1861,40 +1869,31 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { } TypeError::Sorts(values) => { let extra = expected == found; - let sort_string = |ty: Ty<'tcx>, path: Option<PathBuf>| { - let mut s = match (extra, ty.kind()) { - (true, ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. })) => { - let sm = self.tcx.sess.source_map(); - let pos = sm.lookup_char_pos(self.tcx.def_span(*def_id).lo()); - format!( - " (opaque type at <{}:{}:{}>)", - sm.filename_for_diagnostics(&pos.file.name), - pos.line, - pos.col.to_usize() + 1, - ) - } - (true, ty::Alias(ty::Projection, proj)) - if self.tcx.is_impl_trait_in_trait(proj.def_id) => - { - let sm = self.tcx.sess.source_map(); - let pos = sm.lookup_char_pos(self.tcx.def_span(proj.def_id).lo()); - format!( - " (trait associated opaque type at <{}:{}:{}>)", - sm.filename_for_diagnostics(&pos.file.name), - pos.line, - pos.col.to_usize() + 1, - ) - } - (true, _) => format!(" ({})", ty.sort_string(self.tcx)), - (false, _) => "".to_string(), - }; - if let Some(path) = path { - s.push_str(&format!( - "\nthe full type name has been written to '{}'", - path.display(), - )); + let sort_string = |ty: Ty<'tcx>| match (extra, ty.kind()) { + (true, ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. })) => { + let sm = self.tcx.sess.source_map(); + let pos = sm.lookup_char_pos(self.tcx.def_span(*def_id).lo()); + format!( + " (opaque type at <{}:{}:{}>)", + sm.filename_for_diagnostics(&pos.file.name), + pos.line, + pos.col.to_usize() + 1, + ) } - s + (true, ty::Alias(ty::Projection, proj)) + if self.tcx.is_impl_trait_in_trait(proj.def_id) => + { + let sm = self.tcx.sess.source_map(); + let pos = sm.lookup_char_pos(self.tcx.def_span(proj.def_id).lo()); + format!( + " (trait associated opaque type at <{}:{}:{}>)", + sm.filename_for_diagnostics(&pos.file.name), + pos.line, + pos.col.to_usize() + 1, + ) + } + (true, _) => format!(" ({})", ty.sort_string(self.tcx)), + (false, _) => "".to_string(), }; if !(values.expected.is_simple_text(self.tcx) && values.found.is_simple_text(self.tcx)) @@ -1925,9 +1924,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { expected, &found_label, found, - &sort_string(values.expected, exp_p), - &sort_string(values.found, found_p), + &sort_string(values.expected), + &sort_string(values.found), ); + if let Some(path) = path { + diag.note(format!( + "the full type name has been written to '{}'", + path.display(), + )); + } } } } @@ -1999,7 +2004,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { diag.span_note(span, "this closure does not fulfill the lifetime requirements"); self.suggest_for_all_lifetime_closure( span, - self.tcx.hir().get_by_def_id(def_id), + self.tcx.hir_node_by_def_id(def_id), &exp_found, diag, ); @@ -2093,7 +2098,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { if let &(MatchExpressionArm(box MatchExpressionArmCause { source, .. }) | BlockTailExpression(.., source)) = code && let hir::MatchSource::TryDesugar(_) = source - && let Some((expected_ty, found_ty, _, _)) = self.values_str(trace.values) + && let Some((expected_ty, found_ty, _)) = self.values_str(trace.values) { suggestions.push(TypeErrorAdditionalDiags::TryCannotConvert { found: found_ty.content(), @@ -2113,7 +2118,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let TypeError::FixedArraySize(sz) = terr else { return None; }; - let tykind = match hir.find_by_def_id(trace.cause.body_id) { + let tykind = match self.tcx.opt_hir_node_by_def_id(trace.cause.body_id) { Some(hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, _, body_id), .. })) => { let body = hir.body(*body_id); struct LetVisitor<'v> { @@ -2211,33 +2216,20 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn values_str( &self, values: ValuePairs<'tcx>, - ) -> Option<(DiagnosticStyledString, DiagnosticStyledString, Option<PathBuf>, Option<PathBuf>)> - { + ) -> Option<(DiagnosticStyledString, DiagnosticStyledString, Option<PathBuf>)> { match values { infer::Regions(exp_found) => self.expected_found_str(exp_found), infer::Terms(exp_found) => self.expected_found_str_term(exp_found), infer::Aliases(exp_found) => self.expected_found_str(exp_found), infer::ExistentialTraitRef(exp_found) => self.expected_found_str(exp_found), infer::ExistentialProjection(exp_found) => self.expected_found_str(exp_found), - infer::TraitRefs(exp_found) => { - let pretty_exp_found = ty::error::ExpectedFound { - expected: exp_found.expected.print_only_trait_path(), - found: exp_found.found.print_only_trait_path(), - }; - match self.expected_found_str(pretty_exp_found) { - Some((expected, found, _, _)) if expected == found => { - self.expected_found_str(exp_found) - } - ret => ret, - } - } infer::PolyTraitRefs(exp_found) => { let pretty_exp_found = ty::error::ExpectedFound { - expected: exp_found.expected.print_only_trait_path(), - found: exp_found.found.print_only_trait_path(), + expected: exp_found.expected.print_trait_sugared(), + found: exp_found.found.print_trait_sugared(), }; match self.expected_found_str(pretty_exp_found) { - Some((expected, found, _, _)) if expected == found => { + Some((expected, found, _)) if expected == found => { self.expected_found_str(exp_found) } ret => ret, @@ -2249,7 +2241,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { return None; } let (exp, fnd) = self.cmp_fn_sig(&exp_found.expected, &exp_found.found); - Some((exp, fnd, None, None)) + Some((exp, fnd, None)) } } } @@ -2257,8 +2249,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn expected_found_str_term( &self, exp_found: ty::error::ExpectedFound<ty::Term<'tcx>>, - ) -> Option<(DiagnosticStyledString, DiagnosticStyledString, Option<PathBuf>, Option<PathBuf>)> - { + ) -> Option<(DiagnosticStyledString, DiagnosticStyledString, Option<PathBuf>)> { let exp_found = self.resolve_vars_if_possible(exp_found); if exp_found.references_error() { return None; @@ -2273,25 +2264,21 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let len = self.tcx.sess().diagnostic_width() + 40; let exp_s = exp.content(); let fnd_s = fnd.content(); - let mut exp_p = None; - let mut fnd_p = None; + let mut path = None; if exp_s.len() > len { - let (exp_s, exp_path) = self.tcx.short_ty_string(expected); + let exp_s = self.tcx.short_ty_string(expected, &mut path); exp = DiagnosticStyledString::highlighted(exp_s); - exp_p = exp_path; } if fnd_s.len() > len { - let (fnd_s, fnd_path) = self.tcx.short_ty_string(found); + let fnd_s = self.tcx.short_ty_string(found, &mut path); fnd = DiagnosticStyledString::highlighted(fnd_s); - fnd_p = fnd_path; } - (exp, fnd, exp_p, fnd_p) + (exp, fnd, path) } _ => ( DiagnosticStyledString::highlighted(exp_found.expected.to_string()), DiagnosticStyledString::highlighted(exp_found.found.to_string()), None, - None, ), }) } @@ -2300,8 +2287,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { fn expected_found_str<T: fmt::Display + TypeFoldable<TyCtxt<'tcx>>>( &self, exp_found: ty::error::ExpectedFound<T>, - ) -> Option<(DiagnosticStyledString, DiagnosticStyledString, Option<PathBuf>, Option<PathBuf>)> - { + ) -> Option<(DiagnosticStyledString, DiagnosticStyledString, Option<PathBuf>)> { let exp_found = self.resolve_vars_if_possible(exp_found); if exp_found.references_error() { return None; @@ -2311,7 +2297,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { DiagnosticStyledString::highlighted(exp_found.expected.to_string()), DiagnosticStyledString::highlighted(exp_found.found.to_string()), None, - None, )) } @@ -2351,6 +2336,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let labeled_user_string = match bound_kind { GenericKind::Param(ref p) => format!("the parameter type `{p}`"), + GenericKind::Placeholder(ref p) => format!("the placeholder type `{p:?}`"), GenericKind::Alias(ref p) => match p.kind(self.tcx) { ty::AliasKind::Projection | ty::AliasKind::Inherent => { format!("the associated type `{p}`") @@ -2364,7 +2350,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { span, format!("{labeled_user_string} may not live long enough"), match sub.kind() { - ty::ReEarlyBound(_) | ty::ReFree(_) if sub.has_name() => error_code!(E0309), + ty::ReEarlyParam(_) | ty::ReLateParam(_) if sub.has_name() => error_code!(E0309), ty::ReStatic => error_code!(E0310), _ => error_code!(E0311), }, @@ -2372,7 +2358,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { '_explain: { let (description, span) = match sub.kind() { - ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic => { + ty::ReEarlyParam(_) | ty::ReLateParam(_) | ty::ReStatic => { msg_span_from_named_region(self.tcx, sub, Some(span)) } _ => (format!("lifetime `{sub}`"), Some(span)), @@ -2455,7 +2441,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { if !suggs.is_empty() { err.multipart_suggestion_verbose( - format!("{msg}"), + msg, suggs, Applicability::MaybeIncorrect, // Issue #41966 ); @@ -2515,7 +2501,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let (lifetime_def_id, lifetime_scope) = match self.tcx.is_suitable_region(lifetime) { Some(info) if !lifetime.has_name() => { - (info.boundregion.get_id().unwrap().expect_local(), info.def_id) + (info.bound_region.get_id().unwrap().expect_local(), info.def_id) } _ => return lifetime.get_name_or_anon().to_string(), }; @@ -2594,8 +2580,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { if let infer::Subtype(ref sup_trace) = sup_origin && let infer::Subtype(ref sub_trace) = sub_origin - && let Some((sup_expected, sup_found, _, _)) = self.values_str(sup_trace.values) - && let Some((sub_expected, sub_found, _, _)) = self.values_str(sub_trace.values) + && let Some((sup_expected, sup_found, _)) = self.values_str(sup_trace.values) + && let Some((sub_expected, sub_found, _)) = self.values_str(sub_trace.values) && sub_expected == sup_expected && sub_found == sup_found { @@ -2667,11 +2653,6 @@ impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> { self.0.tcx } - fn param_env(&self) -> ty::ParamEnv<'tcx> { - // Unused, only for consts which we treat as always equal - ty::ParamEnv::empty() - } - fn tag(&self) -> &'static str { "SameTypeModuloInfer" } @@ -2714,8 +2695,8 @@ impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> { a: ty::Region<'tcx>, b: ty::Region<'tcx>, ) -> RelateResult<'tcx, ty::Region<'tcx>> { - if (a.is_var() && b.is_free_or_static()) - || (b.is_var() && a.is_free_or_static()) + if (a.is_var() && b.is_free()) + || (b.is_var() && a.is_free()) || (a.is_var() && b.is_var()) || a == b { @@ -2768,18 +2749,20 @@ impl<'tcx> InferCtxt<'tcx> { infer::AddrOfRegion(_) => " for borrow expression".to_string(), infer::Autoref(_) => " for autoref".to_string(), infer::Coercion(_) => " for automatic coercion".to_string(), - infer::LateBoundRegion(_, br, infer::FnCall) => { + infer::BoundRegion(_, br, infer::FnCall) => { format!(" for lifetime parameter {}in function call", br_string(br)) } - infer::LateBoundRegion(_, br, infer::HigherRankedType) => { + infer::BoundRegion(_, br, infer::HigherRankedType) => { format!(" for lifetime parameter {}in generic type", br_string(br)) } - infer::LateBoundRegion(_, br, infer::AssocTypeProjection(def_id)) => format!( + infer::BoundRegion(_, br, infer::AssocTypeProjection(def_id)) => format!( " for lifetime parameter {}in trait containing associated type `{}`", br_string(br), self.tcx.associated_item(def_id).name ), - infer::EarlyBoundRegion(_, name) => format!(" for lifetime parameter `{name}`"), + infer::RegionParameterDefinition(_, name) => { + format!(" for lifetime parameter `{name}`") + } infer::UpvarRegion(ref upvar_id, _) => { let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id); format!(" for capture of `{var_name}` by closure") @@ -2906,9 +2889,6 @@ impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> { CompareImplItemObligation { kind: ty::AssocKind::Const, .. } => { "const is compatible with trait" } - ExprAssignable => "expression is assignable", - IfExpression { .. } => "`if` and `else` have incompatible types", - IfExpressionWithNoElse => "`if` missing an `else` returns `()`", MainFunctionType => "`main` function has the correct type", StartFunctionType => "`#[start]` function has the correct type", LangFunctionType(_) => "lang item function has the correct type", @@ -2929,9 +2909,6 @@ impl IntoDiagnosticArg for ObligationCauseAsDiagArg<'_> { CompareImplItemObligation { kind: ty::AssocKind::Fn, .. } => "method_compat", CompareImplItemObligation { kind: ty::AssocKind::Type, .. } => "type_compat", CompareImplItemObligation { kind: ty::AssocKind::Const, .. } => "const_compat", - ExprAssignable => "expr_assignable", - IfExpression { .. } => "if_else_different", - IfExpressionWithNoElse => "no_else", MainFunctionType => "fn_main_correct_type", StartFunctionType => "fn_start_correct_type", LangFunctionType(_) => "fn_lang_correct_type", @@ -3004,7 +2981,7 @@ impl<'tcx> InferCtxt<'tcx> { /// Given a [`hir::HirId`] for a block, get the span of its last expression /// or statement, peeling off any inner blocks. pub fn find_block_span_from_hir_id(&self, hir_id: hir::HirId) -> Span { - match self.tcx.hir().get(hir_id) { + match self.tcx.hir_node(hir_id) { hir::Node::Block(blk) => self.find_block_span(blk), // The parser was in a weird state if either of these happen, but // it's better not to panic. diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index 4beb51da7..817a4451d 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -232,7 +232,9 @@ fn ty_to_string<'tcx>( /// something users are familiar with. Directly printing the `fn_sig` of closures also /// doesn't work as they actually use the "rust-call" API. fn closure_as_fn_str<'tcx>(infcx: &InferCtxt<'tcx>, ty: Ty<'tcx>) -> String { - let ty::Closure(_, args) = ty.kind() else { unreachable!() }; + let ty::Closure(_, args) = ty.kind() else { + bug!("cannot convert non-closure to fn str in `closure_as_fn_str`") + }; let fn_sig = args.as_closure().sig(); let args = fn_sig .inputs() @@ -374,7 +376,7 @@ impl<'tcx> InferCtxt<'tcx> { multi_suggestions, bad_label, } - .into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic), + .into_diagnostic(self.tcx.sess.dcx()), TypeAnnotationNeeded::E0283 => AmbiguousImpl { span, source_kind, @@ -384,7 +386,7 @@ impl<'tcx> InferCtxt<'tcx> { multi_suggestions, bad_label, } - .into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic), + .into_diagnostic(self.tcx.sess.dcx()), TypeAnnotationNeeded::E0284 => AmbiguousReturn { span, source_kind, @@ -394,7 +396,7 @@ impl<'tcx> InferCtxt<'tcx> { multi_suggestions, bad_label, } - .into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic), + .into_diagnostic(self.tcx.sess.dcx()), } } } @@ -419,7 +421,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { return self.bad_inference_failure_err(failure_span, arg_data, error_code); }; - let mut local_visitor = FindInferSourceVisitor::new(&self, typeck_results, arg); + let mut local_visitor = FindInferSourceVisitor::new(self, typeck_results, arg); if let Some(body_id) = self.tcx.hir().maybe_body_owned_by( self.tcx.typeck_root_def_id(body_def_id.to_def_id()).expect_local(), ) { @@ -581,7 +583,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { multi_suggestions, bad_label: None, } - .into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic), + .into_diagnostic(self.tcx.sess.dcx()), TypeAnnotationNeeded::E0283 => AmbiguousImpl { span, source_kind, @@ -591,7 +593,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { multi_suggestions, bad_label: None, } - .into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic), + .into_diagnostic(self.tcx.sess.dcx()), TypeAnnotationNeeded::E0284 => AmbiguousReturn { span, source_kind, @@ -601,7 +603,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { multi_suggestions, bad_label: None, } - .into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic), + .into_diagnostic(self.tcx.sess.dcx()), } } } @@ -1087,7 +1089,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { Box::new(segment.into_iter()) } - hir::QPath::LangItem(_, _, _) => Box::new(iter::empty()), + hir::QPath::LangItem(_, _) => Box::new(iter::empty()), } } } diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs index 1a60bab18..f56d5d7d3 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/different_lifetimes.rs @@ -70,9 +70,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { let anon_reg_sub = self.tcx().is_suitable_region(sub)?; let scope_def_id_sup = anon_reg_sup.def_id; - let bregion_sup = anon_reg_sup.boundregion; + let bregion_sup = anon_reg_sup.bound_region; let scope_def_id_sub = anon_reg_sub.def_id; - let bregion_sub = anon_reg_sub.boundregion; + let bregion_sub = anon_reg_sub.bound_region; let ty_sup = find_anon_type(self.tcx(), sup, &bregion_sup)?; diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs index 0df417d09..4f74365d0 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs @@ -26,8 +26,7 @@ pub fn find_anon_type<'tcx>( br: &ty::BoundRegionKind, ) -> Option<(&'tcx hir::Ty<'tcx>, &'tcx hir::FnSig<'tcx>)> { let anon_reg = tcx.is_suitable_region(region)?; - let hir_id = tcx.hir().local_def_id_to_hir_id(anon_reg.def_id); - let fn_sig = tcx.hir().get(hir_id).fn_sig()?; + let fn_sig = tcx.hir_node_by_def_id(anon_reg.def_id).fn_sig()?; fn_sig .decl @@ -96,7 +95,7 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> { } } - hir::TyKind::Ref(ref lifetime, _) => { + hir::TyKind::Ref(lifetime, _) => { // the lifetime of the Ref let hir_id = lifetime.hir_id; match (self.tcx.named_bound_var(hir_id), self.bound_region) { diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mismatched_static_lifetime.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mismatched_static_lifetime.rs index 6901955af..df7907e1f 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mismatched_static_lifetime.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mismatched_static_lifetime.rs @@ -81,7 +81,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { for matching_def_id in v.0 { let mut hir_v = super::static_impl_trait::HirTraitObjectVisitor(&mut traits, matching_def_id); - hir_v.visit_ty(&impl_self_ty); + hir_v.visit_ty(impl_self_ty); } if traits.is_empty() { diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs index c38e5b8cd..d98ca995d 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs @@ -197,11 +197,6 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { value_pairs: &ValuePairs<'tcx>, ) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> { let (expected_args, found_args, trait_def_id) = match value_pairs { - ValuePairs::TraitRefs(ExpectedFound { expected, found }) - if expected.def_id == found.def_id => - { - (expected.args, found.args, expected.def_id) - } ValuePairs::PolyTraitRefs(ExpectedFound { expected, found }) if expected.def_id() == found.def_id() => { diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs index e2be6cf42..01b43f719 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -78,7 +78,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { has_impl_path, impl_path, }); - if self.find_impl_on_dyn_trait(&mut err, param.param_ty, &ctxt) { + if self.find_impl_on_dyn_trait(&mut err, param.param_ty, ctxt) { let reported = err.emit(); return Some(reported); } else { @@ -204,7 +204,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { && let ObligationCauseCode::UnifyReceiver(ctxt) = cause.code() // Handle case of `impl Foo for dyn Bar { fn qux(&self) {} }` introducing a // `'static` lifetime when called as a method on a binding: `bar.qux()`. - && self.find_impl_on_dyn_trait(&mut err, param.param_ty, &ctxt) + && self.find_impl_on_dyn_trait(&mut err, param.param_ty, ctxt) { override_error_code = Some(ctxt.assoc_item.name); } @@ -460,7 +460,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { tcx.hir().trait_impls(trait_did).iter().find_map(|&impl_did| { if let Node::Item(Item { kind: ItemKind::Impl(hir::Impl { self_ty, .. }), .. - }) = tcx.hir().find_by_def_id(impl_did)? + }) = tcx.opt_hir_node_by_def_id(impl_did)? && trait_objects.iter().all(|did| { // FIXME: we should check `self_ty` against the receiver // type in the `UnifyReceiver` context, but for now, use @@ -530,7 +530,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { for found_did in found_dids { let mut traits = vec![]; let mut hir_v = HirTraitObjectVisitor(&mut traits, *found_did); - hir_v.visit_ty(&self_ty); + hir_v.visit_ty(self_ty); for &span in &traits { let subdiag = DynTraitConstraintSuggestion { span, ident }; subdiag.add_to_diagnostic(err); diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs index cb51254a1..b16d5c509 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs @@ -101,7 +101,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { ty::AssocKind::Fn => { let hir = self.tcx().hir(); if let Some(hir_id) = - assoc_item.def_id.as_local().map(|id| hir.local_def_id_to_hir_id(id)) + assoc_item.def_id.as_local().map(|id| self.tcx().local_def_id_to_hir_id(id)) { if let Some(decl) = hir.fn_decl_by_hir_id(hir_id) { visitor.visit_fn_decl(decl); diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs index be6d1a375..bfff00b94 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs @@ -41,8 +41,8 @@ pub fn find_param_with_region<'tcx>( replace_region: Region<'tcx>, ) -> Option<AnonymousParamInfo<'tcx>> { let (id, bound_region) = match *anon_region { - ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region), - ty::ReEarlyBound(ebr) => { + ty::ReLateParam(late_param) => (late_param.scope, late_param.bound_region), + ty::ReEarlyParam(ebr) => { (tcx.parent(ebr.def_id), ty::BoundRegionKind::BrNamed(ebr.def_id, ebr.name)) } _ => return None, // not a free region @@ -50,11 +50,10 @@ pub fn find_param_with_region<'tcx>( let hir = &tcx.hir(); let def_id = id.as_local()?; - let hir_id = hir.local_def_id_to_hir_id(def_id); // FIXME: use def_kind // Don't perform this on closures - match hir.get(hir_id) { + match tcx.hir_node_by_def_id(def_id) { hir::Node::Expr(&hir::Expr { kind: hir::ExprKind::Closure { .. }, .. }) => { return None; } @@ -161,7 +160,6 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { && self .tcx() .opt_associated_item(scope_def_id.to_def_id()) - .map(|i| i.fn_has_self_parameter) - == Some(true) + .is_some_and(|i| i.fn_has_self_parameter) } } diff --git a/compiler/rustc_infer/src/infer/error_reporting/note.rs b/compiler/rustc_infer/src/infer/error_reporting/note.rs index 8d3cd23b7..859c10ef1 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note.rs @@ -22,7 +22,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { infer::Subtype(ref trace) => RegionOriginNote::WithRequirement { span: trace.cause.span, requirement: ObligationCauseAsDiagArg(trace.cause.clone()), - expected_found: self.values_str(trace.values).map(|(e, f, _, _)| (e, f)), + expected_found: self.values_str(trace.values).map(|(e, f, _)| (e, f)), } .add_to_diagnostic(err), infer::Reborrow(span) => { @@ -63,7 +63,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { .add_to_diagnostic(err); } infer::CheckAssociatedTypeBounds { ref parent, .. } => { - self.note_region_origin(err, &parent); + self.note_region_origin(err, parent); } infer::AscribeUserTypeProvePredicate(span) => { RegionOriginNote::Plain { @@ -140,7 +140,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { span, notes: reference_valid.into_iter().chain(content_valid).collect(), } - .into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic) + .into_diagnostic(self.tcx.sess.dcx()) } infer::RelateObjectBound(span) => { let object_valid = note_and_explain::RegionExplanation::new( @@ -161,7 +161,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { span, notes: object_valid.into_iter().chain(pointer_valid).collect(), } - .into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic) + .into_diagnostic(self.tcx.sess.dcx()) } infer::RelateParamBound(span, ty, opt_span) => { let prefix = match *sub { @@ -177,7 +177,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { self.tcx, sub, opt_span, prefix, suffix, ); FulfillReqLifetime { span, ty: self.resolve_vars_if_possible(ty), note } - .into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic) + .into_diagnostic(self.tcx.sess.dcx()) } infer::RelateRegionParamBound(span) => { let param_instantiated = note_and_explain::RegionExplanation::new( @@ -198,7 +198,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { span, notes: param_instantiated.into_iter().chain(param_must_outlive).collect(), } - .into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic) + .into_diagnostic(self.tcx.sess.dcx()) } infer::ReferenceOutlivesReferent(ty, span) => { let pointer_valid = note_and_explain::RegionExplanation::new( @@ -220,7 +220,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { ty: self.resolve_vars_if_possible(ty), notes: pointer_valid.into_iter().chain(data_valid).collect(), } - .into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic) + .into_diagnostic(self.tcx.sess.dcx()) } infer::CompareImplItemObligation { span, impl_item_def_id, trait_item_def_id } => { let mut err = self.report_extra_impl_obligation( @@ -281,7 +281,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { span, notes: instantiated.into_iter().chain(must_outlive).collect(), } - .into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic) + .into_diagnostic(self.tcx.sess.dcx()) } }; if sub.is_error() || sup.is_error() { @@ -375,7 +375,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { err.span_note(span, "the lifetime requirement is introduced here"); err } else { - unreachable!() + unreachable!( + "control flow ensures we have a `BindingObligation` or `ExprBindingObligation` here..." + ) } } infer::Subtype(box trace) => { diff --git a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs index a8ae43d52..afb3c5c1e 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs @@ -87,7 +87,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { | (ty::Alias(ty::Projection, proj), ty::Param(p)) if !tcx.is_impl_trait_in_trait(proj.def_id) => { - let parent = tcx.generics_of(body_owner_def_id) + let parent = tcx + .generics_of(body_owner_def_id) .opt_type_param(p, tcx) .and_then(|param| { let p_def_id = param.def_id; @@ -104,7 +105,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { ); } p_def_id.as_local().and_then(|id| { - let local_id = tcx.hir().local_def_id_to_hir_id(id); + let local_id = tcx.local_def_id_to_hir_id(id); let generics = tcx.hir().find_parent(local_id)?.generics()?; Some((id, generics)) }) @@ -654,7 +655,7 @@ fn foo(&self) -> Self::T { String::new() } // When `body_owner` is an `impl` or `trait` item, look in its associated types for // `expected` and point at it. let parent_id = tcx.hir().get_parent_item(hir_id); - let item = tcx.hir().find_by_def_id(parent_id.def_id); + let item = tcx.opt_hir_node_by_def_id(parent_id.def_id); debug!("expected_projection parent item {:?}", item); diff --git a/compiler/rustc_infer/src/infer/error_reporting/suggest.rs b/compiler/rustc_infer/src/infer/error_reporting/suggest.rs index fe18d0029..bbe07b8ed 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/suggest.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/suggest.rs @@ -42,7 +42,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { ] .into_iter() .find_map(|(id, ty)| { - let hir::Node::Block(blk) = self.tcx.hir().get(id?) else { return None }; + let hir::Node::Block(blk) = self.tcx.hir_node(id?) else { return None }; self.could_remove_semicolon(blk, ty) }); match remove_semicolon { @@ -62,7 +62,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let mut ret = None; for (id, ty) in [(first_id, second_ty), (second_id, first_ty)] { if let Some(id) = id - && let hir::Node::Block(blk) = self.tcx.hir().get(id) + && let hir::Node::Block(blk) = self.tcx.hir_node(id) && let Some(diag) = self.consider_returning_binding_diag(blk, ty) { ret = Some(diag); @@ -511,7 +511,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { } let mut visitor = IfVisitor { err_span: span, found_if: false, result: false }; - visitor.visit_body(&body); + visitor.visit_body(body); if visitor.result { return Some(TypeErrorAdditionalDiags::AddLetForLetChains { span: span.shrink_to_lo(), @@ -572,8 +572,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { if let ty::Ref(expected_region, _, _) = expected.kind() && let ty::Ref(found_region, _, _) = found.kind() - && expected_region.is_late_bound() - && !found_region.is_late_bound() + && expected_region.is_bound() + && !found_region.is_bound() && let hir::TyKind::Infer = arg_hir.kind { // If the expected region is late bound, the found region is not, and users are asking compiler @@ -636,10 +636,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { return None; } let last_stmt = blk.stmts.last()?; - let hir::StmtKind::Semi(ref last_expr) = last_stmt.kind else { + let hir::StmtKind::Semi(last_expr) = last_stmt.kind else { return None; }; - let last_expr_ty = self.typeck_results.as_ref()?.expr_ty_opt(*last_expr)?; + let last_expr_ty = self.typeck_results.as_ref()?.expr_ty_opt(last_expr)?; let needs_box = match (last_expr_ty.kind(), expected_ty.kind()) { _ if last_expr_ty.references_error() => return None, _ if self.same_type_modulo_infer(last_expr_ty, expected_ty) => { @@ -668,26 +668,16 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { ( hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds: last_bounds, .. }), hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds: exp_bounds, .. }), - ) if std::iter::zip(*last_bounds, *exp_bounds).all(|(left, right)| { - match (left, right) { - ( - hir::GenericBound::Trait(tl, ml), - hir::GenericBound::Trait(tr, mr), - ) if tl.trait_ref.trait_def_id() == tr.trait_ref.trait_def_id() + ) if std::iter::zip(*last_bounds, *exp_bounds).all(|(left, right)| match ( + left, right, + ) { + (hir::GenericBound::Trait(tl, ml), hir::GenericBound::Trait(tr, mr)) + if tl.trait_ref.trait_def_id() == tr.trait_ref.trait_def_id() && ml == mr => - { - true - } - ( - hir::GenericBound::LangItemTrait(langl, _, _, argsl), - hir::GenericBound::LangItemTrait(langr, _, _, argsr), - ) if langl == langr => { - // FIXME: consider the bounds! - debug!("{:?} {:?}", argsl, argsr); - true - } - _ => false, + { + true } + _ => false, }) => { StatementAsExpression::NeedsBoxing |