mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 18:23:49 +00:00
Filter global bounds from ParamEnv again.
This commit is contained in:
parent
ba64edb3ed
commit
aa5635338c
@ -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);
|
||||
|
||||
|
@ -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<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>>);
|
||||
|
@ -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<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>>);
|
||||
@ -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`.
|
||||
|
32
src/test/ui/issue-50825-1.rs
Normal file
32
src/test/ui/issue-50825-1.rs
Normal file
@ -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
src/test/ui/issue-50825.rs
Normal file
25
src/test/ui/issue-50825.rs
Normal file
@ -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(&[()]);
|
||||
}
|
@ -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
|
||||
|
||||
|
@ -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)]
|
||||
|
@ -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)]
|
||||
|
@ -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)]
|
||||
|
@ -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)]
|
||||
|
@ -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
|
||||
|
@ -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)]
|
||||
|
||||
|
@ -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)]
|
||||
|
||||
|
@ -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)]
|
||||
|
Loading…
Reference in New Issue
Block a user