Skip to content

Commit 789ee5e

Browse files
committed
Auto merge of rust-lang#108576 - megakorre:rustdock_additional_typecheck_before_clean, r=GuillaumeGomez
rustdoc: run more HIR validation to mirror rustc # Explanation While investigating these issues: rust-lang#107093, rust-lang#106079 I thought it maybe would be useful to test running `rustdoc` on all rust files under `tests/ui` grepping for files that causes any ICEs. And these are the files I found would cause ICEs. ``` // These are handled by this fix. tests/ui/late-bound-lifetimes/mismatched_arg_count.rs tests/ui/associated-consts/issue-102335-const.rs tests/ui/const-generics/generic_const_exprs/issue-102768.rs tests/ui/const-generics/const-arg-type-arg-misordered.rs tests/ui/generic-associated-types/parse/trait-path-type-error-once-implemented.rs tests/ui/typeck/issue-88643.rs tests/ui/typeck/issue-75889.rs tests/ui/typeck/issue-83621-placeholder-static-in-extern.rs // These are not they will still produce a ICE after this change tests/ui/limits/issue-56762.rs tests/ui/union/projection-as-union-type-error-2.rs tests/ui/union/projection-as-union-type-error.rs ``` I reduces the issues handled by this PR down to the tests added in the PR. That includes the linked issues. But the 3 files that are not handled I will leave for a future PR. This PR adds the `type_collecting` step from `hir_analysis::check_crate` to the rustdoc typechecks. It had the following comment on it. ``` // this ensures that later parts of type checking can assume that items // have valid types and not error ``` Adding the check report the same errors as rustc does for these input. And not ICE when the lint checker walks the HIR or when in the `rustdoc::clean` pass. This PR updates the expected errors of some existing rustdoc-ui tests (some now report less errors). These new reported errors does mirror the errors reported by rustc. # Performance It does more checking so it will probably regress. We should run ``@bors` try `@rust-timer` queue` and see. # Discussion Maybe instead of calling a subset of the checks in `hir_analysis::check_crate` and having comments that say they should be kept in sync. We could instead call `check_crate` directly and pass in some flag. Maybe `check_toplevel_signatures_only` or something like that. That flag would have to skip most of the checks in that function tough.
2 parents 516a6d3 + 1f9e2d0 commit 789ee5e

18 files changed

+483
-29
lines changed

src/librustdoc/core.rs

