Skip to content

Commit 6b17cf3

Browse files
committed
Merge ExpnId and SyntaxContext.
1 parent 40e52d9 commit 6b17cf3

File tree

45 files changed

+454
-697
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+454
-697
lines changed

src/librustc/hir/lowering.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ use std::mem;
5555
use syntax::attr;
5656
use syntax::ast::*;
5757
use syntax::errors;
58+
use syntax::ext::hygiene::{Mark, SyntaxContext};
5859
use syntax::ptr::P;
5960
use syntax::codemap::{self, respan, Spanned};
6061
use syntax::std_inject;
@@ -252,14 +253,16 @@ impl<'a> LoweringContext<'a> {
252253
}
253254

254255
fn allow_internal_unstable(&self, reason: &'static str, mut span: Span) -> Span {
255-
span.expn_id = self.sess.codemap().record_expansion(codemap::ExpnInfo {
256+
let mark = Mark::fresh();
257+
mark.set_expn_info(codemap::ExpnInfo {
256258
call_site: span,
257259
callee: codemap::NameAndSpan {
258260
format: codemap::CompilerDesugaring(Symbol::intern(reason)),
259261
span: Some(span),
260262
allow_internal_unstable: true,
261263
},
262264
});
265+
span.ctxt = SyntaxContext::empty().apply_mark(mark);
263266
span
264267
}
265268

@@ -1827,7 +1830,7 @@ impl<'a> LoweringContext<'a> {
18271830
volatile: asm.volatile,
18281831
alignstack: asm.alignstack,
18291832
dialect: asm.dialect,
1830-
expn_id: asm.expn_id,
1833+
ctxt: asm.ctxt,
18311834
};
18321835
let outputs =
18331836
asm.outputs.iter().map(|out| self.lower_expr(&out.expr)).collect();

src/librustc/hir/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ use hir::def::Def;
3333
use hir::def_id::DefId;
3434
use util::nodemap::{NodeMap, FxHashSet};
3535

36-
use syntax_pos::{Span, ExpnId, DUMMY_SP};
36+
use syntax_pos::{Span, DUMMY_SP};
3737
use syntax::codemap::{self, Spanned};
3838
use syntax::abi::Abi;
3939
use syntax::ast::{Ident, Name, NodeId, DUMMY_NODE_ID, AsmDialect};
4040
use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, MetaItem};
41+
use syntax::ext::hygiene::SyntaxContext;
4142
use syntax::ptr::P;
4243
use syntax::symbol::{Symbol, keywords};
4344
use syntax::tokenstream::TokenStream;
@@ -1304,7 +1305,7 @@ pub struct InlineAsm {
13041305
pub volatile: bool,
13051306
pub alignstack: bool,
13061307
pub dialect: AsmDialect,
1307-
pub expn_id: ExpnId,
1308+
pub ctxt: SyntaxContext,
13081309
}
13091310

13101311
/// represents an argument in a function header

src/librustc/middle/region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl CodeExtent {
236236
// (This is the special case aluded to in the
237237
// doc-comment for this method)
238238
let stmt_span = blk.stmts[r.first_statement_index as usize].span;
239-
Some(Span { lo: stmt_span.hi, hi: blk.span.hi, expn_id: stmt_span.expn_id })
239+
Some(Span { lo: stmt_span.hi, hi: blk.span.hi, ctxt: stmt_span.ctxt })
240240
}
241241
}
242242
}

src/librustc/middle/stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
467467
}
468468

