Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Jul 2, 2020
1 parent a560a95 commit 831c0df
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/test/ui/const-generics/unused-substs/unused-substs-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![feature(const_generics)] //~ WARN the feature `const_generics` is incomplete
trait Bar<const M: usize> {}
impl<const N: usize> Bar<N> for A<{ 6 + 1 }> {}

struct A<const N: usize>
where
A<N>: Bar<N>;

fn main() {
let _ = A;
//~^ ERROR mismatched types
}
26 changes: 26 additions & 0 deletions src/test/ui/const-generics/unused-substs/unused-substs-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#![feature(const_generics)] //~ WARN the feature `const_generics` is incomplete

// The goal is is to get an unevaluated const `ct` with a `Ty::Infer(TyVar(_#1t)` subst.
//
// If we are then able to infer `ty::Infer(TyVar(_#1t) := Ty<ct>` we introduced an
// artificial inference cycle.
struct Foo<const N: usize>;

trait Bind<T> {
fn bind() -> (T, Self);
}

// `N` has to be `ConstKind::Unevaluated`.
impl<T> Bind<T> for Foo<{ 6 + 1 }> {
fn bind() -> (T, Self) {
(panic!(), Foo)
}
}

fn main() {
let (mut t, foo) = Foo::bind();
// `t` is `ty::Infer(TyVar(_#1t))`
// `foo` contains `ty::Infer(TyVar(_#1t))` in its substs
t = foo;
//~^ ERROR mismatched types
}
18 changes: 18 additions & 0 deletions src/test/ui/const-generics/unused-substs/unused-substs-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/unused-substs-2.rs:1:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information

error[E0308]: mismatched types
--> $DIR/unused-substs-2.rs:24:9
|
LL | t = foo;
| ^^^ cyclic type of infinite size

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0308`.
18 changes: 18 additions & 0 deletions src/test/ui/const-generics/unused-substs/unused-substs-3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

#![feature(const_generics)] //~ WARN the feature `const_generics` is incomplete

// The goal is is to get an unevaluated const `ct` with a `Ty::Infer(TyVar(_#1t)` subst.
//
// If we are then able to infer `ty::Infer(TyVar(_#1t) := Ty<ct>` we introduced an
// artificial inference cycle.
fn bind<T>() -> (T, [u8; 6 + 1]) {
todo!()
}

fn main() {
let (mut t, foo) = bind();
// `t` is `ty::Infer(TyVar(_#1t))`
// `foo` contains `ty::Infer(TyVar(_#1t))` in its substs
t = foo;
//~^ ERROR mismatched types
}
21 changes: 21 additions & 0 deletions src/test/ui/const-generics/unused-substs/unused-substs-3.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/unused-substs-3.rs:2:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information

error[E0308]: mismatched types
--> $DIR/unused-substs-3.rs:16:9
|
LL | t = foo;
| ^^^
| |
| cyclic type of infinite size
| help: try using a conversion method: `foo.to_vec()`

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0308`.

0 comments on commit 831c0df

Please sign in to comment.