Handle 'extern "Rust"' in format_abi()
This commit is contained in:
parent
9537437e52
commit
62e38860b9
3 changed files with 13 additions and 17 deletions
10
src/items.rs
10
src/items.rs
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
// Formatting top-level items - functions, structs, enums, traits, impls.
|
// Formatting top-level items - functions, structs, enums, traits, impls.
|
||||||
|
|
||||||
|
use std::borrow::Cow;
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
|
|
||||||
use syntax::{abi, ast, ptr, symbol};
|
use syntax::{abi, ast, ptr, symbol};
|
||||||
|
@ -126,7 +127,7 @@ impl Rewrite for ast::Local {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
struct Item<'a> {
|
struct Item<'a> {
|
||||||
keyword: &'static str,
|
keyword: &'static str,
|
||||||
abi: String,
|
abi: Cow<'static, str>,
|
||||||
vis: Option<&'a ast::Visibility>,
|
vis: Option<&'a ast::Visibility>,
|
||||||
body: Vec<BodyElement<'a>>,
|
body: Vec<BodyElement<'a>>,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -134,14 +135,9 @@ struct Item<'a> {
|
||||||
|
|
||||||
impl<'a> Item<'a> {
|
impl<'a> Item<'a> {
|
||||||
fn from_foreign_mod(fm: &'a ast::ForeignMod, span: Span, config: &Config) -> Item<'a> {
|
fn from_foreign_mod(fm: &'a ast::ForeignMod, span: Span, config: &Config) -> Item<'a> {
|
||||||
let abi = if fm.abi == abi::Abi::C && !config.force_explicit_abi() {
|
|
||||||
"extern".into()
|
|
||||||
} else {
|
|
||||||
format!("extern {}", fm.abi)
|
|
||||||
};
|
|
||||||
Item {
|
Item {
|
||||||
keyword: "",
|
keyword: "",
|
||||||
abi: abi,
|
abi: format_abi(fm.abi, config.force_explicit_abi(), true),
|
||||||
vis: None,
|
vis: None,
|
||||||
body: fm.items
|
body: fm.items
|
||||||
.iter()
|
.iter()
|
||||||
|
|
14
src/types.rs
14
src/types.rs
|
@ -11,7 +11,6 @@
|
||||||
use std::iter::ExactSizeIterator;
|
use std::iter::ExactSizeIterator;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use syntax::abi;
|
|
||||||
use syntax::ast::{self, FunctionRetTy, Mutability};
|
use syntax::ast::{self, FunctionRetTy, Mutability};
|
||||||
use syntax::codemap::{self, BytePos, Span};
|
use syntax::codemap::{self, BytePos, Span};
|
||||||
use syntax::print::pprust;
|
use syntax::print::pprust;
|
||||||
|
@ -26,7 +25,7 @@ use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListTac
|
||||||
SeparatorPlace, SeparatorTactic};
|
SeparatorPlace, SeparatorTactic};
|
||||||
use rewrite::{Rewrite, RewriteContext};
|
use rewrite::{Rewrite, RewriteContext};
|
||||||
use shape::Shape;
|
use shape::Shape;
|
||||||
use utils::{colon_spaces, extra_offset, format_mutability, last_line_width, mk_sp};
|
use utils::{colon_spaces, extra_offset, format_abi, format_mutability, last_line_width, mk_sp};
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
pub enum PathContext {
|
pub enum PathContext {
|
||||||
|
@ -792,12 +791,11 @@ fn rewrite_bare_fn(
|
||||||
|
|
||||||
result.push_str(::utils::format_unsafety(bare_fn.unsafety));
|
result.push_str(::utils::format_unsafety(bare_fn.unsafety));
|
||||||
|
|
||||||
if bare_fn.abi != abi::Abi::Rust {
|
result.push_str(&format_abi(
|
||||||
result.push_str(&::utils::format_abi(
|
bare_fn.abi,
|
||||||
bare_fn.abi,
|
context.config.force_explicit_abi(),
|
||||||
context.config.force_explicit_abi(),
|
false,
|
||||||
));
|
));
|
||||||
}
|
|
||||||
|
|
||||||
result.push_str("fn");
|
result.push_str("fn");
|
||||||
|
|
||||||
|
|
|
@ -88,8 +88,10 @@ pub fn format_mutability(mutability: ast::Mutability) -> &'static str {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn format_abi(abi: abi::Abi, explicit_abi: bool) -> Cow<'static, str> {
|
pub fn format_abi(abi: abi::Abi, explicit_abi: bool, is_mod: bool) -> Cow<'static, str> {
|
||||||
if abi == abi::Abi::C && !explicit_abi {
|
if abi == abi::Abi::Rust && !is_mod {
|
||||||
|
Cow::from("")
|
||||||
|
} else if abi == abi::Abi::C && !explicit_abi {
|
||||||
Cow::from("extern ")
|
Cow::from("extern ")
|
||||||
} else {
|
} else {
|
||||||
Cow::from(format!("extern {} ", abi))
|
Cow::from(format!("extern {} ", abi))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue