From 35a78459aac12b079750ebc3997136311fc7ece8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Thu, 21 Mar 2024 20:57:54 +0100 Subject: [PATCH] add test for https://github.com/rust-lang/rust/issues/122098 ICE: index out of bounds, snapshot_vec.rs Fixes #122098 --- ...-ifer-var-leaked-out-of-rollback-122098.rs | 25 +++++++ ...r-var-leaked-out-of-rollback-122098.stderr | 72 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 tests/ui/inference/ice-ifer-var-leaked-out-of-rollback-122098.rs create mode 100644 tests/ui/inference/ice-ifer-var-leaked-out-of-rollback-122098.stderr diff --git a/tests/ui/inference/ice-ifer-var-leaked-out-of-rollback-122098.rs b/tests/ui/inference/ice-ifer-var-leaked-out-of-rollback-122098.rs new file mode 100644 index 00000000000..3c2aa176c0f --- /dev/null +++ b/tests/ui/inference/ice-ifer-var-leaked-out-of-rollback-122098.rs @@ -0,0 +1,25 @@ +// test for #122098 ICE snapshot_vec.rs: index out of bounds: the len is 4 but the index is 4 + +trait LendingIterator { + type Item<'q>: 'a; + //~^ ERROR use of undeclared lifetime name `'a` + + fn for_each(mut self, mut f: Box) + 'static>) {} + //~^ ERROR the size for values of type `Self` cannot be known at compilation time +} + +struct Query<'q> {} +//~^ ERROR lifetime parameter `'q` is never used + +impl<'static> Query<'q> { +//~^ ERROR invalid lifetime parameter name: `'static` +//~^^ ERROR use of undeclared lifetime name `'q` + pub fn new() -> Self {} +} + +fn data() { + LendingIterator::for_each(Query::new(&data), Box::new); + //~^ ERROR this function takes 0 arguments but 1 argument was supplied +} + +pub fn main() {} diff --git a/tests/ui/inference/ice-ifer-var-leaked-out-of-rollback-122098.stderr b/tests/ui/inference/ice-ifer-var-leaked-out-of-rollback-122098.stderr new file mode 100644 index 00000000000..e2ddf474c4a --- /dev/null +++ b/tests/ui/inference/ice-ifer-var-leaked-out-of-rollback-122098.stderr @@ -0,0 +1,72 @@ +error[E0261]: use of undeclared lifetime name `'a` + --> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:4:20 + | +LL | type Item<'q>: 'a; + | ^^ undeclared lifetime + | +help: consider introducing lifetime `'a` here + | +LL | type Item<'a, 'q>: 'a; + | +++ +help: consider introducing lifetime `'a` here + | +LL | trait LendingIterator<'a> { + | ++++ + +error[E0262]: invalid lifetime parameter name: `'static` + --> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:14:6 + | +LL | impl<'static> Query<'q> { + | ^^^^^^^ 'static is a reserved lifetime name + +error[E0261]: use of undeclared lifetime name `'q` + --> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:14:21 + | +LL | impl<'static> Query<'q> { + | - ^^ undeclared lifetime + | | + | help: consider introducing lifetime `'q` here: `'q,` + +error[E0392]: lifetime parameter `'q` is never used + --> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:11:14 + | +LL | struct Query<'q> {} + | ^^ unused lifetime parameter + | + = help: consider removing `'q`, referring to it in a field, or using a marker such as `PhantomData` + +error[E0277]: the size for values of type `Self` cannot be known at compilation time + --> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:7:17 + | +LL | fn for_each(mut self, mut f: Box) + 'static>) {} + | ^^^^^^^^ doesn't have a size known at compile-time + | + = help: unsized fn params are gated as an unstable feature +help: consider further restricting `Self` + | +LL | fn for_each(mut self, mut f: Box) + 'static>) where Self: Sized {} + | +++++++++++++++++ +help: function arguments must have a statically known size, borrowed types always have a known size + | +LL | fn for_each(mut &self, mut f: Box) + 'static>) {} + | + + +error[E0061]: this function takes 0 arguments but 1 argument was supplied + --> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:21:31 + | +LL | LendingIterator::for_each(Query::new(&data), Box::new); + | ^^^^^^^^^^ ----- + | | + | unexpected argument of type `&fn() {data}` + | help: remove the extra argument + | +note: associated function defined here + --> $DIR/ice-ifer-var-leaked-out-of-rollback-122098.rs:17:12 + | +LL | pub fn new() -> Self {} + | ^^^ + +error: aborting due to 6 previous errors + +Some errors have detailed explanations: E0061, E0261, E0262, E0277, E0392. +For more information about an error, try `rustc --explain E0061`.