diff --git a/compiler/rustc_typeck/src/bounds.rs b/compiler/rustc_typeck/src/bounds.rs index 80f39051c587f..683707470f406 100644 --- a/compiler/rustc_typeck/src/bounds.rs +++ b/compiler/rustc_typeck/src/bounds.rs @@ -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); diff --git a/src/test/ui/associated-type-bounds/issue-70292.rs b/src/test/ui/associated-type-bounds/issue-70292.rs new file mode 100644 index 0000000000000..945d7688ce65f --- /dev/null +++ b/src/test/ui/associated-type-bounds/issue-70292.rs @@ -0,0 +1,21 @@ +// check-pass + +#![feature(associated_type_bounds)] + +fn foo(_: F) +where + F: for<'a> Trait, +{ +} + +trait Trait { + type Output; +} + +impl Trait for T { + type Output = (); +} + +fn main() { + foo(()); +} diff --git a/src/test/ui/associated-type-bounds/issue-71443-1.rs b/src/test/ui/associated-type-bounds/issue-71443-1.rs new file mode 100644 index 0000000000000..5d2a3e6cbad12 --- /dev/null +++ b/src/test/ui/associated-type-bounds/issue-71443-1.rs @@ -0,0 +1,9 @@ +#![feature(associated_type_bounds)] + +struct Incorrect; + +fn hello Iterator>() { + Incorrect //~ERROR: mismatched types +} + +fn main() {} diff --git a/src/test/ui/associated-type-bounds/issue-71443-1.stderr b/src/test/ui/associated-type-bounds/issue-71443-1.stderr new file mode 100644 index 0000000000000..a9459ee743283 --- /dev/null +++ b/src/test/ui/associated-type-bounds/issue-71443-1.stderr @@ -0,0 +1,11 @@ +error[E0308]: mismatched types + --> $DIR/issue-71443-1.rs:6:5 + | +LL | fn hello Iterator>() { + | - 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`. diff --git a/src/test/ui/associated-type-bounds/issue-71443-2.rs b/src/test/ui/associated-type-bounds/issue-71443-2.rs new file mode 100644 index 0000000000000..813dcd60ad105 --- /dev/null +++ b/src/test/ui/associated-type-bounds/issue-71443-2.rs @@ -0,0 +1,11 @@ +// check-pass + +#![feature(associated_type_bounds)] + +fn hello<'b, F>() +where + for<'a> F: Iterator + 'b, +{ +} + +fn main() {} diff --git a/src/test/ui/associated-types/issue-54108.rs b/src/test/ui/associated-types/issue-54108.rs new file mode 100644 index 0000000000000..87f67ce4b527a --- /dev/null +++ b/src/test/ui/associated-types/issue-54108.rs @@ -0,0 +1,41 @@ +use std::ops::Add; + +pub trait Encoder { + type Size: Add; + + fn foo(&self) -> Self::Size; +} + +pub trait SubEncoder: Encoder { + type ActualSize; + + fn bar(&self) -> Self::Size; +} + +impl Encoder for T +where + T: SubEncoder, +{ + type Size = ::ActualSize; + //~^ ERROR: cannot add `::ActualSize` to `::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(encoder: &R) { + encoder.foo(); +} + +fn main() { + fun(&UnitEncoder {}); +} diff --git a/src/test/ui/associated-types/issue-54108.stderr b/src/test/ui/associated-types/issue-54108.stderr new file mode 100644 index 0000000000000..927a2de996561 --- /dev/null +++ b/src/test/ui/associated-types/issue-54108.stderr @@ -0,0 +1,18 @@ +error[E0277]: cannot add `::ActualSize` to `::ActualSize` + --> $DIR/issue-54108.rs:19:5 + | +LL | type Size: Add; + | ------------------------ required by this bound in `Encoder::Size` +... +LL | type Size = ::ActualSize; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `::ActualSize + ::ActualSize` + | + = help: the trait `Add` is not implemented for `::ActualSize` +help: consider further restricting the associated type + | +LL | T: SubEncoder, ::ActualSize: Add + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/associated-types/issue-65934.rs b/src/test/ui/associated-types/issue-65934.rs new file mode 100644 index 0000000000000..e17b11c5eae1c --- /dev/null +++ b/src/test/ui/associated-types/issue-65934.rs @@ -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() {} diff --git a/src/test/ui/impl-trait/issues/issue-65581.rs b/src/test/ui/impl-trait/issues/issue-65581.rs new file mode 100644 index 0000000000000..af65b79d3e838 --- /dev/null +++ b/src/test/ui/impl-trait/issues/issue-65581.rs @@ -0,0 +1,33 @@ +// check-pass + +#![allow(dead_code)] + +trait Trait1 { + fn f1(self) -> U; +} + +trait Trait2 { + type T; + type U: Trait2; + fn f2(f: impl FnOnce(&Self::U)); +} + +fn f3() -> impl Trait1 { + Struct1 +} + +struct Struct1; + +impl Trait1 for Struct1 { + fn f1(self) -> T::T { + unimplemented!() + } +} + +fn f4() { + T::f2(|_| { + f3::().f1(); + }); +} + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/issue-52843.rs b/src/test/ui/type-alias-impl-trait/issue-52843.rs new file mode 100644 index 0000000000000..b24959d720720 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/issue-52843.rs @@ -0,0 +1,15 @@ +#![feature(type_alias_impl_trait)] + +type Foo = impl Default; +//~^ ERROR: the trait bound `T: Default` is not satisfied + +#[allow(unused)] +fn foo(t: T) -> Foo { + t +} + +struct NotDefault; + +fn main() { + let _ = Foo::::default(); +} diff --git a/src/test/ui/type-alias-impl-trait/issue-52843.stderr b/src/test/ui/type-alias-impl-trait/issue-52843.stderr new file mode 100644 index 0000000000000..25db8dfabfc29 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/issue-52843.stderr @@ -0,0 +1,14 @@ +error[E0277]: the trait bound `T: Default` is not satisfied + --> $DIR/issue-52843.rs:3:15 + | +LL | type Foo = impl Default; + | ^^^^^^^^^^^^ the trait `Default` is not implemented for `T` + | +help: consider restricting type parameter `T` + | +LL | type Foo = impl Default; + | ^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/unboxed-closures/issue-53448.rs b/src/test/ui/unboxed-closures/issue-53448.rs new file mode 100644 index 0000000000000..5c82a56e77e14 --- /dev/null +++ b/src/test/ui/unboxed-closures/issue-53448.rs @@ -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); +} diff --git a/src/test/ui/unboxed-closures/issue-53448.stderr b/src/test/ui/unboxed-closures/issue-53448.stderr new file mode 100644 index 0000000000000..bece9eedc7ffa --- /dev/null +++ b/src/test/ui/unboxed-closures/issue-53448.stderr @@ -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`.