Skip to content

Commit 1ad64a2

Browse files
committed
resolve: Rename CrateLint to Finalize
And `crate_lint`/`record_used` to `finalize`
1 parent 74d079d commit 1ad64a2

File tree

7 files changed

+147
-170
lines changed

7 files changed

+147
-170
lines changed

compiler/rustc_resolve/src/build_reduced_graph.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::def_collector::collect_definitions;
99
use crate::imports::{Import, ImportKind};
1010
use crate::macros::{MacroRulesBinding, MacroRulesScope, MacroRulesScopeRef};
1111
use crate::Namespace::{self, MacroNS, TypeNS, ValueNS};
12-
use crate::{CrateLint, Determinacy, ExternPreludeEntry, Module, ModuleKind, ModuleOrUniformRoot};
12+
use crate::{Determinacy, ExternPreludeEntry, Finalize, Module, ModuleKind, ModuleOrUniformRoot};
1313
use crate::{NameBinding, NameBindingKind, ParentScope, PathResult, PerNS, ResolutionError};
1414
use crate::{Resolver, ResolverArenas, Segment, ToNameBinding, VisResolutionError};
1515

@@ -235,16 +235,16 @@ impl<'a> AsMut<Resolver<'a>> for BuildReducedGraphVisitor<'a, '_> {
235235

236236
impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
237237
fn resolve_visibility(&mut self, vis: &ast::Visibility) -> ty::Visibility {
238-
self.resolve_visibility_speculative(vis, false).unwrap_or_else(|err| {
238+
self.try_resolve_visibility(vis, true).unwrap_or_else(|err| {
239239
self.r.report_vis_error(err);
240240
ty::Visibility::Public
241241
})
242242
}
243243

244-
fn resolve_visibility_speculative<'ast>(
244+
fn try_resolve_visibility<'ast>(
245245
&mut self,
246246
vis: &'ast ast::Visibility,
247-
speculative: bool,
247+
finalize: bool,
248248
) -> Result<ty::Visibility, VisResolutionError<'ast>> {
249249
let parent_scope = &self.parent_scope;
250250
match vis.kind {
@@ -296,11 +296,11 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
296296
&segments,
297297
Some(TypeNS),
298298
parent_scope,
299-
if speculative { CrateLint::No } else { CrateLint::SimplePath(id, path.span) },
299+
if finalize { Finalize::SimplePath(id, path.span) } else { Finalize::No },
300300
) {
301301
PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
302302
let res = module.res().expect("visibility resolved to unnamed block");
303-
if !speculative {
303+
if finalize {
304304
self.r.record_partial_res(id, PartialRes::new(res));
305305
}
306306
if module.is_normal() {
@@ -770,7 +770,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
770770
// correct visibilities for unnamed field placeholders specifically, so the
771771
// constructor visibility should still be determined correctly.
772772
let field_vis = self
773-
.resolve_visibility_speculative(&field.vis, true)
773+
.try_resolve_visibility(&field.vis, false)
774774
.unwrap_or(ty::Visibility::Public);
775775
if ctor_vis.is_at_least(field_vis, &*self.r) {
776776
ctor_vis = field_vis;
@@ -1269,9 +1269,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
12691269
let vis = match item.kind {
12701270
// Visibilities must not be resolved non-speculatively twice
12711271
// and we already resolved this one as a `fn` item visibility.
1272-
ItemKind::Fn(..) => self
1273-
.resolve_visibility_speculative(&item.vis, true)
1274-
.unwrap_or(ty::Visibility::Public),
1272+
ItemKind::Fn(..) => {
1273+
self.try_resolve_visibility(&item.vis, false).unwrap_or(ty::Visibility::Public)
1274+
}
12751275
_ => self.resolve_visibility(&item.vis),
12761276
};
12771277
if vis != ty::Visibility::Public {

compiler/rustc_resolve/src/diagnostics.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ use tracing::debug;
2424
use crate::imports::{Import, ImportKind, ImportResolver};
2525
use crate::path_names_to_string;
2626
use crate::{AmbiguityError, AmbiguityErrorMisc, AmbiguityKind};
27-
use crate::{
28-
BindingError, CrateLint, HasGenericParams, MacroRulesScope, Module, ModuleOrUniformRoot,
29-
};
30-
use crate::{NameBinding, NameBindingKind, PrivacyError, VisResolutionError};
27+
use crate::{BindingError, HasGenericParams, MacroRulesScope, Module, ModuleOrUniformRoot};
28+
use crate::{Finalize, NameBinding, NameBindingKind, PrivacyError, VisResolutionError};
3129
use crate::{ParentScope, PathResult, ResolutionError, Resolver, Scope, ScopeSet, Segment};
3230

3331
type Res = def::Res<ast::NodeId>;
@@ -1424,7 +1422,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
14241422
) -> Option<(Vec<Segment>, Vec<String>)> {
14251423
// Replace first ident with `self` and check if that is valid.
14261424
path[0].ident.name = kw::SelfLower;
1427-
let result = self.r.resolve_path(&path, None, parent_scope, CrateLint::No);
1425+
let result = self.r.resolve_path(&path, None, parent_scope, Finalize::No);
14281426
debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result);
14291427
if let PathResult::Module(..) = result { Some((path, Vec::new())) } else { None }
14301428
}
@@ -1443,7 +1441,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
14431441
) -> Option<(Vec<Segment>, Vec<String>)> {
14441442
// Replace first ident with `crate` and check if that is valid.
14451443
path[0].ident.name = kw::Crate;
1446-
let result = self.r.resolve_path(&path, None, parent_scope, CrateLint::No);
1444+
let result = self.r.resolve_path(&path, None, parent_scope, Finalize::No);
14471445
debug!("make_missing_crate_suggestion: path={:?} result={:?}", path, result);
14481446
if let PathResult::Module(..) = result {
14491447
Some((
@@ -1474,7 +1472,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
14741472
) -> Option<(Vec<Segment>, Vec<String>)> {
14751473
// Replace first ident with `crate` and check if that is valid.
14761474
path[0].ident.name = kw::Super;
1477-
let result = self.r.resolve_path(&path, None, parent_scope, CrateLint::No);
1475+
let result = self.r.resolve_path(&path, None, parent_scope, Finalize::No);
14781476
debug!("make_missing_super_suggestion: path={:?} result={:?}", path, result);
14791477
if let PathResult::Module(..) = result { Some((path, Vec::new())) } else { None }
14801478
}
@@ -1508,7 +1506,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
15081506
for name in extern_crate_names.into_iter() {
15091507
// Replace first ident with a crate name and check if that is valid.
15101508
path[0].ident.name = name;
1511-
let result = self.r.resolve_path(&path, None, parent_scope, CrateLint::No);
1509+
let result = self.r.resolve_path(&path, None, parent_scope, Finalize::No);
15121510
debug!(
15131511
"make_external_crate_suggestion: name={:?} path={:?} result={:?}",
15141512
name, path, result

compiler/rustc_resolve/src/imports.rs

+17-18
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::Namespace::{self, MacroNS, TypeNS};
66
use crate::{module_to_string, names_to_string};
77
use crate::{AmbiguityError, AmbiguityErrorMisc, AmbiguityKind};
88
use crate::{BindingKey, ModuleKind, ResolutionError, Resolver, Segment};
9-
use crate::{CrateLint, Module, ModuleOrUniformRoot, ParentScope, PerNS, ScopeSet, Weak};
9+
use crate::{Finalize, Module, ModuleOrUniformRoot, ParentScope, PerNS, ScopeSet, Weak};
1010
use crate::{NameBinding, NameBindingKind, PathResult, PrivacyError, ToNameBinding};
1111

1212
use rustc_ast::NodeId;
@@ -175,29 +175,29 @@ impl<'a> Resolver<'a> {
175175
ident: Ident,
176176
ns: Namespace,
177177
parent_scope: &ParentScope<'a>,
178-
record_used: Option<Span>,
178+
finalize: Option<Span>,
179179
) -> Result<&'a NameBinding<'a>, Determinacy> {
180180
self.resolve_ident_in_module_unadjusted_ext(
181181
module,
182182
ident,
183183
ns,
184184
parent_scope,
185185
false,
186-
record_used,
186+
finalize,
187187
)
188188
.map_err(|(determinacy, _)| determinacy)
189189
}
190190

191191
/// Attempts to resolve `ident` in namespaces `ns` of `module`.
192-
/// Invariant: if `record_used` is `Some`, expansion and import resolution must be complete.
192+
/// Invariant: if `finalize` is `Some`, expansion and import resolution must be complete.
193193
crate fn resolve_ident_in_module_unadjusted_ext(
194194
&mut self,
195195
module: ModuleOrUniformRoot<'a>,
196196
ident: Ident,
197197
ns: Namespace,
198198
parent_scope: &ParentScope<'a>,
199199
restricted_shadowing: bool,
200-
record_used: Option<Span>,
200+
finalize: Option<Span>,
201201
) -> Result<&'a NameBinding<'a>, (Determinacy, Weak)> {
202202
let module = match module {
203203
ModuleOrUniformRoot::Module(module) => module,
@@ -207,17 +207,16 @@ impl<'a> Resolver<'a> {
207207
ident,
208208
ScopeSet::AbsolutePath(ns),
209209
parent_scope,
210-
record_used,
211-
record_used.is_some(),
210+
finalize,
211+
finalize.is_some(),
212212
);
213213
return binding.map_err(|determinacy| (determinacy, Weak::No));
214214
}
215215
ModuleOrUniformRoot::ExternPrelude => {
216216
assert!(!restricted_shadowing);
217217
return if ns != TypeNS {
218218
Err((Determined, Weak::No))
219-
} else if let Some(binding) = self.extern_prelude_get(ident, record_used.is_none())
220-
{
219+
} else if let Some(binding) = self.extern_prelude_get(ident, finalize.is_some()) {
221220
Ok(binding)
222221
} else if !self.graph_root.unexpanded_invocations.borrow().is_empty() {
223222
// Macro-expanded `extern crate` items can add names to extern prelude.
@@ -247,8 +246,8 @@ impl<'a> Resolver<'a> {
247246
ident,
248247
scopes,
249248
parent_scope,
250-
record_used,
251-
record_used.is_some(),
249+
finalize,
250+
finalize.is_some(),
252251
);
253252
return binding.map_err(|determinacy| (determinacy, Weak::No));
254253
}
@@ -258,7 +257,7 @@ impl<'a> Resolver<'a> {
258257
let resolution =
259258
self.resolution(module, key).try_borrow_mut().map_err(|_| (Determined, Weak::No))?; // This happens when there is a cycle of imports.
260259

261-
if let Some(binding) = resolution.binding && let Some(path_span) = record_used {
260+
if let Some(binding) = resolution.binding && let Some(path_span) = finalize {
262261
if !restricted_shadowing && binding.expansion != LocalExpnId::ROOT {
263262
if let NameBindingKind::Res(_, true) = binding.kind {
264263
self.macro_expanded_macro_export_errors.insert((path_span, binding.span));
@@ -276,7 +275,7 @@ impl<'a> Resolver<'a> {
276275
if usable { Ok(binding) } else { Err((Determined, Weak::No)) }
277276
};
278277

279-
if let Some(path_span) = record_used {
278+
if let Some(path_span) = finalize {
280279
return resolution
281280
.binding
282281
.and_then(|binding| {
@@ -773,7 +772,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
773772
// not define any names while resolving its module path.
774773
let orig_vis = import.vis.replace(ty::Visibility::Invisible);
775774
let path_res =
776-
self.r.resolve_path(&import.module_path, None, &import.parent_scope, CrateLint::No);
775+
self.r.resolve_path(&import.module_path, None, &import.parent_scope, Finalize::No);
777776
import.vis.set(orig_vis);
778777

779778
match path_res {
@@ -865,13 +864,13 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
865864
_ => None,
866865
};
867866
let prev_ambiguity_errors_len = self.r.ambiguity_errors.len();
868-
let crate_lint = CrateLint::UsePath {
867+
let finalize = Finalize::UsePath {
869868
root_id: import.root_id,
870869
root_span: import.root_span,
871870
path_span: import.span,
872871
};
873872
let path_res =
874-
self.r.resolve_path(&import.module_path, None, &import.parent_scope, crate_lint);
873+
self.r.resolve_path(&import.module_path, None, &import.parent_scope, finalize);
875874
let no_ambiguity = self.r.ambiguity_errors.len() == prev_ambiguity_errors_len;
876875
if let Some(orig_unusable_binding) = orig_unusable_binding {
877876
self.r.unusable_binding = orig_unusable_binding;
@@ -958,7 +957,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
958957
// 2 segments, so the `resolve_path` above won't trigger it.
959958
let mut full_path = import.module_path.clone();
960959
full_path.push(Segment::from_ident(Ident::empty()));
961-
self.r.lint_if_path_starts_with_module(crate_lint, &full_path, None);
960+
self.r.lint_if_path_starts_with_module(finalize, &full_path, None);
962961
}
963962

964963
if let ModuleOrUniformRoot::Module(module) = module {
@@ -1223,7 +1222,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
12231222
full_path.push(Segment::from_ident(ident));
12241223
self.r.per_ns(|this, ns| {
12251224
if let Ok(binding) = source_bindings[ns].get() {
1226-
this.lint_if_path_starts_with_module(crate_lint, &full_path, Some(binding));
1225+
this.lint_if_path_starts_with_module(finalize, &full_path, Some(binding));
12271226
}
12281227
});
12291228
}

0 commit comments

Comments
 (0)