Skip to content

Commit e8215a4

Browse files
committed
Use Idents for path segments in HIR
1 parent 1fe9b4d commit e8215a4

File tree

16 files changed

+88
-90
lines changed

16 files changed

+88
-90
lines changed

src/librustc/hir/intravisit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) {
644644
pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V,
645645
path_span: Span,
646646
segment: &'v PathSegment) {
647-
visitor.visit_name(path_span, segment.name);
647+
visitor.visit_ident(segment.ident);
648648
if let Some(ref args) = segment.args {
649649
visitor.visit_generic_args(path_span, args);
650650
}

src/librustc/hir/lowering.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,8 @@ impl<'a> LoweringContext<'a> {
604604
self.sess.diagnostic()
605605
}
606606

607-
fn str_to_ident(&self, s: &'static str) -> Name {
608-
Symbol::gensym(s)
607+
fn str_to_ident(&self, s: &'static str) -> Ident {
608+
Ident::with_empty_ctxt(Symbol::gensym(s))
609609
}
610610

611611
fn allow_internal_unstable(&self, reason: CompilerDesugaringKind, span: Span) -> Span {
@@ -1139,7 +1139,7 @@ impl<'a> LoweringContext<'a> {
11391139
None,
11401140
P(hir::Path {
11411141
def: self.expect_full_def(t.id),
1142-
segments: hir_vec![hir::PathSegment::from_name(keywords::SelfType.name())],
1142+
segments: hir_vec![hir::PathSegment::from_ident(keywords::SelfType.ident())],
11431143
span: t.span,
11441144
}),
11451145
)),
@@ -1195,7 +1195,7 @@ impl<'a> LoweringContext<'a> {
11951195

11961196
let hir_bounds = self.lower_param_bounds(bounds, itctx);
11971197
// Set the name to `impl Bound1 + Bound2`
1198-
let name = Symbol::intern(&pprust::ty_to_string(t));
1198+
let ident = Ident::from_str(&pprust::ty_to_string(t));
11991199
self.in_band_ty_params.push(hir::GenericParam {
12001200
id: def_node_id,
12011201
name: ParamName::Plain(name),
@@ -1214,7 +1214,7 @@ impl<'a> LoweringContext<'a> {
12141214
P(hir::Path {
12151215
span,
12161216
def: Def::TyParam(DefId::local(def_index)),
1217-
segments: hir_vec![hir::PathSegment::from_name(name)],
1217+
segments: hir_vec![hir::PathSegment::from_ident(ident)],
12181218
}),
12191219
))
12201220
}
@@ -1689,7 +1689,7 @@ impl<'a> LoweringContext<'a> {
16891689
&mut self,
16901690
def: Def,
16911691
p: &Path,
1692-
name: Option<Name>,
1692+
ident: Option<Ident>,
16931693
param_mode: ParamMode,
16941694
) -> hir::Path {
16951695
hir::Path {
@@ -1706,7 +1706,7 @@ impl<'a> LoweringContext<'a> {
17061706
ImplTraitContext::Disallowed,
17071707
)
17081708
})
1709-
.chain(name.map(|name| hir::PathSegment::from_name(name)))
1709+
.chain(ident.map(|ident| hir::PathSegment::from_ident(ident)))
17101710
.collect(),
17111711
span: p.span,
17121712
}
@@ -1769,7 +1769,7 @@ impl<'a> LoweringContext<'a> {
17691769
}
17701770

17711771
hir::PathSegment::new(
1772-
self.lower_ident(segment.ident),
1772+
segment.ident,
17731773
generic_args,
17741774
infer_types,
17751775
)
@@ -3307,7 +3307,7 @@ impl<'a> LoweringContext<'a> {
33073307
P(hir::Path {
33083308
span: ident.span,
33093309
def,
3310-
segments: hir_vec![hir::PathSegment::from_name(ident.name)],
3310+
segments: hir_vec![hir::PathSegment::from_ident(ident)],
33113311
}),
33123312
)),
33133313
}
@@ -3670,7 +3670,7 @@ impl<'a> LoweringContext<'a> {
36703670
let e2 = self.lower_expr(e2);
36713671
let ty_path = P(self.std_path(span, &["ops", "RangeInclusive"], None, false));
36723672
let ty = P(self.ty_path(id, span, hir::QPath::Resolved(None, ty_path)));
3673-
let new_seg = P(hir::PathSegment::from_name(Symbol::intern("new")));
3673+
let new_seg = P(hir::PathSegment::from_name(Ident::from_str("new")));
36743674
let new_path = hir::QPath::TypeRelative(ty, new_seg);
36753675
let new = P(self.expr(span, hir::ExprPath(new_path), ThinVec::new()));
36763676
hir::ExprCall(new, hir_vec![e1, e2])
@@ -4340,14 +4340,14 @@ impl<'a> LoweringContext<'a> {
43404340
self.expr(span, hir::ExprCall(e, args), ThinVec::new())
43414341
}
43424342

4343-
fn expr_ident(&mut self, span: Span, id: Name, binding: NodeId) -> hir::Expr {
4344-
self.expr_ident_with_attrs(span, id, binding, ThinVec::new())
4343+
fn expr_ident(&mut self, span: Span, ident: Ident, binding: NodeId) -> hir::Expr {
4344+
self.expr_ident_with_attrs(span, ident, binding, ThinVec::new())
43454345
}
43464346

43474347
fn expr_ident_with_attrs(
43484348
&mut self,
43494349
span: Span,
4350-
id: Name,
4350+
ident: Ident,
43514351
binding: NodeId,
43524352
attrs: ThinVec<Attribute>,
43534353
) -> hir::Expr {
@@ -4356,7 +4356,7 @@ impl<'a> LoweringContext<'a> {
43564356
P(hir::Path {
43574357
span,
43584358
def: Def::Local(binding),
4359-
segments: hir_vec![hir::PathSegment::from_name(id)],
4359+
segments: hir_vec![hir::PathSegment::from_ident(ident)],
43604360
}),
43614361
));
43624362

@@ -4438,7 +4438,7 @@ impl<'a> LoweringContext<'a> {
44384438
&mut self,
44394439
sp: Span,
44404440
mutbl: bool,
4441-
ident: Name,
4441+
ident: Ident,
44424442
ex: P<hir::Expr>,
44434443
) -> (hir::Stmt, NodeId) {
44444444
let pat = if mutbl {
@@ -4509,22 +4509,22 @@ impl<'a> LoweringContext<'a> {
45094509
self.pat(span, pt)
45104510
}
45114511

4512-
fn pat_ident(&mut self, span: Span, name: Name) -> P<hir::Pat> {
4513-
self.pat_ident_binding_mode(span, name, hir::BindingAnnotation::Unannotated)
4512+
fn pat_ident(&mut self, span: Span, ident: Ident) -> P<hir::Pat> {
4513+
self.pat_ident_binding_mode(span, ident, hir::BindingAnnotation::Unannotated)
45144514
}
45154515

45164516
fn pat_ident_binding_mode(
45174517
&mut self,
45184518
span: Span,
4519-
name: Name,
4519+
ident: Ident,
45204520
bm: hir::BindingAnnotation,
45214521
) -> P<hir::Pat> {
45224522
let LoweredNodeId { node_id, hir_id } = self.next_id();
45234523

45244524
P(hir::Pat {
45254525
id: node_id,
45264526
hir_id,
4527-
node: hir::PatKind::Binding(bm, node_id, Spanned { span, node: name }, None),
4527+
node: hir::PatKind::Binding(bm, node_id, Spanned { span, node: ident.name }, None),
45284528
span,
45294529
})
45304530
}

src/librustc/hir/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ pub struct Path {
320320

321321
impl Path {
322322
pub fn is_global(&self) -> bool {
323-
!self.segments.is_empty() && self.segments[0].name == keywords::CrateRoot.name()
323+
!self.segments.is_empty() && self.segments[0].ident.name == keywords::CrateRoot.name()
324324
}
325325
}
326326

@@ -341,7 +341,7 @@ impl fmt::Display for Path {
341341
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
342342
pub struct PathSegment {
343343
/// The identifier portion of this path segment.
344-
pub name: Name,
344+
pub ident: Ident,
345345

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

360360
impl PathSegment {
361361
/// Convert an identifier to the corresponding segment.
362-
pub fn from_name(name: Name) -> PathSegment {
362+
pub fn from_ident(ident: Ident) -> PathSegment {
363363
PathSegment {
364-
name,
364+
ident,
365365
infer_types: true,
366366
args: None,
367367
}
368368
}
369369

370-
pub fn new(name: Name, args: GenericArgs, infer_types: bool) -> Self {
370+
pub fn new(ident: Ident, args: GenericArgs, infer_types: bool) -> Self {
371371
PathSegment {
372-
name,
372+
ident,
373373
infer_types,
374374
args: if args.is_empty() {
375375
None

src/librustc/hir/print.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ impl<'a> State<'a> {
559559

560560
match kind {
561561
hir::UseKind::Single => {
562-
if path.segments.last().unwrap().name != item.name {
562+
if path.segments.last().unwrap().ident.name != item.name {
563563
self.s.space()?;
564564
self.word_space("as")?;
565565
self.print_name(item.name)?;
@@ -845,7 +845,8 @@ impl<'a> State<'a> {
845845
hir::Visibility::Crate(ast::CrateSugar::PubCrate) => self.word_nbsp("pub(crate)")?,
846846
hir::Visibility::Restricted { ref path, .. } => {
847847
self.s.word("pub(")?;
848-
if path.segments.len() == 1 && path.segments[0].name == keywords::Super.name() {
848+
if path.segments.len() == 1 &&
849+
path.segments[0].ident.name == keywords::Super.name() {
849850
// Special case: `super` can print like `pub(super)`.
850851
self.s.word("super")?;
851852
} else {
@@ -1266,7 +1267,7 @@ impl<'a> State<'a> {
12661267
let base_args = &args[1..];
12671268
self.print_expr_maybe_paren(&args[0], parser::PREC_POSTFIX)?;
12681269
self.s.word(".")?;
1269-
self.print_name(segment.name)?;
1270+
self.print_ident(segment.ident)?;
12701271

12711272
segment.with_generic_args(|generic_args| {
12721273
if !generic_args.args.is_empty() || !generic_args.bindings.is_empty() {
@@ -1634,9 +1635,9 @@ impl<'a> State<'a> {
16341635
if i > 0 {
16351636
self.s.word("::")?
16361637
}
1637-
if segment.name != keywords::CrateRoot.name() &&
1638-
segment.name != keywords::DollarCrate.name() {
1639-
self.print_name(segment.name)?;
1638+
if segment.ident.name != keywords::CrateRoot.name() &&
1639+
segment.ident.name != keywords::DollarCrate.name() {
1640+
self.print_ident(segment.ident)?;
16401641
segment.with_generic_args(|generic_args| {
16411642
self.print_generic_args(generic_args, segment.infer_types,
16421643
colons_before_params)
@@ -1665,9 +1666,9 @@ impl<'a> State<'a> {
16651666
if i > 0 {
16661667
self.s.word("::")?
16671668
}
1668-
if segment.name != keywords::CrateRoot.name() &&
1669-
segment.name != keywords::DollarCrate.name() {
1670-
self.print_name(segment.name)?;
1669+
if segment.ident.name != keywords::CrateRoot.name() &&
1670+
segment.ident.name != keywords::DollarCrate.name() {
1671+
self.print_ident(segment.ident)?;
16711672
segment.with_generic_args(|generic_args| {
16721673
self.print_generic_args(generic_args,
16731674
segment.infer_types,
@@ -1679,7 +1680,7 @@ impl<'a> State<'a> {
16791680
self.s.word(">")?;
16801681
self.s.word("::")?;
16811682
let item_segment = path.segments.last().unwrap();
1682-
self.print_name(item_segment.name)?;
1683+
self.print_ident(item_segment.ident)?;
16831684
item_segment.with_generic_args(|generic_args| {
16841685
self.print_generic_args(generic_args,
16851686
item_segment.infer_types,
@@ -1691,7 +1692,7 @@ impl<'a> State<'a> {
16911692
self.print_type(qself)?;
16921693
self.s.word(">")?;
16931694
self.s.word("::")?;
1694-
self.print_name(item_segment.name)?;
1695+
self.print_ident(item_segment.ident)?;
16951696
item_segment.with_generic_args(|generic_args| {
16961697
self.print_generic_args(generic_args,
16971698
item_segment.infer_types,

src/librustc/ich/impls_hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl_stable_hash_for!(struct hir::Path {
172172
});
173173

174174
impl_stable_hash_for!(struct hir::PathSegment {
175-
name,
175+
ident,
176176
infer_types,
177177
args
178178
});

src/librustc_lint/bad_style.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals {
407407
if path.segments.len() == 1 {
408408
NonUpperCaseGlobals::check_upper_case(cx,
409409
"constant in pattern",
410-
path.segments[0].name,
410+
path.segments[0].ident.name,
411411
path.span);
412412
}
413413
}

src/librustc_privacy/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,8 +830,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
830830
let is_local_static = if let Def::Static(..) = def { def_id.is_local() } else { false };
831831
if !self.item_is_accessible(def_id) && !is_local_static {
832832
let name = match *qpath {
833-
hir::QPath::Resolved(_, ref path) => format!("{}", path),
834-
hir::QPath::TypeRelative(_, ref segment) => segment.name.to_string(),
833+
hir::QPath::Resolved(_, ref path) => path.to_string(),
834+
hir::QPath::TypeRelative(_, ref segment) => segment.ident.to_string(),
835835
};
836836
let msg = format!("{} `{}` is private", def.kind_name(), name);
837837
self.tcx.sess.span_err(span, &msg);

src/librustc_resolve/lib.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,16 +1550,16 @@ impl<'a> Resolver<'a> {
15501550
hir::Path {
15511551
span,
15521552
def: Def::Err,
1553-
segments: iter::once(keywords::CrateRoot.name()).chain({
1554-
path_str.split("::").skip(1).map(Symbol::intern)
1555-
}).map(hir::PathSegment::from_name).collect(),
1553+
segments: iter::once(keywords::CrateRoot.ident()).chain({
1554+
path_str.split("::").skip(1).map(Ident::from_str)
1555+
}).map(hir::PathSegment::from_ident).collect(),
15561556
}
15571557
} else {
15581558
hir::Path {
15591559
span,
15601560
def: Def::Err,
1561-
segments: path_str.split("::").map(Symbol::intern)
1562-
.map(hir::PathSegment::from_name).collect(),
1561+
segments: path_str.split("::").map(Ident::from_str)
1562+
.map(hir::PathSegment::from_ident).collect(),
15631563
}
15641564
};
15651565
self.resolve_hir_path_cb(&mut path, is_value, |_, _, _| errored = true);
@@ -1572,13 +1572,11 @@ impl<'a> Resolver<'a> {
15721572

15731573
/// resolve_hir_path, but takes a callback in case there was an error
15741574
fn resolve_hir_path_cb<F>(&mut self, path: &mut hir::Path, is_value: bool, error_callback: F)
1575-
where F: for<'c, 'b> FnOnce(&'c mut Resolver, Span, ResolutionError<'b>)
1576-
{
1575+
where F: for<'c, 'b> FnOnce(&'c mut Resolver, Span, ResolutionError<'b>)
1576+
{
15771577
let namespace = if is_value { ValueNS } else { TypeNS };
15781578
let hir::Path { ref segments, span, ref mut def } = *path;
1579-
let path: Vec<Ident> = segments.iter()
1580-
.map(|seg| Ident::new(seg.name, span))
1581-
.collect();
1579+
let path: Vec<_> = segments.iter().map(|seg| seg.ident).collect();
15821580
// FIXME (Manishearth): Intra doc links won't get warned of epoch changes
15831581
match self.resolve_path(&path, Some(namespace), true, span, CrateLint::No) {
15841582
PathResult::Module(module) => *def = module.def().unwrap(),

src/librustc_typeck/astconv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
873873
-> (Ty<'tcx>, Def)
874874
{
875875
let tcx = self.tcx();
876-
let assoc_name = item_segment.name.to_ident();
876+
let assoc_name = item_segment.ident;
877877

878878
debug!("associated_path_def_to_ty: {:?}::{}", ty, assoc_name);
879879

@@ -962,7 +962,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
962962
self.report_ambiguous_associated_type(span,
963963
"Type",
964964
&path_str,
965-
&item_segment.name.as_str());
965+
&item_segment.ident.as_str());
966966
return tcx.types.err;
967967
};
968968

src/librustc_typeck/check/demand.rs

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