Skip to content

Commit 06e7739

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

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

‎compiler/rustc_resolve/src/diagnostics.rs‎

Lines changed: 1 addition & 1 deletion
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‎

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

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

26+
#[derive(Copy,Clone)]
27+
pubenumUsePrelude{
28+
No,
29+
Yes,
30+
}
31+
32+
implFrom<UsePrelude>forbool{
33+
fnfrom(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-
mutvisitor:implFnMut(
36-
&mutSelf,
37-
Scope<'a>,
38-
/*use_prelude*/bool,
39-
SyntaxContext,
40-
) -> Option<T>,
47+
mutvisitor:implFnMut(&mutSelf,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
iflet 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+
ifmatches!(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)