mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Merge pull request #950 from marcusklaas/extern-abi
Add option to force explicit extern ABI's
This commit is contained in:
commit
75aeca4d39
@ -328,6 +328,7 @@ create_config! {
|
|||||||
"Maximum width of the args of a function call before falling back to vertical formatting";
|
"Maximum width of the args of a function call before falling back to vertical formatting";
|
||||||
struct_lit_width: usize, 16,
|
struct_lit_width: usize, 16,
|
||||||
"Maximum width in the body of a struct lit before falling back to vertical formatting";
|
"Maximum width in the body of a struct lit before falling back to vertical formatting";
|
||||||
|
force_explicit_abi: bool, true, "Always print the abi for extern items";
|
||||||
newline_style: NewlineStyle, NewlineStyle::Unix, "Unix or Windows line endings";
|
newline_style: NewlineStyle, NewlineStyle::Unix, "Unix or Windows line endings";
|
||||||
fn_brace_style: BraceStyle, BraceStyle::SameLineWhere, "Brace style for functions";
|
fn_brace_style: BraceStyle, BraceStyle::SameLineWhere, "Brace style for functions";
|
||||||
item_brace_style: BraceStyle, BraceStyle::SameLineWhere, "Brace style for structs and enums";
|
item_brace_style: BraceStyle, BraceStyle::SameLineWhere, "Brace style for structs and enums";
|
||||||
|
@ -80,7 +80,8 @@ impl Rewrite for ast::Local {
|
|||||||
|
|
||||||
impl<'a> FmtVisitor<'a> {
|
impl<'a> FmtVisitor<'a> {
|
||||||
pub fn format_foreign_mod(&mut self, fm: &ast::ForeignMod, span: Span) {
|
pub fn format_foreign_mod(&mut self, fm: &ast::ForeignMod, span: Span) {
|
||||||
self.buffer.push_str(&::utils::format_abi(fm.abi));
|
let abi_str = ::utils::format_abi(fm.abi, self.config.force_explicit_abi);
|
||||||
|
self.buffer.push_str(&abi_str);
|
||||||
|
|
||||||
let snippet = self.snippet(span);
|
let snippet = self.snippet(span);
|
||||||
let brace_pos = snippet.find_uncommented("{").unwrap();
|
let brace_pos = snippet.find_uncommented("{").unwrap();
|
||||||
@ -1265,7 +1266,7 @@ fn rewrite_fn_base(context: &RewriteContext,
|
|||||||
result.push_str(::utils::format_unsafety(unsafety));
|
result.push_str(::utils::format_unsafety(unsafety));
|
||||||
|
|
||||||
if abi != abi::Abi::Rust {
|
if abi != abi::Abi::Rust {
|
||||||
result.push_str(&::utils::format_abi(abi));
|
result.push_str(&::utils::format_abi(abi, context.config.force_explicit_abi));
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn foo
|
// fn foo
|
||||||
|
@ -608,7 +608,7 @@ fn rewrite_bare_fn(bare_fn: &ast::BareFnTy,
|
|||||||
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 {
|
if bare_fn.abi != abi::Abi::Rust {
|
||||||
result.push_str(&::utils::format_abi(bare_fn.abi));
|
result.push_str(&::utils::format_abi(bare_fn.abi, context.config.force_explicit_abi));
|
||||||
}
|
}
|
||||||
|
|
||||||
result.push_str("fn");
|
result.push_str("fn");
|
||||||
|
@ -91,9 +91,12 @@ pub fn format_mutability(mutability: ast::Mutability) -> &'static str {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
// FIXME(#451): include "C"?
|
pub fn format_abi(abi: abi::Abi, explicit_abi: bool) -> String {
|
||||||
pub fn format_abi(abi: abi::Abi) -> String {
|
if abi == abi::Abi::C && !explicit_abi {
|
||||||
format!("extern {} ", abi)
|
"extern ".into()
|
||||||
|
} else {
|
||||||
|
format!("extern {} ", abi)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The width of the first line in s.
|
// The width of the first line in s.
|
||||||
|
14
tests/source/extern_not_explicit.rs
Normal file
14
tests/source/extern_not_explicit.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// rustfmt-force_explicit_abi: false
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
fn some_fn() -> ();
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" fn sup() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
type funky_func = extern "C" fn (unsafe extern "rust-call" fn(*const JSJitInfo, *mut JSContext,
|
||||||
|
HandleObject, *mut libc::c_void, u32,
|
||||||
|
*mut JSVal)
|
||||||
|
-> u8);
|
15
tests/target/extern_not_explicit.rs
Normal file
15
tests/target/extern_not_explicit.rs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// rustfmt-force_explicit_abi: false
|
||||||
|
|
||||||
|
extern {
|
||||||
|
fn some_fn() -> ();
|
||||||
|
}
|
||||||
|
|
||||||
|
extern fn sup() {}
|
||||||
|
|
||||||
|
type funky_func = extern fn(unsafe extern "rust-call" fn(*const JSJitInfo,
|
||||||
|
*mut JSContext,
|
||||||
|
HandleObject,
|
||||||
|
*mut libc::c_void,
|
||||||
|
u32,
|
||||||
|
*mut JSVal)
|
||||||
|
-> u8);
|
Loading…
Reference in New Issue
Block a user