2018-10-06 16:18:06 +00:00
|
|
|
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2018-05-11 11:20:39 +00:00
|
|
|
#![feature(box_syntax)]
|
2018-10-27 17:31:47 +00:00
|
|
|
#![warn(clippy::no_effect)]
|
2015-10-28 16:50:00 +00:00
|
|
|
#![allow(dead_code)]
|
|
|
|
#![allow(path_statements)]
|
2018-07-28 15:34:52 +00:00
|
|
|
#![allow(clippy::deref_addrof)]
|
|
|
|
#![allow(clippy::redundant_field_names)]
|
2016-09-04 15:39:48 +00:00
|
|
|
#![feature(untagged_unions)]
|
2015-10-28 16:50:00 +00:00
|
|
|
|
|
|
|
struct Unit;
|
|
|
|
struct Tuple(i32);
|
|
|
|
struct Struct {
|
2018-12-09 22:26:16 +00:00
|
|
|
field: i32,
|
2015-10-28 16:50:00 +00:00
|
|
|
}
|
|
|
|
enum Enum {
|
2016-02-01 11:51:33 +00:00
|
|
|
Tuple(i32),
|
|
|
|
Struct { field: i32 },
|
2015-10-28 16:50:00 +00:00
|
|
|
}
|
2017-09-18 19:07:33 +00:00
|
|
|
struct DropUnit;
|
|
|
|
impl Drop for DropUnit {
|
|
|
|
fn drop(&mut self) {}
|
|
|
|
}
|
|
|
|
struct DropStruct {
|
2018-12-09 22:26:16 +00:00
|
|
|
field: i32,
|
2017-09-18 19:07:33 +00:00
|
|
|
}
|
|
|
|
impl Drop for DropStruct {
|
|
|
|
fn drop(&mut self) {}
|
|
|
|
}
|
|
|
|
struct DropTuple(i32);
|
|
|
|
impl Drop for DropTuple {
|
|
|
|
fn drop(&mut self) {}
|
|
|
|
}
|
|
|
|
enum DropEnum {
|
|
|
|
Tuple(i32),
|
|
|
|
Struct { field: i32 },
|
|
|
|
}
|
|
|
|
impl Drop for DropEnum {
|
|
|
|
fn drop(&mut self) {}
|
|
|
|
}
|
2017-10-07 22:32:09 +00:00
|
|
|
struct FooString {
|
|
|
|
s: String,
|
|
|
|
}
|
2016-08-28 17:43:55 +00:00
|
|
|
union Union {
|
|
|
|
a: u8,
|
|
|
|
b: f64,
|
|
|
|
}
|
|
|
|
|
2018-12-09 22:26:16 +00:00
|
|
|
fn get_number() -> i32 {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
fn get_struct() -> Struct {
|
|
|
|
Struct { field: 0 }
|
|
|
|
}
|
|
|
|
fn get_drop_struct() -> DropStruct {
|
|
|
|
DropStruct { field: 0 }
|
|
|
|
}
|
2015-10-28 16:50:00 +00:00
|
|
|
|
2018-12-09 22:26:16 +00:00
|
|
|
unsafe fn unsafe_fn() -> i32 {
|
|
|
|
0
|
|
|
|
}
|
2016-05-25 16:51:35 +00:00
|
|
|
|
2018-12-29 14:14:04 +00:00
|
|
|
struct A(i32);
|
|
|
|
struct B {
|
|
|
|
field: i32,
|
|
|
|
}
|
|
|
|
struct C {
|
|
|
|
b: B,
|
|
|
|
}
|
2018-12-29 14:34:15 +00:00
|
|
|
struct D {
|
|
|
|
arr: [i32; 1],
|
|
|
|
}
|
2018-12-29 14:14:04 +00:00
|
|
|
const A_CONST: A = A(1);
|
|
|
|
const B: B = B { field: 1 };
|
|
|
|
const C: C = C { b: B { field: 1 } };
|
2018-12-29 14:34:15 +00:00
|
|
|
const D: D = D { arr: [1] };
|
2018-12-29 14:14:04 +00:00
|
|
|
|
2015-10-28 16:50:00 +00:00
|
|
|
fn main() {
|
|
|
|
let s = get_struct();
|
2016-02-11 12:50:41 +00:00
|
|
|
let s2 = get_struct();
|
2015-10-28 16:50:00 +00:00
|
|
|
|
2017-02-08 13:58:07 +00:00
|
|
|
0;
|
|
|
|
s2;
|
|
|
|
Unit;
|
|
|
|
Tuple(0);
|
|
|
|
Struct { field: 0 };
|
|
|
|
Struct { ..s };
|
|
|
|
Union { a: 0 };
|
|
|
|
Enum::Tuple(0);
|
|
|
|
Enum::Struct { field: 0 };
|
|
|
|
5 + 6;
|
|
|
|
*&42;
|
|
|
|
&6;
|
|
|
|
(5, 6, 7);
|
|
|
|
box 42;
|
|
|
|
..;
|
|
|
|
5..;
|
|
|
|
..5;
|
|
|
|
5..6;
|
2017-09-28 17:40:19 +00:00
|
|
|
5..=6;
|
2017-02-08 13:58:07 +00:00
|
|
|
[42, 55];
|
|
|
|
[42, 55][1];
|
|
|
|
(42, 55).1;
|
|
|
|
[42; 55];
|
|
|
|
[42; 55][13];
|
2016-02-11 12:50:41 +00:00
|
|
|
let mut x = 0;
|
2017-02-08 13:58:07 +00:00
|
|
|
|| x += 5;
|
2017-10-07 22:32:09 +00:00
|
|
|
let s: String = "foo".into();
|
|
|
|
FooString { s: s };
|
2018-12-29 14:14:04 +00:00
|
|
|
A_CONST.0 = 2;
|
|
|
|
B.field = 2;
|
|
|
|
C.b.field = 2;
|
2018-12-29 14:34:15 +00:00
|
|
|
D.arr[0] = 2;
|
2015-10-28 16:50:00 +00:00
|
|
|
|
|
|
|
// Do not warn
|
|
|
|
get_number();
|
2016-05-25 16:51:35 +00:00
|
|
|
unsafe { unsafe_fn() };
|
2017-09-18 19:07:33 +00:00
|
|
|
DropUnit;
|
|
|
|
DropStruct { field: 0 };
|
|
|
|
DropTuple(0);
|
|
|
|
DropEnum::Tuple(0);
|
|
|
|
DropEnum::Struct { field: 0 };
|
2018-12-29 14:14:04 +00:00
|
|
|
let mut a_mut = A(1);
|
|
|
|
a_mut.0 = 2;
|
|
|
|
let mut b_mut = B { field: 1 };
|
|
|
|
b_mut.field = 2;
|
|
|
|
let mut c_mut = C { b: B { field: 1 } };
|
|
|
|
c_mut.b.field = 2;
|
2018-12-29 14:34:15 +00:00
|
|
|
let mut d_mut = D { arr: [1] };
|
|
|
|
d_mut.arr[0] = 2;
|
2015-10-28 16:50:00 +00:00
|
|
|
}
|