Skip to content

Commit 267cf8d

Browse files
committed
Auto merge of #131224 - notriddle:notriddle/intra-doc-link-value, r=GuillaumeGomez
rustdoc: prevent ctors from resolving Fixes #130591
2 parents 3002af6 + 253fec4 commit 267cf8d

File tree

5 files changed

+105
-6
lines changed

5 files changed

+105
-6
lines changed

compiler/rustc_resolve/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2148,7 +2148,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
21482148

21492149
match self.maybe_resolve_path(&segments, Some(ns), &parent_scope, None) {
21502150
PathResult::Module(ModuleOrUniformRoot::Module(module)) => Some(module.res().unwrap()),
2151-
PathResult::NonModule(path_res) => path_res.full_res(),
2151+
PathResult::NonModule(path_res) => {
2152+
path_res.full_res().filter(|res| !matches!(res, Res::Def(DefKind::Ctor(..), _)))
2153+
}
21522154
PathResult::Module(ModuleOrUniformRoot::ExternPrelude) | PathResult::Failed { .. } => {
21532155
None
21542156
}

tests/rustdoc-ui/intra-doc/disambiguator-mismatch.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ struct X {
9191
//~| HELP prefix with `field@`
9292

9393
/// Link to [field@S::A]
94-
//~^ ERROR incompatible link kind for `S::A`
95-
//~| NOTE this link resolved
94+
//~^ ERROR unresolved link to `S::A`
95+
//~| NOTE this link resolves
9696
//~| HELP prefix with `variant@`
9797
pub fn f() {}

tests/rustdoc-ui/intra-doc/disambiguator-mismatch.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ help: to link to the field, prefix with `field@`
160160
LL | /// Link to [field@X::y]
161161
| ~~~~~~
162162

163-
error: incompatible link kind for `S::A`
163+
error: unresolved link to `S::A`
164164
--> $DIR/disambiguator-mismatch.rs:93:14
165165
|
166166
LL | /// Link to [field@S::A]
167-
| ^^^^^^^^^^ this link resolved to a unit variant, which is not a field
167+
| ^^^^^^^^^^ this link resolves to the variant `A`, which is not in the value namespace
168168
|
169-
help: to link to the unit variant, prefix with `variant@`
169+
help: to link to the variant, prefix with `variant@`
170170
|
171171
LL | /// Link to [variant@S::A]
172172
| ~~~~~~~~
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// https://github.com/rust-lang/rust/issues/130591
2+
#![deny(rustdoc::broken_intra_doc_links)]
3+
#![crate_name = "foo"]
4+
5+
/// [value@Foo::X] //~ERROR broken
6+
pub enum Foo {
7+
X,
8+
}
9+
10+
/// [tst][value@MyStruct] //~ERROR broken
11+
pub struct MyStruct;
12+
13+
pub enum MyEnum {
14+
Internals,
15+
}
16+
17+
pub use MyEnum::*;
18+
19+
/// In this context, [a][type@Internals] is a struct,
20+
/// while [b][value@Internals] fails. //~ERROR broken
21+
/// Also, [c][struct@Internals] is a struct,
22+
/// while [d][variant@Internals] fails. //~ERROR broken
23+
pub struct Internals {
24+
foo: (),
25+
}
26+
27+
pub mod inside {
28+
pub struct Internals2;
29+
}
30+
31+
use inside::*;
32+
33+
/// In this context, [a][type@Internals2] is an enum,
34+
/// while [b][value@Internals2] fails. //~ERROR broken
35+
pub enum Internals2 {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
error: unresolved link to `Foo::X`
2+
--> $DIR/value-ctor.rs:5:6
3+
|
4+
LL | /// [value@Foo::X]
5+
| ^^^^^^^^^^^^ this link resolves to the variant `X`, which is not in the value namespace
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/value-ctor.rs:2:9
9+
|
10+
LL | #![deny(rustdoc::broken_intra_doc_links)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
help: to link to the variant, prefix with `variant@`
13+
|
14+
LL | /// [variant@Foo::X]
15+
| ~~~~~~~~
16+
17+
error: unresolved link to `MyStruct`
18+
--> $DIR/value-ctor.rs:10:11
19+
|
20+
LL | /// [tst][value@MyStruct]
21+
| ^^^^^^^^^^^^^^ this link resolves to the struct `MyStruct`, which is not in the value namespace
22+
|
23+
help: to link to the struct, prefix with `struct@`
24+
|
25+
LL | /// [tst][struct@MyStruct]
26+
| ~~~~~~~
27+
28+
error: unresolved link to `Internals`
29+
--> $DIR/value-ctor.rs:20:15
30+
|
31+
LL | /// while [b][value@Internals] fails.
32+
| ^^^^^^^^^^^^^^^ this link resolves to the struct `Internals`, which is not in the value namespace
33+
|
34+
help: to link to the struct, prefix with `struct@`
35+
|
36+
LL | /// while [b][struct@Internals] fails.
37+
| ~~~~~~~
38+
39+
error: incompatible link kind for `Internals`
40+
--> $DIR/value-ctor.rs:22:15
41+
|
42+
LL | /// while [d][variant@Internals] fails.
43+
| ^^^^^^^^^^^^^^^^^ this link resolved to a struct, which is not a variant
44+
|
45+
help: to link to the struct, prefix with `struct@`
46+
|
47+
LL | /// while [d][struct@Internals] fails.
48+
| ~~~~~~~
49+
50+
error: unresolved link to `Internals2`
51+
--> $DIR/value-ctor.rs:34:15
52+
|
53+
LL | /// while [b][value@Internals2] fails.
54+
| ^^^^^^^^^^^^^^^^ this link resolves to the enum `Internals2`, which is not in the value namespace
55+
|
56+
help: to link to the enum, prefix with `enum@`
57+
|
58+
LL | /// while [b][enum@Internals2] fails.
59+
| ~~~~~
60+
61+
error: aborting due to 5 previous errors
62+

0 commit comments

Comments
 (0)