summary refs log tree commit diff
path: root/src/test/ui/lint/suggestions.rs
blob: e35675eacd835cc88f1d7f7e7e25165ec751f7c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// 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.

// ignore-tidy-tab

#![warn(unused_mut, unused_parens)] // UI tests pass `-A unused`—see Issue #43896
#![feature(no_debug)]

#[no_mangle] static SHENZHOU: usize = 1; // should suggest `pub`
//~^ WARN static is marked #[no_mangle]
#[no_mangle] const DISCOVERY: usize = 1; // should suggest `pub static` rather than `const`
//~^ ERROR const items should never be #[no_mangle]

#[no_mangle] // should suggest removal (generics can't be no-mangle)
pub fn defiant<T>(_t: T) {}
//~^ WARN functions generic over types must be mangled

#[no_mangle]
fn rio_grande() {} // should suggest `pub`
//~^ WARN function is marked

mod badlands {
    // The private-no-mangle lints shouldn't suggest inserting `pub` when the
    // item is already `pub` (but triggered the lint because, e.g., it's in a
    // private module). (Issue #47383)
    #[no_mangle] pub static DAUNTLESS: bool = true;
    //~^ WARN static is marked
    #[no_mangle] pub fn val_jean() {}
    //~^ WARN function is marked
}

struct Equinox {
    warp_factor: f32,
}

#[no_debug] // should suggest removal of deprecated attribute
//~^ WARN deprecated
fn main() {
    while true { // should suggest `loop`
    //~^ WARN denote infinite loops
        let mut a = (1); // should suggest no `mut`, no parens
        //~^ WARN does not need to be mutable
        //~| WARN unnecessary parentheses
        // the line after `mut` has a `\t` at the beginning, this is on purpose
        let mut
	        b = 1;
        //~^^ WARN does not need to be mutable
        let d = Equinox { warp_factor: 9.975 };
        match d {
            Equinox { warp_factor: warp_factor } => {} // should suggest shorthand
            //~^ WARN this pattern is redundant
        }
        println!("{} {}", a, b);
    }
}