Skip to content

Commit db638bd

Browse files
committed
hygiene: modern -> normalize_to_macros_2_0
`modern_and_legacy` -> `normalize_to_macro_rules`
1 parent 8c9a38f commit db638bd

File tree

21 files changed

+141
-110
lines changed

21 files changed

+141
-110
lines changed

src/librustc/ty/mod.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -3083,7 +3083,7 @@ impl<'tcx> TyCtxt<'tcx> {
30833083
pub fn hygienic_eq(self, use_name: Ident, def_name: Ident, def_parent_def_id: DefId) -> bool {
30843084
// We could use `Ident::eq` here, but we deliberately don't. The name
30853085
// comparison fails frequently, and we want to avoid the expensive
3086-
// `modern()` calls required for the span comparison whenever possible.
3086+
// `normalize_to_macros_2_0()` calls required for the span comparison whenever possible.
30873087
use_name.name == def_name.name
30883088
&& use_name
30893089
.span
@@ -3099,7 +3099,7 @@ impl<'tcx> TyCtxt<'tcx> {
30993099
}
31003100

31013101
pub fn adjust_ident(self, mut ident: Ident, scope: DefId) -> Ident {
3102-
ident.span.modernize_and_adjust(self.expansion_that_defined(scope));
3102+
ident.span.normalize_to_macros_2_0_and_adjust(self.expansion_that_defined(scope));
31033103
ident
31043104
}
31053105

@@ -3109,12 +3109,14 @@ impl<'tcx> TyCtxt<'tcx> {
31093109
scope: DefId,
31103110
block: hir::HirId,
31113111
) -> (Ident, DefId) {
3112-
let scope = match ident.span.modernize_and_adjust(self.expansion_that_defined(scope)) {
3113-
Some(actual_expansion) => {
3114-
self.hir().definitions().parent_module_of_macro_def(actual_expansion)
3115-
}
3116-
None => self.parent_module(block),
3117-
};
3112+
let scope =
3113+
match ident.span.normalize_to_macros_2_0_and_adjust(self.expansion_that_defined(scope))
3114+
{
3115+
Some(actual_expansion) => {
3116+
self.hir().definitions().parent_module_of_macro_def(actual_expansion)
3117+
}
3118+
None => self.parent_module(block),
3119+
};
31183120
(ident, scope)
31193121
}
31203122

src/librustc_ast_lowering/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
115115
_ => &[],
116116
};
117117
let lt_def_names = parent_generics.iter().filter_map(|param| match param.kind {
118-
hir::GenericParamKind::Lifetime { .. } => Some(param.name.modern()),
118+
hir::GenericParamKind::Lifetime { .. } => Some(param.name.normalize_to_macros_2_0()),
119119
_ => None,
120120
});
121121
self.in_scope_lifetimes.extend(lt_def_names);

src/librustc_ast_lowering/lib.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ struct LoweringContext<'a, 'hir: 'a> {
153153
/// against this list to see if it is already in-scope, or if a definition
154154
/// needs to be created for it.
155155
///
156-
/// We always store a `modern()` version of the param-name in this
156+
/// We always store a `normalize_to_macros_2_0()` version of the param-name in this
157157
/// vector.
158158
in_scope_lifetimes: Vec<ParamName>,
159159

@@ -805,14 +805,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
805805
return;
806806
}
807807

