blessings
This commit is contained in:
parent
5645e8e285
commit
bb651d358d
@ -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)]
|
||||
|
@ -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 {
|
||||
| ^^^
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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)) {}
|
||||
|
@ -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)) {}
|
||||
|
@ -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
|
||||
|
@ -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) {}
|
||||
@ -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'
|
||||
|
11
tests/ui/traits/upcast_soundness_bug.stderr
Normal file
11
tests/ui/traits/upcast_soundness_bug.stderr
Normal 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`.
|
Loading…
Reference in New Issue
Block a user