Skip to content

Commit abae840

Browse files
committed
rustdoc: Show non-Rust ABIs on methods
Fix #21621
1 parent 43b8503 commit abae840

File tree

6 files changed

+70
-7
lines changed

6 files changed

+70
-7
lines changed

src/librustdoc/clean/inline.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,14 @@ fn build_impl(cx: &DocContext, tcx: &ty::ctxt,
306306
let mut item = method.clean(cx);
307307
item.inner = match item.inner.clone() {
308308
clean::TyMethodItem(clean::TyMethod {
309-
unsafety, decl, self_, generics
309+
unsafety, decl, self_, generics, abi
310310
}) => {
311311
clean::MethodItem(clean::Method {
312312
unsafety: unsafety,
313313
decl: decl,
314314
self_: self_,
315315
generics: generics,
316+
abi: abi
316317
})
317318
}
318319
_ => panic!("not a tymethod"),

src/librustdoc/clean/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub use self::FunctionRetTy::*;
2727
pub use self::TraitMethod::*;
2828

2929
use syntax;
30+
use syntax::abi;
3031
use syntax::ast;
3132
use syntax::ast_util;
3233
use syntax::ast_util::PostExpansionMethod;
@@ -945,6 +946,7 @@ pub struct Method {
945946
pub self_: SelfTy,
946947
pub unsafety: ast::Unsafety,
947948
pub decl: FnDecl,
949+
pub abi: abi::Abi
948950
}
949951

950952
impl Clean<Item> for ast::Method {
@@ -973,6 +975,7 @@ impl Clean<Item> for ast::Method {
973975
self_: self.pe_explicit_self().node.clean(cx),
974976
unsafety: self.pe_unsafety().clone(),
975977
decl: decl,
978+
abi: self.pe_abi()
976979
}),
977980
}
978981
}
@@ -984,6 +987,7 @@ pub struct TyMethod {
984987
pub decl: FnDecl,
985988
pub generics: Generics,
986989
pub self_: SelfTy,
990+
pub abi: abi::Abi
987991
}
988992

989993
impl Clean<Item> for ast::TypeMethod {
@@ -1011,6 +1015,7 @@ impl Clean<Item> for ast::TypeMethod {
10111015
decl: decl,
10121016
self_: self.explicit_self.node.clean(cx),
10131017
generics: self.generics.clean(cx),
1018+
abi: self.abi
10141019
}),
10151020
}
10161021
}
@@ -1301,6 +1306,7 @@ impl<'tcx> Clean<Item> for ty::Method<'tcx> {
13011306
generics: (&self.generics, subst::FnSpace).clean(cx),
13021307
self_: self_,
13031308
decl: (self.def_id, &sig).clean(cx),
1309+
abi: self.fty.abi
13041310
})
13051311
}
13061312
}

src/librustdoc/html/render.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ use externalfiles::ExternalHtml;
5050

5151
use serialize::json;
5252
use serialize::json::ToJson;
53+
use syntax::abi;
5354
use syntax::ast;
5455
use syntax::ast_util;
5556
use rustc::util::nodemap::NodeSet;
@@ -1809,15 +1810,22 @@ fn assoc_type(w: &mut fmt::Formatter, it: &clean::Item,
18091810
}
18101811

18111812
fn render_method(w: &mut fmt::Formatter, meth: &clean::Item) -> fmt::Result {
1812-
fn method(w: &mut fmt::Formatter, it: &clean::Item, unsafety: ast::Unsafety,
1813-
g: &clean::Generics, selfty: &clean::SelfTy,
1814-
d: &clean::FnDecl) -> fmt::Result {
1815-
write!(w, "{}fn <a href='#{ty}.{name}' class='fnname'>{name}</a>\
1813+
fn method(w: &mut fmt::Formatter, it: &clean::Item,
1814+
unsafety: ast::Unsafety, abi: abi::Abi,
1815+
g: &clean::Generics, selfty: &clean::SelfTy,
1816+
d: &clean::FnDecl) -> fmt::Result {
1817+
use syntax::abi::Abi;
1818+
1819+
write!(w, "{}{}fn <a href='#{ty}.{name}' class='fnname'>{name}</a>\
18161820
{generics}{decl}{where_clause}",
18171821
match unsafety {
18181822
ast::Unsafety::Unsafe => "unsafe ",
18191823
_ => "",
18201824
},
1825+
match abi {
1826+
Abi::Rust => String::new(),
1827+
a => format!("extern {} ", a.to_string())
1828+
},
18211829
ty = shortty(it),
18221830
name = it.name.as_ref().unwrap(),
18231831
generics = *g,
@@ -1826,10 +1834,10 @@ fn render_method(w: &mut fmt::Formatter, meth: &clean::Item) -> fmt::Result {
18261834
}
18271835
match meth.inner {
18281836
clean::TyMethodItem(ref m) => {
1829-
method(w, meth, m.unsafety, &m.generics, &m.self_, &m.decl)
1837+
method(w, meth, m.unsafety, m.abi, &m.generics, &m.self_, &m.decl)
18301838
}
18311839
clean::MethodItem(ref m) => {
1832-
method(w, meth, m.unsafety, &m.generics, &m.self_, &m.decl)
1840+
method(w, meth, m.unsafety, m.abi, &m.generics, &m.self_, &m.decl)
18331841
}
18341842
clean::AssociatedTypeItem(ref typ) => {
18351843
assoc_type(w, meth, typ)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-include ../tools.mk
2+
3+
all: foo.rs bar.rs
4+
$(HOST_RPATH_ENV) $(RUSTC) foo.rs
5+
$(HOST_RPATH_ENV) $(RUSTDOC) -w html -o $(TMPDIR)/doc foo.rs
6+
$(HOST_RPATH_ENV) $(RUSTDOC) -L $(TMPDIR) -w html -o $(TMPDIR)/doc bar.rs
7+
$(HTMLDOCCK) $(TMPDIR)/doc bar.rs
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
extern crate foo;
12+
13+
// @has bar/trait.Foo.html //pre "pub trait Foo"
14+
// @has - '//*[@id="tymethod.foo"]//code' 'extern "rust-call" fn foo'
15+
// @has - '//*[@id="tymethod.foo_"]//code' 'extern "rust-call" fn foo_'
16+
pub use foo::Foo;
17+
18+
// @has bar/trait.Bar.html //pre "pub trait Bar"
19+
pub trait Bar {
20+
// @has - '//*[@id="tymethod.bar"]//code' 'extern "rust-call" fn bar'
21+
extern "rust-call" fn bar(&self, _: ());
22+
// @has - '//*[@id="method.bar_"]//code' 'extern "rust-call" fn bar_'
23+
extern "rust-call" fn bar_(&self, _: ()) { }
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_type="lib"]
12+
13+
pub trait Foo {
14+
extern "rust-call" fn foo(&self, _: ()) -> i32;
15+
extern "rust-call" fn foo_(&self, _: ()) -> i32 { 0 }
16+
}

0 commit comments

Comments
 (0)