469469
pub fn check_stability(self, def_id: DefId, id: NodeId, span: Span) {
470-
if self.sess.codemap().span_allows_unstable(span) {
470+
if span.allows_unstable() {
471471
debug!("stability: \
472472
skipping span={:?} since it is internal", span);
473473
return;

src/librustc_driver/driver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
575575

576576
krate = time(time_passes, "crate injection", || {
577577
let alt_std_name = sess.opts.alt_std_name.clone();
578-
syntax::std_inject::maybe_inject_crates_ref(&sess.parse_sess, krate, alt_std_name)
578+
syntax::std_inject::maybe_inject_crates_ref(krate, alt_std_name)
579579
});
580580

581581
let mut addl_plugins = Some(addl_plugins);
@@ -793,7 +793,7 @@ pub fn phase_2_configure_and_expand<F>(sess: &Session,
793793

794794
// Discard hygiene data, which isn't required after lowering to HIR.
795795
if !keep_hygiene_data(sess) {
796-
syntax::ext::hygiene::reset_hygiene_data();
796+
syntax::ext::hygiene::clear_markings();
797797
}
798798

799799
Ok(ExpansionResult {

src/librustc_errors/emitter.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use self::Destination::*;
1212

13-
use syntax_pos::{COMMAND_LINE_SP, DUMMY_SP, FileMap, Span, MultiSpan, CharPos};
13+
use syntax_pos::{DUMMY_SP, FileMap, Span, MultiSpan, CharPos};
1414

1515
use {Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic, CodeMapper};
1616
use RenderSpan::*;
@@ -151,7 +151,7 @@ impl EmitterWriter {
151151

152152
if let Some(ref cm) = self.cm {
153153
for span_label in msp.span_labels() {
154-
if span_label.span == DUMMY_SP || span_label.span == COMMAND_LINE_SP {
154+
if span_label.span == DUMMY_SP {
155155
continue;
156156
}
157157
let lo = cm.lookup_char_pos(span_label.span.lo);
@@ -615,15 +615,15 @@ impl EmitterWriter {
615615
let mut max = 0;
616616
if let Some(ref cm) = self.cm {
617617
for primary_span in msp.primary_spans() {
618-
if primary_span != &DUMMY_SP && primary_span != &COMMAND_LINE_SP {
618+
if primary_span != &DUMMY_SP {
619619
let hi = cm.lookup_char_pos(primary_span.hi);
620620
if hi.line > max {
621621
max = hi.line;
622622
}
623623
}
624624
}
625625
for span_label in msp.span_labels() {
626-
if span_label.span != DUMMY_SP && span_label.span != COMMAND_LINE_SP {
626+
if span_label.span != DUMMY_SP {
627627
let hi = cm.lookup_char_pos(span_label.span.hi);
628628
if hi.line > max {
629629
max = hi.line;
@@ -659,20 +659,20 @@ impl EmitterWriter {
659659

660660
// First, find all the spans in <*macros> and point instead at their use site
661661
for sp in span.primary_spans() {
662-
if (*sp == COMMAND_LINE_SP) || (*sp == DUMMY_SP) {
662+
if *sp == DUMMY_SP {
663663
continue;
664664
}
665665
if cm.span_to_filename(sp.clone()).contains("macros>") {
666-
let v = cm.macro_backtrace(sp.clone());
666+
let v = sp.macro_backtrace();
667667
if let Some(use_site) = v.last() {
668668
before_after.push((sp.clone(), use_site.call_site.clone()));
669669
}
670670
}
671-
for trace in cm.macro_backtrace(sp.clone()).iter().rev() {
671+
for trace in sp.macro_backtrace().iter().rev() {
672672
// Only show macro locations that are local
673673
// and display them like a span_note
674674
if let Some(def_site) = trace.def_site_span {
675-
if (def_site == COMMAND_LINE_SP) || (def_site == DUMMY_SP) {
675+
if def_site == DUMMY_SP {
676676
continue;
677677
}
678678
// Check to make sure we're not in any <*macros>
@@ -689,11 +689,11 @@ impl EmitterWriter {
689689
span.push_span_label(label_span, label_text);
690690
}
691691
for sp_label in span.span_labels() {
692-
if (sp_label.span == COMMAND_LINE_SP) || (sp_label.span == DUMMY_SP) {
692+
if sp_label.span == DUMMY_SP {
693693
continue;
694694
}
695695
if cm.span_to_filename(sp_label.span.clone()).contains("macros>") {
696-
let v = cm.macro_backtrace(sp_label.span.clone());
696+
let v = sp_label.span.macro_backtrace();
697697
if let Some(use_site) = v.last() {
698698
before_after.push((sp_label.span.clone(), use_site.call_site.clone()));
699699
}
@@ -848,7 +848,7 @@ impl EmitterWriter {
848848
// Make sure our primary file comes first
849849
let primary_lo = if let (Some(ref cm), Some(ref primary_span)) =
850850
(self.cm.as_ref(), msp.primary_span().as_ref()) {
851-
if primary_span != &&DUMMY_SP && primary_span != &&COMMAND_LINE_SP {
851+
if primary_span != &&DUMMY_SP {
852852
cm.lookup_char_pos(primary_span.lo)
853853
} else {
854854
emit_to_destination(&buffer.render(), level, &mut self.dst)?;

src/librustc_errors/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ pub mod styled_buffer;
4848
mod lock;
4949

5050
use syntax_pos::{BytePos, Loc, FileLinesResult, FileName, MultiSpan, Span, NO_EXPANSION};
51-
use syntax_pos::MacroBacktrace;
5251

5352
#[derive(Clone, Debug, PartialEq, RustcEncodable, RustcDecodable)]
5453
pub enum RenderSpan {
@@ -75,7 +74,6 @@ pub trait CodeMapper {
7574
fn span_to_lines(&self, sp: Span) -> FileLinesResult;
7675
fn span_to_string(&self, sp: Span) -> String;
7776
fn span_to_filename(&self, sp: Span) -> FileName;
78-
fn macro_backtrace(&self, span: Span) -> Vec<MacroBacktrace>;
7977
fn merge_spans(&self, sp_lhs: Span, sp_rhs: Span) -> Option<Span>;
8078
}
8179

@@ -120,7 +118,7 @@ impl CodeSuggestion {
120118
let bounding_span = Span {
121119
lo: lo,
122120
hi: hi,
123-
expn_id: NO_EXPANSION,
121+
ctxt: NO_EXPANSION,
124122
};
125123
let lines = cm.span_to_lines(bounding_span).unwrap();
126124
assert!(!lines.lines.is_empty());

src/librustc_incremental/calculate_svh/caching_codemap_view.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ impl<'tcx> CachingCodemapView<'tcx> {
4747
}
4848
}
4949

50-
pub fn codemap(&self) -> &'tcx CodeMap {
51-
self.codemap
52-
}
53-
5450
pub fn byte_pos_to_line_and_col(&mut self,
5551
pos: BytePos)
5652
-> Option<(Rc<FileMap>, usize, BytePos)> {

src/librustc_incremental/calculate_svh/svh_visitor.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ use self::SawTraitOrImplItemComponent::*;
1717
use syntax::abi::Abi;
1818
use syntax::ast::{self, Name, NodeId};
1919
use syntax::attr;
20+
use syntax::ext::hygiene::SyntaxContext;
2021
use syntax::parse::token;
2122
use syntax::symbol::InternedString;
22-
use syntax_pos::{Span, NO_EXPANSION, COMMAND_LINE_EXPN, BytePos};
23+
use syntax_pos::{Span, BytePos};
2324
use syntax::tokenstream;
2425
use rustc::hir;
2526
use rustc::hir::*;
@@ -103,10 +104,10 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
103104
span.hi
104105
};
105106

106-
let expn_kind = match span.expn_id {
107-
NO_EXPANSION => SawSpanExpnKind::NoExpansion,
108-
COMMAND_LINE_EXPN => SawSpanExpnKind::CommandLine,
109-
_ => SawSpanExpnKind::SomeExpansion,
107+
let expn_kind = if span.ctxt == SyntaxContext::empty() {
108+
SawSpanExpnKind::NoExpansion
109+
} else {
110+
SawSpanExpnKind::SomeExpansion
110111
};
111112

112113
let loc1 = self.codemap.byte_pos_to_line_and_col(span.lo);
@@ -132,8 +133,7 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
132133
saw.hash(self.st);
133134

134135
if expn_kind == SawSpanExpnKind::SomeExpansion {
135-
let call_site = self.codemap.codemap().source_callsite(span);
136-
self.hash_span(call_site);
136+
self.hash_span(span.source_callsite());
137137
}
138138
}
139139

@@ -494,7 +494,6 @@ fn saw_impl_item(ii: &ImplItemKind) -> SawTraitOrImplItemComponent {
494494
#[derive(Clone, Copy, Hash, Eq, PartialEq)]
495495
enum SawSpanExpnKind {
496496
NoExpansion,
497-
CommandLine,
498497
SomeExpansion,
499498
}
500499

@@ -512,7 +511,7 @@ impl<'a> Hash for StableInlineAsm<'a> {
512511
volatile,
513512
alignstack,
514513
dialect,
515-
expn_id: _, // This is used for error reporting
514+
ctxt: _, // This is used for error reporting
516515
} = *self.0;
517516

518517
asm.as_str().hash(state);

src/librustc_mir/transform/qualify_consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> {
223223
}
224224

225225
// This comes from a macro that has #[allow_internal_unstable].
226-
if self.tcx.sess.codemap().span_allows_unstable(self.span) {
226+
if self.span.allows_unstable() {
227227
return;
228228
}
229229

@@ -810,7 +810,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
810810
self.def_id.is_local() &&
811811

812812
// this doesn't come from a macro that has #[allow_internal_unstable]
813-
!self.tcx.sess.codemap().span_allows_unstable(self.span)
813+
!self.span.allows_unstable()
814814
{
815815
let mut err = self.tcx.sess.struct_span_err(self.span,
816816
"const fns are an unstable feature");

0 commit comments

Comments
 (0)