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
|
// Tests that lint levels can be set for early lints.
#![allow(non_camel_case_types, unsafe_code, while_true, unused_parens)]
// The following is a check of the lints used here to verify they do not warn
// when allowed.
fn verify_no_warnings() {
type non_camel_type = i32; // non_camel_case_types
struct NON_CAMEL_IS_ALLOWED; // non_camel_case_types
unsafe {} // unsafe_code
enum Enum {
VARIANT_CAMEL // non_camel_case_types
}
fn generics<foo>() {} // non_camel_case_types
while true {} // while_true
type T = (i32); // unused_parens
}
// ################## Types
#[deny(non_camel_case_types)]
type type_outer = i32; //~ ERROR type `type_outer` should have an upper camel case name
type BareFnPtr = fn(#[deny(unused_parens)](i32)); //~ ERROR unnecessary parentheses around type
// There aren't any early lints that currently apply to the variadic spot.
// type BareFnPtrVariadic = extern "C" fn(i32, #[deny()]...);
// ################## Items
#[deny(non_camel_case_types)]
struct ITEM_OUTER; //~ ERROR type `ITEM_OUTER` should have an upper camel case name
mod module_inner {
#![deny(unsafe_code)]
fn f() {
unsafe {} //~ ERROR usage of an `unsafe` block
}
}
struct Associated;
impl Associated {
#![deny(unsafe_code)]
fn inherent_denied_from_inner() { unsafe {} } //~ usage of an `unsafe` block
#[deny(while_true)]
fn inherent_fn() { while true {} } //~ ERROR denote infinite loops with
#[deny(while_true)]
const INHERENT_CONST: i32 = {while true {} 1}; //~ ERROR denote infinite loops with
}
trait trait_inner { //~ ERROR trait `trait_inner` should have an upper camel case name
#![deny(non_camel_case_types)]
}
trait AssociatedTrait {
#![deny(unsafe_code)]
fn denied_from_inner() { unsafe {} } //~ ERROR usage of an `unsafe` block
#[deny(while_true)]
fn assoc_fn() { while true {} } //~ ERROR denote infinite loops with
#[deny(while_true)]
const ASSOC_CONST: i32 = {while true {} 1}; //~ ERROR denote infinite loops with
#[deny(non_camel_case_types)]
type assoc_type; //~ ERROR associated type `assoc_type` should have an upper camel case name
}
impl AssociatedTrait for Associated {
#![deny(unsafe_code)]
fn denied_from_inner() { unsafe {} } //~ ERROR usage of an `unsafe` block
#[deny(while_true)]
fn assoc_fn() { while true {} } //~ ERROR denote infinite loops with
#[deny(while_true)]
const ASSOC_CONST: i32 = {while true {} 1}; //~ ERROR denote infinite loops with
#[deny(unused_parens)]
type assoc_type = (i32); //~ ERROR unnecessary parentheses around type
}
struct StructFields {
#[deny(unused_parens)]f1: (i32), //~ ERROR unnecessary parentheses around type
}
struct StructTuple(#[deny(unused_parens)](i32)); //~ ERROR unnecessary parentheses around type
enum Enum {
#[deny(non_camel_case_types)]
VARIANT_CAMEL, //~ ERROR variant `VARIANT_CAMEL` should have an upper camel case name
}
extern "C" {
#![deny(unused_parens)]
fn foreign_denied_from_inner(x: (i32)); //~ ERROR unnecessary parentheses around type
}
extern "C" {
#[deny(unused_parens)]
fn foreign_denied_from_outer(x: (i32)); //~ ERROR unnecessary parentheses around type
}
fn function(#[deny(unused_parens)] param: (i32)) {} //~ ERROR unnecessary parentheses around type
fn generics<#[deny(non_camel_case_types)]foo>() {} //~ ERROR type parameter `foo` should have an upper camel case name
// ################## Statements
fn statements() {
#[deny(unused_parens)]
let x = (1); //~ ERROR unnecessary parentheses around assigned value
}
// ################## Expressions
fn expressions() {
let closure = |#[deny(unused_parens)] param: (i32)| {}; //~ ERROR unnecessary parentheses around type
struct Match{f1: i32}
// Strangely unused_parens doesn't fire with {f1: (123)}
let f = Match{#[deny(unused_parens)]f1: {(123)}}; //~ ERROR unnecessary parentheses around block return value
match f {
#![deny(unsafe_code)]
#[deny(while_true)]
Match{f1} => {
unsafe {} //~ ERROR usage of an `unsafe` block
while true {} //~ ERROR denote infinite loops with
}
}
match f {
#[deny(ellipsis_inclusive_range_patterns)]
Match{f1: 0...100} => {}
//~^ ERROR range patterns are deprecated
//~| WARNING this is accepted in the current edition
_ => {}
}
// Statement Block
{
#![deny(unsafe_code)]
unsafe {} //~ ERROR usage of an `unsafe` block
}
let block_tail: () = {
#[deny(unsafe_code)]
unsafe {} //~ ERROR usage of an `unsafe` block
};
// Before expression as a statement.
#[deny(unsafe_code)]
unsafe {}; //~ ERROR usage of an `unsafe` block
[#[deny(unsafe_code)] unsafe {123}]; //~ ERROR usage of an `unsafe` block
(#[deny(unsafe_code)] unsafe {123},); //~ ERROR usage of an `unsafe` block
fn call(p: i32) {}
call(#[deny(unsafe_code)] unsafe {123}); //~ ERROR usage of an `unsafe` block
struct TupleStruct(i32);
TupleStruct(#[deny(unsafe_code)] unsafe {123}); //~ ERROR usage of an `unsafe` block
}
// ################## Patterns
fn patterns() {
struct PatField{f1: i32, f2: i32};
let f = PatField{f1: 1, f2: 2};
match f {
PatField {
#[deny(ellipsis_inclusive_range_patterns)]
f1: 0...100,
//~^ ERROR range patterns are deprecated
//~| WARNING this is accepted in the current edition
..
} => {}
_ => {}
}
}
fn main() {}
|