Skip to content

Commit 9b5115f

Browse files
committed
rustdoc: run more HIR validation to mirror rustc
1 parent 8a7ca93 commit 9b5115f

15 files changed

+146
-0
lines changed

src/librustdoc/core.rs

Lines changed: 3 additions & 0 deletions
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", || {
Lines changed: 6 additions & 0 deletions
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+
}
Lines changed: 9 additions & 0 deletions
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`.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
static CONST: Option<dyn Fn(& _)> = None;
2+
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for static items [E0121]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items
2+
--> $DIR/invalid-toplevel-const.rs:2:31
3+
|
4+
LL | static CONST: Option<dyn Fn(& _)> = None;
5+
| ^ not allowed in type signatures
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0121`.
Lines changed: 10 additions & 0 deletions
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+
}
Lines changed: 9 additions & 0 deletions
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`.
Lines changed: 6 additions & 0 deletions
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
Lines changed: 33 additions & 0 deletions
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`.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
use std::ops::Generator;
2+
3+
fn gen() -> impl Generator<{}> {}
4+
//~^ERROR constant provided when a type was expected
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0747]: constant provided when a type was expected
2+
--> $DIR/invalid_const_in_type_position.rs:3:28
3+
|
4+
LL | fn gen() -> impl Generator<{}> {}
5+
| ^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0747`.
Lines changed: 2 additions & 0 deletions
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
Lines changed: 15 additions & 0 deletions
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`.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// ensures that we don't ICE when there are too many args supplied to the alias.
2+
3+
trait Trait<'a> {
4+
type Assoc;
5+
}
6+
7+
type Alias<'a, T> = <T as Trait<'a>>::Assoc;
8+
9+
fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {}
10+
//~^ error: type alias takes 1 lifetime argument but 2 lifetime arguments were supplied
11+
12+
fn main() {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0107]: type alias takes 1 lifetime argument but 2 lifetime arguments were supplied
2+
--> $DIR/mismatched_arg_count.rs:9:29
3+
|
4+
LL | fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {}
5+
| ^^^^^ -- help: remove this lifetime argument
6+
| |
7+
| expected 1 lifetime argument
8+
|
9+
note: type alias defined here, with 1 lifetime parameter: `'a`
10+
--> $DIR/mismatched_arg_count.rs:7:6
11+
|
12+
LL | type Alias<'a, T> = <T as Trait<'a>>::Assoc;
13+
| ^^^^^ --
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0107`.

0 commit comments

Comments
 (0)