-
Notifications
You must be signed in to change notification settings - Fork 2k
Open
Labels
A-completionautocompletionautocompletion
Description
When completing, it will auto dereference, just like:
pub fn bar(_: &str) { }
fn main() {
let it = &"";
bar($0); // complete `*it`
}But clippy outputs:
warning: deref which would be done by auto-deref
--> src/bin/main.rs:4:9
|
4 | bar(*it);
| ^^^ help: try: `it`
But if add condition !completion_without_ref.is_reference(),
the following example will report an error:
pub fn foo<'a>(s: &'a [&'a str]) -> impl Iterator<Item = &'a str> {
s.iter().map(|it| {
std::convert::identity(it) // instead of `*it`
})
}Compile error:
error[E0271]: expected `{[email protected]:2:18}` to return `&str`, but it returns `&&str`
--> src/bin/main.rs:3:9
|
1 | pub fn foo<'a>(s: &'a [&'a str]) -> impl Iterator<Item = &'a str> {
| ----------------------------- closure used here
2 | s.iter().map(|it| {
| - ---- this closure
| _____|
| |
3 | | std::convert::identity(it) // instead of `*it`
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&str`, found `&&str`
4 | | })
Is it worth improving on this? How to improve?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-completionautocompletionautocompletion