Skip to content

Only apply inferred bounds if interpolation refers to field#353

Merged
dtolnay merged 2 commits intomasterfrom
inferbound
Nov 4, 2024
Merged

Only apply inferred bounds if interpolation refers to field#353
dtolnay merged 2 commits intomasterfrom
inferbound

Conversation

@dtolnay
Copy link
Owner

@dtolnay dtolnay commented Nov 4, 2024

Fixes #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`
@dtolnay dtolnay merged commit b81fd86 into master Nov 4, 2024
@dtolnay dtolnay deleted the inferbound branch November 4, 2024 22:22
takumi-earth pushed a commit to earthlings-dev/thiserror that referenced this pull request Jan 27, 2026
Only apply inferred bounds if interpolation refers to field
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inappropriate inferred trait bounds when format var name overlaps with field name

1 participant