Skip to content

auto trait incorrectly "unimplemented" by blanket negative impl #108314

New issue

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

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

Already on GitHub? Sign in to your account

Closed
eggyal opened this issue Feb 21, 2023 · 1 comment
Closed

auto trait incorrectly "unimplemented" by blanket negative impl #108314

eggyal opened this issue Feb 21, 2023 · 1 comment
Labels
C-bug Category: This is a bug. F-auto_traits `#![feature(auto_traits)]` F-negative_impls #![feature(negative_impls)]

Comments

@eggyal
Copy link
Contributor

eggyal commented Feb 21, 2023

I tried this code (playground):

#![feature(auto_traits, negative_impls)]

auto trait Blob {}

trait NotBlob {}
impl<B: NotBlob> !Blob for B {}

fn assert_blob(_: impl Blob) {}
fn main() {
    assert_blob(())
}

I expected the code to compile, because Blob is auto-implemented for all types except those for which NotBlob has been implemented (there aren't any); instead, the compiler complains that Blob is not implemented for the unit type ():

error[E0277]: the trait bound `(): Blob` is not satisfied
  --> src/main.rs:10:17
   |
10 |     assert_blob(())
   |     ----------- ^^ the trait `Blob` is not implemented for `()`
   |     |
   |     required by a bound introduced by this call
   |
note: required by a bound in `assert_blob`
  --> src/main.rs:8:24
   |
8  | fn assert_blob(_: impl Blob) {}
   |                        ^^^^ required by this bound in `assert_blob`

For more information about this error, try `rustc --explain E0277`.

Meta

rustc --version --verbose:

rustc 1.69.0 (5243ea5c2 2023-02-20)
binary: rustc
commit-hash: 5243ea5c29b136137c36bd773e5baa663790e097
commit-date: 2023-02-20
host: x86_64-unknown-linux-gnu
release: 1.69.0
LLVM version: 15.0.7

@rustbot label +F-auto_traits +F-negative_impls

@eggyal eggyal added the C-bug Category: This is a bug. label Feb 21, 2023
@rustbot rustbot added F-auto_traits `#![feature(auto_traits)]` F-negative_impls #![feature(negative_impls)] labels Feb 21, 2023
@compiler-errors
Copy link
Member

compiler-errors commented Feb 21, 2023

I think this is necessary for coherence soundness? When considering whether to use an auto trait bound's "implicit" auto implementation, or a user-defined impl (whether negative or positive), we only consider the impl's header and not the where clauses. So to trait selection, it looks like impl<T> !Blob for T and we don't consider the nested where clauses until later.

Anyways, this is a duplicate of #46813 I think!

@compiler-errors compiler-errors closed this as not planned Won't fix, can't repro, duplicate, stale Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-auto_traits `#![feature(auto_traits)]` F-negative_impls #![feature(negative_impls)]
Projects
None yet
Development

No branches or pull requests

3 participants