blessings

This commit is contained in:
Maybe Waffle 2024-02-13 00:17:19 +00:00 committed by Maybe Lapkin
parent 5645e8e285
commit bb651d358d
8 changed files with 27 additions and 20 deletions

View File

@ -4,16 +4,10 @@
#![feature(unsized_tuple_coercion)] #![feature(unsized_tuple_coercion)]
trait Foo<T> {
fn foo(&self, _: T) -> u32 { 42 }
}
trait Bar { //~ WARN trait `Bar` is never used trait Bar { //~ WARN trait `Bar` is never used
fn bar(&self) { println!("Bar!"); } 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 () {} impl Bar for () {}
#[repr(C)] #[repr(C)]

View File

@ -1,5 +1,5 @@
warning: trait `Bar` is never used 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 { LL | trait Bar {
| ^^^ | ^^^

View File

@ -35,4 +35,4 @@ trait Assocked {
fn change_assoc(x: *mut dyn Assocked<Assoc = u8>) -> *mut dyn Assocked<Assoc = u32> { 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 x as _ //~ error: the trait bound `dyn Assocked<Assoc = u8>: Unsize<dyn Assocked<Assoc = u32>>` is not satisfied
} }

View File

@ -3,9 +3,9 @@
trait Trait {} 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 //~^ ERROR incorrect parentheses around trait bounds
ptr as _ loop {}
} }
fn foo2(_: &(dyn Trait + Send)) {} fn foo2(_: &(dyn Trait + Send)) {}

View File

@ -3,9 +3,9 @@
trait Trait {} 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 //~^ ERROR incorrect parentheses around trait bounds
ptr as _ loop {}
} }
fn foo2(_: &dyn (Trait + Send)) {} fn foo2(_: &dyn (Trait + Send)) {}

View File

@ -1,13 +1,13 @@
error: incorrect parentheses around trait bounds 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 help: fix the parentheses
| |
LL - fn assert_send(ptr: *mut dyn Trait) -> *mut dyn (Trait + Send) { LL - fn assert_send() -> *mut dyn (Trait + Send) {
LL + fn assert_send(ptr: *mut dyn Trait) -> *mut (dyn Trait + Send) { LL + fn assert_send() -> *mut (dyn Trait + Send) {
| |
error: incorrect parentheses around trait bounds error: incorrect parentheses around trait bounds

View File

@ -1,7 +1,8 @@
#![feature(trait_upcasting)] #![feature(trait_upcasting)]
//@ known-bug: #120222 // check-fail
//@ check-pass //
//! This will segfault at runtime. // issue: <https://github.com/rust-lang/rust/pull/120222>
//! This would segfault at runtime.
pub trait SupSupA { pub trait SupSupA {
fn method(&self) {} fn method(&self) {}
@ -56,6 +57,7 @@ pub fn user2() -> &'static dyn Trait<u8, u16> {
fn main() { fn main() {
let p: *const dyn Trait<u8, u8> = &(); let p: *const dyn Trait<u8, u8> = &();
let p = p as *const dyn Trait<u8, u16>; // <- this is bad! 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 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)', // accessing from L__unnamed_2 the position for the 'Super<u16> vtable (pointer)',
// thus reading 'null pointer for missing_method' // thus reading 'null pointer for missing_method'

View File

@ -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`.