Rename some things in syntax_pos/hygiene

More consistent with other naming:
ExpnFormat -> ExpnKind
ExpnKind::name -> ExpnKind::descr
DesugaringKind::name -> DesugaringKind::descr

Shorter, no tautology:
CompilerDesugaring -> Desugaring
CompilerDesugaringKind -> DesugaringKind
This commit is contained in:
Vadim Petrochenkov 2019-06-19 01:08:45 +03:00
parent ec376c783e
commit 16918a8e28
25 changed files with 111 additions and 110 deletions

View file

@ -62,8 +62,7 @@ use syntax::ast::*;
use syntax::errors;
use syntax::ext::hygiene::{Mark, SyntaxContext};
use syntax::print::pprust;
use syntax::source_map::{self, respan, ExpnInfo, CompilerDesugaringKind, Spanned};
use syntax::source_map::CompilerDesugaringKind::CondTemporary;
use syntax::source_map::{respan, ExpnInfo, ExpnKind, DesugaringKind, Spanned};
use syntax::std_inject;
use syntax::symbol::{kw, sym, Symbol};
use syntax::tokenstream::{TokenStream, TokenTree};
@ -872,7 +871,7 @@ impl<'a> LoweringContext<'a> {
/// allowed inside this span.
fn mark_span_with_reason(
&self,
reason: CompilerDesugaringKind,
reason: DesugaringKind,
span: Span,
allow_internal_unstable: Option<Lrc<[Symbol]>>,
) -> Span {
@ -880,7 +879,7 @@ impl<'a> LoweringContext<'a> {
mark.set_expn_info(ExpnInfo {
def_site: Some(span),
allow_internal_unstable,
..ExpnInfo::default(source_map::CompilerDesugaring(reason), span, self.sess.edition())
..ExpnInfo::default(ExpnKind::Desugaring(reason), span, self.sess.edition())
});
span.with_ctxt(SyntaxContext::empty().apply_mark(mark))
}
@ -1188,7 +1187,7 @@ impl<'a> LoweringContext<'a> {
};
let unstable_span = self.mark_span_with_reason(
CompilerDesugaringKind::Async,
DesugaringKind::Async,
span,
self.allow_gen_future.clone(),
);
@ -1733,7 +1732,7 @@ impl<'a> LoweringContext<'a> {
// Not tracking it makes lints in rustc and clippy very fragile, as
// frequently opened issues show.
let exist_ty_span = self.mark_span_with_reason(
CompilerDesugaringKind::ExistentialType,
DesugaringKind::ExistentialType,
span,
None,
);
@ -2603,7 +2602,7 @@ impl<'a> LoweringContext<'a> {
let span = output.span();
let exist_ty_span = self.mark_span_with_reason(
CompilerDesugaringKind::Async,
DesugaringKind::Async,
span,
None,
);
@ -3275,7 +3274,7 @@ impl<'a> LoweringContext<'a> {
};
let desugared_span =
this.mark_span_with_reason(CompilerDesugaringKind::Async, span, None);
this.mark_span_with_reason(DesugaringKind::Async, span, None);
// Construct an argument representing `__argN: <ty>` to replace the argument of the
// async function.
@ -4410,7 +4409,9 @@ impl<'a> LoweringContext<'a> {
_ => {
// Lower condition:
let cond = self.lower_expr(cond);
let span_block = self.mark_span_with_reason(CondTemporary, cond.span, None);
let span_block = self.mark_span_with_reason(
DesugaringKind::CondTemporary, cond.span, None
);
// Wrap in a construct equivalent to `{ let _t = $cond; _t }`
// to preserve drop semantics since `if cond { ... }` does not
// let temporaries live outside of `cond`.
@ -4469,7 +4470,9 @@ impl<'a> LoweringContext<'a> {
// Lower condition:
let cond = this.with_loop_condition_scope(|this| this.lower_expr(cond));
let span_block = this.mark_span_with_reason(CondTemporary, cond.span, None);
let span_block = this.mark_span_with_reason(
DesugaringKind::CondTemporary, cond.span, None
);
// Wrap in a construct equivalent to `{ let _t = $cond; _t }`
// to preserve drop semantics since `while cond { ... }` does not
// let temporaries live outside of `cond`.
@ -4508,7 +4511,7 @@ impl<'a> LoweringContext<'a> {
ExprKind::TryBlock(ref body) => {
self.with_catch_scope(body.id, |this| {
let unstable_span = this.mark_span_with_reason(
CompilerDesugaringKind::TryBlock,
DesugaringKind::TryBlock,
body.span,
this.allow_try_trait.clone(),
);
@ -4836,7 +4839,7 @@ impl<'a> LoweringContext<'a> {
let mut head = self.lower_expr(head);
let head_sp = head.span;
let desugared_span = self.mark_span_with_reason(
CompilerDesugaringKind::ForLoop,
DesugaringKind::ForLoop,
head_sp,
None,
);
@ -4990,13 +4993,13 @@ impl<'a> LoweringContext<'a> {
// }
let unstable_span = self.mark_span_with_reason(
CompilerDesugaringKind::QuestionMark,
DesugaringKind::QuestionMark,
e.span,
self.allow_try_trait.clone(),
);
let try_span = self.sess.source_map().end_point(e.span);
let try_span = self.mark_span_with_reason(
CompilerDesugaringKind::QuestionMark,
DesugaringKind::QuestionMark,
try_span,
self.allow_try_trait.clone(),
);
@ -5811,12 +5814,12 @@ impl<'a> LoweringContext<'a> {
}
}
let span = self.mark_span_with_reason(
CompilerDesugaringKind::Await,
DesugaringKind::Await,
await_span,
None,
);
let gen_future_span = self.mark_span_with_reason(
CompilerDesugaringKind::Await,
DesugaringKind::Await,
await_span,
self.allow_gen_future.clone(),
);

View file

@ -398,7 +398,7 @@ impl_stable_hash_for!(enum ::syntax_pos::hygiene::Transparency {
impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnInfo {
call_site,
format,
kind,
def_site,
default_transparency,
allow_internal_unstable,
@ -407,13 +407,13 @@ impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnInfo {
edition
});
impl_stable_hash_for!(enum ::syntax_pos::hygiene::ExpnFormat {
impl_stable_hash_for!(enum ::syntax_pos::hygiene::ExpnKind {
MacroAttribute(sym),
MacroBang(sym),
CompilerDesugaring(kind)
Desugaring(kind)
});
impl_stable_hash_for!(enum ::syntax_pos::hygiene::CompilerDesugaringKind {
impl_stable_hash_for!(enum ::syntax_pos::hygiene::DesugaringKind {
CondTemporary,
Async,
Await,

View file

@ -5,7 +5,7 @@ use crate::infer::InferCtxt;
use crate::infer::type_variable::TypeVariableOriginKind;
use crate::ty::{self, Ty, Infer, TyVar};
use crate::ty::print::Print;
use syntax::source_map::CompilerDesugaringKind;
use syntax::source_map::DesugaringKind;
use syntax_pos::Span;
use errors::DiagnosticBuilder;
@ -194,12 +194,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
));
} else if let Some(pattern) = local_visitor.found_local_pattern {
if let Some(simple_ident) = pattern.simple_ident() {
match pattern.span.compiler_desugaring_kind() {
match pattern.span.desugaring_kind() {
None => labels.push((
pattern.span,
format!("consider giving `{}` {}", simple_ident, suffix),
)),
Some(CompilerDesugaringKind::ForLoop) => labels.push((
Some(DesugaringKind::ForLoop) => labels.push((
pattern.span,
"the element type for this iterator is not specified".to_owned(),
)),

View file

@ -247,10 +247,10 @@ impl EarlyLintPass for LintPassImpl {
}
fn is_lint_pass_expansion(expn_info: &ExpnInfo) -> bool {
if expn_info.format.name() == sym::impl_lint_pass {
if expn_info.kind.descr() == sym::impl_lint_pass {
true
} else if let Some(info) = expn_info.call_site.ctxt().outer_expn_info() {
info.format.name() == sym::declare_lint_pass
info.kind.descr() == sym::declare_lint_pass
} else {
false
}

View file

@ -35,7 +35,7 @@ use crate::util::nodemap::NodeMap;
use errors::{DiagnosticBuilder, DiagnosticId};
use std::{hash, ptr};
use syntax::ast;
use syntax::source_map::{MultiSpan, ExpnFormat, CompilerDesugaringKind};
use syntax::source_map::{MultiSpan, ExpnKind, DesugaringKind};
use syntax::early_buffered_lints::BufferedEarlyLintId;
use syntax::edition::Edition;
use syntax::symbol::{Symbol, sym};
@ -883,11 +883,11 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
None => return false,
};
match info.format {
ExpnFormat::MacroAttribute(..) => true, // definitely a plugin
ExpnFormat::CompilerDesugaring(CompilerDesugaringKind::ForLoop) => false,
ExpnFormat::CompilerDesugaring(_) => true, // well, it's "external"
ExpnFormat::MacroBang(..) => {
match info.kind {
ExpnKind::MacroAttribute(..) => true, // definitely a plugin
ExpnKind::Desugaring(DesugaringKind::ForLoop) => false,
ExpnKind::Desugaring(_) => true, // well, it's "external"
ExpnKind::MacroBang(..) => {
let def_site = match info.def_site {
Some(span) => span,
// no span for the def_site means it's an external macro
@ -911,8 +911,8 @@ pub fn in_derive_expansion(span: Span) -> bool {
None => return false,
};
match info.format {
ExpnFormat::MacroAttribute(symbol) => symbol.as_str().starts_with("derive("),
match info.kind {
ExpnKind::MacroAttribute(symbol) => symbol.as_str().starts_with("derive("),
_ => false,
}
}

View file

@ -928,7 +928,7 @@ impl<'tcx> LocalDecl<'tcx> {
/// `__next` from a `for` loop.
#[inline]
pub fn from_compiler_desugaring(&self) -> bool {
self.source_info.span.compiler_desugaring_kind().is_some()
self.source_info.span.desugaring_kind().is_some()
}
/// Creates a new `LocalDecl` for a temporary.

View file

@ -36,7 +36,7 @@ use errors::{Applicability, DiagnosticBuilder};
use std::fmt;
use syntax::ast;
use syntax::symbol::sym;
use syntax_pos::{DUMMY_SP, Span, ExpnInfo, ExpnFormat};
use syntax_pos::{DUMMY_SP, Span, ExpnInfo, ExpnKind};
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
pub fn report_fulfillment_errors(&self,
@ -62,7 +62,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// if one is the result of a desugaring and the other is not.
let mut span = error.obligation.cause.span;
if let Some(ExpnInfo {
format: ExpnFormat::CompilerDesugaring(_),
kind: ExpnKind::Desugaring(_),
def_site: Some(def_span),
..
}) = span.ctxt().outer_expn_info() {
@ -373,9 +373,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
flags.push((sym::parent_trait, Some(t)));
}
if let Some(k) = obligation.cause.span.compiler_desugaring_kind() {
if let Some(k) = obligation.cause.span.desugaring_kind() {
flags.push((sym::from_desugaring, None));
flags.push((sym::from_desugaring, Some(k.name().to_string())));
flags.push((sym::from_desugaring, Some(k.descr().to_string())));
}
let generics = self.tcx.generics_of(def_id);
let self_ty = trait_ref.self_ty();

View file

@ -8,7 +8,7 @@ use syntax::{
},
attr,
source_map::{
respan, ExpnInfo, MacroAttribute,
respan, ExpnInfo, ExpnKind,
},
ext::{
base::{ExtCtxt, Resolver},
@ -87,7 +87,8 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> {
// Create a fresh Mark for the new macro expansion we are about to do
let mark = Mark::fresh(Mark::root());
mark.set_expn_info(ExpnInfo::with_unstable(
MacroAttribute(sym::global_allocator), item.span, self.sess.edition, &[sym::rustc_attrs]
ExpnKind::MacroAttribute(sym::global_allocator), item.span, self.sess.edition,
&[sym::rustc_attrs],
));
// Tie the span to the macro expansion info we just created

View file

@ -33,7 +33,7 @@ use std::cell::{Cell, RefCell};
use std::fmt;
use std::rc::Rc;
use std::hash::{Hash, Hasher};
use syntax::source_map::CompilerDesugaringKind;
use syntax::source_map::DesugaringKind;
use syntax_pos::{MultiSpan, Span};
use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
use log::debug;
@ -734,8 +734,8 @@ impl BorrowckCtxt<'_, 'tcx> {
},
moved_lp.ty));
}
if let (Some(CompilerDesugaringKind::ForLoop), Ok(snippet)) = (
move_span.compiler_desugaring_kind(),
if let (Some(DesugaringKind::ForLoop), Ok(snippet)) = (
move_span.desugaring_kind(),
self.tcx.sess.source_map().span_to_snippet(move_span),
) {
if !snippet.starts_with("&") {

View file

@ -10,7 +10,7 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::indexed_vec::Idx;
use rustc_errors::{Applicability, DiagnosticBuilder};
use syntax_pos::Span;
use syntax::source_map::CompilerDesugaringKind;
use syntax::source_map::DesugaringKind;
use super::nll::explain_borrow::BorrowExplanation;
use super::nll::region_infer::{RegionName, RegionNameSource};
@ -174,7 +174,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
format!("variable moved due to use{}", move_spans.describe()),
);
}
if Some(CompilerDesugaringKind::ForLoop) == move_span.compiler_desugaring_kind() {
if Some(DesugaringKind::ForLoop) == move_span.desugaring_kind() {
if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) {
err.span_suggestion(
move_span,

View file

@ -335,7 +335,7 @@ fn do_mir_borrowck<'a, 'tcx>(
}
let span = local_decl.source_info.span;
if span.compiler_desugaring_kind().is_some() {
if span.desugaring_kind().is_some() {
// If the `mut` arises as part of a desugaring, we should ignore it.
continue;
}

View file

@ -37,7 +37,6 @@ use syntax::parse::lexer::comments::strip_doc_comment_decoration;
use syntax::print::pprust;
use syntax::visit::{self, Visitor};
use syntax::print::pprust::{arg_to_string, ty_to_string};
use syntax::source_map::MacroAttribute;
use syntax_pos::*;
use json_dumper::JsonDumper;
@ -845,7 +844,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
let callee_span = callee.def_site?;
// Ignore attribute macros, their spans are usually mangled
if let MacroAttribute(_) = callee.format {
if let ExpnKind::MacroAttribute(_) = callee.kind {
return None;
}
@ -870,7 +869,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
let callee_span = self.span_from_span(callee_span);
Some(MacroRef {
span: callsite_span,
qualname: callee.format.name().to_string(), // FIXME: generate the real qualname
qualname: callee.kind.descr().to_string(), // FIXME: generate the real qualname
callee_span,
})
}

View file

@ -15,7 +15,7 @@ use syntax::ast;
use syntax::source_map::Spanned;
use syntax::util::lev_distance::find_best_match_for_name;
use syntax_pos::Span;
use syntax_pos::hygiene::CompilerDesugaringKind;
use syntax_pos::hygiene::DesugaringKind;
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::cmp;
@ -184,7 +184,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// In the case of `if`- and `while`-expressions we've already checked
// that `scrutinee: bool`. We know that the pattern is `true`,
// so an error here would be a duplicate and from the wrong POV.
s.is_compiler_desugaring(CompilerDesugaringKind::CondTemporary)
s.is_desugaring(DesugaringKind::CondTemporary)
})
.is_some());
}

View file

@ -119,7 +119,7 @@ use rustc::ty::subst::{UnpackedKind, Subst, InternalSubsts, SubstsRef, UserSelfT
use rustc::ty::util::{Representability, IntTypeExt, Discr};
use rustc::ty::layout::VariantIdx;
use syntax_pos::{self, BytePos, Span, MultiSpan};
use syntax_pos::hygiene::CompilerDesugaringKind;
use syntax_pos::hygiene::DesugaringKind;
use syntax::ast;
use syntax::attr;
use syntax::feature_gate::{GateIssue, emit_feature_err};
@ -2165,7 +2165,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// If span arose from a desugaring of `if` or `while`, then it is the condition itself,
// which diverges, that we are about to lint on. This gives suboptimal diagnostics.
// Instead, stop here so that the `if`- or `while`-expression's block is linted instead.
!span.is_compiler_desugaring(CompilerDesugaringKind::CondTemporary) {
!span.is_desugaring(DesugaringKind::CondTemporary) {
self.diverges.set(Diverges::WarnedAlways);
debug!("warn_if_unreachable: id={:?} span={:?} kind={}", id, span, kind);

View file

@ -15,7 +15,7 @@ use crate::tokenstream::{self, TokenStream};
use errors::{DiagnosticBuilder, DiagnosticId};
use smallvec::{smallvec, SmallVec};
use syntax_pos::{Span, MultiSpan, DUMMY_SP};
use syntax_pos::hygiene::{ExpnInfo, ExpnFormat};
use syntax_pos::hygiene::{ExpnInfo, ExpnKind};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::{self, Lrc};
@ -642,18 +642,18 @@ impl SyntaxExtension {
}
}
fn expn_format(&self, symbol: Symbol) -> ExpnFormat {
fn expn_kind(&self, descr: Symbol) -> ExpnKind {
match self.kind {
SyntaxExtensionKind::Bang(..) |
SyntaxExtensionKind::LegacyBang(..) => ExpnFormat::MacroBang(symbol),
_ => ExpnFormat::MacroAttribute(symbol),
SyntaxExtensionKind::LegacyBang(..) => ExpnKind::MacroBang(descr),
_ => ExpnKind::MacroAttribute(descr),
}
}
pub fn expn_info(&self, call_site: Span, format: &str) -> ExpnInfo {
pub fn expn_info(&self, call_site: Span, descr: &str) -> ExpnInfo {
ExpnInfo {
call_site,
format: self.expn_format(Symbol::intern(format)),
kind: self.expn_kind(Symbol::intern(descr)),
def_site: Some(self.span),
default_transparency: self.default_transparency,
allow_internal_unstable: self.allow_internal_unstable.clone(),
@ -780,7 +780,7 @@ impl<'a> ExtCtxt<'a> {
let mut last_macro = None;
loop {
if ctxt.outer_expn_info().map_or(None, |info| {
if info.format.name() == sym::include {
if info.kind.descr() == sym::include {
// Stop going up the backtrace once include! is encountered
return None;
}

View file

@ -1,6 +1,6 @@
use crate::attr::HasAttrs;
use crate::ast;
use crate::source_map::{ExpnInfo, ExpnFormat};
use crate::source_map::{ExpnInfo, ExpnKind};
use crate::ext::base::ExtCtxt;
use crate::ext::build::AstBuilder;
use crate::parse::parser::PathStyle;
@ -57,7 +57,7 @@ pub fn add_derived_markers<T>(cx: &mut ExtCtxt<'_>, span: Span, traits: &[ast::P
pretty_name.push(')');
cx.current_expansion.mark.set_expn_info(ExpnInfo::with_unstable(
ExpnFormat::MacroAttribute(Symbol::intern(&pretty_name)), span, cx.parse_sess.edition,
ExpnKind::MacroAttribute(Symbol::intern(&pretty_name)), span, cx.parse_sess.edition,
&[sym::rustc_attrs, sym::structural_match],
));

View file

@ -506,7 +506,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.format.name()));
info.kind.descr()));
err.help(&format!(
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",
suggested_limit));

View file

@ -7,10 +7,8 @@
//! within the SourceMap, which upon request can be converted to line and column
//! information, source code snippets, etc.
pub use syntax_pos::*;
pub use syntax_pos::hygiene::{ExpnFormat, ExpnInfo};
pub use ExpnFormat::*;
pub use syntax_pos::hygiene::{ExpnKind, ExpnInfo};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::StableHasher;

View file

@ -3,7 +3,7 @@ use crate::attr;
use crate::edition::Edition;
use crate::ext::hygiene::{Mark, SyntaxContext};
use crate::symbol::{Ident, Symbol, kw, sym};
use crate::source_map::{ExpnInfo, MacroAttribute, dummy_spanned, respan};
use crate::source_map::{ExpnInfo, ExpnKind, dummy_spanned, respan};
use crate::ptr::P;
use crate::tokenstream::TokenStream;
@ -17,7 +17,7 @@ use syntax_pos::{DUMMY_SP, Span};
fn ignored_span(sp: Span, edition: Edition) -> Span {
let mark = Mark::fresh(Mark::root());
mark.set_expn_info(ExpnInfo::with_unstable(
MacroAttribute(Symbol::intern("std_inject")), sp, edition, &[sym::prelude_import]
ExpnKind::MacroAttribute(Symbol::intern("std_inject")), sp, edition, &[sym::prelude_import]
));
sp.with_ctxt(SyntaxContext::empty().apply_mark(mark))
}

View file

@ -15,7 +15,7 @@ use smallvec::{smallvec, SmallVec};
use syntax_pos::{DUMMY_SP, NO_EXPANSION, Span, SourceFile, BytePos};
use crate::attr::{self, HasAttrs};
use crate::source_map::{self, SourceMap, ExpnInfo, MacroAttribute, dummy_spanned, respan};
use crate::source_map::{self, SourceMap, ExpnInfo, ExpnKind, dummy_spanned, respan};
use crate::config;
use crate::entry::{self, EntryPointType};
use crate::ext::base::{ExtCtxt, Resolver};
@ -280,7 +280,7 @@ fn generate_test_harness(sess: &ParseSess,
};
mark.set_expn_info(ExpnInfo::with_unstable(
MacroAttribute(sym::test_case), DUMMY_SP, sess.edition,
ExpnKind::MacroAttribute(sym::test_case), DUMMY_SP, sess.edition,
&[sym::main, sym::test, sym::rustc_attrs],
));

View file

@ -4,7 +4,7 @@ use crate::deriving;
use syntax::ast::{self, Ident};
use syntax::attr;
use syntax::source_map::{ExpnInfo, MacroAttribute, respan};
use syntax::source_map::{ExpnInfo, ExpnKind, respan};
use syntax::ext::base::ExtCtxt;
use syntax::ext::build::AstBuilder;
use syntax::ext::expand::ExpansionConfig;
@ -348,7 +348,7 @@ fn mk_decls(
) -> P<ast::Item> {
let mark = Mark::fresh(Mark::root());
mark.set_expn_info(ExpnInfo::with_unstable(
MacroAttribute(sym::proc_macro), DUMMY_SP, cx.parse_sess.edition,
ExpnKind::MacroAttribute(sym::proc_macro), DUMMY_SP, cx.parse_sess.edition,
&[sym::rustc_attrs, Symbol::intern("proc_macro_internals")],
));
let span = DUMMY_SP.apply_mark(mark);

View file

@ -9,7 +9,7 @@ use syntax::ast;
use syntax::print::pprust;
use syntax::symbol::{Symbol, sym};
use syntax_pos::Span;
use syntax::source_map::{ExpnInfo, MacroAttribute};
use syntax::source_map::{ExpnInfo, ExpnKind};
use std::iter;
pub fn expand_test(
@ -63,7 +63,7 @@ pub fn expand_test_or_bench(
let (sp, attr_sp) = {
let mark = Mark::fresh(Mark::root());
mark.set_expn_info(ExpnInfo::with_unstable(
MacroAttribute(sym::test), attr_sp, cx.parse_sess.edition,
ExpnKind::MacroAttribute(sym::test), attr_sp, cx.parse_sess.edition,
&[sym::rustc_attrs, sym::test],
));
(item.span.with_ctxt(SyntaxContext::empty().apply_mark(mark)),

View file

@ -16,7 +16,7 @@ use syntax::ast;
use syntax::source_map::respan;
use syntax::symbol::sym;
use syntax_pos::Span;
use syntax::source_map::{ExpnInfo, MacroAttribute};
use syntax::source_map::{ExpnInfo, ExpnKind};
pub fn expand(
ecx: &mut ExtCtxt<'_>,
@ -29,7 +29,7 @@ pub fn expand(
let sp = {
let mark = Mark::fresh(Mark::root());
mark.set_expn_info(ExpnInfo::with_unstable(
MacroAttribute(sym::test_case), attr_sp, ecx.parse_sess.edition,
ExpnKind::MacroAttribute(sym::test_case), attr_sp, ecx.parse_sess.edition,
&[sym::test, sym::rustc_attrs],
));
attr_sp.with_ctxt(SyntaxContext::empty().apply_mark(mark))

View file

@ -162,7 +162,7 @@ impl Mark {
HygieneData::with(|data| {
if data.default_transparency(self) == Transparency::Opaque {
if let Some(expn_info) = &data.marks[self.0 as usize].expn_info {
if let ExpnFormat::MacroAttribute(name) = expn_info.format {
if let ExpnKind::MacroAttribute(name) = expn_info.kind {
if name.as_str().starts_with("derive(") {
return true;
}
@ -654,7 +654,7 @@ pub struct ExpnInfo {
/// pointing to the `foo!` invocation.
pub call_site: Span,
/// The format with which the macro was invoked.
pub format: ExpnFormat,
pub kind: ExpnKind,
// --- The part specific to the macro/desugaring definition.
// --- FIXME: Share it between expansions with the same definition.
@ -681,10 +681,10 @@ pub struct ExpnInfo {
impl ExpnInfo {
/// Constructs an expansion info with default properties.
pub fn default(format: ExpnFormat, call_site: Span, edition: Edition) -> ExpnInfo {
pub fn default(kind: ExpnKind, call_site: Span, edition: Edition) -> ExpnInfo {
ExpnInfo {
call_site,
format,
kind,
def_site: None,
default_transparency: Transparency::SemiTransparent,
allow_internal_unstable: None,
@ -694,31 +694,31 @@ impl ExpnInfo {
}
}
pub fn with_unstable(format: ExpnFormat, call_site: Span, edition: Edition,
pub fn with_unstable(kind: ExpnKind, call_site: Span, edition: Edition,
allow_internal_unstable: &[Symbol]) -> ExpnInfo {
ExpnInfo {
allow_internal_unstable: Some(allow_internal_unstable.into()),
..ExpnInfo::default(format, call_site, edition)
..ExpnInfo::default(kind, call_site, edition)
}
}
}
/// The source of expansion.
#[derive(Clone, Hash, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
pub enum ExpnFormat {
pub enum ExpnKind {
/// e.g., #[derive(...)] <item>
MacroAttribute(Symbol),
/// e.g., `format!()`
MacroBang(Symbol),
/// Desugaring done by the compiler during HIR lowering.
CompilerDesugaring(CompilerDesugaringKind)
Desugaring(DesugaringKind)
}
impl ExpnFormat {
pub fn name(&self) -> Symbol {
impl ExpnKind {
pub fn descr(&self) -> Symbol {
match *self {
ExpnFormat::MacroBang(name) | ExpnFormat::MacroAttribute(name) => name,
ExpnFormat::CompilerDesugaring(kind) => kind.name(),
ExpnKind::MacroBang(name) | ExpnKind::MacroAttribute(name) => name,
ExpnKind::Desugaring(kind) => kind.descr(),
}
}
}
@ -753,7 +753,7 @@ impl MacroKind {
/// The kind of compiler desugaring.
#[derive(Clone, Copy, Hash, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
pub enum CompilerDesugaringKind {
pub enum DesugaringKind {
/// We desugar `if c { i } else { e }` to `match $ExprKind::Use(c) { true => i, _ => e }`.
/// However, we do not want to blame `c` for unreachability but rather say that `i`
/// is unreachable. This desugaring kind allows us to avoid blaming `c`.
@ -770,16 +770,16 @@ pub enum CompilerDesugaringKind {
ForLoop,
}
impl CompilerDesugaringKind {
pub fn name(self) -> Symbol {
impl DesugaringKind {
pub fn descr(self) -> Symbol {
Symbol::intern(match self {
CompilerDesugaringKind::CondTemporary => "if and while condition",
CompilerDesugaringKind::Async => "async",
CompilerDesugaringKind::Await => "await",
CompilerDesugaringKind::QuestionMark => "?",
CompilerDesugaringKind::TryBlock => "try block",
CompilerDesugaringKind::ExistentialType => "existential type",
CompilerDesugaringKind::ForLoop => "for loop",
DesugaringKind::CondTemporary => "if and while condition",
DesugaringKind::Async => "async",
DesugaringKind::Await => "await",
DesugaringKind::QuestionMark => "?",
DesugaringKind::TryBlock => "try block",
DesugaringKind::ExistentialType => "existential type",
DesugaringKind::ForLoop => "for loop",
})
}
}

View file

@ -27,7 +27,7 @@ extern crate serialize as rustc_serialize; // used by deriving
pub mod edition;
use edition::Edition;
pub mod hygiene;
pub use hygiene::{Mark, SyntaxContext, ExpnInfo, ExpnFormat, CompilerDesugaringKind};
pub use hygiene::{Mark, SyntaxContext, ExpnInfo, ExpnKind, DesugaringKind};
mod span_encoding;
pub use span_encoding::{Span, DUMMY_SP};
@ -403,10 +403,10 @@ impl Span {
}
/// Checks if this span arises from a compiler desugaring of kind `kind`.
pub fn is_compiler_desugaring(&self, kind: CompilerDesugaringKind) -> bool {
pub fn is_desugaring(&self, kind: DesugaringKind) -> bool {
match self.ctxt().outer_expn_info() {
Some(info) => match info.format {
ExpnFormat::CompilerDesugaring(k) => k == kind,
Some(info) => match info.kind {
ExpnKind::Desugaring(k) => k == kind,
_ => false,
},
None => false,
@ -415,10 +415,10 @@ impl Span {
/// Returns the compiler desugaring that created this span, or `None`
/// if this span is not from a desugaring.
pub fn compiler_desugaring_kind(&self) -> Option<CompilerDesugaringKind> {
pub fn desugaring_kind(&self) -> Option<DesugaringKind> {
match self.ctxt().outer_expn_info() {
Some(info) => match info.format {
ExpnFormat::CompilerDesugaring(k) => Some(k),
Some(info) => match info.kind {
ExpnKind::Desugaring(k) => Some(k),
_ => None
},
None => None
@ -441,14 +441,14 @@ impl Span {
while let Some(info) = self.ctxt().outer_expn_info() {
// Don't print recursive invocations.
if !info.call_site.source_equal(&prev_span) {
let (pre, post) = match info.format {
ExpnFormat::MacroAttribute(..) => ("#[", "]"),
ExpnFormat::MacroBang(..) => ("", "!"),
ExpnFormat::CompilerDesugaring(..) => ("desugaring of `", "`"),
let (pre, post) = match info.kind {
ExpnKind::MacroAttribute(..) => ("#[", "]"),
ExpnKind::MacroBang(..) => ("", "!"),
ExpnKind::Desugaring(..) => ("desugaring of `", "`"),
};
result.push(MacroBacktrace {
call_site: info.call_site,
macro_decl_name: format!("{}{}{}", pre, info.format.name(), post),
macro_decl_name: format!("{}{}{}", pre, info.kind.descr(), post),
def_site_span: info.def_site,
});
}