Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: run more HIR validation to mirror rustc #108576

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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", || {
Expand Down
6 changes: 6 additions & 0 deletions tests/rustdoc-ui/const_arg_in_type_position.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions tests/rustdoc-ui/const_arg_in_type_position.stderr
Original file line number Diff line number Diff line change
@@ -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`.
10 changes: 10 additions & 0 deletions tests/rustdoc-ui/invalid_associated_const.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 0 deletions tests/rustdoc-ui/invalid_associated_const.stderr
Original file line number Diff line number Diff line change
@@ -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 changes: 6 additions & 0 deletions tests/rustdoc-ui/invalid_const_in_lifetime_position.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 33 additions & 0 deletions tests/rustdoc-ui/invalid_const_in_lifetime_position.stderr
Original file line number Diff line number Diff line change
@@ -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`.
2 changes: 2 additions & 0 deletions tests/rustdoc-ui/invalid_infered_static_and_const.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const FOO: dyn Fn() -> _ = ""; //~ ERROR E0121
static BOO: dyn Fn() -> _ = ""; //~ ERROR E0121
15 changes: 15 additions & 0 deletions tests/rustdoc-ui/invalid_infered_static_and_const.stderr
Original file line number Diff line number Diff line change
@@ -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`.
37 changes: 34 additions & 3 deletions tests/rustdoc-ui/issue-105742.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,50 @@
// compile-flags: -Znormalize-docs

use std::ops::Index;

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

pub trait SVec: Index<
<Self as SVec>::Item,
//~^ expected 1 lifetime argument
//~| expected 1 generic argument
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
Output = <Index<<Self as SVec>::Item,
//~^ expected 1 lifetime argument
//~| expected 1 generic argument
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
Output = <Self as SVec>::Item> as SVec>::Item,
//~^ expected 1 lifetime argument
//~| expected 1 generic argument
//~| expected 1 lifetime argument
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| expected 1 generic argument
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
> {
type Item<'a, T>;

fn len(&self) -> <Self as SVec>::Item;
//~^ ERROR
//~^^ ERROR
//~^ expected 1 lifetime argument
//~| missing generics for associated type `SVec::Item`
//~| expected 1 generic argument
//~| missing generics for associated type `SVec::Item`
}
Loading