+3
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ pub(crate) fn run_global_ctxt(
303303

304304
// HACK(jynelson) this calls an _extremely_ limited subset of `typeck`
305305
// and might break if queries change their assumptions in the future.
306+
tcx.sess.time("type_collecting", || {
307+
tcx.hir().for_each_module(|module| tcx.ensure().collect_mod_item_types(module))
308+
});
306309

307310
// NOTE: This is copy/pasted from typeck/lib.rs and should be kept in sync with those changes.
308311
tcx.sess.time("item_types_checking", || {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type Array<T, const N: usize> = [T; N];
2+
3+
fn foo<const N: usize>() -> Array<N, ()> {
4+
//~^ ERROR constant provided when a type was expected
5+
unimplemented!()
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0747]: constant provided when a type was expected
2+
--> $DIR/const_arg_in_type_position.rs:3:35
3+
|
4+
LL | fn foo<const N: usize>() -> Array<N, ()> {
5+
| ^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0747`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(associated_const_equality)]
2+
3+
trait T {
4+
type A: S<C<X = 0i32> = 34>;
5+
//~^ ERROR associated type bindings are not allowed here
6+
}
7+
8+
trait S {
9+
const C: i32;
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0229]: associated type bindings are not allowed here
2+
--> $DIR/invalid_associated_const.rs:4:17
3+
|
4+
LL | type A: S<C<X = 0i32> = 34>;
5+
| ^^^^^^^^ associated type not allowed here
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0229`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
trait X {
2+
type Y<'a>;
3+
}
4+
fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
5+
//~^ ERROR associated type takes 1 lifetime argument but 0 lifetime arguments
6+
//~| ERROR associated type takes 0 generic arguments but 1 generic argument
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
2+
--> $DIR/invalid_const_in_lifetime_position.rs:4:26
3+
|
4+
LL | fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
5+
| ^ expected 1 lifetime argument
6+
|
7+
note: associated type defined here, with 1 lifetime parameter: `'a`
8+
--> $DIR/invalid_const_in_lifetime_position.rs:2:10
9+
|
10+
LL | type Y<'a>;
11+
| ^ --
12+
help: add missing lifetime argument
13+
|
14+
LL | fn f<'a>(arg : Box<dyn X<Y<'_, 1> = &'a ()>>) {}
15+
| +++
16+
17+
error[E0107]: associated type takes 0 generic arguments but 1 generic argument was supplied
18+
--> $DIR/invalid_const_in_lifetime_position.rs:4:26
19+
|
20+
LL | fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
21+
| ^--- help: remove these generics
22+
| |
23+
| expected 0 generic arguments
24+
|
25+
note: associated type defined here, with 0 generic parameters
26+
--> $DIR/invalid_const_in_lifetime_position.rs:2:10
27+
|
28+
LL | type Y<'a>;
29+
| ^
30+
31+
error: aborting due to 2 previous errors
32+
33+
For more information about this error, try `rustc --explain E0107`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const FOO: dyn Fn() -> _ = ""; //~ ERROR E0121
2+
static BOO: dyn Fn() -> _ = ""; //~ ERROR E0121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items
2+
--> $DIR/invalid_infered_static_and_const.rs:1:24
3+
|
4+
LL | const FOO: dyn Fn() -> _ = "";
5+
| ^ not allowed in type signatures
6+
7+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items
8+
--> $DIR/invalid_infered_static_and_const.rs:2:25
9+
|
10+
LL | static BOO: dyn Fn() -> _ = "";
11+
| ^ not allowed in type signatures
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0121`.

tests/rustdoc-ui/issue-105742.rs

+34-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,50 @@
11
// compile-flags: -Znormalize-docs
2-
32
use std::ops::Index;
43

54
pub fn next<'a, T>(s: &'a mut dyn SVec<Item = T, Output = T>) {
5+
//~^ expected 1 lifetime argument
6+
//~| expected 1 generic argument
7+
//~| the trait `SVec` cannot be made into an object
8+
//~| `SVec` cannot be made into an object
9+
//~| missing generics for associated type `SVec::Item`
10+
//~| missing generics for associated type `SVec::Item`
611
let _ = s;
712
}
813

914
pub trait SVec: Index<
1015
<Self as SVec>::Item,
16+
//~^ expected 1 lifetime argument
17+
//~| expected 1 generic argument
18+
//~| missing generics for associated type `SVec::Item`
19+
//~| missing generics for associated type `SVec::Item`
20+
//~| missing generics for associated type `SVec::Item`
21+
//~| missing generics for associated type `SVec::Item`
1122
Output = <Index<<Self as SVec>::Item,
23+
//~^ expected 1 lifetime argument
24+
//~| expected 1 generic argument
25+
//~| missing generics for associated type `SVec::Item`
26+
//~| missing generics for associated type `SVec::Item`
27+
//~| missing generics for associated type `SVec::Item`
28+
//~| missing generics for associated type `SVec::Item`
1229
Output = <Self as SVec>::Item> as SVec>::Item,
30+
//~^ expected 1 lifetime argument
31+
//~| expected 1 generic argument
32+
//~| expected 1 lifetime argument
33+
//~| missing generics for associated type `SVec::Item`
34+
//~| missing generics for associated type `SVec::Item`
35+
//~| missing generics for associated type `SVec::Item`
36+
//~| missing generics for associated type `SVec::Item`
37+
//~| expected 1 generic argument
38+
//~| missing generics for associated type `SVec::Item`
39+
//~| missing generics for associated type `SVec::Item`
40+
//~| missing generics for associated type `SVec::Item`
41+
//~| missing generics for associated type `SVec::Item`
1342
> {
1443
type Item<'a, T>;
1544

1645
fn len(&self) -> <Self as SVec>::Item;
17-
//~^ ERROR
18-
//~^^ ERROR
46+
//~^ expected 1 lifetime argument
47+
//~| missing generics for associated type `SVec::Item`
48+
//~| expected 1 generic argument
49+
//~| missing generics for associated type `SVec::Item`
1950
}

0 commit comments

Comments
 (0)