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 upMethods in impls allowed more restrictive lifetime bounds than in the trait. #18937
Comments
huonw
added
the
I-ICE
label
Dec 12, 2014
This comment has been minimized.
This comment has been minimized.
|
tl;dr: this bug still reproduces but no longer causes an ICE Hopefully I updated @eddyb's code properly. This compiles and executes fine. #![feature(core, hash)]
use std::hash::{hash, SipHasher};
trait Foo {
fn foo<T>(self) -> u64;
}
impl Foo for () {
fn foo<T: 'static>(self) -> u64 {
// ^^^^^^^ this should cause an error, the bound is missing from the
// method definition in the trait, and calls are checked against that.
hash::<_, SipHasher>(unsafe{ &std::intrinsics::type_id::<&'static T>() })
}
}
fn main() {
println!("{}", ().foo::<&()>());
}
|
ghost
added
the
E-needstest
label
Apr 3, 2015
This comment has been minimized.
This comment has been minimized.
ghost
commented
Apr 3, 2015
|
@JustAPerson Thanks! Marking as |
nikomatsakis
removed
the
E-needstest
label
Apr 6, 2015
This comment has been minimized.
This comment has been minimized.
|
triage: P-backcompat-lang (1.0) I'm removing the E-needstest label because there is still a bug here -- actually ICEing is better than accepting an illegal program. That said, this may be a dup of #22779 -- although I suspect it is somewhat different. I'm going to triage it as 1.0 and try to fix it. |
nikomatsakis
self-assigned this
Apr 6, 2015
rust-highfive
added
the
P-backcompat-lang
label
Apr 6, 2015
rust-highfive
added this to the 1.0 milestone
Apr 6, 2015
brson
added
the
P-high
label
Apr 29, 2015
brson
removed this from the 1.0 milestone
Apr 29, 2015
brson
removed
the
P-backcompat-lang
label
Apr 29, 2015
This comment has been minimized.
This comment has been minimized.
|
Still broken after the fix of #22779 (http://is.gd/rZ0MgK) |
This comment has been minimized.
This comment has been minimized.
|
So I know what the problem is here, but fixing it is a bit annoying due to the way our contexts are structured (we're not processing the fulfillment context's "region obligations" list). I've been wanting to do some restructuring here that would help, I'll look into that. (The very existence of the "region obligations" list is actually a demonstration of the problem.) |
This comment has been minimized.
This comment has been minimized.
|
cc me |
This comment has been minimized.
This comment has been minimized.
stevenblenkinsop
commented
Jul 19, 2015
|
Ran into an example that creates unsoundness and doesn't use unsafe. I think it's ultimately the same issue: https://play.rust-lang.org/?gist=25b7461083e5ee9b3415&version=nightly |
arielb1
added
the
I-unsound 💥
label
Oct 1, 2015
arielb1
referenced this issue
Oct 23, 2015
Closed
Some additional bounds on implemented trait methods are permitted, but not respected #29250
alexcrichton
referenced this issue
Feb 23, 2016
Closed
Can access invalid memory and cause sigsegv using safe Rust #31852
nikomatsakis
referenced this issue
Mar 7, 2016
Closed
covariant method return types on trait impls? #15687
This comment has been minimized.
This comment has been minimized.
vacavaca
commented
Jun 14, 2016
|
Is it planned to be fixed in stable? PS just another example with use after free in safe code from dup issue: |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis said he will look at this when he comes back from vacation. |
brson
added
A-typesystem
A-traits
T-compiler
labels
Jun 23, 2016
This comment has been minimized.
This comment has been minimized.
|
@rust-lang/compiler Can you reaffirm this is P-high and somebody is on it? Maybe this can be mentored? |
This comment has been minimized.
This comment has been minimized.
|
@sanxiyn Says they may be able to do this with some mentoring! |
apasel422
referenced this issue
Aug 16, 2016
Closed
Implementing a trait allows changing lifetime requirements, leading to memory corruption #35730
This comment has been minimized.
This comment has been minimized.
|
I've just closed #35730 as a dupe of this which has another example of a segfault related to this we believe. Renominating as this came up again, unfortunately... |
alexcrichton
added
the
I-nominated
label
Aug 16, 2016
This comment has been minimized.
This comment has been minimized.
|
triage: P-high |
rust-highfive
added
P-high
and removed
I-nominated
P-medium
labels
Aug 18, 2016
nikomatsakis
assigned
jroesch
Aug 18, 2016
brson
added
the
E-hard
label
Aug 25, 2016
This comment has been minimized.
This comment has been minimized.
|
OK, so @jroesch and I implemented an initial fix for this (finally). I did a crater run with the following results:
https://gist.github.com/nikomatsakis/cba00297c8659f71740b8e45dad07137 That's not too bad. I want to dig into those results some more, but I'm hoping we can get away w/o a warning period on this one -- it would be a real pain to support! |
This comment has been minimized.
This comment has been minimized.
|
(It may also be worth investing a bit of energy in the error messages, which do not currently hint at the fact that the impl is imposing more requirements than the trait.) |
This comment has been minimized.
This comment has been minimized.
|
This appears to be broken by the fix: pub trait Leak<T : ?Sized> {
fn leak<'a>(self) -> &'a T where T: 'a;
}
impl<T> Leak<[T]> for Vec<T> {
fn leak<'a>(mut self) -> &'a [T] where [T]: 'a {
let r: *mut [T] = &mut self[..];
std::mem::forget(self);
unsafe { &mut *r }
}
}
fn main() {
println!("Hello, world!");
}error[E0309]: the parameter type `T` may not live long enough
--> src/lib.rs:45:5
|
45 | fn leak<'a>(mut self) -> &'a [T] where [T]: 'a {
| ^
|
= help: consider adding an explicit lifetime bound `T: 'a`...
note: ...so that the type `[T]` will meet its required lifetime bounds
--> src/lib.rs:45:5
|
45 | fn leak<'a>(mut self) -> &'a [T] where [T]: 'a {
| ^ |
This comment has been minimized.
This comment has been minimized.
|
@arielb1 I feel that is an orthogonal issue. It is true that this code no longer compiles, and that it would be nice and safe if it did compile, but it is not true that it should compile with the current state of rustc's reasoning. That is, I think we should indeed deduce that if Now, one could argue -- and I might agree -- that we should try to fix that oversight at the same time as applying this path. I think it'd be fairly straightforward to do, really, though it probably wants an RFC. I think @alexcrichton ran into this limitation in futures in some other setting. |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis do you think you two are still making fwd progress here, or should we delegate? |
This comment has been minimized.
This comment has been minimized.
|
Got distracted but I now have a local branch that I think both rejects the original case but accepts this case. I have to press on a bit more. The key change though is to expand on things like |
This comment has been minimized.
This comment has been minimized.
|
Argh. This is frustrating. So I put in some work into the error messages, which now look like this: lunch-box. rustc --stage1 region-unrelated.rs
error[E0276]: impl has stricter requirements than trait
--> region-unrelated.rs:21:5
|
16 | fn foo() where T: 'a;
| --------------------- definition of `foo` from trait
...
21 | fn foo() where V: 'a { }
| ^^^^^^^^^^^^^^^^^^^^^^^^ impl has extra requirement `V: 'a`
error: aborting due to previous errorI am trying to turn these into future-compatibility lints, but the current infrastructure (e.g., |
This comment has been minimized.
This comment has been minimized.
|
Update: I now have the lints mostly working, though I'm still refactoring the changes I made to that end. |
This was referenced Oct 14, 2016
brson
unassigned
jroesch
Oct 20, 2016
Stebalien
referenced this issue
Oct 26, 2016
Closed
Reference outlives the value it points to (segfault) #37418
bors
added a commit
that referenced
this issue
Nov 2, 2016
bors
added a commit
that referenced
this issue
Nov 3, 2016
bors
added a commit
that referenced
this issue
Nov 3, 2016
This comment has been minimized.
This comment has been minimized.
|
Pr enqueud #37167 |
eddyb commentedNov 13, 2014
cc @nikomatsakis