Commit graph

11 commits

Author SHA1 Message Date
David Tolnay
136859154b
Add regression test for issue 405
error[E0599]: the method `as_display` exists for reference `&<T as FromStr>::Err`, but its trait bounds were not satisfied
       --> tests/test_generics.rs:178:13
        |
    178 |     #[error("couldn't parse entry: {0}")]
        |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^ method cannot be called on `&<T as FromStr>::Err` due to unsatisfied trait bounds
        |
        = note: the following trait bounds were not satisfied:
                `<T as FromStr>::Err: std::fmt::Display`
                which is required by `&<T as FromStr>::Err: AsDisplay<'_>`
2025-01-08 11:43:18 -08:00
David Tolnay
fb8d3a7f44
Add test using generic type with multiple bounds
error[E0277]: the trait bound `T: UpperHex` is not satisfied
       --> tests/test_generics.rs:179:13
        |
    178 |     #[derive(Error, Debug)]
        |              ----- in this derive macro expansion
    179 |     #[error("0x{thing:x} 0x{thing:X}")]
        |             ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `UpperHex` is not implemented for `T`
        |
        = note: required for `&T` to implement `UpperHex`
    note: required by a bound in `core::fmt::rt::Argument::<'_>::new_upper_hex`
       --> $RUSTUP_HOME/toolchains/nightly-aarch64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/rt.rs:133:29
        |
    133 |     pub fn new_upper_hex<T: UpperHex>(x: &T) -> Argument<'_> {
        |                             ^^^^^^^^ required by this bound in `Argument::<'_>::new_upper_hex`
        = note: this error originates in the macro `$crate::format_args` which comes from the expansion of the derive macro `Error` (in Nightly builds, run with -Z macro-backtrace for more info)
2024-11-08 12:44:59 -05:00
David Tolnay
67faae44b4
Add regression test for issue 345
error[E0599]: `test_no_bound_on_named_fmt::Error<DebugOnly>` doesn't implement `std::fmt::Display`
       --> tests/test_generics.rs:173:22
        |
    168 |     struct Error<T> {
        |     --------------- method `to_string` not found for this struct because it doesn't satisfy `_: Display` or `_: ToString`
    ...
    173 |     assert_eq!(error.to_string(), "...");
        |                      ^^^^^^^^^ `test_no_bound_on_named_fmt::Error<DebugOnly>` cannot be formatted with the default formatter
        |
        = note: the following trait bounds were not satisfied:
                `test_no_bound_on_named_fmt::Error<DebugOnly>: std::fmt::Display`
                which is required by `test_no_bound_on_named_fmt::Error<DebugOnly>: ToString`
        = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
    note: the trait `std::fmt::Display` must be implemented
       --> $RUSTUP_HOME/toolchains/nightly-aarch64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:727:1
        |
    727 | pub trait Display {
        | ^^^^^^^^^^^^^^^^^
        = help: items from traits can only be used if the trait is implemented and in scope
        = note: the following trait defines an item `to_string`, perhaps you need to implement it:
                candidate #1: `ToString`
2024-11-04 17:14:17 -05:00
David Tolnay
00b3c1405e
Work around new dead code warning in test
warning: struct `StructTransparentGeneric` is never constructed
       --> tests/test_generics.rs:161:12
        |
    161 | pub struct StructTransparentGeneric<E>(E);
        |            ^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = note: `#[warn(dead_code)]` on by default
2024-07-31 12:25:52 -07:00
Robert Jördens
7b6e35b992 use core::fmt instead of std::fmt 2024-05-17 15:34:04 +02: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
dd9206cfd0
Remove clippy deny attributes from test suite
These were superseded by the clippy invocation made in our CI workflow:

    run: cargo clippy --tests -- -Dclippy::all -Dclippy::pedantic
2022-04-24 15:22:58 -07:00
David Tolnay
604e47ccbd
Ignore needless_late_init Clippy lint in test
error: unneeded late initalization
      --> tests/test_generics.rs:90:5
       |
    90 |     let mut instance: EnumCompound<DisplayOnly, DebugOnly, NoFormat>;
       |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_late_init
    help: declare `instance` here
       |
    92 |     let mut instance: EnumCompound<DisplayOnly, DebugOnly, NoFormat> = EnumCompound::DisplayDebug(DisplayOnly, DebugOnly);
       |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2021-12-07 18:36:06 -08:00
David Tolnay
42d36e5806
Add test with generic transparent field 2021-09-04 19:38:00 -07:00
David Tolnay
1e6e267914
Implied bounds for Display and Error impl 2021-09-04 18:21:37 -07:00
David Tolnay
81b881063f
Add test of generic error types 2021-09-04 18:21:36 -07:00