diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-09-18 17:20:58 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-18 17:20:58 +0200 |
| commit | f28730fcd48f7b6b75ae783a4d3b846e71e3fc37 (patch) | |
| tree | c078ae174ad41009442a739073ed0ee367910771 | |
| parent | b7ab58eb4d6bc12907f2a13c490ac26d53356c85 (diff) | |
| parent | 92646739fe52bc4c40756db71f78fe83b666847e (diff) | |
| download | rust-f28730fcd48f7b6b75ae783a4d3b846e71e3fc37.tar.gz rust-f28730fcd48f7b6b75ae783a4d3b846e71e3fc37.zip | |
Rollup merge of #146622 - aklaiber:91831_add_regression_test, r=jdonszelmann
Add regression test for issue #91831 The requested test for rust-lang/rust#91831. I'm unsure about the filename, the file structure in `tests/ui/lifetimes/lifetime-errors/` isn't entirely clear to me. Any suggestions? Closes rust-lang/rust#91831
| -rw-r--r-- | tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-one-is-struct-5.rs | 13 | ||||
| -rw-r--r-- | tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-one-is-struct-5.stderr | 20 |
2 files changed, 33 insertions, 0 deletions
diff --git a/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-one-is-struct-5.rs b/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-one-is-struct-5.rs new file mode 100644 index 00000000000..16039f177b4 --- /dev/null +++ b/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-one-is-struct-5.rs @@ -0,0 +1,13 @@ +// Regression test for #91831 + +struct Foo<'a>(&'a i32); + +impl<'a> Foo<'a> { + fn modify(&'a mut self) {} +} + +fn bar(foo: &mut Foo) { + foo.modify(); //~ ERROR lifetime may not live long enough +} + +fn main() {} diff --git a/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-one-is-struct-5.stderr b/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-one-is-struct-5.stderr new file mode 100644 index 00000000000..f02b65230b6 --- /dev/null +++ b/tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-one-is-struct-5.stderr @@ -0,0 +1,20 @@ +error: lifetime may not live long enough + --> $DIR/ex3-both-anon-regions-one-is-struct-5.rs:10:5 + | +LL | fn bar(foo: &mut Foo) { + | --- - let's call the lifetime of this reference `'1` + | | + | has type `&mut Foo<'2>` +LL | foo.modify(); + | ^^^^^^^^^^^^ argument requires that `'1` must outlive `'2` + | + = note: requirement occurs because of a mutable reference to `Foo<'_>` + = note: mutable references are invariant over their type parameter + = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance +help: consider introducing a named lifetime parameter + | +LL | fn bar<'a>(foo: &'a mut Foo<'a>) { + | ++++ ++ ++++ + +error: aborting due to 1 previous error + |
