Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Suppress question_mark Clippy false positive
Browse files Browse the repository at this point in the history
rust-lang/rust-clippy#7859

    error: this block may be rewritten with the `?` operator
       --> src/ser.rs:871:9
        |
    871 | /         if self.writer.write_all(s.as_bytes()).is_err() {
    872 | |             return Err(fmt::Error);
    873 | |         }
        | |_________^ help: replace it with: `self.writer.write_all(s.as_bytes())?;`
        |
        = note: `-D clippy::question-mark` implied by `-D clippy::all`
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark

Clippy's suggested replacement does not compile.

    error[E0277]: `?` couldn't convert the error to `std::fmt::Error`
       --> src/ser.rs:871:44
        |
    871 |         self.writer.write_all(s.as_bytes())?;
        |                                            ^ the trait `std::convert::From<std::io::Error>` is not implemented for `std::fmt::Error`
        |
        = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
        = note: required because of the requirements on the impl of `std::ops::FromResidual<std::result::Result<std::convert::Infallible, std::io::Error>>` for `std::result::Result<(), std::fmt::Error>`
    note: required by `std::ops::FromResidual::from_residual`
       --> nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/try_trait.rs:339:5
        |
    339 |     fn from_residual(residual: R) -> Self;
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  • Loading branch information
dtolnay committed Oct 23, 2021
1 parent 68ac1a3 commit a23d8f2
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
#![deny(missing_docs)]
// Suppressed clippy_pedantic lints
#![allow(
// buggy
clippy::question_mark, // https://github.com/rust-lang/rust-clippy/issues/7859
// private Deserializer::next
clippy::should_implement_trait,
// things are often more readable this way
Expand Down

1 comment on commit a23d8f2

@georgmu
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacement would be self.writer.write_all(s.as_bytes()).map_err(|_| fmt::Error)

Please sign in to comment.