special-casing `'static` when winnowing trivial candidates
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
The following code compiles (adapted from tests/ui/trivial-bounds/trivial-bounds-object.rs):
// check-pass
trait A { fn test(&self); }
fn foo(x: &dyn A)
where
dyn A + 'static: A, // Using this bound would lead to a lifetime error.
{
x.test();
}
while this doesn't:
trait A { fn test(&self); }
fn foo<'s>(x: &dyn A)
where
dyn A + 's: A, // Using this bound would lead to a lifetime error.
{
x.test();
//~^ ERROR explicit lifetime required in the type of `x`
}
There are two candidates to satisfy the bound dyn A + '?0: A:
for the first case:
ObjectCandidate(_); no region constraintsParamCandidate(dyn A + 'static: A); requires'?0 = 'static
for the seecond one:
ObjectCandidate(_); no region constraintsParamCandidate(dyn A + 's: A); requires'?0 = 's
The different behavior arises because the param candidate in the first case is considered "global", unlike second case. Global param candidates are dropped in favor of any other candidate. This behavior was introduced by #51042 here:
https://github.com/rust-lang/rust/blob/604f185fae9a4b0edf7e28f616a0f53880f8f074/compiler/rustc_trait_selection/src/traits/select/mod.rs#L1816
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with tests/ui/trivial-bounds/trivial-bounds-object.rs and reproduce the two examples to compare candidate selection. Then read compiler/rustc_trait_selection/src/traits/select/mod.rs around the referenced line and trace how global parameter candidates are winnowed. Done means the lifetime behavior is corrected for the reported cases with appropriate UI test coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100