-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wf-check hidden types at definition site
- Loading branch information
Showing
12 changed files
with
104 additions
and
7 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
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,21 @@ | ||
//! Regression test for #114728. | ||
|
||
trait Extend<'a, 'b> { | ||
fn extend(self, _: &'a str) -> &'b str; | ||
} | ||
|
||
impl<'a, 'b> Extend<'a, 'b> for Option<&'b &'a ()> { | ||
fn extend(self, s: &'a str) -> &'b str { | ||
s | ||
} | ||
} | ||
|
||
fn boom<'a, 'b>() -> impl Extend<'a, 'b> { | ||
None::<&'_ &'_ ()> | ||
//~^ ERROR lifetime may not live long enough | ||
} | ||
|
||
fn main() { | ||
let y = boom().extend(&String::from("temporary")); | ||
println!("{}", y); | ||
} |
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-check-hidden-type.rs:14:5 | ||
| | ||
LL | fn boom<'a, 'b>() -> impl Extend<'a, 'b> { | ||
| -- -- lifetime `'b` defined here | ||
| | | ||
| lifetime `'a` defined here | ||
LL | None::<&'_ &'_ ()> | ||
| ^^^^^^^^^^^^^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` | ||
| | ||
= help: consider adding the following bound: `'a: 'b` | ||
|
||
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
31 changes: 31 additions & 0 deletions
31
tests/ui/type-alias-impl-trait/wf-check-definition-site.rs
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,31 @@ | ||
//! Regression test for #114572. | ||
//! We were inferring an ill-formed type: | ||
//! `Opaque<'a> = Static<&'a str>`, vs | ||
//! `Opaque<'a> = Static<&'static str>`. | ||
// check-pass | ||
|
||
#![feature(type_alias_impl_trait)] | ||
|
||
struct Static<T: 'static>(T); | ||
|
||
type OpaqueRet<'a> = impl Sized + 'a; | ||
fn test_return<'a>(msg: Static<&'static u8>) -> OpaqueRet<'a> { | ||
msg | ||
} | ||
|
||
type OpaqueAssign<'a> = impl Sized + 'a; | ||
fn test_assign<'a>(msg: Static<&'static u8>) -> Option<OpaqueAssign<'a>> { | ||
let _: OpaqueAssign<'a> = msg; | ||
None | ||
} | ||
|
||
// `OpaqueRef<'a, T> = Ref<'a, T>`, vs | ||
// `OpaqueRef<'a, T> = Ref<'static, T>`. | ||
trait RefAt<'a>: 'a {} | ||
struct Ref<'a, T: RefAt<'a>>(&'a T); | ||
type OpaqueRef<'a, T: RefAt<'static>> = impl Sized + 'a; | ||
fn test_trait<'a, T: RefAt<'static>>(msg: Ref<'static, T>) -> OpaqueRef<'a, T> { | ||
msg | ||
} | ||
|
||
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
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