Skip to content

Commit 0ab2634

Browse files
Rollup merge of #156823 - ajasad25:rustdoc-self-submodule-tests-84827, r=camelid
Add regression test Fixes #84827.
2 parents d63db62 + c24ec53 commit 0ab2634

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// https://github.com/rust-lang/rust/issues/84827
2+
//
3+
// Regression test for resolving `Self` in intra-doc links inside an `impl`
4+
// block in a submodule. The `Self` type comes from the impl, not from names
5+
// in scope, so:
6+
// 1. It resolves even when the implemented type is not in scope.
7+
// 2. It resolves to the actual `Self` type, not to a different type with
8+
// the same name that happens to be in scope.
9+
10+
#![crate_name = "foo"]
11+
#![deny(rustdoc::broken_intra_doc_links)]
12+
#![allow(unused_imports)]
13+
14+
pub struct Foo {
15+
pub foo: i32,
16+
}
17+
18+
// Case 1: `Foo` is not in scope inside `bar`, but `Self::foo` still resolves
19+
// to the field on `crate::Foo`.
20+
pub mod bar {
21+
//@ has foo/struct.Foo.html '//a[@href="struct.Foo.html#structfield.foo"]' 'Self::foo'
22+
impl crate::Foo {
23+
/// Baz the [`Self::foo`].
24+
pub fn baz(&self) {}
25+
}
26+
}
27+
28+
// Case 2: A different type named `Foo` is in scope inside `baz`. `Self::foo`
29+
// must still resolve to `crate::Foo::foo`, not to `crate::other::Foo` (which
30+
// is a unit struct and has no `foo` field).
31+
pub mod baz {
32+
use crate::other::Foo;
33+
34+
//@ has foo/struct.Foo.html '//a[@href="struct.Foo.html#structfield.foo"]' 'Self::foo'
35+
impl crate::Foo {
36+
/// Quux the [`Self::foo`].
37+
pub fn quux(&self) {}
38+
}
39+
}
40+
41+
pub mod other {
42+
pub struct Foo;
43+
}

0 commit comments

Comments
 (0)