Skip to content

Commit 8874fd4

Browse files
committed
rustdoc: Show impls for references to types
It's somewhat common to impl traits for `&T` and `&mut T` so show these on the pages for `T` to ensure they're listed somewhere at least. Closes #20175
1 parent 8f6855c commit 8874fd4

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/librustdoc/html/render.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,12 @@ impl DocFolder for Cache {
10591059
// Figure out the id of this impl. This may map to a
10601060
// primitive rather than always to a struct/enum.
10611061
let did = match i.for_ {
1062-
ResolvedPath { did, .. } => Some(did),
1062+
ResolvedPath { did, .. } |
1063+
BorrowedRef {
1064+
type_: box ResolvedPath { did, .. }, ..
1065+
} => {
1066+
Some(did)
1067+
}
10631068

10641069
// References to primitives are picked up as well to
10651070
// recognize implementations for &str, this may not

src/test/rustdoc/issue-20175.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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 foo(&self) {}
13+
}
14+
15+
pub struct Bar;
16+
17+
// @has issue_20175/struct.Bar.html \
18+
// '//*[@id="method.foo"]' \
19+
// 'fn foo'
20+
impl<'a> Foo for &'a Bar {}

0 commit comments

Comments
 (0)