mirror of
https://github.com/dtolnay/thiserror.git
synced 2025-04-05 05:47:39 +03:00
Clippy bug: https://github.com/rust-lang/rust-clippy/issues/7422 error: use of irregular braces for `write!` macro --> tests/test_backtrace.rs:5:10 | 5 | #[derive(Error, Debug)] | ^^^^^ | = note: `-D clippy::nonstandard-macro-braces` implied by `-D clippy::all` help: consider writing `Error` --> tests/test_backtrace.rs:5:10 | 5 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_lints.rs:13:21 | 13 | #[derive(Debug, Error)] | ^^^^^ | = note: `-D clippy::nonstandard-macro-braces` implied by `-D clippy::all` help: consider writing `Error` --> tests/test_lints.rs:13:21 | 13 | #[derive(Debug, Error)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_source.rs:7:10 | 7 | #[derive(Error, Debug)] | ^^^^^ | note: the lint level is defined here --> tests/test_source.rs:1:9 | 1 | #![deny(clippy::all, clippy::pedantic)] | ^^^^^^^^^^^ = note: `#[deny(clippy::nonstandard_macro_braces)]` implied by `#[deny(clippy::all)]` help: consider writing `Error` --> tests/test_source.rs:7:10 | 7 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_source.rs:13:10 | 13 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_source.rs:13:10 | 13 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_source.rs:21:10 | 21 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_source.rs:21:10 | 21 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_source.rs:54:18 | 54 | #[derive(Error)] | ^^^^^ ... 64 | / error_from_macro! { 65 | | #[error("Something")] 66 | | Variant(#[from] io::Error) 67 | | } | |_- in this macro invocation | help: consider writing `Error` --> tests/test_source.rs:54:18 | 54 | #[derive(Error)] | ^^^^^ ... 64 | / error_from_macro! { 65 | | #[error("Something")] 66 | | Variant(#[from] io::Error) 67 | | } | |_- in this macro invocation = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_expr.rs:9:10 | 9 | #[derive(Error, Debug)] | ^^^^^ | note: the lint level is defined here --> tests/test_expr.rs:1:9 | 1 | #![deny(clippy::all, clippy::pedantic)] | ^^^^^^^^^^^ = note: `#[deny(clippy::nonstandard_macro_braces)]` implied by `#[deny(clippy::all)]` help: consider writing `Error` --> tests/test_expr.rs:9:10 | 9 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_expr.rs:39:10 | 39 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_expr.rs:39:10 | 39 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_from.rs:6:10 | 6 | #[derive(Error, Debug)] | ^^^^^ | note: the lint level is defined here --> tests/test_from.rs:1:9 | 1 | #![deny(clippy::all, clippy::pedantic)] | ^^^^^^^^^^^ = note: `#[deny(clippy::nonstandard_macro_braces)]` implied by `#[deny(clippy::all)]` help: consider writing `Error` --> tests/test_from.rs:6:10 | 6 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_from.rs:13:10 | 13 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_from.rs:13:10 | 13 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_path.rs:8:10 | 8 | #[derive(Error, Debug)] | ^^^^^ | note: the lint level is defined here --> tests/test_path.rs:1:9 | 1 | #![deny(clippy::all, clippy::pedantic)] | ^^^^^^^^^^^ = note: `#[deny(clippy::nonstandard_macro_braces)]` implied by `#[deny(clippy::all)]` help: consider writing `Error` --> tests/test_path.rs:8:10 | 8 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_path.rs:14:10 | 14 | #[derive(Error, Debug, RefCast)] | ^^^^^ | help: consider writing `Error` --> tests/test_path.rs:14:10 | 14 | #[derive(Error, Debug, RefCast)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_from.rs:17:10 | 17 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_from.rs:17:10 | 17 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_path.rs:21:10 | 21 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_path.rs:21:10 | 21 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_transparent.rs:14:14 | 14 | #[derive(Error, Debug)] | ^^^^^ | note: the lint level is defined here --> tests/test_transparent.rs:1:9 | 1 | #![deny(clippy::all, clippy::pedantic)] | ^^^^^^^^^^^ = note: `#[deny(clippy::nonstandard_macro_braces)]` implied by `#[deny(clippy::all)]` help: consider writing `Error` --> tests/test_transparent.rs:14:14 | 14 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_from.rs:26:10 | 26 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_from.rs:26:10 | 26 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_transparent.rs:34:14 | 34 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_transparent.rs:34:14 | 34 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_transparent.rs:69:14 | 69 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_transparent.rs:69:14 | 69 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_display.rs:12:14 | 12 | #[derive(Error, Debug)] | ^^^^^ | note: the lint level is defined here --> tests/test_display.rs:1:9 | 1 | #![deny(clippy::all, clippy::pedantic)] | ^^^^^^^^^^^ = note: `#[deny(clippy::nonstandard_macro_braces)]` implied by `#[deny(clippy::all)]` help: consider writing `Error` --> tests/test_display.rs:12:14 | 12 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_display.rs:24:14 | 24 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_display.rs:24:14 | 24 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_display.rs:35:14 | 35 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_display.rs:35:14 | 35 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_display.rs:44:14 | 44 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_display.rs:44:14 | 44 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_display.rs:53:14 | 53 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_display.rs:53:14 | 53 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_display.rs:70:14 | 70 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_display.rs:70:14 | 70 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_display.rs:84:14 | 84 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_display.rs:84:14 | 84 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_display.rs:98:14 | 98 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_display.rs:98:14 | 98 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_display.rs:107:14 | 107 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_display.rs:107:14 | 107 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_display.rs:115:14 | 115 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_display.rs:115:14 | 115 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_display.rs:129:14 | 129 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_display.rs:129:14 | 129 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_display.rs:158:14 | 158 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_display.rs:158:14 | 158 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_display.rs:170:14 | 170 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_display.rs:170:14 | 170 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_display.rs:184:14 | 184 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_display.rs:184:14 | 184 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_display.rs:201:14 | 201 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_display.rs:201:14 | 201 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_display.rs:214:29 | 214 | #[derive(Debug, Error)] | ^^^^^ ... 228 | decl_error!(Repro(u8)); | ----------------------- in this macro invocation | help: consider writing `Error` --> tests/test_display.rs:214:29 | 214 | #[derive(Debug, Error)] | ^^^^^ ... 228 | decl_error!(Repro(u8)); | ----------------------- in this macro invocation = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_display.rs:220:29 | 220 | #[derive(Debug, Error)] | ^^^^^ ... 228 | decl_error!(Repro(u8)); | ----------------------- in this macro invocation | help: consider writing `Error` --> tests/test_display.rs:220:29 | 220 | #[derive(Debug, Error)] | ^^^^^ ... 228 | decl_error!(Repro(u8)); | ----------------------- in this macro invocation = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_display.rs:236:14 | 236 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_display.rs:236:14 | 236 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_display.rs:247:14 | 247 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_display.rs:247:14 | 247 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_display.rs:258:14 | 258 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_display.rs:258:14 | 258 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of irregular braces for `write!` macro --> tests/test_display.rs:269:14 | 269 | #[derive(Error, Debug)] | ^^^^^ | help: consider writing `Error` --> tests/test_display.rs:269:14 | 269 | #[derive(Error, Debug)] | ^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces = note: this error originates in the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info)
93 lines
2.5 KiB
Rust
93 lines
2.5 KiB
Rust
#![deny(clippy::all, clippy::pedantic)]
|
|
#![allow(
|
|
// Clippy bug: https://github.com/rust-lang/rust-clippy/issues/7422
|
|
clippy::nonstandard_macro_braces,
|
|
clippy::option_if_let_else,
|
|
)]
|
|
|
|
use std::fmt::Display;
|
|
use thiserror::Error;
|
|
|
|
// Some of the elaborate cases from the rcc codebase, which is a C compiler in
|
|
// Rust. https://github.com/jyn514/rcc/blob/0.8.0/src/data/error.rs
|
|
#[derive(Error, Debug)]
|
|
pub enum CompilerError {
|
|
#[error("cannot shift {} by {maximum} or more bits (got {current})", if *.is_left { "left" } else { "right" })]
|
|
TooManyShiftBits {
|
|
is_left: bool,
|
|
maximum: u64,
|
|
current: u64,
|
|
},
|
|
|
|
#[error("#error {}", (.0).iter().copied().collect::<Vec<_>>().join(" "))]
|
|
User(Vec<&'static str>),
|
|
|
|
#[error("overflow while parsing {}integer literal",
|
|
if let Some(signed) = .is_signed {
|
|
if *signed { "signed "} else { "unsigned "}
|
|
} else {
|
|
""
|
|
}
|
|
)]
|
|
IntegerOverflow { is_signed: Option<bool> },
|
|
|
|
#[error("overflow while parsing {}integer literal", match .is_signed {
|
|
Some(true) => "signed ",
|
|
Some(false) => "unsigned ",
|
|
None => "",
|
|
})]
|
|
IntegerOverflow2 { is_signed: Option<bool> },
|
|
}
|
|
|
|
// Examples drawn from Rustup.
|
|
#[derive(Error, Debug)]
|
|
pub enum RustupError {
|
|
#[error(
|
|
"toolchain '{name}' does not contain component {component}{}",
|
|
.suggestion
|
|
.as_ref()
|
|
.map_or_else(String::new, |s| format!("; did you mean '{}'?", s)),
|
|
)]
|
|
UnknownComponent {
|
|
name: String,
|
|
component: String,
|
|
suggestion: Option<String>,
|
|
},
|
|
}
|
|
|
|
fn assert<T: Display>(expected: &str, value: T) {
|
|
assert_eq!(expected, value.to_string());
|
|
}
|
|
|
|
#[test]
|
|
fn test_rcc() {
|
|
assert(
|
|
"cannot shift left by 32 or more bits (got 50)",
|
|
CompilerError::TooManyShiftBits {
|
|
is_left: true,
|
|
maximum: 32,
|
|
current: 50,
|
|
},
|
|
);
|
|
|
|
assert("#error A B C", CompilerError::User(vec!["A", "B", "C"]));
|
|
|
|
assert(
|
|
"overflow while parsing signed integer literal",
|
|
CompilerError::IntegerOverflow {
|
|
is_signed: Some(true),
|
|
},
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_rustup() {
|
|
assert(
|
|
"toolchain 'nightly' does not contain component clipy; did you mean 'clippy'?",
|
|
RustupError::UnknownComponent {
|
|
name: "nightly".to_owned(),
|
|
component: "clipy".to_owned(),
|
|
suggestion: Some("clippy".to_owned()),
|
|
},
|
|
);
|
|
}
|