Skip to content

Commit

Permalink
blessings
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Feb 13, 2024
1 parent 51228ea commit 5f27951
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 20 deletions.
6 changes: 0 additions & 6 deletions tests/ui/cast/cast-rfc0401-vtable-kinds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@

#![feature(unsized_tuple_coercion)]

trait Foo<T> {
fn foo(&self, _: T) -> u32 { 42 }
}

trait Bar { //~ WARN trait `Bar` is never used
fn bar(&self) { println!("Bar!"); }
}

impl<T> Foo<T> for () {}
impl Foo<u32> for u32 { fn foo(&self, _: u32) -> u32 { self+43 } }
impl Bar for () {}

#[repr(C)]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/cast/cast-rfc0401-vtable-kinds.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: trait `Bar` is never used
--> $DIR/cast-rfc0401-vtable-kinds.rs:11:7
--> $DIR/cast-rfc0401-vtable-kinds.rs:7:7
|
LL | trait Bar {
| ^^^
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/cast/ptr-to-trait-obj-different-args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ trait Assocked {

fn change_assoc(x: *mut dyn Assocked<Assoc = u8>) -> *mut dyn Assocked<Assoc = u32> {
x as _ //~ error: the trait bound `dyn Assocked<Assoc = u8>: Unsize<dyn Assocked<Assoc = u32>>` is not satisfied
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

trait Trait {}

fn assert_send(ptr: *mut dyn Trait) -> *mut (dyn Trait + Send) {
fn assert_send() -> *mut (dyn Trait + Send) {
//~^ ERROR incorrect parentheses around trait bounds
ptr as _
loop {}
}

fn foo2(_: &(dyn Trait + Send)) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

trait Trait {}

fn assert_send(ptr: *mut dyn Trait) -> *mut dyn (Trait + Send) {
fn assert_send() -> *mut dyn (Trait + Send) {
//~^ ERROR incorrect parentheses around trait bounds
ptr as _
loop {}
}

fn foo2(_: &dyn (Trait + Send)) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error: incorrect parentheses around trait bounds
--> $DIR/issue-114797-bad-parentheses-dyn-trait.rs:6:49
--> $DIR/issue-114797-bad-parentheses-dyn-trait.rs:6:30
|
LL | fn assert_send(ptr: *mut dyn Trait) -> *mut dyn (Trait + Send) {
| ^ ^
LL | fn assert_send() -> *mut dyn (Trait + Send) {
| ^ ^
|
help: fix the parentheses
|
LL - fn assert_send(ptr: *mut dyn Trait) -> *mut dyn (Trait + Send) {
LL + fn assert_send(ptr: *mut dyn Trait) -> *mut (dyn Trait + Send) {
LL - fn assert_send() -> *mut dyn (Trait + Send) {
LL + fn assert_send() -> *mut (dyn Trait + Send) {
|

error: incorrect parentheses around trait bounds
Expand Down
8 changes: 5 additions & 3 deletions tests/ui/traits/upcast_soundness_bug.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#![feature(trait_upcasting)]
// known-bug: #120222
// check-pass
//! This will segfault at runtime.
// check-fail
//
// issue: <https://github.com/rust-lang/rust/pull/120222>
//! This would segfault at runtime.

pub trait SupSupA {
fn method(&self) {}
Expand Down Expand Up @@ -56,6 +57,7 @@ pub fn user2() -> &'static dyn Trait<u8, u16> {
fn main() {
let p: *const dyn Trait<u8, u8> = &();
let p = p as *const dyn Trait<u8, u16>; // <- this is bad!
//~^ error: the trait bound `dyn Trait<u8, u8>: Unsize<dyn Trait<u8, u16>>` is not satisfied
let p = p as *const dyn Super<u16>; // <- this upcast accesses improper vtable entry
// accessing from L__unnamed_2 the position for the 'Super<u16> vtable (pointer)',
// thus reading 'null pointer for missing_method'
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/traits/upcast_soundness_bug.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0277]: the trait bound `dyn Trait<u8, u8>: Unsize<dyn Trait<u8, u16>>` is not satisfied
--> $DIR/upcast_soundness_bug.rs:59:13
|
LL | let p = p as *const dyn Trait<u8, u16>; // <- this is bad!
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Unsize<dyn Trait<u8, u16>>` is not implemented for `dyn Trait<u8, u8>`
|
= note: all implementations of `Unsize` are provided automatically by the compiler, see <https://doc.rust-lang.org/stable/std/marker/trait.Unsize.html> for more information

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.

0 comments on commit 5f27951

Please sign in to comment.