Skip to content

Commit

Permalink
hygiene: Merge NameAndSpan into ExpnInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jun 23, 2018
1 parent 117cb04 commit 20ce910
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 154 deletions.
12 changes: 5 additions & 7 deletions src/librustc/hir/lowering.rs
Expand Up @@ -612,13 +612,11 @@ impl<'a> LoweringContext<'a> {
let mark = Mark::fresh(Mark::root());
mark.set_expn_info(codemap::ExpnInfo {
call_site: span,
callee: codemap::NameAndSpan {
format: codemap::CompilerDesugaring(reason),
span: Some(span),
allow_internal_unstable: true,
allow_internal_unsafe: false,
edition: codemap::hygiene::default_edition(),
},
def_site: Some(span),
format: codemap::CompilerDesugaring(reason),
allow_internal_unstable: true,
allow_internal_unsafe: false,
edition: codemap::hygiene::default_edition(),
});
span.with_ctxt(SyntaxContext::empty().apply_mark(mark))
}
Expand Down
8 changes: 2 additions & 6 deletions src/librustc/ich/impls_syntax.rs
Expand Up @@ -391,15 +391,11 @@ impl_stable_hash_for!(enum ::syntax::ast::MetaItemKind {

impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnInfo {
call_site,
callee
});

impl_stable_hash_for!(struct ::syntax_pos::hygiene::NameAndSpan {
def_site,
format,
allow_internal_unstable,
allow_internal_unsafe,
edition,
span
edition
});

impl_stable_hash_for!(enum ::syntax_pos::hygiene::ExpnFormat {
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/traits/error_reporting.rs
Expand Up @@ -366,9 +366,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
}

if let Some(k) = obligation.cause.span.compiler_desugaring_kind() {
let desugaring = k.as_symbol().as_str();
flags.push(("from_desugaring".to_string(), None));
flags.push(("from_desugaring".to_string(), Some(desugaring.to_string())));
flags.push(("from_desugaring".to_string(), Some(k.name().to_string())));
}
let generics = self.tcx.generics_of(def_id);
let self_ty = trait_ref.self_ty();
Expand Down
14 changes: 6 additions & 8 deletions src/librustc_allocator/expand.rs
Expand Up @@ -15,7 +15,7 @@ use syntax::ast::{Arg, FnHeader, Generics, Mac, Mutability, Ty, Unsafety};
use syntax::ast::{self, Expr, Ident, Item, ItemKind, TyKind, VisibilityKind};
use syntax::attr;
use syntax::codemap::respan;
use syntax::codemap::{ExpnInfo, MacroAttribute, NameAndSpan};
use syntax::codemap::{ExpnInfo, MacroAttribute};
use syntax::ext::base::ExtCtxt;
use syntax::ext::base::Resolver;
use syntax::ext::build::AstBuilder;
Expand Down Expand Up @@ -80,13 +80,11 @@ impl<'a> Folder for ExpandAllocatorDirectives<'a> {
let mark = Mark::fresh(Mark::root());
mark.set_expn_info(ExpnInfo {
call_site: DUMMY_SP,
callee: NameAndSpan {
format: MacroAttribute(Symbol::intern(name)),
span: None,
allow_internal_unstable: true,
allow_internal_unsafe: false,
edition: hygiene::default_edition(),
},
def_site: None,
format: MacroAttribute(Symbol::intern(name)),
allow_internal_unstable: true,
allow_internal_unsafe: false,
edition: hygiene::default_edition(),
});
let span = item.span.with_ctxt(SyntaxContext::empty().apply_mark(mark));
let ecfg = ExpansionConfig::default(name.to_string());
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_save_analysis/lib.rs
Expand Up @@ -844,7 +844,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
let callsite = span.source_callsite();
let callsite_span = self.span_from_span(callsite);
let callee = span.source_callee()?;
let callee_span = callee.span?;
let callee_span = callee.def_site?;

// Ignore attribute macros, their spans are usually mangled
if let MacroAttribute(_) = callee.format {
Expand Down Expand Up @@ -872,7 +872,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
let callee_span = self.span_from_span(callee_span);
Some(MacroRef {
span: callsite_span,
qualname: callee.name().to_string(), // FIXME: generate the real qualname
qualname: callee.format.name().to_string(), // FIXME: generate the real qualname
callee_span,
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/codemap.rs
Expand Up @@ -19,7 +19,7 @@


pub use syntax_pos::*;
pub use syntax_pos::hygiene::{ExpnFormat, ExpnInfo, NameAndSpan};
pub use syntax_pos::hygiene::{ExpnFormat, ExpnInfo};
pub use self::ExpnFormat::*;

use rustc_data_structures::fx::FxHashMap;
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/base.rs
Expand Up @@ -834,7 +834,7 @@ impl<'a> ExtCtxt<'a> {
let mut last_macro = None;
loop {
if ctxt.outer().expn_info().map_or(None, |info| {
if info.callee.name() == "include" {
if info.format.name() == "include" {
// Stop going up the backtrace once include! is encountered
return None;
}
Expand Down
14 changes: 6 additions & 8 deletions src/libsyntax/ext/derive.rs
Expand Up @@ -10,7 +10,7 @@

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

cx.current_expansion.mark.set_expn_info(ExpnInfo {
call_site: span,
callee: NameAndSpan {
format: ExpnFormat::MacroAttribute(Symbol::intern(&pretty_name)),
span: None,
allow_internal_unstable: true,
allow_internal_unsafe: false,
edition: hygiene::default_edition(),
},
def_site: None,
format: ExpnFormat::MacroAttribute(Symbol::intern(&pretty_name)),
allow_internal_unstable: true,
allow_internal_unsafe: false,
edition: hygiene::default_edition(),
});

let span = span.with_ctxt(cx.backtrace());
Expand Down
72 changes: 31 additions & 41 deletions src/libsyntax/ext/expand.rs
Expand Up @@ -11,7 +11,7 @@
use ast::{self, Block, Ident, NodeId, PatKind, Path};
use ast::{MacStmtStyle, StmtKind, ItemKind};
use attr::{self, HasAttrs};
use codemap::{ExpnInfo, NameAndSpan, MacroBang, MacroAttribute, dummy_spanned, respan};
use codemap::{ExpnInfo, MacroBang, MacroAttribute, dummy_spanned, respan};
use config::{is_test_or_bench, StripUnconfigured};
use errors::{Applicability, FatalError};
use ext::base::*;
Expand Down Expand Up @@ -514,7 +514,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
let suggested_limit = self.cx.ecfg.recursion_limit * 2;
let mut err = self.cx.struct_span_err(info.call_site,
&format!("recursion limit reached while expanding the macro `{}`",
info.callee.name()));
info.format.name()));
err.help(&format!(
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",
suggested_limit));
Expand All @@ -538,13 +538,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
attr::mark_used(&attr);
invoc.expansion_data.mark.set_expn_info(ExpnInfo {
call_site: attr.span,
callee: NameAndSpan {
format: MacroAttribute(Symbol::intern(&format!("{}", attr.path))),
span: None,
allow_internal_unstable: false,
allow_internal_unsafe: false,
edition: ext.edition(),
}
def_site: None,
format: MacroAttribute(Symbol::intern(&format!("{}", attr.path))),
allow_internal_unstable: false,
allow_internal_unsafe: false,
edition: ext.edition(),
});

match *ext {
Expand Down Expand Up @@ -727,13 +725,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
}
mark.set_expn_info(ExpnInfo {
call_site: span,
callee: NameAndSpan {
format: macro_bang_format(path),
span: def_site_span,
allow_internal_unstable,
allow_internal_unsafe,
edition,
},
def_site: def_site_span,
format: macro_bang_format(path),
allow_internal_unstable,
allow_internal_unsafe,
edition,
});
Ok(())
};
Expand Down Expand Up @@ -777,13 +773,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
} else {
invoc.expansion_data.mark.set_expn_info(ExpnInfo {
call_site: span,
callee: NameAndSpan {
format: macro_bang_format(path),
span: tt_span,
allow_internal_unstable,
allow_internal_unsafe: false,
edition: hygiene::default_edition(),
}
def_site: tt_span,
format: macro_bang_format(path),
allow_internal_unstable,
allow_internal_unsafe: false,
edition: hygiene::default_edition(),
});

let input: Vec<_> = mac.node.stream().into_trees().collect();
Expand Down Expand Up @@ -815,16 +809,14 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
self.gate_proc_macro_expansion_kind(span, kind);
invoc.expansion_data.mark.set_expn_info(ExpnInfo {
call_site: span,
callee: NameAndSpan {
format: macro_bang_format(path),
// FIXME procedural macros do not have proper span info
// yet, when they do, we should use it here.
span: None,
// FIXME probably want to follow macro_rules macros here.
allow_internal_unstable,
allow_internal_unsafe: false,
edition,
},
// FIXME procedural macros do not have proper span info
// yet, when they do, we should use it here.
def_site: None,
format: macro_bang_format(path),
// FIXME probably want to follow macro_rules macros here.
allow_internal_unstable,
allow_internal_unsafe: false,
edition,
});

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

let mut expn_info = ExpnInfo {
call_site: span,
callee: NameAndSpan {
format: MacroAttribute(pretty_name),
span: None,
allow_internal_unstable: false,
allow_internal_unsafe: false,
edition: ext.edition(),
}
def_site: None,
format: MacroAttribute(pretty_name),
allow_internal_unstable: false,
allow_internal_unsafe: false,
edition: ext.edition(),
};

match *ext {
Expand All @@ -916,7 +906,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
Some(invoc.fragment_kind.expect_from_annotatables(items))
}
BuiltinDerive(func) => {
expn_info.callee.allow_internal_unstable = true;
expn_info.allow_internal_unstable = true;
invoc.expansion_data.mark.set_expn_info(expn_info);
let span = span.with_ctxt(self.cx.backtrace());
let mut items = Vec::new();
Expand Down
14 changes: 6 additions & 8 deletions src/libsyntax/std_inject.rs
Expand Up @@ -14,7 +14,7 @@ use std::cell::Cell;
use ext::hygiene::{Mark, SyntaxContext};
use symbol::{Symbol, keywords};
use syntax_pos::{DUMMY_SP, Span};
use codemap::{ExpnInfo, NameAndSpan, MacroAttribute, dummy_spanned, hygiene, respan};
use codemap::{ExpnInfo, MacroAttribute, dummy_spanned, hygiene, respan};
use ptr::P;
use tokenstream::TokenStream;

Expand All @@ -25,13 +25,11 @@ fn ignored_span(sp: Span) -> Span {
let mark = Mark::fresh(Mark::root());
mark.set_expn_info(ExpnInfo {
call_site: DUMMY_SP,
callee: NameAndSpan {
format: MacroAttribute(Symbol::intern("std_inject")),
span: None,
allow_internal_unstable: true,
allow_internal_unsafe: false,
edition: hygiene::default_edition(),
}
def_site: None,
format: MacroAttribute(Symbol::intern("std_inject")),
allow_internal_unstable: true,
allow_internal_unsafe: false,
edition: hygiene::default_edition(),
});
sp.with_ctxt(SyntaxContext::empty().apply_mark(mark))
}
Expand Down
14 changes: 6 additions & 8 deletions src/libsyntax/test.rs
Expand Up @@ -22,7 +22,7 @@ use std::vec;
use attr::{self, HasAttrs};
use syntax_pos::{self, DUMMY_SP, NO_EXPANSION, Span, FileMap, BytePos};

use codemap::{self, CodeMap, ExpnInfo, NameAndSpan, MacroAttribute, dummy_spanned};
use codemap::{self, CodeMap, ExpnInfo, MacroAttribute, dummy_spanned};
use errors;
use config;
use entry::{self, EntryPointType};
Expand Down Expand Up @@ -307,13 +307,11 @@ fn generate_test_harness(sess: &ParseSess,

mark.set_expn_info(ExpnInfo {
call_site: DUMMY_SP,
callee: NameAndSpan {
format: MacroAttribute(Symbol::intern("test")),
span: None,
allow_internal_unstable: true,
allow_internal_unsafe: false,
edition: hygiene::default_edition(),
}
def_site: None,
format: MacroAttribute(Symbol::intern("test")),
allow_internal_unstable: true,
allow_internal_unsafe: false,
edition: hygiene::default_edition(),
});

TestHarnessGenerator {
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax_ext/deriving/mod.rs
Expand Up @@ -157,11 +157,11 @@ fn call_intrinsic(cx: &ExtCtxt,
intrinsic: &str,
args: Vec<P<ast::Expr>>)
-> P<ast::Expr> {
if cx.current_expansion.mark.expn_info().unwrap().callee.allow_internal_unstable {
if cx.current_expansion.mark.expn_info().unwrap().allow_internal_unstable {
span = span.with_ctxt(cx.backtrace());
} else { // Avoid instability errors with user defined curstom derives, cc #36316
let mut info = cx.current_expansion.mark.expn_info().unwrap();
info.callee.allow_internal_unstable = true;
info.allow_internal_unstable = true;
let mark = Mark::fresh(Mark::root());
mark.set_expn_info(info);
span = span.with_ctxt(SyntaxContext::empty().apply_mark(mark));
Expand Down
14 changes: 6 additions & 8 deletions src/libsyntax_ext/proc_macro_registrar.rs
Expand Up @@ -14,7 +14,7 @@ use errors;

use syntax::ast::{self, Ident, NodeId};
use syntax::attr;
use syntax::codemap::{ExpnInfo, NameAndSpan, MacroAttribute, hygiene, respan};
use syntax::codemap::{ExpnInfo, MacroAttribute, hygiene, respan};
use syntax::ext::base::ExtCtxt;
use syntax::ext::build::AstBuilder;
use syntax::ext::expand::ExpansionConfig;
Expand Down Expand Up @@ -364,13 +364,11 @@ fn mk_registrar(cx: &mut ExtCtxt,
let mark = Mark::fresh(Mark::root());
mark.set_expn_info(ExpnInfo {
call_site: DUMMY_SP,
callee: NameAndSpan {
format: MacroAttribute(Symbol::intern("proc_macro")),
span: None,
allow_internal_unstable: true,
allow_internal_unsafe: false,
edition: hygiene::default_edition(),
}
def_site: None,
format: MacroAttribute(Symbol::intern("proc_macro")),
allow_internal_unstable: true,
allow_internal_unsafe: false,
edition: hygiene::default_edition(),
});
let span = DUMMY_SP.apply_mark(mark);

Expand Down

0 comments on commit 20ce910

Please sign in to comment.