Skip to content

Commit 06e7739

Browse files
committed
Add newtype for using the prelude in resolution
1 parent 3377dac commit 06e7739

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
11111111
suggestions.extend(
11121112
tmp_suggestions
11131113
.into_iter()
1114-
.filter(|s| use_prelude || this.is_builtin_macro(s.res)),
1114+
.filter(|s| use_prelude.into() || this.is_builtin_macro(s.res)),
11151115
);
11161116
}
11171117
}

compiler/rustc_resolve/src/ident.rs

+17-7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ use Namespace::*;
2323

2424
type Visibility = ty::Visibility<LocalDefId>;
2525

26+
#[derive(Copy, Clone)]
27+
pub enum UsePrelude {
28+
No,
29+
Yes,
30+
}
31+
32+
impl From<UsePrelude> for bool {
33+
fn from(up: UsePrelude) -> bool {
34+
matches!(up, UsePrelude::Yes)
35+
}
36+
}
37+
2638
impl<'a, 'tcx> Resolver<'a, 'tcx> {
2739
/// A generic scope visitor.
2840
/// Visits scopes in order to resolve some identifier in them or perform other actions.
@@ -32,12 +44,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3244
scope_set: ScopeSet<'a>,
3345
parent_scope: &ParentScope<'a>,
3446
ctxt: SyntaxContext,
35-
mut visitor: impl FnMut(
36-
&mut Self,
37-
Scope<'a>,
38-
/*use_prelude*/ bool,
39-
SyntaxContext,
40-
) -> Option<T>,
47+
mut visitor: impl FnMut(&mut Self, Scope<'a>, UsePrelude, SyntaxContext) -> Option<T>,
4148
) -> Option<T> {
4249
// General principles:
4350
// 1. Not controlled (user-defined) names should have higher priority than controlled names
@@ -133,6 +140,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
133140
};
134141

135142
if visit {
143+
let use_prelude = if use_prelude { UsePrelude::Yes } else { UsePrelude::No };
136144
if let break_result @ Some(..) = visitor(self, scope, use_prelude, ctxt) {
137145
return break_result;
138146
}
@@ -579,7 +587,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
579587
None,
580588
ignore_binding,
581589
) {
582-
if use_prelude || this.is_builtin_macro(binding.res()) {
590+
if matches!(use_prelude, UsePrelude::Yes)
591+
|| this.is_builtin_macro(binding.res())
592+
{
583593
result = Ok((binding, Flags::MISC_FROM_PRELUDE));
584594
}
585595
}

0 commit comments

Comments
 (0)