Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some regression tests #77741

Merged
merged 8 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions src/test/ui/associated-type-bounds/issue-70292.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// check-pass

#![feature(associated_type_bounds)]

fn foo<F>(_: F)
where
F: for<'a> Trait<Output: 'a>,
matthewjasper marked this conversation as resolved.
Show resolved Hide resolved
{
}

trait Trait {
type Output;
}

impl<T> Trait for T {
type Output = ();
}

fn main() {
foo(());
}
9 changes: 9 additions & 0 deletions src/test/ui/associated-type-bounds/issue-71443-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![feature(associated_type_bounds)]

struct Incorrect;

fn hello<F: for<'a> Iterator<Item: 'a>>() {
Incorrect //~ERROR: mismatched types
}

fn main() {}
11 changes: 11 additions & 0 deletions src/test/ui/associated-type-bounds/issue-71443-1.stderr
Original file line number Diff line number Diff line change
@@ -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`.
11 changes: 11 additions & 0 deletions src/test/ui/associated-type-bounds/issue-71443-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// check-pass

#![feature(associated_type_bounds)]

fn hello<'b, F>()
where
for<'a> F: Iterator<Item: 'a> + 'b,
{
}

fn main() {}
41 changes: 41 additions & 0 deletions src/test/ui/associated-types/issue-54108.rs
Original file line number Diff line number Diff line change
@@ -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 {});
}
18 changes: 18 additions & 0 deletions src/test/ui/associated-types/issue-54108.stderr
Original file line number Diff line number Diff line change
@@ -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`.
17 changes: 17 additions & 0 deletions src/test/ui/associated-types/issue-65934.rs
Original file line number Diff line number Diff line change
@@ -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() {}
33 changes: 33 additions & 0 deletions src/test/ui/impl-trait/issues/issue-65581.rs
Original file line number Diff line number Diff line change
@@ -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() {}
15 changes: 15 additions & 0 deletions src/test/ui/type-alias-impl-trait/issue-52843.rs
Original file line number Diff line number Diff line change
@@ -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();
}
14 changes: 14 additions & 0 deletions src/test/ui/type-alias-impl-trait/issue-52843.stderr
Original file line number Diff line number Diff line change
@@ -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`.
15 changes: 15 additions & 0 deletions src/test/ui/unboxed-closures/issue-53448.rs
Original file line number Diff line number Diff line change
@@ -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);
}
20 changes: 20 additions & 0 deletions src/test/ui/unboxed-closures/issue-53448.stderr
Original file line number Diff line number Diff line change
@@ -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`.