summaryrefslogtreecommitdiffstats
path: root/tests/ui/lint/lint-attr-everywhere-late.rs
blob: 1055157d6020c3442230139ed5d214a17cdd7bdf (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// Tests that lint levels can be set for late lints.
#![allow(
    non_snake_case,
    overflowing_literals,
    missing_docs,
    dyn_drop,
    enum_intrinsics_non_enums,
    clashing_extern_declarations
)]

extern crate core;
use core::mem::{Discriminant, discriminant};

// The following is a check of the lints used here to verify they do not warn
// when allowed.
pub fn missing_docs_allowed() {} // missing_docs
fn dyn_drop_allowed(_x: Box<dyn Drop>) {} // dyn_drop
fn verify_no_warnings() {
    discriminant::<i32>(&123); // enum_intrinsics_non_enums
    let x: u8 = 1000; // overflowing_literals
    let NON_SNAKE_CASE = 1; // non_snake_case
}
mod clashing_extern_allowed {
    extern "C" {
        fn extern_allowed();
    }
}
extern "C" {
    fn extern_allowed(_: i32); // clashing_extern_declarations
}

// ################## Types

#[deny(missing_docs)]
pub type MissingDocType = i32; //~ ERROR missing documentation for a type alias

// There aren't any late lints that I can find that can be easily used with types.
// type BareFnPtr = fn(#[deny()]i32);
// type BareFnPtrVariadic = extern "C" fn(i32, #[deny()]...);

// ################## Items
#[deny(missing_docs)]
pub struct ItemOuter; //~ ERROR missing documentation for a struct

pub mod module_inner { //~ ERROR missing documentation for a module
    #![deny(missing_docs)]
    pub fn missing_inner() {} //~ ERROR missing documentation for a function
}

pub struct Associated;
impl Associated {
    #![deny(missing_docs)]

    pub fn inherent_denied_from_inner() {} //~ ERROR missing documentation for an associated function
}

impl Associated {
    #[deny(missing_docs)]
    pub fn inherent_fn() {} //~ ERROR missing documentation for an associated function

    #[deny(missing_docs)]
    pub const INHERENT_CONST: i32 = 1; //~ ERROR missing documentation for an associated constant
}

pub trait TraitInner { //~ ERROR missing documentation for a trait
    #![deny(missing_docs)]
}

pub trait AssociatedTraitInner { //~ ERROR missing documentation for a trait
    #![deny(missing_docs)]

    fn denied_from_inner() {} //~ ERROR missing documentation for an associated function
}

pub trait AssociatedTrait {
    fn denied_from_inner(_x: Box<dyn Drop>) {} // Used below

    #[deny(missing_docs)]
    fn assoc_fn() {} //~ ERROR missing documentation for an associated function

    #[deny(missing_docs)]
    const ASSOC_CONST: u8 = 1; //~ ERROR missing documentation for an associated constant

    #[deny(missing_docs)]
    type AssocType; //~ ERROR missing documentation for an associated type
}

struct Foo;

impl AssociatedTrait for Associated {
    #![deny(dyn_drop)]

    fn denied_from_inner(_x: Box<dyn Drop>) {} //~ ERROR types that do not implement `Drop`

    #[deny(enum_intrinsics_non_enums)]
    fn assoc_fn() { discriminant::<i32>(&123); } //~ ERROR the return value of

    #[deny(overflowing_literals)] const ASSOC_CONST: u8 = 1000; //~ ERROR literal out of range
    type AssocType = i32;
}


// There aren't any late lints that can apply to a field that I can find.
// non_snake_case doesn't work on fields
// struct StructFields {
//     #[deny()]f1: i32,
// }
// struct StructTuple(#[deny()]i32);

pub enum Enum {
    #[deny(missing_docs)]
    Variant1, //~ ERROR missing documentation for a variant
}

mod clashing_extern {
    extern "C" {
        fn clashing1();
        fn clashing2();
    }
}
extern "C" {
    #![deny(clashing_extern_declarations)]
    fn clashing1(_: i32); //~ ERROR `clashing1` redeclared with a different signature
}

extern "C" {
    #[deny(clashing_extern_declarations)]
    fn clashing2(_: i32); //~ ERROR `clashing2` redeclared with a different signature
}

fn function(#[deny(non_snake_case)] PARAM: i32) {} //~ ERROR variable `PARAM` should have a snake case name
// There aren't any late lints that can apply to generics that I can find.
// fn generics<#[deny()]T>() {}


// ################## Statements
fn statements() {
    #[deny(enum_intrinsics_non_enums)]
    let _ = discriminant::<i32>(&123); //~ ERROR the return value of
}


// ################## Expressions
fn expressions() {
    let closure = |#[deny(non_snake_case)] PARAM: i32| {}; //~ ERROR variable `PARAM` should have a snake case name

    struct Match{f1: i32}
    // I can't find any late lints for patterns.
    // let f = Match{#[deny()]f1: 123};

    let f = Match{f1: 123};
    match f {
        #![deny(enum_intrinsics_non_enums)]
        Match{f1} => {
            discriminant::<i32>(&123); //~ ERROR the return value of
        }
    }
    match f {
        #[deny(enum_intrinsics_non_enums)]
        Match{f1} => {
            discriminant::<i32>(&123); //~ ERROR the return value of
        }
    }

    // Statement Block
    {
        #![deny(enum_intrinsics_non_enums)]
        discriminant::<i32>(&123); //~ ERROR the return value of
    }
    let block_tail = {
        #[deny(enum_intrinsics_non_enums)]
        discriminant::<i32>(&123); //~ ERROR the return value of
    };

    // Before expression as a statement.
    #[deny(enum_intrinsics_non_enums)]
    discriminant::<i32>(&123); //~ ERROR the return value of

    [#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123)]; //~ ERROR the return value of
    (#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123),); //~ ERROR the return value of
    fn call(p: Discriminant<i32>) {}
    call(#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123)); //~ ERROR the return value of
    struct TupleStruct(Discriminant<i32>);
    TupleStruct(#[deny(enum_intrinsics_non_enums)] discriminant::<i32>(&123)); //~ ERROR the return value of
}


// ################## Patterns
fn patterns() {
    // There aren't any late lints that I can find that apply to pattern fields.
    //
    // struct PatField{f1: i32, f2: i32};
    // let f = PatField{f1: 1, f2: 2};
    // let PatField{#[deny()]f1, #[deny()]..} = f;
}

fn main() {}