Repository navigation
Closed
Labels
E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.Performance or correctness regression from stable to nightly.
Description
Code
I tried this code:
use std::marker::PhantomData;
pub struct MyGenericType<T> {
_marker: PhantomData<*const T>,
}
pub struct MyNonGenericType;
impl<T> From<MyGenericType<T>> for MyNonGenericType {
fn from(_: MyGenericType<T>) -> Self {
todo!()
}
}
pub trait MyTrait {
const MY_CONSTANT: i32;
}
impl<T> MyTrait for MyGenericType<T>
where
Self: Into<MyNonGenericType>,
{
const MY_CONSTANT: i32 = 1;
}
impl<T> MyGenericType<T> {
const MY_OTHER_CONSTANT: i32 = <MyGenericType<T> as MyTrait>::MY_CONSTANT;
}I expected to see this happen:
It should compile successfully.
Instead, this happened:
The compiler doesn't realize that Into<MyNonGenericType> is implemented for all MyGenericType<T> and reports an error.
error[E0277]: the trait bound `MyNonGenericType: From<MyGenericType<T>>` is not satisfied
--> src/lib.rs:27:36
|
27 | const MY_OTHER_CONSTANT: i32 = <MyGenericType<T> as MyTrait>::MY_CONSTANT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<MyGenericType<T>>` is not implemented for `MyNonGenericType`
|
= note: required because of the requirements on the impl of `Into<MyNonGenericType>` for `MyGenericType<T>`
note: required because of the requirements on the impl of `MyTrait` for `MyGenericType<T>`
--> src/lib.rs:19:9
|
19 | impl<T> MyTrait for MyGenericType<T>
| ^^^^^^^ ^^^^^^^^^^^^^^^^
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
|
26 | impl<T> MyGenericType<T> where MyNonGenericType: From<MyGenericType<T>> {
| ++++++++++++++++++++++++++++++++++++++++++++++
For more information about this error, try `rustc --explain E0277`.
error: could not compile `regression` due to previous error
Interestingly enough, removing the where Self: Into<MyNonGenericType>, bound makes this compile again.
cargo-bisect-rustc report
searched nightlies: from nightly-2021-12-01 to nightly-2021-12-25
regressed nightly: nightly-2021-12-14
searched commit range: 6bda5b3...8f117a7
regressed commit: 22f8bde
bisected with cargo-bisect-rustc v0.6.1
Host triple: x86_64-unknown-linux-gnu
Reproduce with:
cargo bisect-rustc --test-dir=. --start=2021-12-01 --end=2021-12-25 @rustbot modify labels: +regression-from-stable-to-nightly
Metadata
Metadata
Assignees
Labels
E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.Performance or correctness regression from stable to nightly.
Activity
inquisitivecrystal commentedon Dec 28, 2021
CC @fee1-dead, as the author of the relevant PR.
fee1-dead commentedon Dec 28, 2021
Fixed by #92257, this one is more interesting than the test I added in that PR, as it is stable code (but uses
impl const Into<U> for T where U: ~const From<T>), so I think we could add this one as an ui test as well.Freax13 commentedon Dec 29, 2021
I can confirm that this is fixed on the latest nightly.
fee1-dead commentedon Dec 29, 2021
It's E-needs-test because someone should add an ui test for this issue
weirane commentedon Dec 29, 2021
I'm interested in working on this. Could you tell me where should the test be added? It seems to be somewhere inside
src/test/ui.inquisitivecrystal commentedon Dec 29, 2021
I might go with
src/test/ui/traits/issue-92292.rs. There isn't really much dark magic to picking which directory to file something under; there are a few directories that aren't really used anymore, but other than that, it's just a matter of picking something that makes sense.weirane commentedon Dec 29, 2021
@rustbot claim
Rollup merge of rust-lang#92423 - weirane:ui-92292, r=fee1-dead
Auto merge of rust-lang#92434 - matthiaskrgr:rollup-m8wuq0v, r=matthi…