-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Implement RFC 2056 trivial constraints in where clauses #48557
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d0ec8ea
Implement RFC 2056 - trivial constraints
matthewjasper 27183a9
Feature gate trivial bounds
matthewjasper dabb820
Add trivial bounds lint
matthewjasper 9b0dfe1
Add tests for trivial bounds
matthewjasper dc8ce4c
Update existing tests for trivial bounds changes
matthewjasper be2900c
Make is_global true for latebound regions
matthewjasper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Feature gate trivial bounds
- Loading branch information
commit 27183a903034b1fc3aa3296e497a520508493911
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// 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. | ||
|
||
#![allow(unused)] | ||
#![allow(type_alias_bounds)] | ||
|
||
pub trait Foo { | ||
fn test(&self); | ||
} | ||
|
||
fn generic_function<X: Foo>(x: X) {} | ||
|
||
enum E where i32: Foo { V } //~ ERROR | ||
|
||
struct S where i32: Foo; //~ ERROR | ||
|
||
trait T where i32: Foo {} //~ ERROR | ||
|
||
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) { | ||
3i32.test(); | ||
Foo::test(&4i32); | ||
generic_function(5i32); | ||
} | ||
} | ||
|
||
fn f() where i32: Foo //~ ERROR | ||
{ | ||
let s = S; | ||
3i32.test(); | ||
Foo::test(&4i32); | ||
generic_function(5i32); | ||
} | ||
|
||
fn use_op(s: String) -> String where String: ::std::ops::Neg<Output=String> { //~ ERROR | ||
-s | ||
} | ||
|
||
fn use_for() where i32: Iterator { //~ ERROR | ||
for _ in 2i32 {} | ||
} | ||
|
||
trait A {} | ||
|
||
impl A for i32 {} | ||
|
||
struct Dst<X: ?Sized> { | ||
x: X, | ||
} | ||
|
||
struct TwoStrs(str, str) where str: Sized; //~ ERROR | ||
|
||
fn unsized_local() where Dst<A>: Sized { //~ ERROR | ||
let x: Dst<A> = *(Box::new(Dst { x: 1 }) as Box<Dst<A>>); | ||
} | ||
|
||
fn return_str() -> str where str: Sized { //~ ERROR | ||
*"Sized".to_string().into_boxed_str() | ||
} | ||
|
||
// This is currently accepted because the function pointer isn't | ||
// considered global. | ||
fn global_hr(x: fn(&())) where fn(&()): Foo { // OK | ||
x.test(); | ||
} | ||
|
||
fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
error[E0277]: the trait bound `i32: Foo` is not satisfied | ||
--> $DIR/feature-gate-trivial_bounds.rs:20:1 | ||
| | ||
LL | enum E where i32: Foo { V } //~ ERROR | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `i32` | ||
| | ||
= help: see issue #48214 | ||
= help: add #![feature(trivial_bounds)] to the crate attributes to enable | ||
|
||
error[E0277]: the trait bound `i32: Foo` is not satisfied | ||
--> $DIR/feature-gate-trivial_bounds.rs:22:1 | ||
| | ||
LL | struct S where i32: Foo; //~ ERROR | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `i32` | ||
| | ||
= help: see issue #48214 | ||
= help: add #![feature(trivial_bounds)] to the crate attributes to enable | ||
|
||
error[E0277]: the trait bound `i32: Foo` is not satisfied | ||
--> $DIR/feature-gate-trivial_bounds.rs:24:1 | ||
| | ||
LL | trait T where i32: Foo {} //~ ERROR | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `i32` | ||
| | ||
= help: see issue #48214 | ||
= help: add #![feature(trivial_bounds)] to the crate attributes to enable | ||
|
||
error[E0277]: the trait bound `i32: Foo` is not satisfied | ||
--> $DIR/feature-gate-trivial_bounds.rs:26:1 | ||
| | ||
LL | union U where i32: Foo { f: i32 } //~ ERROR | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `i32` | ||
| | ||
= help: see issue #48214 | ||
= help: add #![feature(trivial_bounds)] to the crate attributes to enable | ||
|
||
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 | | 3i32.test(); | ||
LL | | Foo::test(&4i32); | ||
LL | | generic_function(5i32); | ||
LL | | } | ||
LL | | } | ||
| |_^ the trait `Foo` is not implemented for `i32` | ||
| | ||
= help: see issue #48214 | ||
= help: add #![feature(trivial_bounds)] to the crate attributes to enable | ||
|
||
error[E0277]: the trait bound `i32: Foo` is not satisfied | ||
--> $DIR/feature-gate-trivial_bounds.rs:38:1 | ||
| | ||
LL | / fn f() where i32: Foo //~ ERROR | ||
LL | | { | ||
LL | | let s = S; | ||
LL | | 3i32.test(); | ||
LL | | Foo::test(&4i32); | ||
LL | | generic_function(5i32); | ||
LL | | } | ||
| |_^ the trait `Foo` is not implemented for `i32` | ||
| | ||
= help: see issue #48214 | ||
= help: add #![feature(trivial_bounds)] to the crate attributes to enable | ||
|
||
error[E0277]: the trait bound `std::string::String: std::ops::Neg` is not satisfied | ||
--> $DIR/feature-gate-trivial_bounds.rs:46:1 | ||
| | ||
LL | / fn use_op(s: String) -> String where String: ::std::ops::Neg<Output=String> { //~ ERROR | ||
LL | | -s | ||
LL | | } | ||
| |_^ the trait `std::ops::Neg` is not implemented for `std::string::String` | ||
| | ||
= help: see issue #48214 | ||
= help: add #![feature(trivial_bounds)] to the crate attributes to enable | ||
|
||
error[E0277]: the trait bound `i32: std::iter::Iterator` is not satisfied | ||
--> $DIR/feature-gate-trivial_bounds.rs:50:1 | ||
| | ||
LL | / fn use_for() where i32: Iterator { //~ ERROR | ||
LL | | for _ in 2i32 {} | ||
LL | | } | ||
| |_^ `i32` is not an iterator; maybe try calling `.iter()` or a similar method | ||
| | ||
= help: the trait `std::iter::Iterator` is not implemented for `i32` | ||
= 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:1 | ||
| | ||
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` | ||
= help: see issue #48214 | ||
= help: add #![feature(trivial_bounds)] to the crate attributes to enable | ||
|
||
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 | ||
| | ||
LL | / fn unsized_local() where Dst<A>: Sized { //~ ERROR | ||
LL | | let x: Dst<A> = *(Box::new(Dst { x: 1 }) as Box<Dst<A>>); | ||
LL | | } | ||
| |_^ `A + 'static` does not have a constant size known at compile-time | ||
| | ||
= help: within `Dst<A + 'static>`, the trait `std::marker::Sized` is not implemented for `A + 'static` | ||
= note: required because it appears within the type `Dst<A + 'static>` | ||
= 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:68:1 | ||
| | ||
LL | / fn return_str() -> str where str: Sized { //~ ERROR | ||
LL | | *"Sized".to_string().into_boxed_str() | ||
LL | | } | ||
| |_^ `str` does not have a constant size known at compile-time | ||
| | ||
= help: the trait `std::marker::Sized` is not implemented for `str` | ||
= help: see issue #48214 | ||
= help: add #![feature(trivial_bounds)] to the crate attributes to enable | ||
|
||
error: aborting due to 11 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does it matter if there is something in the cache, actually? It shouldn't, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add some more explanation to this comment. But the reason is that predicates are cached, rather than obligations. The param_env gets emptied for this check but not for the remaining checks, so the usual wf checks will cache any global bounds as true.