Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign up#28669 caused regression compiling pinyin crate on nightly #28853
Comments
eefriedman
referenced this issue
Oct 5, 2015
Merged
Ensure the types of methods are well-formed #28669
This comment has been minimized.
This comment has been minimized.
|
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) |
eefriedman
referenced this issue
Oct 6, 2015
Closed
Nightly regression: lifetime error with autoderef #28854
This comment has been minimized.
This comment has been minimized.
|
@jonas-schievink I think that's a different issue? Anyway, filed #28854 to track it. |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
triage: I-nominated |
rust-highfive
added
the
I-nominated
label
Oct 6, 2015
alexcrichton
added
the
T-compiler
label
Oct 6, 2015
bluss
added
the
regression-from-stable-to-nightly
label
Oct 6, 2015
This comment has been minimized.
This comment has been minimized.
|
triage: P-high |
nikomatsakis
self-assigned this
Oct 15, 2015
rust-highfive
added
P-high
and removed
I-nominated
labels
Oct 15, 2015
This comment has been minimized.
This comment has been minimized.
|
this is a duplicate of #28854. |
This comment has been minimized.
This comment has been minimized.
|
Closing as duplicate of #28854. |
nikomatsakis
closed this
Oct 21, 2015
This comment has been minimized.
This comment has been minimized.
|
Actually, re-opening, as I like the fact that @alexcrichton's test case is relatively standalone. |
nikomatsakis
reopened this
Oct 21, 2015
This comment has been minimized.
This comment has been minimized.
|
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() {} |
This comment has been minimized.
This comment has been minimized.
|
Is this on beta/stable yet? |
This was referenced Nov 21, 2015
This comment has been minimized.
This comment has been minimized.
|
This and #28854 are the same issue. The extraneous address-of operation (to As one of the |
brson
added
regression-from-stable-to-beta
and removed
regression-from-stable-to-nightly
labels
Nov 23, 2015
arielb1
added
the
I-nominated
label
Nov 25, 2015
This comment has been minimized.
This comment has been minimized.
|
nominated for discussion on |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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 comment has been minimized.
This comment has been minimized.
|
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:
|
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
Note that modifying the example to remove the return type will also make things compile: http://is.gd/6LqdTK. This is because the |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
Your explanation is right. However, in this case the correct fix is to remove the |
This comment has been minimized.
This comment has been minimized.
|
Recategorizing as T-libs instead of T-compiler due to @nikomatsakis's analysis to come up during triage. |
alexcrichton
added
T-libs
and removed
T-compiler
labels
Nov 30, 2015
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
|
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. |
alexcrichton
closed this
Dec 3, 2015
This comment has been minimized.
This comment has been minimized.
|
The PR to fix pinyin is linked to this issue, so I didn't think that was a surprise that it was fixed. |
eefriedman commentedOct 5, 2015
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 .