diff options
| author | trevyn <230691+trevyn@users.noreply.github.com> | 2024-02-14 12:42:32 -0800 |
|---|---|---|
| committer | trevyn <230691+trevyn@users.noreply.github.com> | 2024-02-14 12:42:32 -0800 |
| commit | 220e8a7484de6fd4e2679a3f6577ba879be73204 (patch) | |
| tree | 63d80b0d7d67860e89fc5a0e08fa8692558a62d4 /compiler/rustc_resolve/src | |
| parent | 502ce8287bc3c86dca07acc38c5ff9431a6097be (diff) | |
| download | rust-220e8a7484de6fd4e2679a3f6577ba879be73204.tar.gz rust-220e8a7484de6fd4e2679a3f6577ba879be73204.zip | |
For E0038, suggest associated type if available
Diffstat (limited to 'compiler/rustc_resolve/src')
| -rw-r--r-- | compiler/rustc_resolve/src/late.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 6bd221ff058..3ea4df1d2a4 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -18,6 +18,7 @@ use rustc_ast::*; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_errors::{ codes::*, struct_span_code_err, Applicability, DiagnosticArgValue, ErrCode, IntoDiagnosticArg, + StashKey, }; use rustc_hir::def::Namespace::{self, *}; use rustc_hir::def::{self, CtorKind, DefKind, LifetimeRes, NonMacroAttrKind, PartialRes, PerNS}; @@ -3890,6 +3891,23 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, '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.diagnostic_metadata.current_trait_assoc_items + && let [Segment { ident, .. }] = path + && items.iter().any(|item| { + item.ident == *ident && matches!(item.kind, AssocItemKind::Type(_)) + }) + { + 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 { |
