make import.vis
is not mutable
This commit is contained in:
parent
9bad7ba324
commit
8c06dc4dda
9 changed files with 129 additions and 63 deletions
|
@ -14,6 +14,7 @@ use Determinacy::*;
|
|||
use Namespace::*;
|
||||
|
||||
use crate::errors::{ParamKindInEnumDiscriminant, ParamKindInNonTrivialAnonConst};
|
||||
use crate::imports::Import;
|
||||
use crate::late::{ConstantHasGenerics, NoConstantGenericsReason, PathSource, Rib, RibKind};
|
||||
use crate::macros::{sub_namespace_match, MacroRulesScope};
|
||||
use crate::{
|
||||
|
@ -351,6 +352,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
parent_scope,
|
||||
finalize.map(|finalize| Finalize { used: Used::Scope, ..finalize }),
|
||||
ignore_binding,
|
||||
None,
|
||||
);
|
||||
if let Ok(binding) = item {
|
||||
// The ident resolves to an item.
|
||||
|
@ -364,6 +366,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
finalize,
|
||||
finalize.is_some(),
|
||||
ignore_binding,
|
||||
None,
|
||||
)
|
||||
.ok()
|
||||
.map(LexicalScopeBinding::Item)
|
||||
|
@ -383,6 +386,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
finalize: Option<Finalize>,
|
||||
force: bool,
|
||||
ignore_binding: Option<NameBinding<'a>>,
|
||||
ignore_import: Option<Import<'a>>,
|
||||
) -> Result<NameBinding<'a>, Determinacy> {
|
||||
bitflags::bitflags! {
|
||||
#[derive(Clone, Copy)]
|
||||
|
@ -455,6 +459,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
parent_scope,
|
||||
true,
|
||||
force,
|
||||
ignore_import,
|
||||
) {
|
||||
Ok((Some(ext), _)) => {
|
||||
if ext.helper_attrs.contains(&ident.name) {
|
||||
|
@ -496,6 +501,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
parent_scope,
|
||||
finalize,
|
||||
ignore_binding,
|
||||
ignore_import,
|
||||
);
|
||||
match binding {
|
||||
Ok(binding) => Ok((binding, Flags::MODULE | Flags::MISC_SUGGEST_CRATE)),
|
||||
|
@ -518,6 +524,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
!matches!(scope_set, ScopeSet::Late(..)),
|
||||
finalize.map(|finalize| Finalize { used: Used::Scope, ..finalize }),
|
||||
ignore_binding,
|
||||
ignore_import,
|
||||
);
|
||||
match binding {
|
||||
Ok(binding) => {
|
||||
|
@ -585,6 +592,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
parent_scope,
|
||||
None,
|
||||
ignore_binding,
|
||||
ignore_import,
|
||||
) {
|
||||
if matches!(use_prelude, UsePrelude::Yes)
|
||||
|| this.is_builtin_macro(binding.res())
|
||||
|
@ -738,8 +746,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
ident: Ident,
|
||||
ns: Namespace,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
ignore_import: Option<Import<'a>>,
|
||||
) -> Result<NameBinding<'a>, Determinacy> {
|
||||
self.resolve_ident_in_module_ext(module, ident, ns, parent_scope, None, None)
|
||||
self.resolve_ident_in_module_ext(module, ident, ns, parent_scope, None, None, ignore_import)
|
||||
.map_err(|(determinacy, _)| determinacy)
|
||||
}
|
||||
|
||||
|
@ -752,9 +761,18 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
parent_scope: &ParentScope<'a>,
|
||||
finalize: Option<Finalize>,
|
||||
ignore_binding: Option<NameBinding<'a>>,
|
||||
ignore_import: Option<Import<'a>>,
|
||||
) -> Result<NameBinding<'a>, Determinacy> {
|
||||
self.resolve_ident_in_module_ext(module, ident, ns, parent_scope, finalize, ignore_binding)
|
||||
.map_err(|(determinacy, _)| determinacy)
|
||||
self.resolve_ident_in_module_ext(
|
||||
module,
|
||||
ident,
|
||||
ns,
|
||||
parent_scope,
|
||||
finalize,
|
||||
ignore_binding,
|
||||
ignore_import,
|
||||
)
|
||||
.map_err(|(determinacy, _)| determinacy)
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
|
@ -766,6 +784,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
parent_scope: &ParentScope<'a>,
|
||||
finalize: Option<Finalize>,
|
||||
ignore_binding: Option<NameBinding<'a>>,
|
||||
ignore_import: Option<Import<'a>>,
|
||||
) -> Result<NameBinding<'a>, (Determinacy, Weak)> {
|
||||
let tmp_parent_scope;
|
||||
let mut adjusted_parent_scope = parent_scope;
|
||||
|
@ -792,6 +811,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
false,
|
||||
finalize,
|
||||
ignore_binding,
|
||||
ignore_import,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -804,6 +824,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
parent_scope: &ParentScope<'a>,
|
||||
finalize: Option<Finalize>,
|
||||
ignore_binding: Option<NameBinding<'a>>,
|
||||
ignore_import: Option<Import<'a>>,
|
||||
) -> Result<NameBinding<'a>, Determinacy> {
|
||||
self.resolve_ident_in_module_unadjusted_ext(
|
||||
module,
|
||||
|
@ -813,6 +834,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
false,
|
||||
finalize,
|
||||
ignore_binding,
|
||||
ignore_import,
|
||||
)
|
||||
.map_err(|(determinacy, _)| determinacy)
|
||||
}
|
||||
|
@ -831,6 +853,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
// 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<NameBinding<'a>>,
|
||||
ignore_import: Option<Import<'a>>,
|
||||
) -> Result<NameBinding<'a>, (Determinacy, Weak)> {
|
||||
let module = match module {
|
||||
ModuleOrUniformRoot::Module(module) => module,
|
||||
|
@ -843,6 +866,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
finalize,
|
||||
finalize.is_some(),
|
||||
ignore_binding,
|
||||
ignore_import,
|
||||
);
|
||||
return binding.map_err(|determinacy| (determinacy, Weak::No));
|
||||
}
|
||||
|
@ -879,6 +903,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
finalize,
|
||||
finalize.is_some(),
|
||||
ignore_binding,
|
||||
ignore_import,
|
||||
);
|
||||
return binding.map_err(|determinacy| (determinacy, Weak::No));
|
||||
}
|
||||
|
@ -962,25 +987,23 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
// Check if one of single imports can still define the name,
|
||||
// if it can then our result is not determined and can be invalidated.
|
||||
for single_import in &resolution.single_imports {
|
||||
let Some(import_vis) = single_import.vis.get() else {
|
||||
// This branch handles a cycle in single imports, which occurs
|
||||
// when we've previously **steal** the `vis` value during an import
|
||||
// process.
|
||||
if ignore_import == Some(*single_import) {
|
||||
// This branch handles a cycle in single imports.
|
||||
//
|
||||
// For example:
|
||||
// ```
|
||||
// use a::b;
|
||||
// use b as a;
|
||||
// ```
|
||||
// 1. Steal the `vis` in `use a::b` and attempt to locate `a` in the
|
||||
// 1. Record `use a::b` as the `ignore_import` and attempt to locate `a` in the
|
||||
// current module.
|
||||
// 2. Encounter the import `use b as a`, which is a `single_import` for `a`,
|
||||
// and try to find `b` in the current module.
|
||||
// 3. Re-encounter the `use a::b` import since it's a `single_import` of `b`.
|
||||
// This leads to entering this branch.
|
||||
continue;
|
||||
};
|
||||
if !self.is_accessible_from(import_vis, parent_scope.module) {
|
||||
}
|
||||
if !self.is_accessible_from(single_import.vis, parent_scope.module) {
|
||||
continue;
|
||||
}
|
||||
if let Some(ignored) = ignore_binding
|
||||
|
@ -1022,6 +1045,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
&single_import.parent_scope,
|
||||
None,
|
||||
ignore_binding,
|
||||
ignore_import,
|
||||
) {
|
||||
Err(Determined) => continue,
|
||||
Ok(binding)
|
||||
|
@ -1070,10 +1094,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
// Check if one of glob imports can still define the name,
|
||||
// if it can then our "no resolution" result is not determined and can be invalidated.
|
||||
for glob_import in module.globs.borrow().iter() {
|
||||
let Some(import_vis) = glob_import.vis.get() else {
|
||||
if ignore_import == Some(*glob_import) {
|
||||
continue;
|
||||
};
|
||||
if !self.is_accessible_from(import_vis, parent_scope.module) {
|
||||
}
|
||||
if !self.is_accessible_from(glob_import.vis, parent_scope.module) {
|
||||
continue;
|
||||
}
|
||||
let module = match glob_import.imported_module.get() {
|
||||
|
@ -1100,6 +1124,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
adjusted_parent_scope,
|
||||
None,
|
||||
ignore_binding,
|
||||
ignore_import,
|
||||
);
|
||||
|
||||
match result {
|
||||
|
@ -1412,8 +1437,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
path: &[Segment],
|
||||
opt_ns: Option<Namespace>, // `None` indicates a module path in import
|
||||
parent_scope: &ParentScope<'a>,
|
||||
ignore_import: Option<Import<'a>>,
|
||||
) -> PathResult<'a> {
|
||||
self.resolve_path_with_ribs(path, opt_ns, parent_scope, None, None, None)
|
||||
self.resolve_path_with_ribs(path, opt_ns, parent_scope, None, None, None, ignore_import)
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
|
@ -1424,8 +1450,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
parent_scope: &ParentScope<'a>,
|
||||
finalize: Option<Finalize>,
|
||||
ignore_binding: Option<NameBinding<'a>>,
|
||||
ignore_import: Option<Import<'a>>,
|
||||
) -> PathResult<'a> {
|
||||
self.resolve_path_with_ribs(path, opt_ns, parent_scope, finalize, None, ignore_binding)
|
||||
self.resolve_path_with_ribs(
|
||||
path,
|
||||
opt_ns,
|
||||
parent_scope,
|
||||
finalize,
|
||||
None,
|
||||
ignore_binding,
|
||||
ignore_import,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn resolve_path_with_ribs(
|
||||
|
@ -1436,6 +1471,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
finalize: Option<Finalize>,
|
||||
ribs: Option<&PerNS<Vec<Rib<'a>>>>,
|
||||
ignore_binding: Option<NameBinding<'a>>,
|
||||
ignore_import: Option<Import<'a>>,
|
||||
) -> PathResult<'a> {
|
||||
let mut module = None;
|
||||
let mut allow_super = true;
|
||||
|
@ -1538,10 +1574,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
parent_scope,
|
||||
finalize,
|
||||
ignore_binding,
|
||||
ignore_import,
|
||||
)
|
||||
} else if let Some(ribs) = ribs
|
||||
&& let Some(TypeNS | ValueNS) = opt_ns
|
||||
{
|
||||
assert!(ignore_import.is_none());
|
||||
match self.resolve_ident_in_lexical_scope(
|
||||
ident,
|
||||
ns,
|
||||
|
@ -1570,6 +1608,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
finalize,
|
||||
finalize.is_some(),
|
||||
ignore_binding,
|
||||
ignore_import,
|
||||
)
|
||||
};
|
||||
|
||||
|
@ -1644,6 +1683,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
parent_scope,
|
||||
ribs,
|
||||
ignore_binding,
|
||||
ignore_import,
|
||||
module,
|
||||
segment_idx,
|
||||
ident,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue