E0277 could provide useful details
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
I was looking at trim_matches std docs code example and tried to inline x into the trim_matches` :
https://doc.rust-lang.org/std/primitive.str.html#method.trim_matches
#![allow(unused)]
fn main() {
assert_eq!("11foo1bar11".trim_matches('1'), "foo1bar");
assert_eq!("123foo1bar123".trim_matches(char::is_numeric), "foo1bar");
let x: &[_] = &['1', '2'];
// x inlined here:
assert_eq!("12foo1bar12".trim_matches( &['1', '2']), "foo1bar");
}
error[[E0277]](https://doc.rust-lang.org/nightly/error_codes/E0277.html): the trait bound `CharArrayRefSearcher<'_, '_, 2>: DoubleEndedSearcher<'_>` is not satisfied
--> src/main.rs:8:40
|
8 | assert_eq!("12foo1bar12".trim_matches( &['1', '2']), "foo1bar");
| ------------ ^^^^^^^^^^^ the trait `DoubleEndedSearcher<'_>` is not implemented for `CharArrayRefSearcher<'_, '_, 2>`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `DoubleEndedSearcher<'a>`:
CharSearcher<'a>
CharSliceSearcher<'a, 'b>
CharPredicateSearcher<'a, F>
note: required by a bound in `core::str::<impl str>::trim_matches`
--> /rustc/e5cfc55477eceed1317a02189fdf77a4a98f2124/library/core/src/str/mod.rs:2021:5
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (bin "playground") due to previous error
The diagnostic issued is not helping, mentioning 5 different structs 😅
I assume this is some kind of lifetime problem, but my first intuition was "should not matter if the reference to an array is coming from within our without the function call, since its a reference anyway?"
Would be great if the error could give some useful details.
I think we already have "lifetime only goes until here but should go until there for code to be valid` diagnostics somewhere, maybe we could use that and suggest using a var binding for the array?
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
Reproduce the trim_matches example and inspect the diagnostic around library/core/src/str/mod.rs:2021:5. Compare the E0277 output with existing lifetime diagnostics, then determine whether the array binding or lifetime context can be explained more usefully. Done means the reported error gives actionable details instead of primarily listing internal searcher types.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100