From aa5635338c53fbd9f3ca326b55948bc21e655606 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Fri, 18 May 2018 23:40:44 +0100 Subject: [PATCH] Filter global bounds from ParamEnv again. --- src/librustc/traits/mod.rs | 5 +++ src/test/ui/feature-gate-trivial_bounds.rs | 3 +- .../ui/feature-gate-trivial_bounds.stderr | 33 ++++++++++++++++--- src/test/ui/issue-50825-1.rs | 32 ++++++++++++++++++ src/test/ui/issue-50825.rs | 25 ++++++++++++++ ...ounds-inconsistent-associated-functions.rs | 1 + ...ivial-bounds-inconsistent-copy-reborrow.rs | 1 + .../ui/trivial-bounds-inconsistent-copy.rs | 1 + .../ui/trivial-bounds-inconsistent-sized.rs | 1 + ...trivial-bounds-inconsistent-well-formed.rs | 1 + src/test/ui/trivial-bounds-inconsistent.rs | 1 + src/test/ui/trivial-bounds-leak-copy.rs | 1 + src/test/ui/trivial-bounds-leak.rs | 1 + src/test/ui/trivial-bounds-lint.rs | 1 + 14 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 src/test/ui/issue-50825-1.rs create mode 100644 src/test/ui/issue-50825.rs diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index b5115eab7dc3..43eca136861c 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -644,8 +644,13 @@ pub fn normalize_param_env_or_error<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let predicates: Vec<_> = util::elaborate_predicates(tcx, unnormalized_env.caller_bounds.to_vec()) + .filter(|p| !p.is_global() || p.has_late_bound_regions()) // (*) .collect(); + // (*) FIXME(#50825) This shouldn't be needed. + // Removing the bounds here stopped them from being prefered in selection. + // See the issue-50825 ui tests for examples + debug!("normalize_param_env_or_error: elaborated-predicates={:?}", predicates); diff --git a/src/test/ui/feature-gate-trivial_bounds.rs b/src/test/ui/feature-gate-trivial_bounds.rs index ecc6896b7548..e72b8782e50d 100644 --- a/src/test/ui/feature-gate-trivial_bounds.rs +++ b/src/test/ui/feature-gate-trivial_bounds.rs @@ -28,7 +28,7 @@ union U where i32: Foo { f: i32 } //~ ERROR type Y where i32: Foo = (); // OK - bound is ignored impl Foo for () where i32: Foo { //~ ERROR - fn test(&self) { + fn test(&self) { //~ ERROR 3i32.test(); Foo::test(&4i32); generic_function(5i32); @@ -60,6 +60,7 @@ struct Dst { } struct TwoStrs(str, str) where str: Sized; //~ ERROR +//~^ ERROR fn unsized_local() where Dst: Sized { //~ ERROR let x: Dst = *(Box::new(Dst { x: 1 }) as Box>); diff --git a/src/test/ui/feature-gate-trivial_bounds.stderr b/src/test/ui/feature-gate-trivial_bounds.stderr index 0794e86175b2..32b263119e5e 100644 --- a/src/test/ui/feature-gate-trivial_bounds.stderr +++ b/src/test/ui/feature-gate-trivial_bounds.stderr @@ -38,7 +38,7 @@ error[E0277]: the trait bound `i32: Foo` is not satisfied --> $DIR/feature-gate-trivial_bounds.rs:30:1 | LL | / impl Foo for () where i32: Foo { //~ ERROR -LL | | fn test(&self) { +LL | | fn test(&self) { //~ ERROR LL | | 3i32.test(); LL | | Foo::test(&4i32); LL | | generic_function(5i32); @@ -97,8 +97,17 @@ LL | struct TwoStrs(str, str) where str: Sized; //~ ERROR = help: see issue #48214 = help: add #![feature(trivial_bounds)] to the crate attributes to enable +error[E0277]: the trait bound `str: std::marker::Sized` is not satisfied + --> $DIR/feature-gate-trivial_bounds.rs:62:16 + | +LL | struct TwoStrs(str, str) where str: Sized; //~ ERROR + | ^^^ `str` does not have a constant size known at compile-time + | + = help: the trait `std::marker::Sized` is not implemented for `str` + = note: only the last field of a struct may have a dynamically sized type + error[E0277]: the trait bound `A + 'static: std::marker::Sized` is not satisfied in `Dst` - --> $DIR/feature-gate-trivial_bounds.rs:64:1 + --> $DIR/feature-gate-trivial_bounds.rs:65:1 | LL | / fn unsized_local() where Dst: Sized { //~ ERROR LL | | let x: Dst = *(Box::new(Dst { x: 1 }) as Box>); @@ -111,7 +120,7 @@ LL | | } = help: add #![feature(trivial_bounds)] to the crate attributes to enable error[E0277]: the trait bound `str: std::marker::Sized` is not satisfied - --> $DIR/feature-gate-trivial_bounds.rs:68:1 + --> $DIR/feature-gate-trivial_bounds.rs:69:1 | LL | / fn return_str() -> str where str: Sized { //~ ERROR LL | | *"Sized".to_string().into_boxed_str() @@ -122,6 +131,22 @@ LL | | } = help: see issue #48214 = help: add #![feature(trivial_bounds)] to the crate attributes to enable -error: aborting due to 11 previous errors +error[E0277]: the trait bound `i32: Foo` is not satisfied + --> $DIR/feature-gate-trivial_bounds.rs:31:5 + | +LL | / fn test(&self) { //~ ERROR +LL | | 3i32.test(); +LL | | Foo::test(&4i32); +LL | | generic_function(5i32); +LL | | } + | |_____^ the trait `Foo` is not implemented for `i32` + | +note: required by `Foo` + --> $DIR/feature-gate-trivial_bounds.rs:14:1 + | +LL | pub trait Foo { + | ^^^^^^^^^^^^^ + +error: aborting due to 13 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/issue-50825-1.rs b/src/test/ui/issue-50825-1.rs new file mode 100644 index 000000000000..d179530c0148 --- /dev/null +++ b/src/test/ui/issue-50825-1.rs @@ -0,0 +1,32 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-pass +// regression test for issue #50825 +// Make sure that the `impl` bound (): X is prefered over +// the (): X bound in the where clause. + +trait X { + type T; +} + +trait Y: X { + fn foo(x: &Self::T); +} + +impl X for () { + type T = (); +} + +impl Y> for () where (): Y { + fn foo(_x: &()) {} +} + +fn main () {} diff --git a/src/test/ui/issue-50825.rs b/src/test/ui/issue-50825.rs new file mode 100644 index 000000000000..bc15760e77c5 --- /dev/null +++ b/src/test/ui/issue-50825.rs @@ -0,0 +1,25 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-pass +// regression test for issue #50825 +// Make sure that the built-in bound {integer}: Sized is prefered over +// the u64: Sized bound in the where clause. + +fn foo(y: &[()]) +where + u64: Sized, +{ + y[0] +} + +fn main () { + foo(&[()]); +} diff --git a/src/test/ui/trivial-bounds-inconsistent-associated-functions.rs b/src/test/ui/trivial-bounds-inconsistent-associated-functions.rs index 49c9df95bc77..4cacbc2c9144 100644 --- a/src/test/ui/trivial-bounds-inconsistent-associated-functions.rs +++ b/src/test/ui/trivial-bounds-inconsistent-associated-functions.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test FIXME(#50825) // run-pass // Inconsistent bounds with trait implementations diff --git a/src/test/ui/trivial-bounds-inconsistent-copy-reborrow.rs b/src/test/ui/trivial-bounds-inconsistent-copy-reborrow.rs index 2c4d9d813856..a743b4296980 100644 --- a/src/test/ui/trivial-bounds-inconsistent-copy-reborrow.rs +++ b/src/test/ui/trivial-bounds-inconsistent-copy-reborrow.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test FIXME(#50825) // Check that reborrows are still illegal with Copy mutable references #![feature(trivial_bounds)] #![allow(unused)] diff --git a/src/test/ui/trivial-bounds-inconsistent-copy.rs b/src/test/ui/trivial-bounds-inconsistent-copy.rs index 375885a02c75..f73c96a002d4 100644 --- a/src/test/ui/trivial-bounds-inconsistent-copy.rs +++ b/src/test/ui/trivial-bounds-inconsistent-copy.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test FIXME(#50825) // run-pass // Check tautalogically false `Copy` bounds #![feature(trivial_bounds)] diff --git a/src/test/ui/trivial-bounds-inconsistent-sized.rs b/src/test/ui/trivial-bounds-inconsistent-sized.rs index 14ba11c44de1..11f0080fbabf 100644 --- a/src/test/ui/trivial-bounds-inconsistent-sized.rs +++ b/src/test/ui/trivial-bounds-inconsistent-sized.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test FIXME(#50825) // run-pass // Check tautalogically false `Sized` bounds #![feature(trivial_bounds)] diff --git a/src/test/ui/trivial-bounds-inconsistent-well-formed.rs b/src/test/ui/trivial-bounds-inconsistent-well-formed.rs index 5fcdbfc437a8..a78ecdc8ff3d 100644 --- a/src/test/ui/trivial-bounds-inconsistent-well-formed.rs +++ b/src/test/ui/trivial-bounds-inconsistent-well-formed.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test FIXME(#50825) // run-pass // Test that inconsistent bounds are used in well-formedness checks #![feature(trivial_bounds)] diff --git a/src/test/ui/trivial-bounds-inconsistent.rs b/src/test/ui/trivial-bounds-inconsistent.rs index 2c8b873b8c94..c8e8c320bc5f 100644 --- a/src/test/ui/trivial-bounds-inconsistent.rs +++ b/src/test/ui/trivial-bounds-inconsistent.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test FIXME(#50825) // run-pass // Check that tautalogically false bounds are accepted, and are used diff --git a/src/test/ui/trivial-bounds-leak-copy.rs b/src/test/ui/trivial-bounds-leak-copy.rs index 9850ec2bd1fc..6f000006ca9b 100644 --- a/src/test/ui/trivial-bounds-leak-copy.rs +++ b/src/test/ui/trivial-bounds-leak-copy.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test FIXME(#50825) // Check that false Copy bounds don't leak #![feature(trivial_bounds)] diff --git a/src/test/ui/trivial-bounds-leak.rs b/src/test/ui/trivial-bounds-leak.rs index 98cb5b2b5033..15dee64f70e7 100644 --- a/src/test/ui/trivial-bounds-leak.rs +++ b/src/test/ui/trivial-bounds-leak.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test FIXME(#50825) // Check that false bounds don't leak #![feature(trivial_bounds)] diff --git a/src/test/ui/trivial-bounds-lint.rs b/src/test/ui/trivial-bounds-lint.rs index e6988cb9f8bf..e37600a653a9 100644 --- a/src/test/ui/trivial-bounds-lint.rs +++ b/src/test/ui/trivial-bounds-lint.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test FIXME(#50825) #![feature(trivial_bounds)] #![allow(unused)] #![deny(trivial_bounds)]