Skip to content

Account for trait object with implicit 'static lifetime in field type being returned - #164776

Merged
rust-bors[bot] merged 4 commits into
rust-lang:mainfrom
estebank:short-lifetime-in-return-expr-2
Oct 26, 2026
Merged

rust-bors[bot] merged 4 commits into
rust-lang:mainfrom
estebank:short-lifetime-in-return-expr-2

Conversation

@estebank

@estebank estebank commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Point at dyn Trait in field of type definition when it introduces a 'static obligation:

error: lifetime may not live long enough
  --> $DIR/return-expr-with-implicit-trait-object-static-obligation.rs:11:24
   |
LL |         pub fn new(string: &str) -> Self {
   |                            - let's call the lifetime of this reference `'1`
LL |             Thing {
LL |                 chars: Box::new(string.chars()),
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^ coercion requires that `'1` must outlive `'static`
   |
note: `dyn Trait` introduces an implicit `'static` obligation
  --> $DIR/return-expr-with-implicit-trait-object-static-obligation.rs:5:20
   |
LL |     pub struct Thing {
LL |         chars: Box<dyn Iterator<Item = char>>,
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider introducing an explicit lifetime
   |
LL ~     pub struct Thing<'a> {
LL ~         chars: Box<dyn Iterator<Item = char> + 'a>,
   |

Fix #78547.

Point at introduction of unmet lifetime:

error: lifetime may not live long enough
  --> $DIR/return-expr-with-implicit-trait-object-static-obligation.rs:24:13
   |
LL |       impl Thing<'_> {
   |                  -- lifetime `'2` introduced here
LL |           pub fn new(string: &str) -> Self {
   |                              -        ---- return type is `b::Thing<'2>`
   |                              |
   |                              let's call the lifetime of this reference `'1`
LL | /             Thing {
LL | |                 chars: Box::new(string.chars()),
LL | |             }
   | |_____________^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
error: lifetime may not live long enough
  --> $DIR/issue-52742.rs:12:9
   |
LL | impl Foo<'_, '_> {
   |              -- lifetime `'2` introduced here
LL |     fn take_bar(&mut self, b: Bar<'_>) {
   |                 ---------  -      -- lifetime `'1` introduced here
   |                 |          |
   |                 |          has type `Bar<'1>`
   |                 has type `&mut Foo<'_, '2>`
LL |         self.y = b.z
   |         ^^^^^^^^^^^^ assignment requires that `'1` must outlive `'2`

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 23, 2026
@rustbot

rustbot commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

r? @oli-obk

rustbot has assigned @oli-obk.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 77 candidates
  • Random selection from 19 candidates

let (these, s, introduce) = if v.0.len() == 1 {
("this", "", "introduces")
} else {
("these", "s", "introduce")

@oli-obk oli-obk Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There's no tests for the plural version at all, and I'm not sure it's better to pluralize here than to have one span per dyn trait

View changes since the review

@estebank estebank Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There's one span per dyn Trait, but what you propose would cause multiple notes. I'm already being redundant by having both the help and the suggestion point at pretty much the same place (and am considering just leaving the suggestion), wouldn't want to make this even longer output.

It now looks like this:

error: lifetime may not live long enough
  --> $DIR/return-expr-with-implicit-trait-object-static-obligation.rs:126:25
   |
LL |         pub fn new(string: &str) -> Self {
   |                            - let's call the lifetime of this reference `'1`
LL |             Thing {
LL |                 chars: (Box::new(string.chars()), Box::new(string.chars())),
   |                         ^^^^^^^^^^^^^^^^^^^^^^^^ coercion requires that `'1` must outlive `'static`
   |
note: these `dyn Trait`s introduce an implicit `'static` obligation
  --> $DIR/return-expr-with-implicit-trait-object-static-obligation.rs:120:21
   |
LL |     pub struct Thing {
LL |         chars: (Box<dyn Iterator<Item = char>>, Box<dyn Iterator<Item = char>>),
   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^       ^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider introducing an explicit lifetime
   |
LL ~     pub struct Thing<'a> {
LL ~         chars: (Box<dyn Iterator<Item = char> + 'a>, Box<dyn Iterator<Item = char> + 'a>),
   |

I wonder if I should change it to be

error: lifetime may not live long enough
  --> $DIR/return-expr-with-implicit-trait-object-static-obligation.rs:126:25
   |
LL |         pub fn new(string: &str) -> Self {
   |                            - let's call the lifetime of this reference `'1`
LL |             Thing {
LL |                 chars: (Box::new(string.chars()), Box::new(string.chars())),
   |                         ^^^^^^^^^^^^^^^^^^^^^^^^ coercion requires that `'1` must outlive `'static`
   |
note: `dyn Trait`s in the type definition introduce an implicit `'static` obligation, consider introducing an explicit lifetime
   |
LL ~     pub struct Thing<'a> {
LL ~         chars: (Box<dyn Iterator<Item = char> + 'a>, Box<dyn Iterator<Item = char> + 'a>),
   |

The message would still need to account for plurality.

};
diag.span_note(
span,
format!("{these} trait object{s} {introduce} an implicit `'static` obligation"),

@oli-obk oli-obk Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I thought "trait object" was outdated terminology that we're phasing out, but I keep forgetting if that's actually a thing or if we have docs for it or sth

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Used dyn Trait. I thought so too, but did find multiple diagnostics that still use that wording. I'm more certain about dyn-compatibility and it might be what we're both thinking of.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 23, 2026
@rustbot

rustbot commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@estebank
estebank force-pushed the short-lifetime-in-return-expr-2 branch from f1e60ac to d625bbc Compare October 23, 2026 17:05
@rustbot

This comment has been minimized.

@estebank estebank added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 23, 2026
@rust-log-analyzer

This comment has been minimized.

@estebank
estebank force-pushed the short-lifetime-in-return-expr-2 branch from d625bbc to fe5080d Compare October 23, 2026 17:12
@estebank
estebank force-pushed the short-lifetime-in-return-expr-2 branch from fe5080d to cae5ac3 Compare October 24, 2026 15:52
@rustbot

This comment has been minimized.

@estebank
estebank force-pushed the short-lifetime-in-return-expr-2 branch from cae5ac3 to 4dac048 Compare October 24, 2026 15:53
Comment on lines 4 to 9
LL | fn foo(mut x: Ref, y: Ref) {
| ----- - has type `Ref<'_, '1>`
| |
| ----- --- - --- lifetime `'1` introduced here
| | | |
| | | has type `Ref<'_, '1>`
| | lifetime `'2` introduced here
| has type `Ref<'_, '2>`

@estebank estebank Oct 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These cases are made more verbose one could argue unnecessarily, but there are quite a few other cases where it is a significant improvement (because we point at the exact type in a longer path). I can try spending a bit more time to try to filter only these, but this PR is already ballooning in size, so I'll leave it up to you to decide what to do :)

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sometimes more verbose is better if things are hard to debug already. So sgtm for now and we can revisit by throwing some of these at ppl and seeing how useful the messages are to them

Comment on lines 38 to 49
error: lifetime may not live long enough
--> $DIR/implicit-lifetime-in-assoc-type-projection.rs:29:5
|
LL | impl<'a> Publisher<'a> for MyStruct<'a> {
| -- lifetime `'a` defined here
LL | type Output = u64;
LL | fn subscribe(&mut self, t : Box<dyn Subscriber<Input=<Self as Publisher>::Output> + 'a>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| | |
| ^^^^^^^^^^^^^^^^^^^^^^^^-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------^^^^^^^^^^^^^^^^^
| | | |
| | | lifetime `'1` introduced here
| | has type `Box<dyn Subscriber<Input = <MyStruct<'_> as Publisher<'1>>::Output>>`
| requires that `'1` must outlive `'a`

@estebank estebank Oct 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a case where I think the current approach is an improvement (let alone the ones pointing at the impl that we were hiding before).

View changes since the review

…pe being returned

```
error: lifetime may not live long enough
  --> $DIR/return-expr-with-implicit-trait-object-static-obligation.rs:11:24
   |
LL |         pub fn new(string: &str) -> Self {
   |                            - let's call the lifetime of this reference `'1`
LL |             Thing {
LL |                 chars: Box::new(string.chars()),
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^ coercion requires that `'1` must outlive `'static`
   |
note: this trait object introduces an implicit `'static` obligation
  --> $DIR/return-expr-with-implicit-trait-object-static-obligation.rs:5:20
   |
LL |     pub struct Thing {
LL |         chars: Box<dyn Iterator<Item = char>>,
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider introducing an explicit lifetime
   |
LL ~     pub struct Thing<'a> {
LL ~         chars: Box<dyn Iterator<Item = char> + 'a>,
   |
```
…nd add test for multiple `dyn Trait`s

```
error: lifetime may not live long enough
  --> $DIR/return-expr-with-implicit-trait-object-static-obligation.rs:126:25
   |
LL |         pub fn new(string: &str) -> Self {
   |                            - let's call the lifetime of this reference `'1`
LL |             Thing {
LL |                 chars: (Box::new(string.chars()), Box::new(string.chars())),
   |                         ^^^^^^^^^^^^^^^^^^^^^^^^ coercion requires that `'1` must outlive `'static`
   |
note: these `dyn Trait`s introduce an implicit `'static` obligation
  --> $DIR/return-expr-with-implicit-trait-object-static-obligation.rs:120:21
   |
LL |     pub struct Thing {
LL |         chars: (Box<dyn Iterator<Item = char>>, Box<dyn Iterator<Item = char>>),
   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^       ^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider introducing an explicit lifetime
   |
LL ~     pub struct Thing<'a> {
LL ~         chars: (Box<dyn Iterator<Item = char> + 'a>, Box<dyn Iterator<Item = char> + 'a>),
   |
```
```
error: lifetime may not live long enough
  --> $DIR/return-expr-with-implicit-trait-object-static-obligation.rs:24:13
   |
LL |       impl Thing<'_> {
   |                  -- lifetime `'2` introduced here
LL |           pub fn new(string: &str) -> Self {
   |                              -        ---- return type is `b::Thing<'2>`
   |                              |
   |                              let's call the lifetime of this reference `'1`
LL | /             Thing {
LL | |                 chars: Box::new(string.chars()),
LL | |             }
   | |_____________^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
```
```
error: lifetime may not live long enough
  --> $DIR/issue-52742.rs:12:9
   |
LL | impl Foo<'_, '_> {
   |              -- lifetime `'2` introduced here
LL |     fn take_bar(&mut self, b: Bar<'_>) {
   |                 ---------  -      -- lifetime `'1` introduced here
   |                 |          |
   |                 |          has type `Bar<'1>`
   |                 has type `&mut Foo<'_, '2>`
LL |         self.y = b.z
   |         ^^^^^^^^^^^^ assignment requires that `'1` must outlive `'2`
```
@estebank
estebank force-pushed the short-lifetime-in-return-expr-2 branch from 750bb36 to 3574f1d Compare October 24, 2026 20:40
@rustbot

rustbot commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Comment on lines +593 to +599
let lt_span = if let Some(needle) = self.regioncx.to_error_region(needle_fr)
&& let Some(def_id) = needle.opt_param_def_id(self.infcx.tcx, self.mir_def_id().into())
{
Some(self.infcx.tcx.def_span(def_id))
} else {
None
};

@oli-obk oli-obk Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
let lt_span = if let Some(needle) = self.regioncx.to_error_region(needle_fr)
&& let Some(def_id) = needle.opt_param_def_id(self.infcx.tcx, self.mir_def_id().into())
{
Some(self.infcx.tcx.def_span(def_id))
} else {
None
};
let lt_span = self.regioncx
.to_error_region(needle_fr)
.and_then(|needle| needle.opt_param_def_id(self.infcx.tcx, self.mir_def_id())
.map(|def_id| self.infcx.tcx.def_span(def_id.into()));

or sth ^^

View changes since the review

@oli-obk oli-obk left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@rust-bors

rust-bors Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 3574f1d has been approved by oli-obk

It is now in the queue for this repository.

@rust-bors rust-bors Bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Oct 26, 2026
@rust-bors rust-bors Bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 26, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 26, 2026
…expr-2, r=oli-obk

Account for trait object with implicit `'static` lifetime in field type being returned

Point at `dyn Trait` in field of type definition when it introduces a `'static` obligation:

```
error: lifetime may not live long enough
  --> $DIR/return-expr-with-implicit-trait-object-static-obligation.rs:11:24
   |
LL |         pub fn new(string: &str) -> Self {
   |                            - let's call the lifetime of this reference `'1`
LL |             Thing {
LL |                 chars: Box::new(string.chars()),
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^ coercion requires that `'1` must outlive `'static`
   |
note: `dyn Trait` introduces an implicit `'static` obligation
  --> $DIR/return-expr-with-implicit-trait-object-static-obligation.rs:5:20
   |
LL |     pub struct Thing {
LL |         chars: Box<dyn Iterator<Item = char>>,
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider introducing an explicit lifetime
   |
LL ~     pub struct Thing<'a> {
LL ~         chars: Box<dyn Iterator<Item = char> + 'a>,
   |
```

Fix rust-lang#78547.

Point at introduction of unmet lifetime:

```
error: lifetime may not live long enough
  --> $DIR/return-expr-with-implicit-trait-object-static-obligation.rs:24:13
   |
LL |       impl Thing<'_> {
   |                  -- lifetime `'2` introduced here
LL |           pub fn new(string: &str) -> Self {
   |                              -        ---- return type is `b::Thing<'2>`
   |                              |
   |                              let's call the lifetime of this reference `'1`
LL | /             Thing {
LL | |                 chars: Box::new(string.chars()),
LL | |             }
   | |_____________^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
```

```
error: lifetime may not live long enough
  --> $DIR/issue-52742.rs:12:9
   |
LL | impl Foo<'_, '_> {
   |              -- lifetime `'2` introduced here
LL |     fn take_bar(&mut self, b: Bar<'_>) {
   |                 ---------  -      -- lifetime `'1` introduced here
   |                 |          |
   |                 |          has type `Bar<'1>`
   |                 has type `&mut Foo<'_, '2>`
LL |         self.y = b.z
   |         ^^^^^^^^^^^^ assignment requires that `'1` must outlive `'2`
```
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Oct 26, 2026
…expr-2, r=oli-obk

Account for trait object with implicit `'static` lifetime in field type being returned

Point at `dyn Trait` in field of type definition when it introduces a `'static` obligation:

```
error: lifetime may not live long enough
  --> $DIR/return-expr-with-implicit-trait-object-static-obligation.rs:11:24
   |
LL |         pub fn new(string: &str) -> Self {
   |                            - let's call the lifetime of this reference `'1`
LL |             Thing {
LL |                 chars: Box::new(string.chars()),
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^ coercion requires that `'1` must outlive `'static`
   |
note: `dyn Trait` introduces an implicit `'static` obligation
  --> $DIR/return-expr-with-implicit-trait-object-static-obligation.rs:5:20
   |
LL |     pub struct Thing {
LL |         chars: Box<dyn Iterator<Item = char>>,
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider introducing an explicit lifetime
   |
LL ~     pub struct Thing<'a> {
LL ~         chars: Box<dyn Iterator<Item = char> + 'a>,
   |
```

Fix rust-lang#78547.

Point at introduction of unmet lifetime:

```
error: lifetime may not live long enough
  --> $DIR/return-expr-with-implicit-trait-object-static-obligation.rs:24:13
   |
LL |       impl Thing<'_> {
   |                  -- lifetime `'2` introduced here
LL |           pub fn new(string: &str) -> Self {
   |                              -        ---- return type is `b::Thing<'2>`
   |                              |
   |                              let's call the lifetime of this reference `'1`
LL | /             Thing {
LL | |                 chars: Box::new(string.chars()),
LL | |             }
   | |_____________^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
```

```
error: lifetime may not live long enough
  --> $DIR/issue-52742.rs:12:9
   |
LL | impl Foo<'_, '_> {
   |              -- lifetime `'2` introduced here
LL |     fn take_bar(&mut self, b: Bar<'_>) {
   |                 ---------  -      -- lifetime `'1` introduced here
   |                 |          |
   |                 |          has type `Bar<'1>`
   |                 has type `&mut Foo<'_, '2>`
LL |         self.y = b.z
   |         ^^^^^^^^^^^^ assignment requires that `'1` must outlive `'2`
```
rust-bors Bot pushed a commit that referenced this pull request Oct 26, 2026
…uwer

Rollup of 12 pull requests

Successful merges:

 - #162808 (Enable `--generate-link-to-definition` rustdoc option on std docs)
 - #163219 (assumptions_on_binders: Test mixed ambiguous ORs)
 - #164985 (Only recover if we may for `recover_missing_dot`)
 - #161521 (Replace check_attr_crate_level with check_target for #[doc])
 - #162530 (Move #[naked] attribute check to attribute parsing stage)
 - #164103 (trait solver: Resolve region vars before eager placeholder handling)
 - #164692 (move `ppcf128` lang item to `core::num::imp`)
 - #164702 (Point at `impl` through which associated function is provided)
 - #164776 (Account for trait object with implicit `'static` lifetime in field type being returned)
 - #164791 (Self param after const param)
 - #164856 (Switch from `insta` to `expect-test` in bootstrap)
 - #164888 (Add regression tests for #156380)
rust-bors Bot pushed a commit that referenced this pull request Oct 26, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - #163219 (assumptions_on_binders: Test mixed ambiguous ORs)
 - #164985 (Only recover if we may for `recover_missing_dot`)
 - #161521 (Replace check_attr_crate_level with check_target for #[doc])
 - #162530 (Move #[naked] attribute check to attribute parsing stage)
 - #164103 (trait solver: Resolve region vars before eager placeholder handling)
 - #164692 (move `ppcf128` lang item to `core::num::imp`)
 - #164702 (Point at `impl` through which associated function is provided)
 - #164741 (Use explicit target cpu in tests parsing generated asm)
 - #164767 (Add regression tests for transmutability issues)
 - #164776 (Account for trait object with implicit `'static` lifetime in field type being returned)
 - #164791 (Self param after const param)
 - #164856 (Switch from `insta` to `expect-test` in bootstrap)
 - #164888 (Add regression tests for #156380)
 - #164967 (Add codegen test for power of two implying nonzero with debuginfo)
@rust-bors
rust-bors Bot merged commit eb3b00a into rust-lang:main Oct 26, 2026
14 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 26, 2026
rust-bors Bot pushed a commit that referenced this pull request Oct 26, 2026
Rollup merge of #164776 - estebank:short-lifetime-in-return-expr-2, r=oli-obk

Account for trait object with implicit `'static` lifetime in field type being returned

Point at `dyn Trait` in field of type definition when it introduces a `'static` obligation:

```
error: lifetime may not live long enough
  --> $DIR/return-expr-with-implicit-trait-object-static-obligation.rs:11:24
   |
LL |         pub fn new(string: &str) -> Self {
   |                            - let's call the lifetime of this reference `'1`
LL |             Thing {
LL |                 chars: Box::new(string.chars()),
   |                        ^^^^^^^^^^^^^^^^^^^^^^^^ coercion requires that `'1` must outlive `'static`
   |
note: `dyn Trait` introduces an implicit `'static` obligation
  --> $DIR/return-expr-with-implicit-trait-object-static-obligation.rs:5:20
   |
LL |     pub struct Thing {
LL |         chars: Box<dyn Iterator<Item = char>>,
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider introducing an explicit lifetime
   |
LL ~     pub struct Thing<'a> {
LL ~         chars: Box<dyn Iterator<Item = char> + 'a>,
   |
```

Fix #78547.

Point at introduction of unmet lifetime:

```
error: lifetime may not live long enough
  --> $DIR/return-expr-with-implicit-trait-object-static-obligation.rs:24:13
   |
LL |       impl Thing<'_> {
   |                  -- lifetime `'2` introduced here
LL |           pub fn new(string: &str) -> Self {
   |                              -        ---- return type is `b::Thing<'2>`
   |                              |
   |                              let's call the lifetime of this reference `'1`
LL | /             Thing {
LL | |                 chars: Box::new(string.chars()),
LL | |             }
   | |_____________^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
```

```
error: lifetime may not live long enough
  --> $DIR/issue-52742.rs:12:9
   |
LL | impl Foo<'_, '_> {
   |              -- lifetime `'2` introduced here
LL |     fn take_bar(&mut self, b: Bar<'_>) {
   |                 ---------  -      -- lifetime `'1` introduced here
   |                 |          |
   |                 |          has type `Bar<'1>`
   |                 has type `&mut Foo<'_, '2>`
LL |         self.y = b.z
   |         ^^^^^^^^^^^^ assignment requires that `'1` must outlive `'2`
```
github-actions Bot pushed a commit to rust-lang/stdarch that referenced this pull request Oct 26, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - rust-lang/rust#163219 (assumptions_on_binders: Test mixed ambiguous ORs)
 - rust-lang/rust#164985 (Only recover if we may for `recover_missing_dot`)
 - rust-lang/rust#161521 (Replace check_attr_crate_level with check_target for #[doc])
 - rust-lang/rust#162530 (Move #[naked] attribute check to attribute parsing stage)
 - rust-lang/rust#164103 (trait solver: Resolve region vars before eager placeholder handling)
 - rust-lang/rust#164692 (move `ppcf128` lang item to `core::num::imp`)
 - rust-lang/rust#164702 (Point at `impl` through which associated function is provided)
 - rust-lang/rust#164741 (Use explicit target cpu in tests parsing generated asm)
 - rust-lang/rust#164767 (Add regression tests for transmutability issues)
 - rust-lang/rust#164776 (Account for trait object with implicit `'static` lifetime in field type being returned)
 - rust-lang/rust#164791 (Self param after const param)
 - rust-lang/rust#164856 (Switch from `insta` to `expect-test` in bootstrap)
 - rust-lang/rust#164888 (Add regression tests for #156380)
 - rust-lang/rust#164967 (Add codegen test for power of two implying nonzero with debuginfo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Diagnostics: suggest adding lifetime to trait object stored in struct

4 participants