diff options
| author | Michael Goulet <michael@errs.io> | 2025-02-19 19:55:12 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-02-24 19:34:54 +0000 |
| commit | b46acc01916ba3e8b8f8ab9d89608861d1d4cb87 (patch) | |
| tree | 3b7edcaeb87963cebaf06d052c0975691004fe99 /compiler/rustc_hir_analysis/src/coherence/builtin.rs | |
| parent | 5c5ed92c37a70603e9d45c698898841afacfb25f (diff) | |
| download | rust-b46acc01916ba3e8b8f8ab9d89608861d1d4cb87.tar.gz rust-b46acc01916ba3e8b8f8ab9d89608861d1d4cb87.zip | |
Deduplicate CoerceUnsized and DispatchFromDyn impl errors
Diffstat (limited to 'compiler/rustc_hir_analysis/src/coherence/builtin.rs')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/coherence/builtin.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index 9d6bb1cf6bf..cee2f487639 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -195,8 +195,7 @@ fn visit_implementation_of_coerce_unsized(checker: &Checker<'_>) -> Result<(), E // Just compute this for the side-effects, in particular reporting // errors; other parts of the code may demand it for the info of // course. - let span = tcx.def_span(impl_did); - tcx.at(span).ensure_ok().coerce_unsized_info(impl_did) + tcx.ensure_ok().coerce_unsized_info(impl_did) } fn is_from_coerce_pointee_derive(tcx: TyCtxt<'_>, span: Span) -> bool { @@ -218,13 +217,24 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<() let dispatch_from_dyn_trait = tcx.require_lang_item(LangItem::DispatchFromDyn, Some(span)); let source = trait_ref.self_ty(); - assert!(!source.has_escaping_bound_vars()); let target = { assert_eq!(trait_ref.def_id, dispatch_from_dyn_trait); trait_ref.args.type_at(1) }; + // Check `CoercePointee` impl is WF -- if not, then there's no reason to report + // redundant errors for `DispatchFromDyn`. This is best effort, though. + let mut res = Ok(()); + tcx.for_each_relevant_impl( + tcx.require_lang_item(LangItem::CoerceUnsized, Some(span)), + source, + |impl_def_id| { + res = res.and(tcx.ensure_ok().coerce_unsized_info(impl_def_id)); + }, + ); + res?; + debug!("visit_implementation_of_dispatch_from_dyn: {:?} -> {:?}", source, target); let param_env = tcx.param_env(impl_did); |
