Add newtype for using the prelude in resolution
This commit is contained in:
parent
3377dac31e
commit
06e77397e1
2 changed files with 18 additions and 8 deletions
|
@ -1111,7 +1111,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
suggestions.extend(
|
suggestions.extend(
|
||||||
tmp_suggestions
|
tmp_suggestions
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|s| use_prelude || this.is_builtin_macro(s.res)),
|
.filter(|s| use_prelude.into() || this.is_builtin_macro(s.res)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,18 @@ use Namespace::*;
|
||||||
|
|
||||||
type Visibility = ty::Visibility<LocalDefId>;
|
type Visibility = ty::Visibility<LocalDefId>;
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
pub enum UsePrelude {
|
||||||
|
No,
|
||||||
|
Yes,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<UsePrelude> for bool {
|
||||||
|
fn from(up: UsePrelude) -> bool {
|
||||||
|
matches!(up, UsePrelude::Yes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
/// A generic scope visitor.
|
/// A generic scope visitor.
|
||||||
/// Visits scopes in order to resolve some identifier in them or perform other actions.
|
/// Visits scopes in order to resolve some identifier in them or perform other actions.
|
||||||
|
@ -32,12 +44,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
scope_set: ScopeSet<'a>,
|
scope_set: ScopeSet<'a>,
|
||||||
parent_scope: &ParentScope<'a>,
|
parent_scope: &ParentScope<'a>,
|
||||||
ctxt: SyntaxContext,
|
ctxt: SyntaxContext,
|
||||||
mut visitor: impl FnMut(
|
mut visitor: impl FnMut(&mut Self, Scope<'a>, UsePrelude, SyntaxContext) -> Option<T>,
|
||||||
&mut Self,
|
|
||||||
Scope<'a>,
|
|
||||||
/*use_prelude*/ bool,
|
|
||||||
SyntaxContext,
|
|
||||||
) -> Option<T>,
|
|
||||||
) -> Option<T> {
|
) -> Option<T> {
|
||||||
// General principles:
|
// General principles:
|
||||||
// 1. Not controlled (user-defined) names should have higher priority than controlled names
|
// 1. Not controlled (user-defined) names should have higher priority than controlled names
|
||||||
|
@ -133,6 +140,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
if visit {
|
if visit {
|
||||||
|
let use_prelude = if use_prelude { UsePrelude::Yes } else { UsePrelude::No };
|
||||||
if let break_result @ Some(..) = visitor(self, scope, use_prelude, ctxt) {
|
if let break_result @ Some(..) = visitor(self, scope, use_prelude, ctxt) {
|
||||||
return break_result;
|
return break_result;
|
||||||
}
|
}
|
||||||
|
@ -579,7 +587,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
None,
|
None,
|
||||||
ignore_binding,
|
ignore_binding,
|
||||||
) {
|
) {
|
||||||
if use_prelude || this.is_builtin_macro(binding.res()) {
|
if matches!(use_prelude, UsePrelude::Yes)
|
||||||
|
|| this.is_builtin_macro(binding.res())
|
||||||
|
{
|
||||||
result = Ok((binding, Flags::MISC_FROM_PRELUDE));
|
result = Ok((binding, Flags::MISC_FROM_PRELUDE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue