Rollup merge of #73257 - davidtwco:issue-73249-improper-ctypes-projection, r=lcnr,varkor
ty: projections in `transparent_newtype_field` Fixes #73249. This PR modifies `transparent_newtype_field` so that it handles projections with generic parameters, where `normalize_erasing_regions` would ICE.
This commit is contained in:
commit
17064dae1a
11 changed files with 299 additions and 159 deletions
21
src/test/ui/lint/lint-ctypes-73249-1.rs
Normal file
21
src/test/ui/lint/lint-ctypes-73249-1.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// check-pass
|
||||
#![deny(improper_ctypes)]
|
||||
|
||||
pub trait Foo {
|
||||
type Assoc: 'static;
|
||||
}
|
||||
|
||||
impl Foo for () {
|
||||
type Assoc = u32;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
pub fn lint_me(x: Bar<()>);
|
||||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
pub struct Bar<T: Foo> {
|
||||
value: &'static <T as Foo>::Assoc,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
29
src/test/ui/lint/lint-ctypes-73249-2.rs
Normal file
29
src/test/ui/lint/lint-ctypes-73249-2.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#![feature(type_alias_impl_trait)]
|
||||
#![deny(improper_ctypes)]
|
||||
|
||||
pub trait Baz { }
|
||||
|
||||
impl Baz for () { }
|
||||
|
||||
type Qux = impl Baz;
|
||||
|
||||
fn assign() -> Qux {}
|
||||
|
||||
pub trait Foo {
|
||||
type Assoc: 'static;
|
||||
}
|
||||
|
||||
impl Foo for () {
|
||||
type Assoc = Qux;
|
||||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
pub struct A<T: Foo> {
|
||||
x: &'static <T as Foo>::Assoc,
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
pub fn lint_me() -> A<()>; //~ ERROR: uses type `impl Baz`
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
15
src/test/ui/lint/lint-ctypes-73249-2.stderr
Normal file
15
src/test/ui/lint/lint-ctypes-73249-2.stderr
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
error: `extern` block uses type `impl Baz`, which is not FFI-safe
|
||||
--> $DIR/lint-ctypes-73249-2.rs:26:25
|
||||
|
|
||||
LL | pub fn lint_me() -> A<()>;
|
||||
| ^^^^^ not FFI-safe
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/lint-ctypes-73249-2.rs:2:9
|
||||
|
|
||||
LL | #![deny(improper_ctypes)]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
= note: opaque types have no C equivalent
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
21
src/test/ui/lint/lint-ctypes-73249-3.rs
Normal file
21
src/test/ui/lint/lint-ctypes-73249-3.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#![feature(type_alias_impl_trait)]
|
||||
#![deny(improper_ctypes)]
|
||||
|
||||
pub trait Baz { }
|
||||
|
||||
impl Baz for u32 { }
|
||||
|
||||
type Qux = impl Baz;
|
||||
|
||||
fn assign() -> Qux { 3 }
|
||||
|
||||
#[repr(C)]
|
||||
pub struct A {
|
||||
x: Qux,
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
pub fn lint_me() -> A; //~ ERROR: uses type `impl Baz`
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
15
src/test/ui/lint/lint-ctypes-73249-3.stderr
Normal file
15
src/test/ui/lint/lint-ctypes-73249-3.stderr
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
error: `extern` block uses type `impl Baz`, which is not FFI-safe
|
||||
--> $DIR/lint-ctypes-73249-3.rs:18:25
|
||||
|
|
||||
LL | pub fn lint_me() -> A;
|
||||
| ^ not FFI-safe
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/lint-ctypes-73249-3.rs:2:9
|
||||
|
|
||||
LL | #![deny(improper_ctypes)]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
= note: opaque types have no C equivalent
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
24
src/test/ui/lint/lint-ctypes-73249-4.rs
Normal file
24
src/test/ui/lint/lint-ctypes-73249-4.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// check-pass
|
||||
#![deny(improper_ctypes)]
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
trait Foo {
|
||||
type Assoc;
|
||||
}
|
||||
|
||||
impl Foo for () {
|
||||
type Assoc = PhantomData<()>;
|
||||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
struct Wow<T> where T: Foo<Assoc = PhantomData<T>> {
|
||||
x: <T as Foo>::Assoc,
|
||||
v: u32,
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
fn test(v: Wow<()>);
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
21
src/test/ui/lint/lint-ctypes-73249-5.rs
Normal file
21
src/test/ui/lint/lint-ctypes-73249-5.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#![feature(type_alias_impl_trait)]
|
||||
#![deny(improper_ctypes)]
|
||||
|
||||
pub trait Baz { }
|
||||
|
||||
impl Baz for u32 { }
|
||||
|
||||
type Qux = impl Baz;
|
||||
|
||||
fn assign() -> Qux { 3 }
|
||||
|
||||
#[repr(transparent)]
|
||||
pub struct A {
|
||||
x: Qux,
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
pub fn lint_me() -> A; //~ ERROR: uses type `impl Baz`
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
15
src/test/ui/lint/lint-ctypes-73249-5.stderr
Normal file
15
src/test/ui/lint/lint-ctypes-73249-5.stderr
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
error: `extern` block uses type `impl Baz`, which is not FFI-safe
|
||||
--> $DIR/lint-ctypes-73249-5.rs:18:25
|
||||
|
|
||||
LL | pub fn lint_me() -> A;
|
||||
| ^ not FFI-safe
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/lint-ctypes-73249-5.rs:2:9
|
||||
|
|
||||
LL | #![deny(improper_ctypes)]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
= note: opaque types have no C equivalent
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
21
src/test/ui/lint/lint-ctypes-73249.rs
Normal file
21
src/test/ui/lint/lint-ctypes-73249.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
// check-pass
|
||||
#![deny(improper_ctypes)]
|
||||
|
||||
pub trait Foo {
|
||||
type Assoc;
|
||||
}
|
||||
|
||||
impl Foo for () {
|
||||
type Assoc = u32;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
pub fn lint_me(x: Bar<()>);
|
||||
}
|
||||
|
||||
#[repr(transparent)]
|
||||
pub struct Bar<T: Foo> {
|
||||
value: <T as Foo>::Assoc,
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue