]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lint/suggestions.rs
Move parse-fail tests to UI
[rust.git] / src / test / ui / lint / suggestions.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // ignore-tidy-tab
12
13 #![warn(unused_mut, unused_parens)] // UI tests pass `-A unused`—see Issue #43896
14 #![feature(no_debug)]
15
16 #[no_mangle] const DISCOVERY: usize = 1;
17 //~^ ERROR const items should never be #[no_mangle]
18 //~| HELP try a static value
19
20 #[no_mangle]
21 //~^ HELP remove this attribute
22 pub fn defiant<T>(_t: T) {}
23 //~^ WARN functions generic over types must be mangled
24
25 #[no_mangle]
26 fn rio_grande() {}
27
28 mod badlands {
29     // The private-no-mangle lints shouldn't suggest inserting `pub` when the
30     // item is already `pub` (but triggered the lint because, e.g., it's in a
31     // private module). (Issue #47383)
32     #[no_mangle] pub const DAUNTLESS: bool = true;
33     //~^ ERROR const items should never be #[no_mangle]
34     //~| HELP try a static value
35     #[no_mangle] pub fn val_jean<T>() {}
36     //~^ WARN functions generic over types must be mangled
37     //~| HELP remove this attribute
38
39     // ... but we can suggest just-`pub` instead of restricted
40     #[no_mangle] pub(crate) const VETAR: bool = true;
41     //~^ ERROR const items should never be #[no_mangle]
42     //~| HELP try a static value
43     #[no_mangle] pub(crate) fn crossfield<T>() {}
44     //~^ WARN functions generic over types must be mangled
45     //~| HELP remove this attribute
46 }
47
48 struct Equinox {
49     warp_factor: f32,
50 }
51
52 #[no_debug] // should suggest removal of deprecated attribute
53 //~^ WARN deprecated
54 //~| HELP remove this attribute
55 fn main() {
56     while true {
57     //~^ WARN denote infinite loops
58     //~| HELP use `loop`
59         let mut a = (1);
60         //~^ WARN does not need to be mutable
61         //~| HELP remove this `mut`
62         //~| WARN unnecessary parentheses
63         //~| HELP remove these parentheses
64         // the line after `mut` has a `\t` at the beginning, this is on purpose
65         let mut
66                 b = 1;
67         //~^^ WARN does not need to be mutable
68         //~| HELP remove this `mut`
69         let d = Equinox { warp_factor: 9.975 };
70         match d {
71             Equinox { warp_factor: warp_factor } => {}
72             //~^ WARN this pattern is redundant
73             //~| HELP remove this
74         }
75         println!("{} {}", a, b);
76     }
77 }