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

Filter global bounds from ParamEnv again. #50876

Merged
merged 1 commit into from
May 22, 2018
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
5 changes: 5 additions & 0 deletions src/librustc/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/feature-gate-trivial_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -60,6 +60,7 @@ struct Dst<X: ?Sized> {
}

struct TwoStrs(str, str) where str: Sized; //~ ERROR
//~^ ERROR

fn unsized_local() where Dst<A>: Sized { //~ ERROR
let x: Dst<A> = *(Box::new(Dst { x: 1 }) as Box<Dst<A>>);
Expand Down
33 changes: 29 additions & 4 deletions src/test/ui/feature-gate-trivial_bounds.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<A + 'static>`
--> $DIR/feature-gate-trivial_bounds.rs:64:1
--> $DIR/feature-gate-trivial_bounds.rs:65:1
|
LL | / fn unsized_local() where Dst<A>: Sized { //~ ERROR
LL | | let x: Dst<A> = *(Box::new(Dst { x: 1 }) as Box<Dst<A>>);
Expand All @@ -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()
Expand All @@ -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`.
32 changes: 32 additions & 0 deletions src/test/ui/issue-50825-1.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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<T = ()> is prefered over
// the (): X bound in the where clause.

trait X {
type T;
}

trait Y<U>: X {
fn foo(x: &Self::T);
}

impl X for () {
type T = ();
}

impl<T> Y<Vec<T>> for () where (): Y<T> {
fn foo(_x: &()) {}
}

fn main () {}
25 changes: 25 additions & 0 deletions src/test/ui/issue-50825.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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(&[()]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/test/ui/trivial-bounds-inconsistent-copy-reborrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/trivial-bounds-inconsistent-copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/trivial-bounds-inconsistent-sized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/trivial-bounds-inconsistent-well-formed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/trivial-bounds-inconsistent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/trivial-bounds-leak-copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down
1 change: 1 addition & 0 deletions src/test/ui/trivial-bounds-leak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down
1 change: 1 addition & 0 deletions src/test/ui/trivial-bounds-lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down