-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
#28669 caused regression compiling pinyin crate on nightly #28853
Comments
Interesting, I'm wondering if I was hit by the same regression: https://travis-ci.org/jonas-schievink/lea/builds/83592818 (code in question) (The code is horrible, so I might have been accidentally abusing a soundness bug there) |
@jonas-schievink I think that's a different issue? Anyway, filed #28854 to track it. |
At least relatively minimized: trait Borrow<T: ?Sized> {}
impl<T: ?Sized> Borrow<T> for T {}
impl<'a, T: ?Sized> Borrow<T> for &'a T {}
struct Map<K: 'static>(K);
static MAP: Map<&'static str> = Map("bar");
impl<K> Map<K> {
fn get<T>(&self, _key: &T) -> Option<&K> where K: Borrow<T> {
loop {}
}
}
fn _foo<T: FnMut(&Captures)>(_: T) {}
struct Captures<'t>(&'t str);
impl<'t> Captures<'t> {
fn at(&self) -> &'t str { loop {} }
}
pub fn foo() {
_foo(|caps| {
MAP.get(&caps.at());
})
}
fn main() {} Nominating as this code compiles on stable/beta and does not compile on nightly. Also tagging with T-compiler, but T-lang may also be appropriate. |
triage: I-nominated |
triage: P-high |
this is a duplicate of #28854. |
Closing as duplicate of #28854. |
Actually, re-opening, as I like the fact that @alexcrichton's test case is relatively standalone. |
Further minimized: trait Borrow<T: ?Sized> {}
impl<T: ?Sized> Borrow<T> for T {}
impl<'a, T: ?Sized> Borrow<T> for &'a T {}
struct Map<K: 'static>(K);
impl<K> Map<K> {
fn get<T>(&self, _key: &T) -> Option<&K> where K: Borrow<T> {
loop {}
}
}
struct Captures<'t>(&'t str);
impl<'t> Captures<'t> {
fn at(&self) -> &'t str { loop {} }
}
pub fn foo(caps: &Captures,
map: Map<&'static str>) {
map.get(&caps.at());
}
fn main() {} |
Is this on beta/stable yet? |
This and #28854 are the same issue. The extraneous address-of operation (to As one of the |
nominated for discussion on |
OK so I dug into this in some detail. This may duplicate @arielb1's explanation, but let me write out what is happening here as I understand it. The TL;DR is that I believe this regression is legitimate. First off, @alexcrichton's minimized example can be made somewhat more minimal. In particular, you only need this one impl: trait Borrow<T: ?Sized> {}
impl<T: ?Sized> Borrow<T> for T {} This is because the second impl never applies in this case. This might seem surprising, since at first glance it looks like it would: impl<'a, T: ?Sized> Borrow<T> for &'a T {} However, in this instance, the type K is So the question then is why this The reason is because the definition of So, in summary, I think this code should not have compiled in the first place. Now, all of this is At least, this is true of @alexcrichton's example. I guess we have to double check about the original from which it was derived. |
So, looking at the example from #28854: use std::collections::HashMap;
pub fn named_lints<'a>(names: &[&str],
transforms: &'a HashMap<&'static str, u32>)
-> Option<&'a u32> {
transforms.get(&names[0])
}
fn main(){} My explanation doesn't quite fit here, because it is using the standard |
This variation seems to produce the error from #28854: trait Borrow<T: ?Sized> {}
impl<T: ?Sized> Borrow<T> for T {}
struct Map<K>(K);
impl<K> Map<K> {
fn get<T>(&self, _key: &T) -> Option<&u32> where K: Borrow<T> {
loop {}
}
}
struct Captures<'t>(&'t str);
impl<'t> Captures<'t> {
fn at(&self) -> &'t str { loop {} }
}
fn foo<'a>(names: &[&str],
map: &'a Map<&'static str>)
-> Option<&'a u32> {
map.get(&names[0])
}
fn main() {} Error:
|
I think the reason this error is reported is similar. In this case, the problem is that the self type must be fn foo<'a,'b>(names: &[&'b str],
map: &'a Map<&'static str>)
-> Option<&'a u32>
where 'b: 'a
{
map.get(&names[0])
} This is somewhat unfortunate. The |
Note that modifying the example to remove the return type will also make things compile: http://is.gd/6LqdTK. This is because the |
This feels like a libs issue, and probably one we can't really fix. Some more discussion here: https://botbot.me/mozilla/rust-internals/2015-11-25/?msg=54910979&page=8 |
Your explanation is right. However, in this case the correct fix is to remove the |
Recategorizing as T-libs instead of T-compiler due to @nikomatsakis's analysis to come up during triage. |
Of course, we no longer support variance in trait matching, and I don't really have much desire to do so (it opens a big can of worms). I do agree it would address this issue though. |
The libs team discussed this during triage yesterday and the conclusion was that this is an acceptable regression as it was a bugfix in the language. The library side of things may be able to accomodate this in the future but it doesn't seem necessary at this time. @bluss also mentioned that he's updated the crate in question, so that should be taken care of. |
The PR to fix pinyin is linked to this issue, so I didn't think that was a surprise that it was fixed. |
See https://tools.taskcluster.net/task-inspector/#UFk2m1UJRweSxQNABRB84w/0 ; I've confirmed the issue locally, although I haven't managed to reduce it.
For reference, the error message:
CC @arielb1 .
The text was updated successfully, but these errors were encountered: