forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an option not to report resolution errors for rustdoc
- Remove unnecessary `should_loop` variable - Report errors for trait implementations These should give resolution errors because they are visible outside the current scope. Without these errors, rustdoc will give ICEs: ``` thread 'rustc' panicked at 'attempted .def_id() on invalid res: Err', /home/joshua/src/rust/src/libstd/macros.rs:16:9 15: rustc_hir::def::Res<Id>::def_id at /home/joshua/src/rust/src/librustc_hir/def.rs:382 16: rustdoc::clean::utils::register_res at src/librustdoc/clean/utils.rs:627 17: rustdoc::clean::utils::resolve_type at src/librustdoc/clean/utils.rs:587 ``` - Add much more extensive tests + fn -> impl -> fn + fn -> impl -> fn -> macro + errors in function parameters + errors in trait bounds + errors in the type implementing the trait + unknown bounds for the type + unknown types in function bodies + errors generated by macros - Use explicit state instead of trying to reconstruct it from random info - Use an enum instead of a boolean - Add example of ignored error
- Loading branch information
Showing
6 changed files
with
201 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Ensure that rustdoc gives errors for trait impls inside function bodies that don't resolve. | ||
// See https://github.com/rust-lang/rust/pull/73566 | ||
pub struct ValidType; | ||
pub trait ValidTrait {} | ||
pub trait NeedsBody { | ||
type Item; | ||
fn f(); | ||
} | ||
|
||
/// This function has docs | ||
pub fn f<B: UnknownBound>(a: UnknownType, b: B) { | ||
//~^ ERROR cannot find trait `UnknownBound` in this scope | ||
//~| ERROR cannot find type `UnknownType` in this scope | ||
impl UnknownTrait for ValidType {} //~ ERROR cannot find trait `UnknownTrait` | ||
impl<T: UnknownBound> UnknownTrait for T {} | ||
//~^ ERROR cannot find trait `UnknownBound` in this scope | ||
//~| ERROR cannot find trait `UnknownTrait` in this scope | ||
impl ValidTrait for UnknownType {} | ||
//~^ ERROR cannot find type `UnknownType` in this scope | ||
impl ValidTrait for ValidType where ValidTrait: UnknownBound {} | ||
//~^ ERROR cannot find trait `UnknownBound` in this scope | ||
|
||
/// This impl has documentation | ||
impl NeedsBody for ValidType { | ||
type Item = UnknownType; | ||
//~^ ERROR cannot find type `UnknownType` in this scope | ||
|
||
/// This function has documentation | ||
fn f() { | ||
<UnknownTypeShouldBeIgnored>::a(); | ||
content::shouldnt::matter(); | ||
unknown_macro!(); | ||
//~^ ERROR cannot find macro `unknown_macro` in this scope | ||
|
||
/// This is documentation for a macro | ||
macro_rules! can_define_macros_here_too { | ||
() => { | ||
this::content::should::also::be::ignored() | ||
} | ||
} | ||
can_define_macros_here_too!(); | ||
|
||
/// This also is documented. | ||
pub fn doubly_nested(c: UnknownTypeShouldBeIgnored) { | ||
|
||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
error: cannot find macro `unknown_macro` in this scope | ||
--> $DIR/impl-fn-nesting.rs:32:13 | ||
| | ||
LL | unknown_macro!(); | ||
| ^^^^^^^^^^^^^ | ||
|
||
error[E0405]: cannot find trait `UnknownBound` in this scope | ||
--> $DIR/impl-fn-nesting.rs:11:13 | ||
| | ||
LL | pub fn f<B: UnknownBound>(a: UnknownType, b: B) { | ||
| ^^^^^^^^^^^^ not found in this scope | ||
|
||
error[E0412]: cannot find type `UnknownType` in this scope | ||
--> $DIR/impl-fn-nesting.rs:11:30 | ||
| | ||
LL | pub fn f<B: UnknownBound>(a: UnknownType, b: B) { | ||
| ^^^^^^^^^^^ not found in this scope | ||
|
||
error[E0405]: cannot find trait `UnknownTrait` in this scope | ||
--> $DIR/impl-fn-nesting.rs:14:10 | ||
| | ||
LL | impl UnknownTrait for ValidType {} | ||
| ^^^^^^^^^^^^ not found in this scope | ||
|
||
error[E0405]: cannot find trait `UnknownTrait` in this scope | ||
--> $DIR/impl-fn-nesting.rs:15:27 | ||
| | ||
LL | impl<T: UnknownBound> UnknownTrait for T {} | ||
| ^^^^^^^^^^^^ not found in this scope | ||
|
||
error[E0405]: cannot find trait `UnknownBound` in this scope | ||
--> $DIR/impl-fn-nesting.rs:15:13 | ||
| | ||
LL | impl<T: UnknownBound> UnknownTrait for T {} | ||
| ^^^^^^^^^^^^ not found in this scope | ||
|
||
error[E0412]: cannot find type `UnknownType` in this scope | ||
--> $DIR/impl-fn-nesting.rs:18:25 | ||
| | ||
LL | impl ValidTrait for UnknownType {} | ||
| ^^^^^^^^^^^ not found in this scope | ||
|
||
error[E0405]: cannot find trait `UnknownBound` in this scope | ||
--> $DIR/impl-fn-nesting.rs:20:53 | ||
| | ||
LL | impl ValidTrait for ValidType where ValidTrait: UnknownBound {} | ||
| ^^^^^^^^^^^^ not found in this scope | ||
|
||
error[E0412]: cannot find type `UnknownType` in this scope | ||
--> $DIR/impl-fn-nesting.rs:25:21 | ||
| | ||
LL | type Item = UnknownType; | ||
| ^^^^^^^^^^^ not found in this scope | ||
|
||
error: Compilation failed, aborting rustdoc | ||
|
||
error: aborting due to 10 previous errors | ||
|
||
Some errors have detailed explanations: E0405, E0412. | ||
For more information about an error, try `rustc --explain E0405`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters