diff options
| author | bors <bors@rust-lang.org> | 2016-04-27 23:16:41 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-04-27 23:16:41 -0700 |
| commit | cf3970aac536ea446a967a246cc3527a11d89655 (patch) | |
| tree | eac57beb3ffabf57d0a72e81502bd32bf288d16a | |
| parent | 435095f32af93d27baf1390fa34e7dfff5eb7d5d (diff) | |
| parent | 48aabbd9e3a451439070325c56fd84def324bdbd (diff) | |
| download | rust-cf3970aac536ea446a967a246cc3527a11d89655.tar.gz rust-cf3970aac536ea446a967a246cc3527a11d89655.zip | |
Auto merge of #33151 - ollie27:rustdoc_abi, r=alexcrichton
rustdoc: Cleanup ABI rendering Use a common method for rendering `extern "<abi>"`. This now consistently shows `extern fn` rather than `extern "C" fn`.
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 6 | ||||
| -rw-r--r-- | src/librustdoc/html/format.rs | 8 | ||||
| -rw-r--r-- | src/librustdoc/html/render.rs | 7 | ||||
| -rw-r--r-- | src/test/rustdoc/extern-impl.rs | 37 |
4 files changed, 43 insertions, 15 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 23215fd9d47..35922c477cc 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1721,7 +1721,7 @@ impl<'tcx> Clean<Type> 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<BareFunctionDecl> for hir::BareFnTy { @@ -2156,7 +2156,7 @@ impl Clean<BareFunctionDecl> 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 739da1b49d4..d7763197f8a 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -468,11 +468,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) } @@ -788,7 +784,7 @@ impl fmt::Display for AbiSpace { 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 b7d459381ed..5cdddc76582 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2158,8 +2158,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 { @@ -2186,10 +2184,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 00000000000..0e78746704f --- /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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 fn c0()' + pub extern fn c0() {} + // @has - '//code' 'extern 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 fn()' +impl Bar for extern fn() {} +// @has - '//code' 'impl Bar for extern "system" fn()' +impl Bar for extern "system" fn() {} |
