+++ /dev/null
-// run-pass
-
-#![allow(unused_imports)]
-#![deny(unused_assignments)]
-
-use std::mem;
-use std::ops::{
- AddAssign, BitAndAssign, BitOrAssign, BitXorAssign, DivAssign, Index, MulAssign, RemAssign,
- ShlAssign, ShrAssign, SubAssign,
-};
-
-#[derive(Debug, PartialEq)]
-struct Int(i32);
-
-struct Slice([i32]);
-
-impl Slice {
- fn new(slice: &mut [i32]) -> &mut Slice {
- unsafe {
- mem::transmute(slice)
- }
- }
-}
-
-struct View<'a>(&'a mut [i32]);
-
-fn main() {
- let mut x = Int(1);
-
- x += Int(2);
- assert_eq!(x, Int(0b11));
-
- x &= Int(0b01);
- assert_eq!(x, Int(0b01));
-
- x |= Int(0b10);
- assert_eq!(x, Int(0b11));
-
- x ^= Int(0b01);
- assert_eq!(x, Int(0b10));
-
- x /= Int(2);
- assert_eq!(x, Int(1));
-
- x *= Int(3);
- assert_eq!(x, Int(3));
-
- x %= Int(2);
- assert_eq!(x, Int(1));
-
- // overloaded RHS
- x <<= 1u8;
- assert_eq!(x, Int(2));
-
- x <<= 1u16;
- assert_eq!(x, Int(4));
-
- x >>= 1u8;
- assert_eq!(x, Int(2));
-
- x >>= 1u16;
- assert_eq!(x, Int(1));
-
- x -= Int(1);
- assert_eq!(x, Int(0));
-
- // indexed LHS
- let mut v = vec![Int(1), Int(2)];
- v[0] += Int(2);
- assert_eq!(v[0], Int(3));
-
- // unsized RHS
- let mut array = [0, 1, 2];
- *Slice::new(&mut array) += 1;
- assert_eq!(array[0], 1);
- assert_eq!(array[1], 2);
- assert_eq!(array[2], 3);
-
- // sized indirection
- // check that this does *not* trigger the unused_assignments lint
- let mut array = [0, 1, 2];
- let mut view = View(&mut array);
- view += 1;
-}
-
-impl AddAssign for Int {
- fn add_assign(&mut self, rhs: Int) {
- self.0 += rhs.0;
- }
-}
-
-impl BitAndAssign for Int {
- fn bitand_assign(&mut self, rhs: Int) {
- self.0 &= rhs.0;
- }
-}
-
-impl BitOrAssign for Int {
- fn bitor_assign(&mut self, rhs: Int) {
- self.0 |= rhs.0;
- }
-}
-
-impl BitXorAssign for Int {
- fn bitxor_assign(&mut self, rhs: Int) {
- self.0 ^= rhs.0;
- }
-}
-
-impl DivAssign for Int {
- fn div_assign(&mut self, rhs: Int) {
- self.0 /= rhs.0;
- }
-}
-
-impl MulAssign for Int {
- fn mul_assign(&mut self, rhs: Int) {
- self.0 *= rhs.0;
- }
-}
-
-impl RemAssign for Int {
- fn rem_assign(&mut self, rhs: Int) {
- self.0 %= rhs.0;
- }
-}
-
-impl ShlAssign<u8> for Int {
- fn shl_assign(&mut self, rhs: u8) {
- self.0 <<= rhs;
- }
-}
-
-impl ShlAssign<u16> for Int {
- fn shl_assign(&mut self, rhs: u16) {
- self.0 <<= rhs;
- }
-}
-
-impl ShrAssign<u8> for Int {
- fn shr_assign(&mut self, rhs: u8) {
- self.0 >>= rhs;
- }
-}
-
-impl ShrAssign<u16> for Int {
- fn shr_assign(&mut self, rhs: u16) {
- self.0 >>= rhs;
- }
-}
-
-impl SubAssign for Int {
- fn sub_assign(&mut self, rhs: Int) {
- self.0 -= rhs.0;
- }
-}
-
-impl AddAssign<i32> for Slice {
- fn add_assign(&mut self, rhs: i32) {
- for lhs in &mut self.0 {
- *lhs += rhs;
- }
- }
-}
-
-impl<'a> AddAssign<i32> for View<'a> {
- fn add_assign(&mut self, rhs: i32) {
- for lhs in self.0.iter_mut() {
- *lhs += rhs;
- }
- }
-}
+++ /dev/null
-// no-prefer-dynamic
-
-#![crate_type="rlib"]
-#![crate_name="rmeta_aux"]
-
-pub struct Foo {
- pub field: i32,
-}
+++ /dev/null
-// no-prefer-dynamic
-
-// This aux-file will require the eh_personality function to be codegen'd, but
-// it hasn't been defined just yet. Make sure we don't explode.
-
-#![no_std]
-#![crate_type = "rlib"]
-
-struct A;
-
-impl core::ops::Drop for A {
- fn drop(&mut self) {}
-}
-
-pub fn foo() {
- let _a = A;
- panic!("wut");
-}
-
-mod std {
- pub use core::{option, fmt};
-}
+++ /dev/null
-// run-pass
-#![allow(unused_mut)]
-#![allow(unused_variables)]
-// pretty-expanded FIXME #23616
-
-#![feature(box_syntax)]
-
-struct A { a: isize, b: Box<isize> }
-struct B { a: Box<isize>, b: Box<isize> }
-
-fn move_after_copy() {
- let x = A { a: 1, b: box 2 };
- drop(x.a);
- drop(x.b);
-}
-
-fn move_after_fu_copy() {
- let x = A { a: 1, b: box 2 };
- let _y = A { b: box 3, .. x };
- drop(x.b);
-}
-
-fn fu_move_after_copy() {
- let x = A { a: 1, b: box 2 };
- drop(x.a);
- let _y = A { a: 3, .. x };
-}
-
-fn fu_move_after_fu_copy() {
- let x = A { a: 1, b: box 2 };
- let _y = A { b: box 3, .. x };
- let _z = A { a: 4, .. x };
-}
-
-fn copy_after_move() {
- let x = A { a: 1, b: box 2 };
- drop(x.b);
- drop(x.a);
-}
-
-fn copy_after_fu_move() {
- let x = A { a: 1, b: box 2 };
- let y = A { a: 3, .. x };
- drop(x.a);
-}
-
-fn fu_copy_after_move() {
- let x = A { a: 1, b: box 2 };
- drop(x.b);
- let _y = A { b: box 3, .. x };
-}
-
-fn fu_copy_after_fu_move() {
- let x = A { a: 1, b: box 2 };
- let _y = A { a: 3, .. x };
- let _z = A { b: box 3, .. x };
-}
-
-fn borrow_after_move() {
- let x = A { a: 1, b: box 2 };
- drop(x.b);
- let p = &x.a;
- drop(*p);
-}
-
-fn borrow_after_fu_move() {
- let x = A { a: 1, b: box 2 };
- let _y = A { a: 3, .. x };
- let p = &x.a;
- drop(*p);
-}
-
-fn move_after_borrow() {
- let x = A { a: 1, b: box 2 };
- let p = &x.a;
- drop(x.b);
- drop(*p);
-}
-
-fn fu_move_after_borrow() {
- let x = A { a: 1, b: box 2 };
- let p = &x.a;
- let _y = A { a: 3, .. x };
- drop(*p);
-}
-
-fn mut_borrow_after_mut_borrow() {
- let mut x = A { a: 1, b: box 2 };
- let p = &mut x.a;
- let q = &mut x.b;
- drop(*p);
- drop(**q);
-}
-
-fn move_after_move() {
- let x = B { a: box 1, b: box 2 };
- drop(x.a);
- drop(x.b);
-}
-
-fn move_after_fu_move() {
- let x = B { a: box 1, b: box 2 };
- let y = B { a: box 3, .. x };
- drop(x.a);
-}
-
-fn fu_move_after_move() {
- let x = B { a: box 1, b: box 2 };
- drop(x.a);
- let z = B { a: box 3, .. x };
- drop(z.b);
-}
-
-fn fu_move_after_fu_move() {
- let x = B { a: box 1, b: box 2 };
- let _y = B { b: box 3, .. x };
- let _z = B { a: box 4, .. x };
-}
-
-fn copy_after_assign_after_move() {
- let mut x = A { a: 1, b: box 2 };
- drop(x.b);
- x = A { a: 3, b: box 4 };
- drop(*x.b);
-}
-
-fn copy_after_assign_after_fu_move() {
- let mut x = A { a: 1, b: box 2 };
- let _y = A { a: 3, .. x };
- x = A { a: 3, b: box 4 };
- drop(*x.b);
-}
-
-fn copy_after_field_assign_after_move() {
- let mut x = A { a: 1, b: box 2 };
- drop(x.b);
- x.b = box 3;
- drop(*x.b);
-}
-
-fn copy_after_field_assign_after_fu_move() {
- let mut x = A { a: 1, b: box 2 };
- let _y = A { a: 3, .. x };
- x.b = box 3;
- drop(*x.b);
-}
-
-fn borrow_after_assign_after_move() {
- let mut x = A { a: 1, b: box 2 };
- drop(x.b);
- x = A { a: 3, b: box 4 };
- let p = &x.b;
- drop(**p);
-}
-
-fn borrow_after_assign_after_fu_move() {
- let mut x = A { a: 1, b: box 2 };
- let _y = A { a: 3, .. x };
- x = A { a: 3, b: box 4 };
- let p = &x.b;
- drop(**p);
-}
-
-fn borrow_after_field_assign_after_move() {
- let mut x = A { a: 1, b: box 2 };
- drop(x.b);
- x.b = box 3;
- let p = &x.b;
- drop(**p);
-}
-
-fn borrow_after_field_assign_after_fu_move() {
- let mut x = A { a: 1, b: box 2 };
- let _y = A { a: 3, .. x };
- x.b = box 3;
- let p = &x.b;
- drop(**p);
-}
-
-fn move_after_assign_after_move() {
- let mut x = A { a: 1, b: box 2 };
- let _y = x.b;
- x = A { a: 3, b: box 4 };
- drop(x.b);
-}
-
-fn move_after_assign_after_fu_move() {
- let mut x = A { a: 1, b: box 2 };
- let _y = A { a: 3, .. x };
- x = A { a: 3, b: box 4 };
- drop(x.b);
-}
-
-fn move_after_field_assign_after_move() {
- let mut x = A { a: 1, b: box 2 };
- drop(x.b);
- x.b = box 3;
- drop(x.b);
-}
-
-fn move_after_field_assign_after_fu_move() {
- let mut x = A { a: 1, b: box 2 };
- let _y = A { a: 3, .. x };
- x.b = box 3;
- drop(x.b);
-}
-
-fn copy_after_assign_after_uninit() {
- let mut x: A;
- x = A { a: 1, b: box 2 };
- drop(x.a);
-}
-
-fn borrow_after_assign_after_uninit() {
- let mut x: A;
- x = A { a: 1, b: box 2 };
- let p = &x.a;
- drop(*p);
-}
-
-fn move_after_assign_after_uninit() {
- let mut x: A;
- x = A { a: 1, b: box 2 };
- drop(x.b);
-}
-
-fn main() {
- move_after_copy();
- move_after_fu_copy();
- fu_move_after_copy();
- fu_move_after_fu_copy();
- copy_after_move();
- copy_after_fu_move();
- fu_copy_after_move();
- fu_copy_after_fu_move();
-
- borrow_after_move();
- borrow_after_fu_move();
- move_after_borrow();
- fu_move_after_borrow();
- mut_borrow_after_mut_borrow();
-
- move_after_move();
- move_after_fu_move();
- fu_move_after_move();
- fu_move_after_fu_move();
-
- copy_after_assign_after_move();
- copy_after_assign_after_fu_move();
- copy_after_field_assign_after_move();
- copy_after_field_assign_after_fu_move();
-
- borrow_after_assign_after_move();
- borrow_after_assign_after_fu_move();
- borrow_after_field_assign_after_move();
- borrow_after_field_assign_after_fu_move();
-
- move_after_assign_after_move();
- move_after_assign_after_fu_move();
- move_after_field_assign_after_move();
- move_after_field_assign_after_fu_move();
-
- copy_after_assign_after_uninit();
- borrow_after_assign_after_uninit();
- move_after_assign_after_uninit();
-}
+++ /dev/null
-// run-pass
-//compile-flags: -Z borrowck=mir
-
-#![feature(slice_patterns)]
-
-fn mut_head_tail<'a, A>(v: &'a mut [A]) -> Option<(&'a mut A, &'a mut [A])> {
- match *v {
- [ref mut head, ref mut tail..] => {
- Some((head, tail))
- }
- [] => None
- }
-}
-
-fn main() {
- let mut v = [1,2,3,4];
- match mut_head_tail(&mut v) {
- None => {},
- Some((h,t)) => {
- *h = 1000;
- t.reverse();
- }
- }
-}
+++ /dev/null
-// run-pass
-// pretty-expanded FIXME #23616
-
-#![feature(box_syntax)]
-
-struct A { a: isize, b: Box<isize> }
-
-fn field_copy_after_field_borrow() {
- let mut x = A { a: 1, b: box 2 };
- let p = &mut x.b;
- drop(x.a);
- **p = 3;
-}
-
-fn fu_field_copy_after_field_borrow() {
- let mut x = A { a: 1, b: box 2 };
- let p = &mut x.b;
- let y = A { b: box 3, .. x };
- drop(y);
- **p = 4;
-}
-
-fn field_deref_after_field_borrow() {
- let mut x = A { a: 1, b: box 2 };
- let p = &mut x.a;
- drop(*x.b);
- *p = 3;
-}
-
-fn field_move_after_field_borrow() {
- let mut x = A { a: 1, b: box 2 };
- let p = &mut x.a;
- drop(x.b);
- *p = 3;
-}
-
-fn fu_field_move_after_field_borrow() {
- let mut x = A { a: 1, b: box 2 };
- let p = &mut x.a;
- let y = A { a: 3, .. x };
- drop(y);
- *p = 4;
-}
-
-fn main() {
- field_copy_after_field_borrow();
- fu_field_copy_after_field_borrow();
- field_deref_after_field_borrow();
- field_move_after_field_borrow();
- fu_field_move_after_field_borrow();
-}
+++ /dev/null
-#![crate_type = "rlib"]
-#![feature(fundamental)]
-
-pub trait MyCopy { }
-impl MyCopy for i32 { }
-
-pub struct MyStruct<T>(T);
-
-#[fundamental]
-pub struct MyFundamentalStruct<T>(T);
+++ /dev/null
-#![crate_type="lib"]
-
-pub trait Remote {
- fn foo(&self) { }
-}
-
-pub trait Remote1<T> {
- fn foo(&self, t: T) { }
-}
-
-pub trait Remote2<T, U> {
- fn foo(&self, t: T, u: U) { }
-}
-
-pub struct Pair<T,U>(T,U);
+++ /dev/null
-// run-pass
-// revisions: old re
-
-#![cfg_attr(re, feature(re_rebalance_coherence))]
-#![allow(dead_code)]
-// pretty-expanded FIXME #23616
-
-#![feature(optin_builtin_traits)]
-
-use std::marker::Send;
-
-struct TestType;
-
-impl !Send for TestType {}
-
-fn main() {}
+++ /dev/null
-#![allow(dead_code)]
-#![feature(re_rebalance_coherence)]
-
-// run-pass
-// aux-build:re_rebalance_coherence_lib.rs
-
-extern crate re_rebalance_coherence_lib as lib;
-use lib::*;
-
-struct Oracle;
-impl Backend for Oracle {}
-impl<'a, T:'a, Tab> QueryFragment<Oracle> for BatchInsert<'a, T, Tab> {}
-
-fn main() {}
+++ /dev/null
-// run-pass
-
-pub fn main() {
- assert_eq!(format!(concat!("foo", "bar", "{}"), "baz"), "foobarbaz".to_string());
- assert_eq!(format!(concat!()), "".to_string());
- // check trailing comma is allowed in concat
- assert_eq!(concat!("qux", "quux",).to_string(), "quxquux".to_string());
-
- assert_eq!(
- concat!(1, 2, 3, 4f32, 4.0, 'a', true),
- "12344.0atrue"
- );
-
- assert!(match "12344.0atrue" {
- concat!(1, 2, 3, 4f32, 4.0, 'a', true) => true,
- _ => false
- })
-}
+++ /dev/null
-// Crate that exports a const fn. Used for testing cross-crate.
-
-#![crate_type="rlib"]
-
-pub const fn foo() -> usize { 22 }
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-
-#[repr(u8)]
-enum Foo {
- Bar = { let x = 1; 3 }
-}
-
-pub fn main() {
- assert_eq!(3, Foo::Bar as u8);
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-// check for const_err regressions
-
-#![deny(const_err)]
-
-const X: *const u8 = b"" as _;
-const Y: bool = 'A' == 'B';
-const Z: char = 'A';
-const W: bool = Z <= 'B';
-
-
-fn main() {
- let _ = ((-1 as i8) << 8 - 1) as f32;
- let _ = 0u8 as char;
- let _ = true > false;
- let _ = true >= false;
- let _ = true < false;
- let _ = true >= false;
-}
+++ /dev/null
-// run-pass
-
-#![feature(const_int_conversion)]
-
-const REVERSE: u32 = 0x12345678_u32.reverse_bits();
-const FROM_BE_BYTES: i32 = i32::from_be_bytes([0x12, 0x34, 0x56, 0x78]);
-const FROM_LE_BYTES: i32 = i32::from_le_bytes([0x12, 0x34, 0x56, 0x78]);
-const FROM_NE_BYTES: i32 = i32::from_be(i32::from_ne_bytes([0x80, 0, 0, 0]));
-const TO_BE_BYTES: [u8; 4] = 0x12_34_56_78_i32.to_be_bytes();
-const TO_LE_BYTES: [u8; 4] = 0x12_34_56_78_i32.to_le_bytes();
-const TO_NE_BYTES: [u8; 4] = i32::min_value().to_be().to_ne_bytes();
-
-fn main() {
- assert_eq!(REVERSE, 0x1e6a2c48);
- assert_eq!(FROM_BE_BYTES, 0x12_34_56_78);
- assert_eq!(FROM_LE_BYTES, 0x78_56_34_12);
- assert_eq!(FROM_NE_BYTES, i32::min_value());
- assert_eq!(TO_BE_BYTES, [0x12, 0x34, 0x56, 0x78]);
- assert_eq!(TO_LE_BYTES, [0x78, 0x56, 0x34, 0x12]);
- assert_eq!(TO_NE_BYTES, [0x80, 0, 0, 0]);
-}
+++ /dev/null
-// run-pass
-
-const ADD_A: (u32, bool) = 5u32.overflowing_add(2);
-const ADD_B: (u32, bool) = u32::max_value().overflowing_add(1);
-
-const SUB_A: (u32, bool) = 5u32.overflowing_sub(2);
-const SUB_B: (u32, bool) = 0u32.overflowing_sub(1);
-
-const MUL_A: (u32, bool) = 5u32.overflowing_mul(2);
-const MUL_B: (u32, bool) = 1_000_000_000u32.overflowing_mul(10);
-
-const SHL_A: (u32, bool) = 0x1u32.overflowing_shl(4);
-const SHL_B: (u32, bool) = 0x1u32.overflowing_shl(132);
-
-const SHR_A: (u32, bool) = 0x10u32.overflowing_shr(4);
-const SHR_B: (u32, bool) = 0x10u32.overflowing_shr(132);
-
-const NEG_A: (u32, bool) = 0u32.overflowing_neg();
-const NEG_B: (u32, bool) = core::u32::MAX.overflowing_neg();
-
-fn main() {
- assert_eq!(ADD_A, (7, false));
- assert_eq!(ADD_B, (0, true));
-
- assert_eq!(SUB_A, (3, false));
- assert_eq!(SUB_B, (u32::max_value(), true));
-
- assert_eq!(MUL_A, (10, false));
- assert_eq!(MUL_B, (1410065408, true));
-
- assert_eq!(SHL_A, (0x10, false));
- assert_eq!(SHL_B, (0x10, true));
-
- assert_eq!(SHR_A, (0x1, false));
- assert_eq!(SHR_B, (0x1, true));
-
- assert_eq!(NEG_A, (0, false));
- assert_eq!(NEG_B, (1, true));
-}
+++ /dev/null
-// run-pass
-
-const LEFT: u32 = 0x10000b3u32.rotate_left(8);
-const RIGHT: u32 = 0xb301u32.rotate_right(8);
-
-// Rotating these should make no difference
-//
-// We test using 124 bits because to ensure that overlong bit shifts do
-// not cause undefined behaviour. See #10183.
-const LEFT_OVERFLOW: i16 = 0i16.rotate_left(124);
-const RIGHT_OVERFLOW: i16 = 0i16.rotate_right(124);
-const ONE_LEFT_OVERFLOW: u16 = 1u16.rotate_left(124);
-const ONE_RIGHT_OVERFLOW: u16 = 1u16.rotate_right(124);
-
-const NON_ZERO_LEFT_OVERFLOW: u16 = 0b10u16.rotate_left(124);
-const NON_ZERO_RIGHT_OVERFLOW: u16 = 0b10u16.rotate_right(124);
-
-// Rotating by 0 should have no effect
-const ZERO_ROTATE_LEFT: i8 = 0b0010_0001i8.rotate_left(0);
-const ZERO_ROTATE_RIGHT: i8 = 0b0111_1001i8.rotate_right(0);
-
-// Rotating by a multiple of word size should also have no effect
-const MULTIPLE_ROTATE_LEFT: i32 = 0b0010_0001i32.rotate_left(128);
-const MULTIPLE_ROTATE_RIGHT: i32 = 0b0010_0001i32.rotate_right(128);
-
-fn main() {
- assert_eq!(LEFT, 0xb301);
- assert_eq!(RIGHT, 0x0100_00b3);
-
- assert_eq!(LEFT_OVERFLOW, 0);
- assert_eq!(RIGHT_OVERFLOW, 0);
- assert_eq!(ONE_LEFT_OVERFLOW, 0b0001_0000_0000_0000);
- assert_eq!(ONE_RIGHT_OVERFLOW, 0b0001_0000);
-
- assert_eq!(NON_ZERO_LEFT_OVERFLOW, 0b0010_0000_0000_0000);
- assert_eq!(NON_ZERO_RIGHT_OVERFLOW, 0b0000_0000_0010_0000);
-
- assert_eq!(ZERO_ROTATE_LEFT, 0b0010_0001);
- assert_eq!(ZERO_ROTATE_RIGHT, 0b0111_1001);
-
- assert_eq!(MULTIPLE_ROTATE_LEFT, 0b0010_0001);
- assert_eq!(MULTIPLE_ROTATE_RIGHT, 0b0010_0001);
-}
+++ /dev/null
-// run-pass
-
-#![feature(const_int_sign)]
-
-const NEGATIVE_A: bool = (-10i32).is_negative();
-const NEGATIVE_B: bool = 10i32.is_negative();
-const POSITIVE_A: bool = (-10i32).is_positive();
-const POSITIVE_B: bool = 10i32.is_positive();
-
-const SIGNUM_POS: i32 = 10i32.signum();
-const SIGNUM_NIL: i32 = 0i32.signum();
-const SIGNUM_NEG: i32 = (-42i32).signum();
-
-fn main() {
- assert!(NEGATIVE_A);
- assert!(!NEGATIVE_B);
- assert!(!POSITIVE_A);
- assert!(POSITIVE_B);
-
- assert_eq!(SIGNUM_POS, 1);
- assert_eq!(SIGNUM_NIL, 0);
- assert_eq!(SIGNUM_NEG, -1);
-}
+++ /dev/null
-// run-pass
-
-const ADD_A: u32 = 200u32.wrapping_add(55);
-const ADD_B: u32 = 200u32.wrapping_add(u32::max_value());
-
-const SUB_A: u32 = 100u32.wrapping_sub(100);
-const SUB_B: u32 = 100u32.wrapping_sub(u32::max_value());
-
-const MUL_A: u8 = 10u8.wrapping_mul(12);
-const MUL_B: u8 = 25u8.wrapping_mul(12);
-
-const SHL_A: u32 = 1u32.wrapping_shl(7);
-const SHL_B: u32 = 1u32.wrapping_shl(128);
-
-const SHR_A: u32 = 128u32.wrapping_shr(7);
-const SHR_B: u32 = 128u32.wrapping_shr(128);
-
-const NEG_A: u32 = 5u32.wrapping_neg();
-const NEG_B: u32 = 1234567890u32.wrapping_neg();
-
-fn main() {
- assert_eq!(ADD_A, 255);
- assert_eq!(ADD_B, 199);
-
- assert_eq!(SUB_A, 0);
- assert_eq!(SUB_B, 101);
-
- assert_eq!(MUL_A, 120);
- assert_eq!(MUL_B, 44);
-
- assert_eq!(SHL_A, 128);
- assert_eq!(SHL_B, 1);
-
- assert_eq!(SHR_A, 1);
- assert_eq!(SHR_B, 128);
-
- assert_eq!(NEG_A, 4294967291);
- assert_eq!(NEG_B, 3060399406);
-}
+++ /dev/null
-// run-pass
-
-#![feature(ptr_internals, test)]
-
-extern crate test;
-use test::black_box as b; // prevent promotion of the argument and const-propagation of the result
-
-use std::ptr::NonNull;
-
-const DANGLING: NonNull<u32> = NonNull::dangling();
-const CASTED: NonNull<u32> = NonNull::cast(NonNull::<i32>::dangling());
-
-pub fn main() {
- // Be super-extra paranoid and cast the fn items to fn pointers before blackboxing them.
- assert_eq!(DANGLING, b::<fn() -> _>(NonNull::dangling)());
- assert_eq!(CASTED, b::<fn() -> _>(NonNull::dangling)());
-}
+++ /dev/null
-// run-pass
-
-#![feature(ptr_internals, test)]
-
-extern crate test;
-use test::black_box as b; // prevent promotion of the argument and const-propagation of the result
-
-use std::ptr::Unique;
-
-
-const PTR: *mut u32 = Unique::empty().as_ptr();
-
-pub fn main() {
- // Be super-extra paranoid and cast the fn items to fn pointers before blackboxing them.
- assert_eq!(PTR, b::<fn() -> _>(Unique::<u32>::empty)().as_ptr());
-}
+++ /dev/null
-// run-pass
-#![feature(core_intrinsics)]
-#![feature(const_type_id)]
-
-use std::any::TypeId;
-
-struct A;
-
-static ID_ISIZE: TypeId = TypeId::of::<isize>();
-
-pub fn main() {
- assert_eq!(ID_ISIZE, TypeId::of::<isize>());
-
- // sanity test of TypeId
- const T: (TypeId, TypeId, TypeId) = (TypeId::of::<usize>(),
- TypeId::of::<&'static str>(),
- TypeId::of::<A>());
- let (d, e, f) = (TypeId::of::<usize>(), TypeId::of::<&'static str>(),
- TypeId::of::<A>());
-
- assert!(T.0 != T.1);
- assert!(T.0 != T.2);
- assert!(T.1 != T.2);
-
- assert_eq!(T.0, d);
- assert_eq!(T.1, e);
- assert_eq!(T.2, f);
-
- // Check fn pointer against collisions
- const F: (TypeId, TypeId) = (TypeId::of::<fn(fn(A) -> A) -> A>(),
- TypeId::of::<fn(fn() -> A, A) -> A>());
-
- assert!(F.0 != F.1);
-}
+++ /dev/null
-// run-pass
-
-#![feature(raw)]
-
-use std::mem;
-use std::raw;
-
-trait Foo {
- fn foo(&self) {}
-}
-
-struct Bar;
-
-impl Foo for Bar {}
-
-fn main() {
- // Test we can turn a fat pointer to array back into a thin pointer.
- let a: *const [i32] = &[1, 2, 3];
- let b = a as *const [i32; 2];
- unsafe {
- assert_eq!(*b, [1, 2]);
- }
-
- // Test conversion to an address (usize).
- let a: *const [i32; 3] = &[1, 2, 3];
- let b: *const [i32] = a;
- assert_eq!(a as usize, b as *const () as usize);
-
- // And conversion to a void pointer/address for trait objects too.
- let a: *mut dyn Foo = &mut Bar;
- let b = a as *mut ();
- let c = a as *const () as usize;
- let d = unsafe {
- let r: raw::TraitObject = mem::transmute(a);
- r.data
- };
-
- assert_eq!(b, d);
- assert_eq!(c, d as usize);
-
-}
+++ /dev/null
-// run-pass
-
-// Fast path, main can see the concrete type returned.
-fn before() -> impl FnMut(i32) {
- let mut p = Box::new(0);
- move |x| *p = x
-}
-
-fn send<T: Send>(_: T) {}
-
-fn main() {
- send(before());
- send(after());
-}
-
-// Deferred path, main has to wait until typeck finishes,
-// to check if the return type of after is Send.
-fn after() -> impl FnMut(i32) {
- let mut p = Box::new(0);
- move |x| *p = x
-}
+++ /dev/null
-// run-pass
-
-#![feature(specialization)]
-
-trait Foo: std::fmt::Debug + Eq {}
-
-impl<T: std::fmt::Debug + Eq> Foo for T {}
-
-fn hide<T: Foo>(x: T) -> impl Foo {
- x
-}
-
-trait Leak<T>: Sized {
- fn leak(self) -> T;
-}
-impl<T, U> Leak<T> for U {
- default fn leak(self) -> T { panic!("type mismatch") }
-}
-impl<T> Leak<T> for T {
- fn leak(self) -> T { self }
-}
-
-trait CheckIfSend: Sized {
- type T: Default;
- fn check(self) -> Self::T { Default::default() }
-}
-impl<T> CheckIfSend for T {
- default type T = ();
-}
-impl<T: Send> CheckIfSend for T {
- type T = bool;
-}
-
-fn lucky_seven() -> impl Fn(usize) -> u8 {
- let a = [1, 2, 3, 4, 5, 6, 7];
- move |i| a[i]
-}
-
-fn main() {
- assert_eq!(hide(42), hide(42));
-
- assert_eq!(std::mem::size_of_val(&hide([0_u8; 5])), 5);
- assert_eq!(std::mem::size_of_val(&lucky_seven()), 7);
-
- assert_eq!(Leak::<i32>::leak(hide(5_i32)), 5_i32);
-
- assert_eq!(CheckIfSend::check(hide(0_i32)), false);
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-use module_of_many_things::*;
-use dug::too::greedily::and::too::deep::*;
-
-mod module_of_many_things {
- pub fn f1() { println!("f1"); }
- pub fn f2() { println!("f2"); }
- fn f3() { println!("f3"); }
- pub fn f4() { println!("f4"); }
-}
-
-mod dug {
- pub mod too {
- pub mod greedily {
- pub mod and {
- pub mod too {
- pub mod deep {
- pub fn nameless_fear() { println!("Boo!"); }
- pub fn also_redstone() { println!("Whatever."); }
- }
- }
- }
- }
- }
-}
-
-
-pub fn main() { f1(); f2(); f4(); nameless_fear(); also_redstone(); }
+++ /dev/null
-// run-pass
-// pretty-expanded FIXME #23616
-
-extern "Rust" fn main() {}
+++ /dev/null
-// run-pass
-
-pub enum T {
- T1(()),
- T2(())
-}
-
-pub enum V {
- V1(isize),
- V2(bool)
-}
-
-fn foo(x: (T, V)) -> String {
- match x {
- (T::T1(()), V::V1(i)) => format!("T1(()), V1({})", i),
- (T::T2(()), V::V2(b)) => format!("T2(()), V2({})", b),
- _ => String::new()
- }
-}
-
-
-fn main() {
- assert_eq!(foo((T::T1(()), V::V1(99))), "T1(()), V1(99)".to_string());
- assert_eq!(foo((T::T2(()), V::V2(true))), "T2(()), V2(true)".to_string());
-}
+++ /dev/null
-// run-pass
-// pretty-expanded FIXME #23616
-
-use std::any::Any;
-
-fn foo(_: &u8) {
-}
-
-fn main() {
- let _ = &foo as &dyn Any;
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-// pretty-expanded FIXME #23616
-
-#![feature(link_llvm_intrinsics)]
-
-extern {
- #[link_name = "llvm.sqrt.f32"]
- fn sqrt(x: f32) -> f32;
-}
-
-fn main(){
-}
+++ /dev/null
-// run-pass
-#![feature(unsize, coerce_unsized)]
-
-// Verfies that PhantomData is ignored for DST coercions
-
-use std::marker::{Unsize, PhantomData};
-use std::ops::CoerceUnsized;
-
-struct MyRc<T: ?Sized> {
- _ptr: *const T,
- _boo: PhantomData<T>,
-}
-
-impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<MyRc<U>> for MyRc<T>{ }
-
-fn main() {
- let data = [1, 2, 3];
- let iter = data.iter();
- let x = MyRc { _ptr: &iter, _boo: PhantomData };
- let _y: MyRc<dyn Iterator<Item=&u32>> = x;
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-#[repr(packed)]
-pub struct Good {
- data: &'static u32,
- data2: [&'static u32; 2],
- aligned: [u8; 32],
-}
-
-#[repr(packed)]
-pub struct JustArray {
- array: [u32]
-}
-
-// kill this test when that turns to a hard error
-#[allow(safe_packed_borrows)]
-fn main() {
- let good = Good {
- data: &0,
- data2: [&0, &0],
- aligned: [0; 32]
- };
-
- unsafe {
- let _ = &good.data; // ok
- let _ = &good.data2[0]; // ok
- }
-
- let _ = &good.data;
- let _ = &good.data2[0];
- let _ = &*good.data; // ok, behind a pointer
- let _ = &good.aligned; // ok, has align 1
- let _ = &good.aligned[2]; // ok, has align 1
-}
+++ /dev/null
-// run-pass
-#![recursion_limit="1024"]
-
-use std::mem;
-
-pub struct S0<T>(T,T);
-pub struct S1<T>(Option<Box<S0<S0<T>>>>,Option<Box<S0<S0<T>>>>);
-pub struct S2<T>(Option<Box<S1<S1<T>>>>,Option<Box<S1<S1<T>>>>);
-pub struct S3<T>(Option<Box<S2<S2<T>>>>,Option<Box<S2<S2<T>>>>);
-pub struct S4<T>(Option<Box<S3<S3<T>>>>,Option<Box<S3<S3<T>>>>);
-pub struct S5<T>(Option<Box<S4<S4<T>>>>,Option<Box<S4<S4<T>>>>,Option<T>);
-
-trait Foo { fn xxx(&self); }
-/// some local of #[fundamental] trait
-trait Bar {}
-
-impl<T> Foo for T where T: Bar, T: Sync {
- fn xxx(&self) {}
-}
-
-impl Foo for S5<u8> { fn xxx(&self) {} }
-
-fn main() {
- let s = S5(None,None,None);
- s.xxx();
- assert_eq!(mem::size_of_val(&s.2), mem::size_of::<Option<u8>>());
-}
+++ /dev/null
-// run-pass
-fn main() {
- let &ref a = &[0i32] as &[_];
- assert_eq!(a, &[0i32] as &[_]);
-
- let &ref a = "hello";
- assert_eq!(a, "hello");
-
- match "foo" {
- "fool" => unreachable!(),
- "foo" => {},
- ref _x => unreachable!()
- }
-}
+++ /dev/null
-// run-pass
-// aux-build:issue-38715.rs
-// aux-build:issue-38715-modern.rs
-
-// Test that `#[macro_export] macro_rules!` shadow earlier `#[macro_export] macro_rules!`
-
-#[macro_use]
-extern crate issue_38715;
-#[macro_use]
-extern crate issue_38715_modern;
-
-fn main() {
- foo!();
- foo_modern!();
-}
+++ /dev/null
-// run-pass
-// aux-build:issue-41394.rs
-
-extern crate issue_41394 as lib;
-
-fn main() {
- assert_eq!(lib::foo() as u32, 42);
-}
+++ /dev/null
-pub fn increment(x: usize) -> usize {
- x + 1
-}
-
-#[macro_export]
-macro_rules! increment {
- ($x:expr) => ($crate::increment($x))
-}
-
-pub fn check_local() {
- assert_eq!(increment!(3), 4);
-}
+++ /dev/null
-#![feature(staged_api)]
-#![stable(feature = "unit_test", since = "1.0.0")]
-
-#[unstable(feature = "unstable_macros", issue = "0")]
-#[macro_export]
-macro_rules! unstable_macro{ () => () }
+++ /dev/null
-// run-pass
-
-#![allow(unused_mut)]
-
-// Check that when `?` is followed by what looks like a Kleene operator (?, +, and *)
-// then that `?` is not interpreted as a separator. In other words, `$(pat)?+` matches `pat +`
-// or `+` but does not match `pat` or `pat ? pat`.
-
-// edition:2015
-
-macro_rules! foo {
- // Check for `?`.
- ($($a:ident)? ? $num:expr) => {
- foo!($($a)? ; $num);
- };
- // Check for `+`.
- ($($a:ident)? + $num:expr) => {
- foo!($($a)? ; $num);
- };
- // Check for `*`.
- ($($a:ident)? * $num:expr) => {
- foo!($($a)? ; $num);
- };
- // Check for `;`, not a kleene operator.
- ($($a:ident)? ; $num:expr) => {
- let mut x = 0;
-
- $(
- x += $a;
- )?
-
- assert_eq!(x, $num);
- };
-}
-
-pub fn main() {
- let a = 1;
-
- // Accept 0 repetitions.
- foo!( ; 0);
- foo!( + 0);
- foo!( * 0);
- foo!( ? 0);
-
- // Accept 1 repetition.
- foo!(a ; 1);
- foo!(a + 1);
- foo!(a * 1);
- foo!(a ? 1);
-}
+++ /dev/null
-// run-pass
-
-#![allow(unused_mut)]
-
-// Check that when `?` is followed by what looks like a Kleene operator (?, +, and *)
-// then that `?` is not interpreted as a separator. In other words, `$(pat)?+` matches `pat +`
-// or `+` but does not match `pat` or `pat ? pat`.
-
-// edition:2018
-
-macro_rules! foo {
- // Check for `?`.
- ($($a:ident)? ? $num:expr) => {
- foo!($($a)? ; $num);
- };
- // Check for `+`.
- ($($a:ident)? + $num:expr) => {
- foo!($($a)? ; $num);
- };
- // Check for `*`.
- ($($a:ident)? * $num:expr) => {
- foo!($($a)? ; $num);
- };
- // Check for `;`, not a kleene operator.
- ($($a:ident)? ; $num:expr) => {
- let mut x = 0;
-
- $(
- x += $a;
- )?
-
- assert_eq!(x, $num);
- };
-}
-
-pub fn main() {
- let a = 1;
-
- // Accept 0 repetitions.
- foo!( ; 0);
- foo!( + 0);
- foo!( * 0);
- foo!( ? 0);
-
- // Accept 1 repetition.
- foo!(a ; 1);
- foo!(a + 1);
- foo!(a * 1);
- foo!(a ? 1);
-}
+++ /dev/null
-// run-pass
-#![allow(unused_imports)]
-// Ideally, any macro call with a trailing comma should behave
-// identically to a call without the comma.
-//
-// This checks the behavior of macros with trailing commas in key
-// places where regressions in behavior seem highly possible (due
-// to it being e.g., a place where the addition of an argument
-// causes it to go down a code path with subtly different behavior).
-//
-// There is a companion test in compile-fail.
-
-// compile-flags: --test -C debug_assertions=yes
-// revisions: std core
-
-#![cfg_attr(core, no_std)]
-
-#[cfg(std)] use std::fmt;
-#[cfg(core)] use core::fmt;
-
-// an easy mistake in the implementation of 'assert!'
-// would cause this to say "explicit panic"
-#[test]
-#[should_panic(expected = "assertion failed")]
-fn assert_1arg() {
- assert!(false,);
-}
-
-// same as 'assert_1arg'
-#[test]
-#[should_panic(expected = "assertion failed")]
-fn debug_assert_1arg() {
- debug_assert!(false,);
-}
-
-// make sure we don't accidentally forward to `write!("text")`
-#[cfg(std)]
-#[test]
-fn writeln_1arg() {
- use fmt::Write;
-
- let mut s = String::new();
- writeln!(&mut s,).unwrap();
- assert_eq!(&s, "\n");
-}
-
-// A number of format_args-like macros have special-case treatment
-// for a single message string, which is not formatted.
-//
-// This test ensures that the addition of a trailing comma does not
-// suddenly cause these strings to get formatted when they otherwise
-// would not be. This is an easy mistake to make by having such a macro
-// accept ", $($tok:tt)*" instead of ", $($tok:tt)+" after its minimal
-// set of arguments.
-//
-// (Example: Issue #48042)
-#[test]
-fn to_format_or_not_to_format() {
- // ("{}" is the easiest string to test because if this gets
- // sent to format_args!, it'll simply fail to compile.
- // "{{}}" is an example of an input that could compile and
- // produce an incorrect program, but testing the panics
- // would be burdensome.)
- let falsum = || false;
-
- assert!(true, "{}",);
-
- // assert_eq!(1, 1, "{}",); // see compile-fail
- // assert_ne!(1, 2, "{}",); // see compile-fail
-
- debug_assert!(true, "{}",);
-
- // debug_assert_eq!(1, 1, "{}",); // see compile-fail
- // debug_assert_ne!(1, 2, "{}",); // see compile-fail
- // eprint!("{}",); // see compile-fail
- // eprintln!("{}",); // see compile-fail
- // format!("{}",); // see compile-fail
- // format_args!("{}",); // see compile-fail
-
- if falsum() { panic!("{}",); }
-
- // print!("{}",); // see compile-fail
- // println!("{}",); // see compile-fail
- // unimplemented!("{}",); // see compile-fail
-
- if falsum() { unreachable!("{}",); }
-
- // write!(&mut stdout, "{}",); // see compile-fail
- // writeln!(&mut stdout, "{}",); // see compile-fail
-}
+++ /dev/null
-// run-pass
-// This is meant to be a comprehensive test of invocations with/without
-// trailing commas (or other, similar optionally-trailing separators).
-// Every macro is accounted for, even those not tested in this file.
-// (There will be a note indicating why).
-
-// std and core are both tested because they may contain separate
-// implementations for some macro_rules! macros as an implementation
-// detail.
-
-// ignore-pretty issue #37195
-
-// compile-flags: --test -C debug_assertions=yes
-// revisions: std core
-
-#![cfg_attr(core, no_std)]
-
-#![feature(concat_idents)]
-
-#[cfg(std)] use std::fmt;
-#[cfg(core)] use core::fmt;
-
-#[test]
-fn assert() {
- assert!(true);
- assert!(true,);
- assert!(true, "hello");
- assert!(true, "hello",);
- assert!(true, "hello {}", "world");
- assert!(true, "hello {}", "world",);
-}
-
-#[test]
-fn assert_eq() {
- assert_eq!(1, 1);
- assert_eq!(1, 1,);
- assert_eq!(1, 1, "hello");
- assert_eq!(1, 1, "hello",);
- assert_eq!(1, 1, "hello {}", "world");
- assert_eq!(1, 1, "hello {}", "world",);
-}
-
-#[test]
-fn assert_ne() {
- assert_ne!(1, 2);
- assert_ne!(1, 2,);
- assert_ne!(1, 2, "hello");
- assert_ne!(1, 2, "hello",);
- assert_ne!(1, 2, "hello {}", "world");
- assert_ne!(1, 2, "hello {}", "world",);
-}
-
-#[test]
-fn cfg() {
- let _ = cfg!(pants);
- let _ = cfg!(pants,);
- let _ = cfg!(pants = "pants");
- let _ = cfg!(pants = "pants",);
- let _ = cfg!(all(pants));
- let _ = cfg!(all(pants),);
- let _ = cfg!(all(pants,));
- let _ = cfg!(all(pants,),);
-}
-
-#[test]
-fn column() {
- let _ = column!();
-}
-
-// compile_error! is in a companion to this test in compile-fail
-
-#[test]
-fn concat() {
- let _ = concat!();
- let _ = concat!("hello");
- let _ = concat!("hello",);
- let _ = concat!("hello", " world");
- let _ = concat!("hello", " world",);
-}
-
-#[test]
-fn concat_idents() {
- fn foo() {}
- fn foobar() {}
-
- concat_idents!(foo)();
- concat_idents!(foo,)();
- concat_idents!(foo, bar)();
- concat_idents!(foo, bar,)();
-}
-
-#[test]
-fn debug_assert() {
- debug_assert!(true);
- debug_assert!(true, );
- debug_assert!(true, "hello");
- debug_assert!(true, "hello",);
- debug_assert!(true, "hello {}", "world");
- debug_assert!(true, "hello {}", "world",);
-}
-
-#[test]
-fn debug_assert_eq() {
- debug_assert_eq!(1, 1);
- debug_assert_eq!(1, 1,);
- debug_assert_eq!(1, 1, "hello");
- debug_assert_eq!(1, 1, "hello",);
- debug_assert_eq!(1, 1, "hello {}", "world");
- debug_assert_eq!(1, 1, "hello {}", "world",);
-}
-
-#[test]
-fn debug_assert_ne() {
- debug_assert_ne!(1, 2);
- debug_assert_ne!(1, 2,);
- debug_assert_ne!(1, 2, "hello");
- debug_assert_ne!(1, 2, "hello",);
- debug_assert_ne!(1, 2, "hello {}", "world");
- debug_assert_ne!(1, 2, "hello {}", "world",);
-}
-
-#[test]
-fn env() {
- let _ = env!("PATH");
- let _ = env!("PATH",);
- let _ = env!("PATH", "not found");
- let _ = env!("PATH", "not found",);
-}
-
-#[cfg(std)]
-#[test]
-fn eprint() {
- eprint!("hello");
- eprint!("hello",);
- eprint!("hello {}", "world");
- eprint!("hello {}", "world",);
-}
-
-#[cfg(std)]
-#[test]
-fn eprintln() {
- eprintln!();
- eprintln!("hello");
- eprintln!("hello",);
- eprintln!("hello {}", "world");
- eprintln!("hello {}", "world",);
-}
-
-#[test]
-fn file() {
- let _ = file!();
-}
-
-#[cfg(std)]
-#[test]
-fn format() {
- let _ = format!("hello");
- let _ = format!("hello",);
- let _ = format!("hello {}", "world");
- let _ = format!("hello {}", "world",);
-}
-
-#[test]
-fn format_args() {
- let _ = format_args!("hello");
- let _ = format_args!("hello",);
- let _ = format_args!("hello {}", "world");
- let _ = format_args!("hello {}", "world",);
-}
-
-#[test]
-fn include() {
- let _ = include!("auxiliary/macro-comma-support.rs");
- let _ = include!("auxiliary/macro-comma-support.rs",);
-}
-
-#[test]
-fn include_bytes() {
- let _ = include_bytes!("auxiliary/macro-comma-support.rs");
- let _ = include_bytes!("auxiliary/macro-comma-support.rs",);
-}
-
-#[test]
-fn include_str() {
- let _ = include_str!("auxiliary/macro-comma-support.rs");
- let _ = include_str!("auxiliary/macro-comma-support.rs",);
-}
-
-#[test]
-fn line() {
- let _ = line!();
-}
-
-#[test]
-fn module_path() {
- let _ = module_path!();
-}
-
-#[test]
-fn option_env() {
- let _ = option_env!("PATH");
- let _ = option_env!("PATH",);
-}
-
-#[test]
-fn panic() {
- // prevent 'unreachable code' warnings
- let falsum = || false;
-
- if falsum() { panic!(); }
- if falsum() { panic!("hello"); }
- if falsum() { panic!("hello",); }
- if falsum() { panic!("hello {}", "world"); }
- if falsum() { panic!("hello {}", "world",); }
-}
-
-#[cfg(std)]
-#[test]
-fn print() {
- print!("hello");
- print!("hello",);
- print!("hello {}", "world");
- print!("hello {}", "world",);
-}
-
-#[cfg(std)]
-#[test]
-fn println() {
- println!();
- println!("hello");
- println!("hello",);
- println!("hello {}", "world");
- println!("hello {}", "world",);
-}
-
-// stringify! is N/A
-
-#[cfg(std)]
-#[test]
-fn thread_local() {
- // this has an optional trailing *semicolon*
- thread_local! {
- #[allow(unused)] pub static A: () = ()
- }
-
- thread_local! {
- #[allow(unused)] pub static AA: () = ();
- }
-
- thread_local! {
- #[allow(unused)] pub static AAA: () = ();
- #[allow(unused)] pub static AAAA: () = ()
- }
-
- thread_local! {
- #[allow(unused)] pub static AAAAG: () = ();
- #[allow(unused)] pub static AAAAGH: () = ();
- }
-}
-
-#[test]
-fn try() {
- fn inner() -> Result<(), ()> {
- try!(Ok(()));
- try!(Ok(()),);
- Ok(())
- }
-
- inner().unwrap();
-}
-
-#[test]
-fn unimplemented() {
- // prevent 'unreachable code' warnings
- let falsum = || false;
-
- if falsum() { unimplemented!(); }
- if falsum() { unimplemented!("hello"); }
- if falsum() { unimplemented!("hello",); }
- if falsum() { unimplemented!("hello {}", "world"); }
- if falsum() { unimplemented!("hello {}", "world",); }
-}
-
-#[test]
-fn unreachable() {
- // prevent 'unreachable code' warnings
- let falsum = || false;
-
- if falsum() { unreachable!(); }
- if falsum() { unreachable!("hello"); }
- if falsum() { unreachable!("hello",); }
- if falsum() { unreachable!("hello {}", "world"); }
- if falsum() { unreachable!("hello {}", "world",); }
-}
-
-#[cfg(std)]
-#[test]
-fn vec() {
- let _: Vec<()> = vec![];
- let _ = vec![0];
- let _ = vec![0,];
- let _ = vec![0, 1];
- let _ = vec![0, 1,];
-}
-
-// give a test body access to a fmt::Formatter, which seems
-// to be the easiest way to use 'write!' on core.
-macro_rules! test_with_formatter {
- (
- #[test]
- fn $fname:ident($f:ident: &mut fmt::Formatter) $block:block
- ) => {
- #[test]
- fn $fname() {
- struct Struct;
- impl fmt::Display for Struct {
- fn fmt(&self, $f: &mut fmt::Formatter) -> fmt::Result {
- Ok($block)
- }
- }
-
- // suppress "unused"
- assert!(true, "{}", Struct);
- }
- };
-}
-
-test_with_formatter! {
- #[test]
- fn write(f: &mut fmt::Formatter) {
- let _ = write!(f, "hello");
- let _ = write!(f, "hello",);
- let _ = write!(f, "hello {}", "world");
- let _ = write!(f, "hello {}", "world",);
- }
-}
-
-test_with_formatter! {
- #[test]
- fn writeln(f: &mut fmt::Formatter) {
- let _ = writeln!(f);
- let _ = writeln!(f,);
- let _ = writeln!(f, "hello");
- let _ = writeln!(f, "hello",);
- let _ = writeln!(f, "hello {}", "world");
- let _ = writeln!(f, "hello {}", "world",);
- }
-}
+++ /dev/null
-// run-pass
-#![allow(unused_macros)]
-// Check the macro follow sets (see corresponding cfail test).
-
-// FOLLOW(pat) = {FatArrow, Comma, Eq, Or, Ident(if), Ident(in)}
-macro_rules! follow_pat {
- ($p:pat =>) => {};
- ($p:pat ,) => {};
- ($p:pat =) => {};
- ($p:pat |) => {};
- ($p:pat if) => {};
- ($p:pat in) => {};
-}
-// FOLLOW(expr) = {FatArrow, Comma, Semicolon}
-macro_rules! follow_expr {
- ($e:expr =>) => {};
- ($e:expr ,) => {};
- ($e:expr ;) => {};
-}
-// FOLLOW(ty) = {OpenDelim(Brace), Comma, FatArrow, Colon, Eq, Gt, Semi, Or,
-// Ident(as), Ident(where), OpenDelim(Bracket), Nonterminal(Block)}
-macro_rules! follow_ty {
- ($t:ty {}) => {};
- ($t:ty ,) => {};
- ($t:ty =>) => {};
- ($t:ty :) => {};
- ($t:ty =) => {};
- ($t:ty >) => {};
- ($t:ty ;) => {};
- ($t:ty |) => {};
- ($t:ty as) => {};
- ($t:ty where) => {};
- ($t:ty []) => {};
- ($t:ty $b:block) => {};
-}
-// FOLLOW(stmt) = FOLLOW(expr)
-macro_rules! follow_stmt {
- ($s:stmt =>) => {};
- ($s:stmt ,) => {};
- ($s:stmt ;) => {};
-}
-// FOLLOW(path) = FOLLOW(ty)
-macro_rules! follow_path {
- ($p:path {}) => {};
- ($p:path ,) => {};
- ($p:path =>) => {};
- ($p:path :) => {};
- ($p:path =) => {};
- ($p:path >) => {};
- ($p:path ;) => {};
- ($p:path |) => {};
- ($p:path as) => {};
- ($p:path where) => {};
- ($p:path []) => {};
- ($p:path $b:block) => {};
-}
-// FOLLOW(block) = any token
-macro_rules! follow_block {
- ($b:block ()) => {};
- ($b:block []) => {};
- ($b:block {}) => {};
- ($b:block ,) => {};
- ($b:block =>) => {};
- ($b:block :) => {};
- ($b:block =) => {};
- ($b:block >) => {};
- ($b:block ;) => {};
- ($b:block |) => {};
- ($b:block +) => {};
- ($b:block ident) => {};
- ($b:block $p:pat) => {};
- ($b:block $e:expr) => {};
- ($b:block $t:ty) => {};
- ($b:block $s:stmt) => {};
- ($b:block $p:path) => {};
- ($b:block $c:block) => {};
- ($b:block $i:ident) => {};
- ($b:block $t:tt) => {};
- ($b:block $i:item) => {};
- ($b:block $m:meta) => {};
-}
-// FOLLOW(ident) = any token
-macro_rules! follow_ident {
- ($i:ident ()) => {};
- ($i:ident []) => {};
- ($i:ident {}) => {};
- ($i:ident ,) => {};
- ($i:ident =>) => {};
- ($i:ident :) => {};
- ($i:ident =) => {};
- ($i:ident >) => {};
- ($i:ident ;) => {};
- ($i:ident |) => {};
- ($i:ident +) => {};
- ($i:ident ident) => {};
- ($i:ident $p:pat) => {};
- ($i:ident $e:expr) => {};
- ($i:ident $t:ty) => {};
- ($i:ident $s:stmt) => {};
- ($i:ident $p:path) => {};
- ($i:ident $b:block) => {};
- ($i:ident $j:ident) => {};
- ($i:ident $t:tt) => {};
- ($i:ident $j:item) => {};
- ($i:ident $m:meta) => {};
-}
-// FOLLOW(tt) = any token
-macro_rules! follow_tt {
- ($t:tt ()) => {};
- ($t:tt []) => {};
- ($t:tt {}) => {};
- ($t:tt ,) => {};
- ($t:tt =>) => {};
- ($t:tt :) => {};
- ($t:tt =) => {};
- ($t:tt >) => {};
- ($t:tt ;) => {};
- ($t:tt |) => {};
- ($t:tt +) => {};
- ($t:tt ident) => {};
- ($t:tt $p:pat) => {};
- ($t:tt $e:expr) => {};
- ($t:tt $v:ty) => {};
- ($t:tt $s:stmt) => {};
- ($t:tt $p:path) => {};
- ($t:tt $b:block) => {};
- ($t:tt $i:ident) => {};
- ($t:tt $v:tt) => {};
- ($t:tt $i:item) => {};
- ($t:tt $m:meta) => {};
-}
-// FOLLOW(item) = any token
-macro_rules! follow_item {
- ($i:item ()) => {};
- ($i:item []) => {};
- ($i:item {}) => {};
- ($i:item ,) => {};
- ($i:item =>) => {};
- ($i:item :) => {};
- ($i:item =) => {};
- ($i:item >) => {};
- ($i:item ;) => {};
- ($i:item |) => {};
- ($i:item +) => {};
- ($i:item ident) => {};
- ($i:item $p:pat) => {};
- ($i:item $e:expr) => {};
- ($i:item $t:ty) => {};
- ($i:item $s:stmt) => {};
- ($i:item $p:path) => {};
- ($i:item $b:block) => {};
- ($i:item $j:ident) => {};
- ($i:item $t:tt) => {};
- ($i:item $j:item) => {};
- ($i:item $m:meta) => {};
-}
-// FOLLOW(meta) = any token
-macro_rules! follow_meta {
- ($m:meta ()) => {};
- ($m:meta []) => {};
- ($m:meta {}) => {};
- ($m:meta ,) => {};
- ($m:meta =>) => {};
- ($m:meta :) => {};
- ($m:meta =) => {};
- ($m:meta >) => {};
- ($m:meta ;) => {};
- ($m:meta |) => {};
- ($m:meta +) => {};
- ($m:meta ident) => {};
- ($m:meta $p:pat) => {};
- ($m:meta $e:expr) => {};
- ($m:meta $t:ty) => {};
- ($m:meta $s:stmt) => {};
- ($m:meta $p:path) => {};
- ($m:meta $b:block) => {};
- ($m:meta $i:ident) => {};
- ($m:meta $t:tt) => {};
- ($m:meta $i:item) => {};
- ($m:meta $n:meta) => {};
-}
-
-fn main() {}
+++ /dev/null
-// run-pass
-// aux-build:unstable-macros.rs
-
-#![feature(unstable_macros, local_unstable)]
-
-#[macro_use] extern crate unstable_macros;
-
-#[unstable(feature = "local_unstable", issue = "0")]
-macro_rules! local_unstable { () => () }
-
-fn main() {
- unstable_macro!();
- local_unstable!();
-}
+++ /dev/null
-// run-pass
-// ignore-wasm32
-
-#![feature(decl_macro, macros_in_extern)]
-
-macro_rules! returns_isize(
- ($ident:ident) => (
- fn $ident() -> isize;
- )
-);
-
-macro takes_u32_returns_u32($ident:ident) {
- fn $ident (arg: u32) -> u32;
-}
-
-macro_rules! emits_nothing(
- () => ()
-);
-
-fn main() {
- assert_eq!(unsafe { rust_get_test_int() }, 1isize);
- assert_eq!(unsafe { rust_dbg_extern_identity_u32(0xDEADBEEF) }, 0xDEADBEEFu32);
-}
-
-#[link(name = "rust_test_helpers", kind = "static")]
-extern {
- returns_isize!(rust_get_test_int);
- takes_u32_returns_u32!(rust_dbg_extern_identity_u32);
- emits_nothing!();
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-// pretty-expanded FIXME #23616
-
-pub mod test2 {
- // This used to generate an ICE (make sure that default functions are
- // parented to their trait to find the first private thing as the trait).
-
- struct B;
- trait A { fn foo(&self) {} }
- impl A for B {}
-
- mod tests {
- use super::A;
- fn foo() {
- let a = super::B;
- a.foo();
- }
- }
-}
-
-
-pub fn main() {}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-#![allow(non_camel_case_types)]
-
-// pretty-expanded FIXME #23616
-
-struct cat {
- meows : usize,
-
- how_hungry : isize,
-}
-
-impl cat {
- pub fn play(&mut self) {
- self.meows += 1_usize;
- self.nap();
- }
-}
-
-impl cat {
- fn nap(&mut self) { for _ in 1_usize..10_usize { } }
-}
-
-fn cat(in_x : usize, in_y : isize) -> cat {
- cat {
- meows: in_x,
- how_hungry: in_y
- }
-}
-
-pub fn main() {
- let mut nyan : cat = cat(52_usize, 99);
- nyan.play();
-}
+++ /dev/null
-// run-pass
-// aux-build:attr-stmt-expr.rs
-
-#![feature(stmt_expr_attributes, proc_macro_hygiene)]
-
-extern crate attr_stmt_expr;
-use attr_stmt_expr::{expect_let, expect_print_stmt, expect_expr, expect_print_expr,
- no_output, noop};
-
-fn print_str(string: &'static str) {
- // macros are handled a bit differently
- #[expect_print_expr]
- println!("{}", string)
-}
-
-fn main() {
- #[expect_let]
- let string = "Hello, world!";
-
- #[expect_print_stmt]
- println!("{}", string);
-
- let _: () = {
- #[no_output]
- "Hello, world!"
- };
-
- let _: &'static str = #[noop] "Hello, world!";
-
- let _: &'static str = {
- #[noop] "Hello, world!"
- };
-
- #[expect_expr]
- print_str("string")
-}
+++ /dev/null
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-use proc_macro::TokenStream;
-
-#[proc_macro_attribute]
-pub fn expect_let(attr: TokenStream, item: TokenStream) -> TokenStream {
- assert!(attr.to_string().is_empty());
- assert_eq!(item.to_string(), "let string = \"Hello, world!\";");
- item
-}
-
-#[proc_macro_attribute]
-pub fn expect_print_stmt(attr: TokenStream, item: TokenStream) -> TokenStream {
- assert!(attr.to_string().is_empty());
- assert_eq!(item.to_string(), "println!(\"{}\" , string);");
- item
-}
-
-#[proc_macro_attribute]
-pub fn expect_expr(attr: TokenStream, item: TokenStream) -> TokenStream {
- assert!(attr.to_string().is_empty());
- assert_eq!(item.to_string(), "print_str(\"string\")");
- item
-}
-
-#[proc_macro_attribute]
-pub fn expect_print_expr(attr: TokenStream, item: TokenStream) -> TokenStream {
- assert!(attr.to_string().is_empty());
- assert_eq!(item.to_string(), "println!(\"{}\" , string)");
- item
-}
-
-#[proc_macro_attribute]
-pub fn no_output(attr: TokenStream, item: TokenStream) -> TokenStream {
- assert!(attr.to_string().is_empty());
- assert!(!item.to_string().is_empty());
- "".parse().unwrap()
-
-}
-
-#[proc_macro_attribute]
-pub fn noop(attr: TokenStream, item: TokenStream) -> TokenStream {
- assert!(attr.to_string().is_empty());
- assert!(!item.to_string().is_empty());
- item
-}
+++ /dev/null
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-use proc_macro::*;
-
-#[proc_macro]
-pub fn lifetimes_bang(input: TokenStream) -> TokenStream {
- // Roundtrip through token trees
- input.into_iter().collect()
-}
-
-#[proc_macro_attribute]
-pub fn lifetimes_attr(_: TokenStream, input: TokenStream) -> TokenStream {
- // Roundtrip through AST
- input
-}
-
-#[proc_macro_derive(Lifetimes)]
-pub fn lifetimes_derive(input: TokenStream) -> TokenStream {
- // Roundtrip through a string
- format!("mod m {{ {} }}", input).parse().unwrap()
-}
+++ /dev/null
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-
-extern crate proc_macro;
-
-use proc_macro::TokenStream;
-
-#[proc_macro_attribute]
-pub fn nop_attr(_attr: TokenStream, input: TokenStream) -> TokenStream {
- assert!(_attr.to_string().is_empty());
- input
-}
-
-#[proc_macro_attribute]
-pub fn no_output(_attr: TokenStream, _input: TokenStream) -> TokenStream {
- assert!(_attr.to_string().is_empty());
- assert!(!_input.to_string().is_empty());
- "".parse().unwrap()
-}
-
-#[proc_macro]
-pub fn emit_input(input: TokenStream) -> TokenStream {
- input
-}
+++ /dev/null
-// run-pass
-
-#![allow(unused_variables)]
-// aux-build:lifetimes.rs
-
-extern crate lifetimes;
-use lifetimes::*;
-
-lifetimes_bang! {
- fn bang<'a>() -> &'a u8 { &0 }
-}
-
-#[lifetimes_attr]
-fn attr<'a>() -> &'a u8 { &1 }
-
-#[derive(Lifetimes)]
-pub struct Lifetimes<'a> {
- pub field: &'a u8,
-}
-
-fn main() {
- assert_eq!(bang::<'static>(), &0);
- assert_eq!(attr::<'static>(), &1);
- let l1 = Lifetimes { field: &0 };
- let l2 = m::Lifetimes { field: &1 };
-}
+++ /dev/null
-// run-pass
-// aux-build:test-macros.rs
-// ignore-wasm32
-
-#![feature(macros_in_extern)]
-
-extern crate test_macros;
-
-use test_macros::{nop_attr, no_output, emit_input};
-
-fn main() {
- assert_eq!(unsafe { rust_get_test_int() }, 1isize);
- assert_eq!(unsafe { rust_dbg_extern_identity_u32(0xDEADBEEF) }, 0xDEADBEEF);
-}
-
-#[link(name = "rust_test_helpers", kind = "static")]
-extern {
- #[no_output]
- fn some_definitely_unknown_symbol_which_should_be_removed();
-
- #[nop_attr]
- fn rust_get_test_int() -> isize;
-
- emit_input!(fn rust_dbg_extern_identity_u32(arg: u32) -> u32;);
-}
+++ /dev/null
-// run-pass
-
-#![allow(unused_variables)]
-// Test coercions between pointers which don't do anything fancy like unsizing.
-
-// pretty-expanded FIXME #23616
-
-pub fn main() {
- // &mut -> &
- let x: &mut isize = &mut 42;
- let x: &isize = x;
-
- let x: &isize = &mut 42;
-
- // & -> *const
- let x: &isize = &42;
- let x: *const isize = x;
-
- let x: *const isize = &42;
-
- // &mut -> *const
- let x: &mut isize = &mut 42;
- let x: *const isize = x;
-
- let x: *const isize = &mut 42;
-
- // *mut -> *const
- let x: *mut isize = &mut 42;
- let x: *const isize = x;
-}
+++ /dev/null
-// run-pass
-fn invariant_id<'a,'b>(t: &'b mut &'static ()) -> &'b mut &'a ()
- where 'a: 'static { t }
-fn static_id<'a>(t: &'a ()) -> &'static ()
- where 'a: 'static { t }
-fn static_id_indirect<'a,'b>(t: &'a ()) -> &'static ()
- where 'a: 'b, 'b: 'static { t }
-fn ref_id<'a>(t: &'a ()) -> &'a () where 'static: 'a { t }
-
-static UNIT: () = ();
-
-fn main()
-{
- let mut val : &'static () = &UNIT;
- invariant_id(&mut val);
- static_id(val);
- static_id_indirect(val);
- ref_id(val);
-}
+++ /dev/null
-// run-pass
-// Test that using rlibs and rmeta dep crates work together. Specifically, that
-// there can be both an rmeta and an rlib file and rustc will prefer the rlib.
-
-// aux-build:rmeta-rmeta.rs
-// aux-build:rmeta-rlib.rs
-
-extern crate rmeta_aux;
-use rmeta_aux::Foo;
-
-pub fn main() {
- let _ = Foo { field: 42 };
-}
+++ /dev/null
-Tests that specialization is working correctly:
-
-- Dispatch
- - [On methods](specialization-basics.rs), includes:
- - Specialization via adding a trait bound
- - Including both remote and local traits
- - Specialization via pure structure (e.g. `(T, U)` vs `(T, T)`)
- - Specialization via concrete types vs unknown types
- - In top level of the trait reference
- - Embedded within another type (`Vec<T>` vs `Vec<i32>`)
- - [Specialization based on super trait relationships](specialization-super-traits.rs)
- - [On assoc fns](specialization-assoc-fns.rs)
- - [Ensure that impl order doesn't matter](specialization-out-of-order.rs)
-
-- Item inheritance
- - [Correct default cascading for methods](specialization-default-methods.rs)
- - Inheritance works across impls with varying generics
- - [With projections](specialization-translate-projections.rs)
- - [With projections that involve input types](specialization-translate-projections-with-params.rs)
-
-- Normalization issues
- - [Non-default assoc types can be projected](specialization-projection.rs)
- - Including non-specialized cases
- - Including specialized cases
- - [Specialized Impls can happen on projections](specialization-on-projection.rs)
- - [Projections and aliases play well together](specialization-projection-alias.rs)
- - [Projections involving specialization allowed in the trait ref for impls, and overlap can still be determined](specialization-overlap-projection.rs)
- - Only works for the simple case where the most specialized impl directly
- provides a non-`default` associated type
-
-- Across crates
- - [For traits defined in upstream crate](specialization-allowed-cross-crate.rs)
- - [Full method dispatch tests, drawing from upstream crate](specialization-cross-crate.rs)
- - Including *additional* local specializations
- - [Full method dispatch tests, *without* turning on specialization in local crate](specialization-cross-crate-no-gate.rs)
- - [Test that defaults cascade correctly from upstream crates](specialization-cross-crate-defaults.rs)
- - Including *additional* local use of defaults
+++ /dev/null
-// run-pass
-
-// Tests that we can combine a default impl that supplies one method with a
-// full impl that supplies the other, and they can invoke one another.
-
-#![feature(specialization)]
-
-trait Foo {
- fn foo_one(&self) -> &'static str;
- fn foo_two(&self) -> &'static str;
- fn foo_three(&self) -> &'static str;
-}
-
-struct MyStruct;
-
-default impl<T> Foo for T {
- fn foo_one(&self) -> &'static str {
- self.foo_three()
- }
-}
-
-impl Foo for MyStruct {
- fn foo_two(&self) -> &'static str {
- self.foo_one()
- }
-
- fn foo_three(&self) -> &'static str {
- "generic"
- }
-}
-
-fn main() {
- assert!(MyStruct.foo_two() == "generic");
-}
+++ /dev/null
-// run-pass
-
-#![deny(unknown_lints)]
-
-#[allow(clippy::almost_swapped)]
-fn main() {}
+++ /dev/null
-// Simple smoke test that unsafe traits can be compiled etc.
-
-pub unsafe trait Foo {
- fn foo(&self) -> isize;
-}
-
-unsafe impl Foo for isize {
- fn foo(&self) -> isize { *self }
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-#![allow(unused_variables)]
-// pretty-expanded FIXME #23616
-
-trait U {}
-trait T<X: U> { fn get(self) -> X; }
-
-trait S2<Y: U> {
- fn m(x: Box<dyn T<Y>+'static>) {}
-}
-
-struct St<X: U> {
- f: Box<dyn T<X>+'static>,
-}
-
-impl<X: U> St<X> {
- fn blah() {}
-}
-
-fn main() {}
+++ /dev/null
-// run-pass
-#![allow(unused_variables)]
-#![feature(optin_builtin_traits)]
-
-use std::marker::Send;
-
-pub struct WaitToken;
-impl !Send for WaitToken {}
-
-pub struct Test<T>(T);
-unsafe impl<T: 'static> Send for Test<T> {}
-
-pub fn spawn<F>(_: F) -> () where F: FnOnce(), F: Send + 'static {}
-
-fn main() {
- let wt = Test(WaitToken);
- spawn(move || {
- let x = wt;
- println!("Hello, World!");
- });
-}
+++ /dev/null
-// run-pass
-// Test that all coercions can actually be done using casts (modulo the lints).
-
-#![allow(trivial_casts, trivial_numeric_casts)]
-
-trait Foo {
- fn foo(&self) {}
-}
-
-pub struct Bar;
-
-impl Foo for Bar {}
-
-pub fn main() {
- // Numeric
- let _ = 42_i32 as i32;
- let _ = 42_u8 as u8;
-
- // & to * pointers
- let x: &u32 = &42;
- let _ = x as *const u32;
-
- let x: &mut u32 = &mut 42;
- let _ = x as *mut u32;
-
- // unsize array
- let x: &[u32; 3] = &[42, 43, 44];
- let _ = x as &[u32];
- let _ = x as *const [u32];
-
- let x: &mut [u32; 3] = &mut [42, 43, 44];
- let _ = x as &mut [u32];
- let _ = x as *mut [u32];
-
- let x: Box<[u32; 3]> = Box::new([42, 43, 44]);
- let _ = x as Box<[u32]>;
-
- // unsize trait
- let x: &Bar = &Bar;
- let _ = x as &dyn Foo;
- let _ = x as *const dyn Foo;
-
- let x: &mut Bar = &mut Bar;
- let _ = x as &mut dyn Foo;
- let _ = x as *mut dyn Foo;
-
- let x: Box<Bar> = Box::new(Bar);
- let _ = x as Box<dyn Foo>;
-
- // functions
- fn baz(_x: i32) {}
- let _ = &baz as &dyn Fn(i32);
- let x = |_x: i32| {};
- let _ = &x as &dyn Fn(i32);
-}
-
-// subtyping
-pub fn test_subtyping<'a, 'b: 'a>(a: &'a Bar, b: &'b Bar) {
- let _ = a as &'a Bar;
- let _ = b as &'a Bar;
- let _ = b as &'b Bar;
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-#![allow(unused_variables)]
-#![allow(unions_with_drop_fields)]
-
-// Some traits can be derived for unions.
-
-#![feature(untagged_unions)]
-
-#[derive(
- Copy,
- Clone,
- Eq,
-)]
-union U {
- a: u8,
- b: u16,
-}
-
-impl PartialEq for U { fn eq(&self, rhs: &Self) -> bool { true } }
-
-#[derive(
- Clone,
- Copy,
- Eq
-)]
-union W<T> {
- a: T,
-}
-
-impl<T> PartialEq for W<T> { fn eq(&self, rhs: &Self) -> bool { true } }
-
-fn main() {
- let u = U { b: 0 };
- let u1 = u;
- let u2 = u.clone();
- assert!(u1 == u2);
-
- let w = W { a: 0 };
- let w1 = w.clone();
- assert!(w == w1);
-}
+++ /dev/null
-// run-pass
-#![allow(dead_code)]
-#![allow(unions_with_drop_fields)]
-
-#![feature(untagged_unions)]
-
-union MaybeItem<T: Iterator> {
- elem: T::Item,
- none: (),
-}
-
-union U<A, B> {
- a: A,
- b: B,
-}
-
-unsafe fn union_transmute<A, B>(a: A) -> B {
- U { a: a }.b
-}
-
-fn main() {
- unsafe {
- let u = U::<String, Vec<u8>> { a: String::from("abcd") };
-
- assert_eq!(u.b.len(), 4);
- assert_eq!(u.b[0], b'a');
-
- let b = union_transmute::<(u8, u8), u16>((1, 1));
- assert_eq!(b, (1 << 8) + 1);
-
- let v: Vec<u8> = vec![1, 2, 3];
- let mut i = v.iter();
- i.next();
- let mi = MaybeItem::<std::slice::Iter<_>> { elem: i.next().unwrap() };
- assert_eq!(*mi.elem, 2);
- }
-}
+++ /dev/null
-// run-pass
-
-#![feature(untagged_unions)]
-#![allow(dead_code)]
-#![allow(unions_with_drop_fields)]
-
-union U {
- a: u8, // OK
-}
-
-union W {
- a: String, // OK
- b: String, // OK
-}
-
-struct S(String);
-
-// `S` doesn't implement `Drop` trait, but still has non-trivial destructor
-union Y {
- a: S, // OK
-}
-
-// We don't know if `T` is trivially-destructable or not until trans
-union J<T> {
- a: T, // OK
-}
-
-union H<T: Copy> {
- a: T, // OK
-}
-
-fn main() {}
+++ /dev/null
-// run-pass
-
-#![feature(unsized_locals)]
-
-pub trait Foo {
- fn foo(self) -> String;
-}
-
-struct A;
-
-impl Foo for A {
- fn foo(self) -> String {
- format!("hello")
- }
-}
-
-
-fn main() {
- let x = *(Box::new(A) as Box<dyn Foo>);
- assert_eq!(x.foo(), format!("hello"));
-
- // I'm not sure whether we want this to work
- let x = Box::new(A) as Box<dyn Foo>;
- assert_eq!(x.foo(), format!("hello"));
-}
+++ /dev/null
-// run-pass
-
-#![feature(unsized_tuple_coercion, unsized_locals)]
-
-struct A<X: ?Sized>(X);
-
-fn udrop<T: ?Sized>(_x: T) {}
-fn foo() -> Box<[u8]> {
- Box::new(*b"foo")
-}
-fn tfoo() -> Box<(i32, [u8])> {
- Box::new((42, *b"foo"))
-}
-fn afoo() -> Box<A<[u8]>> {
- Box::new(A(*b"foo"))
-}
-
-impl std::ops::Add<i32> for A<[u8]> {
- type Output = ();
- fn add(self, _rhs: i32) -> Self::Output {}
-}
-
-fn main() {
- udrop::<[u8]>(loop {
- break *foo();
- });
- udrop::<[u8]>(if true {
- *foo()
- } else {
- *foo()
- });
- udrop::<[u8]>({*foo()});
- #[allow(unused_parens)]
- udrop::<[u8]>((*foo()));
- udrop::<[u8]>((*tfoo()).1);
- *afoo() + 42;
- udrop as fn([u8]);
-}
+++ /dev/null
-// run-pass
-// Test structs with always-unsized fields.
-
-
-#![allow(warnings)]
-#![feature(box_syntax, unsize, raw)]
-
-use std::mem;
-use std::raw;
-use std::slice;
-
-struct Foo<T> {
- f: [T],
-}
-
-struct Bar {
- f1: usize,
- f2: [usize],
-}
-
-struct Baz {
- f1: usize,
- f2: str,
-}
-
-trait Tr {
- fn foo(&self) -> usize;
-}
-
-struct St {
- f: usize
-}
-
-impl Tr for St {
- fn foo(&self) -> usize {
- self.f
- }
-}
-
-struct Qux<'a> {
- f: Tr+'a
-}
-
-pub fn main() {
- let _: &Foo<f64>;
- let _: &Bar;
- let _: &Baz;
-
- let _: Box<Foo<i32>>;
- let _: Box<Bar>;
- let _: Box<Baz>;
-
- let _ = mem::size_of::<Box<Foo<u8>>>();
- let _ = mem::size_of::<Box<Bar>>();
- let _ = mem::size_of::<Box<Baz>>();
-
- unsafe {
- struct Foo_<T> {
- f: [T; 3]
- }
-
- let data: Box<Foo_<i32>> = box Foo_{f: [1, 2, 3] };
- let x: &Foo<i32> = mem::transmute(slice::from_raw_parts(&*data, 3));
- assert_eq!(x.f.len(), 3);
- assert_eq!(x.f[0], 1);
-
- struct Baz_ {
- f1: usize,
- f2: [u8; 5],
- }
-
- let data: Box<_> = box Baz_ {
- f1: 42, f2: ['a' as u8, 'b' as u8, 'c' as u8, 'd' as u8, 'e' as u8] };
- let x: &Baz = mem::transmute(slice::from_raw_parts(&*data, 5));
- assert_eq!(x.f1, 42);
- let chs: Vec<char> = x.f2.chars().collect();
- assert_eq!(chs.len(), 5);
- assert_eq!(chs[0], 'a');
- assert_eq!(chs[1], 'b');
- assert_eq!(chs[2], 'c');
- assert_eq!(chs[3], 'd');
- assert_eq!(chs[4], 'e');
-
- struct Qux_ {
- f: St
- }
-
- let obj: Box<St> = box St { f: 42 };
- let obj: &Tr = &*obj;
- let obj: raw::TraitObject = mem::transmute(&*obj);
- let data: Box<_> = box Qux_{ f: St { f: 234 } };
- let x: &Qux = mem::transmute(raw::TraitObject { vtable: obj.vtable,
- data: mem::transmute(&*data) });
- assert_eq!(x.f.foo(), 234);
- }
-}
+++ /dev/null
-// run-pass
-//
-#![allow(non_snake_case)]
-
-#![feature(non_ascii_idents)]
-
-pub fn main() {
- let ε = 0.00001f64;
- let Π = 3.14f64;
- let लंच = Π * Π + 1.54;
- assert!(((लंच - 1.54) - (Π * Π)).abs() < ε);
- assert_eq!(საჭმელად_გემრიელი_სადილი(), 0);
-}
-
-fn საჭმელად_გემრიელი_სადილი() -> isize {
-
- // Lunch in several languages.
-
- let ランチ = 10;
- let 午餐 = 10;
-
- let ארוחת_צהריי = 10;
- let غداء = 10_usize;
- let լանչ = 10;
- let обед = 10;
- let абед = 10;
- let μεσημεριανό = 10;
- let hádegismatur = 10;
- let ручек = 10;
-
- let ăn_trưa = 10;
- let อาหารกลางวัน = 10;
-
- // Lunchy arithmetic, mm.
-
- assert_eq!(hádegismatur * ручек * обед, 1000);
- assert_eq!(10, ארוחת_צהריי);
- assert_eq!(ランチ + 午餐 + μεσημεριανό, 30);
- assert_eq!(ăn_trưa + อาหารกลางวัน, 20);
- return (абед + լանչ) >> غداء;
-}
+++ /dev/null
-// run-pass
-#![allow(unused_variables)]
-// pretty-expanded FIXME #23616
-
-trait Foo<T> { fn dummy(&self, arg: T) { } }
-
-trait Bar<A> {
- fn method<B>(&self) where A: Foo<B>;
-}
-
-struct S;
-struct X;
-
-impl Foo<S> for X {}
-
-impl Bar<X> for i32 {
- fn method<U>(&self) where X: Foo<U> {
- }
-}
-
-fn main() {
- 1.method::<S>();
-}
--- /dev/null
+// run-pass
+
+#![allow(unused_imports)]
+#![deny(unused_assignments)]
+
+use std::mem;
+use std::ops::{
+ AddAssign, BitAndAssign, BitOrAssign, BitXorAssign, DivAssign, Index, MulAssign, RemAssign,
+ ShlAssign, ShrAssign, SubAssign,
+};
+
+#[derive(Debug, PartialEq)]
+struct Int(i32);
+
+struct Slice([i32]);
+
+impl Slice {
+ fn new(slice: &mut [i32]) -> &mut Slice {
+ unsafe {
+ mem::transmute(slice)
+ }
+ }
+}
+
+struct View<'a>(&'a mut [i32]);
+
+fn main() {
+ let mut x = Int(1);
+
+ x += Int(2);
+ assert_eq!(x, Int(0b11));
+
+ x &= Int(0b01);
+ assert_eq!(x, Int(0b01));
+
+ x |= Int(0b10);
+ assert_eq!(x, Int(0b11));
+
+ x ^= Int(0b01);
+ assert_eq!(x, Int(0b10));
+
+ x /= Int(2);
+ assert_eq!(x, Int(1));
+
+ x *= Int(3);
+ assert_eq!(x, Int(3));
+
+ x %= Int(2);
+ assert_eq!(x, Int(1));
+
+ // overloaded RHS
+ x <<= 1u8;
+ assert_eq!(x, Int(2));
+
+ x <<= 1u16;
+ assert_eq!(x, Int(4));
+
+ x >>= 1u8;
+ assert_eq!(x, Int(2));
+
+ x >>= 1u16;
+ assert_eq!(x, Int(1));
+
+ x -= Int(1);
+ assert_eq!(x, Int(0));
+
+ // indexed LHS
+ let mut v = vec![Int(1), Int(2)];
+ v[0] += Int(2);
+ assert_eq!(v[0], Int(3));
+
+ // unsized RHS
+ let mut array = [0, 1, 2];
+ *Slice::new(&mut array) += 1;
+ assert_eq!(array[0], 1);
+ assert_eq!(array[1], 2);
+ assert_eq!(array[2], 3);
+
+ // sized indirection
+ // check that this does *not* trigger the unused_assignments lint
+ let mut array = [0, 1, 2];
+ let mut view = View(&mut array);
+ view += 1;
+}
+
+impl AddAssign for Int {
+ fn add_assign(&mut self, rhs: Int) {
+ self.0 += rhs.0;
+ }
+}
+
+impl BitAndAssign for Int {
+ fn bitand_assign(&mut self, rhs: Int) {
+ self.0 &= rhs.0;
+ }
+}
+
+impl BitOrAssign for Int {
+ fn bitor_assign(&mut self, rhs: Int) {
+ self.0 |= rhs.0;
+ }
+}
+
+impl BitXorAssign for Int {
+ fn bitxor_assign(&mut self, rhs: Int) {
+ self.0 ^= rhs.0;
+ }
+}
+
+impl DivAssign for Int {
+ fn div_assign(&mut self, rhs: Int) {
+ self.0 /= rhs.0;
+ }
+}
+
+impl MulAssign for Int {
+ fn mul_assign(&mut self, rhs: Int) {
+ self.0 *= rhs.0;
+ }
+}
+
+impl RemAssign for Int {
+ fn rem_assign(&mut self, rhs: Int) {
+ self.0 %= rhs.0;
+ }
+}
+
+impl ShlAssign<u8> for Int {
+ fn shl_assign(&mut self, rhs: u8) {
+ self.0 <<= rhs;
+ }
+}
+
+impl ShlAssign<u16> for Int {
+ fn shl_assign(&mut self, rhs: u16) {
+ self.0 <<= rhs;
+ }
+}
+
+impl ShrAssign<u8> for Int {
+ fn shr_assign(&mut self, rhs: u8) {
+ self.0 >>= rhs;
+ }
+}
+
+impl ShrAssign<u16> for Int {
+ fn shr_assign(&mut self, rhs: u16) {
+ self.0 >>= rhs;
+ }
+}
+
+impl SubAssign for Int {
+ fn sub_assign(&mut self, rhs: Int) {
+ self.0 -= rhs.0;
+ }
+}
+
+impl AddAssign<i32> for Slice {
+ fn add_assign(&mut self, rhs: i32) {
+ for lhs in &mut self.0 {
+ *lhs += rhs;
+ }
+ }
+}
+
+impl<'a> AddAssign<i32> for View<'a> {
+ fn add_assign(&mut self, rhs: i32) {
+ for lhs in self.0.iter_mut() {
+ *lhs += rhs;
+ }
+ }
+}
--- /dev/null
+// no-prefer-dynamic
+
+#![crate_type="rlib"]
+#![crate_name="rmeta_aux"]
+
+pub struct Foo {
+ pub field: i32,
+}
--- /dev/null
+// run-pass
+#![allow(unused_mut)]
+#![allow(unused_variables)]
+// pretty-expanded FIXME #23616
+
+#![feature(box_syntax)]
+
+struct A { a: isize, b: Box<isize> }
+struct B { a: Box<isize>, b: Box<isize> }
+
+fn move_after_copy() {
+ let x = A { a: 1, b: box 2 };
+ drop(x.a);
+ drop(x.b);
+}
+
+fn move_after_fu_copy() {
+ let x = A { a: 1, b: box 2 };
+ let _y = A { b: box 3, .. x };
+ drop(x.b);
+}
+
+fn fu_move_after_copy() {
+ let x = A { a: 1, b: box 2 };
+ drop(x.a);
+ let _y = A { a: 3, .. x };
+}
+
+fn fu_move_after_fu_copy() {
+ let x = A { a: 1, b: box 2 };
+ let _y = A { b: box 3, .. x };
+ let _z = A { a: 4, .. x };
+}
+
+fn copy_after_move() {
+ let x = A { a: 1, b: box 2 };
+ drop(x.b);
+ drop(x.a);
+}
+
+fn copy_after_fu_move() {
+ let x = A { a: 1, b: box 2 };
+ let y = A { a: 3, .. x };
+ drop(x.a);
+}
+
+fn fu_copy_after_move() {
+ let x = A { a: 1, b: box 2 };
+ drop(x.b);
+ let _y = A { b: box 3, .. x };
+}
+
+fn fu_copy_after_fu_move() {
+ let x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
+ let _z = A { b: box 3, .. x };
+}
+
+fn borrow_after_move() {
+ let x = A { a: 1, b: box 2 };
+ drop(x.b);
+ let p = &x.a;
+ drop(*p);
+}
+
+fn borrow_after_fu_move() {
+ let x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
+ let p = &x.a;
+ drop(*p);
+}
+
+fn move_after_borrow() {
+ let x = A { a: 1, b: box 2 };
+ let p = &x.a;
+ drop(x.b);
+ drop(*p);
+}
+
+fn fu_move_after_borrow() {
+ let x = A { a: 1, b: box 2 };
+ let p = &x.a;
+ let _y = A { a: 3, .. x };
+ drop(*p);
+}
+
+fn mut_borrow_after_mut_borrow() {
+ let mut x = A { a: 1, b: box 2 };
+ let p = &mut x.a;
+ let q = &mut x.b;
+ drop(*p);
+ drop(**q);
+}
+
+fn move_after_move() {
+ let x = B { a: box 1, b: box 2 };
+ drop(x.a);
+ drop(x.b);
+}
+
+fn move_after_fu_move() {
+ let x = B { a: box 1, b: box 2 };
+ let y = B { a: box 3, .. x };
+ drop(x.a);
+}
+
+fn fu_move_after_move() {
+ let x = B { a: box 1, b: box 2 };
+ drop(x.a);
+ let z = B { a: box 3, .. x };
+ drop(z.b);
+}
+
+fn fu_move_after_fu_move() {
+ let x = B { a: box 1, b: box 2 };
+ let _y = B { b: box 3, .. x };
+ let _z = B { a: box 4, .. x };
+}
+
+fn copy_after_assign_after_move() {
+ let mut x = A { a: 1, b: box 2 };
+ drop(x.b);
+ x = A { a: 3, b: box 4 };
+ drop(*x.b);
+}
+
+fn copy_after_assign_after_fu_move() {
+ let mut x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
+ x = A { a: 3, b: box 4 };
+ drop(*x.b);
+}
+
+fn copy_after_field_assign_after_move() {
+ let mut x = A { a: 1, b: box 2 };
+ drop(x.b);
+ x.b = box 3;
+ drop(*x.b);
+}
+
+fn copy_after_field_assign_after_fu_move() {
+ let mut x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
+ x.b = box 3;
+ drop(*x.b);
+}
+
+fn borrow_after_assign_after_move() {
+ let mut x = A { a: 1, b: box 2 };
+ drop(x.b);
+ x = A { a: 3, b: box 4 };
+ let p = &x.b;
+ drop(**p);
+}
+
+fn borrow_after_assign_after_fu_move() {
+ let mut x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
+ x = A { a: 3, b: box 4 };
+ let p = &x.b;
+ drop(**p);
+}
+
+fn borrow_after_field_assign_after_move() {
+ let mut x = A { a: 1, b: box 2 };
+ drop(x.b);
+ x.b = box 3;
+ let p = &x.b;
+ drop(**p);
+}
+
+fn borrow_after_field_assign_after_fu_move() {
+ let mut x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
+ x.b = box 3;
+ let p = &x.b;
+ drop(**p);
+}
+
+fn move_after_assign_after_move() {
+ let mut x = A { a: 1, b: box 2 };
+ let _y = x.b;
+ x = A { a: 3, b: box 4 };
+ drop(x.b);
+}
+
+fn move_after_assign_after_fu_move() {
+ let mut x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
+ x = A { a: 3, b: box 4 };
+ drop(x.b);
+}
+
+fn move_after_field_assign_after_move() {
+ let mut x = A { a: 1, b: box 2 };
+ drop(x.b);
+ x.b = box 3;
+ drop(x.b);
+}
+
+fn move_after_field_assign_after_fu_move() {
+ let mut x = A { a: 1, b: box 2 };
+ let _y = A { a: 3, .. x };
+ x.b = box 3;
+ drop(x.b);
+}
+
+fn copy_after_assign_after_uninit() {
+ let mut x: A;
+ x = A { a: 1, b: box 2 };
+ drop(x.a);
+}
+
+fn borrow_after_assign_after_uninit() {
+ let mut x: A;
+ x = A { a: 1, b: box 2 };
+ let p = &x.a;
+ drop(*p);
+}
+
+fn move_after_assign_after_uninit() {
+ let mut x: A;
+ x = A { a: 1, b: box 2 };
+ drop(x.b);
+}
+
+fn main() {
+ move_after_copy();
+ move_after_fu_copy();
+ fu_move_after_copy();
+ fu_move_after_fu_copy();
+ copy_after_move();
+ copy_after_fu_move();
+ fu_copy_after_move();
+ fu_copy_after_fu_move();
+
+ borrow_after_move();
+ borrow_after_fu_move();
+ move_after_borrow();
+ fu_move_after_borrow();
+ mut_borrow_after_mut_borrow();
+
+ move_after_move();
+ move_after_fu_move();
+ fu_move_after_move();
+ fu_move_after_fu_move();
+
+ copy_after_assign_after_move();
+ copy_after_assign_after_fu_move();
+ copy_after_field_assign_after_move();
+ copy_after_field_assign_after_fu_move();
+
+ borrow_after_assign_after_move();
+ borrow_after_assign_after_fu_move();
+ borrow_after_field_assign_after_move();
+ borrow_after_field_assign_after_fu_move();
+
+ move_after_assign_after_move();
+ move_after_assign_after_fu_move();
+ move_after_field_assign_after_move();
+ move_after_field_assign_after_fu_move();
+
+ copy_after_assign_after_uninit();
+ borrow_after_assign_after_uninit();
+ move_after_assign_after_uninit();
+}
--- /dev/null
+// run-pass
+//compile-flags: -Z borrowck=mir
+
+#![feature(slice_patterns)]
+
+fn mut_head_tail<'a, A>(v: &'a mut [A]) -> Option<(&'a mut A, &'a mut [A])> {
+ match *v {
+ [ref mut head, ref mut tail..] => {
+ Some((head, tail))
+ }
+ [] => None
+ }
+}
+
+fn main() {
+ let mut v = [1,2,3,4];
+ match mut_head_tail(&mut v) {
+ None => {},
+ Some((h,t)) => {
+ *h = 1000;
+ t.reverse();
+ }
+ }
+}
--- /dev/null
+// run-pass
+// pretty-expanded FIXME #23616
+
+#![feature(box_syntax)]
+
+struct A { a: isize, b: Box<isize> }
+
+fn field_copy_after_field_borrow() {
+ let mut x = A { a: 1, b: box 2 };
+ let p = &mut x.b;
+ drop(x.a);
+ **p = 3;
+}
+
+fn fu_field_copy_after_field_borrow() {
+ let mut x = A { a: 1, b: box 2 };
+ let p = &mut x.b;
+ let y = A { b: box 3, .. x };
+ drop(y);
+ **p = 4;
+}
+
+fn field_deref_after_field_borrow() {
+ let mut x = A { a: 1, b: box 2 };
+ let p = &mut x.a;
+ drop(*x.b);
+ *p = 3;
+}
+
+fn field_move_after_field_borrow() {
+ let mut x = A { a: 1, b: box 2 };
+ let p = &mut x.a;
+ drop(x.b);
+ *p = 3;
+}
+
+fn fu_field_move_after_field_borrow() {
+ let mut x = A { a: 1, b: box 2 };
+ let p = &mut x.a;
+ let y = A { a: 3, .. x };
+ drop(y);
+ *p = 4;
+}
+
+fn main() {
+ field_copy_after_field_borrow();
+ fu_field_copy_after_field_borrow();
+ field_deref_after_field_borrow();
+ field_move_after_field_borrow();
+ fu_field_move_after_field_borrow();
+}
--- /dev/null
+// run-pass
+// revisions: old re
+
+#![cfg_attr(re, feature(re_rebalance_coherence))]
+#![allow(dead_code)]
+// pretty-expanded FIXME #23616
+
+#![feature(optin_builtin_traits)]
+
+use std::marker::Send;
+
+struct TestType;
+
+impl !Send for TestType {}
+
+fn main() {}
--- /dev/null
+#![allow(dead_code)]
+#![feature(re_rebalance_coherence)]
+
+// run-pass
+// aux-build:re_rebalance_coherence_lib.rs
+
+extern crate re_rebalance_coherence_lib as lib;
+use lib::*;
+
+struct Oracle;
+impl Backend for Oracle {}
+impl<'a, T:'a, Tab> QueryFragment<Oracle> for BatchInsert<'a, T, Tab> {}
+
+fn main() {}
--- /dev/null
+// run-pass
+
+pub fn main() {
+ assert_eq!(format!(concat!("foo", "bar", "{}"), "baz"), "foobarbaz".to_string());
+ assert_eq!(format!(concat!()), "".to_string());
+ // check trailing comma is allowed in concat
+ assert_eq!(concat!("qux", "quux",).to_string(), "quxquux".to_string());
+
+ assert_eq!(
+ concat!(1, 2, 3, 4f32, 4.0, 'a', true),
+ "12344.0atrue"
+ );
+
+ assert!(match "12344.0atrue" {
+ concat!(1, 2, 3, 4f32, 4.0, 'a', true) => true,
+ _ => false
+ })
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+
+#[repr(u8)]
+enum Foo {
+ Bar = { let x = 1; 3 }
+}
+
+pub fn main() {
+ assert_eq!(3, Foo::Bar as u8);
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+// check for const_err regressions
+
+#![deny(const_err)]
+
+const X: *const u8 = b"" as _;
+const Y: bool = 'A' == 'B';
+const Z: char = 'A';
+const W: bool = Z <= 'B';
+
+
+fn main() {
+ let _ = ((-1 as i8) << 8 - 1) as f32;
+ let _ = 0u8 as char;
+ let _ = true > false;
+ let _ = true >= false;
+ let _ = true < false;
+ let _ = true >= false;
+}
--- /dev/null
+// run-pass
+
+#![feature(const_int_conversion)]
+
+const REVERSE: u32 = 0x12345678_u32.reverse_bits();
+const FROM_BE_BYTES: i32 = i32::from_be_bytes([0x12, 0x34, 0x56, 0x78]);
+const FROM_LE_BYTES: i32 = i32::from_le_bytes([0x12, 0x34, 0x56, 0x78]);
+const FROM_NE_BYTES: i32 = i32::from_be(i32::from_ne_bytes([0x80, 0, 0, 0]));
+const TO_BE_BYTES: [u8; 4] = 0x12_34_56_78_i32.to_be_bytes();
+const TO_LE_BYTES: [u8; 4] = 0x12_34_56_78_i32.to_le_bytes();
+const TO_NE_BYTES: [u8; 4] = i32::min_value().to_be().to_ne_bytes();
+
+fn main() {
+ assert_eq!(REVERSE, 0x1e6a2c48);
+ assert_eq!(FROM_BE_BYTES, 0x12_34_56_78);
+ assert_eq!(FROM_LE_BYTES, 0x78_56_34_12);
+ assert_eq!(FROM_NE_BYTES, i32::min_value());
+ assert_eq!(TO_BE_BYTES, [0x12, 0x34, 0x56, 0x78]);
+ assert_eq!(TO_LE_BYTES, [0x78, 0x56, 0x34, 0x12]);
+ assert_eq!(TO_NE_BYTES, [0x80, 0, 0, 0]);
+}
--- /dev/null
+// run-pass
+
+const ADD_A: (u32, bool) = 5u32.overflowing_add(2);
+const ADD_B: (u32, bool) = u32::max_value().overflowing_add(1);
+
+const SUB_A: (u32, bool) = 5u32.overflowing_sub(2);
+const SUB_B: (u32, bool) = 0u32.overflowing_sub(1);
+
+const MUL_A: (u32, bool) = 5u32.overflowing_mul(2);
+const MUL_B: (u32, bool) = 1_000_000_000u32.overflowing_mul(10);
+
+const SHL_A: (u32, bool) = 0x1u32.overflowing_shl(4);
+const SHL_B: (u32, bool) = 0x1u32.overflowing_shl(132);
+
+const SHR_A: (u32, bool) = 0x10u32.overflowing_shr(4);
+const SHR_B: (u32, bool) = 0x10u32.overflowing_shr(132);
+
+const NEG_A: (u32, bool) = 0u32.overflowing_neg();
+const NEG_B: (u32, bool) = core::u32::MAX.overflowing_neg();
+
+fn main() {
+ assert_eq!(ADD_A, (7, false));
+ assert_eq!(ADD_B, (0, true));
+
+ assert_eq!(SUB_A, (3, false));
+ assert_eq!(SUB_B, (u32::max_value(), true));
+
+ assert_eq!(MUL_A, (10, false));
+ assert_eq!(MUL_B, (1410065408, true));
+
+ assert_eq!(SHL_A, (0x10, false));
+ assert_eq!(SHL_B, (0x10, true));
+
+ assert_eq!(SHR_A, (0x1, false));
+ assert_eq!(SHR_B, (0x1, true));
+
+ assert_eq!(NEG_A, (0, false));
+ assert_eq!(NEG_B, (1, true));
+}
--- /dev/null
+// run-pass
+
+const LEFT: u32 = 0x10000b3u32.rotate_left(8);
+const RIGHT: u32 = 0xb301u32.rotate_right(8);
+
+// Rotating these should make no difference
+//
+// We test using 124 bits because to ensure that overlong bit shifts do
+// not cause undefined behaviour. See #10183.
+const LEFT_OVERFLOW: i16 = 0i16.rotate_left(124);
+const RIGHT_OVERFLOW: i16 = 0i16.rotate_right(124);
+const ONE_LEFT_OVERFLOW: u16 = 1u16.rotate_left(124);
+const ONE_RIGHT_OVERFLOW: u16 = 1u16.rotate_right(124);
+
+const NON_ZERO_LEFT_OVERFLOW: u16 = 0b10u16.rotate_left(124);
+const NON_ZERO_RIGHT_OVERFLOW: u16 = 0b10u16.rotate_right(124);
+
+// Rotating by 0 should have no effect
+const ZERO_ROTATE_LEFT: i8 = 0b0010_0001i8.rotate_left(0);
+const ZERO_ROTATE_RIGHT: i8 = 0b0111_1001i8.rotate_right(0);
+
+// Rotating by a multiple of word size should also have no effect
+const MULTIPLE_ROTATE_LEFT: i32 = 0b0010_0001i32.rotate_left(128);
+const MULTIPLE_ROTATE_RIGHT: i32 = 0b0010_0001i32.rotate_right(128);
+
+fn main() {
+ assert_eq!(LEFT, 0xb301);
+ assert_eq!(RIGHT, 0x0100_00b3);
+
+ assert_eq!(LEFT_OVERFLOW, 0);
+ assert_eq!(RIGHT_OVERFLOW, 0);
+ assert_eq!(ONE_LEFT_OVERFLOW, 0b0001_0000_0000_0000);
+ assert_eq!(ONE_RIGHT_OVERFLOW, 0b0001_0000);
+
+ assert_eq!(NON_ZERO_LEFT_OVERFLOW, 0b0010_0000_0000_0000);
+ assert_eq!(NON_ZERO_RIGHT_OVERFLOW, 0b0000_0000_0010_0000);
+
+ assert_eq!(ZERO_ROTATE_LEFT, 0b0010_0001);
+ assert_eq!(ZERO_ROTATE_RIGHT, 0b0111_1001);
+
+ assert_eq!(MULTIPLE_ROTATE_LEFT, 0b0010_0001);
+ assert_eq!(MULTIPLE_ROTATE_RIGHT, 0b0010_0001);
+}
--- /dev/null
+// run-pass
+
+#![feature(const_int_sign)]
+
+const NEGATIVE_A: bool = (-10i32).is_negative();
+const NEGATIVE_B: bool = 10i32.is_negative();
+const POSITIVE_A: bool = (-10i32).is_positive();
+const POSITIVE_B: bool = 10i32.is_positive();
+
+const SIGNUM_POS: i32 = 10i32.signum();
+const SIGNUM_NIL: i32 = 0i32.signum();
+const SIGNUM_NEG: i32 = (-42i32).signum();
+
+fn main() {
+ assert!(NEGATIVE_A);
+ assert!(!NEGATIVE_B);
+ assert!(!POSITIVE_A);
+ assert!(POSITIVE_B);
+
+ assert_eq!(SIGNUM_POS, 1);
+ assert_eq!(SIGNUM_NIL, 0);
+ assert_eq!(SIGNUM_NEG, -1);
+}
--- /dev/null
+// run-pass
+
+const ADD_A: u32 = 200u32.wrapping_add(55);
+const ADD_B: u32 = 200u32.wrapping_add(u32::max_value());
+
+const SUB_A: u32 = 100u32.wrapping_sub(100);
+const SUB_B: u32 = 100u32.wrapping_sub(u32::max_value());
+
+const MUL_A: u8 = 10u8.wrapping_mul(12);
+const MUL_B: u8 = 25u8.wrapping_mul(12);
+
+const SHL_A: u32 = 1u32.wrapping_shl(7);
+const SHL_B: u32 = 1u32.wrapping_shl(128);
+
+const SHR_A: u32 = 128u32.wrapping_shr(7);
+const SHR_B: u32 = 128u32.wrapping_shr(128);
+
+const NEG_A: u32 = 5u32.wrapping_neg();
+const NEG_B: u32 = 1234567890u32.wrapping_neg();
+
+fn main() {
+ assert_eq!(ADD_A, 255);
+ assert_eq!(ADD_B, 199);
+
+ assert_eq!(SUB_A, 0);
+ assert_eq!(SUB_B, 101);
+
+ assert_eq!(MUL_A, 120);
+ assert_eq!(MUL_B, 44);
+
+ assert_eq!(SHL_A, 128);
+ assert_eq!(SHL_B, 1);
+
+ assert_eq!(SHR_A, 1);
+ assert_eq!(SHR_B, 128);
+
+ assert_eq!(NEG_A, 4294967291);
+ assert_eq!(NEG_B, 3060399406);
+}
--- /dev/null
+// run-pass
+
+#![feature(ptr_internals, test)]
+
+extern crate test;
+use test::black_box as b; // prevent promotion of the argument and const-propagation of the result
+
+use std::ptr::NonNull;
+
+const DANGLING: NonNull<u32> = NonNull::dangling();
+const CASTED: NonNull<u32> = NonNull::cast(NonNull::<i32>::dangling());
+
+pub fn main() {
+ // Be super-extra paranoid and cast the fn items to fn pointers before blackboxing them.
+ assert_eq!(DANGLING, b::<fn() -> _>(NonNull::dangling)());
+ assert_eq!(CASTED, b::<fn() -> _>(NonNull::dangling)());
+}
--- /dev/null
+// run-pass
+
+#![feature(ptr_internals, test)]
+
+extern crate test;
+use test::black_box as b; // prevent promotion of the argument and const-propagation of the result
+
+use std::ptr::Unique;
+
+
+const PTR: *mut u32 = Unique::empty().as_ptr();
+
+pub fn main() {
+ // Be super-extra paranoid and cast the fn items to fn pointers before blackboxing them.
+ assert_eq!(PTR, b::<fn() -> _>(Unique::<u32>::empty)().as_ptr());
+}
--- /dev/null
+// run-pass
+#![feature(core_intrinsics)]
+#![feature(const_type_id)]
+
+use std::any::TypeId;
+
+struct A;
+
+static ID_ISIZE: TypeId = TypeId::of::<isize>();
+
+pub fn main() {
+ assert_eq!(ID_ISIZE, TypeId::of::<isize>());
+
+ // sanity test of TypeId
+ const T: (TypeId, TypeId, TypeId) = (TypeId::of::<usize>(),
+ TypeId::of::<&'static str>(),
+ TypeId::of::<A>());
+ let (d, e, f) = (TypeId::of::<usize>(), TypeId::of::<&'static str>(),
+ TypeId::of::<A>());
+
+ assert!(T.0 != T.1);
+ assert!(T.0 != T.2);
+ assert!(T.1 != T.2);
+
+ assert_eq!(T.0, d);
+ assert_eq!(T.1, e);
+ assert_eq!(T.2, f);
+
+ // Check fn pointer against collisions
+ const F: (TypeId, TypeId) = (TypeId::of::<fn(fn(A) -> A) -> A>(),
+ TypeId::of::<fn(fn() -> A, A) -> A>());
+
+ assert!(F.0 != F.1);
+}
--- /dev/null
+// run-pass
+
+#![feature(raw)]
+
+use std::mem;
+use std::raw;
+
+trait Foo {
+ fn foo(&self) {}
+}
+
+struct Bar;
+
+impl Foo for Bar {}
+
+fn main() {
+ // Test we can turn a fat pointer to array back into a thin pointer.
+ let a: *const [i32] = &[1, 2, 3];
+ let b = a as *const [i32; 2];
+ unsafe {
+ assert_eq!(*b, [1, 2]);
+ }
+
+ // Test conversion to an address (usize).
+ let a: *const [i32; 3] = &[1, 2, 3];
+ let b: *const [i32] = a;
+ assert_eq!(a as usize, b as *const () as usize);
+
+ // And conversion to a void pointer/address for trait objects too.
+ let a: *mut dyn Foo = &mut Bar;
+ let b = a as *mut ();
+ let c = a as *const () as usize;
+ let d = unsafe {
+ let r: raw::TraitObject = mem::transmute(a);
+ r.data
+ };
+
+ assert_eq!(b, d);
+ assert_eq!(c, d as usize);
+
+}
--- /dev/null
+// run-pass
+
+// Fast path, main can see the concrete type returned.
+fn before() -> impl FnMut(i32) {
+ let mut p = Box::new(0);
+ move |x| *p = x
+}
+
+fn send<T: Send>(_: T) {}
+
+fn main() {
+ send(before());
+ send(after());
+}
+
+// Deferred path, main has to wait until typeck finishes,
+// to check if the return type of after is Send.
+fn after() -> impl FnMut(i32) {
+ let mut p = Box::new(0);
+ move |x| *p = x
+}
--- /dev/null
+// run-pass
+
+#![feature(specialization)]
+
+trait Foo: std::fmt::Debug + Eq {}
+
+impl<T: std::fmt::Debug + Eq> Foo for T {}
+
+fn hide<T: Foo>(x: T) -> impl Foo {
+ x
+}
+
+trait Leak<T>: Sized {
+ fn leak(self) -> T;
+}
+impl<T, U> Leak<T> for U {
+ default fn leak(self) -> T { panic!("type mismatch") }
+}
+impl<T> Leak<T> for T {
+ fn leak(self) -> T { self }
+}
+
+trait CheckIfSend: Sized {
+ type T: Default;
+ fn check(self) -> Self::T { Default::default() }
+}
+impl<T> CheckIfSend for T {
+ default type T = ();
+}
+impl<T: Send> CheckIfSend for T {
+ type T = bool;
+}
+
+fn lucky_seven() -> impl Fn(usize) -> u8 {
+ let a = [1, 2, 3, 4, 5, 6, 7];
+ move |i| a[i]
+}
+
+fn main() {
+ assert_eq!(hide(42), hide(42));
+
+ assert_eq!(std::mem::size_of_val(&hide([0_u8; 5])), 5);
+ assert_eq!(std::mem::size_of_val(&lucky_seven()), 7);
+
+ assert_eq!(Leak::<i32>::leak(hide(5_i32)), 5_i32);
+
+ assert_eq!(CheckIfSend::check(hide(0_i32)), false);
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+use module_of_many_things::*;
+use dug::too::greedily::and::too::deep::*;
+
+mod module_of_many_things {
+ pub fn f1() { println!("f1"); }
+ pub fn f2() { println!("f2"); }
+ fn f3() { println!("f3"); }
+ pub fn f4() { println!("f4"); }
+}
+
+mod dug {
+ pub mod too {
+ pub mod greedily {
+ pub mod and {
+ pub mod too {
+ pub mod deep {
+ pub fn nameless_fear() { println!("Boo!"); }
+ pub fn also_redstone() { println!("Whatever."); }
+ }
+ }
+ }
+ }
+ }
+}
+
+
+pub fn main() { f1(); f2(); f4(); nameless_fear(); also_redstone(); }
--- /dev/null
+// run-pass
+// pretty-expanded FIXME #23616
+
+extern "Rust" fn main() {}
--- /dev/null
+// run-pass
+
+pub enum T {
+ T1(()),
+ T2(())
+}
+
+pub enum V {
+ V1(isize),
+ V2(bool)
+}
+
+fn foo(x: (T, V)) -> String {
+ match x {
+ (T::T1(()), V::V1(i)) => format!("T1(()), V1({})", i),
+ (T::T2(()), V::V2(b)) => format!("T2(()), V2({})", b),
+ _ => String::new()
+ }
+}
+
+
+fn main() {
+ assert_eq!(foo((T::T1(()), V::V1(99))), "T1(()), V1(99)".to_string());
+ assert_eq!(foo((T::T2(()), V::V2(true))), "T2(()), V2(true)".to_string());
+}
--- /dev/null
+// run-pass
+// pretty-expanded FIXME #23616
+
+use std::any::Any;
+
+fn foo(_: &u8) {
+}
+
+fn main() {
+ let _ = &foo as &dyn Any;
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+// pretty-expanded FIXME #23616
+
+#![feature(link_llvm_intrinsics)]
+
+extern {
+ #[link_name = "llvm.sqrt.f32"]
+ fn sqrt(x: f32) -> f32;
+}
+
+fn main(){
+}
--- /dev/null
+// run-pass
+#![feature(unsize, coerce_unsized)]
+
+// Verfies that PhantomData is ignored for DST coercions
+
+use std::marker::{Unsize, PhantomData};
+use std::ops::CoerceUnsized;
+
+struct MyRc<T: ?Sized> {
+ _ptr: *const T,
+ _boo: PhantomData<T>,
+}
+
+impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<MyRc<U>> for MyRc<T>{ }
+
+fn main() {
+ let data = [1, 2, 3];
+ let iter = data.iter();
+ let x = MyRc { _ptr: &iter, _boo: PhantomData };
+ let _y: MyRc<dyn Iterator<Item=&u32>> = x;
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+#[repr(packed)]
+pub struct Good {
+ data: &'static u32,
+ data2: [&'static u32; 2],
+ aligned: [u8; 32],
+}
+
+#[repr(packed)]
+pub struct JustArray {
+ array: [u32]
+}
+
+// kill this test when that turns to a hard error
+#[allow(safe_packed_borrows)]
+fn main() {
+ let good = Good {
+ data: &0,
+ data2: [&0, &0],
+ aligned: [0; 32]
+ };
+
+ unsafe {
+ let _ = &good.data; // ok
+ let _ = &good.data2[0]; // ok
+ }
+
+ let _ = &good.data;
+ let _ = &good.data2[0];
+ let _ = &*good.data; // ok, behind a pointer
+ let _ = &good.aligned; // ok, has align 1
+ let _ = &good.aligned[2]; // ok, has align 1
+}
--- /dev/null
+// run-pass
+#![recursion_limit="1024"]
+
+use std::mem;
+
+pub struct S0<T>(T,T);
+pub struct S1<T>(Option<Box<S0<S0<T>>>>,Option<Box<S0<S0<T>>>>);
+pub struct S2<T>(Option<Box<S1<S1<T>>>>,Option<Box<S1<S1<T>>>>);
+pub struct S3<T>(Option<Box<S2<S2<T>>>>,Option<Box<S2<S2<T>>>>);
+pub struct S4<T>(Option<Box<S3<S3<T>>>>,Option<Box<S3<S3<T>>>>);
+pub struct S5<T>(Option<Box<S4<S4<T>>>>,Option<Box<S4<S4<T>>>>,Option<T>);
+
+trait Foo { fn xxx(&self); }
+/// some local of #[fundamental] trait
+trait Bar {}
+
+impl<T> Foo for T where T: Bar, T: Sync {
+ fn xxx(&self) {}
+}
+
+impl Foo for S5<u8> { fn xxx(&self) {} }
+
+fn main() {
+ let s = S5(None,None,None);
+ s.xxx();
+ assert_eq!(mem::size_of_val(&s.2), mem::size_of::<Option<u8>>());
+}
--- /dev/null
+// run-pass
+fn main() {
+ let &ref a = &[0i32] as &[_];
+ assert_eq!(a, &[0i32] as &[_]);
+
+ let &ref a = "hello";
+ assert_eq!(a, "hello");
+
+ match "foo" {
+ "fool" => unreachable!(),
+ "foo" => {},
+ ref _x => unreachable!()
+ }
+}
--- /dev/null
+// run-pass
+// aux-build:issue-38715.rs
+// aux-build:issue-38715-modern.rs
+
+// Test that `#[macro_export] macro_rules!` shadow earlier `#[macro_export] macro_rules!`
+
+#[macro_use]
+extern crate issue_38715;
+#[macro_use]
+extern crate issue_38715_modern;
+
+fn main() {
+ foo!();
+ foo_modern!();
+}
--- /dev/null
+// run-pass
+// aux-build:issue-41394.rs
+
+extern crate issue_41394 as lib;
+
+fn main() {
+ assert_eq!(lib::foo() as u32, 42);
+}
--- /dev/null
+// run-pass
+
+#![allow(unused_mut)]
+
+// Check that when `?` is followed by what looks like a Kleene operator (?, +, and *)
+// then that `?` is not interpreted as a separator. In other words, `$(pat)?+` matches `pat +`
+// or `+` but does not match `pat` or `pat ? pat`.
+
+// edition:2015
+
+macro_rules! foo {
+ // Check for `?`.
+ ($($a:ident)? ? $num:expr) => {
+ foo!($($a)? ; $num);
+ };
+ // Check for `+`.
+ ($($a:ident)? + $num:expr) => {
+ foo!($($a)? ; $num);
+ };
+ // Check for `*`.
+ ($($a:ident)? * $num:expr) => {
+ foo!($($a)? ; $num);
+ };
+ // Check for `;`, not a kleene operator.
+ ($($a:ident)? ; $num:expr) => {
+ let mut x = 0;
+
+ $(
+ x += $a;
+ )?
+
+ assert_eq!(x, $num);
+ };
+}
+
+pub fn main() {
+ let a = 1;
+
+ // Accept 0 repetitions.
+ foo!( ; 0);
+ foo!( + 0);
+ foo!( * 0);
+ foo!( ? 0);
+
+ // Accept 1 repetition.
+ foo!(a ; 1);
+ foo!(a + 1);
+ foo!(a * 1);
+ foo!(a ? 1);
+}
--- /dev/null
+// run-pass
+
+#![allow(unused_mut)]
+
+// Check that when `?` is followed by what looks like a Kleene operator (?, +, and *)
+// then that `?` is not interpreted as a separator. In other words, `$(pat)?+` matches `pat +`
+// or `+` but does not match `pat` or `pat ? pat`.
+
+// edition:2018
+
+macro_rules! foo {
+ // Check for `?`.
+ ($($a:ident)? ? $num:expr) => {
+ foo!($($a)? ; $num);
+ };
+ // Check for `+`.
+ ($($a:ident)? + $num:expr) => {
+ foo!($($a)? ; $num);
+ };
+ // Check for `*`.
+ ($($a:ident)? * $num:expr) => {
+ foo!($($a)? ; $num);
+ };
+ // Check for `;`, not a kleene operator.
+ ($($a:ident)? ; $num:expr) => {
+ let mut x = 0;
+
+ $(
+ x += $a;
+ )?
+
+ assert_eq!(x, $num);
+ };
+}
+
+pub fn main() {
+ let a = 1;
+
+ // Accept 0 repetitions.
+ foo!( ; 0);
+ foo!( + 0);
+ foo!( * 0);
+ foo!( ? 0);
+
+ // Accept 1 repetition.
+ foo!(a ; 1);
+ foo!(a + 1);
+ foo!(a * 1);
+ foo!(a ? 1);
+}
--- /dev/null
+// run-pass
+#![allow(unused_imports)]
+// Ideally, any macro call with a trailing comma should behave
+// identically to a call without the comma.
+//
+// This checks the behavior of macros with trailing commas in key
+// places where regressions in behavior seem highly possible (due
+// to it being e.g., a place where the addition of an argument
+// causes it to go down a code path with subtly different behavior).
+//
+// There is a companion test in compile-fail.
+
+// compile-flags: --test -C debug_assertions=yes
+// revisions: std core
+
+#![cfg_attr(core, no_std)]
+
+#[cfg(std)] use std::fmt;
+#[cfg(core)] use core::fmt;
+
+// an easy mistake in the implementation of 'assert!'
+// would cause this to say "explicit panic"
+#[test]
+#[should_panic(expected = "assertion failed")]
+fn assert_1arg() {
+ assert!(false,);
+}
+
+// same as 'assert_1arg'
+#[test]
+#[should_panic(expected = "assertion failed")]
+fn debug_assert_1arg() {
+ debug_assert!(false,);
+}
+
+// make sure we don't accidentally forward to `write!("text")`
+#[cfg(std)]
+#[test]
+fn writeln_1arg() {
+ use fmt::Write;
+
+ let mut s = String::new();
+ writeln!(&mut s,).unwrap();
+ assert_eq!(&s, "\n");
+}
+
+// A number of format_args-like macros have special-case treatment
+// for a single message string, which is not formatted.
+//
+// This test ensures that the addition of a trailing comma does not
+// suddenly cause these strings to get formatted when they otherwise
+// would not be. This is an easy mistake to make by having such a macro
+// accept ", $($tok:tt)*" instead of ", $($tok:tt)+" after its minimal
+// set of arguments.
+//
+// (Example: Issue #48042)
+#[test]
+fn to_format_or_not_to_format() {
+ // ("{}" is the easiest string to test because if this gets
+ // sent to format_args!, it'll simply fail to compile.
+ // "{{}}" is an example of an input that could compile and
+ // produce an incorrect program, but testing the panics
+ // would be burdensome.)
+ let falsum = || false;
+
+ assert!(true, "{}",);
+
+ // assert_eq!(1, 1, "{}",); // see compile-fail
+ // assert_ne!(1, 2, "{}",); // see compile-fail
+
+ debug_assert!(true, "{}",);
+
+ // debug_assert_eq!(1, 1, "{}",); // see compile-fail
+ // debug_assert_ne!(1, 2, "{}",); // see compile-fail
+ // eprint!("{}",); // see compile-fail
+ // eprintln!("{}",); // see compile-fail
+ // format!("{}",); // see compile-fail
+ // format_args!("{}",); // see compile-fail
+
+ if falsum() { panic!("{}",); }
+
+ // print!("{}",); // see compile-fail
+ // println!("{}",); // see compile-fail
+ // unimplemented!("{}",); // see compile-fail
+
+ if falsum() { unreachable!("{}",); }
+
+ // write!(&mut stdout, "{}",); // see compile-fail
+ // writeln!(&mut stdout, "{}",); // see compile-fail
+}
--- /dev/null
+// run-pass
+// This is meant to be a comprehensive test of invocations with/without
+// trailing commas (or other, similar optionally-trailing separators).
+// Every macro is accounted for, even those not tested in this file.
+// (There will be a note indicating why).
+
+// std and core are both tested because they may contain separate
+// implementations for some macro_rules! macros as an implementation
+// detail.
+
+// ignore-pretty issue #37195
+
+// compile-flags: --test -C debug_assertions=yes
+// revisions: std core
+
+#![cfg_attr(core, no_std)]
+
+#![feature(concat_idents)]
+
+#[cfg(std)] use std::fmt;
+#[cfg(core)] use core::fmt;
+
+#[test]
+fn assert() {
+ assert!(true);
+ assert!(true,);
+ assert!(true, "hello");
+ assert!(true, "hello",);
+ assert!(true, "hello {}", "world");
+ assert!(true, "hello {}", "world",);
+}
+
+#[test]
+fn assert_eq() {
+ assert_eq!(1, 1);
+ assert_eq!(1, 1,);
+ assert_eq!(1, 1, "hello");
+ assert_eq!(1, 1, "hello",);
+ assert_eq!(1, 1, "hello {}", "world");
+ assert_eq!(1, 1, "hello {}", "world",);
+}
+
+#[test]
+fn assert_ne() {
+ assert_ne!(1, 2);
+ assert_ne!(1, 2,);
+ assert_ne!(1, 2, "hello");
+ assert_ne!(1, 2, "hello",);
+ assert_ne!(1, 2, "hello {}", "world");
+ assert_ne!(1, 2, "hello {}", "world",);
+}
+
+#[test]
+fn cfg() {
+ let _ = cfg!(pants);
+ let _ = cfg!(pants,);
+ let _ = cfg!(pants = "pants");
+ let _ = cfg!(pants = "pants",);
+ let _ = cfg!(all(pants));
+ let _ = cfg!(all(pants),);
+ let _ = cfg!(all(pants,));
+ let _ = cfg!(all(pants,),);
+}
+
+#[test]
+fn column() {
+ let _ = column!();
+}
+
+// compile_error! is in a companion to this test in compile-fail
+
+#[test]
+fn concat() {
+ let _ = concat!();
+ let _ = concat!("hello");
+ let _ = concat!("hello",);
+ let _ = concat!("hello", " world");
+ let _ = concat!("hello", " world",);
+}
+
+#[test]
+fn concat_idents() {
+ fn foo() {}
+ fn foobar() {}
+
+ concat_idents!(foo)();
+ concat_idents!(foo,)();
+ concat_idents!(foo, bar)();
+ concat_idents!(foo, bar,)();
+}
+
+#[test]
+fn debug_assert() {
+ debug_assert!(true);
+ debug_assert!(true, );
+ debug_assert!(true, "hello");
+ debug_assert!(true, "hello",);
+ debug_assert!(true, "hello {}", "world");
+ debug_assert!(true, "hello {}", "world",);
+}
+
+#[test]
+fn debug_assert_eq() {
+ debug_assert_eq!(1, 1);
+ debug_assert_eq!(1, 1,);
+ debug_assert_eq!(1, 1, "hello");
+ debug_assert_eq!(1, 1, "hello",);
+ debug_assert_eq!(1, 1, "hello {}", "world");
+ debug_assert_eq!(1, 1, "hello {}", "world",);
+}
+
+#[test]
+fn debug_assert_ne() {
+ debug_assert_ne!(1, 2);
+ debug_assert_ne!(1, 2,);
+ debug_assert_ne!(1, 2, "hello");
+ debug_assert_ne!(1, 2, "hello",);
+ debug_assert_ne!(1, 2, "hello {}", "world");
+ debug_assert_ne!(1, 2, "hello {}", "world",);
+}
+
+#[test]
+fn env() {
+ let _ = env!("PATH");
+ let _ = env!("PATH",);
+ let _ = env!("PATH", "not found");
+ let _ = env!("PATH", "not found",);
+}
+
+#[cfg(std)]
+#[test]
+fn eprint() {
+ eprint!("hello");
+ eprint!("hello",);
+ eprint!("hello {}", "world");
+ eprint!("hello {}", "world",);
+}
+
+#[cfg(std)]
+#[test]
+fn eprintln() {
+ eprintln!();
+ eprintln!("hello");
+ eprintln!("hello",);
+ eprintln!("hello {}", "world");
+ eprintln!("hello {}", "world",);
+}
+
+#[test]
+fn file() {
+ let _ = file!();
+}
+
+#[cfg(std)]
+#[test]
+fn format() {
+ let _ = format!("hello");
+ let _ = format!("hello",);
+ let _ = format!("hello {}", "world");
+ let _ = format!("hello {}", "world",);
+}
+
+#[test]
+fn format_args() {
+ let _ = format_args!("hello");
+ let _ = format_args!("hello",);
+ let _ = format_args!("hello {}", "world");
+ let _ = format_args!("hello {}", "world",);
+}
+
+#[test]
+fn include() {
+ let _ = include!("auxiliary/macro-comma-support.rs");
+ let _ = include!("auxiliary/macro-comma-support.rs",);
+}
+
+#[test]
+fn include_bytes() {
+ let _ = include_bytes!("auxiliary/macro-comma-support.rs");
+ let _ = include_bytes!("auxiliary/macro-comma-support.rs",);
+}
+
+#[test]
+fn include_str() {
+ let _ = include_str!("auxiliary/macro-comma-support.rs");
+ let _ = include_str!("auxiliary/macro-comma-support.rs",);
+}
+
+#[test]
+fn line() {
+ let _ = line!();
+}
+
+#[test]
+fn module_path() {
+ let _ = module_path!();
+}
+
+#[test]
+fn option_env() {
+ let _ = option_env!("PATH");
+ let _ = option_env!("PATH",);
+}
+
+#[test]
+fn panic() {
+ // prevent 'unreachable code' warnings
+ let falsum = || false;
+
+ if falsum() { panic!(); }
+ if falsum() { panic!("hello"); }
+ if falsum() { panic!("hello",); }
+ if falsum() { panic!("hello {}", "world"); }
+ if falsum() { panic!("hello {}", "world",); }
+}
+
+#[cfg(std)]
+#[test]
+fn print() {
+ print!("hello");
+ print!("hello",);
+ print!("hello {}", "world");
+ print!("hello {}", "world",);
+}
+
+#[cfg(std)]
+#[test]
+fn println() {
+ println!();
+ println!("hello");
+ println!("hello",);
+ println!("hello {}", "world");
+ println!("hello {}", "world",);
+}
+
+// stringify! is N/A
+
+#[cfg(std)]
+#[test]
+fn thread_local() {
+ // this has an optional trailing *semicolon*
+ thread_local! {
+ #[allow(unused)] pub static A: () = ()
+ }
+
+ thread_local! {
+ #[allow(unused)] pub static AA: () = ();
+ }
+
+ thread_local! {
+ #[allow(unused)] pub static AAA: () = ();
+ #[allow(unused)] pub static AAAA: () = ()
+ }
+
+ thread_local! {
+ #[allow(unused)] pub static AAAAG: () = ();
+ #[allow(unused)] pub static AAAAGH: () = ();
+ }
+}
+
+#[test]
+fn try() {
+ fn inner() -> Result<(), ()> {
+ try!(Ok(()));
+ try!(Ok(()),);
+ Ok(())
+ }
+
+ inner().unwrap();
+}
+
+#[test]
+fn unimplemented() {
+ // prevent 'unreachable code' warnings
+ let falsum = || false;
+
+ if falsum() { unimplemented!(); }
+ if falsum() { unimplemented!("hello"); }
+ if falsum() { unimplemented!("hello",); }
+ if falsum() { unimplemented!("hello {}", "world"); }
+ if falsum() { unimplemented!("hello {}", "world",); }
+}
+
+#[test]
+fn unreachable() {
+ // prevent 'unreachable code' warnings
+ let falsum = || false;
+
+ if falsum() { unreachable!(); }
+ if falsum() { unreachable!("hello"); }
+ if falsum() { unreachable!("hello",); }
+ if falsum() { unreachable!("hello {}", "world"); }
+ if falsum() { unreachable!("hello {}", "world",); }
+}
+
+#[cfg(std)]
+#[test]
+fn vec() {
+ let _: Vec<()> = vec![];
+ let _ = vec![0];
+ let _ = vec![0,];
+ let _ = vec![0, 1];
+ let _ = vec![0, 1,];
+}
+
+// give a test body access to a fmt::Formatter, which seems
+// to be the easiest way to use 'write!' on core.
+macro_rules! test_with_formatter {
+ (
+ #[test]
+ fn $fname:ident($f:ident: &mut fmt::Formatter) $block:block
+ ) => {
+ #[test]
+ fn $fname() {
+ struct Struct;
+ impl fmt::Display for Struct {
+ fn fmt(&self, $f: &mut fmt::Formatter) -> fmt::Result {
+ Ok($block)
+ }
+ }
+
+ // suppress "unused"
+ assert!(true, "{}", Struct);
+ }
+ };
+}
+
+test_with_formatter! {
+ #[test]
+ fn write(f: &mut fmt::Formatter) {
+ let _ = write!(f, "hello");
+ let _ = write!(f, "hello",);
+ let _ = write!(f, "hello {}", "world");
+ let _ = write!(f, "hello {}", "world",);
+ }
+}
+
+test_with_formatter! {
+ #[test]
+ fn writeln(f: &mut fmt::Formatter) {
+ let _ = writeln!(f);
+ let _ = writeln!(f,);
+ let _ = writeln!(f, "hello");
+ let _ = writeln!(f, "hello",);
+ let _ = writeln!(f, "hello {}", "world");
+ let _ = writeln!(f, "hello {}", "world",);
+ }
+}
--- /dev/null
+// run-pass
+#![allow(unused_macros)]
+// Check the macro follow sets (see corresponding cfail test).
+
+// FOLLOW(pat) = {FatArrow, Comma, Eq, Or, Ident(if), Ident(in)}
+macro_rules! follow_pat {
+ ($p:pat =>) => {};
+ ($p:pat ,) => {};
+ ($p:pat =) => {};
+ ($p:pat |) => {};
+ ($p:pat if) => {};
+ ($p:pat in) => {};
+}
+// FOLLOW(expr) = {FatArrow, Comma, Semicolon}
+macro_rules! follow_expr {
+ ($e:expr =>) => {};
+ ($e:expr ,) => {};
+ ($e:expr ;) => {};
+}
+// FOLLOW(ty) = {OpenDelim(Brace), Comma, FatArrow, Colon, Eq, Gt, Semi, Or,
+// Ident(as), Ident(where), OpenDelim(Bracket), Nonterminal(Block)}
+macro_rules! follow_ty {
+ ($t:ty {}) => {};
+ ($t:ty ,) => {};
+ ($t:ty =>) => {};
+ ($t:ty :) => {};
+ ($t:ty =) => {};
+ ($t:ty >) => {};
+ ($t:ty ;) => {};
+ ($t:ty |) => {};
+ ($t:ty as) => {};
+ ($t:ty where) => {};
+ ($t:ty []) => {};
+ ($t:ty $b:block) => {};
+}
+// FOLLOW(stmt) = FOLLOW(expr)
+macro_rules! follow_stmt {
+ ($s:stmt =>) => {};
+ ($s:stmt ,) => {};
+ ($s:stmt ;) => {};
+}
+// FOLLOW(path) = FOLLOW(ty)
+macro_rules! follow_path {
+ ($p:path {}) => {};
+ ($p:path ,) => {};
+ ($p:path =>) => {};
+ ($p:path :) => {};
+ ($p:path =) => {};
+ ($p:path >) => {};
+ ($p:path ;) => {};
+ ($p:path |) => {};
+ ($p:path as) => {};
+ ($p:path where) => {};
+ ($p:path []) => {};
+ ($p:path $b:block) => {};
+}
+// FOLLOW(block) = any token
+macro_rules! follow_block {
+ ($b:block ()) => {};
+ ($b:block []) => {};
+ ($b:block {}) => {};
+ ($b:block ,) => {};
+ ($b:block =>) => {};
+ ($b:block :) => {};
+ ($b:block =) => {};
+ ($b:block >) => {};
+ ($b:block ;) => {};
+ ($b:block |) => {};
+ ($b:block +) => {};
+ ($b:block ident) => {};
+ ($b:block $p:pat) => {};
+ ($b:block $e:expr) => {};
+ ($b:block $t:ty) => {};
+ ($b:block $s:stmt) => {};
+ ($b:block $p:path) => {};
+ ($b:block $c:block) => {};
+ ($b:block $i:ident) => {};
+ ($b:block $t:tt) => {};
+ ($b:block $i:item) => {};
+ ($b:block $m:meta) => {};
+}
+// FOLLOW(ident) = any token
+macro_rules! follow_ident {
+ ($i:ident ()) => {};
+ ($i:ident []) => {};
+ ($i:ident {}) => {};
+ ($i:ident ,) => {};
+ ($i:ident =>) => {};
+ ($i:ident :) => {};
+ ($i:ident =) => {};
+ ($i:ident >) => {};
+ ($i:ident ;) => {};
+ ($i:ident |) => {};
+ ($i:ident +) => {};
+ ($i:ident ident) => {};
+ ($i:ident $p:pat) => {};
+ ($i:ident $e:expr) => {};
+ ($i:ident $t:ty) => {};
+ ($i:ident $s:stmt) => {};
+ ($i:ident $p:path) => {};
+ ($i:ident $b:block) => {};
+ ($i:ident $j:ident) => {};
+ ($i:ident $t:tt) => {};
+ ($i:ident $j:item) => {};
+ ($i:ident $m:meta) => {};
+}
+// FOLLOW(tt) = any token
+macro_rules! follow_tt {
+ ($t:tt ()) => {};
+ ($t:tt []) => {};
+ ($t:tt {}) => {};
+ ($t:tt ,) => {};
+ ($t:tt =>) => {};
+ ($t:tt :) => {};
+ ($t:tt =) => {};
+ ($t:tt >) => {};
+ ($t:tt ;) => {};
+ ($t:tt |) => {};
+ ($t:tt +) => {};
+ ($t:tt ident) => {};
+ ($t:tt $p:pat) => {};
+ ($t:tt $e:expr) => {};
+ ($t:tt $v:ty) => {};
+ ($t:tt $s:stmt) => {};
+ ($t:tt $p:path) => {};
+ ($t:tt $b:block) => {};
+ ($t:tt $i:ident) => {};
+ ($t:tt $v:tt) => {};
+ ($t:tt $i:item) => {};
+ ($t:tt $m:meta) => {};
+}
+// FOLLOW(item) = any token
+macro_rules! follow_item {
+ ($i:item ()) => {};
+ ($i:item []) => {};
+ ($i:item {}) => {};
+ ($i:item ,) => {};
+ ($i:item =>) => {};
+ ($i:item :) => {};
+ ($i:item =) => {};
+ ($i:item >) => {};
+ ($i:item ;) => {};
+ ($i:item |) => {};
+ ($i:item +) => {};
+ ($i:item ident) => {};
+ ($i:item $p:pat) => {};
+ ($i:item $e:expr) => {};
+ ($i:item $t:ty) => {};
+ ($i:item $s:stmt) => {};
+ ($i:item $p:path) => {};
+ ($i:item $b:block) => {};
+ ($i:item $j:ident) => {};
+ ($i:item $t:tt) => {};
+ ($i:item $j:item) => {};
+ ($i:item $m:meta) => {};
+}
+// FOLLOW(meta) = any token
+macro_rules! follow_meta {
+ ($m:meta ()) => {};
+ ($m:meta []) => {};
+ ($m:meta {}) => {};
+ ($m:meta ,) => {};
+ ($m:meta =>) => {};
+ ($m:meta :) => {};
+ ($m:meta =) => {};
+ ($m:meta >) => {};
+ ($m:meta ;) => {};
+ ($m:meta |) => {};
+ ($m:meta +) => {};
+ ($m:meta ident) => {};
+ ($m:meta $p:pat) => {};
+ ($m:meta $e:expr) => {};
+ ($m:meta $t:ty) => {};
+ ($m:meta $s:stmt) => {};
+ ($m:meta $p:path) => {};
+ ($m:meta $b:block) => {};
+ ($m:meta $i:ident) => {};
+ ($m:meta $t:tt) => {};
+ ($m:meta $i:item) => {};
+ ($m:meta $n:meta) => {};
+}
+
+fn main() {}
--- /dev/null
+// run-pass
+// aux-build:unstable-macros.rs
+
+#![feature(unstable_macros, local_unstable)]
+
+#[macro_use] extern crate unstable_macros;
+
+#[unstable(feature = "local_unstable", issue = "0")]
+macro_rules! local_unstable { () => () }
+
+fn main() {
+ unstable_macro!();
+ local_unstable!();
+}
--- /dev/null
+// run-pass
+// ignore-wasm32
+
+#![feature(decl_macro, macros_in_extern)]
+
+macro_rules! returns_isize(
+ ($ident:ident) => (
+ fn $ident() -> isize;
+ )
+);
+
+macro takes_u32_returns_u32($ident:ident) {
+ fn $ident (arg: u32) -> u32;
+}
+
+macro_rules! emits_nothing(
+ () => ()
+);
+
+fn main() {
+ assert_eq!(unsafe { rust_get_test_int() }, 1isize);
+ assert_eq!(unsafe { rust_dbg_extern_identity_u32(0xDEADBEEF) }, 0xDEADBEEFu32);
+}
+
+#[link(name = "rust_test_helpers", kind = "static")]
+extern {
+ returns_isize!(rust_get_test_int);
+ takes_u32_returns_u32!(rust_dbg_extern_identity_u32);
+ emits_nothing!();
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+// pretty-expanded FIXME #23616
+
+pub mod test2 {
+ // This used to generate an ICE (make sure that default functions are
+ // parented to their trait to find the first private thing as the trait).
+
+ struct B;
+ trait A { fn foo(&self) {} }
+ impl A for B {}
+
+ mod tests {
+ use super::A;
+ fn foo() {
+ let a = super::B;
+ a.foo();
+ }
+ }
+}
+
+
+pub fn main() {}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+#![allow(non_camel_case_types)]
+
+// pretty-expanded FIXME #23616
+
+struct cat {
+ meows : usize,
+
+ how_hungry : isize,
+}
+
+impl cat {
+ pub fn play(&mut self) {
+ self.meows += 1_usize;
+ self.nap();
+ }
+}
+
+impl cat {
+ fn nap(&mut self) { for _ in 1_usize..10_usize { } }
+}
+
+fn cat(in_x : usize, in_y : isize) -> cat {
+ cat {
+ meows: in_x,
+ how_hungry: in_y
+ }
+}
+
+pub fn main() {
+ let mut nyan : cat = cat(52_usize, 99);
+ nyan.play();
+}
--- /dev/null
+// run-pass
+// aux-build:attr-stmt-expr-rpass.rs
+
+#![feature(stmt_expr_attributes, proc_macro_hygiene)]
+
+extern crate attr_stmt_expr_rpass as attr_stmt_expr;
+use attr_stmt_expr::{expect_let, expect_print_stmt, expect_expr, expect_print_expr,
+ no_output, noop};
+
+fn print_str(string: &'static str) {
+ // macros are handled a bit differently
+ #[expect_print_expr]
+ println!("{}", string)
+}
+
+fn main() {
+ #[expect_let]
+ let string = "Hello, world!";
+
+ #[expect_print_stmt]
+ println!("{}", string);
+
+ let _: () = {
+ #[no_output]
+ "Hello, world!"
+ };
+
+ let _: &'static str = #[noop] "Hello, world!";
+
+ let _: &'static str = {
+ #[noop] "Hello, world!"
+ };
+
+ #[expect_expr]
+ print_str("string")
+}
--- /dev/null
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::TokenStream;
+
+#[proc_macro_attribute]
+pub fn expect_let(attr: TokenStream, item: TokenStream) -> TokenStream {
+ assert!(attr.to_string().is_empty());
+ assert_eq!(item.to_string(), "let string = \"Hello, world!\";");
+ item
+}
+
+#[proc_macro_attribute]
+pub fn expect_print_stmt(attr: TokenStream, item: TokenStream) -> TokenStream {
+ assert!(attr.to_string().is_empty());
+ assert_eq!(item.to_string(), "println!(\"{}\" , string);");
+ item
+}
+
+#[proc_macro_attribute]
+pub fn expect_expr(attr: TokenStream, item: TokenStream) -> TokenStream {
+ assert!(attr.to_string().is_empty());
+ assert_eq!(item.to_string(), "print_str(\"string\")");
+ item
+}
+
+#[proc_macro_attribute]
+pub fn expect_print_expr(attr: TokenStream, item: TokenStream) -> TokenStream {
+ assert!(attr.to_string().is_empty());
+ assert_eq!(item.to_string(), "println!(\"{}\" , string)");
+ item
+}
+
+#[proc_macro_attribute]
+pub fn no_output(attr: TokenStream, item: TokenStream) -> TokenStream {
+ assert!(attr.to_string().is_empty());
+ assert!(!item.to_string().is_empty());
+ "".parse().unwrap()
+
+}
+
+#[proc_macro_attribute]
+pub fn noop(attr: TokenStream, item: TokenStream) -> TokenStream {
+ assert!(attr.to_string().is_empty());
+ assert!(!item.to_string().is_empty());
+ item
+}
--- /dev/null
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::*;
+
+#[proc_macro]
+pub fn lifetimes_bang(input: TokenStream) -> TokenStream {
+ // Roundtrip through token trees
+ input.into_iter().collect()
+}
+
+#[proc_macro_attribute]
+pub fn lifetimes_attr(_: TokenStream, input: TokenStream) -> TokenStream {
+ // Roundtrip through AST
+ input
+}
+
+#[proc_macro_derive(Lifetimes)]
+pub fn lifetimes_derive(input: TokenStream) -> TokenStream {
+ // Roundtrip through a string
+ format!("mod m {{ {} }}", input).parse().unwrap()
+}
--- /dev/null
+// force-host
+// no-prefer-dynamic
+
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::TokenStream;
+
+#[proc_macro_attribute]
+pub fn nop_attr(_attr: TokenStream, input: TokenStream) -> TokenStream {
+ assert!(_attr.to_string().is_empty());
+ input
+}
+
+#[proc_macro_attribute]
+pub fn no_output(_attr: TokenStream, _input: TokenStream) -> TokenStream {
+ assert!(_attr.to_string().is_empty());
+ assert!(!_input.to_string().is_empty());
+ "".parse().unwrap()
+}
+
+#[proc_macro]
+pub fn emit_input(input: TokenStream) -> TokenStream {
+ input
+}
--- /dev/null
+// run-pass
+
+#![allow(unused_variables)]
+// aux-build:lifetimes-rpass.rs
+
+extern crate lifetimes_rpass as lifetimes;
+use lifetimes::*;
+
+lifetimes_bang! {
+ fn bang<'a>() -> &'a u8 { &0 }
+}
+
+#[lifetimes_attr]
+fn attr<'a>() -> &'a u8 { &1 }
+
+#[derive(Lifetimes)]
+pub struct Lifetimes<'a> {
+ pub field: &'a u8,
+}
+
+fn main() {
+ assert_eq!(bang::<'static>(), &0);
+ assert_eq!(attr::<'static>(), &1);
+ let l1 = Lifetimes { field: &0 };
+ let l2 = m::Lifetimes { field: &1 };
+}
--- /dev/null
+// run-pass
+// aux-build:test-macros-rpass.rs
+// ignore-wasm32
+
+#![feature(macros_in_extern)]
+
+extern crate test_macros_rpass as test_macros;
+
+use test_macros::{nop_attr, no_output, emit_input};
+
+fn main() {
+ assert_eq!(unsafe { rust_get_test_int() }, 1isize);
+ assert_eq!(unsafe { rust_dbg_extern_identity_u32(0xDEADBEEF) }, 0xDEADBEEF);
+}
+
+#[link(name = "rust_test_helpers", kind = "static")]
+extern {
+ #[no_output]
+ fn some_definitely_unknown_symbol_which_should_be_removed();
+
+ #[nop_attr]
+ fn rust_get_test_int() -> isize;
+
+ emit_input!(fn rust_dbg_extern_identity_u32(arg: u32) -> u32;);
+}
--- /dev/null
+// run-pass
+
+#![allow(unused_variables)]
+// Test coercions between pointers which don't do anything fancy like unsizing.
+
+// pretty-expanded FIXME #23616
+
+pub fn main() {
+ // &mut -> &
+ let x: &mut isize = &mut 42;
+ let x: &isize = x;
+
+ let x: &isize = &mut 42;
+
+ // & -> *const
+ let x: &isize = &42;
+ let x: *const isize = x;
+
+ let x: *const isize = &42;
+
+ // &mut -> *const
+ let x: &mut isize = &mut 42;
+ let x: *const isize = x;
+
+ let x: *const isize = &mut 42;
+
+ // *mut -> *const
+ let x: *mut isize = &mut 42;
+ let x: *const isize = x;
+}
--- /dev/null
+// run-pass
+fn invariant_id<'a,'b>(t: &'b mut &'static ()) -> &'b mut &'a ()
+ where 'a: 'static { t }
+fn static_id<'a>(t: &'a ()) -> &'static ()
+ where 'a: 'static { t }
+fn static_id_indirect<'a,'b>(t: &'a ()) -> &'static ()
+ where 'a: 'b, 'b: 'static { t }
+fn ref_id<'a>(t: &'a ()) -> &'a () where 'static: 'a { t }
+
+static UNIT: () = ();
+
+fn main()
+{
+ let mut val : &'static () = &UNIT;
+ invariant_id(&mut val);
+ static_id(val);
+ static_id_indirect(val);
+ ref_id(val);
+}
--- /dev/null
+// run-pass
+// Test that using rlibs and rmeta dep crates work together. Specifically, that
+// there can be both an rmeta and an rlib file and rustc will prefer the rlib.
+
+// aux-build:rmeta-rmeta.rs
+// aux-build:rmeta-rlib-rpass.rs
+
+extern crate rmeta_aux;
+use rmeta_aux::Foo;
+
+pub fn main() {
+ let _ = Foo { field: 42 };
+}
--- /dev/null
+Tests that specialization is working correctly:
+
+- Dispatch
+ - [On methods](specialization-basics.rs), includes:
+ - Specialization via adding a trait bound
+ - Including both remote and local traits
+ - Specialization via pure structure (e.g. `(T, U)` vs `(T, T)`)
+ - Specialization via concrete types vs unknown types
+ - In top level of the trait reference
+ - Embedded within another type (`Vec<T>` vs `Vec<i32>`)
+ - [Specialization based on super trait relationships](specialization-super-traits.rs)
+ - [On assoc fns](specialization-assoc-fns.rs)
+ - [Ensure that impl order doesn't matter](specialization-out-of-order.rs)
+
+- Item inheritance
+ - [Correct default cascading for methods](specialization-default-methods.rs)
+ - Inheritance works across impls with varying generics
+ - [With projections](specialization-translate-projections.rs)
+ - [With projections that involve input types](specialization-translate-projections-with-params.rs)
+
+- Normalization issues
+ - [Non-default assoc types can be projected](specialization-projection.rs)
+ - Including non-specialized cases
+ - Including specialized cases
+ - [Specialized Impls can happen on projections](specialization-on-projection.rs)
+ - [Projections and aliases play well together](specialization-projection-alias.rs)
+ - [Projections involving specialization allowed in the trait ref for impls, and overlap can still be determined](specialization-overlap-projection.rs)
+ - Only works for the simple case where the most specialized impl directly
+ provides a non-`default` associated type
+
+- Across crates
+ - [For traits defined in upstream crate](specialization-allowed-cross-crate.rs)
+ - [Full method dispatch tests, drawing from upstream crate](specialization-cross-crate.rs)
+ - Including *additional* local specializations
+ - [Full method dispatch tests, *without* turning on specialization in local crate](specialization-cross-crate-no-gate.rs)
+ - [Test that defaults cascade correctly from upstream crates](specialization-cross-crate-defaults.rs)
+ - Including *additional* local use of defaults
--- /dev/null
+// run-pass
+
+// Tests that we can combine a default impl that supplies one method with a
+// full impl that supplies the other, and they can invoke one another.
+
+#![feature(specialization)]
+
+trait Foo {
+ fn foo_one(&self) -> &'static str;
+ fn foo_two(&self) -> &'static str;
+ fn foo_three(&self) -> &'static str;
+}
+
+struct MyStruct;
+
+default impl<T> Foo for T {
+ fn foo_one(&self) -> &'static str {
+ self.foo_three()
+ }
+}
+
+impl Foo for MyStruct {
+ fn foo_two(&self) -> &'static str {
+ self.foo_one()
+ }
+
+ fn foo_three(&self) -> &'static str {
+ "generic"
+ }
+}
+
+fn main() {
+ assert!(MyStruct.foo_two() == "generic");
+}
--- /dev/null
+// run-pass
+
+#![deny(unknown_lints)]
+
+#[allow(clippy::almost_swapped)]
+fn main() {}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+#![allow(unused_variables)]
+// pretty-expanded FIXME #23616
+
+trait U {}
+trait T<X: U> { fn get(self) -> X; }
+
+trait S2<Y: U> {
+ fn m(x: Box<dyn T<Y>+'static>) {}
+}
+
+struct St<X: U> {
+ f: Box<dyn T<X>+'static>,
+}
+
+impl<X: U> St<X> {
+ fn blah() {}
+}
+
+fn main() {}
--- /dev/null
+// run-pass
+#![allow(unused_variables)]
+#![feature(optin_builtin_traits)]
+
+use std::marker::Send;
+
+pub struct WaitToken;
+impl !Send for WaitToken {}
+
+pub struct Test<T>(T);
+unsafe impl<T: 'static> Send for Test<T> {}
+
+pub fn spawn<F>(_: F) -> () where F: FnOnce(), F: Send + 'static {}
+
+fn main() {
+ let wt = Test(WaitToken);
+ spawn(move || {
+ let x = wt;
+ println!("Hello, World!");
+ });
+}
--- /dev/null
+// run-pass
+// Test that all coercions can actually be done using casts (modulo the lints).
+
+#![allow(trivial_casts, trivial_numeric_casts)]
+
+trait Foo {
+ fn foo(&self) {}
+}
+
+pub struct Bar;
+
+impl Foo for Bar {}
+
+pub fn main() {
+ // Numeric
+ let _ = 42_i32 as i32;
+ let _ = 42_u8 as u8;
+
+ // & to * pointers
+ let x: &u32 = &42;
+ let _ = x as *const u32;
+
+ let x: &mut u32 = &mut 42;
+ let _ = x as *mut u32;
+
+ // unsize array
+ let x: &[u32; 3] = &[42, 43, 44];
+ let _ = x as &[u32];
+ let _ = x as *const [u32];
+
+ let x: &mut [u32; 3] = &mut [42, 43, 44];
+ let _ = x as &mut [u32];
+ let _ = x as *mut [u32];
+
+ let x: Box<[u32; 3]> = Box::new([42, 43, 44]);
+ let _ = x as Box<[u32]>;
+
+ // unsize trait
+ let x: &Bar = &Bar;
+ let _ = x as &dyn Foo;
+ let _ = x as *const dyn Foo;
+
+ let x: &mut Bar = &mut Bar;
+ let _ = x as &mut dyn Foo;
+ let _ = x as *mut dyn Foo;
+
+ let x: Box<Bar> = Box::new(Bar);
+ let _ = x as Box<dyn Foo>;
+
+ // functions
+ fn baz(_x: i32) {}
+ let _ = &baz as &dyn Fn(i32);
+ let x = |_x: i32| {};
+ let _ = &x as &dyn Fn(i32);
+}
+
+// subtyping
+pub fn test_subtyping<'a, 'b: 'a>(a: &'a Bar, b: &'b Bar) {
+ let _ = a as &'a Bar;
+ let _ = b as &'a Bar;
+ let _ = b as &'b Bar;
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+#![allow(unused_variables)]
+#![allow(unions_with_drop_fields)]
+
+// Some traits can be derived for unions.
+
+#![feature(untagged_unions)]
+
+#[derive(
+ Copy,
+ Clone,
+ Eq,
+)]
+union U {
+ a: u8,
+ b: u16,
+}
+
+impl PartialEq for U { fn eq(&self, rhs: &Self) -> bool { true } }
+
+#[derive(
+ Clone,
+ Copy,
+ Eq
+)]
+union W<T> {
+ a: T,
+}
+
+impl<T> PartialEq for W<T> { fn eq(&self, rhs: &Self) -> bool { true } }
+
+fn main() {
+ let u = U { b: 0 };
+ let u1 = u;
+ let u2 = u.clone();
+ assert!(u1 == u2);
+
+ let w = W { a: 0 };
+ let w1 = w.clone();
+ assert!(w == w1);
+}
--- /dev/null
+// run-pass
+#![allow(dead_code)]
+#![allow(unions_with_drop_fields)]
+
+#![feature(untagged_unions)]
+
+union MaybeItem<T: Iterator> {
+ elem: T::Item,
+ none: (),
+}
+
+union U<A, B> {
+ a: A,
+ b: B,
+}
+
+unsafe fn union_transmute<A, B>(a: A) -> B {
+ U { a: a }.b
+}
+
+fn main() {
+ unsafe {
+ let u = U::<String, Vec<u8>> { a: String::from("abcd") };
+
+ assert_eq!(u.b.len(), 4);
+ assert_eq!(u.b[0], b'a');
+
+ let b = union_transmute::<(u8, u8), u16>((1, 1));
+ assert_eq!(b, (1 << 8) + 1);
+
+ let v: Vec<u8> = vec![1, 2, 3];
+ let mut i = v.iter();
+ i.next();
+ let mi = MaybeItem::<std::slice::Iter<_>> { elem: i.next().unwrap() };
+ assert_eq!(*mi.elem, 2);
+ }
+}
--- /dev/null
+// run-pass
+
+#![feature(untagged_unions)]
+#![allow(dead_code)]
+#![allow(unions_with_drop_fields)]
+
+union U {
+ a: u8, // OK
+}
+
+union W {
+ a: String, // OK
+ b: String, // OK
+}
+
+struct S(String);
+
+// `S` doesn't implement `Drop` trait, but still has non-trivial destructor
+union Y {
+ a: S, // OK
+}
+
+// We don't know if `T` is trivially-destructable or not until trans
+union J<T> {
+ a: T, // OK
+}
+
+union H<T: Copy> {
+ a: T, // OK
+}
+
+fn main() {}
--- /dev/null
+// run-pass
+
+#![feature(unsized_locals)]
+
+pub trait Foo {
+ fn foo(self) -> String;
+}
+
+struct A;
+
+impl Foo for A {
+ fn foo(self) -> String {
+ format!("hello")
+ }
+}
+
+
+fn main() {
+ let x = *(Box::new(A) as Box<dyn Foo>);
+ assert_eq!(x.foo(), format!("hello"));
+
+ // I'm not sure whether we want this to work
+ let x = Box::new(A) as Box<dyn Foo>;
+ assert_eq!(x.foo(), format!("hello"));
+}
--- /dev/null
+// run-pass
+
+#![feature(unsized_tuple_coercion, unsized_locals)]
+
+struct A<X: ?Sized>(X);
+
+fn udrop<T: ?Sized>(_x: T) {}
+fn foo() -> Box<[u8]> {
+ Box::new(*b"foo")
+}
+fn tfoo() -> Box<(i32, [u8])> {
+ Box::new((42, *b"foo"))
+}
+fn afoo() -> Box<A<[u8]>> {
+ Box::new(A(*b"foo"))
+}
+
+impl std::ops::Add<i32> for A<[u8]> {
+ type Output = ();
+ fn add(self, _rhs: i32) -> Self::Output {}
+}
+
+fn main() {
+ udrop::<[u8]>(loop {
+ break *foo();
+ });
+ udrop::<[u8]>(if true {
+ *foo()
+ } else {
+ *foo()
+ });
+ udrop::<[u8]>({*foo()});
+ #[allow(unused_parens)]
+ udrop::<[u8]>((*foo()));
+ udrop::<[u8]>((*tfoo()).1);
+ *afoo() + 42;
+ udrop as fn([u8]);
+}
--- /dev/null
+// run-pass
+// Test structs with always-unsized fields.
+
+
+#![allow(warnings)]
+#![feature(box_syntax, unsize, raw)]
+
+use std::mem;
+use std::raw;
+use std::slice;
+
+struct Foo<T> {
+ f: [T],
+}
+
+struct Bar {
+ f1: usize,
+ f2: [usize],
+}
+
+struct Baz {
+ f1: usize,
+ f2: str,
+}
+
+trait Tr {
+ fn foo(&self) -> usize;
+}
+
+struct St {
+ f: usize
+}
+
+impl Tr for St {
+ fn foo(&self) -> usize {
+ self.f
+ }
+}
+
+struct Qux<'a> {
+ f: Tr+'a
+}
+
+pub fn main() {
+ let _: &Foo<f64>;
+ let _: &Bar;
+ let _: &Baz;
+
+ let _: Box<Foo<i32>>;
+ let _: Box<Bar>;
+ let _: Box<Baz>;
+
+ let _ = mem::size_of::<Box<Foo<u8>>>();
+ let _ = mem::size_of::<Box<Bar>>();
+ let _ = mem::size_of::<Box<Baz>>();
+
+ unsafe {
+ struct Foo_<T> {
+ f: [T; 3]
+ }
+
+ let data: Box<Foo_<i32>> = box Foo_{f: [1, 2, 3] };
+ let x: &Foo<i32> = mem::transmute(slice::from_raw_parts(&*data, 3));
+ assert_eq!(x.f.len(), 3);
+ assert_eq!(x.f[0], 1);
+
+ struct Baz_ {
+ f1: usize,
+ f2: [u8; 5],
+ }
+
+ let data: Box<_> = box Baz_ {
+ f1: 42, f2: ['a' as u8, 'b' as u8, 'c' as u8, 'd' as u8, 'e' as u8] };
+ let x: &Baz = mem::transmute(slice::from_raw_parts(&*data, 5));
+ assert_eq!(x.f1, 42);
+ let chs: Vec<char> = x.f2.chars().collect();
+ assert_eq!(chs.len(), 5);
+ assert_eq!(chs[0], 'a');
+ assert_eq!(chs[1], 'b');
+ assert_eq!(chs[2], 'c');
+ assert_eq!(chs[3], 'd');
+ assert_eq!(chs[4], 'e');
+
+ struct Qux_ {
+ f: St
+ }
+
+ let obj: Box<St> = box St { f: 42 };
+ let obj: &Tr = &*obj;
+ let obj: raw::TraitObject = mem::transmute(&*obj);
+ let data: Box<_> = box Qux_{ f: St { f: 234 } };
+ let x: &Qux = mem::transmute(raw::TraitObject { vtable: obj.vtable,
+ data: mem::transmute(&*data) });
+ assert_eq!(x.f.foo(), 234);
+ }
+}
--- /dev/null
+// run-pass
+//
+#![allow(non_snake_case)]
+
+#![feature(non_ascii_idents)]
+
+pub fn main() {
+ let ε = 0.00001f64;
+ let Π = 3.14f64;
+ let लंच = Π * Π + 1.54;
+ assert!(((लंच - 1.54) - (Π * Π)).abs() < ε);
+ assert_eq!(საჭმელად_გემრიელი_სადილი(), 0);
+}
+
+fn საჭმელად_გემრიელი_სადილი() -> isize {
+
+ // Lunch in several languages.
+
+ let ランチ = 10;
+ let 午餐 = 10;
+
+ let ארוחת_צהריי = 10;
+ let غداء = 10_usize;
+ let լանչ = 10;
+ let обед = 10;
+ let абед = 10;
+ let μεσημεριανό = 10;
+ let hádegismatur = 10;
+ let ручек = 10;
+
+ let ăn_trưa = 10;
+ let อาหารกลางวัน = 10;
+
+ // Lunchy arithmetic, mm.
+
+ assert_eq!(hádegismatur * ручек * обед, 1000);
+ assert_eq!(10, ארוחת_צהריי);
+ assert_eq!(ランチ + 午餐 + μεσημεριανό, 30);
+ assert_eq!(ăn_trưa + อาหารกลางวัน, 20);
+ return (абед + լանչ) >> غداء;
+}
--- /dev/null
+// run-pass
+#![allow(unused_variables)]
+// pretty-expanded FIXME #23616
+
+trait Foo<T> { fn dummy(&self, arg: T) { } }
+
+trait Bar<A> {
+ fn method<B>(&self) where A: Foo<B>;
+}
+
+struct S;
+struct X;
+
+impl Foo<S> for X {}
+
+impl Bar<X> for i32 {
+ fn method<U>(&self) where X: Foo<U> {
+ }
+}
+
+fn main() {
+ 1.method::<S>();
+}