resolve: Merge last_import_segment
into Finalize
This commit is contained in:
parent
ffedcec4e8
commit
f0e0434feb
5 changed files with 16 additions and 44 deletions
|
@ -1500,7 +1500,6 @@ impl<'a> Resolver<'a> {
|
||||||
&parent_scope,
|
&parent_scope,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
false,
|
|
||||||
None,
|
None,
|
||||||
) {
|
) {
|
||||||
let desc = match binding.res() {
|
let desc = match binding.res() {
|
||||||
|
@ -1860,7 +1859,6 @@ impl<'a> Resolver<'a> {
|
||||||
ns_to_try,
|
ns_to_try,
|
||||||
parent_scope,
|
parent_scope,
|
||||||
None,
|
None,
|
||||||
false,
|
|
||||||
unusable_binding,
|
unusable_binding,
|
||||||
).ok()
|
).ok()
|
||||||
} else if let Some(ribs) = ribs
|
} else if let Some(ribs) = ribs
|
||||||
|
@ -1886,7 +1884,6 @@ impl<'a> Resolver<'a> {
|
||||||
parent_scope,
|
parent_scope,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
false,
|
|
||||||
unusable_binding,
|
unusable_binding,
|
||||||
).ok()
|
).ok()
|
||||||
};
|
};
|
||||||
|
|
|
@ -343,7 +343,6 @@ impl<'a> Resolver<'a> {
|
||||||
ns,
|
ns,
|
||||||
parent_scope,
|
parent_scope,
|
||||||
finalize,
|
finalize,
|
||||||
false,
|
|
||||||
unusable_binding,
|
unusable_binding,
|
||||||
);
|
);
|
||||||
if let Ok(binding) = item {
|
if let Ok(binding) = item {
|
||||||
|
@ -357,7 +356,6 @@ impl<'a> Resolver<'a> {
|
||||||
parent_scope,
|
parent_scope,
|
||||||
finalize,
|
finalize,
|
||||||
finalize.is_some(),
|
finalize.is_some(),
|
||||||
false,
|
|
||||||
unusable_binding,
|
unusable_binding,
|
||||||
)
|
)
|
||||||
.ok()
|
.ok()
|
||||||
|
@ -377,7 +375,6 @@ impl<'a> Resolver<'a> {
|
||||||
parent_scope: &ParentScope<'a>,
|
parent_scope: &ParentScope<'a>,
|
||||||
finalize: Option<Finalize>,
|
finalize: Option<Finalize>,
|
||||||
force: bool,
|
force: bool,
|
||||||
last_import_segment: bool,
|
|
||||||
unusable_binding: Option<&'a NameBinding<'a>>,
|
unusable_binding: Option<&'a NameBinding<'a>>,
|
||||||
) -> Result<&'a NameBinding<'a>, Determinacy> {
|
) -> Result<&'a NameBinding<'a>, Determinacy> {
|
||||||
bitflags::bitflags! {
|
bitflags::bitflags! {
|
||||||
|
@ -498,7 +495,6 @@ impl<'a> Resolver<'a> {
|
||||||
ns,
|
ns,
|
||||||
parent_scope,
|
parent_scope,
|
||||||
finalize,
|
finalize,
|
||||||
last_import_segment,
|
|
||||||
unusable_binding,
|
unusable_binding,
|
||||||
);
|
);
|
||||||
match binding {
|
match binding {
|
||||||
|
@ -521,7 +517,6 @@ impl<'a> Resolver<'a> {
|
||||||
adjusted_parent_scope,
|
adjusted_parent_scope,
|
||||||
!matches!(scope_set, ScopeSet::Late(..)),
|
!matches!(scope_set, ScopeSet::Late(..)),
|
||||||
finalize,
|
finalize,
|
||||||
last_import_segment,
|
|
||||||
unusable_binding,
|
unusable_binding,
|
||||||
);
|
);
|
||||||
match binding {
|
match binding {
|
||||||
|
@ -607,7 +602,6 @@ impl<'a> Resolver<'a> {
|
||||||
ns,
|
ns,
|
||||||
parent_scope,
|
parent_scope,
|
||||||
None,
|
None,
|
||||||
last_import_segment,
|
|
||||||
unusable_binding,
|
unusable_binding,
|
||||||
) {
|
) {
|
||||||
if use_prelude || this.is_builtin_macro(binding.res()) {
|
if use_prelude || this.is_builtin_macro(binding.res()) {
|
||||||
|
@ -730,7 +724,7 @@ impl<'a> Resolver<'a> {
|
||||||
ns: Namespace,
|
ns: Namespace,
|
||||||
parent_scope: &ParentScope<'a>,
|
parent_scope: &ParentScope<'a>,
|
||||||
) -> Result<&'a NameBinding<'a>, Determinacy> {
|
) -> 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)
|
.map_err(|(determinacy, _)| determinacy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -742,8 +736,6 @@ impl<'a> Resolver<'a> {
|
||||||
ns: Namespace,
|
ns: Namespace,
|
||||||
parent_scope: &ParentScope<'a>,
|
parent_scope: &ParentScope<'a>,
|
||||||
finalize: Option<Finalize>,
|
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
|
// This binding should be ignored during in-module resolution, so that we don't get
|
||||||
// "self-confirming" import resolutions during import validation.
|
// "self-confirming" import resolutions during import validation.
|
||||||
unusable_binding: Option<&'a NameBinding<'a>>,
|
unusable_binding: Option<&'a NameBinding<'a>>,
|
||||||
|
@ -754,7 +746,6 @@ impl<'a> Resolver<'a> {
|
||||||
ns,
|
ns,
|
||||||
parent_scope,
|
parent_scope,
|
||||||
finalize,
|
finalize,
|
||||||
last_import_segment,
|
|
||||||
unusable_binding,
|
unusable_binding,
|
||||||
)
|
)
|
||||||
.map_err(|(determinacy, _)| determinacy)
|
.map_err(|(determinacy, _)| determinacy)
|
||||||
|
@ -768,7 +759,6 @@ impl<'a> Resolver<'a> {
|
||||||
ns: Namespace,
|
ns: Namespace,
|
||||||
parent_scope: &ParentScope<'a>,
|
parent_scope: &ParentScope<'a>,
|
||||||
finalize: Option<Finalize>,
|
finalize: Option<Finalize>,
|
||||||
last_import_segment: bool,
|
|
||||||
unusable_binding: Option<&'a NameBinding<'a>>,
|
unusable_binding: Option<&'a NameBinding<'a>>,
|
||||||
) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> {
|
) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> {
|
||||||
let tmp_parent_scope;
|
let tmp_parent_scope;
|
||||||
|
@ -795,7 +785,6 @@ impl<'a> Resolver<'a> {
|
||||||
adjusted_parent_scope,
|
adjusted_parent_scope,
|
||||||
false,
|
false,
|
||||||
finalize,
|
finalize,
|
||||||
last_import_segment,
|
|
||||||
unusable_binding,
|
unusable_binding,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -808,7 +797,6 @@ impl<'a> Resolver<'a> {
|
||||||
ns: Namespace,
|
ns: Namespace,
|
||||||
parent_scope: &ParentScope<'a>,
|
parent_scope: &ParentScope<'a>,
|
||||||
finalize: Option<Finalize>,
|
finalize: Option<Finalize>,
|
||||||
last_import_segment: bool,
|
|
||||||
unusable_binding: Option<&'a NameBinding<'a>>,
|
unusable_binding: Option<&'a NameBinding<'a>>,
|
||||||
) -> Result<&'a NameBinding<'a>, Determinacy> {
|
) -> Result<&'a NameBinding<'a>, Determinacy> {
|
||||||
self.resolve_ident_in_module_unadjusted_ext(
|
self.resolve_ident_in_module_unadjusted_ext(
|
||||||
|
@ -818,7 +806,6 @@ impl<'a> Resolver<'a> {
|
||||||
parent_scope,
|
parent_scope,
|
||||||
false,
|
false,
|
||||||
finalize,
|
finalize,
|
||||||
last_import_segment,
|
|
||||||
unusable_binding,
|
unusable_binding,
|
||||||
)
|
)
|
||||||
.map_err(|(determinacy, _)| determinacy)
|
.map_err(|(determinacy, _)| determinacy)
|
||||||
|
@ -835,7 +822,6 @@ impl<'a> Resolver<'a> {
|
||||||
parent_scope: &ParentScope<'a>,
|
parent_scope: &ParentScope<'a>,
|
||||||
restricted_shadowing: bool,
|
restricted_shadowing: bool,
|
||||||
finalize: Option<Finalize>,
|
finalize: Option<Finalize>,
|
||||||
last_import_segment: bool,
|
|
||||||
unusable_binding: Option<&'a NameBinding<'a>>,
|
unusable_binding: Option<&'a NameBinding<'a>>,
|
||||||
) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> {
|
) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> {
|
||||||
let module = match module {
|
let module = match module {
|
||||||
|
@ -848,7 +834,6 @@ impl<'a> Resolver<'a> {
|
||||||
parent_scope,
|
parent_scope,
|
||||||
finalize,
|
finalize,
|
||||||
finalize.is_some(),
|
finalize.is_some(),
|
||||||
last_import_segment,
|
|
||||||
unusable_binding,
|
unusable_binding,
|
||||||
);
|
);
|
||||||
return binding.map_err(|determinacy| (determinacy, Weak::No));
|
return binding.map_err(|determinacy| (determinacy, Weak::No));
|
||||||
|
@ -889,7 +874,6 @@ impl<'a> Resolver<'a> {
|
||||||
parent_scope,
|
parent_scope,
|
||||||
finalize,
|
finalize,
|
||||||
finalize.is_some(),
|
finalize.is_some(),
|
||||||
last_import_segment,
|
|
||||||
unusable_binding,
|
unusable_binding,
|
||||||
);
|
);
|
||||||
return binding.map_err(|determinacy| (determinacy, Weak::No));
|
return binding.map_err(|determinacy| (determinacy, Weak::No));
|
||||||
|
@ -900,7 +884,7 @@ impl<'a> Resolver<'a> {
|
||||||
let resolution =
|
let resolution =
|
||||||
self.resolution(module, key).try_borrow_mut().map_err(|_| (Determined, Weak::No))?; // This happens when there is a cycle of imports.
|
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
|
// 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
|
// 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
|
// 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 !self.is_accessible_from(binding.vis, parent_scope.module) {
|
||||||
if last_import_segment {
|
if report_private {
|
||||||
return Err((Determined, Weak::No));
|
|
||||||
} else {
|
|
||||||
self.privacy_errors.push(PrivacyError {
|
self.privacy_errors.push(PrivacyError {
|
||||||
ident,
|
ident,
|
||||||
binding,
|
binding,
|
||||||
dedup_span: path_span,
|
dedup_span: path_span,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
return Err((Determined, Weak::No));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -995,7 +979,6 @@ impl<'a> Resolver<'a> {
|
||||||
ns,
|
ns,
|
||||||
&single_import.parent_scope,
|
&single_import.parent_scope,
|
||||||
None,
|
None,
|
||||||
last_import_segment,
|
|
||||||
unusable_binding,
|
unusable_binding,
|
||||||
) {
|
) {
|
||||||
Err(Determined) => continue,
|
Err(Determined) => continue,
|
||||||
|
@ -1072,7 +1055,6 @@ impl<'a> Resolver<'a> {
|
||||||
ns,
|
ns,
|
||||||
adjusted_parent_scope,
|
adjusted_parent_scope,
|
||||||
None,
|
None,
|
||||||
last_import_segment,
|
|
||||||
unusable_binding,
|
unusable_binding,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1495,7 +1477,6 @@ impl<'a> Resolver<'a> {
|
||||||
ns,
|
ns,
|
||||||
parent_scope,
|
parent_scope,
|
||||||
finalize,
|
finalize,
|
||||||
false,
|
|
||||||
unusable_binding,
|
unusable_binding,
|
||||||
)
|
)
|
||||||
} else if let Some(ribs) = ribs
|
} else if let Some(ribs) = ribs
|
||||||
|
@ -1523,7 +1504,6 @@ impl<'a> Resolver<'a> {
|
||||||
parent_scope,
|
parent_scope,
|
||||||
finalize,
|
finalize,
|
||||||
finalize.is_some(),
|
finalize.is_some(),
|
||||||
false,
|
|
||||||
unusable_binding,
|
unusable_binding,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
|
@ -545,7 +545,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||||
ns,
|
ns,
|
||||||
&import.parent_scope,
|
&import.parent_scope,
|
||||||
None,
|
None,
|
||||||
false,
|
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
import.vis.set(orig_vis);
|
import.vis.set(orig_vis);
|
||||||
|
@ -594,13 +593,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
let prev_ambiguity_errors_len = self.r.ambiguity_errors.len();
|
let prev_ambiguity_errors_len = self.r.ambiguity_errors.len();
|
||||||
let finalize =
|
let finalize = Finalize::with_root_span(import.root_id, import.span, import.root_span);
|
||||||
Some(Finalize::with_root_span(import.root_id, import.span, import.root_span));
|
|
||||||
let path_res = self.r.resolve_path(
|
let path_res = self.r.resolve_path(
|
||||||
&import.module_path,
|
&import.module_path,
|
||||||
None,
|
None,
|
||||||
&import.parent_scope,
|
&import.parent_scope,
|
||||||
finalize,
|
Some(finalize),
|
||||||
unusable_binding,
|
unusable_binding,
|
||||||
);
|
);
|
||||||
let no_ambiguity = self.r.ambiguity_errors.len() == prev_ambiguity_errors_len;
|
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.
|
// 2 segments, so the `resolve_path` above won't trigger it.
|
||||||
let mut full_path = import.module_path.clone();
|
let mut full_path = import.module_path.clone();
|
||||||
full_path.push(Segment::from_ident(Ident::empty()));
|
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 {
|
if let ModuleOrUniformRoot::Module(module) = module {
|
||||||
|
@ -717,8 +715,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||||
ident,
|
ident,
|
||||||
ns,
|
ns,
|
||||||
&import.parent_scope,
|
&import.parent_scope,
|
||||||
finalize,
|
Some(Finalize { report_private: false, ..finalize }),
|
||||||
true,
|
|
||||||
target_bindings[ns].get(),
|
target_bindings[ns].get(),
|
||||||
);
|
);
|
||||||
import.vis.set(orig_vis);
|
import.vis.set(orig_vis);
|
||||||
|
@ -778,8 +775,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||||
ident,
|
ident,
|
||||||
ns,
|
ns,
|
||||||
&import.parent_scope,
|
&import.parent_scope,
|
||||||
finalize,
|
Some(finalize),
|
||||||
false,
|
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
if binding.is_ok() {
|
if binding.is_ok() {
|
||||||
|
@ -945,7 +941,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
|
||||||
full_path.push(Segment::from_ident(ident));
|
full_path.push(Segment::from_ident(ident));
|
||||||
self.r.per_ns(|this, ns| {
|
self.r.per_ns(|this, ns| {
|
||||||
if let Ok(binding) = source_bindings[ns].get() {
|
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,
|
&import.parent_scope,
|
||||||
None,
|
None,
|
||||||
false,
|
false,
|
||||||
false,
|
|
||||||
target_bindings[ns].get(),
|
target_bindings[ns].get(),
|
||||||
) {
|
) {
|
||||||
Ok(other_binding) => {
|
Ok(other_binding) => {
|
||||||
|
|
|
@ -2053,15 +2053,18 @@ struct Finalize {
|
||||||
/// Span of the path start, suitable for prepending something to to it.
|
/// 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.
|
/// E.g. span of `foo` in `foo::{a, b, c}`, or full span for regular paths.
|
||||||
root_span: Span,
|
root_span: Span,
|
||||||
|
/// Whether to report privacy errors or silently return "no resolution" for them,
|
||||||
|
/// similarly to speculative resolution.
|
||||||
|
report_private: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Finalize {
|
impl Finalize {
|
||||||
fn new(node_id: NodeId, path_span: Span) -> 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 {
|
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 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -604,7 +604,6 @@ impl<'a> Resolver<'a> {
|
||||||
parent_scope,
|
parent_scope,
|
||||||
None,
|
None,
|
||||||
force,
|
force,
|
||||||
false,
|
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
if let Err(Determinacy::Undetermined) = binding {
|
if let Err(Determinacy::Undetermined) = binding {
|
||||||
|
@ -710,7 +709,6 @@ impl<'a> Resolver<'a> {
|
||||||
&parent_scope,
|
&parent_scope,
|
||||||
Some(Finalize::new(ast::CRATE_NODE_ID, ident.span)),
|
Some(Finalize::new(ast::CRATE_NODE_ID, ident.span)),
|
||||||
true,
|
true,
|
||||||
false,
|
|
||||||
None,
|
None,
|
||||||
) {
|
) {
|
||||||
Ok(binding) => {
|
Ok(binding) => {
|
||||||
|
@ -753,7 +751,6 @@ impl<'a> Resolver<'a> {
|
||||||
&parent_scope,
|
&parent_scope,
|
||||||
Some(Finalize::new(ast::CRATE_NODE_ID, ident.span)),
|
Some(Finalize::new(ast::CRATE_NODE_ID, ident.span)),
|
||||||
true,
|
true,
|
||||||
false,
|
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue