diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index d846b23d20da7..72d8a2989b16e 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 ecc6896b75488..e72b8782e50d5 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 0794e86175b25..32b263119e5e2 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 0000000000000..d179530c01485 --- /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 0000000000000..bc15760e77c57 --- /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 49c9df95bc772..4cacbc2c91445 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 2c4d9d813856c..a743b4296980d 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 375885a02c75a..f73c96a002d43 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 14ba11c44de13..11f0080fbabf1 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 5fcdbfc437a81..a78ecdc8ff3d4 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 2c8b873b8c946..c8e8c320bc5ff 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 9850ec2bd1fc0..6f000006ca9b0 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 98cb5b2b50332..15dee64f70e75 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 e6988cb9f8bfe..e37600a653a90 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)]