Skip to content
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

Adding generic trait impl with const_evaluatable_checked bound can lead to compilation error in code using the trait. #82279

Closed
steffahn opened this issue Feb 19, 2021 · 1 comment · Fixed by #82707
Assignees
Labels
A-const-eval Area: constant evaluation (mir interpretation) A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` F-generic_const_exprs `#![feature(generic_const_exprs)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@steffahn
Copy link
Member

steffahn commented Feb 19, 2021

#![feature(const_generics)]
#![feature(const_evaluatable_checked)]
#![allow(incomplete_features)]

trait Foo {}

fn f<T: Foo>() {}

impl<T> Foo for T
where
    [(); std::mem::size_of::<T>()]:
{}

Note that the above code compiles without the function f, so the trait impl itself is valid. Also, obviously, it compiles without
the impl. Adding an impl should not be a breaking change like that. While adding a blanket impl is a breaking change, AFAIR it isn’t for sealed traits; and anyways, a similar error occurs when T is replaced by Struct<T>, like this.

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error: unconstrained generic constant
  --> src/lib.rs:7:9
   |
7  | fn f<T: Foo>() {}
   |         ^^^
   |
help: try adding a `where` bound using this expression: `where [u8; std::mem::size_of::<T>()]: Sized`
  --> src/lib.rs:11:10
   |
11 |     [(); std::mem::size_of::<T>()]:
   |          ^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

error: could not compile `playground`

To learn more, run the command again with --verbose.

@rustbot modify labels: F-const_evaluatable_checked, T-compiler, C-bug, requires-nightly, F-const_generics

@rustbot rustbot added C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 19, 2021
@JohnTitor JohnTitor added A-const-eval Area: constant evaluation (mir interpretation) A-const-generics Area: const generics (parameters and arguments) labels Feb 23, 2021
@BoxyUwU
Copy link
Member

BoxyUwU commented Mar 1, 2021

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: constant evaluation (mir interpretation) A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` F-generic_const_exprs `#![feature(generic_const_exprs)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants