Skip to content

Commit fe15119

Browse files
committedMar 30, 2017
Auto merge of #40597 - jseyfried:improve_span_expn_info, r=jseyfried
macros: improve `Span`'s expansion information This PR improves `Span`'s expansion information. More specifically: - It refactors AST node span construction to preserve expansion information. - Today, we only use the underlying tokens' `BytePos`s, throwing away the `ExpnId`s. - This improves the accuracy of AST nodes' expansion information, fixing #30506. - It refactors `span.expn_id: ExpnId` to `span.ctxt: SyntaxContext` and removes `ExpnId`. - This gives all tokens as much hygiene information as `Ident`s. - This is groundwork for procedural macros 2.0 `TokenStream` API. - This is also groundwork for declarative macros 2.0, which will need this hygiene information for some non-`Ident` tokens. - It simplifies processing of spans' expansion information throughout the compiler. - It fixes #40649. - It fixes #39450 and fixes part of #23480. r? @nrc
2 parents 6afa0d4 + 8fde04b commit fe15119

Some content is hidden

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

67 files changed

+932
-1408
lines changed
 

‎src/librustc/hir/lowering.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ use std::mem;
5757
use syntax::attr;
5858
use syntax::ast::*;
5959
use syntax::errors;
60+
use syntax::ext::hygiene::{Mark, SyntaxContext};
6061
use syntax::ptr::P;
6162
use syntax::codemap::{self, respan, Spanned};
6263
use syntax::std_inject;
@@ -392,14 +393,16 @@ impl<'a> LoweringContext<'a> {
392393
}
393394

394395
fn allow_internal_unstable(&self, reason: &'static str, mut span: Span) -> Span {
395-
span.expn_id = self.sess.codemap().record_expansion(codemap::ExpnInfo {
396+
let mark = Mark::fresh();
397+
mark.set_expn_info(codemap::ExpnInfo {
396398
call_site: span,
397399
callee: codemap::NameAndSpan {
398400
format: codemap::CompilerDesugaring(Symbol::intern(reason)),
399401
span: Some(span),
400402
allow_internal_unstable: true,
401403
},
402404
});
405+
span.ctxt = SyntaxContext::empty().apply_mark(mark);
403406
span
404407
}
405408

@@ -1993,7 +1996,7 @@ impl<'a> LoweringContext<'a> {
19931996
volatile: asm.volatile,
19941997
alignstack: asm.alignstack,
19951998
dialect: asm.dialect,
1996-
expn_id: asm.expn_id,
1999+
ctxt: asm.ctxt,
19972000
};
19982001
let outputs =
19992002
asm.outputs.iter().map(|out| self.lower_expr(&out.expr)).collect();

‎src/librustc/hir/map/def_collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<'a> DefCollector<'a> {
9292
fn visit_macro_invoc(&mut self, id: NodeId, const_expr: bool) {
9393
if let Some(ref mut visit) = self.visit_macro_invoc {
9494
visit(MacroInvocationData {
95-
mark: Mark::from_placeholder_id(id),
95+
mark: id.placeholder_to_mark(),
9696
const_expr: const_expr,
9797
def_index: self.parent_def.unwrap(),
9898
})

0 commit comments

Comments
 (0)