Skip to content
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

Printed hint for lint or_fun_call is cropped and does not show the solution #8239

Closed
aleksanderkrauze opened this issue Jan 7, 2022 · 2 comments · Fixed by #8292
Closed
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@aleksanderkrauze
Copy link

Description

Desctiption

Following code snippet was correctly marked by clippy as or_fun_call. However it's output could be better. Problem here is at the last line of this block, but clippy's hint is cropped and this bottom part is not shown. It seams that clippy is omitting different lines in the warning and in the hint.

Code

self.frames
    .iter()
    .map(|f| f.encode())
    .reduce(|mut acc, mut f| {
        acc.append(&mut f);
        acc
    })
    .unwrap_or(Vec::new())

Clippy's output

warning: use of `unwrap_or` followed by a call to `new`
  --> src/server/frame.rs:89:9
   |
89 | /         self.frames
90 | |             .iter()
91 | |             .map(|f| f.encode())
92 | |             .reduce(|mut acc, mut f| {
...  |
95 | |             })
96 | |             .unwrap_or(Vec::new())
   | |__________________________________^
   |
   = note: `#[warn(clippy::or_fun_call)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#or_fun_call
help: try this
   |
89 ~         self.frames
90 +             .iter()
91 +             .map(|f| f.encode())
92 +             .reduce(|mut acc, mut f| {
93 +                 acc.append(&mut f);
94 +                 acc
 ...

Version

rustc 1.57.0 (f1edd0429 2021-11-29)
binary: rustc
commit-hash: f1edd0429582dd29cccacaf50fd134b05593bd9c
commit-date: 2021-11-29
host: x86_64-unknown-linux-gnu
release: 1.57.0
LLVM version: 13.0.0

Additional Labels

@rustbot label +C-enhancement

@rustbot rustbot added the C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages label Jan 7, 2022
@aleksanderkrauze aleksanderkrauze changed the title Printed hint for lint or_fun_call is not log enought Printed hint for lint or_fun_call is croppend and does not show the solution Jan 7, 2022
@aleksanderkrauze aleksanderkrauze changed the title Printed hint for lint or_fun_call is croppend and does not show the solution Printed hint for lint or_fun_call is cropped and does not show the solution Jan 7, 2022
@camsteffen camsteffen added C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy and removed C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels Jan 7, 2022
@marekdownar
Copy link
Contributor

marekdownar commented Jan 14, 2022

Isn't it strictly connected with current rustc diagnostics emitter?
pub const MAX_SUGGESTION_HIGHLIGHT_LINES: usize = 6;
It looks like DiagnosticBuilder span_suggestion formats the result suggestion with max 6 lines of output.

@xFrednet
Copy link
Member

This is strictly connected. However, we can adjust the help message to say try using `unwrap_or_else(Vec::new)`: to make the suggestion clear if the snippet spans over multiple lines. Or we could restrict the suggestion span to the .unwrap_or(Vec::new()) call, as the previous text stays the same. Both would be valid solutions 🙃

@xFrednet xFrednet added the L-suggestion Lint: Improving, adding or fixing lint suggestions label Jan 14, 2022
marekdownar added a commit to marekdownar/rust-clippy that referenced this issue Jan 15, 2022
marekdownar added a commit to marekdownar/rust-clippy that referenced this issue Jan 15, 2022
@bors bors closed this as completed in 8d14c94 Jan 17, 2022
@xFrednet xFrednet self-assigned this Mar 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants