Skip to content

Commit aa56353

Browse files
committed
Filter global bounds from ParamEnv again.
1 parent ba64edb commit aa56353

14 files changed

+102
-5
lines changed

src/librustc/traits/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,13 @@ pub fn normalize_param_env_or_error<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
644644

645645
let predicates: Vec<_> =
646646
util::elaborate_predicates(tcx, unnormalized_env.caller_bounds.to_vec())
647+
.filter(|p| !p.is_global() || p.has_late_bound_regions()) // (*)
647648
.collect();
648649

650+
// (*) FIXME(#50825) This shouldn't be needed.
651+
// Removing the bounds here stopped them from being prefered in selection.
652+
// See the issue-50825 ui tests for examples
653+
649654
debug!("normalize_param_env_or_error: elaborated-predicates={:?}",
650655
predicates);
651656

src/test/ui/feature-gate-trivial_bounds.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ union U where i32: Foo { f: i32 } //~ ERROR
2828
type Y where i32: Foo = (); // OK - bound is ignored
2929

3030
impl Foo for () where i32: Foo { //~ ERROR
31-
fn test(&self) {
31+
fn test(&self) { //~ ERROR
3232
3i32.test();
3333
Foo::test(&4i32);
3434
generic_function(5i32);
@@ -60,6 +60,7 @@ struct Dst<X: ?Sized> {
6060
}
6161

6262
struct TwoStrs(str, str) where str: Sized; //~ ERROR
63+
//~^ ERROR
6364

6465
fn unsized_local() where Dst<A>: Sized { //~ ERROR
6566
let x: Dst<A> = *(Box::new(Dst { x: 1 }) as Box<Dst<A>>);

src/test/ui/feature-gate-trivial_bounds.stderr

+29-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ error[E0277]: the trait bound `i32: Foo` is not satisfied
3838
--> $DIR/feature-gate-trivial_bounds.rs:30:1
3939
|
4040
LL | / impl Foo for () where i32: Foo { //~ ERROR
41-
LL | | fn test(&self) {
41+
LL | | fn test(&self) { //~ ERROR
4242
LL | | 3i32.test();
4343
LL | | Foo::test(&4i32);
4444
LL | | generic_function(5i32);
@@ -97,8 +97,17 @@ LL | struct TwoStrs(str, str) where str: Sized; //~ ERROR
9797
= help: see issue #48214
9898
= help: add #![feature(trivial_bounds)] to the crate attributes to enable
9999

100+
error[E0277]: the trait bound `str: std::marker::Sized` is not satisfied
101+
--> $DIR/feature-gate-trivial_bounds.rs:62:16
102+
|
103+
LL | struct TwoStrs(str, str) where str: Sized; //~ ERROR
104+
| ^^^ `str` does not have a constant size known at compile-time
105+
|
106+
= help: the trait `std::marker::Sized` is not implemented for `str`
107+
= note: only the last field of a struct may have a dynamically sized type
108+
100109
error[E0277]: the trait bound `A + 'static: std::marker::Sized` is not satisfied in `Dst<A + 'static>`
101-
--> $DIR/feature-gate-trivial_bounds.rs:64:1
110+
--> $DIR/feature-gate-trivial_bounds.rs:65:1
102111
|
103112
LL | / fn unsized_local() where Dst<A>: Sized { //~ ERROR
104113
LL | | let x: Dst<A> = *(Box::new(Dst { x: 1 }) as Box<Dst<A>>);
@@ -111,7 +120,7 @@ LL | | }
111120
= help: add #![feature(trivial_bounds)] to the crate attributes to enable
112121

113122
error[E0277]: the trait bound `str: std::marker::Sized` is not satisfied
114-
--> $DIR/feature-gate-trivial_bounds.rs:68:1
123+
--> $DIR/feature-gate-trivial_bounds.rs:69:1
115124
|
116125
LL | / fn return_str() -> str where str: Sized { //~ ERROR
117126
LL | | *"Sized".to_string().into_boxed_str()
@@ -122,6 +131,22 @@ LL | | }
122131
= help: see issue #48214
123132
= help: add #![feature(trivial_bounds)] to the crate attributes to enable
124133

125-
error: aborting due to 11 previous errors
134+
error[E0277]: the trait bound `i32: Foo` is not satisfied
135+
--> $DIR/feature-gate-trivial_bounds.rs:31:5
136+
|
137+
LL | / fn test(&self) { //~ ERROR
138+
LL | | 3i32.test();
139+
LL | | Foo::test(&4i32);
140+
LL | | generic_function(5i32);
141+
LL | | }
142+
| |_____^ the trait `Foo` is not implemented for `i32`
143+
|
144+
note: required by `Foo`
145+
--> $DIR/feature-gate-trivial_bounds.rs:14:1
146+
|
147+
LL | pub trait Foo {
148+
| ^^^^^^^^^^^^^
149+
150+
error: aborting due to 13 previous errors
126151

127152
For more information about this error, try `rustc --explain E0277`.

src/test/ui/issue-50825-1.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// run-pass
12+
// regression test for issue #50825
13+
// Make sure that the `impl` bound (): X<T = ()> is prefered over
14+
// the (): X bound in the where clause.
15+
16+
trait X {
17+
type T;
18+
}
19+
20+
trait Y<U>: X {
21+
fn foo(x: &Self::T);
22+
}
23+
24+
impl X for () {
25+
type T = ();
26+
}
27+
28+
impl<T> Y<Vec<T>> for () where (): Y<T> {
29+
fn foo(_x: &()) {}
30+
}
31+
32+
fn main () {}

src/test/ui/issue-50825.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// run-pass
12+
// regression test for issue #50825
13+
// Make sure that the built-in bound {integer}: Sized is prefered over
14+
// the u64: Sized bound in the where clause.
15+
16+
fn foo(y: &[()])
17+
where
18+
u64: Sized,
19+
{
20+
y[0]
21+
}
22+
23+
fn main () {
24+
foo(&[()]);
25+
}

src/test/ui/trivial-bounds-inconsistent-associated-functions.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-test FIXME(#50825)
1112
// run-pass
1213
// Inconsistent bounds with trait implementations
1314

src/test/ui/trivial-bounds-inconsistent-copy-reborrow.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-test FIXME(#50825)
1112
// Check that reborrows are still illegal with Copy mutable references
1213
#![feature(trivial_bounds)]
1314
#![allow(unused)]

src/test/ui/trivial-bounds-inconsistent-copy.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-test FIXME(#50825)
1112
// run-pass
1213
// Check tautalogically false `Copy` bounds
1314
#![feature(trivial_bounds)]

src/test/ui/trivial-bounds-inconsistent-sized.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-test FIXME(#50825)
1112
// run-pass
1213
// Check tautalogically false `Sized` bounds
1314
#![feature(trivial_bounds)]

src/test/ui/trivial-bounds-inconsistent-well-formed.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-test FIXME(#50825)
1112
// run-pass
1213
// Test that inconsistent bounds are used in well-formedness checks
1314
#![feature(trivial_bounds)]

src/test/ui/trivial-bounds-inconsistent.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-test FIXME(#50825)
1112
// run-pass
1213

1314
// Check that tautalogically false bounds are accepted, and are used

src/test/ui/trivial-bounds-leak-copy.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-test FIXME(#50825)
1112
// Check that false Copy bounds don't leak
1213
#![feature(trivial_bounds)]
1314

src/test/ui/trivial-bounds-leak.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-test FIXME(#50825)
1112
// Check that false bounds don't leak
1213
#![feature(trivial_bounds)]
1314

src/test/ui/trivial-bounds-lint.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-test FIXME(#50825)
1112
#![feature(trivial_bounds)]
1213
#![allow(unused)]
1314
#![deny(trivial_bounds)]

0 commit comments

Comments
 (0)