rustdoc: run more HIR validation to mirror rustc
This commit is contained in:
parent
8a7ca936e6
commit
9b5115f92b
@ -303,6 +303,9 @@ pub(crate) fn run_global_ctxt(
|
||||
|
||||
// HACK(jynelson) this calls an _extremely_ limited subset of `typeck`
|
||||
// and might break if queries change their assumptions in the future.
|
||||
tcx.sess.time("type_collecting", || {
|
||||
tcx.hir().for_each_module(|module| tcx.ensure().collect_mod_item_types(module))
|
||||
});
|
||||
|
||||
// NOTE: This is copy/pasted from typeck/lib.rs and should be kept in sync with those changes.
|
||||
tcx.sess.time("item_types_checking", || {
|
||||
|
6
tests/rustdoc-ui/const_arg_in_type_position.rs
Normal file
6
tests/rustdoc-ui/const_arg_in_type_position.rs
Normal file
@ -0,0 +1,6 @@
|
||||
type Array<T, const N: usize> = [T; N];
|
||||
|
||||
fn foo<const N: usize>() -> Array<N, ()> {
|
||||
//~^ ERROR constant provided when a type was expected
|
||||
unimplemented!()
|
||||
}
|
9
tests/rustdoc-ui/const_arg_in_type_position.stderr
Normal file
9
tests/rustdoc-ui/const_arg_in_type_position.stderr
Normal file
@ -0,0 +1,9 @@
|
||||
error[E0747]: constant provided when a type was expected
|
||||
--> $DIR/const_arg_in_type_position.rs:3:35
|
||||
|
|
||||
LL | fn foo<const N: usize>() -> Array<N, ()> {
|
||||
| ^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0747`.
|
2
tests/rustdoc-ui/invalid-toplevel-const.rs
Normal file
2
tests/rustdoc-ui/invalid-toplevel-const.rs
Normal file
@ -0,0 +1,2 @@
|
||||
static CONST: Option<dyn Fn(& _)> = None;
|
||||
//~^ ERROR: the placeholder `_` is not allowed within types on item signatures for static items [E0121]
|
9
tests/rustdoc-ui/invalid-toplevel-const.stderr
Normal file
9
tests/rustdoc-ui/invalid-toplevel-const.stderr
Normal file
@ -0,0 +1,9 @@
|
||||
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items
|
||||
--> $DIR/invalid-toplevel-const.rs:2:31
|
||||
|
|
||||
LL | static CONST: Option<dyn Fn(& _)> = None;
|
||||
| ^ not allowed in type signatures
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0121`.
|
10
tests/rustdoc-ui/invalid_associated_const.rs
Normal file
10
tests/rustdoc-ui/invalid_associated_const.rs
Normal file
@ -0,0 +1,10 @@
|
||||
#![feature(associated_const_equality)]
|
||||
|
||||
trait T {
|
||||
type A: S<C<X = 0i32> = 34>;
|
||||
//~^ ERROR associated type bindings are not allowed here
|
||||
}
|
||||
|
||||
trait S {
|
||||
const C: i32;
|
||||
}
|
9
tests/rustdoc-ui/invalid_associated_const.stderr
Normal file
9
tests/rustdoc-ui/invalid_associated_const.stderr
Normal file
@ -0,0 +1,9 @@
|
||||
error[E0229]: associated type bindings are not allowed here
|
||||
--> $DIR/invalid_associated_const.rs:4:17
|
||||
|
|
||||
LL | type A: S<C<X = 0i32> = 34>;
|
||||
| ^^^^^^^^ associated type not allowed here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0229`.
|
6
tests/rustdoc-ui/invalid_const_in_lifetime_position.rs
Normal file
6
tests/rustdoc-ui/invalid_const_in_lifetime_position.rs
Normal file
@ -0,0 +1,6 @@
|
||||
trait X {
|
||||
type Y<'a>;
|
||||
}
|
||||
fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
|
||||
//~^ ERROR associated type takes 1 lifetime argument but 0 lifetime arguments
|
||||
//~| ERROR associated type takes 0 generic arguments but 1 generic argument
|
33
tests/rustdoc-ui/invalid_const_in_lifetime_position.stderr
Normal file
33
tests/rustdoc-ui/invalid_const_in_lifetime_position.stderr
Normal file
@ -0,0 +1,33 @@
|
||||
error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
|
||||
--> $DIR/invalid_const_in_lifetime_position.rs:4:26
|
||||
|
|
||||
LL | fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
|
||||
| ^ expected 1 lifetime argument
|
||||
|
|
||||
note: associated type defined here, with 1 lifetime parameter: `'a`
|
||||
--> $DIR/invalid_const_in_lifetime_position.rs:2:10
|
||||
|
|
||||
LL | type Y<'a>;
|
||||
| ^ --
|
||||
help: add missing lifetime argument
|
||||
|
|
||||
LL | fn f<'a>(arg : Box<dyn X<Y<'_, 1> = &'a ()>>) {}
|
||||
| +++
|
||||
|
||||
error[E0107]: associated type takes 0 generic arguments but 1 generic argument was supplied
|
||||
--> $DIR/invalid_const_in_lifetime_position.rs:4:26
|
||||
|
|
||||
LL | fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
|
||||
| ^--- help: remove these generics
|
||||
| |
|
||||
| expected 0 generic arguments
|
||||
|
|
||||
note: associated type defined here, with 0 generic parameters
|
||||
--> $DIR/invalid_const_in_lifetime_position.rs:2:10
|
||||
|
|
||||
LL | type Y<'a>;
|
||||
| ^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0107`.
|
4
tests/rustdoc-ui/invalid_const_in_type_position.rs
Normal file
4
tests/rustdoc-ui/invalid_const_in_type_position.rs
Normal file
@ -0,0 +1,4 @@
|
||||
use std::ops::Generator;
|
||||
|
||||
fn gen() -> impl Generator<{}> {}
|
||||
//~^ERROR constant provided when a type was expected
|
9
tests/rustdoc-ui/invalid_const_in_type_position.stderr
Normal file
9
tests/rustdoc-ui/invalid_const_in_type_position.stderr
Normal file
@ -0,0 +1,9 @@
|
||||
error[E0747]: constant provided when a type was expected
|
||||
--> $DIR/invalid_const_in_type_position.rs:3:28
|
||||
|
|
||||
LL | fn gen() -> impl Generator<{}> {}
|
||||
| ^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0747`.
|
2
tests/rustdoc-ui/invalid_infered_static_and_const.rs
Normal file
2
tests/rustdoc-ui/invalid_infered_static_and_const.rs
Normal file
@ -0,0 +1,2 @@
|
||||
const FOO: dyn Fn() -> _ = ""; //~ ERROR E0121
|
||||
static BOO: dyn Fn() -> _ = ""; //~ ERROR E0121
|
15
tests/rustdoc-ui/invalid_infered_static_and_const.stderr
Normal file
15
tests/rustdoc-ui/invalid_infered_static_and_const.stderr
Normal file
@ -0,0 +1,15 @@
|
||||
error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items
|
||||
--> $DIR/invalid_infered_static_and_const.rs:1:24
|
||||
|
|
||||
LL | const FOO: dyn Fn() -> _ = "";
|
||||
| ^ not allowed in type signatures
|
||||
|
||||
error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items
|
||||
--> $DIR/invalid_infered_static_and_const.rs:2:25
|
||||
|
|
||||
LL | static BOO: dyn Fn() -> _ = "";
|
||||
| ^ not allowed in type signatures
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0121`.
|
12
tests/rustdoc-ui/mismatched_arg_count.rs
Normal file
12
tests/rustdoc-ui/mismatched_arg_count.rs
Normal file
@ -0,0 +1,12 @@
|
||||
// ensures that we don't ICE when there are too many args supplied to the alias.
|
||||
|
||||
trait Trait<'a> {
|
||||
type Assoc;
|
||||
}
|
||||
|
||||
type Alias<'a, T> = <T as Trait<'a>>::Assoc;
|
||||
|
||||
fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {}
|
||||
//~^ error: type alias takes 1 lifetime argument but 2 lifetime arguments were supplied
|
||||
|
||||
fn main() {}
|
17
tests/rustdoc-ui/mismatched_arg_count.stderr
Normal file
17
tests/rustdoc-ui/mismatched_arg_count.stderr
Normal file
@ -0,0 +1,17 @@
|
||||
error[E0107]: type alias takes 1 lifetime argument but 2 lifetime arguments were supplied
|
||||
--> $DIR/mismatched_arg_count.rs:9:29
|
||||
|
|
||||
LL | fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {}
|
||||
| ^^^^^ -- help: remove this lifetime argument
|
||||
| |
|
||||
| expected 1 lifetime argument
|
||||
|
|
||||
note: type alias defined here, with 1 lifetime parameter: `'a`
|
||||
--> $DIR/mismatched_arg_count.rs:7:6
|
||||
|
|
||||
LL | type Alias<'a, T> = <T as Trait<'a>>::Assoc;
|
||||
| ^^^^^ --
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0107`.
|
Loading…
Reference in New Issue
Block a user