Skip to content

negative_impls impl changed for tuple #118728

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
wangyanci opened this issue Dec 8, 2023 · 2 comments
Closed

negative_impls impl changed for tuple #118728

wangyanci opened this issue Dec 8, 2023 · 2 comments
Labels
C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression.

Comments

@wangyanci
Copy link

Code

I tried this code:

#![feature(negative_impls, auto_traits)]

auto trait NotEqual {}

impl<T> ! NotEqual for (T, T) {} // expected: NotEqual is not implemented only and only if for tuple(a, b) a and b are of the same type

fn call<T>(_: T) where T: NotEqual {} // expected: only tuple(a, b) a and b are of the same type compile err; but a and b are of the different type compile ok

fn main() {
    // compile ok in all nightly;  it's exactly what i expected
    call(1);
    call((1,1.2, 1.3));

    // compile not ok in all nightly;  yes, it's exactly what i expected
    // call((1,1));

    // compile ok in nightly-2023-07-28(cmd: cargo +nightly-2023-07-28 run);  yes, it's exactly what i expected
    // compile not ok after nightly-2023-07-29 version(cmd: cargo +nightly-2023-07-29 run);  it's not exactly what i expected! why? for what reasons did it change?
    call((1,1.2));
}

I expected to see this happen:
just compile ok like before nightly-2023-07-28 version

$ cargo +nightly-2023-07-28 run
   Compiling test_negative_impls v0.1.0 (/Users/wangyanci/workspace_rust/test_negative_impls)
    Finished dev [unoptimized + debuginfo] target(s) in 0.20s
     Running `target/debug/test_negative_impls`

Instead, this happened:
compile error after nightly-2023-07-29 version

Compiling test_negative_impls v0.1.0 (/Users/wangyanci/workspace_rust/test_negative_impls)
error[E0277]: the trait bound `({integer}, {float}): NotEqual` is not satisfied
  --> src/main.rs:15:10
   |
15 |     call((1,1.2));
   |     ---- ^^^^^^^ the trait `NotEqual` is not implemented for `({integer}, {float})`
   |     |
   |     required by a bound introduced by this call
   |
note: required by a bound in `call`
  --> src/main.rs:7:27
   |
7  | fn call<T>(_: T) where T: NotEqual {}
   |                           ^^^^^^^^ required by this bound in `call`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `test_negative_impls` (bin "test_negative_impls") due to previous error

Version it worked on

It most recently worked on: nightly-2023-07-28

$rustup install nightly-2023-07-28
info: syncing channel updates for 'nightly-2023-07-28-x86_64-apple-darwin'

  nightly-2023-07-28-x86_64-apple-darwin unchanged - rustc 1.73.0-nightly (500647fd8 2023-07-27)

info: checking for self-update

Version with regression

rustc --version --verbose:
nightly-2023-07-28

$ rustup override set nightly-2023-07-28 && rustc --version --verbose
info: using existing install for 'nightly-2023-07-28-x86_64-apple-darwin'
info: override toolchain for '/Users/wangyanci/workspace_rust/test_negative_impls' set to 'nightly-2023-07-28-x86_64-apple-darwin'

  nightly-2023-07-28-x86_64-apple-darwin unchanged - rustc 1.73.0-nightly (500647fd8 2023-07-27)

rustc 1.73.0-nightly (500647fd8 2023-07-27)
binary: rustc
commit-hash: 500647fd8138cc09e87edb08d62f81654fbf6ef8
commit-date: 2023-07-27
host: x86_64-apple-darwin
release: 1.73.0-nightly
LLVM version: 16.0.5

nightly-2023-07-28

rustup override set nightly-2023-07-29 && rustc --version --verbose
info: using existing install for 'nightly-2023-07-29-x86_64-apple-darwin'
info: override toolchain for '/Users/wangyanci/workspace_rust/test_negative_impls' set to 'nightly-2023-07-29-x86_64-apple-darwin'

$  nightly-2023-07-29-x86_64-apple-darwin unchanged - rustc 1.73.0-nightly (04abc370b 2023-07-28)

rustc 1.73.0-nightly (04abc370b 2023-07-28)
binary: rustc
commit-hash: 04abc370b9f3855b28172b65a7f7d5a433f41412
commit-date: 2023-07-28
host: x86_64-apple-darwin
release: 1.73.0-nightly
LLVM version: 16.0.5

Backtrace

Backtrace

$ cargo +nightly-2023-07-29 run
error[E0277]: the trait bound `({integer}, {float}): NotEqual` is not satisfied
  --> src/main.rs:15:10
   |
15 |     call((1,1.2));
   |     ---- ^^^^^^^ the trait `NotEqual` is not implemented for `({integer}, {float})`
   |     |
   |     required by a bound introduced by this call
   |
note: required by a bound in `call`
  --> src/main.rs:7:27
   |
7  | fn call<T>(_: T) where T: NotEqual {}
   |                           ^^^^^^^^ required by this bound in `call`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `test_negative_impls` (bin "test_negative_impls") due to previous error

I'd like to know what considerations changed it or is it a problem in itself

@wangyanci wangyanci added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Dec 8, 2023
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 8, 2023
@compiler-errors
Copy link
Member

This is intentional. This broke in #113312 -- see the FCP in #113312 (comment), which decided that we would adjust the way that impls (positive or negative) interact with auto traits to fix unsoundness.

@wangyanci
Copy link
Author

This is intentional. This broke in #113312 -- see the FCP in #113312 (comment), which decided that we would adjust the way that impls (positive or negative) interact with auto traits to fix unsoundness.

OK, thanks

@apiraino apiraino removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 8, 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. regression-untriaged Untriaged performance or correctness regression.
Projects
None yet
Development

No branches or pull requests

4 participants