diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2022-04-30 17:31:44 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2022-05-01 18:02:35 +0300 |
| commit | f0e0434feb7ac3011e4f3ae2966cd0cabe9c4ea1 (patch) | |
| tree | e151b7e154f787e985174b9213c924fa2e90a8bb | |
| parent | ffedcec4e8c9de11b8195074f59d014511bcb422 (diff) | |
| download | rust-f0e0434feb7ac3011e4f3ae2966cd0cabe9c4ea1.tar.gz rust-f0e0434feb7ac3011e4f3ae2966cd0cabe9c4ea1.zip | |
resolve: Merge `last_import_segment` into `Finalize`
| -rw-r--r-- | compiler/rustc_resolve/src/diagnostics.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/ident.rs | 30 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/imports.rs | 17 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/lib.rs | 7 | ||||
| -rw-r--r-- | 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 981d60db2f3..8cb5d815f0d 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 0f1c4f38bc7..0ca04d4c893 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<Finalize>, 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<Finalize>, - // 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<Finalize>, - 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<Finalize>, - 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<Finalize>, - 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 b5b7f1418f1..cae9b1498c2 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 330636fe543..2e625fc1b4f 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 815bff5b23e..19a9c1b99fc 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, ); } |
