Skip to content

Machine applicable suggestion ignores empty where bounds #120838

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
oli-obk opened this issue Feb 9, 2024 · 1 comment · Fixed by #120874
Closed

Machine applicable suggestion ignores empty where bounds #120838

oli-obk opened this issue Feb 9, 2024 · 1 comment · Fixed by #120874
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code.

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Feb 9, 2024

I tried this code:

(from https://github.com/rust-lang/rust/blob/cf2dff2b1e3fa55fa5415d524200070d0d7aacfe/tests/ui/trait-impl-bound-suggestions.rs)

use std::fmt::Debug;

struct ConstrainedStruct<X: Copy> {
    x: X
}

trait InsufficientlyConstrainedGeneric<X=()> where {
    fn return_the_constrained_type(&self, x: X) -> ConstrainedStruct<X> {
        ConstrainedStruct { x }
    }
}

fn main() { }

I expected to see this happen:

10 | trait InsufficientlyConstrainedGeneric<X=()> where X: std::marker::Copy {
   |                                                    ++++++++++++++++++++

just add the new predicate

Instead, this happened:

10 | trait InsufficientlyConstrainedGeneric<X=()> where where X: std::marker::Copy {
   |                                                    ++++++++++++++++++++++++++

I noticed this because a change to the compiler caused two predicates to get added, so even without an empty where clause (so with none), you'd get where X: std::marker::Copy where X: std::marker::Copy, because the usual suggestion application logic does not see that there is a conflict, because the spans don't actually overlap.

Meta

rustc --version --verbose:

1.78 (nightly, but also happens on earlier stables)
@oli-obk oli-obk added A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Feb 9, 2024
@gurry
Copy link
Contributor

gurry commented Feb 9, 2024

@rustbot claim

@bors bors closed this as completed in 0171057 Feb 11, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 11, 2024
Rollup merge of rust-lang#120874 - gurry:120838-extra-where-in-suggestion, r=fmease

Take empty `where` bounds into account when suggesting predicates

Fixes rust-lang#120838
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants