Repository navigation
Rewrite relaxed bound policy code - #165677
jdonszelmann wants to merge 1 commit into
Conversation
|
|
This comment has been minimized.
This comment has been minimized.
a178158 to
11493ff
Compare
| error: relaxed bounds are not permitted in trait object types | ||
| --> $DIR/missing-associated_item_or_field_def_ids.rs:3:29 | ||
| | | ||
| LL | fn main() -> dyn Iterator + ?Iterator::advance_by(usize) { |
There was a problem hiding this comment.
there's a nameres issue here, we stop emitting further errors now. If we don't do that it becomes really hard to check for specific traits that are allowed/disallowed in relaxed bounds.
| @@ -7,5 +7,4 @@ trait Tr { | |||
| fn main() { | |||
| let _: dyn Tr + ?Foo<Assoc = ()>; | |||
| //~^ ERROR: cannot find trait `Foo` in this scope | |||
| //~| ERROR: relaxed bounds are not permitted in trait object types | |||
There was a problem hiding this comment.
Same here, Foo has a nameres error
| @@ -4,14 +4,12 @@ | |||
| #[lang = "default_trait2"] auto trait Trait2 {} | |||
|
|
|||
| trait Trait3: ?Trait1 {} | |||
| //~^ ERROR relaxed bounds are not permitted in supertrait bounds | |||
| //~| ERROR bound modifier `?` can only be applied to `Sized` | |||
There was a problem hiding this comment.
feature(more_maybe_bounds) is not on, and we already error in that case for non-?Sized relaxed bounds. This is just a duplicate.
| @@ -7,17 +7,17 @@ fn f<T: (Copy) + (?Sized) + (for<'a> Trait<'a>)>() {} | |||
|
|
|||
| fn main() { | |||
| let _: Box<(Obj) + (?Sized) + (for<'a> Trait<'a>)>; | |||
| //~^ ERROR relaxed bounds are not permitted in trait object types | |||
There was a problem hiding this comment.
We start mentioning that it's a relaxed Sized bound specifically. I think it's a nicer error personally.
| @@ -6,21 +6,19 @@ use std::marker::{MetaSized, PointeeSized}; | |||
| trait Sized_: Sized { } | |||
|
|
|||
| trait NegSized: ?Sized { } | |||
| //~^ ERROR relaxed bounds are not permitted in supertrait bounds | |||
There was a problem hiding this comment.
same ^^
| @@ -3,7 +3,7 @@ | |||
| // Ensure that relaxed bounds are not permitted in the `Self` bounds of trait aliases because trait | |||
| // aliases (like traits) aren't implicitly bounded by `Sized` so there's nothing to relax. | |||
|
|
|||
| trait Alias0 = ?Sized; //~ ERROR relaxed bounds are not permitted in trait alias bounds | |||
There was a problem hiding this comment.
Same ^^
| @@ -12,8 +12,7 @@ struct S3<T>(T) where &'static T: ?Sized; //~ ERROR this relaxed bound is not pe | |||
| trait Trait<'a> {} | |||
|
|
|||
| struct S4<T>(T) where for<'a> T: ?Trait<'a>; | |||
| //~^ ERROR this relaxed bound is not permitted here | |||
There was a problem hiding this comment.
feature(more_maybe_bounds) is not on, and we already error in that case for non-?Sized relaxed bounds. This is just a duplicate.
| #[derive(Copy, Clone, Debug)] | ||
| struct AllowedRelaxedBounds: u32 { | ||
| const SIZED = 1 << 0; | ||
| const FORGET = 1 << 1; |
There was a problem hiding this comment.
I could remove Forget here again. It's temporarily unused, though will soon be. I guess I kept it as an example of how this will work. Doesn't do much harm either.
| span, | ||
| format!( | ||
| "relaxed {}bounds are not permitted in {context}", | ||
| trait_name.map(|i| format!("{i} ")).unwrap_or_default() |
There was a problem hiding this comment.
| trait_name.map(|i| format!("{i} ")).unwrap_or_default() | |
| trait_name.map(|i| format!("`{i}` ")).unwrap_or_default() |
There was a problem hiding this comment.
good catch, changed it!
11493ff to
e14043c
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
☔ The latest upstream changes (presumably #165760) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
r? @WaffleLapkin
Because we may want to allow "relaxed bounds" more in the future as we land the Move and Forget traits, this code was such a mess it deserved a rewrite. There are some test changes, and I'll leave comments on each explaining why I think they're warranted. The old code is an absolute mess of logic, let me comment on it here:
Importantly, the code above intertwines the idea of Sized and
feature(more_maybe_bounds)so much that it's absolutely impossible to distinguish more auto traits likeForget.The new code: