Skip to content

RA suggests incorrect quick fix / replacement that Clippy doesn't #16596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nsabovic opened this issue Feb 18, 2024 · 1 comment · Fixed by #16647
Closed

RA suggests incorrect quick fix / replacement that Clippy doesn't #16596

nsabovic opened this issue Feb 18, 2024 · 1 comment · Fixed by #16647
Assignees
Labels
A-diagnostics diagnostics / error reporting C-bug Category: bug

Comments

@nsabovic
Copy link

rust-analyzer version: 0.3.1839-standalone (c06ca6c 2024-02-11)
rust-analyzer version: 0.4.1843-standalone (b9b0d29 2024-02-15)

rustc version: rustc 1.76.0 (07dca489a 2024-02-04)

relevant settings: N/A

In the following code RA suggests replacing filter_map().next() with find_map(), however find_map() requires Self to be Sized (why is beyond me) so actually running this replacement produces code that doesn't compile. Clippy does not offer this suggestion. Tried on stable and preview VSCode plugin.

let mut j = [0].into_iter();
let i: &mut dyn Iterator<Item = i32>  = &mut j;
let dummy_fn = |v| (v > 0).then_some(v + 1);
let _res = i.filter_map(dummy_fn).next();
@nsabovic nsabovic added the C-bug Category: bug label Feb 18, 2024
@Veykril
Copy link
Member

Veykril commented Feb 18, 2024

The problem here is the difference between next and find_map wrt to Self::Sized (the latte probably requires it due to the use of try_fold). We shouldn't show the lint here 👍

@Veykril Veykril added the A-diagnostics diagnostics / error reporting label Feb 18, 2024
@Young-Flash Young-Flash self-assigned this Feb 19, 2024
bors added a commit that referenced this issue Feb 26, 2024
…ind_map, r=Veykril

fix: replace_filter_map_next_with_find_map shouldn't work for dyn trait

close #16596
@bors bors closed this as completed in 8929853 Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics diagnostics / error reporting C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants