diff options
| author | bors <bors@rust-lang.org> | 2021-07-20 10:56:08 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-07-20 10:56:08 +0000 |
| commit | da7d405357600a76f2b93b8aa41fe5ee5da7885d (patch) | |
| tree | 9763cf30603b2489abef4a9fefe570465c287b29 /compiler/rustc_trait_selection | |
| parent | 718d53b0cb7dde93499cb92950d60b412f5a3d05 (diff) | |
| parent | ae024919845a44473c22b8c3f1dfa075c9c5c75d (diff) | |
| download | rust-da7d405357600a76f2b93b8aa41fe5ee5da7885d.tar.gz rust-da7d405357600a76f2b93b8aa41fe5ee5da7885d.zip | |
Auto merge of #87244 - jackh726:issue-71883, r=estebank
Better diagnostics with mismatched types due to implicit static lifetime Fixes #78113 I think this is my first diagnostics PR...definitely happy to hear thoughts on the direction/implementation here. I was originally just trying to solve the error above, where the lifetime on a GAT was causing a cryptic "mismatched types" error. But as I was writing this, I realized that this (unintentionally) also applied to a different case: `wf-in-foreign-fn-decls-issue-80468.rs`. I'm not sure if this diagnostic should get a new error code, or even reuse an existing one. And, there might be some ways to make this even more generalized. Also, the error is a bit more lengthy and verbose than probably needed. So thoughts there are welcome too. This PR essentially ended up adding a new nice region error pass that triggers if a type doesn't match the self type of an impl which is selected because of a predicate because of an implicit static bound on that self type. r? `@estebank`
Diffstat (limited to 'compiler/rustc_trait_selection')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/select/mod.rs | 8 |
2 files changed, 9 insertions, 2 deletions
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 02d87666e96..1c6a83b5783 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); |
