diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index f5f7618285e1f..0b715970944d2 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -625,7 +625,6 @@ pub enum StashKey { /// FRU syntax MaybeFruTypo, CallAssocMethod, - AssociatedTypeSuggestion, /// Query cycle detected, stashing in favor of a better error. Cycle, UndeterminedMacroResolution, @@ -983,7 +982,9 @@ impl<'a> DiagCtxtHandle<'a> { } pub fn has_stashed_diagnostic(&self, span: Span, key: StashKey) -> bool { - self.inner.borrow().stashed_diagnostics.get(&(span.with_parent(None), key)).is_some() + let inner = self.inner.borrow(); + !inner.stashed_diagnostics.is_empty() + && inner.stashed_diagnostics.get(&(span.with_parent(None), key)).is_some() } /// Emit all stashed diagnostics. diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs index 8e62dce21913b..7aad53e3c6eb8 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs @@ -1,6 +1,6 @@ use rustc_ast::TraitObjectSyntax; use rustc_errors::codes::*; -use rustc_errors::{Diag, EmissionGuarantee, ErrorGuaranteed, StashKey, Suggestions}; +use rustc_errors::{Diag, EmissionGuarantee, ErrorGuaranteed}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Namespace, Res}; use rustc_hir::def_id::DefId; @@ -100,16 +100,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { poly_trait_ref.trait_ref.trait_def_id(), &mut diag, ); - // In case there is an associated type with the same name - // Add the suggestion to this error - if let Some(mut sugg) = - tcx.dcx().steal_non_err(self_ty.span, StashKey::AssociatedTypeSuggestion) - && let Suggestions::Enabled(ref mut s1) = diag.suggestions - && let Suggestions::Enabled(ref mut s2) = sugg.suggestions - { - s1.append(s2); - sugg.cancel(); - } Some(diag.emit()) } else { tcx.node_span_lint(BARE_TRAIT_OBJECTS, self_ty.hir_id, self_ty.span, |lint| { diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 20e19caf9096b..648961aa70491 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -20,9 +20,7 @@ use rustc_ast::*; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_data_structures::unord::{UnordMap, UnordSet}; use rustc_errors::codes::*; -use rustc_errors::{ - Applicability, DiagArgValue, ErrorGuaranteed, IntoDiagArg, StashKey, Suggestions, -}; +use rustc_errors::{Applicability, DiagArgValue, ErrorGuaranteed, IntoDiagArg, Suggestions}; use rustc_hir::def::Namespace::{self, *}; use rustc_hir::def::{self, CtorKind, DefKind, LifetimeRes, NonMacroAttrKind, PartialRes, PerNS}; use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LOCAL_CRATE, LocalDefId}; @@ -4340,29 +4338,6 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { finalize, ) { Ok(Some(partial_res)) if let Some(res) = partial_res.full_res() => { - // if we also have an associated type that matches the ident, stash a suggestion - if let Some(items) = self.diag_metadata.current_trait_assoc_items - && let [Segment { ident, .. }] = path - && items.iter().any(|item| { - if let AssocItemKind::Type(alias) = &item.kind - && alias.ident == *ident - { - true - } else { - false - } - }) - { - let mut diag = self.r.tcx.dcx().struct_allow(""); - diag.span_suggestion_verbose( - path_span.shrink_to_lo(), - "there is an associated type with the same name", - "Self::", - Applicability::MaybeIncorrect, - ); - diag.stash(path_span, StashKey::AssociatedTypeSuggestion); - } - if source.is_expected(res) || res == Res::Err { partial_res } else { diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index bc45fc11e9bbe..fad61bb3d2aac 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -7,8 +7,8 @@ use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::unord::UnordSet; use rustc_errors::codes::*; use rustc_errors::{ - Applicability, Diag, ErrorGuaranteed, Level, MultiSpan, StashKey, StringPart, Suggestions, - pluralize, struct_span_code_err, + Applicability, Diag, ErrorGuaranteed, Level, MultiSpan, StashKey, StringPart, pluralize, + struct_span_code_err, }; use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId}; use rustc_hir::intravisit::Visitor; @@ -2446,15 +2446,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { obligation.cause.code(), ); self.suggest_unsized_bound_if_applicable(err, obligation); - if let Some(span) = err.span.primary_span() - && let Some(mut diag) = - self.dcx().steal_non_err(span, StashKey::AssociatedTypeSuggestion) - && let Suggestions::Enabled(ref mut s1) = err.suggestions - && let Suggestions::Enabled(ref mut s2) = diag.suggestions - { - s1.append(s2); - diag.cancel() - } } }