Skip to content

Commit 57a45e9

Browse files
committed
Avoid some unnecessary &str to Ident conversions
1 parent e8d2f62 commit 57a45e9

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

src/librustc_metadata/cstore_impl.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,8 @@ impl cstore::CStore {
444444
.insert(local_span, (name.to_string(), data.get_span(id.index, sess)));
445445

446446
LoadedMacro::MacroDef(ast::Item {
447-
ident: ast::Ident::from_str(&name.as_str()),
447+
// FIXME: cross-crate hygiene
448+
ident: ast::Ident::with_dummy_span(name.as_symbol()),
448449
id: ast::DUMMY_NODE_ID,
449450
span: local_span,
450451
attrs: attrs.iter().cloned().collect(),

src/libsyntax/ext/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl<'a> ExtCtxt<'a> {
363363
self.expr(sp, ast::ExprKind::Field(expr, ident.with_span_pos(sp)))
364364
}
365365
pub fn expr_tup_field_access(&self, sp: Span, expr: P<ast::Expr>, idx: usize) -> P<ast::Expr> {
366-
let ident = Ident::from_str(&idx.to_string()).with_span_pos(sp);
366+
let ident = Ident::new(sym::integer(idx), sp);
367367
self.expr(sp, ast::ExprKind::Field(expr, ident))
368368
}
369369
pub fn expr_addr_of(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> {

src/libsyntax_ext/deriving/generic/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub struct MethodDef<'a> {
237237
/// Whether there is a self argument (outer Option) i.e., whether
238238
/// this is a static function, and whether it is a pointer (inner
239239
/// Option)
240-
pub explicit_self: Option<Option<PtrTy<'a>>>,
240+
pub explicit_self: Option<Option<PtrTy>>,
241241

242242
/// Arguments other than the self argument
243243
pub args: Vec<(Ty<'a>, &'a str)>,

src/libsyntax_ext/deriving/generic/ty.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ use syntax_pos::symbol::kw;
1313

1414
/// The types of pointers
1515
#[derive(Clone)]
16-
pub enum PtrTy<'a> {
16+
pub enum PtrTy {
1717
/// &'lifetime mut
18-
Borrowed(Option<&'a str>, ast::Mutability),
18+
Borrowed(Option<Ident>, ast::Mutability),
1919
/// *mut
2020
#[allow(dead_code)]
2121
Raw(ast::Mutability),
@@ -26,7 +26,7 @@ pub enum PtrTy<'a> {
2626
#[derive(Clone)]
2727
pub struct Path<'a> {
2828
path: Vec<&'a str>,
29-
lifetime: Option<&'a str>,
29+
lifetime: Option<Ident>,
3030
params: Vec<Box<Ty<'a>>>,
3131
kind: PathKind,
3232
}
@@ -46,7 +46,7 @@ impl<'a> Path<'a> {
4646
Path::new_(vec![path], None, Vec::new(), PathKind::Local)
4747
}
4848
pub fn new_<'r>(path: Vec<&'r str>,
49-
lifetime: Option<&'r str>,
49+
lifetime: Option<Ident>,
5050
params: Vec<Box<Ty<'r>>>,
5151
kind: PathKind)
5252
-> Path<'r> {
@@ -99,22 +99,22 @@ impl<'a> Path<'a> {
9999
pub enum Ty<'a> {
100100
Self_,
101101
/// &/Box/ Ty
102-
Ptr(Box<Ty<'a>>, PtrTy<'a>),
102+
Ptr(Box<Ty<'a>>, PtrTy),
103103
/// mod::mod::Type<[lifetime], [Params...]>, including a plain type
104104
/// parameter, and things like `i32`
105105
Literal(Path<'a>),
106106
/// includes unit
107107
Tuple(Vec<Ty<'a>>),
108108
}
109109

110-
pub fn borrowed_ptrty<'r>() -> PtrTy<'r> {
110+
pub fn borrowed_ptrty() -> PtrTy {
111111
Borrowed(None, ast::Mutability::Immutable)
112112
}
113113
pub fn borrowed(ty: Box<Ty<'_>>) -> Ty<'_> {
114114
Ptr(ty, borrowed_ptrty())
115115
}
116116

117-
pub fn borrowed_explicit_self<'r>() -> Option<Option<PtrTy<'r>>> {
117+
pub fn borrowed_explicit_self() -> Option<Option<PtrTy>> {
118118
Some(Some(borrowed_ptrty()))
119119
}
120120

@@ -126,13 +126,11 @@ pub fn nil_ty<'r>() -> Ty<'r> {
126126
Tuple(Vec::new())
127127
}
128128

129-
fn mk_lifetime(cx: &ExtCtxt<'_>, span: Span, lt: &Option<&str>) -> Option<ast::Lifetime> {
130-
lt.map(|s|
131-
cx.lifetime(span, Ident::from_str(s))
132-
)
129+
fn mk_lifetime(cx: &ExtCtxt<'_>, span: Span, lt: &Option<Ident>) -> Option<ast::Lifetime> {
130+
lt.map(|ident| cx.lifetime(span, ident))
133131
}
134132

135-
fn mk_lifetimes(cx: &ExtCtxt<'_>, span: Span, lt: &Option<&str>) -> Vec<ast::Lifetime> {
133+
fn mk_lifetimes(cx: &ExtCtxt<'_>, span: Span, lt: &Option<Ident>) -> Vec<ast::Lifetime> {
136134
mk_lifetime(cx, span, lt).into_iter().collect()
137135
}
138136

@@ -265,7 +263,7 @@ impl<'a> LifetimeBounds<'a> {
265263

266264
pub fn get_explicit_self(cx: &ExtCtxt<'_>,
267265
span: Span,
268-
self_ptr: &Option<PtrTy<'_>>)
266+
self_ptr: &Option<PtrTy>)
269267
-> (P<Expr>, ast::ExplicitSelf) {
270268
// this constructs a fresh `self` path
271269
let self_path = cx.expr_self(span);
@@ -276,7 +274,7 @@ pub fn get_explicit_self(cx: &ExtCtxt<'_>,
276274
respan(span,
277275
match *ptr {
278276
Borrowed(ref lt, mutbl) => {
279-
let lt = lt.map(|s| cx.lifetime(span, Ident::from_str(s)));
277+
let lt = lt.map(|s| cx.lifetime(span, s));
280278
SelfKind::Region(lt, mutbl)
281279
}
282280
Raw(_) => {

src/libsyntax_ext/test_harness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
288288
// Honor the reexport_test_harness_main attribute
289289
let main_id = match cx.reexport_test_harness_main {
290290
Some(sym) => Ident::new(sym, sp.with_ctxt(SyntaxContext::root())),
291-
None => Ident::from_str_and_span("main", sp),
291+
None => Ident::new(sym::main, sp),
292292
};
293293

294294
let main = P(ast::Item {

0 commit comments

Comments
 (0)