Auto merge of #77741 - JohnTitor:add-tests, r=matthewjasper

Add some regression tests

They're fixed since nightly-2020-10-07:
Closes #52843
Closes #53448
Closes #54108
Closes #65581
Closes #65934
Closes #70292
Closes #71443
This commit is contained in:
bors 2020-10-14 06:43:10 +00:00
commit 5565241f65
13 changed files with 226 additions and 1 deletions

View File

@ -72,7 +72,7 @@ impl<'tcx> Bounds<'tcx> {
.iter()
.map(|&(region_bound, span)| {
let outlives = ty::OutlivesPredicate(param_ty, region_bound);
(ty::Binder::dummy(outlives).to_predicate(tcx), span)
(ty::Binder::bind(outlives).to_predicate(tcx), span)
})
.chain(self.trait_bounds.iter().map(|&(bound_trait_ref, span, constness)| {
let predicate = bound_trait_ref.with_constness(constness).to_predicate(tcx);

View File

@ -0,0 +1,21 @@
// check-pass
#![feature(associated_type_bounds)]
fn foo<F>(_: F)
where
F: for<'a> Trait<Output: 'a>,
{
}
trait Trait {
type Output;
}
impl<T> Trait for T {
type Output = ();
}
fn main() {
foo(());
}

View File

@ -0,0 +1,9 @@
#![feature(associated_type_bounds)]
struct Incorrect;
fn hello<F: for<'a> Iterator<Item: 'a>>() {
Incorrect //~ERROR: mismatched types
}
fn main() {}

View File

@ -0,0 +1,11 @@
error[E0308]: mismatched types
--> $DIR/issue-71443-1.rs:6:5
|
LL | fn hello<F: for<'a> Iterator<Item: 'a>>() {
| - help: try adding a return type: `-> Incorrect`
LL | Incorrect
| ^^^^^^^^^ expected `()`, found struct `Incorrect`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.

View File

@ -0,0 +1,11 @@
// check-pass
#![feature(associated_type_bounds)]
fn hello<'b, F>()
where
for<'a> F: Iterator<Item: 'a> + 'b,
{
}
fn main() {}

View File

@ -0,0 +1,41 @@
use std::ops::Add;
pub trait Encoder {
type Size: Add<Output = Self::Size>;
fn foo(&self) -> Self::Size;
}
pub trait SubEncoder: Encoder {
type ActualSize;
fn bar(&self) -> Self::Size;
}
impl<T> Encoder for T
where
T: SubEncoder,
{
type Size = <Self as SubEncoder>::ActualSize;
//~^ ERROR: cannot add `<T as SubEncoder>::ActualSize` to `<T as SubEncoder>::ActualSize`
fn foo(&self) -> Self::Size {
self.bar() + self.bar()
}
}
pub struct UnitEncoder;
impl SubEncoder for UnitEncoder {
type ActualSize = ();
fn bar(&self) {}
}
pub fn fun<R: Encoder>(encoder: &R) {
encoder.foo();
}
fn main() {
fun(&UnitEncoder {});
}

View File

@ -0,0 +1,18 @@
error[E0277]: cannot add `<T as SubEncoder>::ActualSize` to `<T as SubEncoder>::ActualSize`
--> $DIR/issue-54108.rs:19:5
|
LL | type Size: Add<Output = Self::Size>;
| ------------------------ required by this bound in `Encoder::Size`
...
LL | type Size = <Self as SubEncoder>::ActualSize;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `<T as SubEncoder>::ActualSize + <T as SubEncoder>::ActualSize`
|
= help: the trait `Add` is not implemented for `<T as SubEncoder>::ActualSize`
help: consider further restricting the associated type
|
LL | T: SubEncoder, <T as SubEncoder>::ActualSize: Add
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

View File

@ -0,0 +1,17 @@
// check-pass
trait Trait {
type Assoc;
}
impl Trait for () {
type Assoc = ();
}
fn unit() -> impl Into<<() as Trait>::Assoc> {}
pub fn ice() {
Into::into(unit());
}
fn main() {}

View File

@ -0,0 +1,33 @@
// check-pass
#![allow(dead_code)]
trait Trait1<T, U> {
fn f1(self) -> U;
}
trait Trait2 {
type T;
type U: Trait2<T = Self::T>;
fn f2(f: impl FnOnce(&Self::U));
}
fn f3<T: Trait2>() -> impl Trait1<T, T::T> {
Struct1
}
struct Struct1;
impl<T: Trait2> Trait1<T, T::T> for Struct1 {
fn f1(self) -> T::T {
unimplemented!()
}
}
fn f4<T: Trait2>() {
T::f2(|_| {
f3::<T::U>().f1();
});
}
fn main() {}

View File

@ -0,0 +1,15 @@
#![feature(type_alias_impl_trait)]
type Foo<T> = impl Default;
//~^ ERROR: the trait bound `T: Default` is not satisfied
#[allow(unused)]
fn foo<T: Default>(t: T) -> Foo<T> {
t
}
struct NotDefault;
fn main() {
let _ = Foo::<NotDefault>::default();
}

View File

@ -0,0 +1,14 @@
error[E0277]: the trait bound `T: Default` is not satisfied
--> $DIR/issue-52843.rs:3:15
|
LL | type Foo<T> = impl Default;
| ^^^^^^^^^^^^ the trait `Default` is not implemented for `T`
|
help: consider restricting type parameter `T`
|
LL | type Foo<T: Default> = impl Default;
| ^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

View File

@ -0,0 +1,15 @@
#![feature(unboxed_closures)]
trait Lt<'a> {
type T;
}
impl<'a> Lt<'a> for () {
type T = ();
}
fn main() {
let v: <() as Lt<'_>>::T = ();
let f: &mut dyn FnMut<(_,), Output = ()> = &mut |_: <() as Lt<'_>>::T| {};
//~^ ERROR: the size for values of type `<() as Lt<'_>>::T` cannot be known
f(v);
}

View File

@ -0,0 +1,20 @@
error[E0277]: the size for values of type `<() as Lt<'_>>::T` cannot be known at compilation time
--> $DIR/issue-53448.rs:12:54
|
LL | let f: &mut dyn FnMut<(_,), Output = ()> = &mut |_: <() as Lt<'_>>::T| {};
| ^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `<() as Lt<'_>>::T`
= help: unsized locals are gated as an unstable feature
help: consider further restricting the associated type
|
LL | fn main() where <() as Lt<'_>>::T: Sized {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: function arguments must have a statically known size, borrowed types always have a known size
|
LL | let f: &mut dyn FnMut<(_,), Output = ()> = &mut |_: &<() as Lt<'_>>::T| {};
| ^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.