Fix tests and bootstrap

This commit is contained in:
Matthew Jasper 2020-06-29 22:15:11 +01:00
parent 2bdf723da7
commit 042464f75a
20 changed files with 182 additions and 63 deletions

View File

@ -1170,8 +1170,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
// This also instantiates nested instances of `impl Trait`.
let predicate = self.instantiate_opaque_types_in_map(&predicate);
let cause =
traits::ObligationCause::new(span, self.body_id, traits::MiscObligation);
let cause = traits::ObligationCause::new(span, self.body_id, traits::MiscObligation);
// Require that the predicate holds for the concrete type.
debug!("instantiate_opaque_types: predicate={:?}", predicate);

View File

@ -241,18 +241,27 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
traits::ObligationCause::new(self.span, self.body_id, code)
}
fn normalize(&mut self) -> Vec<traits::PredicateObligation<'tcx>> {
fn normalize(mut self) -> Vec<traits::PredicateObligation<'tcx>> {
let cause = self.cause(traits::MiscObligation);
let infcx = &mut self.infcx;
let param_env = self.param_env;
let mut obligations = Vec::with_capacity(self.out.len());
for pred in &self.out {
assert!(!pred.has_escaping_bound_vars());
for mut obligation in self.out {
assert!(!obligation.has_escaping_bound_vars());
let mut selcx = traits::SelectionContext::new(infcx);
let i = obligations.len();
let value =
traits::normalize_to(&mut selcx, param_env, cause.clone(), pred, &mut obligations);
obligations.insert(i, value);
// Don't normalize the whole obligation, the param env is either
// already normalized, or we're currently normalizing the
// param_env. Either way we should only normalize the predicate.
let normalized_predicate = traits::normalize_to(
&mut selcx,
param_env,
cause.clone(),
&obligation.predicate,
&mut obligations,
);
obligation.predicate = normalized_predicate;
obligations.insert(i, obligation);
}
obligations
}

View File

@ -1256,6 +1256,7 @@ pub fn check_type_bounds<'tcx>(
);
debug!("compare_projection_bounds: normalized predicate = {:?}", normalized_predicate);
inh.register_predicates(obligations);
inh.register_predicate(obligation);
}

View File

@ -1787,10 +1787,22 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat
}) => {
if impl_trait_fn.is_some() {
// return-position impl trait
// TODO: Investigate why we have this special case?
//
// We don't inherit predicates from the parent here:
// If we have, say `fn f<'a, T: 'a>() -> impl Sized {}`
// then the return type is `f::<'static, T>::{{opaque}}`.
//
// If we inherited the predicates of `f` then we would
// require that `T: 'static` to show that the return
// type is well-formed.
//
// The only way to have something with this opaque type
// is from the return type of the containing function,
// which will ensure that the function's predicates
// hold.
return ty::GenericPredicates { parent: None, predicates: &[] };
} else {
// type alias impl trait
// type-alias impl trait
generics
}
}

View File

@ -1,6 +1,6 @@
// revisions: rpass cfail
trait Tr {
trait Tr where Self::Arr: Sized {
type Arr;
const C: usize = 0;

View File

@ -1,6 +1,6 @@
- // MIR for `id_try` before SimplifyArmIdentity
+ // MIR for `id_try` after SimplifyArmIdentity
fn id_try(_1: std::result::Result<u8, i32>) -> std::result::Result<u8, i32> {
debug r => _1; // in scope 0 at $DIR/simplify-arm.rs:23:11: 23:12
let mut _0: std::result::Result<u8, i32>; // return place in scope 0 at $DIR/simplify-arm.rs:23:34: 23:49
@ -42,7 +42,7 @@
scope 6 {
debug self => _4; // in scope 6 at $SRC_DIR/core/src/result.rs:LL:COL
}
bb0: {
StorageLive(_2); // scope 0 at $DIR/simplify-arm.rs:24:9: 24:10
StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
@ -53,7 +53,7 @@
_5 = discriminant(_3); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
switchInt(move _5) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
}
bb1: {
- StorageLive(_10); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
- _10 = ((_3 as Ok).0: u8); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
@ -69,11 +69,11 @@
StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
}
bb2: {
unreachable; // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
}
bb3: {
- StorageLive(_6); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
- _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
@ -94,9 +94,9 @@
StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
}
bb4: {
return; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
}
}

View File

@ -1,6 +1,6 @@
- // MIR for `id_try` before SimplifyBranchSame
+ // MIR for `id_try` after SimplifyBranchSame
fn id_try(_1: std::result::Result<u8, i32>) -> std::result::Result<u8, i32> {
debug r => _1; // in scope 0 at $DIR/simplify-arm.rs:23:11: 23:12
let mut _0: std::result::Result<u8, i32>; // return place in scope 0 at $DIR/simplify-arm.rs:23:34: 23:49
@ -37,7 +37,7 @@
scope 6 {
debug self => _4; // in scope 6 at $SRC_DIR/core/src/result.rs:LL:COL
}
bb0: {
StorageLive(_2); // scope 0 at $DIR/simplify-arm.rs:24:9: 24:10
StorageLive(_3); // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
@ -49,7 +49,7 @@
- switchInt(move _5) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
+ goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:24:14: 24:15
}
bb1: {
_0 = move _3; // scope 1 at $DIR/simplify-arm.rs:25:5: 25:10
StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16
@ -57,20 +57,20 @@
- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
+ goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
}
bb2: {
- unreachable; // scope 0 at $DIR/simplify-arm.rs:24:13: 24:15
- }
-
-
- bb3: {
- _0 = move _3; // scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
- StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:24:15: 24:16
- StorageDead(_2); // scope 0 at $DIR/simplify-arm.rs:26:1: 26:2
- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
- }
-
-
- bb4: {
return; // scope 0 at $DIR/simplify-arm.rs:26:2: 26:2
}
}

View File

@ -25,7 +25,7 @@
}
scope 8 {
debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:8:14: 8:15
let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:8:13: 8:15
}
}
}

