rust/tests/ui/coercion/coerce-expect-unsized.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
1.6 KiB
Rust
Raw Normal View History

// run-pass
2020-03-27 15:56:19 -05:00
#![allow(unused_braces)]
use std::cell::RefCell;
std: Rename Show/String to Debug/Display This commit is an implementation of [RFC 565][rfc] which is a stabilization of the `std::fmt` module and the implementations of various formatting traits. Specifically, the following changes were performed: [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0565-show-string-guidelines.md * The `Show` trait is now deprecated, it was renamed to `Debug` * The `String` trait is now deprecated, it was renamed to `Display` * Many `Debug` and `Display` implementations were audited in accordance with the RFC and audited implementations now have the `#[stable]` attribute * Integers and floats no longer print a suffix * Smart pointers no longer print details that they are a smart pointer * Paths with `Debug` are now quoted and escape characters * The `unwrap` methods on `Result` now require `Display` instead of `Debug` * The `Error` trait no longer has a `detail` method and now requires that `Display` must be implemented. With the loss of `String`, this has moved into libcore. * `impl<E: Error> FromError<E> for Box<Error>` now exists * `derive(Show)` has been renamed to `derive(Debug)`. This is not currently warned about due to warnings being emitted on stage1+ While backwards compatibility is attempted to be maintained with a blanket implementation of `Display` for the old `String` trait (and the same for `Show`/`Debug`) this is still a breaking change due to primitives no longer implementing `String` as well as modifications such as `unwrap` and the `Error` trait. Most code is fairly straightforward to update with a rename or tweaks of method calls. [breaking-change] Closes #21436
2015-01-20 17:45:07 -06:00
use std::fmt::Debug;
use std::rc::Rc;
// Check that coercions apply at the pointer level and don't cause
// rvalue expressions to be unsized. See #20169 for more information.
pub fn main() {
let _: Box<[isize]> = Box::new({ [1, 2, 3] });
let _: Box<[isize]> = Box::new(if true { [1, 2, 3] } else { [1, 3, 4] });
let _: Box<[isize]> = Box::new(match true { true => [1, 2, 3], false => [1, 3, 4] });
2019-05-28 13:47:21 -05:00
let _: Box<dyn Fn(isize) -> _> = Box::new({ |x| (x as u8) });
let _: Box<dyn Debug> = Box::new(if true { false } else { true });
let _: Box<dyn Debug> = Box::new(match true { true => 'a', false => 'b' });
let _: &[isize] = &{ [1, 2, 3] };
let _: &[isize] = &if true { [1, 2, 3] } else { [1, 3, 4] };
let _: &[isize] = &match true { true => [1, 2, 3], false => [1, 3, 4] };
2019-05-28 13:47:21 -05:00
let _: &dyn Fn(isize) -> _ = &{ |x| (x as u8) };
let _: &dyn Debug = &if true { false } else { true };
let _: &dyn Debug = &match true { true => 'a', false => 'b' };
2016-02-14 07:38:48 -06:00
let _: &str = &{ String::new() };
let _: &str = &if true { String::from("...") } else { 5.to_string() };
let _: &str = &match true {
true => format!("{}", false),
false => ["x", "y"].join("+")
};
let _: Box<[isize]> = Box::new([1, 2, 3]);
2019-05-28 13:47:21 -05:00
let _: Box<dyn Fn(isize) -> _> = Box::new(|x| (x as u8));
let _: Rc<RefCell<[isize]>> = Rc::new(RefCell::new([1, 2, 3]));
2019-05-28 13:47:21 -05:00
let _: Rc<RefCell<dyn FnMut(isize) -> _>> = Rc::new(RefCell::new(|x| (x as u8)));
2019-05-28 13:47:21 -05:00
let _: Vec<Box<dyn Fn(isize) -> _>> = vec![
Box::new(|x| (x as u8)),
Box::new(|x| (x as i16 as u8)),
];
}