Commit Graph

159 Commits

Author SHA1 Message Date
Conrado Gouvea bc3cc1d36c Merge remote-tracking branch 'fork/master' 2024-02-26 13:40:15 -03:00
David Tolnay d43b759e3a
Ignore needless_raw_string_hashes pedantic clippy lint in test
warning: unnecessary hashes around raw string literal
       --> tests/test_display.rs:354:12
        |
    354 |     assert(r#"raw brace left {"#, Error::BraceLeft);
        |            ^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_raw_string_hashes
        = note: `-W clippy::needless-raw-string-hashes` implied by `-W clippy::pedantic`
        = help: to override `-W clippy::pedantic` add `#[allow(clippy::needless_raw_string_hashes)]`
    help: remove all the hashes around the string literal
        |
    354 -     assert(r#"raw brace left {"#, Error::BraceLeft);
    354 +     assert(r"raw brace left {", Error::BraceLeft);
        |

    warning: unnecessary hashes around raw string literal
       --> tests/test_display.rs:355:12
        |
    355 |     assert(r#"raw brace left 2 \x7B"#, Error::BraceLeft2);
        |            ^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_raw_string_hashes
    help: remove all the hashes around the string literal
        |
    355 -     assert(r#"raw brace left 2 \x7B"#, Error::BraceLeft2);
    355 +     assert(r"raw brace left 2 \x7B", Error::BraceLeft2);
        |

    warning: unnecessary hashes around raw string literal
       --> tests/test_display.rs:356:12
        |
    356 |     assert(r#"raw brace right }"#, Error::BraceRight);
        |            ^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_raw_string_hashes
    help: remove all the hashes around the string literal
        |
    356 -     assert(r#"raw brace right }"#, Error::BraceRight);
    356 +     assert(r"raw brace right }", Error::BraceRight);
        |

    warning: unnecessary hashes around raw string literal
       --> tests/test_display.rs:357:12
        |
    357 |     assert(r#"raw brace right 2 \x7D"#, Error::BraceRight2);
        |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_raw_string_hashes
    help: remove all the hashes around the string literal
        |
    357 -     assert(r#"raw brace right 2 \x7D"#, Error::BraceRight2);
    357 +     assert(r"raw brace right 2 \x7D", Error::BraceRight2);
        |
2024-02-11 10:27:54 -08:00
Yuri Astrakhan cd79876fe8 optimize by avoiding second fmt.value() call 2024-02-08 23:56:26 -05:00
Yuri Astrakhan d7e738e1d8 Optimize simple literals for Display::fmt
Compiler is unable to generate as efficient code for `write!(f, "text")` as it does for `f.write_str("text")`.  This PR checks if the `#[error("text")]` uses a simple string literal without the `{` and `}` characters, and without arguments, and uses `write_str` if so.
2024-02-08 23:16:52 -05:00
David Tolnay 0717de3f50
Update ui test suite to nightly-2024-02-08 2024-02-07 21:13:02 -08:00
David Tolnay c7c75470ec
Update ui test suite to nightly-2024-01-31 2024-01-30 22:18:29 -08:00
Conrado Gouvea 6a4a8182d2 support no_std by simply not deriving the Error trait 2024-01-10 17:40:49 -03:00
David Tolnay b97654ab2c
Remove option_if_let_else clippy suppression 2023-12-30 14:42:20 -08:00
David Tolnay b94add8c9b
Add ui test where fallback impl conflicts with handwritten Display 2023-12-15 14:18:41 -08:00
David Tolnay 1754825c24
Work around trivial bounds being unstable 2023-12-15 14:13:00 -08:00
David Tolnay 1567f40ec3
Try to remove "doesn't implement Debug" in fallback expansion 2023-12-15 14:12:59 -08:00
David Tolnay d7e3bdd980
Fix redundant "Error doesn't implement Display" in fallback 2023-12-15 14:12:30 -08:00
David Tolnay 7e5ff62806
Emit an Error impl even in the presence of bad attributes 2023-12-15 14:12:13 -08:00
David Tolnay b010e52359
Add test looking for invalid input to still generate an impl 2023-12-15 12:13:36 -08:00
David Tolnay abb651db3e
Regenerate missing-display.stderr using modern trybuild 2023-12-15 10:47:33 -08:00
David Tolnay 88edb2b0df
Update to nightly-2023-01-14 2023-12-15 10:47:33 -08:00
David Tolnay cf0c5a85c3
Update to nightly-2022-12-12 2023-12-15 10:47:33 -08:00
David Tolnay e7ab6fbd4c
Update to nightly-2022-08-24 2023-12-15 10:47:33 -08:00
David Tolnay 2fe64972de
Update to nightly-2021-08-18 2023-12-15 10:47:33 -08:00
David Tolnay 34e4333af7
Update to nightly-2020-07-29 2023-12-15 10:47:33 -08:00
David Tolnay 65f7773cca
Update to nightly-2020-04-20 2023-12-15 10:47:33 -08:00
David Tolnay 4fe306f5c3
Restore UI test involving missing Display impl
This test existed prior to 04b91d7646.

Since 791a98eb93, we can rely on rust-src being installed.
2023-12-15 10:47:29 -08:00
David Tolnay ebebf77fe0
Format ui tests with rustfmt
`rustfmt tests/ui/*.rs`
2023-10-19 11:05:01 -07:00
Maarten de Vries a49f7c603d Change span of `as_dyn_error()` to point compile error at attribute. 2023-10-19 17:09:30 +02:00
David Tolnay de580887e2
Ignore uninlined_format_args pedantic clippy lint in test
error: variables can be used directly in the `format!` string
      --> tests/test_expr.rs:44:43
       |
    44 |             .map_or_else(String::new, |s| format!("; did you mean '{}'?", s)),
       |                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
       |
    44 -             .map_or_else(String::new, |s| format!("; did you mean '{}'?", s)),
    44 +             .map_or_else(String::new, |s| format!("; did you mean '{s}'?")),
       |
2023-09-02 13:25:01 -07:00
David Tolnay 080cac54d4
Ignore uninlined_format_args pedantic clippy lint
warning: variables can be used directly in the `format!` string
      --> tests/test_generics.rs:93:5
       |
    93 |     assert_eq!(format!("{}", instance), "display only DebugOnly");
       |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
       |
    93 -     assert_eq!(format!("{}", instance), "display only DebugOnly");
    93 +     assert_eq!(format!("{instance}"), "display only DebugOnly");
       |

    warning: variables can be used directly in the `format!` string
      --> tests/test_generics.rs:96:5
       |
    96 |     assert_eq!(format!("{}", instance), "display only");
       |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
       |
    96 -     assert_eq!(format!("{}", instance), "display only");
    96 +     assert_eq!(format!("{instance}"), "display only");
       |

    warning: variables can be used directly in the `format!` string
      --> tests/test_generics.rs:99:5
       |
    99 |     assert_eq!(format!("{}", instance), "DebugOnly");
       |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
       |
    99 -     assert_eq!(format!("{}", instance), "DebugOnly");
    99 +     assert_eq!(format!("{instance}"), "DebugOnly");
       |

    warning: `thiserror` (test "test_generics") generated 3 warnings (run `cargo clippy --fix --test "test_generics"` to apply 3 suggestions)
    warning: variables can be used directly in the `format!` string
       --> tests/test_display.rs:129:20
        |
    129 |         Some(n) => format!("error occurred with {}", n),
        |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
        |
    129 -         Some(n) => format!("error occurred with {}", n),
    129 +         Some(n) => format!("error occurred with {n}"),
        |

    warning: variables can be used directly in the `format!` string
       --> tests/test_display.rs:153:32
        |
    153 |                     Some(n) => write!(formatter, "error occurred with {}", n),
        |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
        |
    153 -                     Some(n) => write!(formatter, "error occurred with {}", n),
    153 +                     Some(n) => write!(formatter, "error occurred with {n}"),
        |
2023-09-02 13:14:40 -07:00
David Tolnay bd640d10e6
Remove unsafe code from AsDisplay 2023-09-02 12:52:34 -07:00
Michal Nazarewicz 97eeb45b8b Replace DisplayAsDisplay and PathAsDisplay with AsDisplay trait
Rather than having separate traits implementing as_display method,
replace DisplayAsDisplay and PathAsDisplay traits with a AsDisplay
trait.  The difference between those two traits is in the result
returned by the as_display method.  With AsDisplay trait this is
captured by an associated type.

The main motivation for the change is making it simpler to support
no_std builds in the future.  Previously, PathAsDisplay would have to
be handled specially in such builds on the side of macro expansion.
Now, thiserror-impl doesn’t need to be aware of any complications
around AsDisplay since they are all contained in thiserror crate.
2023-09-01 04:59:43 +02:00
David Tolnay 78e0ffed90
Pull in anyhow's new Error::provide support 2023-08-15 00:00:07 -07:00
David Tolnay 8a95c2583e
Update to nightly's new Error::provide API 2023-08-14 23:15:54 -07:00
David Tolnay 5cc5855cd0
Revert "Ui tests with compile_error resolved at call site"
This reverts commit b534dafe3b.
2023-06-07 20:50:23 -07:00
David Tolnay b534dafe3b
Ui tests with compile_error resolved at call site 2023-06-07 19:59:12 -07:00
David Tolnay 920ad73295
Ignore extra_unused_type_parameters clippy lint in test
error: type parameter goes unused in function definition
      --> tests/test_from.rs:51:15
       |
    51 | fn assert_impl<T: From<io::Error>>() {}
       |               ^^^^^^^^^^^^^^^^^^^^
       |
       = help: consider removing the parameter
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_type_parameters
       = note: `-D clippy::extra-unused-type-parameters` implied by `-D clippy::all`
2023-02-10 19:17:59 -08:00
David Tolnay db78fa2cd8
Update ui test suite to nightly-2022-12-15 2022-12-14 18:29:48 -08:00
David Tolnay 4b06a3e263
Add test of Display impl nested inside display attribute 2022-10-20 10:30:04 -07:00
David Tolnay 29ee95ef47
Ui test changes for trybuild 1.0.66 2022-10-04 22:28:04 -07:00
David Tolnay c79b023ce1
Update ui test suite to nightly-2022-09-25 2022-09-24 19:49:27 -07:00
David Tolnay 1a90b77165
Pull in Provider impl from anyhow 1.0.65 2022-09-13 11:53:57 -07:00
David Tolnay 01e7c18310
Temporarily disable AnyhowBacktrace test 2022-09-13 11:33:54 -07:00
David Tolnay 21198c9c0a
Move multiple-provide test into test_backtrace
Currently fails with:

    error[E0034]: multiple applicable items in scope
       --> tests/test_backtrace.rs:165:13
        |
    165 |             x: std::io::Error,
        |             ^ multiple `provide` found
        |
        = note: candidate #1 is defined in an impl of the trait `Provider` for the type `E`
        = note: candidate #2 is defined in an impl of the trait `std::error::Error` for the type `std::io::Error`
    help: disambiguate the associated function for candidate #1
        |
    165 |             Provider::provide(&x, Error): std::io::Error,
        |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    help: disambiguate the associated function for candidate #2
        |
    165 |             std::error::Error::provide(&x, Error): std::io::Error,
        |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2022-09-13 11:31:51 -07:00
David Tolnay 4aa7a1c2c8
Add test involving backtrace from a Box<dyn Error> 2022-09-05 19:35:25 -07:00
David Tolnay bd0bd70ae7
Add test of getting backtrace from an anyhow source 2022-09-05 18:44:02 -07:00
David Tolnay 9e9afbff24
Add temporary ui test of 'multiple applicable items' error 2022-09-05 18:32:49 -07:00
David Tolnay 8adf113f0a
Revert "Delete broken #[deprecated] test"
This reverts commit 8862629bcc.
2022-08-30 19:14:00 -07:00
David Tolnay e11c97babf
Update backtrace test to provider API 2022-08-30 19:08:59 -07:00
David Tolnay 986e106172
Revert "Disable nightly backtrace testing until converted to provider API"
This reverts commit c1fb583043.
2022-08-30 19:04:12 -07:00
David Tolnay 034c6ecf10
Update ui test suite to nightly-2022-08-24 2022-08-24 02:15:12 -07:00
David Tolnay 1442e27eaf
Remove stabilized feature(backtrace) from ui test 2022-08-10 21:18:11 -07:00
David Tolnay 0ac645e896
Update ui test suite to nightly-2022-08-11 2022-08-10 21:17:07 -07:00
David Tolnay c1fb583043
Disable nightly backtrace testing until converted to provider API 2022-08-02 20:46:44 -07:00