View File

@ -29,7 +29,7 @@
scope 8 {
- debug v => _8; // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
+ debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:8:14: 8:15
let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:8:13: 8:15
}
}
}

View File

@ -24,7 +24,7 @@ fn try_identity(_1: std::result::Result<u32, i32>) -> std::result::Result<u32, i
}
scope 8 {
debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/core/src/result.rs:LL:COL
let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:8:14: 8:15
let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:8:13: 8:15
}
}
}

View File

@ -0,0 +1,39 @@
// Minimized case from typenum that didn't compile because:
// - We tried to normalize the ParamEnv of the second impl
// - This requires trying to normalize `GrEq<Self, Square<Square<U>>>`
// - This requires proving `Square<Square<U>>: Sized` so that the first impl
// applies
// - This requires Providing `Square<Square<U>>` is well-formed, so that we
// can use the `Sized` bound on `Mul::Output`
// - This requires proving `Square<U>: Mul`
// - But first we tried normalizing the whole obligation, including the
// ParamEnv, which leads to a cycle error.
// check-pass
trait PrivateSquareRoot {}
pub trait Mul<Rhs = Self> {
type Output;
}
pub trait IsGreaterOrEqual<Rhs> {
type Output;
}
pub type Square<A> = <A as Mul>::Output;
pub type GrEq<A, B> = <A as IsGreaterOrEqual<B>>::Output;
impl<A, B> IsGreaterOrEqual<B> for A {
type Output = ();
}
impl<U> PrivateSquareRoot for U
where
U: Mul,
Square<U>: Mul,
GrEq<Self, Square<Square<U>>>: Sized,
{
}
fn main() {}

View File

@ -1,3 +1,4 @@
// ignore-tidy-linelength
// compile-flags: -Zsave-analysis
// This is also a regression test for #69415 and the above flag is needed.

View File

