Report an ambiguity if both modules and primitives are in scope

- Add a new `prim@` disambiguator, since both modules and primitives are
in the same namespace
- Refactor `report_ambiguity` into a closure

Additionally, I noticed that rustdoc would previously allow
`[struct@char]` if `char` resolved to a primitive (not if it had a
DefId). I fixed that and added a test case.
This commit is contained in:
Joshua Nelson 2020-08-22 15:00:19 -04:00
parent 8fdce9bbb9
commit 47b8a5258d
3 changed files with 192 additions and 43 deletions

View file

@ -0,0 +1,30 @@
#![deny(broken_intra_doc_links)]
//~^ NOTE lint level is defined
/// [char]
//~^ ERROR both a module and a builtin type
//~| NOTE ambiguous link
//~| HELP to link to the module
//~| HELP to link to the builtin type
/// [type@char]
//~^ ERROR both a module and a builtin type
//~| NOTE ambiguous link
//~| HELP to link to the module
//~| HELP to link to the builtin type
/// [mod@char] // ok
/// [prim@char] // ok
/// [struct@char]
//~^ ERROR incompatible link
//~| HELP use its disambiguator
//~| NOTE resolved to a module
pub mod char {}
pub mod inner {
//! [struct@char]
//~^ ERROR incompatible link
//~| HELP use its disambiguator
//~| NOTE resolved to a builtin type
}

View file

@ -0,0 +1,53 @@
error: `char` is both a module and a builtin type
--> $DIR/intra-link-prim-conflict.rs:4:6
|
LL | /// [char]
| ^^^^ ambiguous link
|
note: the lint level is defined here
--> $DIR/intra-link-prim-conflict.rs:1:9
|
LL | #![deny(broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^
help: to link to the module, prefix with the item type
|
LL | /// [module@char]
| ^^^^^^^^^^^
help: to link to the builtin type, prefix with the item type
|
LL | /// [prim@char]
| ^^^^^^^^^
error: `char` is both a module and a builtin type
--> $DIR/intra-link-prim-conflict.rs:10:6
|
LL | /// [type@char]
| ^^^^^^^^^ ambiguous link
|
help: to link to the module, prefix with the item type
|
LL | /// [module@char]
| ^^^^^^^^^^^
help: to link to the builtin type, prefix with the item type
|
LL | /// [prim@char]
| ^^^^^^^^^
error: incompatible link kind for `char`
--> $DIR/intra-link-prim-conflict.rs:19:6
|
LL | /// [struct@char]
| ^^^^^^^^^^^ help: to link to the module, use its disambiguator: `mod@char`
|
= note: this link resolved to a module, which is not a struct
error: incompatible link kind for `char`
--> $DIR/intra-link-prim-conflict.rs:26:10
|
LL | //! [struct@char]
| ^^^^^^^^^^^ help: to link to the builtin type, use its disambiguator: `prim@char`
|
= note: this link resolved to a builtin type, which is not a struct
error: aborting due to 4 previous errors