808-
if self.in_scope_lifetimes.contains(&ParamName::Plain(ident.modern())) {
808+
if self.in_scope_lifetimes.contains(&ParamName::Plain(ident.normalize_to_macros_2_0())) {
809809
return;
810810
}
811811

812812
let hir_name = ParamName::Plain(ident);
813813

814-
if self.lifetimes_to_define.iter().any(|(_, lt_name)| lt_name.modern() == hir_name.modern())
815-
{
814+
if self.lifetimes_to_define.iter().any(|(_, lt_name)| {
815+
lt_name.normalize_to_macros_2_0() == hir_name.normalize_to_macros_2_0()
816+
}) {
816817
return;
817818
}
818819

@@ -840,7 +841,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
840841
) -> T {
841842
let old_len = self.in_scope_lifetimes.len();
842843
let lt_def_names = params.iter().filter_map(|param| match param.kind {
843-
GenericParamKind::Lifetime { .. } => Some(ParamName::Plain(param.ident.modern())),
844+
GenericParamKind::Lifetime { .. } => {
845+
Some(ParamName::Plain(param.ident.normalize_to_macros_2_0()))
846+
}
844847
_ => None,
845848
});
846849
self.in_scope_lifetimes.extend(lt_def_names);

src/librustc_hir/hir.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ impl ParamName {
7979
}
8080
}
8181

82-
pub fn modern(&self) -> ParamName {
82+
pub fn normalize_to_macros_2_0(&self) -> ParamName {
8383
match *self {
84-
ParamName::Plain(ident) => ParamName::Plain(ident.modern()),
84+
ParamName::Plain(ident) => ParamName::Plain(ident.normalize_to_macros_2_0()),
8585
param_name => param_name,
8686
}
8787
}
@@ -151,9 +151,11 @@ impl LifetimeName {
151151
self == &LifetimeName::Static
152152
}
153153

154-
pub fn modern(&self) -> LifetimeName {
154+
pub fn normalize_to_macros_2_0(&self) -> LifetimeName {
155155
match *self {
156-
LifetimeName::Param(param_name) => LifetimeName::Param(param_name.modern()),
156+
LifetimeName::Param(param_name) => {
157+
LifetimeName::Param(param_name.normalize_to_macros_2_0())
158+
}
157159
lifetime_name => lifetime_name,
158160
}
159161
}

src/librustc_mir/monomorphize/collector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1088,9 +1088,9 @@ fn create_mono_items_for_default_impls<'tcx>(
10881088
let param_env = ty::ParamEnv::reveal_all();
10891089
let trait_ref = tcx.normalize_erasing_regions(param_env, trait_ref);
10901090
let overridden_methods: FxHashSet<_> =
1091-
items.iter().map(|iiref| iiref.ident.modern()).collect();
1091+
items.iter().map(|iiref| iiref.ident.normalize_to_macros_2_0()).collect();
10921092
for method in tcx.provided_trait_methods(trait_ref.def_id) {
1093-
if overridden_methods.contains(&method.ident.modern()) {
1093+
if overridden_methods.contains(&method.ident.normalize_to_macros_2_0()) {
10941094
continue;
10951095
}
10961096

src/librustc_resolve/build_reduced_graph.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
645645
self.r.potentially_unused_imports.push(import);
646646
let imported_binding = self.r.import(binding, import);
647647
if ptr::eq(parent, self.r.graph_root) {
648-
if let Some(entry) = self.r.extern_prelude.get(&ident.modern()) {
648+
if let Some(entry) = self.r.extern_prelude.get(&ident.normalize_to_macros_2_0())
649+
{
649650
if expansion != ExpnId::root()
650651
&& orig_name.is_some()
651652
&& entry.extern_crate_item.is_none()
@@ -656,10 +657,12 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
656657
}
657658
}
658659
let entry =
659-
self.r.extern_prelude.entry(ident.modern()).or_insert(ExternPreludeEntry {
660-
extern_crate_item: None,
661-
introduced_by_item: true,
662-
});
660+
self.r.extern_prelude.entry(ident.normalize_to_macros_2_0()).or_insert(
661+
ExternPreludeEntry {
662+
extern_crate_item: None,
663+
introduced_by_item: true,
664+
},
665+
);
663666
entry.extern_crate_item = Some(imported_binding);
664667
if orig_name.is_some() {
665668
entry.introduced_by_item = true;
@@ -1119,7 +1122,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
11191122
self.r.local_macro_def_scopes.insert(item.id, parent_scope.module);
11201123

11211124
if macro_rules {
1122-
let ident = ident.modern();
1125+
let ident = ident.normalize_to_macros_2_0();
11231126
self.r.macro_names.insert(ident);
11241127
let is_macro_export = attr::contains_name(&item.attrs, sym::macro_export);
11251128
let vis = if is_macro_export {

src/librustc_resolve/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ impl<'a> Resolver<'a> {
758758
let msg = format!("unsafe traits like `{}` should be implemented explicitly", ident);
759759
err.span_note(ident.span, &msg);
760760
}
761-
if self.macro_names.contains(&ident.modern()) {
761+
if self.macro_names.contains(&ident.normalize_to_macros_2_0()) {
762762
err.help("have you added the `#[macro_use]` on the module/import?");
763763
}
764764
}

src/librustc_resolve/imports.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,8 @@ impl<'a> Resolver<'a> {
416416
None => return Err((Undetermined, Weak::Yes)),
417417
};
418418
let tmp_parent_scope;
419-
let (mut adjusted_parent_scope, mut ident) = (parent_scope, ident.modern());
419+
let (mut adjusted_parent_scope, mut ident) =
420+
(parent_scope, ident.normalize_to_macros_2_0());
420421
match ident.span.glob_adjust(module.expansion, glob_import.span) {
421422
Some(Some(def)) => {
422423
tmp_parent_scope =

src/librustc_resolve/late.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
935935
_ => unreachable!(),
936936
};
937937

938-
let ident = param.ident.modern();
938+
let ident = param.ident.normalize_to_macros_2_0();
939939
debug!("with_generic_param_rib: {}", param.id);
940940

941941
if seen_bindings.contains_key(&ident) {
@@ -1464,7 +1464,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
14641464
// Add the binding to the local ribs, if it doesn't already exist in the bindings map.
14651465
// (We must not add it if it's in the bindings map because that breaks the assumptions
14661466
// later passes make about or-patterns.)
1467-
let ident = ident.modern_and_legacy();
1467+
let ident = ident.normalize_to_macro_rules();
14681468

14691469
let mut bound_iter = bindings.iter().filter(|(_, set)| set.contains(&ident));
14701470
// Already bound in a product pattern? e.g. `(a, a)` which is not allowed.
@@ -1873,7 +1873,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
18731873
self.diagnostic_metadata.unused_labels.insert(id, label.ident.span);
18741874
}
18751875
self.with_label_rib(NormalRibKind, |this| {
1876-
let ident = label.ident.modern_and_legacy();
1876+
let ident = label.ident.normalize_to_macro_rules();
18771877
this.label_ribs.last_mut().unwrap().bindings.insert(ident, id);
18781878
f(this);
18791879
});
@@ -1949,7 +1949,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
19491949

19501950
ExprKind::Break(Some(label), _) | ExprKind::Continue(Some(label)) => {
19511951
let node_id = self.search_label(label.ident, |rib, ident| {
1952-
rib.bindings.get(&ident.modern_and_legacy()).cloned()
1952+
rib.bindings.get(&ident.normalize_to_macro_rules()).cloned()
19531953
});
19541954
match node_id {
19551955
None => {
@@ -2115,7 +2115,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
21152115
}
21162116
}
21172117

2118-
ident.span = ident.span.modern();
2118+
ident.span = ident.span.normalize_to_macros_2_0();
21192119
let mut search_module = self.parent_scope.module;
21202120
loop {
21212121
self.get_traits_in_module_containing_item(ident, ns, search_module, &mut found_traits);

src/librustc_resolve/late/lifetimes.rs

+16-11
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl RegionExt for Region {
6262
let def_id = hir_map.local_def_id(param.hir_id);
6363
let origin = LifetimeDefOrigin::from_param(param);
6464
debug!("Region::early: index={} def_id={:?}", i, def_id);
65-
(param.name.modern(), Region::EarlyBound(i, def_id, origin))
65+
(param.name.normalize_to_macros_2_0(), Region::EarlyBound(i, def_id, origin))
6666
}
6767

6868
fn late(hir_map: &Map<'_>, param: &GenericParam<'_>) -> (ParamName, Region) {
@@ -73,7 +73,7 @@ impl RegionExt for Region {
7373
"Region::late: param={:?} depth={:?} def_id={:?} origin={:?}",
7474
param, depth, def_id, origin,
7575
);
76-
(param.name.modern(), Region::LateBound(depth, def_id, origin))
76+
(param.name.normalize_to_macros_2_0(), Region::LateBound(depth, def_id, origin))
7777
}
7878

7979
fn late_anon(index: &Cell<u32>) -> Region {
@@ -1174,7 +1174,9 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body<'_>) {
11741174

11751175
Scope::Binder { ref lifetimes, s, .. } => {
11761176
// FIXME (#24278): non-hygienic comparison
1177-
if let Some(def) = lifetimes.get(&hir::ParamName::Plain(label.modern())) {
1177+
if let Some(def) =
1178+
lifetimes.get(&hir::ParamName::Plain(label.normalize_to_macros_2_0()))
1179+
{
11781180
let hir_id = tcx.hir().as_local_hir_id(def.id().unwrap()).unwrap();
11791181

11801182
signal_shadowing_problem(
@@ -1253,7 +1255,7 @@ fn object_lifetime_defaults_for_item(
12531255
fn add_bounds(set: &mut Set1<hir::LifetimeName>, bounds: &[hir::GenericBound<'_>]) {
12541256
for bound in bounds {
12551257
if let hir::GenericBound::Outlives(ref lifetime) = *bound {
1256-
set.insert(lifetime.name.modern());
1258+
set.insert(lifetime.name.normalize_to_macros_2_0());
12571259
}
12581260
}
12591261
}
@@ -1791,7 +1793,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
17911793
Scope::Binder { ref lifetimes, s, .. } => {
17921794
match lifetime_ref.name {
17931795
LifetimeName::Param(param_name) => {
1794-
if let Some(&def) = lifetimes.get(&param_name.modern()) {
1796+
if let Some(&def) = lifetimes.get(&param_name.normalize_to_macros_2_0())
1797+
{
17951798
break Some(def.shifted(late_depth));
17961799
}
17971800
}
@@ -2544,7 +2547,9 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
25442547
let lifetimes: Vec<_> = params
25452548
.iter()
25462549
.filter_map(|param| match param.kind {
2547-
GenericParamKind::Lifetime { .. } => Some((param, param.name.modern())),
2550+
GenericParamKind::Lifetime { .. } => {
2551+
Some((param, param.name.normalize_to_macros_2_0()))
2552+
}
25482553
_ => None,
25492554
})
25502555
.collect();
@@ -2661,7 +2666,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
26612666
}
26622667

26632668
Scope::Binder { ref lifetimes, s, .. } => {
2664-
if let Some(&def) = lifetimes.get(&param.name.modern()) {
2669+
if let Some(&def) = lifetimes.get(&param.name.normalize_to_macros_2_0()) {
26652670
let hir_id = self.tcx.hir().as_local_hir_id(def.id().unwrap()).unwrap();
26662671

26672672
signal_shadowing_problem(
@@ -2799,7 +2804,7 @@ fn insert_late_bound_lifetimes(
27992804
// `'a: 'b` means both `'a` and `'b` are referenced
28002805
appears_in_where_clause
28012806
.regions
2802-
.insert(hir::LifetimeName::Param(param.name.modern()));
2807+
.insert(hir::LifetimeName::Param(param.name.normalize_to_macros_2_0()));
28032808
}
28042809
}
28052810
}
@@ -2821,7 +2826,7 @@ fn insert_late_bound_lifetimes(
28212826
hir::GenericParamKind::Type { .. } | hir::GenericParamKind::Const { .. } => continue,
28222827
}
28232828

2824-
let lt_name = hir::LifetimeName::Param(param.name.modern());
2829+
let lt_name = hir::LifetimeName::Param(param.name.normalize_to_macros_2_0());
28252830
// appears in the where clauses? early-bound.
28262831
if appears_in_where_clause.regions.contains(&lt_name) {
28272832
continue;
@@ -2885,7 +2890,7 @@ fn insert_late_bound_lifetimes(
28852890
}
28862891

28872892
fn visit_lifetime(&mut self, lifetime_ref: &'v hir::Lifetime) {
2888-
self.regions.insert(lifetime_ref.name.modern());
2893+
self.regions.insert(lifetime_ref.name.normalize_to_macros_2_0());
28892894
}
28902895
}
28912896

@@ -2902,7 +2907,7 @@ fn insert_late_bound_lifetimes(
29022907
}
29032908

29042909
fn visit_lifetime(&mut self, lifetime_ref: &'v hir::Lifetime) {
2905-
self.regions.insert(lifetime_ref.name.modern());
2910+
self.regions.insert(lifetime_ref.name.normalize_to_macros_2_0());
29062911
}
29072912
}
29082913
}

0 commit comments

Comments
 (0)