From 900607f49a60e76ca5ca793048723b9ccc2bcd63 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 30 Apr 2022 16:26:36 +0300 Subject: [PATCH 1/4] resolve: Turn `enum Finalize` into an optional struct --- .../rustc_resolve/src/build_reduced_graph.rs | 2 +- compiler/rustc_resolve/src/diagnostics.rs | 19 +++---- compiler/rustc_resolve/src/ident.rs | 14 ++--- compiler/rustc_resolve/src/imports.rs | 7 +-- compiler/rustc_resolve/src/late.rs | 55 ++++++++----------- .../rustc_resolve/src/late/diagnostics.rs | 8 +-- compiler/rustc_resolve/src/lib.rs | 44 +++++---------- compiler/rustc_resolve/src/macros.rs | 2 +- 8 files changed, 59 insertions(+), 92 deletions(-) diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 650a0dc82ce23..7485dd51863b7 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -298,7 +298,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { &segments, Some(TypeNS), parent_scope, - if finalize { Finalize::SimplePath(id, path.span) } else { Finalize::No }, + finalize.then(|| Finalize::new(id, path.span)), None, ) { PathResult::Module(ModuleOrUniformRoot::Module(module)) => { diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index e0a83ba8c0d4a..981d60db2f381 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -417,15 +417,12 @@ impl<'a> Resolver<'a> { crate fn lint_if_path_starts_with_module( &mut self, - finalize: Finalize, + finalize: Option, path: &[Segment], second_binding: Option<&NameBinding<'_>>, ) { - let (diag_id, diag_span) = match finalize { - Finalize::No => return, - Finalize::SimplePath(id, path_span) => (id, path_span), - Finalize::UsePath { root_id, root_span, .. } => (root_id, root_span), - Finalize::QPathTrait { qpath_id, qpath_span, .. } => (qpath_id, qpath_span), + let Some(Finalize { node_id, root_span, .. }) = finalize else { + return; }; let first_name = match path.get(0) { @@ -463,11 +460,11 @@ impl<'a> Resolver<'a> { } } - let diag = BuiltinLintDiagnostics::AbsPathWithModule(diag_span); + let diag = BuiltinLintDiagnostics::AbsPathWithModule(root_span); self.lint_buffer.buffer_lint_with_diagnostic( ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE, - diag_id, - diag_span, + node_id, + root_span, "absolute paths must start with `self`, `super`, \ `crate`, or an external crate name in the 2018 edition", diag, @@ -1873,7 +1870,7 @@ impl<'a> Resolver<'a> { ident, ns_to_try, parent_scope, - Finalize::No, + None, &ribs[ns_to_try], unusable_binding, ) { @@ -1921,7 +1918,7 @@ impl<'a> Resolver<'a> { ident, ValueNS, parent_scope, - Finalize::No, + None, &ribs[ValueNS], unusable_binding, ) diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 84fe0ec83d26c..48a052dd2f07d 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -279,7 +279,7 @@ impl<'a> Resolver<'a> { mut ident: Ident, ns: Namespace, parent_scope: &ParentScope<'a>, - finalize_full: Finalize, + finalize_full: Option, ribs: &[Rib<'a>], unusable_binding: Option<&'a NameBinding<'a>>, ) -> Option> { @@ -302,7 +302,7 @@ impl<'a> Resolver<'a> { let normalized_ident = Ident { span: normalized_span, ..ident }; // Walk backwards up the ribs in scope. - let finalize = finalize_full.path_span(); + let finalize = finalize_full.map(|finalize| finalize.path_span); let mut module = self.graph_root; for i in (0..ribs.len()).rev() { debug!("walk rib\n{:?}", ribs[i].bindings); @@ -354,7 +354,7 @@ impl<'a> Resolver<'a> { } self.early_resolve_ident_in_lexical_scope( orig_ident, - ScopeSet::Late(ns, module, finalize_full.node_id()), + ScopeSet::Late(ns, module, finalize_full.map(|finalize| finalize.node_id)), parent_scope, finalize, finalize.is_some(), @@ -1371,7 +1371,7 @@ impl<'a> Resolver<'a> { opt_ns: Option, // `None` indicates a module path in import parent_scope: &ParentScope<'a>, ) -> PathResult<'a> { - self.resolve_path_with_ribs(path, opt_ns, parent_scope, Finalize::No, None, None) + self.resolve_path_with_ribs(path, opt_ns, parent_scope, None, None, None) } #[tracing::instrument(level = "debug", skip(self))] @@ -1380,7 +1380,7 @@ impl<'a> Resolver<'a> { path: &[Segment], opt_ns: Option, // `None` indicates a module path in import parent_scope: &ParentScope<'a>, - finalize: Finalize, + finalize: Option, unusable_binding: Option<&'a NameBinding<'a>>, ) -> PathResult<'a> { self.resolve_path_with_ribs(path, opt_ns, parent_scope, finalize, None, unusable_binding) @@ -1391,13 +1391,13 @@ impl<'a> Resolver<'a> { path: &[Segment], opt_ns: Option, // `None` indicates a module path in import parent_scope: &ParentScope<'a>, - finalize_full: Finalize, + finalize_full: Option, ribs: Option<&PerNS>>>, unusable_binding: Option<&'a NameBinding<'a>>, ) -> PathResult<'a> { debug!("resolve_path(path={:?}, opt_ns={:?}, finalize={:?})", path, opt_ns, finalize_full); - let finalize = finalize_full.path_span(); + let finalize = finalize_full.map(|finalize| finalize.path_span); let mut module = None; let mut allow_super = true; let mut second_binding = None; diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 01dc727737a5a..3d6ad8a42b899 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -594,11 +594,8 @@ impl<'a, 'b> ImportResolver<'a, 'b> { _ => None, }; let prev_ambiguity_errors_len = self.r.ambiguity_errors.len(); - let finalize = Finalize::UsePath { - root_id: import.root_id, - root_span: import.root_span, - path_span: import.span, - }; + let finalize = + Some(Finalize::with_root_span(import.root_id, import.span, import.root_span)); let path_res = self.r.resolve_path( &import.module_path, None, diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 53bd589fdcde1..106c6a2d4ec3e 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -578,7 +578,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { .resolve_ident_in_lexical_scope( self_ty, TypeNS, - Finalize::SimplePath(ty.id, ty.span), + Some(Finalize::new(ty.id, ty.span)), None, ) .map_or(Res::Err, |d| d.res()); @@ -958,7 +958,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { ident, ns, &self.parent_scope, - Finalize::No, + None, &self.ribs[ns], None, ) @@ -968,7 +968,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { &mut self, ident: Ident, ns: Namespace, - finalize: Finalize, + finalize: Option, unusable_binding: Option<&'a NameBinding<'a>>, ) -> Option> { self.r.resolve_ident_in_lexical_scope( @@ -985,7 +985,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { &mut self, path: &[Segment], opt_ns: Option, // `None` indicates a module path in import - finalize: Finalize, + finalize: Option, ) -> PathResult<'a> { self.r.resolve_path_with_ribs( path, @@ -1299,11 +1299,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { partial_res: PartialRes, path: &[Segment], source: PathSource<'_>, - finalize: Finalize, + path_span: Span, ) { - let Some(path_span) = finalize.path_span() else { - return; - }; let proj_start = path.len() - partial_res.unresolved_segments(); for (i, segment) in path.iter().enumerate() { if segment.has_lifetime_args { @@ -1576,8 +1573,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { report_error(self, ns); } Some(LexicalScopeBinding::Item(binding)) => { - if let Some(LexicalScopeBinding::Res(..)) = self - .resolve_ident_in_lexical_scope(ident, ns, Finalize::No, Some(binding)) + if let Some(LexicalScopeBinding::Res(..)) = + self.resolve_ident_in_lexical_scope(ident, ns, None, Some(binding)) { report_error(self, ns); } @@ -1979,7 +1976,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { None, &path, PathSource::Trait(AliasPossibility::No), - Finalize::SimplePath(trait_ref.ref_id, trait_ref.path.span), + Finalize::new(trait_ref.ref_id, trait_ref.path.span), ); if let Some(def_id) = res.base_res().opt_def_id() { new_id = Some(def_id); @@ -2653,7 +2650,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { qself, &Segment::from_path(path), source, - Finalize::SimplePath(id, path.span), + Finalize::new(id, path.span), ); } @@ -2672,8 +2669,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { ); let ns = source.namespace(); - let (id, path_span) = - finalize.node_id_and_path_span().expect("unexpected speculative resolution"); + let Finalize { node_id, path_span, .. } = finalize; let report_errors = |this: &mut Self, res: Option| { if this.should_report_errs() { let (err, candidates) = @@ -2787,7 +2783,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { if ns == ValueNS { let item_name = path.last().unwrap().ident; let traits = self.traits_in_scope(item_name, ns); - self.r.trait_map.insert(id, traits); + self.r.trait_map.insert(node_id, traits); } if PrimTy::from_name(path[0].ident.name).is_some() { @@ -2796,7 +2792,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { std_path.push(Segment::from_ident(Ident::with_dummy_span(sym::std))); std_path.extend(path); if let PathResult::Module(_) | PathResult::NonModule(_) = - self.resolve_path(&std_path, Some(ns), Finalize::No) + self.resolve_path(&std_path, Some(ns), None) { // Check if we wrote `str::from_utf8` instead of `std::str::from_utf8` let item_span = @@ -2823,8 +2819,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { if !matches!(source, PathSource::TraitItem(..)) { // Avoid recording definition of `A::B` in `::B::C`. - self.r.record_partial_res(id, partial_res); - self.resolve_elided_lifetimes_in_path(id, partial_res, path, source, finalize); + self.r.record_partial_res(node_id, partial_res); + self.resolve_elided_lifetimes_in_path(node_id, partial_res, path, source, path_span); } partial_res @@ -2932,21 +2928,12 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { // the trait (the slice upto and including // `qself.position`). And then we recursively resolve that, // but with `qself` set to `None`. - // - // However, setting `qself` to none (but not changing the - // span) loses the information about where this path - // *actually* appears, so for the purposes of the crate - // lint we pass along information that this is the trait - // name from a fully qualified path, and this also - // contains the full span (the `Finalize::QPathTrait`). let ns = if qself.position + 1 == path.len() { ns } else { TypeNS }; let partial_res = self.smart_resolve_path_fragment( None, &path[..=qself.position], PathSource::TraitItem(ns), - finalize.node_id_and_path_span().map_or(Finalize::No, |(qpath_id, path_span)| { - Finalize::QPathTrait { qpath_id, qpath_span: qself.path_span, path_span } - }), + Finalize::with_root_span(finalize.node_id, finalize.path_span, qself.path_span), ); // The remaining segments (the `C` in our example) will @@ -2958,7 +2945,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { ))); } - let result = match self.resolve_path(&path, Some(ns), finalize) { + let result = match self.resolve_path(&path, Some(ns), Some(finalize)) { PathResult::NonModule(path_res) => path_res, PathResult::Module(ModuleOrUniformRoot::Module(module)) if !module.is_normal() => { PartialRes::new(module.res().unwrap()) @@ -2996,10 +2983,9 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { && result.base_res() != Res::Err && path[0].ident.name != kw::PathRoot && path[0].ident.name != kw::DollarCrate - && let Some((id, path_span)) = finalize.node_id_and_path_span() { let unqualified_result = { - match self.resolve_path(&[*path.last().unwrap()], Some(ns), Finalize::No) { + match self.resolve_path(&[*path.last().unwrap()], Some(ns), None) { PathResult::NonModule(path_res) => path_res.base_res(), PathResult::Module(ModuleOrUniformRoot::Module(module)) => { module.res().unwrap() @@ -3009,7 +2995,12 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { }; if result.base_res() == unqualified_result { let lint = lint::builtin::UNUSED_QUALIFICATIONS; - self.r.lint_buffer.buffer_lint(lint, id, path_span, "unnecessary qualification") + self.r.lint_buffer.buffer_lint( + lint, + finalize.node_id, + finalize.path_span, + "unnecessary qualification", + ) } } diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index a5243bf8ac3f8..3076cc1131700 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -3,7 +3,7 @@ use crate::late::lifetimes::{ElisionFailureInfo, LifetimeContext}; use crate::late::{AliasPossibility, LateResolutionVisitor, RibKind}; use crate::late::{LifetimeBinderKind, LifetimeRibKind}; use crate::path_names_to_string; -use crate::{Finalize, Module, ModuleKind, ModuleOrUniformRoot}; +use crate::{Module, ModuleKind, ModuleOrUniformRoot}; use crate::{PathResult, PathSource, Segment}; use rustc_ast::visit::FnKind; @@ -189,7 +189,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { (String::new(), "the crate root".to_string()) } else { let mod_path = &path[..path.len() - 1]; - let mod_prefix = match self.resolve_path(mod_path, Some(TypeNS), Finalize::No) { + let mod_prefix = match self.resolve_path(mod_path, Some(TypeNS), None) { PathResult::Module(ModuleOrUniformRoot::Module(module)) => module.res(), _ => None, } @@ -648,7 +648,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { if let crate::PathSource::TraitItem(_) = source { let mod_path = &path[..path.len() - 1]; if let PathResult::Module(ModuleOrUniformRoot::Module(module)) = - self.resolve_path(mod_path, None, Finalize::No) + self.resolve_path(mod_path, None, None) { let resolutions = self.r.resolutions(module).borrow(); let targets: Vec<_> = @@ -1362,7 +1362,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { // Search in module. let mod_path = &path[..path.len() - 1]; if let PathResult::Module(ModuleOrUniformRoot::Module(module)) = - self.resolve_path(mod_path, Some(TypeNS), Finalize::No) + self.resolve_path(mod_path, Some(TypeNS), None) { self.r.add_module_candidates(module, &mut names, &filter_fn); } diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index dbc4f337ad3b5..330636fe54326 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -2044,42 +2044,24 @@ fn module_to_string(module: Module<'_>) -> Option { } #[derive(Copy, Clone, Debug)] -enum Finalize { - /// Do not issue the lint. - No, - - /// This lint applies to some arbitrary path; e.g., `impl ::foo::Bar`. - /// In this case, we can take the span of that path. - SimplePath(NodeId, Span), - - /// This lint comes from a `use` statement. In this case, what we - /// care about really is the *root* `use` statement; e.g., if we - /// have nested things like `use a::{b, c}`, we care about the - /// `use a` part. - UsePath { root_id: NodeId, root_span: Span, path_span: Span }, - - /// This is the "trait item" from a fully qualified path. For example, - /// we might be resolving `X::Y::Z` from a path like `::Z`. - /// The `path_span` is the span of the to the trait itself (`X::Y`). - QPathTrait { qpath_id: NodeId, qpath_span: Span, path_span: Span }, +struct Finalize { + /// Node ID for linting. + node_id: NodeId, + /// Span of the whole path or some its characteristic fragment. + /// E.g. span of `b` in `foo::{a, b, c}`, or full span for regular paths. + path_span: Span, + /// Span of the path start, suitable for prepending something to to it. + /// E.g. span of `foo` in `foo::{a, b, c}`, or full span for regular paths. + root_span: Span, } impl Finalize { - fn node_id_and_path_span(&self) -> Option<(NodeId, Span)> { - match *self { - Finalize::No => None, - Finalize::SimplePath(id, path_span) - | Finalize::UsePath { root_id: id, path_span, .. } - | Finalize::QPathTrait { qpath_id: id, path_span, .. } => Some((id, path_span)), - } - } - - fn node_id(&self) -> Option { - self.node_id_and_path_span().map(|(id, _)| id) + fn new(node_id: NodeId, path_span: Span) -> Finalize { + Finalize { node_id, path_span, root_span: path_span } } - fn path_span(&self) -> Option { - self.node_id_and_path_span().map(|(_, path_span)| path_span) + fn with_root_span(node_id: NodeId, path_span: Span, root_span: Span) -> Finalize { + Finalize { node_id, path_span, root_span } } } diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index 01f0b11f1ac3b..e1aa227656695 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -673,7 +673,7 @@ impl<'a> Resolver<'a> { &path, Some(MacroNS), &parent_scope, - Finalize::SimplePath(ast::CRATE_NODE_ID, path_span), + Some(Finalize::new(ast::CRATE_NODE_ID, path_span)), None, ) { PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 => { From ffedcec4e8c9de11b8195074f59d014511bcb422 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 30 Apr 2022 16:57:18 +0300 Subject: [PATCH 2/4] resolve: Pass full `Finalize` in nearly all cases --- compiler/rustc_resolve/src/ident.rs | 30 +++++++++++++-------------- compiler/rustc_resolve/src/imports.rs | 4 ++-- compiler/rustc_resolve/src/macros.rs | 4 ++-- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 48a052dd2f07d..0f1c4f38bc74f 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -279,7 +279,7 @@ impl<'a> Resolver<'a> { mut ident: Ident, ns: Namespace, parent_scope: &ParentScope<'a>, - finalize_full: Option, + finalize: Option, ribs: &[Rib<'a>], unusable_binding: Option<&'a NameBinding<'a>>, ) -> Option> { @@ -302,7 +302,6 @@ impl<'a> Resolver<'a> { let normalized_ident = Ident { span: normalized_span, ..ident }; // Walk backwards up the ribs in scope. - let finalize = finalize_full.map(|finalize| finalize.path_span); let mut module = self.graph_root; for i in (0..ribs.len()).rev() { debug!("walk rib\n{:?}", ribs[i].bindings); @@ -316,7 +315,7 @@ impl<'a> Resolver<'a> { i, rib_ident, *res, - finalize, + finalize.map(|finalize| finalize.path_span), *original_rib_ident_def, ribs, ))); @@ -354,7 +353,7 @@ impl<'a> Resolver<'a> { } self.early_resolve_ident_in_lexical_scope( orig_ident, - ScopeSet::Late(ns, module, finalize_full.map(|finalize| finalize.node_id)), + ScopeSet::Late(ns, module, finalize.map(|finalize| finalize.node_id)), parent_scope, finalize, finalize.is_some(), @@ -376,7 +375,7 @@ impl<'a> Resolver<'a> { orig_ident: Ident, scope_set: ScopeSet<'a>, parent_scope: &ParentScope<'a>, - finalize: Option, + finalize: Option, force: bool, last_import_segment: bool, unusable_binding: Option<&'a NameBinding<'a>>, @@ -742,7 +741,7 @@ impl<'a> Resolver<'a> { ident: Ident, ns: Namespace, parent_scope: &ParentScope<'a>, - finalize: Option, + finalize: Option, // We are resolving a last import segment during import validation. last_import_segment: bool, // This binding should be ignored during in-module resolution, so that we don't get @@ -768,7 +767,7 @@ impl<'a> Resolver<'a> { mut ident: Ident, ns: Namespace, parent_scope: &ParentScope<'a>, - finalize: Option, + finalize: Option, last_import_segment: bool, unusable_binding: Option<&'a NameBinding<'a>>, ) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> { @@ -808,7 +807,7 @@ impl<'a> Resolver<'a> { ident: Ident, ns: Namespace, parent_scope: &ParentScope<'a>, - finalize: Option, + finalize: Option, last_import_segment: bool, unusable_binding: Option<&'a NameBinding<'a>>, ) -> Result<&'a NameBinding<'a>, Determinacy> { @@ -835,7 +834,7 @@ impl<'a> Resolver<'a> { ns: Namespace, parent_scope: &ParentScope<'a>, restricted_shadowing: bool, - finalize: Option, + finalize: Option, last_import_segment: bool, unusable_binding: Option<&'a NameBinding<'a>>, ) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> { @@ -901,7 +900,7 @@ impl<'a> Resolver<'a> { let resolution = self.resolution(module, key).try_borrow_mut().map_err(|_| (Determined, Weak::No))?; // This happens when there is a cycle of imports. - if let Some(path_span) = finalize { + if let Some(Finalize { path_span, .. }) = finalize { // If the primary binding is unusable, search further and return the shadowed glob // binding if it exists. What we really want here is having two separate scopes in // a module - one for non-globs and one for globs, but until that's done use this @@ -1391,13 +1390,12 @@ impl<'a> Resolver<'a> { path: &[Segment], opt_ns: Option, // `None` indicates a module path in import parent_scope: &ParentScope<'a>, - finalize_full: Option, + finalize: Option, ribs: Option<&PerNS>>>, unusable_binding: Option<&'a NameBinding<'a>>, ) -> PathResult<'a> { - debug!("resolve_path(path={:?}, opt_ns={:?}, finalize={:?})", path, opt_ns, finalize_full); + debug!("resolve_path(path={:?}, opt_ns={:?}, finalize={:?})", path, opt_ns, finalize); - let finalize = finalize_full.map(|finalize| finalize.path_span); let mut module = None; let mut allow_super = true; let mut second_binding = None; @@ -1507,7 +1505,7 @@ impl<'a> Resolver<'a> { ident, ns, parent_scope, - finalize_full, + finalize, &ribs[ns], unusable_binding, ) { @@ -1566,7 +1564,7 @@ impl<'a> Resolver<'a> { } else if res == Res::Err { return PathResult::NonModule(PartialRes::new(Res::Err)); } else if opt_ns.is_some() && (is_last || maybe_assoc) { - self.lint_if_path_starts_with_module(finalize_full, path, second_binding); + self.lint_if_path_starts_with_module(finalize, path, second_binding); return PathResult::NonModule(PartialRes::with_unresolved_segments( res, path.len() - i - 1, @@ -1609,7 +1607,7 @@ impl<'a> Resolver<'a> { } } - self.lint_if_path_starts_with_module(finalize_full, path, second_binding); + self.lint_if_path_starts_with_module(finalize, path, second_binding); PathResult::Module(match module { Some(module) => module, diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 3d6ad8a42b899..b5b7f1418f1cf 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -717,7 +717,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { ident, ns, &import.parent_scope, - Some(import.span), + finalize, true, target_bindings[ns].get(), ); @@ -778,7 +778,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { ident, ns, &import.parent_scope, - Some(import.span), + finalize, false, None, ); diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index e1aa227656695..815bff5b23e74 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -708,7 +708,7 @@ impl<'a> Resolver<'a> { ident, ScopeSet::Macro(kind), &parent_scope, - Some(ident.span), + Some(Finalize::new(ast::CRATE_NODE_ID, ident.span)), true, false, None, @@ -751,7 +751,7 @@ impl<'a> Resolver<'a> { ident, ScopeSet::Macro(MacroKind::Attr), &parent_scope, - Some(ident.span), + Some(Finalize::new(ast::CRATE_NODE_ID, ident.span)), true, false, None, From f0e0434feb7ac3011e4f3ae2966cd0cabe9c4ea1 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 30 Apr 2022 17:31:44 +0300 Subject: [PATCH 3/4] resolve: Merge `last_import_segment` into `Finalize` --- compiler/rustc_resolve/src/diagnostics.rs | 3 --- compiler/rustc_resolve/src/ident.rs | 30 ++++------------------- compiler/rustc_resolve/src/imports.rs | 17 +++++-------- compiler/rustc_resolve/src/lib.rs | 7 ++++-- compiler/rustc_resolve/src/macros.rs | 3 --- 5 files changed, 16 insertions(+), 44 deletions(-) diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 981d60db2f381..8cb5d815f0d2c 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1500,7 +1500,6 @@ impl<'a> Resolver<'a> { &parent_scope, None, false, - false, None, ) { let desc = match binding.res() { @@ -1860,7 +1859,6 @@ impl<'a> Resolver<'a> { ns_to_try, parent_scope, None, - false, unusable_binding, ).ok() } else if let Some(ribs) = ribs @@ -1886,7 +1884,6 @@ impl<'a> Resolver<'a> { parent_scope, None, false, - false, unusable_binding, ).ok() }; diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 0f1c4f38bc74f..0ca04d4c8934c 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -343,7 +343,6 @@ impl<'a> Resolver<'a> { ns, parent_scope, finalize, - false, unusable_binding, ); if let Ok(binding) = item { @@ -357,7 +356,6 @@ impl<'a> Resolver<'a> { parent_scope, finalize, finalize.is_some(), - false, unusable_binding, ) .ok() @@ -377,7 +375,6 @@ impl<'a> Resolver<'a> { parent_scope: &ParentScope<'a>, finalize: Option, force: bool, - last_import_segment: bool, unusable_binding: Option<&'a NameBinding<'a>>, ) -> Result<&'a NameBinding<'a>, Determinacy> { bitflags::bitflags! { @@ -498,7 +495,6 @@ impl<'a> Resolver<'a> { ns, parent_scope, finalize, - last_import_segment, unusable_binding, ); match binding { @@ -521,7 +517,6 @@ impl<'a> Resolver<'a> { adjusted_parent_scope, !matches!(scope_set, ScopeSet::Late(..)), finalize, - last_import_segment, unusable_binding, ); match binding { @@ -607,7 +602,6 @@ impl<'a> Resolver<'a> { ns, parent_scope, None, - last_import_segment, unusable_binding, ) { if use_prelude || this.is_builtin_macro(binding.res()) { @@ -730,7 +724,7 @@ impl<'a> Resolver<'a> { ns: Namespace, parent_scope: &ParentScope<'a>, ) -> Result<&'a NameBinding<'a>, Determinacy> { - self.resolve_ident_in_module_ext(module, ident, ns, parent_scope, None, false, None) + self.resolve_ident_in_module_ext(module, ident, ns, parent_scope, None, None) .map_err(|(determinacy, _)| determinacy) } @@ -742,8 +736,6 @@ impl<'a> Resolver<'a> { ns: Namespace, parent_scope: &ParentScope<'a>, finalize: Option, - // We are resolving a last import segment during import validation. - last_import_segment: bool, // This binding should be ignored during in-module resolution, so that we don't get // "self-confirming" import resolutions during import validation. unusable_binding: Option<&'a NameBinding<'a>>, @@ -754,7 +746,6 @@ impl<'a> Resolver<'a> { ns, parent_scope, finalize, - last_import_segment, unusable_binding, ) .map_err(|(determinacy, _)| determinacy) @@ -768,7 +759,6 @@ impl<'a> Resolver<'a> { ns: Namespace, parent_scope: &ParentScope<'a>, finalize: Option, - last_import_segment: bool, unusable_binding: Option<&'a NameBinding<'a>>, ) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> { let tmp_parent_scope; @@ -795,7 +785,6 @@ impl<'a> Resolver<'a> { adjusted_parent_scope, false, finalize, - last_import_segment, unusable_binding, ) } @@ -808,7 +797,6 @@ impl<'a> Resolver<'a> { ns: Namespace, parent_scope: &ParentScope<'a>, finalize: Option, - last_import_segment: bool, unusable_binding: Option<&'a NameBinding<'a>>, ) -> Result<&'a NameBinding<'a>, Determinacy> { self.resolve_ident_in_module_unadjusted_ext( @@ -818,7 +806,6 @@ impl<'a> Resolver<'a> { parent_scope, false, finalize, - last_import_segment, unusable_binding, ) .map_err(|(determinacy, _)| determinacy) @@ -835,7 +822,6 @@ impl<'a> Resolver<'a> { parent_scope: &ParentScope<'a>, restricted_shadowing: bool, finalize: Option, - last_import_segment: bool, unusable_binding: Option<&'a NameBinding<'a>>, ) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> { let module = match module { @@ -848,7 +834,6 @@ impl<'a> Resolver<'a> { parent_scope, finalize, finalize.is_some(), - last_import_segment, unusable_binding, ); return binding.map_err(|determinacy| (determinacy, Weak::No)); @@ -889,7 +874,6 @@ impl<'a> Resolver<'a> { parent_scope, finalize, finalize.is_some(), - last_import_segment, unusable_binding, ); return binding.map_err(|determinacy| (determinacy, Weak::No)); @@ -900,7 +884,7 @@ impl<'a> Resolver<'a> { let resolution = self.resolution(module, key).try_borrow_mut().map_err(|_| (Determined, Weak::No))?; // This happens when there is a cycle of imports. - if let Some(Finalize { path_span, .. }) = finalize { + if let Some(Finalize { path_span, report_private, .. }) = finalize { // If the primary binding is unusable, search further and return the shadowed glob // binding if it exists. What we really want here is having two separate scopes in // a module - one for non-globs and one for globs, but until that's done use this @@ -921,14 +905,14 @@ impl<'a> Resolver<'a> { }; if !self.is_accessible_from(binding.vis, parent_scope.module) { - if last_import_segment { - return Err((Determined, Weak::No)); - } else { + if report_private { self.privacy_errors.push(PrivacyError { ident, binding, dedup_span: path_span, }); + } else { + return Err((Determined, Weak::No)); } } @@ -995,7 +979,6 @@ impl<'a> Resolver<'a> { ns, &single_import.parent_scope, None, - last_import_segment, unusable_binding, ) { Err(Determined) => continue, @@ -1072,7 +1055,6 @@ impl<'a> Resolver<'a> { ns, adjusted_parent_scope, None, - last_import_segment, unusable_binding, ); @@ -1495,7 +1477,6 @@ impl<'a> Resolver<'a> { ns, parent_scope, finalize, - false, unusable_binding, ) } else if let Some(ribs) = ribs @@ -1523,7 +1504,6 @@ impl<'a> Resolver<'a> { parent_scope, finalize, finalize.is_some(), - false, unusable_binding, ) }; diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index b5b7f1418f1cf..cae9b1498c287 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -545,7 +545,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> { ns, &import.parent_scope, None, - false, None, ); import.vis.set(orig_vis); @@ -594,13 +593,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> { _ => None, }; let prev_ambiguity_errors_len = self.r.ambiguity_errors.len(); - let finalize = - Some(Finalize::with_root_span(import.root_id, import.span, import.root_span)); + let finalize = Finalize::with_root_span(import.root_id, import.span, import.root_span); let path_res = self.r.resolve_path( &import.module_path, None, &import.parent_scope, - finalize, + Some(finalize), unusable_binding, ); let no_ambiguity = self.r.ambiguity_errors.len() == prev_ambiguity_errors_len; @@ -682,7 +680,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { // 2 segments, so the `resolve_path` above won't trigger it. let mut full_path = import.module_path.clone(); full_path.push(Segment::from_ident(Ident::empty())); - self.r.lint_if_path_starts_with_module(finalize, &full_path, None); + self.r.lint_if_path_starts_with_module(Some(finalize), &full_path, None); } if let ModuleOrUniformRoot::Module(module) = module { @@ -717,8 +715,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { ident, ns, &import.parent_scope, - finalize, - true, + Some(Finalize { report_private: false, ..finalize }), target_bindings[ns].get(), ); import.vis.set(orig_vis); @@ -778,8 +775,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { ident, ns, &import.parent_scope, - finalize, - false, + Some(finalize), None, ); if binding.is_ok() { @@ -945,7 +941,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { full_path.push(Segment::from_ident(ident)); self.r.per_ns(|this, ns| { if let Ok(binding) = source_bindings[ns].get() { - this.lint_if_path_starts_with_module(finalize, &full_path, Some(binding)); + this.lint_if_path_starts_with_module(Some(finalize), &full_path, Some(binding)); } }); } @@ -1000,7 +996,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> { &import.parent_scope, None, false, - false, target_bindings[ns].get(), ) { Ok(other_binding) => { diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 330636fe54326..2e625fc1b4f7b 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -2053,15 +2053,18 @@ struct Finalize { /// Span of the path start, suitable for prepending something to to it. /// E.g. span of `foo` in `foo::{a, b, c}`, or full span for regular paths. root_span: Span, + /// Whether to report privacy errors or silently return "no resolution" for them, + /// similarly to speculative resolution. + report_private: bool, } impl Finalize { fn new(node_id: NodeId, path_span: Span) -> Finalize { - Finalize { node_id, path_span, root_span: path_span } + Finalize::with_root_span(node_id, path_span, path_span) } fn with_root_span(node_id: NodeId, path_span: Span, root_span: Span) -> Finalize { - Finalize { node_id, path_span, root_span } + Finalize { node_id, path_span, root_span, report_private: true } } } diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index 815bff5b23e74..19a9c1b99fc47 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -604,7 +604,6 @@ impl<'a> Resolver<'a> { parent_scope, None, force, - false, None, ); if let Err(Determinacy::Undetermined) = binding { @@ -710,7 +709,6 @@ impl<'a> Resolver<'a> { &parent_scope, Some(Finalize::new(ast::CRATE_NODE_ID, ident.span)), true, - false, None, ) { Ok(binding) => { @@ -753,7 +751,6 @@ impl<'a> Resolver<'a> { &parent_scope, Some(Finalize::new(ast::CRATE_NODE_ID, ident.span)), true, - false, None, ); } From 7841247ca9d344ee253a07f356348445ec2965e9 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 30 Apr 2022 18:01:01 +0300 Subject: [PATCH 4/4] resolve: Rename `unusable_binding` to `ignore_binding` --- compiler/rustc_resolve/src/diagnostics.rs | 10 +-- compiler/rustc_resolve/src/ident.rs | 77 ++++++++++------------- compiler/rustc_resolve/src/imports.rs | 4 +- compiler/rustc_resolve/src/late.rs | 4 +- 4 files changed, 41 insertions(+), 54 deletions(-) diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 8cb5d815f0d2c..7d40ecb18b747 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1807,7 +1807,7 @@ impl<'a> Resolver<'a> { opt_ns: Option, // `None` indicates a module path in import parent_scope: &ParentScope<'a>, ribs: Option<&PerNS>>>, - unusable_binding: Option<&'a NameBinding<'a>>, + ignore_binding: Option<&'a NameBinding<'a>>, module: Option>, i: usize, ident: Ident, @@ -1859,7 +1859,7 @@ impl<'a> Resolver<'a> { ns_to_try, parent_scope, None, - unusable_binding, + ignore_binding, ).ok() } else if let Some(ribs) = ribs && let Some(TypeNS | ValueNS) = opt_ns @@ -1870,7 +1870,7 @@ impl<'a> Resolver<'a> { parent_scope, None, &ribs[ns_to_try], - unusable_binding, + ignore_binding, ) { // we found a locally-imported or available item/module Some(LexicalScopeBinding::Item(binding)) => Some(binding), @@ -1884,7 +1884,7 @@ impl<'a> Resolver<'a> { parent_scope, None, false, - unusable_binding, + ignore_binding, ).ok() }; if let Some(binding) = binding { @@ -1917,7 +1917,7 @@ impl<'a> Resolver<'a> { parent_scope, None, &ribs[ValueNS], - unusable_binding, + ignore_binding, ) } else { None diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 0ca04d4c8934c..18ce359524da2 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -281,7 +281,7 @@ impl<'a> Resolver<'a> { parent_scope: &ParentScope<'a>, finalize: Option, ribs: &[Rib<'a>], - unusable_binding: Option<&'a NameBinding<'a>>, + ignore_binding: Option<&'a NameBinding<'a>>, ) -> Option> { assert!(ns == TypeNS || ns == ValueNS); let orig_ident = ident; @@ -343,7 +343,7 @@ impl<'a> Resolver<'a> { ns, parent_scope, finalize, - unusable_binding, + ignore_binding, ); if let Ok(binding) = item { // The ident resolves to an item. @@ -356,7 +356,7 @@ impl<'a> Resolver<'a> { parent_scope, finalize, finalize.is_some(), - unusable_binding, + ignore_binding, ) .ok() .map(LexicalScopeBinding::Item) @@ -375,7 +375,7 @@ impl<'a> Resolver<'a> { parent_scope: &ParentScope<'a>, finalize: Option, force: bool, - unusable_binding: Option<&'a NameBinding<'a>>, + ignore_binding: Option<&'a NameBinding<'a>>, ) -> Result<&'a NameBinding<'a>, Determinacy> { bitflags::bitflags! { struct Flags: u8 { @@ -495,7 +495,7 @@ impl<'a> Resolver<'a> { ns, parent_scope, finalize, - unusable_binding, + ignore_binding, ); match binding { Ok(binding) => Ok((binding, Flags::MODULE | Flags::MISC_SUGGEST_CRATE)), @@ -517,7 +517,7 @@ impl<'a> Resolver<'a> { adjusted_parent_scope, !matches!(scope_set, ScopeSet::Late(..)), finalize, - unusable_binding, + ignore_binding, ); match binding { Ok(binding) => { @@ -602,7 +602,7 @@ impl<'a> Resolver<'a> { ns, parent_scope, None, - unusable_binding, + ignore_binding, ) { if use_prelude || this.is_builtin_macro(binding.res()) { result = Ok((binding, Flags::MISC_FROM_PRELUDE)); @@ -736,19 +736,10 @@ impl<'a> Resolver<'a> { ns: Namespace, parent_scope: &ParentScope<'a>, finalize: Option, - // This binding should be ignored during in-module resolution, so that we don't get - // "self-confirming" import resolutions during import validation. - unusable_binding: Option<&'a NameBinding<'a>>, + ignore_binding: Option<&'a NameBinding<'a>>, ) -> Result<&'a NameBinding<'a>, Determinacy> { - self.resolve_ident_in_module_ext( - module, - ident, - ns, - parent_scope, - finalize, - unusable_binding, - ) - .map_err(|(determinacy, _)| determinacy) + self.resolve_ident_in_module_ext(module, ident, ns, parent_scope, finalize, ignore_binding) + .map_err(|(determinacy, _)| determinacy) } #[tracing::instrument(level = "debug", skip(self))] @@ -759,7 +750,7 @@ impl<'a> Resolver<'a> { ns: Namespace, parent_scope: &ParentScope<'a>, finalize: Option, - unusable_binding: Option<&'a NameBinding<'a>>, + ignore_binding: Option<&'a NameBinding<'a>>, ) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> { let tmp_parent_scope; let mut adjusted_parent_scope = parent_scope; @@ -785,7 +776,7 @@ impl<'a> Resolver<'a> { adjusted_parent_scope, false, finalize, - unusable_binding, + ignore_binding, ) } @@ -797,7 +788,7 @@ impl<'a> Resolver<'a> { ns: Namespace, parent_scope: &ParentScope<'a>, finalize: Option, - unusable_binding: Option<&'a NameBinding<'a>>, + ignore_binding: Option<&'a NameBinding<'a>>, ) -> Result<&'a NameBinding<'a>, Determinacy> { self.resolve_ident_in_module_unadjusted_ext( module, @@ -806,7 +797,7 @@ impl<'a> Resolver<'a> { parent_scope, false, finalize, - unusable_binding, + ignore_binding, ) .map_err(|(determinacy, _)| determinacy) } @@ -822,7 +813,9 @@ impl<'a> Resolver<'a> { parent_scope: &ParentScope<'a>, restricted_shadowing: bool, finalize: Option, - unusable_binding: Option<&'a NameBinding<'a>>, + // This binding should be ignored during in-module resolution, so that we don't get + // "self-confirming" import resolutions during import validation and checking. + ignore_binding: Option<&'a NameBinding<'a>>, ) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> { let module = match module { ModuleOrUniformRoot::Module(module) => module, @@ -834,7 +827,7 @@ impl<'a> Resolver<'a> { parent_scope, finalize, finalize.is_some(), - unusable_binding, + ignore_binding, ); return binding.map_err(|determinacy| (determinacy, Weak::No)); } @@ -874,7 +867,7 @@ impl<'a> Resolver<'a> { parent_scope, finalize, finalize.is_some(), - unusable_binding, + ignore_binding, ); return binding.map_err(|determinacy| (determinacy, Weak::No)); } @@ -891,12 +884,8 @@ impl<'a> Resolver<'a> { // hack to avoid inconsistent resolution ICEs during import validation. let binding = [resolution.binding, resolution.shadowed_glob] .into_iter() - .filter_map(|binding| match (binding, unusable_binding) { - (Some(binding), Some(unusable_binding)) - if ptr::eq(binding, unusable_binding) => - { - None - } + .filter_map(|binding| match (binding, ignore_binding) { + (Some(binding), Some(ignored)) if ptr::eq(binding, ignored) => None, _ => binding, }) .next(); @@ -943,10 +932,8 @@ impl<'a> Resolver<'a> { } let check_usable = |this: &mut Self, binding: &'a NameBinding<'a>| { - if let Some(unusable_binding) = unusable_binding { - if ptr::eq(binding, unusable_binding) { - return Err((Determined, Weak::No)); - } + if let Some(ignored) = ignore_binding && ptr::eq(binding, ignored) { + return Err((Determined, Weak::No)); } let usable = this.is_accessible_from(binding.vis, parent_scope.module); if usable { Ok(binding) } else { Err((Determined, Weak::No)) } @@ -979,7 +966,7 @@ impl<'a> Resolver<'a> { ns, &single_import.parent_scope, None, - unusable_binding, + ignore_binding, ) { Err(Determined) => continue, Ok(binding) @@ -1055,7 +1042,7 @@ impl<'a> Resolver<'a> { ns, adjusted_parent_scope, None, - unusable_binding, + ignore_binding, ); match result { @@ -1362,9 +1349,9 @@ impl<'a> Resolver<'a> { opt_ns: Option, // `None` indicates a module path in import parent_scope: &ParentScope<'a>, finalize: Option, - unusable_binding: Option<&'a NameBinding<'a>>, + ignore_binding: Option<&'a NameBinding<'a>>, ) -> PathResult<'a> { - self.resolve_path_with_ribs(path, opt_ns, parent_scope, finalize, None, unusable_binding) + self.resolve_path_with_ribs(path, opt_ns, parent_scope, finalize, None, ignore_binding) } crate fn resolve_path_with_ribs( @@ -1374,7 +1361,7 @@ impl<'a> Resolver<'a> { parent_scope: &ParentScope<'a>, finalize: Option, ribs: Option<&PerNS>>>, - unusable_binding: Option<&'a NameBinding<'a>>, + ignore_binding: Option<&'a NameBinding<'a>>, ) -> PathResult<'a> { debug!("resolve_path(path={:?}, opt_ns={:?}, finalize={:?})", path, opt_ns, finalize); @@ -1477,7 +1464,7 @@ impl<'a> Resolver<'a> { ns, parent_scope, finalize, - unusable_binding, + ignore_binding, ) } else if let Some(ribs) = ribs && let Some(TypeNS | ValueNS) = opt_ns @@ -1488,7 +1475,7 @@ impl<'a> Resolver<'a> { parent_scope, finalize, &ribs[ns], - unusable_binding, + ignore_binding, ) { // we found a locally-imported or available item/module Some(LexicalScopeBinding::Item(binding)) => Ok(binding), @@ -1504,7 +1491,7 @@ impl<'a> Resolver<'a> { parent_scope, finalize, finalize.is_some(), - unusable_binding, + ignore_binding, ) }; FindBindingResult::Binding(binding) @@ -1577,7 +1564,7 @@ impl<'a> Resolver<'a> { opt_ns, parent_scope, ribs, - unusable_binding, + ignore_binding, module, i, ident, diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index cae9b1498c287..ef06ec356bd68 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -588,7 +588,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { /// consolidate multiple unresolved import errors into a single diagnostic. fn finalize_import(&mut self, import: &'b Import<'b>) -> Option { let orig_vis = import.vis.replace(ty::Visibility::Invisible); - let unusable_binding = match &import.kind { + let ignore_binding = match &import.kind { ImportKind::Single { target_bindings, .. } => target_bindings[TypeNS].get(), _ => None, }; @@ -599,7 +599,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { None, &import.parent_scope, Some(finalize), - unusable_binding, + ignore_binding, ); let no_ambiguity = self.r.ambiguity_errors.len() == prev_ambiguity_errors_len; import.vis.set(orig_vis); diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 106c6a2d4ec3e..ca89f61032221 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -969,7 +969,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { ident: Ident, ns: Namespace, finalize: Option, - unusable_binding: Option<&'a NameBinding<'a>>, + ignore_binding: Option<&'a NameBinding<'a>>, ) -> Option> { self.r.resolve_ident_in_lexical_scope( ident, @@ -977,7 +977,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { &self.parent_scope, finalize, &self.ribs[ns], - unusable_binding, + ignore_binding, ) }