@ -1,5 +1,5 @@
error[E0658]: associated type bounds are unstable
--> $DIR/feature-gate-associated_type_bounds.rs:15:22
--> $DIR/feature-gate-associated_type_bounds.rs:16:22
|
LL | type A: Iterator<Item: Copy>;
| ^^^^^^^^^^
@ -8,7 +8,7 @@ LL | type A: Iterator<Item: Copy>;
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
error[E0658]: associated type bounds are unstable
--> $DIR/feature-gate-associated_type_bounds.rs:19:22
--> $DIR/feature-gate-associated_type_bounds.rs:20:22
|
LL | type B: Iterator<Item: 'static>;
| ^^^^^^^^^^^^^
@ -17,7 +17,7 @@ LL | type B: Iterator<Item: 'static>;
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
error[E0658]: associated type bounds are unstable
--> $DIR/feature-gate-associated_type_bounds.rs:23:20
--> $DIR/feature-gate-associated_type_bounds.rs:24:20
|
LL | struct _St1<T: Tr1<As1: Tr2>> {
| ^^^^^^^^
@ -26,7 +26,7 @@ LL | struct _St1<T: Tr1<As1: Tr2>> {
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
error[E0658]: associated type bounds are unstable
--> $DIR/feature-gate-associated_type_bounds.rs:30:18
--> $DIR/feature-gate-associated_type_bounds.rs:31:18
|
LL | enum _En1<T: Tr1<As1: Tr2>> {
| ^^^^^^^^
@ -35,7 +35,7 @@ LL | enum _En1<T: Tr1<As1: Tr2>> {
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
error[E0658]: associated type bounds are unstable
--> $DIR/feature-gate-associated_type_bounds.rs:37:19
--> $DIR/feature-gate-associated_type_bounds.rs:38:19
|
LL | union _Un1<T: Tr1<As1: Tr2>> {
| ^^^^^^^^
@ -44,7 +44,7 @@ LL | union _Un1<T: Tr1<As1: Tr2>> {
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
error[E0658]: associated type bounds are unstable
--> $DIR/feature-gate-associated_type_bounds.rs:44:37
--> $DIR/feature-gate-associated_type_bounds.rs:45:37
|
LL | type _TaWhere1<T> where T: Iterator<Item: Copy> = T;
| ^^^^^^^^^^
@ -53,7 +53,7 @@ LL | type _TaWhere1<T> where T: Iterator<Item: Copy> = T;
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
error[E0658]: associated type bounds are unstable
--> $DIR/feature-gate-associated_type_bounds.rs:47:22
--> $DIR/feature-gate-associated_type_bounds.rs:48:22
|
LL | fn _apit(_: impl Tr1<As1: Copy>) {}
| ^^^^^^^^^
@ -62,7 +62,7 @@ LL | fn _apit(_: impl Tr1<As1: Copy>) {}
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
error[E0658]: associated type bounds are unstable
--> $DIR/feature-gate-associated_type_bounds.rs:49:26
--> $DIR/feature-gate-associated_type_bounds.rs:50:26
|
LL | fn _apit_dyn(_: &dyn Tr1<As1: Copy>) {}
| ^^^^^^^^^
@ -71,7 +71,7 @@ LL | fn _apit_dyn(_: &dyn Tr1<As1: Copy>) {}
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
error[E0658]: associated type bounds are unstable
--> $DIR/feature-gate-associated_type_bounds.rs:52:24
--> $DIR/feature-gate-associated_type_bounds.rs:53:24
|
LL | fn _rpit() -> impl Tr1<As1: Copy> { S1 }
| ^^^^^^^^^
@ -80,7 +80,7 @@ LL | fn _rpit() -> impl Tr1<As1: Copy> { S1 }
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
error[E0658]: associated type bounds are unstable
--> $DIR/feature-gate-associated_type_bounds.rs:55:31
--> $DIR/feature-gate-associated_type_bounds.rs:56:31
|
LL | fn _rpit_dyn() -> Box<dyn Tr1<As1: Copy>> { Box::new(S1) }
| ^^^^^^^^^
@ -89,7 +89,7 @@ LL | fn _rpit_dyn() -> Box<dyn Tr1<As1: Copy>> { Box::new(S1) }
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
error[E0658]: associated type bounds are unstable
--> $DIR/feature-gate-associated_type_bounds.rs:58:23
--> $DIR/feature-gate-associated_type_bounds.rs:59:23
|
LL | const _cdef: impl Tr1<As1: Copy> = S1;
| ^^^^^^^^^
@ -98,7 +98,7 @@ LL | const _cdef: impl Tr1<As1: Copy> = S1;
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
error[E0658]: associated type bounds are unstable
--> $DIR/feature-gate-associated_type_bounds.rs:64:24
--> $DIR/feature-gate-associated_type_bounds.rs:65:24
|
LL | static _sdef: impl Tr1<As1: Copy> = S1;
| ^^^^^^^^^
@ -107,7 +107,7 @@ LL | static _sdef: impl Tr1<As1: Copy> = S1;
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
error[E0658]: associated type bounds are unstable
--> $DIR/feature-gate-associated_type_bounds.rs:71:21
--> $DIR/feature-gate-associated_type_bounds.rs:72:21
|
LL | let _: impl Tr1<As1: Copy> = S1;
| ^^^^^^^^^
@ -116,7 +116,7 @@ LL | let _: impl Tr1<As1: Copy> = S1;
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
--> $DIR/feature-gate-associated_type_bounds.rs:58:14
--> $DIR/feature-gate-associated_type_bounds.rs:59:14
|
LL | const _cdef: impl Tr1<As1: Copy> = S1;
| ^^^^^^^^^^^^^^^^^^^
@ -124,7 +124,7 @@ LL | const _cdef: impl Tr1<As1: Copy> = S1;
= help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
--> $DIR/feature-gate-associated_type_bounds.rs:64:15
--> $DIR/feature-gate-associated_type_bounds.rs:65:15
|
LL | static _sdef: impl Tr1<As1: Copy> = S1;
| ^^^^^^^^^^^^^^^^^^^
@ -132,7 +132,7 @@ LL | static _sdef: impl Tr1<As1: Copy> = S1;
= help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
--> $DIR/feature-gate-associated_type_bounds.rs:71:12
--> $DIR/feature-gate-associated_type_bounds.rs:72:12
|
LL | let _: impl Tr1<As1: Copy> = S1;
| ^^^^^^^^^^^^^^^^^^^
@ -140,7 +140,7 @@ LL | let _: impl Tr1<As1: Copy> = S1;
= help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable
error[E0277]: the trait bound `<<Self as _Tr3>::A as std::iter::Iterator>::Item: std::marker::Copy` is not satisfied
--> $DIR/feature-gate-associated_type_bounds.rs:15:28
--> $DIR/feature-gate-associated_type_bounds.rs:16:28
|
LL | type A: Iterator<Item: Copy>;
| ^^^^ the trait `std::marker::Copy` is not implemented for `<<Self as _Tr3>::A as std::iter::Iterator>::Item`

View File

@ -1,14 +1,16 @@
// E0277 should point exclusively at line 14, not the entire for loop span
// E0277 should point exclusively at line 6, not the entire for loop span
// ignore-tidy-linelength
fn main() {
for c in "asdf" {
//~^ ERROR `&str` is not an iterator
//~| NOTE `&str` is not an iterator
//~| HELP the trait `Iterator` is not implemented for `&str`
//~| NOTE required by `into_iter`
//~| NOTE in this expansion of desugaring of `for` loop
//~| NOTE in this expansion of desugaring of `for` loop
//~| NOTE in this expansion of desugaring of `for` loop
//~^ ERROR `&str` is not an iterator
//~| NOTE `&str` is not an iterator
//~| HELP the trait `Iterator` is not implemented for `&str`
//~| NOTE required by `into_iter`
//~| NOTE in this expansion of desugaring of `for` loop
//~| NOTE in this expansion of desugaring of `for` loop
//~| NOTE in this expansion of desugaring of `for` loop
println!();
}
}

View File

@ -1,5 +1,5 @@
error[E0277]: `&str` is not an iterator
--> $DIR/for-c-in-str.rs:4:14
--> $DIR/for-c-in-str.rs:6:14
|
LL | for c in "asdf" {
| ^^^^^^ `&str` is not an iterator; try calling `.chars()` or `.bytes()`

View File

@ -0,0 +1,8 @@
#![feature(generic_associated_types)]
use std::{future::Future, pin::Pin};
pub trait Foo {
type Bar: AsRef<()>;
fn foo(&self) -> Pin<Box<dyn Future<Output = Self::Bar> + '_>>;
}

View File

@ -0,0 +1,32 @@
// regression test for #73816
// We handled bounds differently when `feature(generic_associated_types)` was enabled
// edition:2018
// aux-build:foo_defn.rs
extern crate foo_defn;
use foo_defn::Foo;
use std::{future::Future, pin::Pin};
pub struct FooImpl;
impl Foo for FooImpl {
type Bar = ();
//~^ ERROR the trait bound `(): std::convert::AsRef<()>` is not satisfied
fn foo(&self) -> Pin<Box<dyn Future<Output = Self::Bar> + '_>> {
panic!()
}
}
async fn foo() {
bar(&FooImpl).await;
}
async fn bar<F: Foo>(foo: &F) {
foo.foo().await.as_ref();
}
fn main() {
// futures::executor::block_on(foo());
}

View File

@ -0,0 +1,14 @@
error[E0277]: the trait bound `(): std::convert::AsRef<()>` is not satisfied
--> $DIR/cross-crate-bounds.rs:15:5
|
LL | type Bar = ();
| ^^^^^^^^^^^^^^ the trait `std::convert::AsRef<()>` is not implemented for `()`
|
::: $DIR/auxiliary/foo_defn.rs:6:15
|
LL | type Bar: AsRef<()>;
| --------- required by this bound in `foo_defn::Foo::Bar`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

View File

@ -18,4 +18,3 @@ pub fn main() {
println!("{}", z)
}

View File

@ -1,12 +1,15 @@
error[E0277]: the trait bound `str: std::clone::Clone` is not satisfied
--> $DIR/check-trait-object-bounds-3.rs:12:5
error[E0597]: `s` does not live long enough
--> $DIR/check-trait-object-bounds-3.rs:15:34
|
LL | fn f<T: X + ?Sized>() {
| - required by this bound in `f`
...
LL | f::<dyn X<Y = str>>();
| ^^^^^^^^^^^^^^^^^^^ the trait `std::clone::Clone` is not implemented for `str`
LL | z = f::<dyn X<Y = &str>>(&s);
| ---------------------^^-
| | |
| | borrowed value does not live long enough
| argument requires that `s` is borrowed for `'static`
LL |
LL | }
| - `s` dropped here while still borrowed
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
For more information about this error, try `rustc --explain E0597`.