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:
parent
ec376c783e
commit
16918a8e28
25 changed files with 111 additions and 110 deletions
|
@ -62,8 +62,7 @@ use syntax::ast::*;
|
||||||
use syntax::errors;
|
use syntax::errors;
|
||||||
use syntax::ext::hygiene::{Mark, SyntaxContext};
|
use syntax::ext::hygiene::{Mark, SyntaxContext};
|
||||||
use syntax::print::pprust;
|
use syntax::print::pprust;
|
||||||
use syntax::source_map::{self, respan, ExpnInfo, CompilerDesugaringKind, Spanned};
|
use syntax::source_map::{respan, ExpnInfo, ExpnKind, DesugaringKind, Spanned};
|
||||||
use syntax::source_map::CompilerDesugaringKind::CondTemporary;
|
|
||||||
use syntax::std_inject;
|
use syntax::std_inject;
|
||||||
use syntax::symbol::{kw, sym, Symbol};
|
use syntax::symbol::{kw, sym, Symbol};
|
||||||
use syntax::tokenstream::{TokenStream, TokenTree};
|
use syntax::tokenstream::{TokenStream, TokenTree};
|
||||||
|
@ -872,7 +871,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
/// allowed inside this span.
|
/// allowed inside this span.
|
||||||
fn mark_span_with_reason(
|
fn mark_span_with_reason(
|
||||||
&self,
|
&self,
|
||||||
reason: CompilerDesugaringKind,
|
reason: DesugaringKind,
|
||||||
span: Span,
|
span: Span,
|
||||||
allow_internal_unstable: Option<Lrc<[Symbol]>>,
|
allow_internal_unstable: Option<Lrc<[Symbol]>>,
|
||||||
) -> Span {
|
) -> Span {
|
||||||
|
@ -880,7 +879,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
mark.set_expn_info(ExpnInfo {
|
mark.set_expn_info(ExpnInfo {
|
||||||
def_site: Some(span),
|
def_site: Some(span),
|
||||||
allow_internal_unstable,
|
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))
|
span.with_ctxt(SyntaxContext::empty().apply_mark(mark))
|
||||||
}
|
}
|
||||||
|
@ -1188,7 +1187,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let unstable_span = self.mark_span_with_reason(
|
let unstable_span = self.mark_span_with_reason(
|
||||||
CompilerDesugaringKind::Async,
|
DesugaringKind::Async,
|
||||||
span,
|
span,
|
||||||
self.allow_gen_future.clone(),
|
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
|
// Not tracking it makes lints in rustc and clippy very fragile, as
|
||||||
// frequently opened issues show.
|
// frequently opened issues show.
|
||||||
let exist_ty_span = self.mark_span_with_reason(
|
let exist_ty_span = self.mark_span_with_reason(
|
||||||
CompilerDesugaringKind::ExistentialType,
|
DesugaringKind::ExistentialType,
|
||||||
span,
|
span,
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
@ -2603,7 +2602,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
let span = output.span();
|
let span = output.span();
|
||||||
|
|
||||||
let exist_ty_span = self.mark_span_with_reason(
|
let exist_ty_span = self.mark_span_with_reason(
|
||||||
CompilerDesugaringKind::Async,
|
DesugaringKind::Async,
|
||||||
span,
|
span,
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
@ -3275,7 +3274,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let desugared_span =
|
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
|
// Construct an argument representing `__argN: <ty>` to replace the argument of the
|
||||||
// async function.
|
// async function.
|
||||||
|
@ -4410,7 +4409,9 @@ impl<'a> LoweringContext<'a> {
|
||||||
_ => {
|
_ => {
|
||||||
// Lower condition:
|
// Lower condition:
|
||||||
let cond = self.lower_expr(cond);
|
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 }`
|
// Wrap in a construct equivalent to `{ let _t = $cond; _t }`
|
||||||
// to preserve drop semantics since `if cond { ... }` does not
|
// to preserve drop semantics since `if cond { ... }` does not
|
||||||
// let temporaries live outside of `cond`.
|
// let temporaries live outside of `cond`.
|
||||||
|
@ -4469,7 +4470,9 @@ impl<'a> LoweringContext<'a> {
|
||||||
|
|
||||||
// Lower condition:
|
// Lower condition:
|
||||||
let cond = this.with_loop_condition_scope(|this| this.lower_expr(cond));
|
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 }`
|
// Wrap in a construct equivalent to `{ let _t = $cond; _t }`
|
||||||
// to preserve drop semantics since `while cond { ... }` does not
|
// to preserve drop semantics since `while cond { ... }` does not
|
||||||
// let temporaries live outside of `cond`.
|
// let temporaries live outside of `cond`.
|
||||||
|
@ -4508,7 +4511,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
ExprKind::TryBlock(ref body) => {
|
ExprKind::TryBlock(ref body) => {
|
||||||
self.with_catch_scope(body.id, |this| {
|
self.with_catch_scope(body.id, |this| {
|
||||||
let unstable_span = this.mark_span_with_reason(
|
let unstable_span = this.mark_span_with_reason(
|
||||||
CompilerDesugaringKind::TryBlock,
|
DesugaringKind::TryBlock,
|
||||||
body.span,
|
body.span,
|
||||||
this.allow_try_trait.clone(),
|
this.allow_try_trait.clone(),
|
||||||
);
|
);
|
||||||
|
@ -4836,7 +4839,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
let mut head = self.lower_expr(head);
|
let mut head = self.lower_expr(head);
|
||||||
let head_sp = head.span;
|
let head_sp = head.span;
|
||||||
let desugared_span = self.mark_span_with_reason(
|
let desugared_span = self.mark_span_with_reason(
|
||||||
CompilerDesugaringKind::ForLoop,
|
DesugaringKind::ForLoop,
|
||||||
head_sp,
|
head_sp,
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
@ -4990,13 +4993,13 @@ impl<'a> LoweringContext<'a> {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
let unstable_span = self.mark_span_with_reason(
|
let unstable_span = self.mark_span_with_reason(
|
||||||
CompilerDesugaringKind::QuestionMark,
|
DesugaringKind::QuestionMark,
|
||||||
e.span,
|
e.span,
|
||||||
self.allow_try_trait.clone(),
|
self.allow_try_trait.clone(),
|
||||||
);
|
);
|
||||||
let try_span = self.sess.source_map().end_point(e.span);
|
let try_span = self.sess.source_map().end_point(e.span);
|
||||||
let try_span = self.mark_span_with_reason(
|
let try_span = self.mark_span_with_reason(
|
||||||
CompilerDesugaringKind::QuestionMark,
|
DesugaringKind::QuestionMark,
|
||||||
try_span,
|
try_span,
|
||||||
self.allow_try_trait.clone(),
|
self.allow_try_trait.clone(),
|
||||||
);
|
);
|
||||||
|
@ -5811,12 +5814,12 @@ impl<'a> LoweringContext<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let span = self.mark_span_with_reason(
|
let span = self.mark_span_with_reason(
|
||||||
CompilerDesugaringKind::Await,
|
DesugaringKind::Await,
|
||||||
await_span,
|
await_span,
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
let gen_future_span = self.mark_span_with_reason(
|
let gen_future_span = self.mark_span_with_reason(
|
||||||
CompilerDesugaringKind::Await,
|
DesugaringKind::Await,
|
||||||
await_span,
|
await_span,
|
||||||
self.allow_gen_future.clone(),
|
self.allow_gen_future.clone(),
|
||||||
);
|
);
|
||||||
|
|
|
@ -398,7 +398,7 @@ impl_stable_hash_for!(enum ::syntax_pos::hygiene::Transparency {
|
||||||
|
|
||||||
impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnInfo {
|
impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnInfo {
|
||||||
call_site,
|
call_site,
|
||||||
format,
|
kind,
|
||||||
def_site,
|
def_site,
|
||||||
default_transparency,
|
default_transparency,
|
||||||
allow_internal_unstable,
|
allow_internal_unstable,
|
||||||
|
@ -407,13 +407,13 @@ impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnInfo {
|
||||||
edition
|
edition
|
||||||
});
|
});
|
||||||
|
|
||||||
impl_stable_hash_for!(enum ::syntax_pos::hygiene::ExpnFormat {
|
impl_stable_hash_for!(enum ::syntax_pos::hygiene::ExpnKind {
|
||||||
MacroAttribute(sym),
|
MacroAttribute(sym),
|
||||||
MacroBang(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,
|
CondTemporary,
|
||||||
Async,
|
Async,
|
||||||
Await,
|
Await,
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::infer::InferCtxt;
|
||||||
use crate::infer::type_variable::TypeVariableOriginKind;
|
use crate::infer::type_variable::TypeVariableOriginKind;
|
||||||
use crate::ty::{self, Ty, Infer, TyVar};
|
use crate::ty::{self, Ty, Infer, TyVar};
|
||||||
use crate::ty::print::Print;
|
use crate::ty::print::Print;
|
||||||
use syntax::source_map::CompilerDesugaringKind;
|
use syntax::source_map::DesugaringKind;
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
use errors::DiagnosticBuilder;
|
use errors::DiagnosticBuilder;
|
||||||
|
|
||||||
|
@ -194,12 +194,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
));
|
));
|
||||||
} else if let Some(pattern) = local_visitor.found_local_pattern {
|
} else if let Some(pattern) = local_visitor.found_local_pattern {
|
||||||
if let Some(simple_ident) = pattern.simple_ident() {
|
if let Some(simple_ident) = pattern.simple_ident() {
|
||||||
match pattern.span.compiler_desugaring_kind() {
|
match pattern.span.desugaring_kind() {
|
||||||
None => labels.push((
|
None => labels.push((
|
||||||
pattern.span,
|
pattern.span,
|
||||||
format!("consider giving `{}` {}", simple_ident, suffix),
|
format!("consider giving `{}` {}", simple_ident, suffix),
|
||||||
)),
|
)),
|
||||||
Some(CompilerDesugaringKind::ForLoop) => labels.push((
|
Some(DesugaringKind::ForLoop) => labels.push((
|
||||||
pattern.span,
|
pattern.span,
|
||||||
"the element type for this iterator is not specified".to_owned(),
|
"the element type for this iterator is not specified".to_owned(),
|
||||||
)),
|
)),
|
||||||
|
|
|
@ -247,10 +247,10 @@ impl EarlyLintPass for LintPassImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_lint_pass_expansion(expn_info: &ExpnInfo) -> bool {
|
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
|
true
|
||||||
} else if let Some(info) = expn_info.call_site.ctxt().outer_expn_info() {
|
} 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 {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ use crate::util::nodemap::NodeMap;
|
||||||
use errors::{DiagnosticBuilder, DiagnosticId};
|
use errors::{DiagnosticBuilder, DiagnosticId};
|
||||||
use std::{hash, ptr};
|
use std::{hash, ptr};
|
||||||
use syntax::ast;
|
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::early_buffered_lints::BufferedEarlyLintId;
|
||||||
use syntax::edition::Edition;
|
use syntax::edition::Edition;
|
||||||
use syntax::symbol::{Symbol, sym};
|
use syntax::symbol::{Symbol, sym};
|
||||||
|
@ -883,11 +883,11 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
|
||||||
None => return false,
|
None => return false,
|
||||||
};
|
};
|
||||||
|
|
||||||
match info.format {
|
match info.kind {
|
||||||
ExpnFormat::MacroAttribute(..) => true, // definitely a plugin
|
ExpnKind::MacroAttribute(..) => true, // definitely a plugin
|
||||||
ExpnFormat::CompilerDesugaring(CompilerDesugaringKind::ForLoop) => false,
|
ExpnKind::Desugaring(DesugaringKind::ForLoop) => false,
|
||||||
ExpnFormat::CompilerDesugaring(_) => true, // well, it's "external"
|
ExpnKind::Desugaring(_) => true, // well, it's "external"
|
||||||
ExpnFormat::MacroBang(..) => {
|
ExpnKind::MacroBang(..) => {
|
||||||
let def_site = match info.def_site {
|
let def_site = match info.def_site {
|
||||||
Some(span) => span,
|
Some(span) => span,
|
||||||
// no span for the def_site means it's an external macro
|
// 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,
|
None => return false,
|
||||||
};
|
};
|
||||||
|
|
||||||
match info.format {
|
match info.kind {
|
||||||
ExpnFormat::MacroAttribute(symbol) => symbol.as_str().starts_with("derive("),
|
ExpnKind::MacroAttribute(symbol) => symbol.as_str().starts_with("derive("),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -928,7 +928,7 @@ impl<'tcx> LocalDecl<'tcx> {
|
||||||
/// `__next` from a `for` loop.
|
/// `__next` from a `for` loop.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_compiler_desugaring(&self) -> bool {
|
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.
|
/// Creates a new `LocalDecl` for a temporary.
|
||||||
|
|
|
@ -36,7 +36,7 @@ use errors::{Applicability, DiagnosticBuilder};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::symbol::sym;
|
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> {
|
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
pub fn report_fulfillment_errors(&self,
|
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.
|
// if one is the result of a desugaring and the other is not.
|
||||||
let mut span = error.obligation.cause.span;
|
let mut span = error.obligation.cause.span;
|
||||||
if let Some(ExpnInfo {
|
if let Some(ExpnInfo {
|
||||||
format: ExpnFormat::CompilerDesugaring(_),
|
kind: ExpnKind::Desugaring(_),
|
||||||
def_site: Some(def_span),
|
def_site: Some(def_span),
|
||||||
..
|
..
|
||||||
}) = span.ctxt().outer_expn_info() {
|
}) = span.ctxt().outer_expn_info() {
|
||||||
|
@ -373,9 +373,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
flags.push((sym::parent_trait, Some(t)));
|
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, 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 generics = self.tcx.generics_of(def_id);
|
||||||
let self_ty = trait_ref.self_ty();
|
let self_ty = trait_ref.self_ty();
|
||||||
|
|
|
@ -8,7 +8,7 @@ use syntax::{
|
||||||
},
|
},
|
||||||
attr,
|
attr,
|
||||||
source_map::{
|
source_map::{
|
||||||
respan, ExpnInfo, MacroAttribute,
|
respan, ExpnInfo, ExpnKind,
|
||||||
},
|
},
|
||||||
ext::{
|
ext::{
|
||||||
base::{ExtCtxt, Resolver},
|
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
|
// Create a fresh Mark for the new macro expansion we are about to do
|
||||||
let mark = Mark::fresh(Mark::root());
|
let mark = Mark::fresh(Mark::root());
|
||||||
mark.set_expn_info(ExpnInfo::with_unstable(
|
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
|
// Tie the span to the macro expansion info we just created
|
||||||
|
|
|
@ -33,7 +33,7 @@ use std::cell::{Cell, RefCell};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use syntax::source_map::CompilerDesugaringKind;
|
use syntax::source_map::DesugaringKind;
|
||||||
use syntax_pos::{MultiSpan, Span};
|
use syntax_pos::{MultiSpan, Span};
|
||||||
use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
|
use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
@ -734,8 +734,8 @@ impl BorrowckCtxt<'_, 'tcx> {
|
||||||
},
|
},
|
||||||
moved_lp.ty));
|
moved_lp.ty));
|
||||||
}
|
}
|
||||||
if let (Some(CompilerDesugaringKind::ForLoop), Ok(snippet)) = (
|
if let (Some(DesugaringKind::ForLoop), Ok(snippet)) = (
|
||||||
move_span.compiler_desugaring_kind(),
|
move_span.desugaring_kind(),
|
||||||
self.tcx.sess.source_map().span_to_snippet(move_span),
|
self.tcx.sess.source_map().span_to_snippet(move_span),
|
||||||
) {
|
) {
|
||||||
if !snippet.starts_with("&") {
|
if !snippet.starts_with("&") {
|
||||||
|
|
|
@ -10,7 +10,7 @@ use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_data_structures::indexed_vec::Idx;
|
use rustc_data_structures::indexed_vec::Idx;
|
||||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
use rustc_errors::{Applicability, DiagnosticBuilder};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
use syntax::source_map::CompilerDesugaringKind;
|
use syntax::source_map::DesugaringKind;
|
||||||
|
|
||||||
use super::nll::explain_borrow::BorrowExplanation;
|
use super::nll::explain_borrow::BorrowExplanation;
|
||||||
use super::nll::region_infer::{RegionName, RegionNameSource};
|
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()),
|
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) {
|
if let Ok(snippet) = self.infcx.tcx.sess.source_map().span_to_snippet(span) {
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
move_span,
|
move_span,
|
||||||
|
|
|
@ -335,7 +335,7 @@ fn do_mir_borrowck<'a, 'tcx>(
|
||||||
}
|
}
|
||||||
|
|
||||||
let span = local_decl.source_info.span;
|
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.
|
// If the `mut` arises as part of a desugaring, we should ignore it.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,6 @@ use syntax::parse::lexer::comments::strip_doc_comment_decoration;
|
||||||
use syntax::print::pprust;
|
use syntax::print::pprust;
|
||||||
use syntax::visit::{self, Visitor};
|
use syntax::visit::{self, Visitor};
|
||||||
use syntax::print::pprust::{arg_to_string, ty_to_string};
|
use syntax::print::pprust::{arg_to_string, ty_to_string};
|
||||||
use syntax::source_map::MacroAttribute;
|
|
||||||
use syntax_pos::*;
|
use syntax_pos::*;
|
||||||
|
|
||||||
use json_dumper::JsonDumper;
|
use json_dumper::JsonDumper;
|
||||||
|
@ -845,7 +844,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
|
||||||
let callee_span = callee.def_site?;
|
let callee_span = callee.def_site?;
|
||||||
|
|
||||||
// Ignore attribute macros, their spans are usually mangled
|
// Ignore attribute macros, their spans are usually mangled
|
||||||
if let MacroAttribute(_) = callee.format {
|
if let ExpnKind::MacroAttribute(_) = callee.kind {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -870,7 +869,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
|
||||||
let callee_span = self.span_from_span(callee_span);
|
let callee_span = self.span_from_span(callee_span);
|
||||||
Some(MacroRef {
|
Some(MacroRef {
|
||||||
span: callsite_span,
|
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,
|
callee_span,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ use syntax::ast;
|
||||||
use syntax::source_map::Spanned;
|
use syntax::source_map::Spanned;
|
||||||
use syntax::util::lev_distance::find_best_match_for_name;
|
use syntax::util::lev_distance::find_best_match_for_name;
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
use syntax_pos::hygiene::CompilerDesugaringKind;
|
use syntax_pos::hygiene::DesugaringKind;
|
||||||
|
|
||||||
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||||
use std::cmp;
|
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
|
// In the case of `if`- and `while`-expressions we've already checked
|
||||||
// that `scrutinee: bool`. We know that the pattern is `true`,
|
// that `scrutinee: bool`. We know that the pattern is `true`,
|
||||||
// so an error here would be a duplicate and from the wrong POV.
|
// 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());
|
.is_some());
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,7 @@ use rustc::ty::subst::{UnpackedKind, Subst, InternalSubsts, SubstsRef, UserSelfT
|
||||||
use rustc::ty::util::{Representability, IntTypeExt, Discr};
|
use rustc::ty::util::{Representability, IntTypeExt, Discr};
|
||||||
use rustc::ty::layout::VariantIdx;
|
use rustc::ty::layout::VariantIdx;
|
||||||
use syntax_pos::{self, BytePos, Span, MultiSpan};
|
use syntax_pos::{self, BytePos, Span, MultiSpan};
|
||||||
use syntax_pos::hygiene::CompilerDesugaringKind;
|
use syntax_pos::hygiene::DesugaringKind;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::feature_gate::{GateIssue, emit_feature_err};
|
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,
|
// 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.
|
// 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.
|
// 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);
|
self.diverges.set(Diverges::WarnedAlways);
|
||||||
|
|
||||||
debug!("warn_if_unreachable: id={:?} span={:?} kind={}", id, span, kind);
|
debug!("warn_if_unreachable: id={:?} span={:?} kind={}", id, span, kind);
|
||||||
|
|
|
@ -15,7 +15,7 @@ use crate::tokenstream::{self, TokenStream};
|
||||||
use errors::{DiagnosticBuilder, DiagnosticId};
|
use errors::{DiagnosticBuilder, DiagnosticId};
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{smallvec, SmallVec};
|
||||||
use syntax_pos::{Span, MultiSpan, DUMMY_SP};
|
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::fx::FxHashMap;
|
||||||
use rustc_data_structures::sync::{self, Lrc};
|
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 {
|
match self.kind {
|
||||||
SyntaxExtensionKind::Bang(..) |
|
SyntaxExtensionKind::Bang(..) |
|
||||||
SyntaxExtensionKind::LegacyBang(..) => ExpnFormat::MacroBang(symbol),
|
SyntaxExtensionKind::LegacyBang(..) => ExpnKind::MacroBang(descr),
|
||||||
_ => ExpnFormat::MacroAttribute(symbol),
|
_ => 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 {
|
ExpnInfo {
|
||||||
call_site,
|
call_site,
|
||||||
format: self.expn_format(Symbol::intern(format)),
|
kind: self.expn_kind(Symbol::intern(descr)),
|
||||||
def_site: Some(self.span),
|
def_site: Some(self.span),
|
||||||
default_transparency: self.default_transparency,
|
default_transparency: self.default_transparency,
|
||||||
allow_internal_unstable: self.allow_internal_unstable.clone(),
|
allow_internal_unstable: self.allow_internal_unstable.clone(),
|
||||||
|
@ -780,7 +780,7 @@ impl<'a> ExtCtxt<'a> {
|
||||||
let mut last_macro = None;
|
let mut last_macro = None;
|
||||||
loop {
|
loop {
|
||||||
if ctxt.outer_expn_info().map_or(None, |info| {
|
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
|
// Stop going up the backtrace once include! is encountered
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::attr::HasAttrs;
|
use crate::attr::HasAttrs;
|
||||||
use crate::ast;
|
use crate::ast;
|
||||||
use crate::source_map::{ExpnInfo, ExpnFormat};
|
use crate::source_map::{ExpnInfo, ExpnKind};
|
||||||
use crate::ext::base::ExtCtxt;
|
use crate::ext::base::ExtCtxt;
|
||||||
use crate::ext::build::AstBuilder;
|
use crate::ext::build::AstBuilder;
|
||||||
use crate::parse::parser::PathStyle;
|
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(')');
|
pretty_name.push(')');
|
||||||
|
|
||||||
cx.current_expansion.mark.set_expn_info(ExpnInfo::with_unstable(
|
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],
|
&[sym::rustc_attrs, sym::structural_match],
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -506,7 +506,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
let suggested_limit = self.cx.ecfg.recursion_limit * 2;
|
let suggested_limit = self.cx.ecfg.recursion_limit * 2;
|
||||||
let mut err = self.cx.struct_span_err(info.call_site,
|
let mut err = self.cx.struct_span_err(info.call_site,
|
||||||
&format!("recursion limit reached while expanding the macro `{}`",
|
&format!("recursion limit reached while expanding the macro `{}`",
|
||||||
info.format.name()));
|
info.kind.descr()));
|
||||||
err.help(&format!(
|
err.help(&format!(
|
||||||
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",
|
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",
|
||||||
suggested_limit));
|
suggested_limit));
|
||||||
|
|
|
@ -7,10 +7,8 @@
|
||||||
//! within the SourceMap, which upon request can be converted to line and column
|
//! within the SourceMap, which upon request can be converted to line and column
|
||||||
//! information, source code snippets, etc.
|
//! information, source code snippets, etc.
|
||||||
|
|
||||||
|
|
||||||
pub use syntax_pos::*;
|
pub use syntax_pos::*;
|
||||||
pub use syntax_pos::hygiene::{ExpnFormat, ExpnInfo};
|
pub use syntax_pos::hygiene::{ExpnKind, ExpnInfo};
|
||||||
pub use ExpnFormat::*;
|
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::stable_hasher::StableHasher;
|
use rustc_data_structures::stable_hasher::StableHasher;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::attr;
|
||||||
use crate::edition::Edition;
|
use crate::edition::Edition;
|
||||||
use crate::ext::hygiene::{Mark, SyntaxContext};
|
use crate::ext::hygiene::{Mark, SyntaxContext};
|
||||||
use crate::symbol::{Ident, Symbol, kw, sym};
|
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::ptr::P;
|
||||||
use crate::tokenstream::TokenStream;
|
use crate::tokenstream::TokenStream;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ use syntax_pos::{DUMMY_SP, Span};
|
||||||
fn ignored_span(sp: Span, edition: Edition) -> Span {
|
fn ignored_span(sp: Span, edition: Edition) -> Span {
|
||||||
let mark = Mark::fresh(Mark::root());
|
let mark = Mark::fresh(Mark::root());
|
||||||
mark.set_expn_info(ExpnInfo::with_unstable(
|
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))
|
sp.with_ctxt(SyntaxContext::empty().apply_mark(mark))
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ use smallvec::{smallvec, SmallVec};
|
||||||
use syntax_pos::{DUMMY_SP, NO_EXPANSION, Span, SourceFile, BytePos};
|
use syntax_pos::{DUMMY_SP, NO_EXPANSION, Span, SourceFile, BytePos};
|
||||||
|
|
||||||
use crate::attr::{self, HasAttrs};
|
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::config;
|
||||||
use crate::entry::{self, EntryPointType};
|
use crate::entry::{self, EntryPointType};
|
||||||
use crate::ext::base::{ExtCtxt, Resolver};
|
use crate::ext::base::{ExtCtxt, Resolver};
|
||||||
|
@ -280,7 +280,7 @@ fn generate_test_harness(sess: &ParseSess,
|
||||||
};
|
};
|
||||||
|
|
||||||
mark.set_expn_info(ExpnInfo::with_unstable(
|
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],
|
&[sym::main, sym::test, sym::rustc_attrs],
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::deriving;
|
||||||
|
|
||||||
use syntax::ast::{self, Ident};
|
use syntax::ast::{self, Ident};
|
||||||
use syntax::attr;
|
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::base::ExtCtxt;
|
||||||
use syntax::ext::build::AstBuilder;
|
use syntax::ext::build::AstBuilder;
|
||||||
use syntax::ext::expand::ExpansionConfig;
|
use syntax::ext::expand::ExpansionConfig;
|
||||||
|
@ -348,7 +348,7 @@ fn mk_decls(
|
||||||
) -> P<ast::Item> {
|
) -> P<ast::Item> {
|
||||||
let mark = Mark::fresh(Mark::root());
|
let mark = Mark::fresh(Mark::root());
|
||||||
mark.set_expn_info(ExpnInfo::with_unstable(
|
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")],
|
&[sym::rustc_attrs, Symbol::intern("proc_macro_internals")],
|
||||||
));
|
));
|
||||||
let span = DUMMY_SP.apply_mark(mark);
|
let span = DUMMY_SP.apply_mark(mark);
|
||||||
|
|
|
@ -9,7 +9,7 @@ use syntax::ast;
|
||||||
use syntax::print::pprust;
|
use syntax::print::pprust;
|
||||||
use syntax::symbol::{Symbol, sym};
|
use syntax::symbol::{Symbol, sym};
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
use syntax::source_map::{ExpnInfo, MacroAttribute};
|
use syntax::source_map::{ExpnInfo, ExpnKind};
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
pub fn expand_test(
|
pub fn expand_test(
|
||||||
|
@ -63,7 +63,7 @@ pub fn expand_test_or_bench(
|
||||||
let (sp, attr_sp) = {
|
let (sp, attr_sp) = {
|
||||||
let mark = Mark::fresh(Mark::root());
|
let mark = Mark::fresh(Mark::root());
|
||||||
mark.set_expn_info(ExpnInfo::with_unstable(
|
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],
|
&[sym::rustc_attrs, sym::test],
|
||||||
));
|
));
|
||||||
(item.span.with_ctxt(SyntaxContext::empty().apply_mark(mark)),
|
(item.span.with_ctxt(SyntaxContext::empty().apply_mark(mark)),
|
||||||
|
|
|
@ -16,7 +16,7 @@ use syntax::ast;
|
||||||
use syntax::source_map::respan;
|
use syntax::source_map::respan;
|
||||||
use syntax::symbol::sym;
|
use syntax::symbol::sym;
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
use syntax::source_map::{ExpnInfo, MacroAttribute};
|
use syntax::source_map::{ExpnInfo, ExpnKind};
|
||||||
|
|
||||||
pub fn expand(
|
pub fn expand(
|
||||||
ecx: &mut ExtCtxt<'_>,
|
ecx: &mut ExtCtxt<'_>,
|
||||||
|
@ -29,7 +29,7 @@ pub fn expand(
|
||||||
let sp = {
|
let sp = {
|
||||||
let mark = Mark::fresh(Mark::root());
|
let mark = Mark::fresh(Mark::root());
|
||||||
mark.set_expn_info(ExpnInfo::with_unstable(
|
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],
|
&[sym::test, sym::rustc_attrs],
|
||||||
));
|
));
|
||||||
attr_sp.with_ctxt(SyntaxContext::empty().apply_mark(mark))
|
attr_sp.with_ctxt(SyntaxContext::empty().apply_mark(mark))
|
||||||
|
|
|
@ -162,7 +162,7 @@ impl Mark {
|
||||||
HygieneData::with(|data| {
|
HygieneData::with(|data| {
|
||||||
if data.default_transparency(self) == Transparency::Opaque {
|
if data.default_transparency(self) == Transparency::Opaque {
|
||||||
if let Some(expn_info) = &data.marks[self.0 as usize].expn_info {
|
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(") {
|
if name.as_str().starts_with("derive(") {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -654,7 +654,7 @@ pub struct ExpnInfo {
|
||||||
/// pointing to the `foo!` invocation.
|
/// pointing to the `foo!` invocation.
|
||||||
pub call_site: Span,
|
pub call_site: Span,
|
||||||
/// The format with which the macro was invoked.
|
/// The format with which the macro was invoked.
|
||||||
pub format: ExpnFormat,
|
pub kind: ExpnKind,
|
||||||
|
|
||||||
// --- The part specific to the macro/desugaring definition.
|
// --- The part specific to the macro/desugaring definition.
|
||||||
// --- FIXME: Share it between expansions with the same definition.
|
// --- FIXME: Share it between expansions with the same definition.
|
||||||
|
@ -681,10 +681,10 @@ pub struct ExpnInfo {
|
||||||
|
|
||||||
impl ExpnInfo {
|
impl ExpnInfo {
|
||||||
/// Constructs an expansion info with default properties.
|
/// 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 {
|
ExpnInfo {
|
||||||
call_site,
|
call_site,
|
||||||
format,
|
kind,
|
||||||
def_site: None,
|
def_site: None,
|
||||||
default_transparency: Transparency::SemiTransparent,
|
default_transparency: Transparency::SemiTransparent,
|
||||||
allow_internal_unstable: None,
|
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 {
|
allow_internal_unstable: &[Symbol]) -> ExpnInfo {
|
||||||
ExpnInfo {
|
ExpnInfo {
|
||||||
allow_internal_unstable: Some(allow_internal_unstable.into()),
|
allow_internal_unstable: Some(allow_internal_unstable.into()),
|
||||||
..ExpnInfo::default(format, call_site, edition)
|
..ExpnInfo::default(kind, call_site, edition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The source of expansion.
|
/// The source of expansion.
|
||||||
#[derive(Clone, Hash, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
|
#[derive(Clone, Hash, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
|
||||||
pub enum ExpnFormat {
|
pub enum ExpnKind {
|
||||||
/// e.g., #[derive(...)] <item>
|
/// e.g., #[derive(...)] <item>
|
||||||
MacroAttribute(Symbol),
|
MacroAttribute(Symbol),
|
||||||
/// e.g., `format!()`
|
/// e.g., `format!()`
|
||||||
MacroBang(Symbol),
|
MacroBang(Symbol),
|
||||||
/// Desugaring done by the compiler during HIR lowering.
|
/// Desugaring done by the compiler during HIR lowering.
|
||||||
CompilerDesugaring(CompilerDesugaringKind)
|
Desugaring(DesugaringKind)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExpnFormat {
|
impl ExpnKind {
|
||||||
pub fn name(&self) -> Symbol {
|
pub fn descr(&self) -> Symbol {
|
||||||
match *self {
|
match *self {
|
||||||
ExpnFormat::MacroBang(name) | ExpnFormat::MacroAttribute(name) => name,
|
ExpnKind::MacroBang(name) | ExpnKind::MacroAttribute(name) => name,
|
||||||
ExpnFormat::CompilerDesugaring(kind) => kind.name(),
|
ExpnKind::Desugaring(kind) => kind.descr(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -753,7 +753,7 @@ impl MacroKind {
|
||||||
|
|
||||||
/// The kind of compiler desugaring.
|
/// The kind of compiler desugaring.
|
||||||
#[derive(Clone, Copy, Hash, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
|
#[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 }`.
|
/// 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`
|
/// 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`.
|
/// is unreachable. This desugaring kind allows us to avoid blaming `c`.
|
||||||
|
@ -770,16 +770,16 @@ pub enum CompilerDesugaringKind {
|
||||||
ForLoop,
|
ForLoop,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CompilerDesugaringKind {
|
impl DesugaringKind {
|
||||||
pub fn name(self) -> Symbol {
|
pub fn descr(self) -> Symbol {
|
||||||
Symbol::intern(match self {
|
Symbol::intern(match self {
|
||||||
CompilerDesugaringKind::CondTemporary => "if and while condition",
|
DesugaringKind::CondTemporary => "if and while condition",
|
||||||
CompilerDesugaringKind::Async => "async",
|
DesugaringKind::Async => "async",
|
||||||
CompilerDesugaringKind::Await => "await",
|
DesugaringKind::Await => "await",
|
||||||
CompilerDesugaringKind::QuestionMark => "?",
|
DesugaringKind::QuestionMark => "?",
|
||||||
CompilerDesugaringKind::TryBlock => "try block",
|
DesugaringKind::TryBlock => "try block",
|
||||||
CompilerDesugaringKind::ExistentialType => "existential type",
|
DesugaringKind::ExistentialType => "existential type",
|
||||||
CompilerDesugaringKind::ForLoop => "for loop",
|
DesugaringKind::ForLoop => "for loop",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ extern crate serialize as rustc_serialize; // used by deriving
|
||||||
pub mod edition;
|
pub mod edition;
|
||||||
use edition::Edition;
|
use edition::Edition;
|
||||||
pub mod hygiene;
|
pub mod hygiene;
|
||||||
pub use hygiene::{Mark, SyntaxContext, ExpnInfo, ExpnFormat, CompilerDesugaringKind};
|
pub use hygiene::{Mark, SyntaxContext, ExpnInfo, ExpnKind, DesugaringKind};
|
||||||
|
|
||||||
mod span_encoding;
|
mod span_encoding;
|
||||||
pub use span_encoding::{Span, DUMMY_SP};
|
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`.
|
/// 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() {
|
match self.ctxt().outer_expn_info() {
|
||||||
Some(info) => match info.format {
|
Some(info) => match info.kind {
|
||||||
ExpnFormat::CompilerDesugaring(k) => k == kind,
|
ExpnKind::Desugaring(k) => k == kind,
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
None => false,
|
None => false,
|
||||||
|
@ -415,10 +415,10 @@ impl Span {
|
||||||
|
|
||||||
/// Returns the compiler desugaring that created this span, or `None`
|
/// Returns the compiler desugaring that created this span, or `None`
|
||||||
/// if this span is not from a desugaring.
|
/// 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() {
|
match self.ctxt().outer_expn_info() {
|
||||||
Some(info) => match info.format {
|
Some(info) => match info.kind {
|
||||||
ExpnFormat::CompilerDesugaring(k) => Some(k),
|
ExpnKind::Desugaring(k) => Some(k),
|
||||||
_ => None
|
_ => None
|
||||||
},
|
},
|
||||||
None => None
|
None => None
|
||||||
|
@ -441,14 +441,14 @@ impl Span {
|
||||||
while let Some(info) = self.ctxt().outer_expn_info() {
|
while let Some(info) = self.ctxt().outer_expn_info() {
|
||||||
// Don't print recursive invocations.
|
// Don't print recursive invocations.
|
||||||
if !info.call_site.source_equal(&prev_span) {
|
if !info.call_site.source_equal(&prev_span) {
|
||||||
let (pre, post) = match info.format {
|
let (pre, post) = match info.kind {
|
||||||
ExpnFormat::MacroAttribute(..) => ("#[", "]"),
|
ExpnKind::MacroAttribute(..) => ("#[", "]"),
|
||||||
ExpnFormat::MacroBang(..) => ("", "!"),
|
ExpnKind::MacroBang(..) => ("", "!"),
|
||||||
ExpnFormat::CompilerDesugaring(..) => ("desugaring of `", "`"),
|
ExpnKind::Desugaring(..) => ("desugaring of `", "`"),
|
||||||
};
|
};
|
||||||
result.push(MacroBacktrace {
|
result.push(MacroBacktrace {
|
||||||
call_site: info.call_site,
|
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,
|
def_site_span: info.def_site,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue