-
Notifications
You must be signed in to change notification settings - Fork 13.5k
More robustly deal with relaxed bounds and improve their diagnostics #142693
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
Open
fmease
wants to merge
8
commits into
rust-lang:master
Choose a base branch
from
fmease:unbound-bettering
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+780
−687
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
af163d4
HIR ty lowering: Simplify signature of `lower_poly_trait_ref`
fmease ee0b644
HIR ty lowering: Validate relaxed bounds in trait object types
fmease 624f1f8
Update comment about `where Ty:`
fmease c619141
AST lowering: More robustly deal with relaxed bounds
fmease 3cace54
Reword diagnostics about relaxed bounds in invalid contexts
fmease 6983b44
Reword diagnostic about relaxing non-`Sized` bound
fmease 2028d25
Don't reject *multiple* relaxed bounds, reject *duplicate* ones.
fmease 45a63cb
HIR ty lowering: Validate `PointeeSized` bounds
fmease 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
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
struct Foo<T: ?Hash> {} | ||
//~^ ERROR expected trait, found derive macro `Hash` | ||
//~| ERROR relaxing a default bound only does something for `?Sized` | ||
//~| ERROR bound modifier `?` can only be applied to `Sized` | ||
|
||
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
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
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,29 @@ | ||
// FIXME(more_maybe_bounds): Even under `more_maybe_bounds` / `-Zexperimental-default-bounds`, | ||
// trying to relax non-default bounds should still be an error in all contexts! As you can see | ||
// there are placed like supertrait bounds and trait object types where we currently don't perform | ||
// this check. | ||
#![feature(auto_traits, more_maybe_bounds, negative_impls)] | ||
|
||
trait Trait1 {} | ||
auto trait Trait2 {} | ||
|
||
// FIXME: `?Trait1` should be rejected, `Trait1` isn't marked `#[lang = "default_traitN"]`. | ||
trait Trait3: ?Trait1 {} | ||
trait Trait4 where Self: Trait1 {} | ||
|
||
// FIXME: `?Trait2` should be rejected, `Trait2` isn't marked `#[lang = "default_traitN"]`. | ||
fn foo(_: Box<(dyn Trait3 + ?Trait2)>) {} | ||
fn bar<T: ?Sized + ?Trait2 + ?Trait1 + ?Trait4>(_: &T) {} | ||
//~^ ERROR bound modifier `?` can only be applied to default traits like `Sized` | ||
//~| ERROR bound modifier `?` can only be applied to default traits like `Sized` | ||
//~| ERROR bound modifier `?` can only be applied to default traits like `Sized` | ||
|
||
struct S; | ||
impl !Trait2 for S {} | ||
impl Trait1 for S {} | ||
impl Trait3 for S {} | ||
|
||
fn main() { | ||
foo(Box::new(S)); | ||
bar(&S); | ||
} |
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,20 @@ | ||
error: bound modifier `?` can only be applied to default traits like `Sized` | ||
--> $DIR/more_maybe_bounds.rs:16:20 | ||
| | ||
LL | fn bar<T: ?Sized + ?Trait2 + ?Trait1 + ?Trait4>(_: &T) {} | ||
| ^^^^^^^ | ||
|
||
error: bound modifier `?` can only be applied to default traits like `Sized` | ||
--> $DIR/more_maybe_bounds.rs:16:30 | ||
| | ||
LL | fn bar<T: ?Sized + ?Trait2 + ?Trait1 + ?Trait4>(_: &T) {} | ||
| ^^^^^^^ | ||
|
||
error: bound modifier `?` can only be applied to default traits like `Sized` | ||
--> $DIR/more_maybe_bounds.rs:16:40 | ||
| | ||
LL | fn bar<T: ?Sized + ?Trait2 + ?Trait1 + ?Trait4>(_: &T) {} | ||
| ^^^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
|
Oops, something went wrong.
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.
(We likely can't actually do it in
lower_poly_trait_ref
because we need access to all the neighboring HIR bounds)