diff options
| author | bors <bors@rust-lang.org> | 2025-03-24 19:43:42 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-03-24 19:43:42 +0000 |
| commit | f8c27dfe1a2e7fb538fd91dad53de06992c7c967 (patch) | |
| tree | c453df3f38612e8b1cbd7714e78dffaadba831ff /compiler/rustc_resolve/src | |
| parent | 4510e86a41388733675465a8647d4235f3bf2023 (diff) | |
| parent | 4202bf96698125785719a061dec561a8ab70ba9c (diff) | |
| download | rust-f8c27dfe1a2e7fb538fd91dad53de06992c7c967.tar.gz rust-f8c27dfe1a2e7fb538fd91dad53de06992c7c967.zip | |
Auto merge of #138901 - matthiaskrgr:rollup-qbbanhr, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #138662 (Implement some basics in UEFI fs) - #138800 (remove remnants of const_box feature) - #138821 (match lowering cleanup: remove unused unsizing logic from `non_scalar_compare`) - #138864 (Rework `--print` options documentation) - #138868 (Add do_not_recommend typo help) - #138882 (`with_scope` is only ever used for ast modules) - #138894 (Update books) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_resolve/src')
| -rw-r--r-- | compiler/rustc_resolve/src/late.rs | 25 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/macros.rs | 14 |
2 files changed, 18 insertions, 21 deletions
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 6056a69ee71..e04d0083548 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -1544,20 +1544,17 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { ret } - fn with_scope<T>(&mut self, id: NodeId, f: impl FnOnce(&mut Self) -> T) -> T { - if let Some(module) = self.r.get_module(self.r.local_def_id(id).to_def_id()) { - // Move down in the graph. - let orig_module = replace(&mut self.parent_scope.module, module); - self.with_rib(ValueNS, RibKind::Module(module), |this| { - this.with_rib(TypeNS, RibKind::Module(module), |this| { - let ret = f(this); - this.parent_scope.module = orig_module; - ret - }) + fn with_mod_rib<T>(&mut self, id: NodeId, f: impl FnOnce(&mut Self) -> T) -> T { + let module = self.r.expect_module(self.r.local_def_id(id).to_def_id()); + // Move down in the graph. + let orig_module = replace(&mut self.parent_scope.module, module); + self.with_rib(ValueNS, RibKind::Module(module), |this| { + this.with_rib(TypeNS, RibKind::Module(module), |this| { + let ret = f(this); + this.parent_scope.module = orig_module; + ret }) - } else { - f(self) - } + }) } fn visit_generic_params(&mut self, params: &'ast [GenericParam], add_self_upper: bool) { @@ -2738,7 +2735,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { } ItemKind::Mod(..) => { - self.with_scope(item.id, |this| { + self.with_mod_rib(item.id, |this| { if mod_inner_docs { this.resolve_doc_links(&item.attrs, MaybeExported::Ok(item.id)); } diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index c4304a7a6df..34441d313f5 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -28,7 +28,7 @@ use rustc_session::lint::builtin::{ UNUSED_MACRO_RULES, UNUSED_MACROS, }; use rustc_session::parse::feature_err; -use rustc_span::edit_distance::edit_distance; +use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::edition::Edition; use rustc_span::hygiene::{self, AstPass, ExpnData, ExpnKind, LocalExpnId, MacroKind}; use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym}; @@ -652,13 +652,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { if res == Res::NonMacroAttr(NonMacroAttrKind::Tool) && let [namespace, attribute, ..] = &*path.segments && namespace.ident.name == sym::diagnostic - && !(attribute.ident.name == sym::on_unimplemented - || attribute.ident.name == sym::do_not_recommend) + && ![sym::on_unimplemented, sym::do_not_recommend].contains(&attribute.ident.name) { - let distance = - edit_distance(attribute.ident.name.as_str(), sym::on_unimplemented.as_str(), 5); - - let typo_name = distance.map(|_| sym::on_unimplemented); + let typo_name = find_best_match_for_name( + &[sym::on_unimplemented, sym::do_not_recommend], + attribute.ident.name, + Some(5), + ); self.tcx.sess.psess.buffer_lint( UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, |
