diff options
| author | bors <bors@rust-lang.org> | 2024-02-16 16:40:45 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-02-16 16:40:45 +0000 |
| commit | d2e8ecd8bd26a22111cdebfb813258450b07fbf0 (patch) | |
| tree | afe320e52e840709dbf49a51d1dee3ecd70b6469 /compiler/rustc_resolve/src/late.rs | |
| parent | ae9d7b0c6434b27e4e2effe8f05b16d37e7ef33f (diff) | |
| parent | f82875e2425c565db12643a562e60c0f08b28c87 (diff) | |
| download | rust-d2e8ecd8bd26a22111cdebfb813258450b07fbf0.tar.gz rust-d2e8ecd8bd26a22111cdebfb813258450b07fbf0.zip | |
Auto merge of #121188 - GuillaumeGomez:rollup-bejz7fq, r=GuillaumeGomez
Rollup of 6 pull requests Successful merges: - #119928 (suggest `into_iter()` when `Iterator` method called on `impl IntoIterator`) - #121020 (Avoid an ICE in diagnostics) - #121111 (For E0038, suggest associated type if available) - #121137 (Add clippy into the known `cfg` list) - #121179 (allow mutable references in const values when they point to no memory) - #121181 (Fix an ICE in the recursion lint) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_resolve/src/late.rs')
| -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 { |
