ast: Add span to Extern
This commit is contained in:
parent
5018181c79
commit
18ca2946e0
@ -2667,13 +2667,16 @@ pub fn span_with_attributes(&self) -> Span {
|
||||
#[derive(Clone, Copy, Encodable, Decodable, Debug)]
|
||||
pub enum Extern {
|
||||
None,
|
||||
Implicit,
|
||||
Explicit(StrLit),
|
||||
Implicit(Span),
|
||||
Explicit(StrLit, Span),
|
||||
}
|
||||
|
||||
impl Extern {
|
||||
pub fn from_abi(abi: Option<StrLit>) -> Extern {
|
||||
abi.map_or(Extern::Implicit, Extern::Explicit)
|
||||
pub fn from_abi(abi: Option<StrLit>, span: Span) -> Extern {
|
||||
match abi {
|
||||
Some(name) => Extern::Explicit(name, span),
|
||||
None => Extern::Implicit(span),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1272,8 +1272,8 @@ pub(super) fn lower_abi(&mut self, abi: StrLit) -> abi::Abi {
|
||||
pub(super) fn lower_extern(&mut self, ext: Extern) -> abi::Abi {
|
||||
match ext {
|
||||
Extern::None => abi::Abi::Rust,
|
||||
Extern::Implicit => abi::Abi::FALLBACK,
|
||||
Extern::Explicit(abi) => self.lower_abi(abi),
|
||||
Extern::Implicit(_) => abi::Abi::FALLBACK,
|
||||
Extern::Explicit(abi, _) => self.lower_abi(abi),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -630,7 +630,8 @@ fn check_c_variadic_type(&self, fk: FnKind<'a>) {
|
||||
match (fk.ctxt(), fk.header()) {
|
||||
(Some(FnCtxt::Foreign), _) => return,
|
||||
(Some(FnCtxt::Free), Some(header)) => match header.ext {
|
||||
Extern::Explicit(StrLit { symbol_unescaped: sym::C, .. }) | Extern::Implicit
|
||||
Extern::Explicit(StrLit { symbol_unescaped: sym::C, .. }, _)
|
||||
| Extern::Implicit(_)
|
||||
if matches!(header.unsafety, Unsafe::Yes(_)) =>
|
||||
{
|
||||
return;
|
||||
@ -842,7 +843,7 @@ fn visit_ty_common(&mut self, ty: &'a Ty) {
|
||||
.emit();
|
||||
});
|
||||
self.check_late_bound_lifetime_defs(&bfty.generic_params);
|
||||
if let Extern::Implicit = bfty.ext {
|
||||
if let Extern::Implicit(_) = bfty.ext {
|
||||
let sig_span = self.session.source_map().next_point(ty.span.shrink_to_lo());
|
||||
self.maybe_lint_missing_abi(sig_span, ty.id);
|
||||
}
|
||||
@ -1556,7 +1557,7 @@ fn visit_fn(&mut self, fk: FnKind<'a>, span: Span, id: NodeId) {
|
||||
if let FnKind::Fn(
|
||||
_,
|
||||
_,
|
||||
FnSig { span: sig_span, header: FnHeader { ext: Extern::Implicit, .. }, .. },
|
||||
FnSig { span: sig_span, header: FnHeader { ext: Extern::Implicit(_), .. }, .. },
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
|
@ -283,7 +283,7 @@ fn check_abi(&self, abi: ast::StrLit, constness: ast::Const) {
|
||||
}
|
||||
|
||||
fn check_extern(&self, ext: ast::Extern, constness: ast::Const) {
|
||||
if let ast::Extern::Explicit(abi) = ext {
|
||||
if let ast::Extern::Explicit(abi, _) = ext {
|
||||
self.check_abi(abi, constness);
|
||||
}
|
||||
}
|
||||
|
@ -1734,10 +1734,10 @@ pub(crate) fn print_fn_header_info(&mut self, header: ast::FnHeader) {
|
||||
|
||||
match header.ext {
|
||||
ast::Extern::None => {}
|
||||
ast::Extern::Implicit => {
|
||||
ast::Extern::Implicit(_) => {
|
||||
self.word_nbsp("extern");
|
||||
}
|
||||
ast::Extern::Explicit(abi) => {
|
||||
ast::Extern::Explicit(abi, _) => {
|
||||
self.word_nbsp("extern");
|
||||
self.print_literal(&abi.as_lit());
|
||||
self.nbsp();
|
||||
|
@ -1353,7 +1353,16 @@ fn recover_incorrect_vis_restriction(&mut self) -> PResult<'a, ()> {
|
||||
|
||||
/// Parses `extern string_literal?`.
|
||||
fn parse_extern(&mut self) -> Extern {
|
||||
if self.eat_keyword(kw::Extern) { Extern::from_abi(self.parse_abi()) } else { Extern::None }
|
||||
if self.eat_keyword(kw::Extern) {
|
||||
let mut extern_span = self.prev_token.span;
|
||||
let abi = self.parse_abi();
|
||||
if let Some(abi) = abi {
|
||||
extern_span = extern_span.to(abi.span);
|
||||
}
|
||||
Extern::from_abi(abi, extern_span)
|
||||
} else {
|
||||
Extern::None
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses a string literal as an ABI spec.
|
||||
|
@ -94,7 +94,7 @@ pub fn new(max_struct_bools: u64, max_fn_params_bools: u64) -> Self {
|
||||
|
||||
fn check_fn_sig(&self, cx: &EarlyContext<'_>, fn_sig: &FnSig, span: Span) {
|
||||
match fn_sig.header.ext {
|
||||
Extern::Implicit | Extern::Explicit(_) => return,
|
||||
Extern::Implicit(_) | Extern::Explicit(_, _) => return,
|
||||
Extern::None => (),
|
||||
}
|
||||
|
||||
|
@ -600,8 +600,8 @@ pub fn eq_ty(l: &Ty, r: &Ty) -> bool {
|
||||
pub fn eq_ext(l: &Extern, r: &Extern) -> bool {
|
||||
use Extern::*;
|
||||
match (l, r) {
|
||||
(None, None) | (Implicit, Implicit) => true,
|
||||
(Explicit(l), Explicit(r)) => eq_str_lit(l, r),
|
||||
(None, None) | (Implicit(_), Implicit(_)) => true,
|
||||
(Explicit(l,_), Explicit(r,_)) => eq_str_lit(l, r),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ fn from_foreign_mod(fm: &'a ast::ForeignMod, span: Span, config: &Config) -> Ite
|
||||
Item {
|
||||
unsafety: fm.unsafety,
|
||||
abi: format_extern(
|
||||
ast::Extern::from_abi(fm.abi),
|
||||
ast::Extern::from_abi(fm.abi, DUMMY_SP),
|
||||
config.force_explicit_abi(),
|
||||
true,
|
||||
),
|
||||
|
@ -138,8 +138,8 @@ pub(crate) fn format_extern(
|
||||
) -> Cow<'static, str> {
|
||||
let abi = match ext {
|
||||
ast::Extern::None => "Rust".to_owned(),
|
||||
ast::Extern::Implicit => "C".to_owned(),
|
||||
ast::Extern::Explicit(abi) => abi.symbol_unescaped.to_string(),
|
||||
ast::Extern::Implicit(_) => "C".to_owned(),
|
||||
ast::Extern::Explicit(abi, _) => abi.symbol_unescaped.to_string(),
|
||||
};
|
||||
|
||||
if abi == "Rust" && !is_mod {
|
||||
|
Loading…
Reference in New Issue
Block a user