forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#73287 - davidtwco:issue-73251-opaque-types-…
…in-projections, r=estebank lint: normalize projections using opaque types Fixes rust-lang#73251. This PR normalizes projections which use opaque types (opaque types are otherwise linted against, which is would have previously made the test cases added in this PR fail).
- Loading branch information
Showing
6 changed files
with
127 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#![feature(type_alias_impl_trait)] | ||
#![deny(improper_ctypes)] | ||
|
||
pub trait Baz { } | ||
|
||
impl Baz for u32 { } | ||
|
||
type Qux = impl Baz; | ||
|
||
pub trait Foo { | ||
type Assoc; | ||
} | ||
|
||
impl Foo for u32 { | ||
type Assoc = Qux; | ||
} | ||
|
||
fn assign() -> Qux { 1 } | ||
|
||
extern "C" { | ||
pub fn lint_me() -> <u32 as Foo>::Assoc; //~ ERROR: uses type `impl Baz` | ||
} | ||
|
||
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,15 @@ | ||
error: `extern` block uses type `impl Baz`, which is not FFI-safe | ||
--> $DIR/lint-ctypes-73251-1.rs:21:25 | ||
| | ||
LL | pub fn lint_me() -> <u32 as Foo>::Assoc; | ||
| ^^^^^^^^^^^^^^^^^^^ not FFI-safe | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/lint-ctypes-73251-1.rs:2:9 | ||
| | ||
LL | #![deny(improper_ctypes)] | ||
| ^^^^^^^^^^^^^^^ | ||
= note: opaque types have no C equivalent | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#![feature(type_alias_impl_trait)] | ||
#![deny(improper_ctypes)] | ||
|
||
pub trait TraitA { | ||
type Assoc; | ||
} | ||
|
||
impl TraitA for u32 { | ||
type Assoc = u32; | ||
} | ||
|
||
pub trait TraitB { | ||
type Assoc; | ||
} | ||
|
||
impl<T> TraitB for T where T: TraitA { | ||
type Assoc = <T as TraitA>::Assoc; | ||
} | ||
|
||
type AliasA = impl TraitA<Assoc = u32>; | ||
|
||
type AliasB = impl TraitB<Assoc = AliasA>; | ||
|
||
fn use_of_a() -> AliasA { 3 } | ||
|
||
fn use_of_b() -> AliasB { 3 } | ||
|
||
extern "C" { | ||
pub fn lint_me() -> <AliasB as TraitB>::Assoc; //~ ERROR: uses type `impl TraitA` | ||
} | ||
|
||
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,15 @@ | ||
error: `extern` block uses type `impl TraitA`, which is not FFI-safe | ||
--> $DIR/lint-ctypes-73251-2.rs:29:25 | ||
| | ||
LL | pub fn lint_me() -> <AliasB as TraitB>::Assoc; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/lint-ctypes-73251-2.rs:2:9 | ||
| | ||
LL | #![deny(improper_ctypes)] | ||
| ^^^^^^^^^^^^^^^ | ||
= note: opaque types have no C equivalent | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// check-pass | ||
|
||
#![feature(type_alias_impl_trait)] | ||
#![deny(improper_ctypes)] | ||
|
||
pub trait Foo { | ||
type Assoc; | ||
} | ||
|
||
impl Foo for () { | ||
type Assoc = u32; | ||
} | ||
|
||
type Bar = impl Foo<Assoc = u32>; | ||
|
||
fn assign() -> Bar {} | ||
|
||
extern "C" { | ||
pub fn lint_me() -> <Bar as Foo>::Assoc; | ||
} | ||
|
||
fn main() {} |