Skip to content

Commit 72fd35a

Browse files
committed
Use Idents for path segments in HIR
1 parent ade1d28 commit 72fd35a

File tree

16 files changed

+94
-96
lines changed

16 files changed

+94
-96
lines changed

src/librustc/hir/intravisit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) {
634634
pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V,
635635
path_span: Span,
636636
segment: &'v PathSegment) {
637-
visitor.visit_name(path_span, segment.name);
637+
visitor.visit_ident(segment.ident);
638638
if let Some(ref parameters) = segment.parameters {
639639
visitor.visit_path_parameters(path_span, parameters);
640640
}

src/librustc/hir/lowering.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,8 @@ impl<'a> LoweringContext<'a> {
575575
self.sess.diagnostic()
576576
}
577577

578-
fn str_to_ident(&self, s: &'static str) -> Name {
579-
Symbol::gensym(s)
578+
fn str_to_ident(&self, s: &'static str) -> Ident {
579+
Ident::with_empty_ctxt(Symbol::gensym(s))
580580
}
581581

582582
fn allow_internal_unstable(&self, reason: CompilerDesugaringKind, span: Span) -> Span {
@@ -1072,7 +1072,7 @@ impl<'a> LoweringContext<'a> {
10721072
None,
10731073
P(hir::Path {
10741074
def: self.expect_full_def(t.id),
1075-
segments: hir_vec![hir::PathSegment::from_name(keywords::SelfType.name())],
1075+
segments: hir_vec![hir::PathSegment::from_ident(keywords::SelfType.ident())],
10761076
span: t.span,
10771077
}),
10781078
)),
@@ -1145,9 +1145,9 @@ impl<'a> LoweringContext<'a> {
11451145

11461146
let hir_bounds = self.lower_bounds(bounds, itctx);
11471147
// Set the name to `impl Bound1 + Bound2`
1148-
let name = Symbol::intern(&pprust::ty_to_string(t));
1148+
let ident = Ident::from_str(&pprust::ty_to_string(t));
11491149
self.in_band_ty_params.push(hir::TyParam {
1150-
name,
1150+
name: ident.name,
11511151
id: def_node_id,
11521152
bounds: hir_bounds,
11531153
default: None,
@@ -1162,7 +1162,7 @@ impl<'a> LoweringContext<'a> {
11621162
P(hir::Path {
11631163
span,
11641164
def: Def::TyParam(DefId::local(def_index)),
1165-
segments: hir_vec![hir::PathSegment::from_name(name)],
1165+
segments: hir_vec![hir::PathSegment::from_ident(ident)],
11661166
}),
11671167
))
11681168
}
@@ -1535,7 +1535,7 @@ impl<'a> LoweringContext<'a> {
15351535
&mut self,
15361536
id: NodeId,
15371537
p: &Path,
1538-
name: Option<Name>,
1538+
ident: Option<Ident>,
15391539
param_mode: ParamMode,
15401540
) -> hir::Path {
15411541
hir::Path {
@@ -1552,7 +1552,7 @@ impl<'a> LoweringContext<'a> {
15521552
ImplTraitContext::Disallowed,
15531553
)
15541554
})
1555-
.chain(name.map(|name| hir::PathSegment::from_name(name)))
1555+
.chain(ident.map(|ident| hir::PathSegment::from_ident(ident)))
15561556
.collect(),
15571557
span: p.span,
15581558
}
@@ -1605,7 +1605,7 @@ impl<'a> LoweringContext<'a> {
16051605
}
16061606

16071607
hir::PathSegment::new(
1608-
self.lower_ident(segment.ident),
1608+
segment.ident,
16091609
parameters,
16101610
infer_types,
16111611
)
@@ -2839,7 +2839,7 @@ impl<'a> LoweringContext<'a> {
28392839
P(hir::Path {
28402840
span: ident.span,
28412841
def,
2842-
segments: hir_vec![hir::PathSegment::from_name(ident.name)],
2842+
segments: hir_vec![hir::PathSegment::from_ident(ident)],
28432843
}),
28442844
)),
28452845
}
@@ -3137,7 +3137,7 @@ impl<'a> LoweringContext<'a> {
31373137
let e2 = self.lower_expr(e2);
31383138
let ty_path = P(self.std_path(span, &["ops", "RangeInclusive"], false));
31393139
let ty = self.ty_path(id, span, hir::QPath::Resolved(None, ty_path));
3140-
let new_seg = P(hir::PathSegment::from_name(Symbol::intern("new")));
3140+
let new_seg = P(hir::PathSegment::from_ident(Ident::from_str("new")));
31413141
let new_path = hir::QPath::TypeRelative(ty, new_seg);
31423142
let new = P(self.expr(span, hir::ExprPath(new_path), ThinVec::new()));
31433143
hir::ExprCall(new, hir_vec![e1, e2])
@@ -3804,14 +3804,14 @@ impl<'a> LoweringContext<'a> {
38043804
self.expr(span, hir::ExprCall(e, args), ThinVec::new())
38053805
}
38063806

3807-
fn expr_ident(&mut self, span: Span, id: Name, binding: NodeId) -> hir::Expr {
3808-
self.expr_ident_with_attrs(span, id, binding, ThinVec::new())
3807+
fn expr_ident(&mut self, span: Span, ident: Ident, binding: NodeId) -> hir::Expr {
3808+
self.expr_ident_with_attrs(span, ident, binding, ThinVec::new())
38093809
}
38103810

38113811
fn expr_ident_with_attrs(
38123812
&mut self,
38133813
span: Span,
3814-
id: Name,
3814+
ident: Ident,
38153815
binding: NodeId,
38163816
attrs: ThinVec<Attribute>,
38173817
) -> hir::Expr {
@@ -3820,7 +3820,7 @@ impl<'a> LoweringContext<'a> {
38203820
P(hir::Path {
38213821
span,
38223822
def: Def::Local(binding),
3823-
segments: hir_vec![hir::PathSegment::from_name(id)],
3823+
segments: hir_vec![hir::PathSegment::from_ident(ident)],
38243824
}),
38253825
));
38263826

@@ -3901,7 +3901,7 @@ impl<'a> LoweringContext<'a> {
39013901
&mut self,
39023902
sp: Span,
39033903
mutbl: bool,
3904-
ident: Name,
3904+
ident: Ident,
39053905
ex: P<hir::Expr>,
39063906
) -> (hir::Stmt, NodeId) {
39073907
let pat = if mutbl {
@@ -3972,22 +3972,22 @@ impl<'a> LoweringContext<'a> {
39723972
self.pat(span, pt)
39733973
}
39743974

3975-
fn pat_ident(&mut self, span: Span, name: Name) -> P<hir::Pat> {
3976-
self.pat_ident_binding_mode(span, name, hir::BindingAnnotation::Unannotated)
3975+
fn pat_ident(&mut self, span: Span, ident: Ident) -> P<hir::Pat> {
3976+
self.pat_ident_binding_mode(span, ident, hir::BindingAnnotation::Unannotated)
39773977
}
39783978

39793979
fn pat_ident_binding_mode(
39803980
&mut self,
39813981
span: Span,
3982-
name: Name,
3982+
ident: Ident,
39833983
bm: hir::BindingAnnotation,
39843984
) -> P<hir::Pat> {
39853985
let LoweredNodeId { node_id, hir_id } = self.next_id();
39863986

39873987
P(hir::Pat {
39883988
id: node_id,
39893989
hir_id,
3990-
node: hir::PatKind::Binding(bm, node_id, Spanned { span, node: name }, None),
3990+
node: hir::PatKind::Binding(bm, node_id, Spanned { span, node: ident.name }, None),
39913991
span,
39923992
})
39933993
}

src/librustc/hir/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ pub struct Path {
311311

312312
impl Path {
313313
pub fn is_global(&self) -> bool {
314-
!self.segments.is_empty() && self.segments[0].name == keywords::CrateRoot.name()
314+
!self.segments.is_empty() && self.segments[0].ident.name == keywords::CrateRoot.name()
315315
}
316316
}
317317

@@ -332,7 +332,7 @@ impl fmt::Display for Path {
332332
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
333333
pub struct PathSegment {
334334
/// The identifier portion of this path segment.
335-
pub name: Name,
335+
pub ident: Ident,
336336

337337
/// Type/lifetime parameters attached to this path. They come in
338338
/// two flavors: `Path<A,B,C>` and `Path(A,B) -> C`. Note that
@@ -350,17 +350,17 @@ pub struct PathSegment {
350350

351351
impl PathSegment {
352352
/// Convert an identifier to the corresponding segment.
353-
pub fn from_name(name: Name) -> PathSegment {
353+
pub fn from_ident(ident: Ident) -> PathSegment {
354354
PathSegment {
355-
name,
355+
ident,
356356
infer_types: true,
357357
parameters: None
358358
}
359359
}
360360

361-
pub fn new(name: Name, parameters: PathParameters, infer_types: bool) -> Self {
361+
pub fn new(ident: Ident, parameters: PathParameters, infer_types: bool) -> Self {
362362
PathSegment {
363-
name,
363+
ident,
364364
infer_types,
365365
parameters: if parameters.is_empty() {
366366
None

src/librustc/hir/print.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ impl<'a> State<'a> {
543543

544544
match kind {
545545
hir::UseKind::Single => {
546-
if path.segments.last().unwrap().name != item.name {
546+
if path.segments.last().unwrap().ident.name != item.name {
547547
self.s.space()?;
548548
self.word_space("as")?;
549549
self.print_name(item.name)?;
@@ -806,7 +806,8 @@ impl<'a> State<'a> {
806806
hir::Visibility::Crate(ast::CrateSugar::PubCrate) => self.word_nbsp("pub(crate)")?,
807807
hir::Visibility::Restricted { ref path, .. } => {
808808
self.s.word("pub(")?;
809-
if path.segments.len() == 1 && path.segments[0].name == keywords::Super.name() {
809+
if path.segments.len() == 1 &&
810+
path.segments[0].ident.name == keywords::Super.name() {
810811
// Special case: `super` can print like `pub(super)`.
811812
self.s.word("super")?;
812813
} else {
@@ -1229,7 +1230,7 @@ impl<'a> State<'a> {
12291230
let base_args = &args[1..];
12301231
self.print_expr_maybe_paren(&args[0], parser::PREC_POSTFIX)?;
12311232
self.s.word(".")?;
1232-
self.print_name(segment.name)?;
1233+
self.print_ident(segment.ident)?;
12331234

12341235
segment.with_parameters(|parameters| {
12351236
if !parameters.lifetimes.is_empty() ||
@@ -1601,9 +1602,9 @@ impl<'a> State<'a> {
16011602
if i > 0 {
16021603
self.s.word("::")?
16031604
}
1604-
if segment.name != keywords::CrateRoot.name() &&
1605-
segment.name != keywords::DollarCrate.name() {
1606-
self.print_name(segment.name)?;
1605+
if segment.ident.name != keywords::CrateRoot.name() &&
1606+
segment.ident.name != keywords::DollarCrate.name() {
1607+
self.print_ident(segment.ident)?;
16071608
segment.with_parameters(|parameters| {
16081609
self.print_path_parameters(parameters,
16091610
segment.infer_types,
@@ -1633,9 +1634,9 @@ impl<'a> State<'a> {
16331634
if i > 0 {
16341635
self.s.word("::")?
16351636
}
1636-
if segment.name != keywords::CrateRoot.name() &&
1637-
segment.name != keywords::DollarCrate.name() {
1638-
self.print_name(segment.name)?;
1637+
if segment.ident.name != keywords::CrateRoot.name() &&
1638+
segment.ident.name != keywords::DollarCrate.name() {
1639+
self.print_ident(segment.ident)?;
16391640
segment.with_parameters(|parameters| {
16401641
self.print_path_parameters(parameters,
16411642
segment.infer_types,
@@ -1647,7 +1648,7 @@ impl<'a> State<'a> {
16471648
self.s.word(">")?;
16481649
self.s.word("::")?;
16491650
let item_segment = path.segments.last().unwrap();
1650-
self.print_name(item_segment.name)?;
1651+
self.print_ident(item_segment.ident)?;
16511652
item_segment.with_parameters(|parameters| {
16521653
self.print_path_parameters(parameters,
16531654
item_segment.infer_types,
@@ -1659,7 +1660,7 @@ impl<'a> State<'a> {
16591660
self.print_type(qself)?;
16601661
self.s.word(">")?;
16611662
self.s.word("::")?;
1662-
self.print_name(item_segment.name)?;
1663+
self.print_ident(item_segment.ident)?;
16631664
item_segment.with_parameters(|parameters| {
16641665
self.print_path_parameters(parameters,
16651666
item_segment.infer_types,

src/librustc/ich/impls_hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl_stable_hash_for!(struct hir::Path {
175175
});
176176

177177
impl_stable_hash_for!(struct hir::PathSegment {
178-
name,
178+
ident,
179179
infer_types,
180180
parameters
181181
});

src/librustc_lint/bad_style.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals {
405405
if path.segments.len() == 1 {
406406
NonUpperCaseGlobals::check_upper_case(cx,
407407
"constant in pattern",
408-
path.segments[0].name,
408+
path.segments[0].ident.name,
409409
path.span);
410410
}
411411
}

src/librustc_privacy/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -822,8 +822,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
822822
let is_local_static = if let Def::Static(..) = def { def_id.is_local() } else { false };
823823
if !self.item_is_accessible(def_id) && !is_local_static {
824824
let name = match *qpath {
825-
hir::QPath::Resolved(_, ref path) => format!("{}", path),
826-
hir::QPath::TypeRelative(_, ref segment) => segment.name.to_string(),
825+
hir::QPath::Resolved(_, ref path) => path.to_string(),
826+
hir::QPath::TypeRelative(_, ref segment) => segment.ident.to_string(),
827827
};
828828
let msg = format!("{} `{}` is private", def.kind_name(), name);
829829
self.tcx.sess.span_err(span, &msg);

src/librustc_resolve/lib.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -1502,9 +1502,9 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
15021502
let mut path = hir::Path {
15031503
span,
15041504
def: Def::Err,
1505-
segments: iter::once(keywords::CrateRoot.name()).chain({
1506-
crate_root.into_iter().chain(components.iter().cloned()).map(Symbol::intern)
1507-
}).map(hir::PathSegment::from_name).collect(),
1505+
segments: iter::once(keywords::CrateRoot.ident()).chain({
1506+
crate_root.into_iter().chain(components.iter().cloned()).map(Ident::from_str)
1507+
}).map(hir::PathSegment::from_ident).collect(),
15081508
};
15091509

15101510
self.resolve_hir_path(&mut path, is_value);
@@ -1534,16 +1534,16 @@ impl<'a> Resolver<'a> {
15341534
hir::Path {
15351535
span,
15361536
def: Def::Err,
1537-
segments: iter::once(keywords::CrateRoot.name()).chain({
1538-
path_str.split("::").skip(1).map(Symbol::intern)
1539-
}).map(hir::PathSegment::from_name).collect(),
1537+
segments: iter::once(keywords::CrateRoot.ident()).chain({
1538+
path_str.split("::").skip(1).map(Ident::from_str)
1539+
}).map(hir::PathSegment::from_ident).collect(),
15401540
}
15411541
} else {
15421542
hir::Path {
15431543
span,
15441544
def: Def::Err,
1545-
segments: path_str.split("::").map(Symbol::intern)
1546-
.map(hir::PathSegment::from_name).collect(),
1545+
segments: path_str.split("::").map(Ident::from_str)
1546+
.map(hir::PathSegment::from_ident).collect(),
15471547
}
15481548
};
15491549
self.resolve_hir_path_cb(&mut path, is_value, |_, _, _| errored = true);
@@ -1556,13 +1556,11 @@ impl<'a> Resolver<'a> {
15561556

15571557
/// resolve_hir_path, but takes a callback in case there was an error
15581558
fn resolve_hir_path_cb<F>(&mut self, path: &mut hir::Path, is_value: bool, error_callback: F)
1559-
where F: for<'c, 'b> FnOnce(&'c mut Resolver, Span, ResolutionError<'b>)
1560-
{
1559+
where F: for<'c, 'b> FnOnce(&'c mut Resolver, Span, ResolutionError<'b>)
1560+
{
15611561
let namespace = if is_value { ValueNS } else { TypeNS };
15621562
let hir::Path { ref segments, span, ref mut def } = *path;
1563-
let path: Vec<Ident> = segments.iter()
1564-
.map(|seg| Ident::new(seg.name, span))
1565-
.collect();
1563+
let path: Vec<_> = segments.iter().map(|seg| seg.ident).collect();
15661564
// FIXME (Manishearth): Intra doc links won't get warned of epoch changes
15671565
match self.resolve_path(&path, Some(namespace), true, span, CrateLint::No) {
15681566
PathResult::Module(module) => *def = module.def().unwrap(),

src/librustc_typeck/astconv.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
863863
-> (Ty<'tcx>, Def)
864864
{
865865
let tcx = self.tcx();
866-
let assoc_name = item_segment.name.to_ident();
866+
let assoc_name = item_segment.ident;
867867

868868
debug!("associated_path_def_to_ty: {:?}::{}", ty, assoc_name);
869869

@@ -952,7 +952,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
952952
self.report_ambiguous_associated_type(span,
953953
"Type",
954954
&path_str,
955-
&item_segment.name.as_str());
955+
&item_segment.ident.as_str());
956956
return tcx.types.err;
957957
};
958958

src/librustc_typeck/check/demand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
226226
})), 1) = (self.tcx.hir.find(parent), decl.inputs.len()) {
227227
let self_ty = self.tables.borrow().node_id_to_type(expr[0].hir_id);
228228
let self_ty = format!("{:?}", self_ty);
229-
let name = path.name.as_str();
229+
let name = path.ident.as_str();
230230
let is_as_ref_able = (
231231
self_ty.starts_with("&std::option::Option") ||
232232
self_ty.starts_with("&std::result::Result") ||

0 commit comments

Comments
 (0)