-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Nightly regression - Option::cloned method resolution #44208
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
Comments
Nominating for @rust-lang/libs. Not sure if we can do much about this -- I'd expect this not to happen, as mutability shouldn't be inferred in most cases? A smaller example would definitely be helpful. |
@Mark-Simulacrum I got one! It's a bit weird... https://play.rust-lang.org/?gist=ca256a29f753fe800b3a5673f4a7efa7&version=stable
It seems to be caused by the two impls here, as removing the second eliminates the error (which is why I was having trouble finding a small reproduction) [EDITED with smaller example. Previous] (If anyone is curious why we have |
See rust-lang/rust#44208 for context
132: Fix compile on nightly r=CAD97 a=CAD97 See rust-lang/rust#44208 for context
It looks like the actual ambiguity is cause by having implementations for both |
The libs team discussed this yesterday and @aturon volunteered to investigate this issue. In the meantime though we decided that we probably aren't going to revert. |
@aturon Any updates? This is due to land in 1.22 (which releases next week). If not, perhaps we can reassign. |
Using the case in #44208 (comment), it still causes an error on beta/nightly but not on stable:
|
Right, because stable doesn't yet have the regression -- it will once 1.22 (current beta) is released next Thursday. |
@Mark-Simulacrum thanks much for checking in. I don't have the cycles to look into this at the moment. @eddyb or @arielb1, would one of you mind? |
IIRC @arielb1 made some changes in the recent past to method resolution, not sure if they're related. |
There's more to it than just an added fn. This case should not be offered Using a reproduction case as simple as I was able to make it: https://play.rust-lang.org/?gist=73317abb09e9e9b3469eb32d6a7d2545&version=beta trait DataTable<V> {
fn find(&self, needle: char) -> Option<V>;
}
impl<'a, V> DataTable<&'a V> for &'a [(char, V)] {
fn find(&self, _: char) -> Option<&'a V> {
None
}
}
impl DataTable<()> for &'static [(char, char)] {
fn find(&self, _: char) -> Option<()> {
None
}
}
fn main() {
static TABLE: &[(char, char)] = &[('a', 'a')];
let x: Option<char> = TABLE.find('a').cloned();
} Run as is, we get
Comment out the second impl block, lines 11-15, it compiles fine. Comment out the first impl block, lines 5-9, and we get
For completion, removing the call to
The type annotation on Because the two impls Whatever the issue is, it's more than the interface evolving to have multiple options. These two options should not both be considered in this case. Something with resolution must be going wrong to suggest the |
I have made a repro case of what I believe to be the same root issue (occurring on stable) without the stdlib fn call: https://play.rust-lang.org/?gist=1d1adac4824aa2241dc1c6bd3d38f8f8&version=stable (previously https://play.rust-lang.org/?gist=0faa6d4304f76c72d6941934c02edd97&version=stable) struct Container<T> {
inner: T,
}
impl<T> Container<&'static T> {
fn do_something(&self) {
println!("Container<&'a T>::do_something");
}
}
impl<'a, T> Container<&'a mut T> {
fn do_something(&self) {
println!("Container<&'a mut T>::do_something");
}
}
trait Issue<T> {
fn make_container(&self) -> Container<T>;
}
impl<T> Issue<&'static T> for &'static T {
fn make_container(&self) -> Container<&'static T> {
Container { inner: &self }
}
}
impl Issue<()> for &'static char {
fn make_container(&self) -> Container<()> {
Container { inner: () }
}
}
fn main() {
static ARR: &char = &'a';
let _ = ARR.make_container().do_something();
} Compiling gives us:
OK, we have conflicting impls for
I can open a new issue or rewrite the OP to focus on this issue directly if desired. If someone else wants to take a go at simplifying this repro down more, please do take a stab at it; I was unable to remove anything more while still reproing this behavior. |
Given that the inference issue is preexisting for this strange case and the regression is merely from expanding the available fn on |
In (every version of) Rust, type inference does not consider active trait requirements when resolving type ambiguities, only inference variables (i.e. method lookup is done on |
@arielb1 Could we use it only in case of ambiguity? |
That would be fragile - a predicate-saatisfying method could still shadow a valid method. Inference being guided only by type variables is a nice compromise. |
I actually worked around this on a branch for rabble a few months ago but haven't merged it in. I will say, I didn't really understand what the problem was as I'm no expert in inference, but it was fixable in a hacky sort of way. https://github.com/andrewjstone/rabble/compare/histogram#diff-12d610bc541176e32ea0df8d15d0a369 |
@aturon Do you want to look into this or should we just close it? Nothing is really going to change here I think since this is on stable anyway -- might be a bug in the compiler, though. |
I believe @arielb1 believes that this isn't really a bug, and that the cause is known. As such, I'm going to close. Please comment if that's not the correct conclusion to draw from the discussion above. |
unic-ucd-normal (and thus the supercrate unic) was compiling on
rustc 1.21.0-nightly (e26688824 2017-08-27)
but fails onrustc 1.21.0-nightly (c11f689d2 2017-08-29)
. (This is with the unpublished version at https://github.com/behnam/rust-unic/tree/master/unic/ucd/normal only.)Passing build & Failing build
This appears to be #43738 (tracking) / #43705 (impl) that is causing this. Note that we do not have
#![feature(option_ref_mut_cloned)]
(it didn't exist until today(?)).Small reproduction in #44208 (comment)
The text was updated successfully, but these errors were encountered: