Update transmute size lints.
Also moves a few transmute tests to UI tests to better test their output.
This commit is contained in:
parent
28cc0c5a7b
commit
effa869cab
17 changed files with 247 additions and 33 deletions
|
|
@ -12,5 +12,4 @@ fn takes_u8(_: u8) {}
|
|||
|
||||
fn main() {
|
||||
unsafe { takes_u8(::std::mem::transmute(0u16)); } //~ ERROR E0512
|
||||
//~| transmuting between 16 bits and 8 bits
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ trait Trait<'a> {
|
|||
|
||||
fn foo<'a, T: Trait<'a>>(value: T::A) {
|
||||
let new: T::B = unsafe { std::mem::transmute(value) };
|
||||
//~^ ERROR: transmute called with differently sized types
|
||||
//~^ ERROR: transmute called with types of different sizes
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ struct ArrayPeano<T: Bar> {
|
|||
}
|
||||
|
||||
fn foo<T>(a: &ArrayPeano<T>) -> &[T] where T: Bar {
|
||||
unsafe { std::mem::transmute(a) } //~ ERROR transmute called with differently sized types
|
||||
unsafe { std::mem::transmute(a) } //~ ERROR transmute called with types of different sizes
|
||||
}
|
||||
|
||||
impl Bar for () {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ struct Bar<U: Foo> {
|
|||
|
||||
fn foo<U: Foo>(x: [usize; 2]) -> Bar<U> {
|
||||
unsafe { mem::transmute(x) }
|
||||
//~^ ERROR transmute called with differently sized types
|
||||
//~^ ERROR transmute called with types of different sizes
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
// the error points to the start of the file, not the line with the
|
||||
// transmute
|
||||
|
||||
// error-pattern: transmute called with differently sized types
|
||||
// error-pattern: transmute called with types of different sizes
|
||||
|
||||
use std::mem;
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
// the error points to the start of the file, not the line with the
|
||||
// transmute
|
||||
|
||||
// error-pattern: transmute called with differently sized types
|
||||
// error-pattern: transmute called with types of different sizes
|
||||
|
||||
use std::mem;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,12 +17,12 @@ use std::mem::transmute;
|
|||
|
||||
unsafe fn f() {
|
||||
let _: i8 = transmute(16i16);
|
||||
//~^ ERROR transmute called with differently sized types
|
||||
//~^ ERROR transmute called with types of different sizes
|
||||
}
|
||||
|
||||
unsafe fn g<T>(x: &T) {
|
||||
let _: i8 = transmute(x);
|
||||
//~^ ERROR transmute called with differently sized types
|
||||
//~^ ERROR transmute called with types of different sizes
|
||||
}
|
||||
|
||||
trait Specializable { type Output; }
|
||||
|
|
@ -33,7 +33,7 @@ impl<T> Specializable for T {
|
|||
|
||||
unsafe fn specializable<T>(x: u16) -> <T as Specializable>::Output {
|
||||
transmute(x)
|
||||
//~^ ERROR transmute called with differently sized types
|
||||
//~^ ERROR transmute called with types of different sizes
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -15,11 +15,11 @@
|
|||
use std::mem::transmute;
|
||||
|
||||
fn a<T, U: ?Sized>(x: &[T]) -> &U {
|
||||
unsafe { transmute(x) } //~ ERROR transmute called with differently sized types
|
||||
unsafe { transmute(x) } //~ ERROR transmute called with types of different sizes
|
||||
}
|
||||
|
||||
fn b<T: ?Sized, U: ?Sized>(x: &T) -> &U {
|
||||
unsafe { transmute(x) } //~ ERROR transmute called with differently sized types
|
||||
unsafe { transmute(x) } //~ ERROR transmute called with types of different sizes
|
||||
}
|
||||
|
||||
fn c<T, U>(x: &T) -> &U {
|
||||
|
|
@ -31,11 +31,11 @@ fn d<T, U>(x: &[T]) -> &[U] {
|
|||
}
|
||||
|
||||
fn e<T: ?Sized, U>(x: &T) -> &U {
|
||||
unsafe { transmute(x) } //~ ERROR transmute called with differently sized types
|
||||
unsafe { transmute(x) } //~ ERROR transmute called with types of different sizes
|
||||
}
|
||||
|
||||
fn f<T, U: ?Sized>(x: &T) -> &U {
|
||||
unsafe { transmute(x) } //~ ERROR transmute called with differently sized types
|
||||
unsafe { transmute(x) } //~ ERROR transmute called with types of different sizes
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
|
|||
|
|
@ -1,70 +0,0 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::mem;
|
||||
|
||||
unsafe fn foo() -> (isize, *const (), Option<fn()>) {
|
||||
let i = mem::transmute(bar);
|
||||
//~^ ERROR is zero-sized and can't be transmuted
|
||||
//~^^ NOTE cast with `as` to a pointer instead
|
||||
|
||||
let p = mem::transmute(foo);
|
||||
//~^ ERROR is zero-sized and can't be transmuted
|
||||
//~^^ NOTE cast with `as` to a pointer instead
|
||||
|
||||
let of = mem::transmute(main);
|
||||
//~^ ERROR is zero-sized and can't be transmuted
|
||||
//~^^ NOTE cast with `as` to a pointer instead
|
||||
|
||||
(i, p, of)
|
||||
}
|
||||
|
||||
unsafe fn bar() {
|
||||
// Error as usual if the resulting type is not pointer-sized.
|
||||
mem::transmute::<_, u8>(main);
|
||||
//~^ ERROR transmute called with differently sized types
|
||||
//~^^ NOTE transmuting between 0 bits and 8 bits
|
||||
|
||||
mem::transmute::<_, *mut ()>(foo);
|
||||
//~^ ERROR is zero-sized and can't be transmuted
|
||||
//~^^ NOTE cast with `as` to a pointer instead
|
||||
|
||||
mem::transmute::<_, fn()>(bar);
|
||||
//~^ ERROR is zero-sized and can't be transmuted
|
||||
//~^^ NOTE cast with `as` to a pointer instead
|
||||
|
||||
// No error if a coercion would otherwise occur.
|
||||
mem::transmute::<fn(), usize>(main);
|
||||
}
|
||||
|
||||
unsafe fn baz() {
|
||||
mem::transmute::<_, *mut ()>(Some(foo));
|
||||
//~^ ERROR is zero-sized and can't be transmuted
|
||||
//~^^ NOTE cast with `as` to a pointer instead
|
||||
|
||||
mem::transmute::<_, fn()>(Some(bar));
|
||||
//~^ ERROR is zero-sized and can't be transmuted
|
||||
//~^^ NOTE cast with `as` to a pointer instead
|
||||
|
||||
mem::transmute::<_, Option<fn()>>(Some(baz));
|
||||
//~^ ERROR is zero-sized and can't be transmuted
|
||||
//~^^ NOTE cast with `as` to a pointer instead
|
||||
|
||||
// No error if a coercion would otherwise occur.
|
||||
mem::transmute::<Option<fn()>, usize>(Some(main));
|
||||
}
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
foo();
|
||||
bar();
|
||||
baz();
|
||||
}
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ impl<T: ?Sized> Foo<T> {
|
|||
|
||||
fn n(x: &T) -> &isize {
|
||||
// Not OK here, because T : Sized is not in scope.
|
||||
unsafe { transmute(x) } //~ ERROR transmute called with differently sized types
|
||||
unsafe { transmute(x) } //~ ERROR transmute called with types of different sizes
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,54 +0,0 @@
|
|||
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Tests that `transmute` cannot be called on type parameters.
|
||||
|
||||
use std::mem::transmute;
|
||||
|
||||
unsafe fn f<T>(x: T) {
|
||||
let _: isize = transmute(x);
|
||||
//~^ ERROR differently sized types: T (size can vary) to isize
|
||||
}
|
||||
|
||||
unsafe fn g<T>(x: (T, isize)) {
|
||||
let _: isize = transmute(x);
|
||||
//~^ ERROR differently sized types: (T, isize) (size can vary because of T) to isize
|
||||
}
|
||||
|
||||
unsafe fn h<T>(x: [T; 10]) {
|
||||
let _: isize = transmute(x);
|
||||
//~^ ERROR differently sized types: [T; 10] (size can vary because of T) to isize
|
||||
}
|
||||
|
||||
struct Bad<T> {
|
||||
f: T,
|
||||
}
|
||||
|
||||
unsafe fn i<T>(x: Bad<T>) {
|
||||
let _: isize = transmute(x);
|
||||
//~^ ERROR differently sized types: Bad<T> (size can vary because of T) to isize
|
||||
}
|
||||
|
||||
enum Worse<T> {
|
||||
A(T),
|
||||
B,
|
||||
}
|
||||
|
||||
unsafe fn j<T>(x: Worse<T>) {
|
||||
let _: isize = transmute(x);
|
||||
//~^ ERROR differently sized types: Worse<T> (size can vary because of T) to isize
|
||||
}
|
||||
|
||||
unsafe fn k<T>(x: Option<T>) {
|
||||
let _: isize = transmute(x);
|
||||
//~^ ERROR differently sized types: std::option::Option<T> (size can vary because of T) to isize
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue