From 3cd5ad5cd7d85fc36c3696e3022bef5c5af088d2 Mon Sep 17 00:00:00 2001 From: jackh726 Date: Thu, 15 Jul 2021 10:03:39 -0400 Subject: Better diagnostics when mismatched types due to implict static lifetime --- .../src/traits/error_reporting/suggestions.rs | 3 ++- compiler/rustc_trait_selection/src/traits/select/mod.rs | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'compiler/rustc_trait_selection') diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index adeb1d58d1e..50a18ce0ebf 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1903,7 +1903,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { | ObligationCauseCode::UnifyReceiver(..) | ObligationCauseCode::OpaqueType | ObligationCauseCode::MiscObligation - | ObligationCauseCode::WellFormed(..) => {} + | ObligationCauseCode::WellFormed(..) + | ObligationCauseCode::MatchImpl(..) => {} ObligationCauseCode::SliceOrArrayElem => { err.note("slice and array elements must have `Sized` type"); } diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 564c63ef30c..1bdc8b34cf6 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1903,9 +1903,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { debug!(?impl_trait_ref, ?placeholder_obligation_trait_ref); + let cause = ObligationCause::new( + obligation.cause.span, + obligation.cause.body_id, + ObligationCauseCode::MatchImpl(Lrc::new(obligation.cause.code.clone()), impl_def_id), + ); + let InferOk { obligations, .. } = self .infcx - .at(&obligation.cause, obligation.param_env) + .at(&cause, obligation.param_env) .eq(placeholder_obligation_trait_ref, impl_trait_ref) .map_err(|e| debug!("match_impl: failed eq_trait_refs due to `{}`", e))?; nested_obligations.extend(obligations); -- cgit 1.4.1-3-g733a5