-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
borrowck: use implied bounds from impl header
- Loading branch information
Showing
6 changed files
with
89 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// check that associated consts can assume the impl header is well-formed. | ||
|
||
// FIXME(aliemjay): we should check the impl header is WF at the use site | ||
// but we currently don't in some cases. This is *unsound*. | ||
|
||
trait Foo<'a, 'b, T>: Sized { | ||
const EVIL: fn(u: &'b u32) -> &'a u32; | ||
} | ||
|
||
struct Evil<'a, 'b: 'a>(Option<&'a &'b ()>); | ||
|
||
impl<'a, 'b> Foo<'a, 'b, Evil<'a, 'b>> for () { | ||
const EVIL: fn(&'b u32) -> &'a u32 = { |u| u }; | ||
} | ||
|
||
struct IndirectEvil<'a, 'b: 'a>(Option<&'a &'b ()>); | ||
|
||
impl<'a, 'b> Foo<'a, 'b, ()> for IndirectEvil<'a, 'b> { | ||
const EVIL: fn(&'b u32) -> &'a u32 = { |u| u }; | ||
} | ||
|
||
impl<'a, 'b> Evil<'a, 'b> { | ||
const INHERENT_EVIL: fn(&'b u32) -> &'a u32 = { |u| u }; | ||
} | ||
|
||
// while static methods can *assume* this, we should still | ||
// *check* that it holds at the use site. | ||
|
||
fn evil<'a, 'b>(b: &'b u32) -> &'a u32 { | ||
<()>::EVIL(b) // FIXME: should be an error | ||
} | ||
|
||
fn indirect_evil<'a, 'b>(b: &'b u32) -> &'a u32 { | ||
<IndirectEvil>::EVIL(b) // FIXME: should be an error | ||
} | ||
|
||
fn inherent_evil<'a, 'b>(b: &'b u32) -> &'a u32 { | ||
<Evil>::INHERENT_EVIL(b) | ||
//~^ ERROR lifetime may not live long enough | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/wf-associated-const.rs:38:5 | ||
| | ||
LL | fn inherent_evil<'a, 'b>(b: &'b u32) -> &'a u32 { | ||
| -- -- lifetime `'b` defined here | ||
| | | ||
| lifetime `'a` defined here | ||
LL | <Evil>::INHERENT_EVIL(b) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b` | ||
| | ||
= help: consider adding the following bound: `'b: 'a` | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters