Skip to content

Commit f28730f

Browse files
authored
Rollup merge of #146622 - aklaiber:91831_add_regression_test, r=jdonszelmann
Add regression test for issue #91831 The requested test for #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 #91831
2 parents b7ab58e + 9264673 commit f28730f

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Regression test for #91831
2+
3+
struct Foo<'a>(&'a i32);
4+
5+
impl<'a> Foo<'a> {
6+
fn modify(&'a mut self) {}
7+
}
8+
9+
fn bar(foo: &mut Foo) {
10+
foo.modify(); //~ ERROR lifetime may not live long enough
11+
}
12+
13+
fn main() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/ex3-both-anon-regions-one-is-struct-5.rs:10:5
3+
|
4+
LL | fn bar(foo: &mut Foo) {
5+
| --- - let's call the lifetime of this reference `'1`
6+
| |
7+
| has type `&mut Foo<'2>`
8+
LL | foo.modify();
9+
| ^^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
10+
|
11+
= note: requirement occurs because of a mutable reference to `Foo<'_>`
12+
= note: mutable references are invariant over their type parameter
13+
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
14+
help: consider introducing a named lifetime parameter
15+
|
16+
LL | fn bar<'a>(foo: &'a mut Foo<'a>) {
17+
| ++++ ++ ++++
18+
19+
error: aborting due to 1 previous error
20+

0 commit comments

Comments
 (0)