]> git.proxmox.com Git - rustc.git/blame - src/test/ui/lint/suggestions.rs
New upstream version 1.29.0+dfsg1
[rustc.git] / src / test / ui / lint / suggestions.rs
CommitLineData
8bb4bdeb 1// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
223e47cc
LB
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
2c00a5a8
XL
11// ignore-tidy-tab
12
abe05a73 13#![warn(unused_mut, unused_parens)] // UI tests pass `-A unused`—see Issue #43896
ea8adc8c 14#![feature(no_debug)]
3b2f2976 15
8faf50e0 16#[no_mangle] static SHENZHOU: usize = 1;
ff7c6d11 17//~^ WARN static is marked #[no_mangle]
8faf50e0
XL
18//~| HELP try making it public
19#[no_mangle] const DISCOVERY: usize = 1;
ff7c6d11 20//~^ ERROR const items should never be #[no_mangle]
8faf50e0 21//~| HELP try a static value
abe05a73 22
8faf50e0
XL
23#[no_mangle]
24//~^ HELP remove this attribute
abe05a73 25pub fn defiant<T>(_t: T) {}
ff7c6d11 26//~^ WARN functions generic over types must be mangled
abe05a73
XL
27
28#[no_mangle]
8faf50e0 29fn rio_grande() {}
ff7c6d11 30//~^ WARN function is marked
8faf50e0 31//~| HELP try making it public
abe05a73 32
2c00a5a8
XL
33mod badlands {
34 // The private-no-mangle lints shouldn't suggest inserting `pub` when the
35 // item is already `pub` (but triggered the lint because, e.g., it's in a
36 // private module). (Issue #47383)
37 #[no_mangle] pub static DAUNTLESS: bool = true;
38 //~^ WARN static is marked
8faf50e0 39 //~| HELP try exporting the item with a `pub use` statement
2c00a5a8
XL
40 #[no_mangle] pub fn val_jean() {}
41 //~^ WARN function is marked
8faf50e0
XL
42 //~| HELP try exporting the item with a `pub use` statement
43
44 // ... but we can suggest just-`pub` instead of restricted
45 #[no_mangle] pub(crate) static VETAR: bool = true;
46 //~^ WARN static is marked
47 //~| HELP try making it public
48 #[no_mangle] pub(crate) fn crossfield() {}
49 //~^ WARN function is marked
50 //~| HELP try making it public
2c00a5a8
XL
51}
52
abe05a73
XL
53struct Equinox {
54 warp_factor: f32,
55}
56
ea8adc8c 57#[no_debug] // should suggest removal of deprecated attribute
ff7c6d11 58//~^ WARN deprecated
8faf50e0 59//~| HELP remove this attribute
7453a54e 60fn main() {
8faf50e0 61 while true {
ff7c6d11 62 //~^ WARN denote infinite loops
8faf50e0
XL
63 //~| HELP use `loop`
64 let mut a = (1);
ff7c6d11 65 //~^ WARN does not need to be mutable
8faf50e0 66 //~| HELP remove this `mut`
ff7c6d11 67 //~| WARN unnecessary parentheses
8faf50e0 68 //~| HELP remove these parentheses
2c00a5a8
XL
69 // the line after `mut` has a `\t` at the beginning, this is on purpose
70 let mut
71 b = 1;
72 //~^^ WARN does not need to be mutable
8faf50e0 73 //~| HELP remove this `mut`
abe05a73
XL
74 let d = Equinox { warp_factor: 9.975 };
75 match d {
8faf50e0 76 Equinox { warp_factor: warp_factor } => {}
ff7c6d11 77 //~^ WARN this pattern is redundant
8faf50e0 78 //~| HELP remove this
abe05a73 79 }
2c00a5a8 80 println!("{} {}", a, b);
ea8adc8c 81 }
223e47cc 82}