Skip to content

Commit d7fcee8

Browse files
committed
rustdoc: Detect provided methods on inlined traits
Closes #23864
1 parent 947f1b6 commit d7fcee8

File tree

5 files changed

+64
-9
lines changed

5 files changed

+64
-9
lines changed

src/librustdoc/clean/mod.rs

+30-7
Original file line numberDiff line numberDiff line change
@@ -1296,20 +1296,43 @@ impl<'tcx> Clean<Item> for ty::Method<'tcx> {
12961296
}
12971297
};
12981298

1299+
let generics = (&self.generics, &self.predicates,
1300+
subst::FnSpace).clean(cx);
1301+
let decl = (self.def_id, &sig).clean(cx);
1302+
let provided = match self.container {
1303+
ty::ImplContainer(..) => false,
1304+
ty::TraitContainer(did) => {
1305+
ty::provided_trait_methods(cx.tcx(), did).iter().any(|m| {
1306+
m.def_id == self.def_id
1307+
})
1308+
}
1309+
};
1310+
let inner = if provided {
1311+
MethodItem(Method {
1312+
unsafety: self.fty.unsafety,
1313+
generics: generics,
1314+
self_: self_,
1315+
decl: decl,
1316+
abi: self.fty.abi
1317+
})
1318+
} else {
1319+
TyMethodItem(TyMethod {
1320+
unsafety: self.fty.unsafety,
1321+
generics: generics,
1322+
self_: self_,
1323+
decl: decl,
1324+
abi: self.fty.abi
1325+
})
1326+
};
1327+
12991328
Item {
13001329
name: Some(self.name.clean(cx)),
13011330
visibility: Some(ast::Inherited),
13021331
stability: get_stability(cx, self.def_id),
13031332
def_id: self.def_id,
13041333
attrs: inline::load_attrs(cx, cx.tcx(), self.def_id),
13051334
source: Span::empty(),
1306-
inner: TyMethodItem(TyMethod {
1307-
unsafety: self.fty.unsafety,
1308-
generics: (&self.generics, &self.predicates, subst::FnSpace).clean(cx),
1309-
self_: self_,
1310-
decl: (self.def_id, &sig).clean(cx),
1311-
abi: self.fty.abi
1312-
})
1335+
inner: inner,
13131336
}
13141337
}
13151338
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
pub trait Foo {
12+
fn bar(&self);
13+
fn foo(&mut self) {}
14+
}

src/test/rustdoc/extern-method.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extern crate rustdoc_extern_method as foo;
1616

1717
// @has extern_method/trait.Foo.html //pre "pub trait Foo"
1818
// @has - '//*[@id="tymethod.foo"]//code' 'extern "rust-call" fn foo'
19-
// @has - '//*[@id="tymethod.foo_"]//code' 'extern "rust-call" fn foo_'
19+
// @has - '//*[@id="method.foo_"]//code' 'extern "rust-call" fn foo_'
2020
pub use foo::Foo;
2121

2222
// @has extern_method/trait.Bar.html //pre "pub trait Bar"
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
// aux-build:inline-default-methods.rs
12+
13+
extern crate inline_default_methods;
14+
15+
// @has inline_default_methods/trait.Foo.html
16+
// @has - '//*[@class="rust trait"]' 'fn bar(&self);'
17+
// @has - '//*[@class="rust trait"]' 'fn foo(&mut self) { ... }'
18+
pub use inline_default_methods::Foo;

src/test/rustdoc/issue-17476.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ extern crate issue_17476;
1515
pub struct Foo;
1616

1717
// @has issue_17476/struct.Foo.html \
18-
// '//*[@href="http://example.com/issue_17476/trait.Foo.html#tymethod.foo"]' \
18+
// '//*[@href="http://example.com/issue_17476/trait.Foo.html#method.foo"]' \
1919
// 'foo'
2020
impl issue_17476::Foo for Foo {}

0 commit comments

Comments
 (0)