Rollup merge of #65191 - varkor:const-generics-test-cases, r=nikomatsakis

Add some regression tests

- Add a test for #62187.
- Clean up the directory structure in `src/test/ui/const-generics`
- Closes #64792.
- Closes #57399.
- Closes #57271.
This commit is contained in:
Tyler Mandry 2019-10-11 15:09:45 -07:00 committed by GitHub
commit 728adc446c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 142 additions and 0 deletions

View file

@ -0,0 +1,16 @@
// run-pass
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
pub trait BitLen: Sized {
const BIT_LEN: usize;
}
impl<const L: usize> BitLen for [u8; L] {
const BIT_LEN: usize = 8 * L;
}
fn main() {
let foo = <[u8; 2]>::BIT_LEN;
}

View file

@ -0,0 +1,16 @@
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/issue-62187-encountered-polymorphic-const.rs:3:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
warning: unused variable: `foo`
--> $DIR/issue-62187-encountered-polymorphic-const.rs:15:9
|
LL | let foo = <[u8; 2]>::BIT_LEN;
| ^^^ help: consider prefixing with an underscore: `_foo`
|
= note: `#[warn(unused_variables)]` on by default

View file

@ -0,0 +1,11 @@
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum BaseType {
Byte,
Char,
Double,
Float,
Int,
Long,
Short,
Boolean,
}

View file

@ -0,0 +1,24 @@
// aux-build:issue-57271-lib.rs
extern crate issue_57271_lib;
use issue_57271_lib::BaseType;
pub enum ObjectType { //~ ERROR recursive type `ObjectType` has infinite size
Class(ClassTypeSignature),
Array(TypeSignature),
TypeVariable(()),
}
pub struct ClassTypeSignature {
pub package: (),
pub class: (),
pub inner: (),
}
pub enum TypeSignature { //~ ERROR recursive type `TypeSignature` has infinite size
Base(BaseType),
Object(ObjectType),
}
fn main() {}

View file

@ -0,0 +1,25 @@
error[E0072]: recursive type `ObjectType` has infinite size
--> $DIR/issue-57271.rs:7:1
|
LL | pub enum ObjectType {
| ^^^^^^^^^^^^^^^^^^^ recursive type has infinite size
LL | Class(ClassTypeSignature),
LL | Array(TypeSignature),
| ------------- recursive without indirection
|
= help: insert indirection (e.g., a `Box`, `Rc`, or `&`) at some point to make `ObjectType` representable
error[E0072]: recursive type `TypeSignature` has infinite size
--> $DIR/issue-57271.rs:19:1
|
LL | pub enum TypeSignature {
| ^^^^^^^^^^^^^^^^^^^^^^ recursive type has infinite size
LL | Base(BaseType),
LL | Object(ObjectType),
| ---------- recursive without indirection
|
= help: insert indirection (e.g., a `Box`, `Rc`, or `&`) at some point to make `TypeSignature` representable
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0072`.

View file

@ -0,0 +1,22 @@
// run-pass
trait T {
type T;
}
impl T for i32 {
type T = u32;
}
struct S<A> {
a: A,
}
impl From<u32> for S<<i32 as T>::T> {
fn from(a: u32) -> Self {
Self { a }
}
}
fn main() {}

View file

@ -0,0 +1,8 @@
warning: field is never used: `a`
--> $DIR/issue-57399-self-return-impl-trait.rs:12:5
|
LL | a: A,
| ^^^^
|
= note: `#[warn(dead_code)]` on by default

View file

@ -0,0 +1,5 @@
struct X {}
const Y: X = X("ö"); //~ ERROR expected function, found struct `X`
fn main() {}

View file

@ -0,0 +1,15 @@
error[E0423]: expected function, found struct `X`
--> $DIR/issue-64792-bad-unicode-ctor.rs:3:14
|
LL | struct X {}
| ----------- `X` defined here
LL |
LL | const Y: X = X("ö");
| ^
| |
| did you mean `X { /* fields */ }`?
| help: a constant with a similar name exists: `Y`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0423`.