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

add more ice tests #122863

Merged
merged 7 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// test for ICE "no entry found for key" in generics_of.rs #113017

#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

pub fn String<V>(elem)
//~^ ERROR expected one of `:`, `@`, or `|`, found `)`
where
V: 'a,
//~^ ERROR use of undeclared lifetime name `'a`
for<const N: usize = { || {}}> V: 'a,
//~^ ERROR use of undeclared lifetime name `'a`
//~^^ ERROR only lifetime parameters can be used in this context
//~^^^ ERROR defaults for generic parameters are not allowed in `for<...>` binders
for<C2: , R2, R3: > <&str as IntoIterator>::Item: 'static,
//~^ ERROR `&` without an explicit lifetime name cannot be used here
//~^^ ERROR only lifetime parameters can be used in this context
{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expecct that this file is still not minimized for this ICE
and believe that most of the syntax issues don't contribute to the ICE and make it more likely this tests ends up being ineffective once we change the way we handle such errors when continuing compilation.

It would be nice to manually spend a few minutes trying to fix all unrelated errors while tracking whether the ICE still triggers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well what you call "syntax issues" I call "additional coverage" 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what I mean is, we want tests to also protect against future ICEs and minimizing everything to the absolute minimum just reduces the effectiveness in that regard

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll use the example from #113017 (comment)


pub fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
error: expected one of `:`, `@`, or `|`, found `)`
--> $DIR/ice-generics_of-no-entry-found-for-key-113017.rs:6:22
|
LL | pub fn String<V>(elem)
| ^ expected one of `:`, `@`, or `|`
|
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
help: if this is a `self` type, give it a parameter name
|
LL | pub fn String<V>(self: elem)
| +++++
help: if this is a parameter name, give it a type
|
LL | pub fn String<V>(elem: TypeName)
| ++++++++++
help: if this is a type, explicitly ignore the parameter name
|
LL | pub fn String<V>(_: elem)
| ++

error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/ice-generics_of-no-entry-found-for-key-113017.rs:9:8
|
LL | V: 'a,
| ^^ undeclared lifetime
|
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the bound lifetime-generic with a new `'a` lifetime
|
LL | for<'a> V: 'a,
| +++++++
help: consider introducing lifetime `'a` here
|
LL | pub fn String<'a, V>(elem)
| +++

error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/ice-generics_of-no-entry-found-for-key-113017.rs:11:39
|
LL | for<const N: usize = { || {}}> V: 'a,
| ^^ undeclared lifetime
|
help: consider making the bound lifetime-generic with a new `'a` lifetime
|
LL | for<'a, const N: usize = { || {}}> V: 'a,
| +++
help: consider introducing lifetime `'a` here
|
LL | pub fn String<'a, V>(elem)
| +++

error[E0637]: `&` without an explicit lifetime name cannot be used here
--> $DIR/ice-generics_of-no-entry-found-for-key-113017.rs:15:26
|
LL | for<C2: , R2, R3: > <&str as IntoIterator>::Item: 'static,
| ^ explicit lifetime name needed here
|
help: consider introducing a higher-ranked lifetime here
|
LL | for<'a> for<C2: , R2, R3: > <&'a str as IntoIterator>::Item: 'static,
| +++++++ ++

error[E0658]: only lifetime parameters can be used in this context
--> $DIR/ice-generics_of-no-entry-found-for-key-113017.rs:11:15
|
LL | for<const N: usize = { || {}}> V: 'a,
| ^
|
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
= help: add `#![feature(non_lifetime_binders)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0658]: only lifetime parameters can be used in this context
--> $DIR/ice-generics_of-no-entry-found-for-key-113017.rs:15:9
|
LL | for<C2: , R2, R3: > <&str as IntoIterator>::Item: 'static,
| ^^ ^^ ^^
|
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
= help: add `#![feature(non_lifetime_binders)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: defaults for generic parameters are not allowed in `for<...>` binders
--> $DIR/ice-generics_of-no-entry-found-for-key-113017.rs:11:9
|
LL | for<const N: usize = { || {}}> V: 'a,
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 7 previous errors

Some errors have detailed explanations: E0261, E0637, E0658.
For more information about an error, try `rustc --explain E0261`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// test for ICE #119275 "no entry found for key" in predicates_of.rs

#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

fn bug<const N: Nat>(&self)
//~^ ERROR `self` parameter is only allowed in associated functions
//~^^ ERROR cannot find type `Nat` in this scope
where
for<const N: usize = 3, T = u32> [(); COT::BYTES]:,
//~^ ERROR only lifetime parameters can be used in this context
//~^^ ERROR defaults for generic parameters are not allowed in `for<...>` binders
//~^^^ ERROR defaults for generic parameters are not allowed in `for<...>` binders
//~^^^^ ERROR failed to resolve: use of undeclared type `COT`
{
}

pub fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
error: `self` parameter is only allowed in associated functions
--> $DIR/ice-predicates-of-no-entry-found-for-key-119275.rs:6:22
|
LL | fn bug<const N: Nat>(&self)
| ^^^^^ not semantically valid as function parameter
|
= note: associated functions are those in `impl` or `trait` definitions

error[E0412]: cannot find type `Nat` in this scope
--> $DIR/ice-predicates-of-no-entry-found-for-key-119275.rs:6:17
|
LL | fn bug<const N: Nat>(&self)
| ^^^ not found in this scope

error[E0658]: only lifetime parameters can be used in this context
--> $DIR/ice-predicates-of-no-entry-found-for-key-119275.rs:10:15
|
LL | for<const N: usize = 3, T = u32> [(); COT::BYTES]:,
| ^ ^
|
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
= help: add `#![feature(non_lifetime_binders)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: defaults for generic parameters are not allowed in `for<...>` binders
--> $DIR/ice-predicates-of-no-entry-found-for-key-119275.rs:10:9
|
LL | for<const N: usize = 3, T = u32> [(); COT::BYTES]:,
| ^^^^^^^^^^^^^^^^^^

error: defaults for generic parameters are not allowed in `for<...>` binders
--> $DIR/ice-predicates-of-no-entry-found-for-key-119275.rs:10:29
|
LL | for<const N: usize = 3, T = u32> [(); COT::BYTES]:,
| ^^^^^^^

error[E0433]: failed to resolve: use of undeclared type `COT`
--> $DIR/ice-predicates-of-no-entry-found-for-key-119275.rs:10:43
|
LL | for<const N: usize = 3, T = u32> [(); COT::BYTES]:,
| ^^^ use of undeclared type `COT`

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0412, E0433, E0658.
For more information about an error, try `rustc --explain E0412`.
20 changes: 20 additions & 0 deletions tests/ui/const_prop/ice-type-mismatch-when-copying-112824.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// test for #112824 ICE type mismatching when copying!

pub struct Opcode(pub u8);

pub struct Opcode2(&'a S);
//~^ ERROR use of undeclared lifetime name `'a`
//~^^ ERROR cannot find type `S` in this scope

impl Opcode2 {
pub const OP2: Opcode2 = Opcode2(Opcode(0x1));
}

pub fn example2(msg_type: Opcode2) -> impl FnMut(&[u8]) {
move |i| match msg_type {
Opcode2::OP2 => unimplemented!(),
//~^ ERROR could not evaluate constant pattern
}
}

pub fn main() {}
29 changes: 29 additions & 0 deletions tests/ui/const_prop/ice-type-mismatch-when-copying-112824.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/ice-type-mismatch-when-copying-112824.rs:5:21
|
LL | pub struct Opcode2(&'a S);
| - ^^ undeclared lifetime
| |
| help: consider introducing lifetime `'a` here: `<'a>`

error[E0412]: cannot find type `S` in this scope
--> $DIR/ice-type-mismatch-when-copying-112824.rs:5:24
|
LL | pub struct Opcode2(&'a S);
| ^ not found in this scope
|
help: you might be missing a type parameter
|
LL | pub struct Opcode2<S>(&'a S);
| +++

error: could not evaluate constant pattern
--> $DIR/ice-type-mismatch-when-copying-112824.rs:15:9
|
LL | Opcode2::OP2 => unimplemented!(),
| ^^^^^^^^^^^^

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0261, E0412.
For more information about an error, try `rustc --explain E0261`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// test for ICE #112823
// Unexpected parameter Type(Repr) when substituting in region

#![feature(impl_trait_in_assoc_type)]

use std::future::Future;

trait Stream {}

trait X {
type LineStream<'a, Repr>
where
Self: 'a;
type LineStreamFut<'a, Repr>
where
Self: 'a;
}

struct Y;

impl X for Y {
type LineStream<'c, 'd> = impl Stream;
//~^ ERROR type `LineStream` has 0 type parameters but its trait declaration has 1 type parameter
type LineStreamFut<'a, Repr> = impl Future<Output = Self::LineStream<'a, Repr>>;
fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {}
//~^ ERROR `()` is not a future
//~^^ method `line_stream` is not a member of trait `X`
}

pub fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
error[E0407]: method `line_stream` is not a member of trait `X`
--> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:25:5
|
LL | fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a member of trait `X`

error[E0049]: type `LineStream` has 0 type parameters but its trait declaration has 1 type parameter
--> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:22:21
|
LL | type LineStream<'a, Repr>
| -- ----
| |
| expected 1 type parameter
...
LL | type LineStream<'c, 'd> = impl Stream;
| ^^ ^^
| |
| found 0 type parameters

error[E0277]: `()` is not a future
--> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:25:43
|
LL | fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not a future
|
= help: the trait `Future` is not implemented for `()`

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0049, E0277, E0407.
For more information about an error, try `rustc --explain E0049`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// test for #110696
// failed to resolve instance for <Scope<()> as MyIndex<()>>::my_index
// ignore-tidy-linelength
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of that adapt the formatting/don't use the full message for the expected error? 🤔


#![feature(type_alias_impl_trait)]

use std::marker::PhantomData;


trait MyIndex<T> {
type O;
fn my_index(self) -> Self::O;
}
trait MyFrom<T>: Sized {
type Error;
fn my_from(value: T) -> Result<Self, Self::Error>;
}


trait F {}
impl F for () {}
type DummyT<T> = impl F;
fn _dummy_t<T>() -> DummyT<T> {}

struct Phantom1<T>(PhantomData<T>);
struct Phantom2<T>(PhantomData<T>);
struct Scope<T>(Phantom2<DummyT<T>>);

impl<T> Scope<T> {
fn new() -> Self {
unimplemented!()
}
}

impl<T> MyFrom<Phantom2<T>> for Phantom1<T> {
type Error = ();
fn my_from(_: Phantom2<T>) -> Result<Self, Self::Error> {
unimplemented!()
}
}

impl<T: MyFrom<Phantom2<DummyT<U>>>, U> MyIndex<DummyT<T>> for Scope<U> {
//~^ ERROR the type parameter `T` is not constrained by the impl trait, self type, or predicates
type O = T;
fn my_index(self) -> Self::O {
MyFrom::my_from(self.0).ok().unwrap()
}
}

fn main() {
let _pos: Phantom1<DummyT<()>> = Scope::new().my_index();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
--> $DIR/ice-failed-to-resolve-instance-for-110696.rs:42:6
|
LL | impl<T: MyFrom<Phantom2<DummyT<U>>>, U> MyIndex<DummyT<T>> for Scope<U> {
| ^ unconstrained type parameter

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0207`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// test for ICE #121472 index out of bounds un_derefer.rs
#![feature(type_alias_impl_trait)]

trait T {}

type Alias<'a> = impl T;

struct S;
impl<'a> T for &'a S {}

fn with_positive(fun: impl Fn(Alias<'_>)) {}

fn main() {
with_positive(|&n| ());
//~^ ERROR mismatched types
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error[E0308]: mismatched types
--> $DIR/underef-index-out-of-bounds-121472.rs:14:20
|
LL | type Alias<'a> = impl T;
| ------ the expected opaque type
...
LL | with_positive(|&n| ());
| ^^
| |
| expected opaque type, found `&_`
| expected due to this
|
= note: expected opaque type `Alias<'_>`
found reference `&_`
help: consider removing `&` from the pattern
|
LL - with_positive(|&n| ());
LL + with_positive(|n| ());
|

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
Loading