Skip to content

Commit

Permalink
Add newtype for using the prelude in resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
clubby789 committed Feb 20, 2024
1 parent 3377dac commit 06e7739
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
suggestions.extend(
tmp_suggestions
.into_iter()
.filter(|s| use_prelude || this.is_builtin_macro(s.res)),
.filter(|s| use_prelude.into() || this.is_builtin_macro(s.res)),
);
}
}
Expand Down
24 changes: 17 additions & 7 deletions compiler/rustc_resolve/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ use Namespace::*;

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> {
/// A generic scope visitor.
/// Visits scopes in order to resolve some identifier in them or perform other actions.
Expand All @@ -32,12 +44,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
scope_set: ScopeSet<'a>,
parent_scope: &ParentScope<'a>,
ctxt: SyntaxContext,
mut visitor: impl FnMut(
&mut Self,
Scope<'a>,
/*use_prelude*/ bool,
SyntaxContext,
) -> Option<T>,
mut visitor: impl FnMut(&mut Self, Scope<'a>, UsePrelude, SyntaxContext) -> Option<T>,
) -> Option<T> {
// General principles:
// 1. Not controlled (user-defined) names should have higher priority than controlled names
Expand Down Expand Up @@ -133,6 +140,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
};

if visit {
let use_prelude = if use_prelude { UsePrelude::Yes } else { UsePrelude::No };
if let break_result @ Some(..) = visitor(self, scope, use_prelude, ctxt) {
return break_result;
}
Expand Down Expand Up @@ -579,7 +587,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
None,
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));
}
}
Expand Down

0 comments on commit 06e7739

Please sign in to comment.