hygiene: Remove Options from functions returning ExpnInfo
The expansion info is not optional and should always exist
This commit is contained in:
parent
6cb28b6617
commit
73dee258c1
14 changed files with 98 additions and 155 deletions
|
|
@ -9,7 +9,6 @@ use errors::Applicability;
|
|||
use rustc_data_structures::fx::FxHashMap;
|
||||
use syntax::ast::{Ident, Item, ItemKind};
|
||||
use syntax::symbol::{sym, Symbol};
|
||||
use syntax_pos::ExpnInfo;
|
||||
|
||||
declare_tool_lint! {
|
||||
pub rustc::DEFAULT_HASH_TYPES,
|
||||
|
|
@ -228,30 +227,20 @@ impl EarlyLintPass for LintPassImpl {
|
|||
if let ItemKind::Impl(_, _, _, _, Some(lint_pass), _, _) = &item.node {
|
||||
if let Some(last) = lint_pass.path.segments.last() {
|
||||
if last.ident.name == sym::LintPass {
|
||||
match &lint_pass.path.span.ctxt().outer_expn_info() {
|
||||
Some(info) if is_lint_pass_expansion(info) => {}
|
||||
_ => {
|
||||
cx.struct_span_lint(
|
||||
LINT_PASS_IMPL_WITHOUT_MACRO,
|
||||
lint_pass.path.span,
|
||||
"implementing `LintPass` by hand",
|
||||
)
|
||||
.help("try using `declare_lint_pass!` or `impl_lint_pass!` instead")
|
||||
.emit();
|
||||
}
|
||||
let expn_info = lint_pass.path.span.ctxt().outer_expn_info();
|
||||
let call_site = expn_info.call_site;
|
||||
if expn_info.kind.descr() != sym::impl_lint_pass &&
|
||||
call_site.ctxt().outer_expn_info().kind.descr() != sym::declare_lint_pass {
|
||||
cx.struct_span_lint(
|
||||
LINT_PASS_IMPL_WITHOUT_MACRO,
|
||||
lint_pass.path.span,
|
||||
"implementing `LintPass` by hand",
|
||||
)
|
||||
.help("try using `declare_lint_pass!` or `impl_lint_pass!` instead")
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn is_lint_pass_expansion(expn_info: &ExpnInfo) -> bool {
|
||||
if expn_info.kind.descr() == sym::impl_lint_pass {
|
||||
true
|
||||
} else if let Some(info) = expn_info.call_site.ctxt().outer_expn_info() {
|
||||
info.kind.descr() == sym::declare_lint_pass
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -885,21 +885,16 @@ pub fn provide(providers: &mut Providers<'_>) {
|
|||
/// This is used to test whether a lint should not even begin to figure out whether it should
|
||||
/// be reported on the current node.
|
||||
pub fn in_external_macro(sess: &Session, span: Span) -> bool {
|
||||
let info = match span.ctxt().outer_expn_info() {
|
||||
Some(info) => info,
|
||||
// no ExpnInfo means this span doesn't come from a macro
|
||||
None => return false,
|
||||
};
|
||||
|
||||
match info.kind {
|
||||
let expn_info = span.ctxt().outer_expn_info();
|
||||
match expn_info.kind {
|
||||
ExpnKind::Root | ExpnKind::Desugaring(DesugaringKind::ForLoop) => false,
|
||||
ExpnKind::Desugaring(_) => true, // well, it's "external"
|
||||
ExpnKind::Macro(MacroKind::Bang, _) => {
|
||||
if info.def_site.is_dummy() {
|
||||
if expn_info.def_site.is_dummy() {
|
||||
// dummy span for the def_site means it's an external macro
|
||||
return true;
|
||||
}
|
||||
match sess.source_map().span_to_snippet(info.def_site) {
|
||||
match sess.source_map().span_to_snippet(expn_info.def_site) {
|
||||
Ok(code) => !code.starts_with("macro_rules"),
|
||||
// no snippet = external macro or compiler-builtin expansion
|
||||
Err(_) => true,
|
||||
|
|
@ -911,10 +906,8 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
|
|||
|
||||
/// Returns whether `span` originates in a derive macro's expansion
|
||||
pub fn in_derive_expansion(span: Span) -> bool {
|
||||
if let Some(info) = span.ctxt().outer_expn_info() {
|
||||
if let ExpnKind::Macro(MacroKind::Derive, _) = info.kind {
|
||||
return true;
|
||||
}
|
||||
if let ExpnKind::Macro(MacroKind::Derive, _) = span.ctxt().outer_expn_info().kind {
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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, ExpnKind};
|
||||
use syntax_pos::{DUMMY_SP, Span, ExpnKind};
|
||||
|
||||
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
pub fn report_fulfillment_errors(&self,
|
||||
|
|
@ -61,9 +61,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
// We want to ignore desugarings here: spans are equivalent even
|
||||
// if one is the result of a desugaring and the other is not.
|
||||
let mut span = error.obligation.cause.span;
|
||||
if let Some(ExpnInfo { kind: ExpnKind::Desugaring(_), def_site, .. })
|
||||
= span.ctxt().outer_expn_info() {
|
||||
span = def_site;
|
||||
let expn_info = span.ctxt().outer_expn_info();
|
||||
if let ExpnKind::Desugaring(_) = expn_info.kind {
|
||||
span = expn_info.call_site;
|
||||
}
|
||||
|
||||
error_map.entry(span).or_default().push(
|
||||
|
|
|
|||
|
|
@ -820,18 +820,14 @@ where
|
|||
TAG_NO_EXPANSION_INFO.encode(self)
|
||||
} else {
|
||||
let (expn_id, expn_info) = span_data.ctxt.outer_expn_with_info();
|
||||
if let Some(expn_info) = expn_info {
|
||||
if let Some(pos) = self.expn_info_shorthands.get(&expn_id).cloned() {
|
||||
TAG_EXPANSION_INFO_SHORTHAND.encode(self)?;
|
||||
pos.encode(self)
|
||||
} else {
|
||||
TAG_EXPANSION_INFO_INLINE.encode(self)?;
|
||||
let pos = AbsoluteBytePos::new(self.position());
|
||||
self.expn_info_shorthands.insert(expn_id, pos);
|
||||
expn_info.encode(self)
|
||||
}
|
||||
if let Some(pos) = self.expn_info_shorthands.get(&expn_id).cloned() {
|
||||
TAG_EXPANSION_INFO_SHORTHAND.encode(self)?;
|
||||
pos.encode(self)
|
||||
} else {
|
||||
TAG_NO_EXPANSION_INFO.encode(self)
|
||||
TAG_EXPANSION_INFO_INLINE.encode(self)?;
|
||||
let pos = AbsoluteBytePos::new(self.position());
|
||||
self.expn_info_shorthands.insert(expn_id, pos);
|
||||
expn_info.encode(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue