diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-03-28 21:18:32 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-28 21:18:32 +0100 |
| commit | 3e968c7e9fcd1131e98974dfa72e966713a6a21a (patch) | |
| tree | 2c3ed19fa5dd67b8baeb3d7f10d58c8eee9afe44 /tests | |
| parent | 7c0a14f03008ce0b5f442f7a3fed236f686a1efc (diff) | |
| parent | dabee5d5635fd9f5093031df19cacf805292528c (diff) | |
| download | rust-3e968c7e9fcd1131e98974dfa72e966713a6a21a.tar.gz rust-3e968c7e9fcd1131e98974dfa72e966713a6a21a.zip | |
Rollup merge of #139075 - oli-obk:resolver-item-lifetime, r=compiler-errors
Do not treat lifetimes from parent items as influencing child items
```rust
struct A;
impl Bar<'static> for A {
const STATIC: &str = "";
// ^ no future incompat warning
}
```
has no future incompat warning, because there is no ambiguity. But
```rust
struct C;
impl Bar<'_> for C {
// ^^ this lifeimte
const STATIC: &'static str = {
struct B;
impl Bar<'static> for B {
const STATIC: &str = "";
// causes ^ to emit a future incompat warning
}
""
};
}
```
had one before this PR, because the impl for `B` (which is just a copy of `A`) thought it was influenced by a lifetime on the impl for `C`.
I double checked all other `lifetime_ribs` iterations and all of them do check for `Item` boundaries. This feels very fragile tho, and ~~I think we should do not even be able to see ribs from parent items, but that's a different refactoring that I'd rather not do at the same time as a bugfix~~. EDIT: ah nevermind, this is needed for improving diagnostics like "use of undeclared lifetime" being "can't use generic parameters from outer item" instead.
r? `@compiler-errors`
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/consts/static-default-lifetime/static-trait-impl.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/ui/consts/static-default-lifetime/static-trait-impl.rs b/tests/ui/consts/static-default-lifetime/static-trait-impl.rs index b50bf01453d..1e12259e483 100644 --- a/tests/ui/consts/static-default-lifetime/static-trait-impl.rs +++ b/tests/ui/consts/static-default-lifetime/static-trait-impl.rs @@ -17,4 +17,17 @@ impl Bar<'static> for B { const STATIC: &str = ""; } +struct C; +impl Bar<'_> for C { + // make ^^ not cause + const STATIC: &'static str = { + struct B; + impl Bar<'static> for B { + const STATIC: &str = ""; + // ^ to emit a future incompat warning + } + "" + }; +} + fn main() {} |
