-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent opaque types being instantiated twice with different regions …
…within the same function
- Loading branch information
Showing
17 changed files
with
298 additions
and
54 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,22 @@ | ||
#![feature(type_alias_impl_trait)] | ||
|
||
type Foo<'a> = impl Sized; | ||
|
||
fn foo<'a, 'b>(x: &'a u32, y: &'b u32) -> (Foo<'a>, Foo<'b>) { | ||
(x, y) | ||
//~^ ERROR opaque type used twice with different lifetimes | ||
} | ||
|
||
type Bar<'a, 'b> = impl std::fmt::Debug; | ||
|
||
fn bar<'x, 'y>(i: &'x i32, j: &'y i32) -> (Bar<'x, 'y>, Bar<'y, 'x>) { | ||
(i, j) | ||
//~^ ERROR opaque type used twice with different lifetimes | ||
//~| ERROR opaque type used twice with different lifetimes | ||
} | ||
|
||
fn main() { | ||
let meh = 42; | ||
let muh = 69; | ||
println!("{:?}", bar(&meh, &muh)); | ||
} |
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,47 @@ | ||
error: opaque type used twice with different lifetimes | ||
--> $DIR/lifetime_mismatch.rs:6:5 | ||
| | ||
LL | (x, y) | ||
| ^^^^^^ | ||
| | | ||
| lifetime `'a` used here | ||
| lifetime `'b` previously used here | ||
| | ||
note: if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types | ||
--> $DIR/lifetime_mismatch.rs:6:5 | ||
| | ||
LL | (x, y) | ||
| ^^^^^^ | ||
|
||
error: opaque type used twice with different lifetimes | ||
--> $DIR/lifetime_mismatch.rs:13:5 | ||
| | ||
LL | (i, j) | ||
| ^^^^^^ | ||
| | | ||
| lifetime `'x` used here | ||
| lifetime `'y` previously used here | ||
| | ||
note: if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types | ||
--> $DIR/lifetime_mismatch.rs:13:5 | ||
| | ||
LL | (i, j) | ||
| ^^^^^^ | ||
|
||
error: opaque type used twice with different lifetimes | ||
--> $DIR/lifetime_mismatch.rs:13:5 | ||
| | ||
LL | (i, j) | ||
| ^^^^^^ | ||
| | | ||
| lifetime `'y` used here | ||
| lifetime `'x` previously used here | ||
| | ||
note: if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types | ||
--> $DIR/lifetime_mismatch.rs:13:5 | ||
| | ||
LL | (i, j) | ||
| ^^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
|
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
29 changes: 25 additions & 4 deletions
29
tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr
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 |
---|---|---|
@@ -1,11 +1,32 @@ | ||
error: concrete type differs from previous defining opaque type use | ||
error: opaque type used twice with different lifetimes | ||
--> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:5 | ||
| | ||
LL | (i, i) | ||
| ^^^^^^ | ||
| | | ||
| expected `&'a i32`, got `&'b i32` | ||
| this expression supplies two conflicting concrete types for the same opaque type | ||
| lifetime `'x` used here | ||
| lifetime `'y` previously used here | ||
| | ||
note: if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types | ||
--> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:5 | ||
| | ||
LL | (i, i) | ||
| ^^^^^^ | ||
|
||
error: opaque type used twice with different lifetimes | ||
--> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:5 | ||
| | ||
LL | (i, i) | ||
| ^^^^^^ | ||
| | | ||
| lifetime `'y` used here | ||
| lifetime `'x` previously used here | ||
| | ||
note: if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types | ||
--> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:5 | ||
| | ||
LL | (i, i) | ||
| ^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
error: aborting due to 2 previous errors | ||
|
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,16 @@ | ||
//! This test checks that when checking for opaque types that | ||
//! only differ in lifetimes, we handle the case of non-generic | ||
//! regions correctly. | ||
#![feature(type_alias_impl_trait)] | ||
|
||
fn id(s: &str) -> &str { | ||
s | ||
} | ||
type Opaque<'a> = impl Sized + 'a; | ||
// The second `Opaque<'_>` has a higher kinded lifetime, not a generic parameter | ||
fn test(s: &str) -> (Opaque<'_>, impl Fn(&str) -> Opaque<'_>) { | ||
(s, id) | ||
//~^ ERROR: expected generic lifetime parameter, found `'_` | ||
} | ||
|
||
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,12 @@ | ||
error[E0792]: expected generic lifetime parameter, found `'_` | ||
--> $DIR/param_mismatch.rs:12:5 | ||
| | ||
LL | type Opaque<'a> = impl Sized + 'a; | ||
| -- this generic parameter must be used with a generic lifetime parameter | ||
... | ||
LL | (s, id) | ||
| ^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0792`. |
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,16 @@ | ||
//! This test checks that when checking for opaque types that | ||
//! only differ in lifetimes, we handle the case of non-generic | ||
//! regions correctly. | ||
#![feature(type_alias_impl_trait)] | ||
|
||
fn id(s: &str) -> &str { | ||
s | ||
} | ||
|
||
type Opaque<'a> = impl Sized + 'a; | ||
|
||
fn test(s: &str) -> (impl Fn(&str) -> Opaque<'_>, impl Fn(&str) -> Opaque<'_>) { | ||
(id, id) //~ ERROR: expected generic lifetime parameter, found `'_` | ||
} | ||
|
||
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,12 @@ | ||
error[E0792]: expected generic lifetime parameter, found `'_` | ||
--> $DIR/param_mismatch2.rs:13:5 | ||
| | ||
LL | type Opaque<'a> = impl Sized + 'a; | ||
| -- this generic parameter must be used with a generic lifetime parameter | ||
... | ||
LL | (id, id) | ||
| ^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0792`. |
Oops, something went wrong.