-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
ICE: OutputTypeParameterMismatch error under -Clink-dead-code #86703
Comments
This may be related to #86702 |
The weird thing is that even if I make sure all of the functions are used, I still do not get the error without I cannot get this ICE to occur without |
Jonas says this might be #62529 |
The ICE here is fixed by #85499, however it gets replaced with the following (incorrect) error: error: implementation of `Yokeable` is not general enough
--> foo.rs:31:7
|
31 | y.project(move |yk, _| yk.as_bytes())
| ^^^^^^^ implementation of `Yokeable` is not general enough
|
= note: `&[u8]` must implement `Yokeable<'0>`, for any lifetime `'0`...
= note: ...but `Yokeable<'_>` is actually implemented for the type `&'static [u8]` |
Reduced to this: trait Yokeable<'a> {
type Output: 'a;
}
fn project(_: for<'a> fn(<() as Yokeable<'a>>::Output)) {}
impl<'a> Yokeable<'a> for () {
type Output = ();
}
fn main() {
project(|_| {});
} looks related at least |
@lqd you're right. Here's what needs to be done, to be able to trigger the ICE with fn crash() {
project(|_| {});
}
fn main() {} which seems plausible, because that's what |
I guess it depends on your reduction goals :) If you want the minimal ICE regardless of the intent of the OP, that's valuable for tests and debugging. Equally valuable, we could reduce to try to understand why the OP doesn't compile, even without the ICE: there could be
This would likely require reducing using the CI artifacts of that PR. |
Here is a smaller reproduction of this that passes on current master but fails in #85499. It's // build-pass
#![feature(no_core)]
pub trait Yokeable<'a> {
type Output: 'a;
}
pub struct Yoke<Y: for<'a> Yokeable<'a>> {
_yokeable: Y,
}
impl<Y: for<'a> Yokeable<'a>> Yoke<Y> {
pub fn project<'this, P>(
&'this self,
_f: for<'a> fn(&'this <Y as Yokeable<'a>>::Output, &'a ()) -> <P as Yokeable<'a>>::Output,
) -> Yoke<P>
where
P: for<'a> Yokeable<'a>,
{
unimplemented!()
}
}
pub fn slice(y: Yoke<&'static ()>) -> Yoke<&'static ()> {
y.project(move |yk, _| *yk)
}
impl<'a, T> Yokeable<'a> for &'static T {
type Output = &'a T;
}
fn main() {} |
I find the -Clink-dead-code to be an interesting part of the bug as well fwiw since i don't think we have bugs like that anywhere else in this class of ICEs. |
Issue: rust-lang/rust#86703
With the latest #85499 I get the following bug on the nonminimized case.
|
@Manishearth can you run with |
|
Okay, so looks like my minimization in #86703 (comment) doesn't fully capture the issue (though that did fail and now doesn't). Looking at the @Manishearth do you think you can on getting a more minimized repro using #85499? Just getting it done to one file is enough for me to work with. That being said, I'm tempted to let this slip through the PR if I can't figure out a quick and easy solution, given that this didn't come up in the crater run and this exact issue is "gated" behind an ICE right now anyways. |
IIUC the minimized test in the OP ICEs similarly |
@jackh726 The minimized tescase in my post, if you add a
To be clear, this code is in a published crate, I've preemptively disabled the test because we run coverage tests and they fail under |
Okay, I'll look into it. no_core version of the repro// build-pass
// compile-flags: -Z verbose
#![feature(no_core)]
#[no_core]
pub trait Borrow<Borrowed: ?Sized> {
fn borrow(&self) -> &Borrowed;
}
pub trait ToOwned {
type Owned: Borrow<Self>;
fn to_owned(&self) -> Self::Owned;
}
pub enum Cow<'a, B: ?Sized + 'a>
where
B: ToOwned,
{
Borrowed(&'a B),
Owned(<B as ToOwned>::Owned),
}
pub struct Rc<T: ?Sized> {
_t: Box<T>,
}
pub unsafe trait Yokeable<'a>: 'static {
type Output: 'a;
}
pub struct Yoke<Y: for<'a> Yokeable<'a>, C> {
// must be the first field for drop order
// this will have a 'static lifetime parameter, that parameter is a lie
yokeable: Y,
cart: C,
}
impl<Y: for<'a> Yokeable<'a>> Yoke<Y, Rc<[u8]>> {
pub fn project<'this, P>(
&'this self,
f: for<'a> fn(&'this <Y as Yokeable<'a>>::Output, &'a ()) -> <P as Yokeable<'a>>::Output,
) -> Yoke<P, Rc<[u8]>>
where
P: for<'a> Yokeable<'a>,
{
unimplemented!()
}
}
pub fn slice(y: Yoke<&'static str, Rc<[u8]>>) -> Yoke<&'static [u8], Rc<[u8]>> {
y.project(move |yk, _| yk.as_bytes())
}
unsafe impl<'a, T: 'static + ToOwned + ?Sized> Yokeable<'a> for Cow<'static, T>
where
<T as ToOwned>::Owned: Sized,
{
type Output = Cow<'a, T>;
}
unsafe impl<'a, T: 'static + ?Sized> Yokeable<'a> for &'static T {
type Output = &'a T;
}
fn main() {} |
(@jackh726 Out of curiosity, is there a reason you like |
For me, yes, easier to debug. Making a test |
minimized a bit more the one in the OP (not the pub unsafe trait Yokeable<'a> {
type Output: 'a;
}
pub struct Yoke<Y: for<'a> Yokeable<'a>> {
_marker: std::marker::PhantomData<Y>,
}
impl<Y: for<'a> Yokeable<'a>> Yoke<Y> {
pub fn project<P>(
&self,
_f: for<'a> fn(&<Y as Yokeable<'a>>::Output, &'a ()) -> <P as Yokeable<'a>>::Output,
) -> Yoke<P>
where
P: for<'a> Yokeable<'a>,
{
unimplemented!()
}
}
pub fn slice(y: Yoke<&'static str>) -> Yoke<&'static [u8]> {
y.project(move |yk, _| yk.as_bytes())
}
unsafe impl<'a, T: 'static + ?Sized> Yokeable<'a> for &'static T {
type Output = &'a T;
}
fn main() {
} |
@Manishearth just pushed a fix. Can you confirm? |
@jackh726 will take me a while since that commit hasn't been trybuilt. But it looks like you checked in the reduced testcase, so that's good! |
It works, thanks! |
The original issue here is fixed by #85499, but there might be a separate problem that was exposed here. Can someone (@Manishearth?) check if that minimization fails? If so, might make sense to open a separate issue. If not, this can be closed (probably with a PR for that minimization as a test case) |
I'll have a look! I recall commenting on the normalize PR with this issue as well, and I think one of your try builds was successful in fixing this, but I should check again. Will do tomorrow. |
Well, a non -Clink-dead-code variant is fixed by #85499 (there's a test). But if the comment above is correct, there might be a -Clink-dead-code issue hiding (I don't see any normalization under binders in that repro, so I assume it's not the same error) Edit: I just realised that the comment I linked isn't a full repro, but relies on the other code that does have normalization under binders. In that case, I think this is directly covered by the test in #85499. Going to close this. |
Code
Must be compiled with
-C link-dead-code
Minimized test
Nonminimized original failure
For the nonminimized example, the tests under https://github.com/Manishearth/icu4x/blob/yoke-ice/utils/yoke/src/yoke.rs#L474-L551 fail when run under
-Clink-dead-code
Steps:
yoke-ice
branch of https://github.com/Manishearth/icu4xcd utils/yoke
RUSTDOCFLAGS="-Clink-dead-code" cargo +nightly test
Adding code that makes use of the functions defined in these tests does not change anything, e.g. the function in the first test is not being called, but if you add code that calls it like below, the ICE still happens. I'm not sure as to what role
-Clink-dead-code
has here.Meta
rustc --version --verbose
:Error output
Backtrace
The text was updated successfully, but these errors were encountered: