Skip to content

Commit 20ce910

Browse files
committed
hygiene: Merge NameAndSpan into ExpnInfo
1 parent 117cb04 commit 20ce910

File tree

15 files changed

+116
-154
lines changed

15 files changed

+116
-154
lines changed

src/librustc/hir/lowering.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -612,13 +612,11 @@ impl<'a> LoweringContext<'a> {
612612
let mark = Mark::fresh(Mark::root());
613613
mark.set_expn_info(codemap::ExpnInfo {
614614
call_site: span,
615-
callee: codemap::NameAndSpan {
616-
format: codemap::CompilerDesugaring(reason),
617-
span: Some(span),
618-
allow_internal_unstable: true,
619-
allow_internal_unsafe: false,
620-
edition: codemap::hygiene::default_edition(),
621-
},
615+
def_site: Some(span),
616+
format: codemap::CompilerDesugaring(reason),
617+
allow_internal_unstable: true,
618+
allow_internal_unsafe: false,
619+
edition: codemap::hygiene::default_edition(),
622620
});
623621
span.with_ctxt(SyntaxContext::empty().apply_mark(mark))
624622
}

src/librustc/ich/impls_syntax.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -391,15 +391,11 @@ impl_stable_hash_for!(enum ::syntax::ast::MetaItemKind {
391391

392392
impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnInfo {
393393
call_site,
394-
callee
395-
});
396-
397-
impl_stable_hash_for!(struct ::syntax_pos::hygiene::NameAndSpan {
394+
def_site,
398395
format,
399396
allow_internal_unstable,
400397
allow_internal_unsafe,
401-
edition,
402-
span
398+
edition
403399
});
404400

405401
impl_stable_hash_for!(enum ::syntax_pos::hygiene::ExpnFormat {

src/librustc/traits/error_reporting.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
366366
}
367367

368368
if let Some(k) = obligation.cause.span.compiler_desugaring_kind() {
369-
let desugaring = k.as_symbol().as_str();
370369
flags.push(("from_desugaring".to_string(), None));
371-
flags.push(("from_desugaring".to_string(), Some(desugaring.to_string())));
370+
flags.push(("from_desugaring".to_string(), Some(k.name().to_string())));
372371
}
373372
let generics = self.tcx.generics_of(def_id);
374373
let self_ty = trait_ref.self_ty();

src/librustc_allocator/expand.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use syntax::ast::{Arg, FnHeader, Generics, Mac, Mutability, Ty, Unsafety};
1515
use syntax::ast::{self, Expr, Ident, Item, ItemKind, TyKind, VisibilityKind};
1616
use syntax::attr;
1717
use syntax::codemap::respan;
18-
use syntax::codemap::{ExpnInfo, MacroAttribute, NameAndSpan};
18+
use syntax::codemap::{ExpnInfo, MacroAttribute};
1919
use syntax::ext::base::ExtCtxt;
2020
use syntax::ext::base::Resolver;
2121
use syntax::ext::build::AstBuilder;
@@ -80,13 +80,11 @@ impl<'a> Folder for ExpandAllocatorDirectives<'a> {
8080
let mark = Mark::fresh(Mark::root());
8181
mark.set_expn_info(ExpnInfo {
8282
call_site: DUMMY_SP,
83-
callee: NameAndSpan {
84-
format: MacroAttribute(Symbol::intern(name)),
85-
span: None,
86-
allow_internal_unstable: true,
87-
allow_internal_unsafe: false,
88-
edition: hygiene::default_edition(),
89-
},
83+
def_site: None,
84+
format: MacroAttribute(Symbol::intern(name)),
85+
allow_internal_unstable: true,
86+
allow_internal_unsafe: false,
87+
edition: hygiene::default_edition(),
9088
});
9189
let span = item.span.with_ctxt(SyntaxContext::empty().apply_mark(mark));
9290
let ecfg = ExpansionConfig::default(name.to_string());

src/librustc_save_analysis/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
844844
let callsite = span.source_callsite();
845845
let callsite_span = self.span_from_span(callsite);
846846
let callee = span.source_callee()?;
847-
let callee_span = callee.span?;
847+
let callee_span = callee.def_site?;
848848

849849
// Ignore attribute macros, their spans are usually mangled
850850
if let MacroAttribute(_) = callee.format {
@@ -872,7 +872,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
872872
let callee_span = self.span_from_span(callee_span);
873873
Some(MacroRef {
874874
span: callsite_span,
875-
qualname: callee.name().to_string(), // FIXME: generate the real qualname
875+
qualname: callee.format.name().to_string(), // FIXME: generate the real qualname
876876
callee_span,
877877
})
878878
}

src/libsyntax/codemap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020

2121
pub use syntax_pos::*;
22-
pub use syntax_pos::hygiene::{ExpnFormat, ExpnInfo, NameAndSpan};
22+
pub use syntax_pos::hygiene::{ExpnFormat, ExpnInfo};
2323
pub use self::ExpnFormat::*;
2424

2525
use rustc_data_structures::fx::FxHashMap;

src/libsyntax/ext/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ impl<'a> ExtCtxt<'a> {
834834
let mut last_macro = None;
835835
loop {
836836
if ctxt.outer().expn_info().map_or(None, |info| {
837-
if info.callee.name() == "include" {
837+
if info.format.name() == "include" {
838838
// Stop going up the backtrace once include! is encountered
839839
return None;
840840
}

src/libsyntax/ext/derive.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use attr::HasAttrs;
1212
use ast;
13-
use codemap::{hygiene, ExpnInfo, NameAndSpan, ExpnFormat};
13+
use codemap::{hygiene, ExpnInfo, ExpnFormat};
1414
use ext::base::ExtCtxt;
1515
use ext::build::AstBuilder;
1616
use parse::parser::PathStyle;
@@ -60,13 +60,11 @@ pub fn add_derived_markers<T>(cx: &mut ExtCtxt, span: Span, traits: &[ast::Path]
6060

6161
cx.current_expansion.mark.set_expn_info(ExpnInfo {
6262
call_site: span,
63-
callee: NameAndSpan {
64-
format: ExpnFormat::MacroAttribute(Symbol::intern(&pretty_name)),
65-
span: None,
66-
allow_internal_unstable: true,
67-
allow_internal_unsafe: false,
68-
edition: hygiene::default_edition(),
69-
},
63+
def_site: None,
64+
format: ExpnFormat::MacroAttribute(Symbol::intern(&pretty_name)),
65+
allow_internal_unstable: true,
66+
allow_internal_unsafe: false,
67+
edition: hygiene::default_edition(),
7068
});
7169

7270
let span = span.with_ctxt(cx.backtrace());

src/libsyntax/ext/expand.rs

+31-41
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use ast::{self, Block, Ident, NodeId, PatKind, Path};
1212
use ast::{MacStmtStyle, StmtKind, ItemKind};
1313
use attr::{self, HasAttrs};
14-
use codemap::{ExpnInfo, NameAndSpan, MacroBang, MacroAttribute, dummy_spanned, respan};
14+
use codemap::{ExpnInfo, MacroBang, MacroAttribute, dummy_spanned, respan};
1515
use config::{is_test_or_bench, StripUnconfigured};
1616
use errors::{Applicability, FatalError};
1717
use ext::base::*;
@@ -514,7 +514,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
514514
let suggested_limit = self.cx.ecfg.recursion_limit * 2;
515515
let mut err = self.cx.struct_span_err(info.call_site,
516516
&format!("recursion limit reached while expanding the macro `{}`",
517-
info.callee.name()));
517+
info.format.name()));
518518
err.help(&format!(
519519
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",
520520
suggested_limit));
@@ -538,13 +538,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
538538
attr::mark_used(&attr);
539539
invoc.expansion_data.mark.set_expn_info(ExpnInfo {
540540
call_site: attr.span,
541-
callee: NameAndSpan {
542-
format: MacroAttribute(Symbol::intern(&format!("{}", attr.path))),
543-
span: None,
544-
allow_internal_unstable: false,
545-
allow_internal_unsafe: false,
546-
edition: ext.edition(),
547-
}
541+
def_site: None,
542+
format: MacroAttribute(Symbol::intern(&format!("{}", attr.path))),
543+
allow_internal_unstable: false,
544+
allow_internal_unsafe: false,
545+
edition: ext.edition(),
548546
});
549547

550548
match *ext {
@@ -727,13 +725,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
727725
}
728726
mark.set_expn_info(ExpnInfo {
729727
call_site: span,
730-
callee: NameAndSpan {
731-
format: macro_bang_format(path),
732-
span: def_site_span,
733-
allow_internal_unstable,
734-
allow_internal_unsafe,
735-
edition,
736-
},
728+
def_site: def_site_span,
729+
format: macro_bang_format(path),
730+
allow_internal_unstable,
731+
allow_internal_unsafe,
732+
edition,
737733
});
738734
Ok(())
739735
};
@@ -777,13 +773,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
777773
} else {
778774
invoc.expansion_data.mark.set_expn_info(ExpnInfo {
779775
call_site: span,
780-
callee: NameAndSpan {
781-
format: macro_bang_format(path),
782-
span: tt_span,
783-
allow_internal_unstable,
784-
allow_internal_unsafe: false,
785-
edition: hygiene::default_edition(),
786-
}
776+
def_site: tt_span,
777+
format: macro_bang_format(path),
778+
allow_internal_unstable,
779+
allow_internal_unsafe: false,
780+
edition: hygiene::default_edition(),
787781
});
788782

789783
let input: Vec<_> = mac.node.stream().into_trees().collect();
@@ -815,16 +809,14 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
815809
self.gate_proc_macro_expansion_kind(span, kind);
816810
invoc.expansion_data.mark.set_expn_info(ExpnInfo {
817811
call_site: span,
818-
callee: NameAndSpan {
819-
format: macro_bang_format(path),
820-
// FIXME procedural macros do not have proper span info
821-
// yet, when they do, we should use it here.
822-
span: None,
823-
// FIXME probably want to follow macro_rules macros here.
824-
allow_internal_unstable,
825-
allow_internal_unsafe: false,
826-
edition,
827-
},
812+
// FIXME procedural macros do not have proper span info
813+
// yet, when they do, we should use it here.
814+
def_site: None,
815+
format: macro_bang_format(path),
816+
// FIXME probably want to follow macro_rules macros here.
817+
allow_internal_unstable,
818+
allow_internal_unsafe: false,
819+
edition,
828820
});
829821

830822
let tok_result = expandfun.expand(self.cx, span, mac.node.stream());
@@ -894,13 +886,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
894886

895887
let mut expn_info = ExpnInfo {
896888
call_site: span,
897-
callee: NameAndSpan {
898-
format: MacroAttribute(pretty_name),
899-
span: None,
900-
allow_internal_unstable: false,
901-
allow_internal_unsafe: false,
902-
edition: ext.edition(),
903-
}
889+
def_site: None,
890+
format: MacroAttribute(pretty_name),
891+
allow_internal_unstable: false,
892+
allow_internal_unsafe: false,
893+
edition: ext.edition(),
904894
};
905895

906896
match *ext {
@@ -916,7 +906,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
916906
Some(invoc.fragment_kind.expect_from_annotatables(items))
917907
}
918908
BuiltinDerive(func) => {
919-
expn_info.callee.allow_internal_unstable = true;
909+
expn_info.allow_internal_unstable = true;
920910
invoc.expansion_data.mark.set_expn_info(expn_info);
921911
let span = span.with_ctxt(self.cx.backtrace());
922912
let mut items = Vec::new();

src/libsyntax/std_inject.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::cell::Cell;
1414
use ext::hygiene::{Mark, SyntaxContext};
1515
use symbol::{Symbol, keywords};
1616
use syntax_pos::{DUMMY_SP, Span};
17-
use codemap::{ExpnInfo, NameAndSpan, MacroAttribute, dummy_spanned, hygiene, respan};
17+
use codemap::{ExpnInfo, MacroAttribute, dummy_spanned, hygiene, respan};
1818
use ptr::P;
1919
use tokenstream::TokenStream;
2020

@@ -25,13 +25,11 @@ fn ignored_span(sp: Span) -> Span {
2525
let mark = Mark::fresh(Mark::root());
2626
mark.set_expn_info(ExpnInfo {
2727
call_site: DUMMY_SP,
28-
callee: NameAndSpan {
29-
format: MacroAttribute(Symbol::intern("std_inject")),
30-
span: None,
31-
allow_internal_unstable: true,
32-
allow_internal_unsafe: false,
33-
edition: hygiene::default_edition(),
34-
}
28+
def_site: None,
29+
format: MacroAttribute(Symbol::intern("std_inject")),
30+
allow_internal_unstable: true,
31+
allow_internal_unsafe: false,
32+
edition: hygiene::default_edition(),
3533
});
3634
sp.with_ctxt(SyntaxContext::empty().apply_mark(mark))
3735
}

src/libsyntax/test.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::vec;
2222
use attr::{self, HasAttrs};
2323
use syntax_pos::{self, DUMMY_SP, NO_EXPANSION, Span, FileMap, BytePos};
2424

25-
use codemap::{self, CodeMap, ExpnInfo, NameAndSpan, MacroAttribute, dummy_spanned};
25+
use codemap::{self, CodeMap, ExpnInfo, MacroAttribute, dummy_spanned};
2626
use errors;
2727
use config;
2828
use entry::{self, EntryPointType};
@@ -307,13 +307,11 @@ fn generate_test_harness(sess: &ParseSess,
307307

308308
mark.set_expn_info(ExpnInfo {
309309
call_site: DUMMY_SP,
310-
callee: NameAndSpan {
311-
format: MacroAttribute(Symbol::intern("test")),
312-
span: None,
313-
allow_internal_unstable: true,
314-
allow_internal_unsafe: false,
315-
edition: hygiene::default_edition(),
316-
}
310+
def_site: None,
311+
format: MacroAttribute(Symbol::intern("test")),
312+
allow_internal_unstable: true,
313+
allow_internal_unsafe: false,
314+
edition: hygiene::default_edition(),
317315
});
318316

319317
TestHarnessGenerator {

src/libsyntax_ext/deriving/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ fn call_intrinsic(cx: &ExtCtxt,
157157
intrinsic: &str,
158158
args: Vec<P<ast::Expr>>)
159159
-> P<ast::Expr> {
160-
if cx.current_expansion.mark.expn_info().unwrap().callee.allow_internal_unstable {
160+
if cx.current_expansion.mark.expn_info().unwrap().allow_internal_unstable {
161161
span = span.with_ctxt(cx.backtrace());
162162
} else { // Avoid instability errors with user defined curstom derives, cc #36316
163163
let mut info = cx.current_expansion.mark.expn_info().unwrap();
164-
info.callee.allow_internal_unstable = true;
164+
info.allow_internal_unstable = true;
165165
let mark = Mark::fresh(Mark::root());
166166
mark.set_expn_info(info);
167167
span = span.with_ctxt(SyntaxContext::empty().apply_mark(mark));

src/libsyntax_ext/proc_macro_registrar.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use errors;
1414

1515
use syntax::ast::{self, Ident, NodeId};
1616
use syntax::attr;
17-
use syntax::codemap::{ExpnInfo, NameAndSpan, MacroAttribute, hygiene, respan};
17+
use syntax::codemap::{ExpnInfo, MacroAttribute, hygiene, respan};
1818
use syntax::ext::base::ExtCtxt;
1919
use syntax::ext::build::AstBuilder;
2020
use syntax::ext::expand::ExpansionConfig;
@@ -364,13 +364,11 @@ fn mk_registrar(cx: &mut ExtCtxt,
364364
let mark = Mark::fresh(Mark::root());
365365
mark.set_expn_info(ExpnInfo {
366366
call_site: DUMMY_SP,
367-
callee: NameAndSpan {
368-
format: MacroAttribute(Symbol::intern("proc_macro")),
369-
span: None,
370-
allow_internal_unstable: true,
371-
allow_internal_unsafe: false,
372-
edition: hygiene::default_edition(),
373-
}
367+
def_site: None,
368+
format: MacroAttribute(Symbol::intern("proc_macro")),
369+
allow_internal_unstable: true,
370+
allow_internal_unsafe: false,
371+
edition: hygiene::default_edition(),
374372
});
375373
let span = DUMMY_SP.apply_mark(mark);
376374

0 commit comments

Comments
 (0)