Skip to content

Commit f4e6ebd

Browse files
committed
Fix tests and improve error message if :: isn't found
1 parent 42bed03 commit f4e6ebd

File tree

5 files changed

+33
-54
lines changed

5 files changed

+33
-54
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,10 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
324324
})
325325
// If there's no `::`, it's not an associated item.
326326
// So we can be sure that `rustc_resolve` was accurate when it said it wasn't resolved.
327-
.ok_or(ErrorKind::Resolve(ResolutionFailure::NotInScope(
328-
item_name.to_string().into(),
329-
)))?;
327+
.ok_or_else(|| {
328+
debug!("found no `::`, assumming {} was correctly not in scope", item_name);
329+
ErrorKind::Resolve(ResolutionFailure::NotInScope(item_name.to_string().into()))
330+
})?;
330331

331332
if let Some((path, prim)) = is_primitive(&path_root, ns) {
332333
let impls = primitive_impl(cx, &path).ok_or_else(|| {
@@ -361,6 +362,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
361362

362363
let (_, ty_res) = cx
363364
.enter_resolver(|resolver| {
365+
// only types can have associated items
364366
resolver.resolve_str_path_error(DUMMY_SP, &path_root, TypeNS, module_id)
365367
})
366368
.map_err(|_| {
@@ -1450,10 +1452,7 @@ fn resolution_failure(
14501452
// FIXME: when are items neither a primitive nor a Def?
14511453
if let Res::Def(_, def_id) = res {
14521454
let name = cx.tcx.item_name(def_id);
1453-
let note = format!(
1454-
"`{}` has no field, variant, or associated item named `{}`",
1455-
name, assoc_item
1456-
);
1455+
let note = format!("no `{}` in `{}`", assoc_item, name,);
14571456
diag.note(&note);
14581457
}
14591458
}

src/test/rustdoc-ui/intra-doc-alias-ice.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ note: the lint level is defined here
1010
LL | #![deny(broken_intra_doc_links)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^
1212
= note: this link partially resolves to the type alias `TypeAlias`
13-
= note: `TypeAlias` has no field, variant, or associated item named `hoge`
13+
= note: no `hoge` in `TypeAlias`
1414

1515
error: aborting due to previous error
1616

src/test/rustdoc-ui/intra-link-errors.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#![deny(broken_intra_doc_links)]
22
//~^ NOTE lint level is defined
33

4-
//! [std::io::oops]
5-
//! [std::io::oops::not::here]
6-
74
// FIXME: this should say that it was skipped (maybe an allowed by default lint?)
85
/// [<invalid syntax>]
96
@@ -22,26 +19,26 @@
2219
/// [S::A]
2320
//~^ ERROR unresolved link
2421
//~| NOTE this link partially resolves
25-
//~| NOTE `S` has no field
22+
//~| NOTE no `A` in `S`
2623

2724
/// [S::fmt]
2825
//~^ ERROR unresolved link
2926
//~| NOTE this link partially resolves
30-
//~| NOTE `S` has no field
27+
//~| NOTE no `fmt` in `S`
3128

3229
/// [E::D]
3330
//~^ ERROR unresolved link
3431
//~| NOTE this link partially resolves
35-
//~| NOTE `E` has no field
32+
//~| NOTE no `D` in `E`
3633

3734
/// [u8::not_found]
3835
//~^ ERROR unresolved link
3936
//~| NOTE the builtin type `u8` does not have an associated item named `not_found`
4037

4138
/// [S!]
4239
//~^ ERROR unresolved link
43-
//~| HELP to link to the unit struct, use its disambiguator
44-
//~| NOTE this link resolves to the unit struct `S`
40+
//~| HELP to link to the struct, use its disambiguator
41+
//~| NOTE this link resolves to the struct `S`
4542
pub fn f() {}
4643
#[derive(Debug)]
4744
pub struct S;
@@ -62,6 +59,9 @@ impl S {
6259
//~| NOTE not in the type namespace
6360

6461
/// [T::h!]
62+
//~^ ERROR unresolved link
63+
//~| NOTE no item named `T::h`
64+
//~| HELP to escape
6565
pub trait T {
6666
fn g() {}
6767
}
Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,19 @@
1-
error: unresolved link to `std::io::oops`
2-
--> $DIR/intra-link-errors.rs:4:6
1+
error: unresolved link to `path::to::nonexistent::module`
2+
--> $DIR/intra-link-errors.rs:8:6
33
|
4-
LL | //! [std::io::oops]
5-
| ^^^^^^^^^^^^^
4+
LL | /// [path::to::nonexistent::module]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
note: the lint level is defined here
88
--> $DIR/intra-link-errors.rs:1:9
99
|
1010
LL | #![deny(broken_intra_doc_links)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^
12-
= note: this link resolves to the crate `std`, which is not an enum
13-
= note: if this were an enum, it might have a variant which resolved
14-
= note: this link partially resolves to the module `io`
15-
= note: `io` has no field, variant, or associated item named `oops`
16-
17-
error: unresolved link to `std::io::oops::not::here`
18-
--> $DIR/intra-link-errors.rs:5:6
19-
|
20-
LL | //! [std::io::oops::not::here]
21-
| ^^^^^^^^^^^^^^^^^^^^^^^^
22-
|
23-
= note: no item named `std::io::oops::not` is in scope
24-
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
25-
26-
error: unresolved link to `path::to::nonexistent::module`
27-
--> $DIR/intra-link-errors.rs:11:6
28-
|
29-
LL | /// [path::to::nonexistent::module]
30-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31-
|
3212
= note: no item named `path::to::nonexistent` is in scope
3313
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
3414

3515
error: unresolved link to `f::A`
36-
--> $DIR/intra-link-errors.rs:17:6
16+
--> $DIR/intra-link-errors.rs:14:6
3717
|
3818
LL | /// [f::A]
3919
| ^^^^
@@ -42,58 +22,58 @@ LL | /// [f::A]
4222
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
4323

4424
error: unresolved link to `S::A`
45-
--> $DIR/intra-link-errors.rs:22:6
25+
--> $DIR/intra-link-errors.rs:19:6
4626
|
4727
LL | /// [S::A]
4828
| ^^^^
4929
|
5030
= note: this link partially resolves to the struct `S`
51-
= note: `S` has no field, variant, or associated item named `A`
31+
= note: no `A` in `S`
5232

5333
error: unresolved link to `S::fmt`
54-
--> $DIR/intra-link-errors.rs:27:6
34+
--> $DIR/intra-link-errors.rs:24:6
5535
|
5636
LL | /// [S::fmt]
5737
| ^^^^^^
5838
|
5939
= note: this link partially resolves to the struct `S`
60-
= note: `S` has no field, variant, or associated item named `fmt`
40+
= note: no `fmt` in `S`
6141

6242
error: unresolved link to `E::D`
63-
--> $DIR/intra-link-errors.rs:32:6
43+
--> $DIR/intra-link-errors.rs:29:6
6444
|
6545
LL | /// [E::D]
6646
| ^^^^
6747
|
6848
= note: this link partially resolves to the enum `E`
69-
= note: `E` has no field, variant, or associated item named `D`
49+
= note: no `D` in `E`
7050

7151
error: unresolved link to `u8::not_found`
72-
--> $DIR/intra-link-errors.rs:37:6
52+
--> $DIR/intra-link-errors.rs:34:6
7353
|
7454
LL | /// [u8::not_found]
7555
| ^^^^^^^^^^^^^
7656
|
7757
= note: the builtin type `u8` does not have an associated item named `not_found`
7858

7959
error: unresolved link to `S`
80-
--> $DIR/intra-link-errors.rs:41:6
60+
--> $DIR/intra-link-errors.rs:38:6
8161
|
8262
LL | /// [S!]
8363
| ^^ help: to link to the struct, use its disambiguator: `struct@S`
8464
|
8565
= note: this link resolves to the struct `S`, which is not in the macro namespace
8666

8767
error: unresolved link to `T::g`
88-
--> $DIR/intra-link-errors.rs:59:6
68+
--> $DIR/intra-link-errors.rs:56:6
8969
|
9070
LL | /// [type@T::g]
9171
| ^^^^^^^^^ help: to link to the associated function, use its disambiguator: `T::g()`
9272
|
9373
= note: this link resolves to the associated function `g`, which is not in the type namespace
9474

9575
error: unresolved link to `T::h`
96-
--> $DIR/intra-link-errors.rs:64:6
76+
--> $DIR/intra-link-errors.rs:61:6
9777
|
9878
LL | /// [T::h!]
9979
| ^^^^^
@@ -102,12 +82,12 @@ LL | /// [T::h!]
10282
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
10383

10484
error: unresolved link to `S::h`
105-
--> $DIR/intra-link-errors.rs:51:6
85+
--> $DIR/intra-link-errors.rs:48:6
10686
|
10787
LL | /// [type@S::h]
10888
| ^^^^^^^^^ help: to link to the associated function, use its disambiguator: `S::h()`
10989
|
11090
= note: this link resolves to the associated function `h`, which is not in the type namespace
11191

112-
error: aborting due to 12 previous errors
92+
error: aborting due to 10 previous errors
11393

src/test/rustdoc-ui/intra-links-warning.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | //! Test with [Foo::baz], [Bar::foo], ...
66
|
77
= note: `#[warn(broken_intra_doc_links)]` on by default
88
= note: this link partially resolves to the struct `Foo`
9-
= note: `Foo` has no field, variant, or associated item named `baz`
9+
= note: no `baz` in `Foo`
1010

1111
warning: unresolved link to `Bar::foo`
1212
--> $DIR/intra-links-warning.rs:3:35

0 commit comments

Comments
 (0)