Trait resolution with index operator and mixed lifetimes #92603
Labels
A-borrow-checker
Area: The borrow checker
A-lifetimes
Area: Lifetimes / regions
A-NLL
Area: Non-lexical lifetimes (NLL)
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
As far as I can tell the error generated by this is wrong.
If the lifetime comes from an impl block, a completely different error message is given.
Which is saying
&'static str
doesn't implementBorrow<&'a str>
, which is technically true. The closest matching impl isimpl<T> Borrow<T> for T
which would mean it implementsBorrow<&'static str>
notBorrow<&'a str>
. My understanding is trait resolution is not supposed to take lifetimes into account when determining if a type implements a trait which would make this error incorrect.When either
key
is a&'static str
, or the index method is used directly the errors do not occur.and
This came up while looking at rust-lang/rust-clippy#1725
Tested on the playground (stable 1.57)
The text was updated successfully, but these errors were encountered: