-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Allow *const W<dyn A> -> *const dyn A
ptr cast
#136127
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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,36 @@ | ||
// Combination of `ptr-to-trait-obj-wrap.rs` and `ptr-to-trait-obj-add-auto.rs`. | ||
// | ||
// Checks that you *can't* add auto traits to trait object in pointer casts involving wrapping said | ||
// traits structures. | ||
|
||
trait A {} | ||
|
||
struct W<T: ?Sized>(T); | ||
struct X<T: ?Sized>(T); | ||
|
||
fn unwrap(a: *const W<dyn A>) -> *const (dyn A + Send) { | ||
a as _ | ||
//~^ error: cannot add auto trait `Send` to dyn bound via pointer cast | ||
} | ||
|
||
fn unwrap_nested(a: *const W<W<dyn A>>) -> *const W<dyn A + Send> { | ||
a as _ | ||
//~^ error: cannot add auto trait `Send` to dyn bound via pointer cast | ||
} | ||
|
||
fn rewrap(a: *const W<dyn A>) -> *const X<dyn A + Send> { | ||
a as _ | ||
//~^ error: cannot add auto trait `Send` to dyn bound via pointer cast | ||
} | ||
|
||
fn rewrap_nested(a: *const W<W<dyn A>>) -> *const W<X<dyn A + Send>> { | ||
a as _ | ||
//~^ error: cannot add auto trait `Send` to dyn bound via pointer cast | ||
} | ||
|
||
fn wrap(a: *const dyn A) -> *const W<dyn A + Send> { | ||
a as _ | ||
//~^ error: cannot add auto trait `Send` to dyn bound via pointer cast | ||
} | ||
|
||
fn main() {} |
This file contains 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,48 @@ | ||
error[E0804]: cannot add auto trait `Send` to dyn bound via pointer cast | ||
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:12:5 | ||
| | ||
LL | a as _ | ||
| ^^^^^^ unsupported cast | ||
| | ||
= note: this could allow UB elsewhere | ||
= help: use `transmute` if you're sure this is sound | ||
|
||
error[E0804]: cannot add auto trait `Send` to dyn bound via pointer cast | ||
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:17:5 | ||
| | ||
LL | a as _ | ||
| ^^^^^^ unsupported cast | ||
| | ||
= note: this could allow UB elsewhere | ||
= help: use `transmute` if you're sure this is sound | ||
|
||
error[E0804]: cannot add auto trait `Send` to dyn bound via pointer cast | ||
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:22:5 | ||
| | ||
LL | a as _ | ||
| ^^^^^^ unsupported cast | ||
| | ||
= note: this could allow UB elsewhere | ||
= help: use `transmute` if you're sure this is sound | ||
|
||
error[E0804]: cannot add auto trait `Send` to dyn bound via pointer cast | ||
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:27:5 | ||
| | ||
LL | a as _ | ||
| ^^^^^^ unsupported cast | ||
| | ||
= note: this could allow UB elsewhere | ||
= help: use `transmute` if you're sure this is sound | ||
|
||
error[E0804]: cannot add auto trait `Send` to dyn bound via pointer cast | ||
--> $DIR/ptr-to-trait-obj-wrap-add-auto.rs:32:5 | ||
| | ||
LL | a as _ | ||
| ^^^^^^ unsupported cast | ||
| | ||
= note: this could allow UB elsewhere | ||
= help: use `transmute` if you're sure this is sound | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0804`. |
This file contains 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,36 @@ | ||
// Combination of `ptr-to-trait-obj-different-args.rs` and `ptr-to-trait-obj-wrap.rs`. | ||
// | ||
// Checks that you *can't* change type arguments of trait objects in pointer casts involving | ||
// wrapping said traits structures. | ||
|
||
trait A<T> {} | ||
|
||
struct W<T: ?Sized>(T); | ||
struct X<T: ?Sized>(T); | ||
|
||
fn unwrap<F, G>(a: *const W<dyn A<F>>) -> *const dyn A<G> { | ||
a as _ | ||
//~^ error casting `*const W<(dyn A<F> + 'static)>` as `*const dyn A<G>` is invalid | ||
} | ||
|
||
fn unwrap_nested<F, G>(a: *const W<W<dyn A<F>>>) -> *const W<dyn A<G>> { | ||
a as _ | ||
//~^ error casting `*const W<W<(dyn A<F> + 'static)>>` as `*const W<dyn A<G>>` is invalid | ||
} | ||
|
||
fn rewrap<F, G>(a: *const W<dyn A<F>>) -> *const X<dyn A<G>> { | ||
a as _ | ||
//~^ error: casting `*const W<(dyn A<F> + 'static)>` as `*const X<dyn A<G>>` is invalid | ||
} | ||
|
||
fn rewrap_nested<F, G>(a: *const W<W<dyn A<F>>>) -> *const W<X<dyn A<G>>> { | ||
a as _ | ||
//~^ error: casting `*const W<W<(dyn A<F> + 'static)>>` as `*const W<X<dyn A<G>>>` is invalid | ||
} | ||
|
||
fn wrap<F, G>(a: *const dyn A<F>) -> *const W<dyn A<G>> { | ||
a as _ | ||
//~^ error: casting `*const (dyn A<F> + 'static)` as `*const W<dyn A<G>>` is invalid | ||
} | ||
|
||
fn main() {} |
This file contains 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,43 @@ | ||
error[E0606]: casting `*const W<(dyn A<F> + 'static)>` as `*const dyn A<G>` is invalid | ||
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:12:5 | ||
| | ||
LL | a as _ | ||
| ^^^^^^ | ||
| | ||
= note: the trait objects may have different vtables | ||
|
||
error[E0606]: casting `*const W<W<(dyn A<F> + 'static)>>` as `*const W<dyn A<G>>` is invalid | ||
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:17:5 | ||
| | ||
LL | a as _ | ||
| ^^^^^^ | ||
| | ||
= note: the trait objects may have different vtables | ||
|
||
error[E0606]: casting `*const W<(dyn A<F> + 'static)>` as `*const X<dyn A<G>>` is invalid | ||
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:22:5 | ||
| | ||
LL | a as _ | ||
| ^^^^^^ | ||
| | ||
= note: the trait objects may have different vtables | ||
|
||
error[E0606]: casting `*const W<W<(dyn A<F> + 'static)>>` as `*const W<X<dyn A<G>>>` is invalid | ||
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:27:5 | ||
| | ||
LL | a as _ | ||
| ^^^^^^ | ||
| | ||
= note: the trait objects may have different vtables | ||
|
||
error[E0606]: casting `*const (dyn A<F> + 'static)` as `*const W<dyn A<G>>` is invalid | ||
--> $DIR/ptr-to-trait-obj-wrap-different-args.rs:32:5 | ||
| | ||
LL | a as _ | ||
| ^^^^^^ | ||
| | ||
= note: the trait objects may have different vtables | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0606`. |
This file contains 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,41 @@ | ||
// Combination of `ptr-to-trait-obj-different-regions-misc.rs` and `ptr-to-trait-obj-wrap.rs`. | ||
// | ||
// Checks that you *can't* change lifetime arguments of trait objects in pointer casts involving | ||
// wrapping said traits structures. | ||
|
||
trait A<'a> {} | ||
|
||
struct W<T: ?Sized>(T); | ||
struct X<T: ?Sized>(T); | ||
|
||
fn unwrap<'a, 'b>(a: *const W<dyn A<'a>>) -> *const dyn A<'b> { | ||
a as _ | ||
//~^ error | ||
//~| error | ||
} | ||
|
||
fn unwrap_nested<'a, 'b>(a: *const W<W<dyn A<'a>>>) -> *const W<dyn A<'b>> { | ||
a as _ | ||
//~^ error | ||
//~| error | ||
} | ||
|
||
fn rewrap<'a, 'b>(a: *const W<dyn A<'a>>) -> *const X<dyn A<'b>> { | ||
a as _ | ||
//~^ error: lifetime may not live long enough | ||
//~| error: lifetime may not live long enough | ||
} | ||
|
||
fn rewrap_nested<'a, 'b>(a: *const W<W<dyn A<'a>>>) -> *const W<X<dyn A<'b>>> { | ||
a as _ | ||
//~^ error: lifetime may not live long enough | ||
//~| error: lifetime may not live long enough | ||
} | ||
|
||
fn wrap<'a, 'b>(a: *const dyn A<'a>) -> *const W<dyn A<'b>> { | ||
a as _ | ||
//~^ error: lifetime may not live long enough | ||
//~| error: lifetime may not live long enough | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.
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.
Can you clarify in a comment what this is doign? also, i think the "kind match + normalize projection + check its adt kind" can be uplifted into a closure, not just the normalize part.
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.
er, actually maybe just move that comment from above down here?