resolve: prohibit foreign statics w/ generics
This commit modifies resolve to disallow foreign statics that use parent generics. `improper_ctypes` is not written to support type parameters, as these are normally disallowed before the lint is run. Thus, type parameters in foreign statics must be prohibited before the lint. The only other case where this *could* have occured is in functions, but typeck prohibits this with a "foreign items may not have type parameters" error - a similar error did not exist for statics, because statics cannot have type parameters, but they can use any type parameters that are in scope (which isn't the case for functions). Signed-off-by: David Wood <david@davidtw.co>
This commit is contained in:
parent
7870050796
commit
ccbf2b76a6
8 changed files with 263 additions and 178 deletions
|
|
@ -2,9 +2,7 @@ error[E0401]: can't use generic parameters from outer function
|
|||
--> $DIR/inner-static-type-parameter.rs:6:19
|
||||
|
|
||||
LL | fn foo<T>() {
|
||||
| --- - type parameter from outer function
|
||||
| |
|
||||
| try adding a local generic parameter in this method instead
|
||||
| - type parameter from outer function
|
||||
LL | static a: Bar<T> = Bar::What;
|
||||
| ^ use of generic parameter from outer function
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
unsafe fn foo<A>() {
|
||||
extern "C" {
|
||||
static baz: *const A;
|
||||
//~^ ERROR can't use generic parameters from outer function
|
||||
}
|
||||
|
||||
let bar: *const u64 = core::mem::transmute(&baz);
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
error[E0401]: can't use generic parameters from outer function
|
||||
--> $DIR/issue-65025-extern-static-parent-generics.rs:3:28
|
||||
|
|
||||
LL | unsafe fn foo<A>() {
|
||||
| - type parameter from outer function
|
||||
LL | extern "C" {
|
||||
LL | static baz: *const A;
|
||||
| ^ use of generic parameter from outer function
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0401`.
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
|
||||
|
||||
fn f<T>() {
|
||||
extern "C" {
|
||||
static a: *const T;
|
||||
//~^ ERROR can't use generic parameters from outer function
|
||||
}
|
||||
}
|
||||
|
||||
fn g<T: Default>() {
|
||||
static a: *const T = Default::default();
|
||||
//~^ ERROR can't use generic parameters from outer function
|
||||
}
|
||||
|
||||
fn h<const N: usize>() {
|
||||
extern "C" {
|
||||
static a: [u8; N];
|
||||
//~^ ERROR can't use generic parameters from outer function
|
||||
}
|
||||
}
|
||||
|
||||
fn i<const N: usize>() {
|
||||
static a: [u8; N] = [0; N];
|
||||
//~^ ERROR can't use generic parameters from outer function
|
||||
//~^^ ERROR can't use generic parameters from outer function
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
error[E0401]: can't use generic parameters from outer function
|
||||
--> $DIR/issue-65035-static-with-parent-generics.rs:6:26
|
||||
|
|
||||
LL | fn f<T>() {
|
||||
| - type parameter from outer function
|
||||
LL | extern "C" {
|
||||
LL | static a: *const T;
|
||||
| ^ use of generic parameter from outer function
|
||||
|
||||
error[E0401]: can't use generic parameters from outer function
|
||||
--> $DIR/issue-65035-static-with-parent-generics.rs:12:22
|
||||
|
|
||||
LL | fn g<T: Default>() {
|
||||
| - type parameter from outer function
|
||||
LL | static a: *const T = Default::default();
|
||||
| ^ use of generic parameter from outer function
|
||||
|
||||
error[E0401]: can't use generic parameters from outer function
|
||||
--> $DIR/issue-65035-static-with-parent-generics.rs:18:24
|
||||
|
|
||||
LL | fn h<const N: usize>() {
|
||||
| - const parameter from outer function
|
||||
LL | extern "C" {
|
||||
LL | static a: [u8; N];
|
||||
| ^ use of generic parameter from outer function
|
||||
|
||||
error[E0401]: can't use generic parameters from outer function
|
||||
--> $DIR/issue-65035-static-with-parent-generics.rs:24:20
|
||||
|
|
||||
LL | fn i<const N: usize>() {
|
||||
| - const parameter from outer function
|
||||
LL | static a: [u8; N] = [0; N];
|
||||
| ^ use of generic parameter from outer function
|
||||
|
||||
error[E0401]: can't use generic parameters from outer function
|
||||
--> $DIR/issue-65035-static-with-parent-generics.rs:24:29
|
||||
|
|
||||
LL | fn i<const N: usize>() {
|
||||
| - const parameter from outer function
|
||||
LL | static a: [u8; N] = [0; N];
|
||||
| ^ use of generic parameter from outer function
|
||||
|
||||
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
|
||||
--> $DIR/issue-65035-static-with-parent-generics.rs:1:12
|
||||
|
|
||||
LL | #![feature(const_generics)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0401`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue