Skip to content

Machine applicable suggestion ignores empty where bounds #120838

Closed
@oli-obk

Description

@oli-obk
Contributor

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)

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
C-bugCategory: This is a bug.
A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.
on Feb 9, 2024
gurry

gurry commented on Feb 9, 2024

@gurry
Contributor

@rustbot claim

added a commit that references this issue on Feb 11, 2024

Rollup merge of rust-lang#120874 - gurry:120838-extra-where-in-sugges…

0171057
added a commit that references this issue on Feb 11, 2024
530afbd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @oli-obk@gurry

    Issue actions

      Machine applicable suggestion ignores empty where bounds · Issue #120838 · rust-lang/rust