Skip to content

Commit d7072b5

Browse files
committedJun 28, 2018
Fix rebase
1 parent 554b428 commit d7072b5

File tree

12 files changed

+71
-58
lines changed

12 files changed

+71
-58
lines changed
 

‎src/librustc/hir/lowering.rs

+18-17
Original file line numberDiff line numberDiff line change
@@ -676,15 +676,15 @@ impl<'a> LoweringContext<'a> {
676676
// that collisions are ok here and this shouldn't
677677
// really show up for end-user.
678678
let str_name = match hir_name {
679-
ParamName::Plain(ident) => name.as_interned_str(),
679+
ParamName::Plain(ident) => ident.as_interned_str(),
680680
ParamName::Fresh(_) => keywords::UnderscoreLifetime.name().as_interned_str(),
681681
};
682682

683683
// Add a definition for the in-band lifetime def
684684
self.resolver.definitions().create_def_with_parent(
685685
parent_id.index,
686686
def_node_id,
687-
DefPathData::LifetimeDef(str_name),
687+
DefPathData::LifetimeParam(str_name),
688688
DefIndexAddressSpace::High,
689689
Mark::root(),
690690
span,
@@ -719,10 +719,10 @@ impl<'a> LoweringContext<'a> {
719719
return;
720720
}
721721

722-
let hir_name = ParamName::Plain(name);
722+
let hir_name = ParamName::Plain(ident);
723723

724724
if self.lifetimes_to_define.iter()
725-
.any(|(_, lt_name)| *lt_name.modern() == hir_name.modern()) {
725+
.any(|(_, lt_name)| lt_name.modern() == hir_name.modern()) {
726726
return;
727727
}
728728

@@ -1185,10 +1185,11 @@ impl<'a> LoweringContext<'a> {
11851185
let ident = Ident::from_str(&pprust::ty_to_string(t)).with_span_pos(span);
11861186
self.in_band_ty_params.push(hir::GenericParam {
11871187
id: def_node_id,
1188-
ident: ParamName::Plain(ident),
1188+
name: ParamName::Plain(ident),
11891189
pure_wrt_drop: false,
11901190
attrs: hir_vec![],
11911191
bounds: hir_bounds,
1192+
span,
11921193
kind: hir::GenericParamKind::Type {
11931194
default: None,
11941195
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
@@ -1438,7 +1439,7 @@ impl<'a> LoweringContext<'a> {
14381439

14391440
let name = match name {
14401441
hir::LifetimeName::Underscore => {
1441-
hir::ParamName::Plain(keywords::UnderscoreLifetime.name())
1442+
hir::ParamName::Plain(keywords::UnderscoreLifetime.ident())
14421443
}
14431444
hir::LifetimeName::Param(param_name) => param_name,
14441445
_ => bug!("expected LifetimeName::Param or ParamName::Plain"),
@@ -2101,7 +2102,7 @@ impl<'a> LoweringContext<'a> {
21012102
let future_params = P(hir::GenericArgs {
21022103
args: hir_vec![],
21032104
bindings: hir_vec![hir::TypeBinding {
2104-
name: Symbol::intern(FN_OUTPUT_NAME),
2105+
ident: Ident::from_str(FN_OUTPUT_NAME),
21052106
ty: output_ty,
21062107
id: this.next_id().node_id,
21072108
span,
@@ -2163,7 +2164,7 @@ impl<'a> LoweringContext<'a> {
21632164

21642165
fn lower_lifetime(&mut self, l: &Lifetime) -> hir::Lifetime {
21652166
let span = l.ident.span;
2166-
match self.lower_ident(l.ident) {
2167+
match l.ident {
21672168
ident if ident.name == keywords::StaticLifetime.name() =>
21682169
self.new_named_lifetime(l.id, span, hir::LifetimeName::Static),
21692170
ident if ident.name == keywords::UnderscoreLifetime.name() =>
@@ -2221,7 +2222,7 @@ impl<'a> LoweringContext<'a> {
22212222
let lt = self.lower_lifetime(&Lifetime { id: param.id, ident: param.ident });
22222223
let param_name = match lt.name {
22232224
hir::LifetimeName::Param(param_name) => param_name,
2224-
_ => hir::ParamName::Plain(lt.name.name()),
2225+
_ => hir::ParamName::Plain(lt.name.ident()),
22252226
};
22262227
let param = hir::GenericParam {
22272228
id: lt.id,
@@ -2238,14 +2239,14 @@ impl<'a> LoweringContext<'a> {
22382239
param
22392240
}
22402241
GenericParamKind::Type { ref default, .. } => {
2241-
let mut name = self.lower_ident(param.ident);
2242-
22432242
// Don't expose `Self` (recovered "keyword used as ident" parse error).
22442243
// `rustc::ty` expects `Self` to be only used for a trait's `Self`.
22452244
// Instead, use gensym("Self") to create a distinct name that looks the same.
2246-
if name == keywords::SelfType.name() {
2247-
name = Symbol::gensym("Self");
2248-
}
2245+
let ident = if param.ident.name == keywords::SelfType.name() {
2246+
param.ident.gensym()
2247+
} else {
2248+
param.ident
2249+
};
22492250

22502251
let add_bounds = add_bounds.get(&param.id).map_or(&[][..], |x| &x);
22512252
if !add_bounds.is_empty() {
@@ -2256,11 +2257,11 @@ impl<'a> LoweringContext<'a> {
22562257

22572258
hir::GenericParam {
22582259
id: self.lower_node_id(param.id).node_id,
2259-
name: hir::ParamName::Plain(name),
2260-
span: param.ident.span,
2260+
name: hir::ParamName::Plain(ident),
22612261
pure_wrt_drop: attr::contains_name(&param.attrs, "may_dangle"),
22622262
attrs: self.lower_attrs(&param.attrs),
22632263
bounds,
2264+
span: ident.span,
22642265
kind: hir::GenericParamKind::Type {
22652266
default: default.as_ref().map(|x| {
22662267
self.lower_ty(x, ImplTraitContext::Disallowed)
@@ -3656,7 +3657,7 @@ impl<'a> LoweringContext<'a> {
36563657
let e2 = self.lower_expr(e2);
36573658
let ty_path = P(self.std_path(span, &["ops", "RangeInclusive"], None, false));
36583659
let ty = P(self.ty_path(id, span, hir::QPath::Resolved(None, ty_path)));
3659-
let new_seg = P(hir::PathSegment::from_name(Ident::from_str("new")));
3660+
let new_seg = P(hir::PathSegment::from_ident(Ident::from_str("new")));
36603661
let new_path = hir::QPath::TypeRelative(ty, new_seg);
36613662
let new = P(self.expr(span, hir::ExprPath(new_path), ThinVec::new()));
36623663
hir::ExprCall(new, hir_vec![e1, e2])

‎src/librustc/hir/map/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ impl<'hir> Map<'hir> {
616616
NodeItem(&Item { node: ItemTrait(..), .. }) => {
617617
keywords::SelfType.name()
618618
}
619-
NodeGenericParam(param) => param.name.ident(),
619+
NodeGenericParam(param) => param.name.ident().name,
620620
_ => bug!("ty_param_name: {} not a type parameter", self.node_to_string(id)),
621621
}
622622
}
@@ -955,7 +955,7 @@ impl<'hir> Map<'hir> {
955955
NodeField(f) => f.ident.name,
956956
NodeLifetime(lt) => lt.name.ident().name,
957957
NodeGenericParam(param) => param.name.ident().name,
958-
NodeBinding(&Pat { node: PatKind::Binding(_,_,l,_), .. }) => l.node,
958+
NodeBinding(&Pat { node: PatKind::Binding(_,_,l,_), .. }) => l.name,
959959
NodeStructCtor(_) => self.name(self.get_parent(id)),
960960
_ => bug!("no name for {}", self.node_to_string(id))
961961
}
@@ -1021,7 +1021,7 @@ impl<'hir> Map<'hir> {
10211021
Some(EntryBlock(_, _, block)) => block.span,
10221022
Some(EntryStructCtor(_, _, _)) => self.expect_item(self.get_parent(id)).span,
10231023
Some(EntryLifetime(_, _, lifetime)) => lifetime.span,
1024-
Some(EntryGenericParam(_, _, param)) => param.ident.span,
1024+
Some(EntryGenericParam(_, _, param)) => param.span,
10251025
Some(EntryVisibility(_, _, &Visibility::Restricted { ref path, .. })) => path.span,
10261026
Some(EntryVisibility(_, _, v)) => bug!("unexpected Visibility {:?}", v),
10271027
Some(EntryLocal(_, _, local)) => local.span,

‎src/librustc/hir/mod.rs

+17-11
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ pub struct Lifetime {
201201
#[derive(Debug, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
202202
pub enum ParamName {
203203
/// Some user-given name like `T` or `'x`.
204-
Plain(Name),
204+
Plain(Ident),
205205

206206
/// Synthetic name generated when user elided a lifetime in an impl header,
207207
/// e.g. the lifetimes in cases like these:
@@ -220,10 +220,17 @@ pub enum ParamName {
220220
}
221221

222222
impl ParamName {
223-
pub fn name(&self) -> Name {
223+
pub fn ident(&self) -> Ident {
224+
match *self {
225+
ParamName::Plain(ident) => ident,
226+
ParamName::Fresh(_) => keywords::UnderscoreLifetime.ident(),
227+
}
228+
}
229+
230+
pub fn modern(&self) -> ParamName {
224231
match *self {
225-
ParamName::Plain(name) => name,
226-
ParamName::Fresh(_) => keywords::UnderscoreLifetime.name(),
232+
ParamName::Plain(ident) => ParamName::Plain(ident.modern()),
233+
param_name => param_name,
227234
}
228235
}
229236
}
@@ -247,24 +254,22 @@ impl LifetimeName {
247254
pub fn ident(&self) -> Ident {
248255
match *self {
249256
LifetimeName::Implicit => keywords::Invalid.ident(),
250-
LifetimeName::Fresh(_) | LifetimeName::Underscore =>
251-
keywords::UnderscoreLifetime.ident(),
257+
LifetimeName::Underscore => keywords::UnderscoreLifetime.ident(),
252258
LifetimeName::Static => keywords::StaticLifetime.ident(),
253-
LifetimeName::Ident(ident) => ident,
259+
LifetimeName::Param(param_name) => param_name.ident(),
254260
}
255261
}
256262

257263
pub fn is_elided(&self) -> bool {
258-
use self::LifetimeName::*;
259264
match self {
260-
Implicit | Underscore => true,
265+
LifetimeName::Implicit | LifetimeName::Underscore => true,
261266

262267
// It might seem surprising that `Fresh(_)` counts as
263268
// *not* elided -- but this is because, as far as the code
264269
// in the compiler is concerned -- `Fresh(_)` variants act
265270
// equivalently to "some fresh name". They correspond to
266271
// early-bound regions on an impl, in other words.
267-
Param(_) | Static => false,
272+
LifetimeName::Param(_) | LifetimeName::Static => false,
268273
}
269274
}
270275

@@ -274,7 +279,7 @@ impl LifetimeName {
274279

275280
pub fn modern(&self) -> LifetimeName {
276281
match *self {
277-
LifetimeName::Ident(ident) => LifetimeName::Ident(ident.modern()),
282+
LifetimeName::Param(param_name) => LifetimeName::Param(param_name.modern()),
278283
lifetime_name => lifetime_name,
279284
}
280285
}
@@ -492,6 +497,7 @@ pub struct GenericParam {
492497
pub name: ParamName,
493498
pub attrs: HirVec<Attribute>,
494499
pub bounds: GenericBounds,
500+
pub span: Span,
495501
pub pure_wrt_drop: bool,
496502

497503
pub kind: GenericParamKind,

‎src/librustc/hir/print.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2113,7 +2113,7 @@ impl<'a> State<'a> {
21132113
}
21142114

21152115
pub fn print_generic_param(&mut self, param: &GenericParam) -> io::Result<()> {
2116-
self.print_name(param.name.name())?;
2116+
self.print_ident(param.name.ident())?;
21172117
match param.kind {
21182118
GenericParamKind::Lifetime { .. } => {
21192119
let mut sep = ":";
@@ -2144,7 +2144,7 @@ impl<'a> State<'a> {
21442144
}
21452145

21462146
pub fn print_lifetime(&mut self, lifetime: &hir::Lifetime) -> io::Result<()> {
2147-
self.print_name(lifetime.name.name())
2147+
self.print_ident(lifetime.name.ident())
21482148
}
21492149

21502150
pub fn print_where_clause(&mut self, where_clause: &hir::WhereClause) -> io::Result<()> {

‎src/librustc/ich/impls_hir.rs

+1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ impl_stable_hash_for!(struct hir::GenericParam {
203203
pure_wrt_drop,
204204
attrs,
205205
bounds,
206+
span,
206207
kind
207208
});
208209

‎src/librustc/middle/resolve_lifetime.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
689689
GenericParamKind::Lifetime { .. } => {
690690
let (name, reg) = Region::early(&self.tcx.hir, &mut index, &param);
691691
if let hir::ParamName::Plain(param_name) = name {
692-
if param_name == keywords::UnderscoreLifetime.name() {
692+
if param_name.name == keywords::UnderscoreLifetime.name() {
693693
// Pick the elided lifetime "definition" if one exists
694694
// and use it to make an elision scope.
695695
elision = Some(reg);
@@ -1175,7 +1175,7 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body) {
11751175
ref lifetimes, s, ..
11761176
} => {
11771177
// FIXME (#24278): non-hygienic comparison
1178-
if let Some(def) = lifetimes.get(&hir::LifetimeName::Ident(label.modern())) {
1178+
if let Some(def) = lifetimes.get(&hir::ParamName::Plain(label.modern())) {
11791179
let node_id = tcx.hir.as_local_node_id(def.id().unwrap()).unwrap();
11801180

11811181
signal_shadowing_problem(
@@ -1397,10 +1397,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
13971397
debug!("node id first={:?}", node_id);
13981398
if let Some((id, span, name)) = match self.tcx.hir.get(node_id) {
13991399
hir::map::NodeLifetime(hir_lifetime) => {
1400-
Some((hir_lifetime.id, hir_lifetime.span, hir_lifetime.name.name()))
1400+
Some((hir_lifetime.id, hir_lifetime.span, hir_lifetime.name.ident()))
14011401
}
14021402
hir::map::NodeGenericParam(param) => {
1403-
Some((param.id, param.span, param.name.name()))
1403+
Some((param.id, param.span, param.name.ident()))
14041404
}
14051405
_ => None,
14061406
} {
@@ -1423,10 +1423,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14231423
let node_id = self.tcx.hir.as_local_node_id(def_id).unwrap();
14241424
if let Some((id, span, name)) = match self.tcx.hir.get(node_id) {
14251425
hir::map::NodeLifetime(hir_lifetime) => {
1426-
Some((hir_lifetime.id, hir_lifetime.span, hir_lifetime.name.name()))
1426+
Some((hir_lifetime.id, hir_lifetime.span, hir_lifetime.name.ident()))
14271427
}
14281428
hir::map::NodeGenericParam(param) => {
1429-
Some((param.id, param.span, param.name.name()))
1429+
Some((param.id, param.span, param.name.ident()))
14301430
}
14311431
_ => None,
14321432
} {
@@ -2243,15 +2243,15 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
22432243
}).collect();
22442244
for (i, (lifetime_i, lifetime_i_name)) in lifetimes.iter().enumerate() {
22452245
if let hir::ParamName::Plain(_) = lifetime_i_name {
2246-
let name = lifetime_i_name.name();
2246+
let name = lifetime_i_name.ident().name;
22472247
if name == keywords::UnderscoreLifetime.name() ||
22482248
name == keywords::StaticLifetime.name() {
22492249
let mut err = struct_span_err!(
22502250
self.tcx.sess,
22512251
lifetime_i.span,
22522252
E0262,
22532253
"invalid lifetime parameter name: `{}`",
2254-
lifetime
2254+
lifetime_i.name.ident(),
22552255
);
22562256
err.span_label(
22572257
lifetime_i.span,
@@ -2269,7 +2269,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
22692269
lifetime_j.span,
22702270
E0263,
22712271
"lifetime name `{}` declared twice in the same scope",
2272-
lifetime_j.name.name()
2272+
lifetime_j.name.ident()
22732273
).span_label(lifetime_j.span, "declared twice")
22742274
.span_label(lifetime_i.span, "previous declaration here")
22752275
.emit();
@@ -2298,12 +2298,12 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
22982298
lifetime_i.span.to(lt.span),
22992299
&format!(
23002300
"unnecessary lifetime parameter `{}`",
2301-
lifetime_i.name.name(),
2301+
lifetime_i.name.ident(),
23022302
),
23032303
).help(&format!(
23042304
"you can use the `'static` lifetime directly, in place \
23052305
of `{}`",
2306-
lifetime_i.name.name(),
2306+
lifetime_i.name.ident(),
23072307
)).emit();
23082308
}
23092309
hir::LifetimeName::Param(_)
@@ -2549,7 +2549,7 @@ fn insert_late_bound_lifetimes(
25492549
}
25502550

25512551
debug!("insert_late_bound_lifetimes: lifetime {:?} with id {:?} is late-bound",
2552-
param.name.name(),
2552+
param.name.ident(),
25532553
param.id);
25542554

25552555
let inserted = map.late_bound.insert(param.id);

‎src/librustc_mir/hair/pattern/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchVisitor, pat: &Pat) {
331331
err.span_suggestion_with_applicability(
332332
p.span,
333333
"to match on the variant, qualify the path",
334-
format!("{}::{}", ty_path, name.node),
334+
format!("{}::{}", ty_path, ident),
335335
Applicability::MachineApplicable
336336
);
337337
err.emit();

‎src/librustc_resolve/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1497,17 +1497,17 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
14971497
args: Option<P<hir::GenericArgs>>,
14981498
is_value: bool
14991499
) -> hir::Path {
1500-
let mut segments = iter::once(keywords::CrateRoot.name())
1500+
let mut segments = iter::once(keywords::CrateRoot.ident())
15011501
.chain(
15021502
crate_root.into_iter()
15031503
.chain(components.iter().cloned())
1504-
.map(Symbol::intern)
1505-
).map(hir::PathSegment::from_name).collect::<Vec<_>>();
1504+
.map(Ident::from_str)
1505+
).map(hir::PathSegment::from_ident).collect::<Vec<_>>();
15061506

15071507
if let Some(args) = args {
1508-
let name = segments.last().unwrap().name;
1508+
let ident = segments.last().unwrap().ident;
15091509
*segments.last_mut().unwrap() = hir::PathSegment {
1510-
name,
1510+
ident,
15111511
args: Some(args),
15121512
infer_types: true,
15131513
};

‎src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3836,7 +3836,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
38363836
// ... except when we try to 'break rust;'.
38373837
// ICE this expression in particular (see #43162).
38383838
if let hir::ExprPath(hir::QPath::Resolved(_, ref path)) = e.node {
3839-
if path.segments.len() == 1 && path.segments[0].name == "rust" {
3839+
if path.segments.len() == 1 && path.segments[0].ident.name == "rust" {
38403840
fatally_break_rust(self.tcx.sess);
38413841
}
38423842
}

‎src/librustdoc/clean/auto_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
251251
match param.kind {
252252
ty::GenericParamDefKind::Lifetime => {
253253
let name = if param.name == "" {
254-
hir::ParamName::Plain(keywords::StaticLifetime.name())
254+
hir::ParamName::Plain(keywords::StaticLifetime.ident())
255255
} else {
256256
hir::ParamName::Plain(ast::Ident::from_interned_str(param.name))
257257
};

‎src/librustdoc/clean/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1896,19 +1896,19 @@ impl Clean<GenericParamDef> for hir::GenericParam {
18961896
hir::GenericBound::Outlives(lt) => lt,
18971897
_ => panic!(),
18981898
});
1899-
let name = bounds.next().unwrap().name.name();
1900-
let mut s = format!("{}: {}", self.name.name(), name);
1899+
let name = bounds.next().unwrap().name.ident();
1900+
let mut s = format!("{}: {}", self.name.ident(), name);
19011901
for bound in bounds {
1902-
s.push_str(&format!(" + {}", bound.name.name()));
1902+
s.push_str(&format!(" + {}", bound.name.ident()));
19031903
}
19041904
s
19051905
} else {
1906-
self.name.name().to_string()
1906+
self.name.ident().to_string()
19071907
};
19081908
(name, GenericParamDefKind::Lifetime)
19091909
}
19101910
hir::GenericParamKind::Type { ref default, synthetic, .. } => {
1911-
(self.name.name().clean(cx), GenericParamDefKind::Type {
1911+
(self.name.ident().name.clean(cx), GenericParamDefKind::Type {
19121912
did: cx.tcx.hir.local_def_id(self.id),
19131913
bounds: self.bounds.clean(cx),
19141914
default: default.clean(cx),

‎src/libsyntax_pos/symbol.rs

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ impl Ident {
5959
Ident::new(Symbol::intern(self.as_str().trim_left_matches('\'')), self.span)
6060
}
6161

62+
/// "Normalize" ident for use in comparisons using "item hygiene".
63+
/// Identifiers with same string value become same if they came from the same "modern" macro
64+
/// (e.g. `macro` item, but not `macro_rules` item) and stay different if they came from
65+
/// different "modern" macros.
66+
/// Technically, this operation strips all non-opaque marks from ident's syntactic context.
6267
pub fn modern(self) -> Ident {
6368
Ident::new(self.name, self.span.modern())
6469
}

0 commit comments

Comments
 (0)
Please sign in to comment.