Skip to content

Commit 25cbb43

Browse files
committed
Move ExpnInfo to Name
1 parent 4ec7b71 commit 25cbb43

File tree

9 files changed

+37
-38
lines changed

9 files changed

+37
-38
lines changed

src/libsyntax/codemap.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ use std::io::{self, Read};
2929

3030
use serialize::{Encodable, Decodable, Encoder, Decoder};
3131

32+
use parse::token::intern;
33+
use ast::Name;
3234

3335
// _____________________________________________________________________________
3436
// Pos, BytePos, CharPos
@@ -260,9 +262,9 @@ pub struct FileMapAndBytePos { pub fm: Rc<FileMap>, pub pos: BytePos }
260262
#[derive(Clone, Hash, Debug, PartialEq, Eq)]
261263
pub enum ExpnFormat {
262264
/// e.g. #[derive(...)] <item>
263-
MacroAttribute(String),
265+
MacroAttribute(Name),
264266
/// e.g. `format!()`
265-
MacroBang(String),
267+
MacroBang(Name),
266268
/// Syntax sugar expansion performed by the compiler (libsyntax::expand).
267269
CompilerExpansion(CompilerExpansionFormat),
268270
}
@@ -302,13 +304,13 @@ pub struct NameAndSpan {
302304
}
303305

304306
impl NameAndSpan {
305-
pub fn name(&self) -> &str{
307+
pub fn name(&self) -> Name {
306308
match self.format {
307-
ExpnFormat::MacroAttribute(ref s) => &s,
308-
ExpnFormat::MacroBang(ref s) => &s,
309-
ExpnFormat::CompilerExpansion(ce) => ce.name(),
309+
ExpnFormat::MacroAttribute(s) => s,
310+
ExpnFormat::MacroBang(s) => s,
311+
ExpnFormat::CompilerExpansion(ce) => intern(ce.name()),
310312
}
311-
}
313+
}
312314
}
313315

314316
/// Extra information for tracking spans of macro and syntax sugar expansion

src/libsyntax/ext/asm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use codemap::Span;
1919
use ext::base;
2020
use ext::base::*;
2121
use feature_gate;
22-
use parse::token::InternedString;
22+
use parse::token::{intern, InternedString};
2323
use parse::token;
2424
use ptr::P;
2525

