Rollup merge of #106366 - GuillaumeGomez:fix-rustdoc-ice-typedef-type-mismatch, r=notriddle

Fix rustdoc ICE on bad typedef with mismatching types

Fixes https://github.com/rust-lang/rust/issues/106226.
Fixes #105742.
Fixes #105737.
Fixes #105334.
Fixes #96287.

In this case, it's ok to replace the panic with `rustc_error::raise` because the compiler provided us with a `Error`.

r? `@notriddle`
This commit is contained in:
Michael Goulet 2023-01-02 15:39:19 -08:00 committed by GitHub
commit ea3c4d8ddd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 497 additions and 1 deletions

View File

@ -1853,7 +1853,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
ty::Placeholder(..) => panic!("Placeholder"),
ty::GeneratorWitness(..) => panic!("GeneratorWitness"),
ty::Infer(..) => panic!("Infer"),
ty::Error(_) => panic!("Error"),
ty::Error(_) => rustc_errors::FatalError.raise(),
}
}

View File

@ -0,0 +1,2 @@
impl Vec< br##"*.."## > {}
//~^ ERROR

View File

@ -0,0 +1,9 @@
error[E0747]: constant provided when a type was expected
--> $DIR/issue-105334.rs:1:11
|
LL | impl Vec< br##"*.."## > {}
| ^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0747`.

View File

@ -0,0 +1,4 @@
impl Vec<lol> {}
//~^ ERROR
pub fn lol() {}

View File

@ -0,0 +1,12 @@
error[E0747]: constant provided when a type was expected
--> $DIR/issue-105737.rs:1:10
|
LL | impl Vec<lol> {}
| ^^^
|
= help: `lol` is a function item, not a type
= help: function item types cannot be named directly
error: aborting due to previous error
For more information about this error, try `rustc --explain E0747`.

View File

@ -0,0 +1,40 @@
// compile-flags: -Znormalize-docs
use std::ops::Index;
pub fn next<'a, T>(s: &'a mut dyn SVec<Item = T, Output = T>) {
//~^ ERROR
//~^^ ERROR
//~^^^ ERROR
let _ = s;
}
pub trait SVec: Index<
<Self as SVec>::Item,
//~^ ERROR
//~^^ ERROR
//~^^^ ERROR
//~^^^^ ERROR
Output = <Index<<Self as SVec>::Item,
//~^ ERROR
//~^^ ERROR
//~^^^ ERROR
//~^^^^ ERROR
Output = <Self as SVec>::Item> as SVec>::Item,
//~^ ERROR
//~^^ ERROR
//~^^^ ERROR
//~^^^^ ERROR
//~^^^^^ ERROR
//~^^^^^^ ERROR
//~^^^^^^^ ERROR
//~^^^^^^^^ ERROR
> {
type Item<'a, T>;
fn len(&self) -> <Self as SVec>::Item;
//~^ ERROR
//~^^ ERROR
//~^^^ ERROR
//~^^^^ ERROR
}

View File

@ -0,0 +1,385 @@
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:13:21
|
LL | <Self as SVec>::Item,
| ^^^^ expected 1 lifetime argument
|
note: associated type defined here, with 1 lifetime parameter: `'a`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ --
help: add missing lifetime argument
|
LL | <Self as SVec>::Item<'a>,
| ~~~~~~~~
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:13:21
|
LL | <Self as SVec>::Item,
| ^^^^ expected 1 generic argument
|
note: associated type defined here, with 1 generic parameter: `T`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ -
help: add missing generic argument
|
LL | <Self as SVec>::Item<T>,
| ~~~~~~~
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:18:37
|
LL | Output = <Index<<Self as SVec>::Item,
| ^^^^ expected 1 lifetime argument
|
note: associated type defined here, with 1 lifetime parameter: `'a`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ --
help: add missing lifetime argument
|
LL | Output = <Index<<Self as SVec>::Item<'a>,
| ~~~~~~~~
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:18:37
|
LL | Output = <Index<<Self as SVec>::Item,
| ^^^^ expected 1 generic argument
|
note: associated type defined here, with 1 generic parameter: `T`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ -
help: add missing generic argument
|
LL | Output = <Index<<Self as SVec>::Item<T>,
| ~~~~~~~
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:23:30
|
LL | Output = <Self as SVec>::Item> as SVec>::Item,
| ^^^^ expected 1 lifetime argument
|
note: associated type defined here, with 1 lifetime parameter: `'a`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ --
help: add missing lifetime argument
|
LL | Output = <Self as SVec>::Item<'a>> as SVec>::Item,
| ~~~~~~~~
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:23:30
|
LL | Output = <Self as SVec>::Item> as SVec>::Item,
| ^^^^ expected 1 generic argument
|
note: associated type defined here, with 1 generic parameter: `T`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ -
help: add missing generic argument
|
LL | Output = <Self as SVec>::Item<T>> as SVec>::Item,
| ~~~~~~~
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:23:46
|
LL | Output = <Self as SVec>::Item> as SVec>::Item,
| ^^^^ expected 1 lifetime argument
|
note: associated type defined here, with 1 lifetime parameter: `'a`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ --
help: add missing lifetime argument
|
LL | Output = <Self as SVec>::Item> as SVec>::Item<'a>,
| ~~~~~~~~
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:23:46
|
LL | Output = <Self as SVec>::Item> as SVec>::Item,
| ^^^^ expected 1 generic argument
|
note: associated type defined here, with 1 generic parameter: `T`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ -
help: add missing generic argument
|
LL | Output = <Self as SVec>::Item> as SVec>::Item<T>,
| ~~~~~~~
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:5:40
|
LL | pub fn next<'a, T>(s: &'a mut dyn SVec<Item = T, Output = T>) {
| ^^^^ expected 1 lifetime argument
|
note: associated type defined here, with 1 lifetime parameter: `'a`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ --
help: add missing lifetime argument
|
LL | pub fn next<'a, T>(s: &'a mut dyn SVec<Item<'_> = T, Output = T>) {
| ~~~~~~~~
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:5:40
|
LL | pub fn next<'a, T>(s: &'a mut dyn SVec<Item = T, Output = T>) {
| ^^^^ expected 1 generic argument
|
note: associated type defined here, with 1 generic parameter: `T`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ -
help: add missing generic argument
|
LL | pub fn next<'a, T>(s: &'a mut dyn SVec<Item<T> = T, Output = T>) {
| ~~~~~~~
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:13:21
|
LL | <Self as SVec>::Item,
| ^^^^ expected 1 lifetime argument
|
note: associated type defined here, with 1 lifetime parameter: `'a`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ --
help: add missing lifetime argument
|
LL | <Self as SVec>::Item<'a>,
| ~~~~~~~~
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:13:21
|
LL | <Self as SVec>::Item,
| ^^^^ expected 1 generic argument
|
note: associated type defined here, with 1 generic parameter: `T`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ -
help: add missing generic argument
|
LL | <Self as SVec>::Item<T>,
| ~~~~~~~
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:18:37
|
LL | Output = <Index<<Self as SVec>::Item,
| ^^^^ expected 1 lifetime argument
|
note: associated type defined here, with 1 lifetime parameter: `'a`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ --
help: add missing lifetime argument
|
LL | Output = <Index<<Self as SVec>::Item<'a>,
| ~~~~~~~~
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:18:37
|
LL | Output = <Index<<Self as SVec>::Item,
| ^^^^ expected 1 generic argument
|
note: associated type defined here, with 1 generic parameter: `T`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ -
help: add missing generic argument
|
LL | Output = <Index<<Self as SVec>::Item<T>,
| ~~~~~~~
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:23:30
|
LL | Output = <Self as SVec>::Item> as SVec>::Item,
| ^^^^ expected 1 lifetime argument
|
note: associated type defined here, with 1 lifetime parameter: `'a`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ --
help: add missing lifetime argument
|
LL | Output = <Self as SVec>::Item<'a>> as SVec>::Item,
| ~~~~~~~~
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:23:30
|
LL | Output = <Self as SVec>::Item> as SVec>::Item,
| ^^^^ expected 1 generic argument
|
note: associated type defined here, with 1 generic parameter: `T`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ -
help: add missing generic argument
|
LL | Output = <Self as SVec>::Item<T>> as SVec>::Item,
| ~~~~~~~
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:23:46
|
LL | Output = <Self as SVec>::Item> as SVec>::Item,
| ^^^^ expected 1 lifetime argument
|
note: associated type defined here, with 1 lifetime parameter: `'a`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ --
help: add missing lifetime argument
|
LL | Output = <Self as SVec>::Item> as SVec>::Item<'a>,
| ~~~~~~~~
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:23:46
|
LL | Output = <Self as SVec>::Item> as SVec>::Item,
| ^^^^ expected 1 generic argument
|
note: associated type defined here, with 1 generic parameter: `T`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ -
help: add missing generic argument
|
LL | Output = <Self as SVec>::Item> as SVec>::Item<T>,
| ~~~~~~~
error[E0038]: the trait `SVec` cannot be made into an object
--> $DIR/issue-105742.rs:5:31
|
LL | pub fn next<'a, T>(s: &'a mut dyn SVec<Item = T, Output = T>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `SVec` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/issue-105742.rs:12:17
|
LL | pub trait SVec: Index<
| ____________----__^
| | |
| | this trait cannot be made into an object...
LL | | <Self as SVec>::Item,
LL | |
LL | |
... |
LL | |/ Output = <Index<<Self as SVec>::Item,
LL | ||
LL | ||
LL | ||
LL | ||
LL | || Output = <Self as SVec>::Item> as SVec>::Item,
| ||_________________________________________________^ ...because it uses `Self` as a type parameter
... |
LL | |
LL | | > {
| |__^ ...because it uses `Self` as a type parameter
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:35:38
|
LL | fn len(&self) -> <Self as SVec>::Item;
| ^^^^ expected 1 lifetime argument
|
note: associated type defined here, with 1 lifetime parameter: `'a`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ --
help: add missing lifetime argument
|
LL | fn len(&self) -> <Self as SVec>::Item<'_>;
| ~~~~~~~~
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:35:38
|
LL | fn len(&self) -> <Self as SVec>::Item;
| ^^^^ expected 1 generic argument
|
note: associated type defined here, with 1 generic parameter: `T`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ -
help: add missing generic argument
|
LL | fn len(&self) -> <Self as SVec>::Item<T>;
| ~~~~~~~
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:35:38
|
LL | fn len(&self) -> <Self as SVec>::Item;
| ^^^^ expected 1 lifetime argument
|
note: associated type defined here, with 1 lifetime parameter: `'a`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ --
help: add missing lifetime argument
|
LL | fn len(&self) -> <Self as SVec>::Item<'_>;
| ~~~~~~~~
error[E0107]: missing generics for associated type `SVec::Item`
--> $DIR/issue-105742.rs:35:38
|
LL | fn len(&self) -> <Self as SVec>::Item;
| ^^^^ expected 1 generic argument
|
note: associated type defined here, with 1 generic parameter: `T`
--> $DIR/issue-105742.rs:33:10
|
LL | type Item<'a, T>;
| ^^^^ -
help: add missing generic argument
|
LL | fn len(&self) -> <Self as SVec>::Item<T>;
| ~~~~~~~
error: aborting due to 23 previous errors
Some errors have detailed explanations: E0038, E0107.
For more information about an error, try `rustc --explain E0038`.

View File

@ -0,0 +1,3 @@
// This is a regression test for <https://github.com/rust-lang/rust/issues/106226>.
type F = [_; ()];
//~^ ERROR

View File

@ -0,0 +1,9 @@
error[E0308]: mismatched types
--> $DIR/issue-106226.rs:2:14
|
LL | type F = [_; ()];
| ^^ expected `usize`, found `()`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.

View File

@ -0,0 +1,17 @@
#![feature(type_alias_impl_trait)]
pub trait TraitWithAssoc {
type Assoc;
}
pub type Foo<V> = impl Trait<V::Assoc>;
//~^ ERROR
//~^^ ERROR
pub trait Trait<U> {}
impl<W> Trait<W> for () {}
pub fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T> {
()
}

View File

@ -0,0 +1,15 @@
error[E0220]: associated type `Assoc` not found for `V`
--> $DIR/issue-96287.rs:7:33
|
LL | pub type Foo<V> = impl Trait<V::Assoc>;
| ^^^^^ there is a similarly named associated type `Assoc` in the trait `TraitWithAssoc`
error[E0220]: associated type `Assoc` not found for `V`
--> $DIR/issue-96287.rs:7:33
|
LL | pub type Foo<V> = impl Trait<V::Assoc>;
| ^^^^^ there is a similarly named associated type `Assoc` in the trait `TraitWithAssoc`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0220`.