diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index c9f40a1adae32..c030f02f12334 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1721,7 +1721,7 @@ impl<'tcx> Clean for ty::Ty<'tcx> { where_predicates: Vec::new() }, decl: (cx.map.local_def_id(0), &fty.sig).clean(cx), - abi: fty.abi.to_string(), + abi: fty.abi, }), ty::TyStruct(def, substs) | ty::TyEnum(def, substs) => { @@ -2143,7 +2143,7 @@ pub struct BareFunctionDecl { pub unsafety: hir::Unsafety, pub generics: Generics, pub decl: FnDecl, - pub abi: String, + pub abi: Abi, } impl Clean for hir::BareFnTy { @@ -2156,7 +2156,7 @@ impl Clean for hir::BareFnTy { where_predicates: Vec::new() }, decl: self.decl.clean(cx), - abi: self.abi.to_string(), + abi: self.abi, } } } diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index d4212bba59060..72414ad4c5e9c 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -451,11 +451,7 @@ impl fmt::Display for clean::Type { clean::BareFunction(ref decl) => { write!(f, "{}{}fn{}{}", UnsafetySpace(decl.unsafety), - match &*decl.abi { - "" => " extern ".to_string(), - "\"Rust\"" => "".to_string(), - s => format!(" extern {} ", s) - }, + AbiSpace(decl.abi), decl.generics, decl.decl) } @@ -770,8 +766,7 @@ impl fmt::Display for AbiSpace { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.0 { Abi::Rust => Ok(()), - Abi::C => write!(f, "extern "), - abi => write!(f, "extern {} ", abi), + abi => write!(f, "extern "{}" ", abi.name()), } } } diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index c08d917589d3c..f41c81f20edf9 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2129,8 +2129,6 @@ fn render_assoc_item(w: &mut fmt::Formatter, d: &clean::FnDecl, link: AssocItemLink) -> fmt::Result { - use syntax::abi::Abi; - let name = meth.name.as_ref().unwrap(); let anchor = format!("#{}.{}", shortty(meth), name); let href = match link { @@ -2157,10 +2155,7 @@ fn render_assoc_item(w: &mut fmt::Formatter, {generics}{decl}{where_clause}", ConstnessSpace(vis_constness), UnsafetySpace(unsafety), - match abi { - Abi::Rust => String::new(), - a => format!("extern {} ", a.to_string()) - }, + AbiSpace(abi), href = href, name = name, generics = *g, diff --git a/src/test/rustdoc/extern-impl.rs b/src/test/rustdoc/extern-impl.rs new file mode 100644 index 0000000000000..5c64b4118c3ab --- /dev/null +++ b/src/test/rustdoc/extern-impl.rs @@ -0,0 +1,37 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_name = "foo"] + +// @has foo/struct.Foo.html +pub struct Foo; + +impl Foo { + // @has - '//code' 'fn rust0()' + pub fn rust0() {} + // @has - '//code' 'fn rust1()' + pub extern "Rust" fn rust1() {} + // @has - '//code' 'extern "C" fn c0()' + pub extern fn c0() {} + // @has - '//code' 'extern "C" fn c1()' + pub extern "C" fn c1() {} + // @has - '//code' 'extern "system" fn system0()' + pub extern "system" fn system0() {} +} + +// @has foo/trait.Bar.html +pub trait Bar {} + +// @has - '//code' 'impl Bar for fn()' +impl Bar for fn() {} +// @has - '//code' 'impl Bar for extern "C" fn()' +impl Bar for extern fn() {} +// @has - '//code' 'impl Bar for extern "system" fn()' +impl Bar for extern "system" fn() {} diff --git a/src/test/rustdoc/ffi.rs b/src/test/rustdoc/ffi.rs index 3997dcd81e153..8511d461703de 100644 --- a/src/test/rustdoc/ffi.rs +++ b/src/test/rustdoc/ffi.rs @@ -13,10 +13,10 @@ extern crate rustdoc_ffi as lib; -// @has ffi/fn.foreigner.html //pre 'pub unsafe extern fn foreigner(cold_as_ice: u32)' +// @has ffi/fn.foreigner.html //pre 'pub unsafe extern "C" fn foreigner(cold_as_ice: u32)' pub use lib::foreigner; extern "C" { - // @has ffi/fn.another.html //pre 'pub unsafe extern fn another(cold_as_ice: u32)' + // @has ffi/fn.another.html //pre 'pub unsafe extern "C" fn another(cold_as_ice: u32)' pub fn another(cold_as_ice: u32); } diff --git a/src/test/rustdoc/issue-22038.rs b/src/test/rustdoc/issue-22038.rs index 6f84428b0798f..75df53589454f 100644 --- a/src/test/rustdoc/issue-22038.rs +++ b/src/test/rustdoc/issue-22038.rs @@ -10,7 +10,7 @@ extern { // @has issue_22038/fn.foo1.html \ - // '//*[@class="rust fn"]' 'pub unsafe extern fn foo1()' + // '//*[@class="rust fn"]' 'pub unsafe extern "C" fn foo1()' pub fn foo1(); } @@ -21,7 +21,7 @@ extern "system" { } // @has issue_22038/fn.bar.html \ -// '//*[@class="rust fn"]' 'pub extern fn bar()' +// '//*[@class="rust fn"]' 'pub extern "C" fn bar()' pub extern fn bar() {} // @has issue_22038/fn.baz.html \ diff --git a/src/test/rustdoc/variadic.rs b/src/test/rustdoc/variadic.rs index 1b60c2a334fa5..6ba776ba4679f 100644 --- a/src/test/rustdoc/variadic.rs +++ b/src/test/rustdoc/variadic.rs @@ -9,6 +9,6 @@ // except according to those terms. extern "C" { - // @has variadic/fn.foo.html //pre 'pub unsafe extern fn foo(x: i32, ...)' + // @has variadic/fn.foo.html //pre 'pub unsafe extern "C" fn foo(x: i32, ...)' pub fn foo(x: i32, ...); }