@@ -211,7 +211,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
211211
let expn_id = cx.codemap().record_expansion(codemap::ExpnInfo {
212212
call_site: sp,
213213
callee: codemap::NameAndSpan {
214-
format: codemap::MacroBang("asm".to_string()),
214+
format: codemap::MacroBang(intern("asm")),
215215
span: None,
216216
allow_internal_unstable: false,
217217
},

src/libsyntax/ext/deriving/generic/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ use codemap::Span;
205205
use diagnostic::SpanHandler;
206206
use fold::MoveMap;
207207
use owned_slice::OwnedSlice;
208-
use parse::token::InternedString;
208+
use parse::token::{intern, InternedString};
209209
use parse::token::special_idents;
210210
use ptr::P;
211211

@@ -1436,7 +1436,7 @@ impl<'a> TraitDef<'a> {
14361436
to_set.expn_id = cx.codemap().record_expansion(codemap::ExpnInfo {
14371437
call_site: to_set,
14381438
callee: codemap::NameAndSpan {
1439-
format: codemap::MacroAttribute(format!("derive({})", trait_name)),
1439+
format: codemap::MacroAttribute(intern(&format!("derive({})", trait_name))),
14401440
span: Some(self.span),
14411441
allow_internal_unstable: false,
14421442
}

src/libsyntax/ext/expand.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ fn expand_mac_invoc<T, F, G>(mac: ast::Mac,
543543
fld.cx.bt_push(ExpnInfo {
544544
call_site: span,
545545
callee: NameAndSpan {
546-
format: MacroBang(extname.to_string()),
546+
format: MacroBang(extname),
547547
span: exp_span,
548548
allow_internal_unstable: allow_internal_unstable,
549549
},
@@ -721,7 +721,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
721721
fld.cx.bt_push(ExpnInfo {
722722
call_site: it.span,
723723
callee: NameAndSpan {
724-
format: MacroBang(extname.to_string()),
724+
format: MacroBang(extname),
725725
span: span,
726726
allow_internal_unstable: allow_internal_unstable,
727727
}
@@ -740,7 +740,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
740740
fld.cx.bt_push(ExpnInfo {
741741
call_site: it.span,
742742
callee: NameAndSpan {
743-
format: MacroBang(extname.to_string()),
743+
format: MacroBang(extname),
744744
span: span,
745745
allow_internal_unstable: allow_internal_unstable,
746746
}
@@ -760,7 +760,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
760760
fld.cx.bt_push(ExpnInfo {
761761
call_site: it.span,
762762
callee: NameAndSpan {
763-
format: MacroBang(extname.to_string()),
763+
format: MacroBang(extname),
764764
span: None,
765765
// `macro_rules!` doesn't directly allow
766766
// unstable (this is orthogonal to whether
@@ -1087,7 +1087,7 @@ fn expand_pat(p: P<ast::Pat>, fld: &mut MacroExpander) -> P<ast::Pat> {
10871087
fld.cx.bt_push(ExpnInfo {
10881088
call_site: span,
10891089
callee: NameAndSpan {
1090-
format: MacroBang(extname.to_string()),
1090+
format: MacroBang(extname),
10911091
span: tt_span,
10921092
allow_internal_unstable: allow_internal_unstable,
10931093
}
@@ -1289,16 +1289,16 @@ fn expand_decorators(a: Annotatable,
12891289
new_attrs: &mut Vec<ast::Attribute>)
12901290
{
12911291
for attr in a.attrs() {
1292-
let mname = attr.name();
1293-
match fld.cx.syntax_env.find(&intern(&mname)) {
1292+
let mname = intern(&attr.name());
1293+
match fld.cx.syntax_env.find(&mname) {
12941294
Some(rc) => match *rc {
12951295
Decorator(ref dec) => {
12961296
attr::mark_used(&attr);
12971297

12981298
fld.cx.bt_push(ExpnInfo {
12991299
call_site: attr.span,
13001300
callee: NameAndSpan {
1301-
format: MacroAttribute(mname.to_string()),
1301+
format: MacroAttribute(mname),
13021302
span: Some(attr.span),
13031303
// attributes can do whatever they like,
13041304
// for now.
@@ -1325,7 +1325,7 @@ fn expand_decorators(a: Annotatable,
13251325
fld.cx.bt_push(ExpnInfo {
13261326
call_site: attr.span,
13271327
callee: NameAndSpan {
1328-
format: MacroAttribute(mname.to_string()),
1328+
format: MacroAttribute(mname),
13291329
span: Some(attr.span),
13301330
// attributes can do whatever they like,
13311331
// for now.
@@ -1366,16 +1366,16 @@ fn expand_item_multi_modifier(mut it: Annotatable,
13661366
}
13671367

13681368
for attr in &modifiers {
1369-
let mname = attr.name();
1369+
let mname = intern(&attr.name());
13701370

1371-
match fld.cx.syntax_env.find(&intern(&mname)) {
1371+
match fld.cx.syntax_env.find(&mname) {
13721372
Some(rc) => match *rc {
13731373
MultiModifier(ref mac) => {
13741374
attr::mark_used(attr);
13751375
fld.cx.bt_push(ExpnInfo {
13761376
call_site: attr.span,
13771377
callee: NameAndSpan {
1378-
format: MacroAttribute(mname.to_string()),
1378+
format: MacroAttribute(mname),
13791379
span: Some(attr.span),
13801380
// attributes can do whatever they like,
13811381
// for now
@@ -1414,16 +1414,16 @@ fn expand_item_modifiers(mut it: P<ast::Item>,
14141414
}
14151415

14161416
for attr in &modifiers {
1417-
let mname = attr.name();
1417+
let mname = intern(&attr.name());
14181418

1419-
match fld.cx.syntax_env.find(&intern(&mname)) {
1419+
match fld.cx.syntax_env.find(&mname) {
14201420
Some(rc) => match *rc {
14211421
Modifier(ref mac) => {
14221422
attr::mark_used(attr);
14231423
fld.cx.bt_push(ExpnInfo {
14241424
call_site: attr.span,
14251425
callee: NameAndSpan {
1426-
format: MacroAttribute(mname.to_string()),
1426+
format: MacroAttribute(mname),
14271427
span: Some(attr.span),
14281428
// attributes can do whatever they like,
14291429
// for now

src/libsyntax/std_inject.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use codemap::{DUMMY_SP, Span, ExpnInfo, NameAndSpan, MacroAttribute};
1414
use codemap;
1515
use fold::Folder;
1616
use fold;
17-
use parse::token::InternedString;
18-
use parse::token::special_idents;
17+
use parse::token::{intern, InternedString, special_idents};
1918
use parse::{token, ParseSess};
2019
use ptr::P;
2120
use util::small_vector::SmallVector;
@@ -27,7 +26,7 @@ fn ignored_span(sess: &ParseSess, sp: Span) -> Span {
2726
let info = ExpnInfo {
2827
call_site: DUMMY_SP,
2928
callee: NameAndSpan {
30-
format: MacroAttribute("std_inject".to_string()),
29+
format: MacroAttribute(intern("std_inject")),
3130
span: None,
3231
allow_internal_unstable: true,
3332
}

src/libsyntax/test.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use ext::expand::ExpansionConfig;
3030
use fold::{Folder, MoveMap};
3131
use fold;
3232
use owned_slice::OwnedSlice;
33-
use parse::token::InternedString;
33+
use parse::token::{intern, InternedString};
3434
use parse::{token, ParseSess};
3535
use print::pprust;
3636
use {ast, ast_util};
@@ -265,7 +265,7 @@ fn generate_test_harness(sess: &ParseSess,
265265
cx.ext_cx.bt_push(ExpnInfo {
266266
call_site: DUMMY_SP,
267267
callee: NameAndSpan {
268-
format: MacroAttribute("test".to_string()),
268+
format: MacroAttribute(intern("test")),
269269
span: None,
270270
allow_internal_unstable: false,
271271
}
@@ -297,7 +297,7 @@ fn ignored_span(cx: &TestCtxt, sp: Span) -> Span {
297297
let info = ExpnInfo {
298298
call_site: DUMMY_SP,
299299
callee: NameAndSpan {
300-
format: MacroAttribute("test".to_string()),
300+
format: MacroAttribute(intern("test")),
301301
span: None,
302302
allow_internal_unstable: true,
303303
}

src/test/compile-fail-fulldeps/qquote.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ fn main() {
2727
cx.bt_push(syntax::codemap::ExpnInfo {
2828
call_site: DUMMY_SP,
2929
callee: syntax::codemap::NameAndSpan {
30-
name: "".to_string(),
31-
format: syntax::codemap::MacroBang,
30+
format: syntax::codemap::MacroBang(parse::token::intern("")),
3231
allow_internal_unstable: false,
3332
span: None,
3433
}

src/test/run-fail-fulldeps/qquote.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ fn main() {
3131
cx.bt_push(syntax::codemap::ExpnInfo {
3232
call_site: DUMMY_SP,
3333
callee: syntax::codemap::NameAndSpan {
34-
name: "".to_string(),
35-
format: syntax::codemap::MacroBang,
34+
format: syntax::codemap::MacroBang(parse::token::intern("")),
3635
allow_internal_unstable: false,
3736
span: None,
3837
}

src/test/run-pass-fulldeps/qquote.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ extern crate syntax;
1616

1717
use syntax::codemap::DUMMY_SP;
1818
use syntax::print::pprust::*;
19+
use syntax::parse::token::intern;
1920

2021
fn main() {
2122
let ps = syntax::parse::ParseSess::new();
@@ -27,8 +28,7 @@ fn main() {
2728
cx.bt_push(syntax::codemap::ExpnInfo {
2829
call_site: DUMMY_SP,
2930
callee: syntax::codemap::NameAndSpan {
30-
name: "".to_string(),
31-
format: syntax::codemap::MacroBang,
31+
format: syntax::codemap::MacroBang(intern("")),
3232
allow_internal_unstable: false,
3333
span: None,
3434
}

0 commit comments

Comments
 (0)