]> git.lizzy.rs Git - rust.git/blob - tests/ui/redundant_field_names.rs
rustfmt tests
[rust.git] / tests / ui / redundant_field_names.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #![warn(clippy::redundant_field_names)]
11 #![allow(unused_variables)]
12 #![feature(inclusive_range, inclusive_range_fields, inclusive_range_methods)]
13
14 #[macro_use]
15 extern crate derive_new;
16
17 use std::ops::{Range, RangeFrom, RangeInclusive, RangeTo, RangeToInclusive};
18
19 mod foo {
20     pub const BAR: u8 = 0;
21 }
22
23 struct Person {
24     gender: u8,
25     age: u8,
26     name: u8,
27     buzz: u64,
28     foo: u8,
29 }
30
31 #[derive(new)]
32 pub struct S {
33     v: String,
34 }
35
36 fn main() {
37     let gender: u8 = 42;
38     let age = 0;
39     let fizz: u64 = 0;
40     let name: u8 = 0;
41
42     let me = Person {
43         gender: gender,
44         age: age,
45
46         name,          //should be ok
47         buzz: fizz,    //should be ok
48         foo: foo::BAR, //should be ok
49     };
50
51     // Range expressions
52     let (start, end) = (0, 0);
53
54     let _ = start..;
55     let _ = ..end;
56     let _ = start..end;
57
58     let _ = ..=end;
59     let _ = start..=end;
60
61     // Issue #2799
62     let _: Vec<_> = (start..end).collect();
63
64     // hand-written Range family structs are linted
65     let _ = RangeFrom { start: start };
66     let _ = RangeTo { end: end };
67     let _ = Range { start: start, end: end };
68     let _ = RangeInclusive::new(start, end);
69     let _ = RangeToInclusive { end: end };
70 }