Skip to content

Negative trait impls show as "found implementations" in error messages #79458

Closed
@scottmcm

Description

@scottmcm

(Spotted in https://users.rust-lang.org/t/the-trait-clone-is-not-implemented-for-mut-t/51989?u=scottmcm)

I tried this code https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=6862c5bd66f1fcdf55fd725a93baffcd:

#[derive(Clone)]
struct Foo<'a, T> {
    x: &'a mut T,
}

Which of course fails to compile, but it gives the following confusing help:

  = help: the following implementations were found:
            <&T as Clone>
            <&mut T as Clone>

The library now has impl<'_, T> !Clone for &'_ mut T, so it looks like this error-generation code path needs to be updated to account for that.

Ideally it'd take advantage of the explicit negative here to say that it's not clone and has been promised that it never will be, but at the very least is shouldn't be showing <&mut T as Clone> which makes it look like it's actually Clone.

cc #68318

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.F-negative_impls#![feature(negative_impls)]T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions