-
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
Broken code after 2017-09-30 nightly #45142
Comments
Notice that if I change the inner try_from call and call the function fn a_function<'a, R: io::Read>(_: &'a mut EventReader<R>) {} everything is fine. The way I understand both calls should work the same way. |
Changing a_function to fn a_function<'a, R: io::Read>(value: &'a mut EventReader<R>) -> Result<Other, ()> {
Other::try_from(value)
} makes everything work. So I believe this is actually a bug. |
Most likely caused by #43880 |
I think what is happening is that we are no longer inserting the auto-coercion because of the inner details of how method calls are working after #43880 -- i.e., we used to effectively pass @pedrohjordao if you rewrite to |
triage: P-high Calling P-high -- we should decide if we plan to fix. cc @arielb1 |
@nikomatsakis huum, I think I get the reasoning behind what you're saying about the change, but I do hope you decide to fix it or make a really nice compiler error pointing to the correct call. Anyway, it might be my sleepy brain making me confuse, but there might still be something wrong. What you said still doesn't work: https://play.rust-lang.org/?gist=5d5fc92da3270bf04736f943e8f236a5&version=undefined |
That's because you need |
I can't get this code as written to compile with any version of rustc. |
Are you sure? Not even the nightly I said?
Em qui, 2 de nov de 2017 19:38, Ariel Ben-Yehuda <notifications@github.com>
escreveu:
I can't get this code as written to compile with *any* version of rustc.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#45142 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFkDZMOaatqwPWvdFA3HDsPD5JgOtBYEks5syjZYgaJpZM4Pyx9Z>
.
--
Att.
Pedro Jordão
|
I tried again and it worked. |
Minimal example (you can use the actual struct Test;
struct EventReader<R>(R);
impl<'a, R> TryFrom<&'a mut EventReader<R>> for Test {
type Error = ();
fn try_from(value: &'a mut EventReader<R>) -> Result<Self, Self::Error> {
Other::try_from(value);
Other::try_from(value);
Ok(Test {})
}
}
struct Other;
pub trait TryFrom<T>: Sized {
/// The type returned in the event of a conversion error.
type Error;
/// Performs the conversion.
fn try_from(value: T) -> Result<Self, Self::Error>;
}
impl<'a, R> TryFrom<&'a mut EventReader<R>> for Other {
type Error = ();
fn try_from(value: &'a mut EventReader<R>) -> Result<Self, Self::Error> {
unimplemented!()
}
}
pub enum Infallible {}
#[cfg(error)]
impl<T, U> TryFrom<U> for T where T: From<U> {
type Error = Infallible;
fn try_from(value: U) -> Result<Self, Self::Error> {
Ok(T::from(value))
}
}
#[cfg(not(error))]
impl<'a, T> TryFrom<&'a str> for T where T: std::str::FromStr
{
type Error = <T as std::str::FromStr>::Err;
fn try_from(s: &'a str) -> Result<T, Self::Error> {
std::str::FromStr::from_str(s)
}
}
fn main() {} |
This looks like a change in an unstable library interface, let's see T-libs opinion on this. |
cc @rust-lang/libs |
Possible fixes are
|
Is this final? I get why these solutions would fix the error, but I think
the way it worked before is just more intuitive.
Also, if it is final, could the compiler give a better message?
Em qui, 2 de nov de 2017 20:11, Ariel Ben-Yehuda <notifications@github.com>
escreveu:
@pedrohjordao <https://github.com/pedrohjordao>
Possible fixes are
1. <Other as TryFrom<&mut _>>::try_from(value)
2. Other::try_from(&mut *value)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#45142 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFkDZHjZhNsCI4m0nVe3vvqDkD-J8Xc9ks5syj39gaJpZM4Pyx9Z>
.
--
Att.
Pedro Jordão
|
This is not a regression in the compiler but rather a new impl that was added to I don't think we'll revert the impl we added to fix this use-case - it's an unstable trait and therefore changes are to be expected, and even if it was stable we very rarely revert new impls because of inference difficulties such as this. However, I think that NLL (technically, MIR borrowck) will allow us to unify borrows and moves of mutable references and therefore to avoid this problem, so it is not final in that sense. But don't count on that. |
Alright, that's good enough for me.
Em qui, 2 de nov de 2017 às 20:29, Ariel Ben-Yehuda <
notifications@github.com> escreveu:
@pedrohjordao <https://github.com/pedrohjordao>
This is not a regression in the compiler but rather a new impl that was
added to TryFrom, therefore there's no simple compiler fix we can write
to make this work.
I don't think we'll revert the impl we added to fix this use-case - it's
an unstable trait and therefore changes are to be expected, and even if it
was stable we *very rarely* revert new impls because of inference
difficulties such as this.
However, I think that NLL (technically, MIR borrowck) will allow us to
unify borrows and moves of mutable references and therefore to avoid this
problem, so it is not "final* in that sense.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#45142 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFkDZIgHoqMX4-898BC-szwGcd_kN9oZks5sykJBgaJpZM4Pyx9Z>
.
--
Att.
Pedro Jordão
|
The minimal example compiles fine on current stable. |
The aforementioned "minimal example" used cfg blocks to include both working and non-working variants. Here's a modified version that makes the non-working one the default, rather than vice versa: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2015&gist=170ae503a6bd8d2cda4081b65fba6e3c AFAICT, the non-working one still errors. I haven't read the thread carefully yet, but I think the intention of the "minimal example" as written is that the non-working one should in fact work... |
Looking at this (after a long time of it lying fallow), I'm not sure if the "minimal example" that @arielb1 provided above is actually illustrating the bug described here, because (I think) the error from ariel's example happens in every Rust version going back to version 1.0.6
I'm going to try to go back to the original example filed on this bug to double-check what the story is. |
Okay, when I look at the original example from the bug, I get the following diagnostic:
As @nikomatsakis and @arielb1 have previously stated, we are not likely to attempt to start re-inserting the auto-reborrows in this case like we used to before #43880. However, I find it interesting that niko and ariel were initially suggesting this work-around: But it seems much more concise to just inject the reborrow ourselves into the source, which was ariel's second suggestion above: Furthermore, it seems entirely doable for us to extend the diagnostic above to include a suggestion to try doing just that, as a way to avoid moving a I'm going to file a new bug (with a reduced example) requesting that change to the diangostic. After that's been filed, I'll close this as not-a-bug. |
Filed issue #62112 for extending the diagnostic. Closing this as not-a-bug. |
The following code was working until the 2017-09-30 nightly:
Playground
Maybe it's catching something I'm not seeing. If that's the case maybe someone could explain it to me?
The text was updated successfully, but these errors were encountered: