Skip to content

Commit c796b1f

Browse files
committed
Add tests for internal lints
1 parent 0ba7d41 commit c796b1f

File tree

4 files changed

+345
-0
lines changed

4 files changed

+345
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2018 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+
// compile-flags: -Z internal-lints
12+
13+
#![feature(rustc_private)]
14+
15+
extern crate rustc_data_structures;
16+
17+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
18+
use std::collections::{HashMap, HashSet};
19+
//~^ WARNING Prefer FxHashMap over HashMap, it has better performance
20+
//~^^ WARNING Prefer FxHashSet over HashSet, it has better performance
21+
22+
#[deny(default_hash_types)]
23+
fn main() {
24+
let _map: HashMap<String, String> = HashMap::default();
25+
//~^ ERROR Prefer FxHashMap over HashMap, it has better performance
26+
//~^^ ERROR Prefer FxHashMap over HashMap, it has better performance
27+
let _set: HashSet<String> = HashSet::default();
28+
//~^ ERROR Prefer FxHashSet over HashSet, it has better performance
29+
//~^^ ERROR Prefer FxHashSet over HashSet, it has better performance
30+
31+
// test that the lint doesn't also match the Fx variants themselves
32+
let _fx_map: FxHashMap<String, String> = FxHashMap::default();
33+
let _fx_set: FxHashSet<String> = FxHashSet::default();
34+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
warning: Prefer FxHashMap over HashMap, it has better performance
2+
--> $DIR/default_hash_types.rs:18:24
3+
|
4+
LL | use std::collections::{HashMap, HashSet};
5+
| ^^^^^^^ help: use: `FxHashMap`
6+
|
7+
= note: #[warn(default_hash_types)] on by default
8+
= note: a `use rustc_data_structures::fx::FxHashMap` may be necessary
9+
10+
warning: Prefer FxHashSet over HashSet, it has better performance
11+
--> $DIR/default_hash_types.rs:18:33
12+
|
13+
LL | use std::collections::{HashMap, HashSet};
14+
| ^^^^^^^ help: use: `FxHashSet`
15+
|
16+
= note: a `use rustc_data_structures::fx::FxHashSet` may be necessary
17+
18+
error: Prefer FxHashMap over HashMap, it has better performance
19+
--> $DIR/default_hash_types.rs:24:15
20+
|
21+
LL | let _map: HashMap<String, String> = HashMap::default();
22+
| ^^^^^^^ help: use: `FxHashMap`
23+
|
24+
note: lint level defined here
25+
--> $DIR/default_hash_types.rs:22:8
26+
|
27+
LL | #[deny(default_hash_types)]
28+
| ^^^^^^^^^^^^^^^^^^
29+
= note: a `use rustc_data_structures::fx::FxHashMap` may be necessary
30+
31+
error: Prefer FxHashMap over HashMap, it has better performance
32+
--> $DIR/default_hash_types.rs:24:41
33+
|
34+
LL | let _map: HashMap<String, String> = HashMap::default();
35+
| ^^^^^^^ help: use: `FxHashMap`
36+
|
37+
= note: a `use rustc_data_structures::fx::FxHashMap` may be necessary
38+
39+
error: Prefer FxHashSet over HashSet, it has better performance
40+
--> $DIR/default_hash_types.rs:27:15
41+
|
42+
LL | let _set: HashSet<String> = HashSet::default();
43+
| ^^^^^^^ help: use: `FxHashSet`
44+
|
45+
= note: a `use rustc_data_structures::fx::FxHashSet` may be necessary
46+
47+
error: Prefer FxHashSet over HashSet, it has better performance
48+
--> $DIR/default_hash_types.rs:27:33
49+
|
50+
LL | let _set: HashSet<String> = HashSet::default();
51+
| ^^^^^^^ help: use: `FxHashSet`
52+
|
53+
= note: a `use rustc_data_structures::fx::FxHashSet` may be necessary
54+
55+
error: aborting due to 4 previous errors
56+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2018 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+
// compile-flags: -Z internal-lints
12+
13+
#![feature(rustc_private)]
14+
15+
extern crate rustc;
16+
17+
use rustc::ty::{self, Ty, TyKind};
18+
19+
#[deny(usage_of_ty_tykind)]
20+
fn main() {
21+
let sty = TyKind::Bool; //~ ERROR usage of `ty::TyKind::<kind>`
22+
23+
match sty {
24+
TyKind::Bool => (), //~ ERROR usage of `ty::TyKind::<kind>`
25+
TyKind::Char => (), //~ ERROR usage of `ty::TyKind::<kind>`
26+
TyKind::Int(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
27+
TyKind::Uint(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
28+
TyKind::Float(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
29+
TyKind::Adt(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
30+
TyKind::Foreign(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
31+
TyKind::Str => (), //~ ERROR usage of `ty::TyKind::<kind>`
32+
TyKind::Array(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
33+
TyKind::Slice(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
34+
TyKind::RawPtr(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
35+
TyKind::Ref(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
36+
TyKind::FnDef(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
37+
TyKind::FnPtr(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
38+
TyKind::Dynamic(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
39+
TyKind::Closure(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
40+
TyKind::Generator(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
41+
TyKind::GeneratorWitness(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
42+
TyKind::Never => (), //~ ERROR usage of `ty::TyKind::<kind>`
43+
TyKind::Tuple(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
44+
TyKind::Projection(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
45+
TyKind::UnnormalizedProjection(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
46+
TyKind::Opaque(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
47+
TyKind::Param(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
48+
TyKind::Bound(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
49+
TyKind::Placeholder(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
50+
TyKind::Infer(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
51+
TyKind::Error => (), //~ ERROR usage of `ty::TyKind::<kind>`
52+
}
53+
54+
if let ty::Int(int_ty) = sty {}
55+
56+
if let TyKind::Int(int_ty) = sty {} //~ ERROR usage of `ty::TyKind::<kind>`
57+
58+
fn ty_kind(ty_bad: TyKind<'_>, ty_good: Ty<'_>) {} //~ ERROR usage of `ty::TyKind`
59+
}
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
error: usage of `ty::TyKind::<kind>`
2+
--> $DIR/ty_tykind_usage.rs:21:15
3+
|
4+
LL | let sty = TyKind::Bool; //~ ERROR usage of `ty::TyKind::<kind>`
5+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
6+
|
7+
note: lint level defined here
8+
--> $DIR/ty_tykind_usage.rs:19:8
9+
|
10+
LL | #[deny(usage_of_ty_tykind)]
11+
| ^^^^^^^^^^^^^^^^^^
12+
13+
error: usage of `ty::TyKind::<kind>`
14+
--> $DIR/ty_tykind_usage.rs:24:9
15+
|
16+
LL | TyKind::Bool => (), //~ ERROR usage of `ty::TyKind::<kind>`
17+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
18+
19+
error: usage of `ty::TyKind::<kind>`
20+
--> $DIR/ty_tykind_usage.rs:25:9
21+
|
22+
LL | TyKind::Char => (), //~ ERROR usage of `ty::TyKind::<kind>`
23+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
24+
25+
error: usage of `ty::TyKind::<kind>`
26+
--> $DIR/ty_tykind_usage.rs:26:9
27+
|
28+
LL | TyKind::Int(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
29+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
30+
31+
error: usage of `ty::TyKind::<kind>`
32+
--> $DIR/ty_tykind_usage.rs:27:9
33+
|
34+
LL | TyKind::Uint(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
35+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
36+
37+
error: usage of `ty::TyKind::<kind>`
38+
--> $DIR/ty_tykind_usage.rs:28:9
39+
|
40+
LL | TyKind::Float(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
41+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
42+
43+
error: usage of `ty::TyKind::<kind>`
44+
--> $DIR/ty_tykind_usage.rs:29:9
45+
|
46+
LL | TyKind::Adt(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
47+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
48+
49+
error: usage of `ty::TyKind::<kind>`
50+
--> $DIR/ty_tykind_usage.rs:30:9
51+
|
52+
LL | TyKind::Foreign(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
53+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
54+
55+
error: usage of `ty::TyKind::<kind>`
56+
--> $DIR/ty_tykind_usage.rs:31:9
57+
|
58+
LL | TyKind::Str => (), //~ ERROR usage of `ty::TyKind::<kind>`
59+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
60+
61+
error: usage of `ty::TyKind::<kind>`
62+
--> $DIR/ty_tykind_usage.rs:32:9
63+
|
64+
LL | TyKind::Array(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
65+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
66+
67+
error: usage of `ty::TyKind::<kind>`
68+
--> $DIR/ty_tykind_usage.rs:33:9
69+
|
70+
LL | TyKind::Slice(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
71+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
72+
73+
error: usage of `ty::TyKind::<kind>`
74+
--> $DIR/ty_tykind_usage.rs:34:9
75+
|
76+
LL | TyKind::RawPtr(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
77+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
78+
79+
error: usage of `ty::TyKind::<kind>`
80+
--> $DIR/ty_tykind_usage.rs:35:9
81+
|
82+
LL | TyKind::Ref(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
83+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
84+
85+
error: usage of `ty::TyKind::<kind>`
86+
--> $DIR/ty_tykind_usage.rs:36:9
87+
|
88+
LL | TyKind::FnDef(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
89+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
90+
91+
error: usage of `ty::TyKind::<kind>`
92+
--> $DIR/ty_tykind_usage.rs:37:9
93+
|
94+
LL | TyKind::FnPtr(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
95+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
96+
97+
error: usage of `ty::TyKind::<kind>`
98+
--> $DIR/ty_tykind_usage.rs:38:9
99+
|
100+
LL | TyKind::Dynamic(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
101+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
102+
103+
error: usage of `ty::TyKind::<kind>`
104+
--> $DIR/ty_tykind_usage.rs:39:9
105+
|
106+
LL | TyKind::Closure(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
107+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
108+
109+
error: usage of `ty::TyKind::<kind>`
110+
--> $DIR/ty_tykind_usage.rs:40:9
111+
|
112+
LL | TyKind::Generator(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
113+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
114+
115+
error: usage of `ty::TyKind::<kind>`
116+
--> $DIR/ty_tykind_usage.rs:41:9
117+
|
118+
LL | TyKind::GeneratorWitness(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
119+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
120+
121+
error: usage of `ty::TyKind::<kind>`
122+
--> $DIR/ty_tykind_usage.rs:42:9
123+
|
124+
LL | TyKind::Never => (), //~ ERROR usage of `ty::TyKind::<kind>`
125+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
126+
127+
error: usage of `ty::TyKind::<kind>`
128+
--> $DIR/ty_tykind_usage.rs:43:9
129+
|
130+
LL | TyKind::Tuple(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
131+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
132+
133+
error: usage of `ty::TyKind::<kind>`
134+
--> $DIR/ty_tykind_usage.rs:44:9
135+
|
136+
LL | TyKind::Projection(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
137+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
138+
139+
error: usage of `ty::TyKind::<kind>`
140+
--> $DIR/ty_tykind_usage.rs:45:9
141+
|
142+
LL | TyKind::UnnormalizedProjection(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
143+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
144+
145+
error: usage of `ty::TyKind::<kind>`
146+
--> $DIR/ty_tykind_usage.rs:46:9
147+
|
148+
LL | TyKind::Opaque(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
149+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
150+
151+
error: usage of `ty::TyKind::<kind>`
152+
--> $DIR/ty_tykind_usage.rs:47:9
153+
|
154+
LL | TyKind::Param(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
155+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
156+
157+
error: usage of `ty::TyKind::<kind>`
158+
--> $DIR/ty_tykind_usage.rs:48:9
159+
|
160+
LL | TyKind::Bound(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
161+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
162+
163+
error: usage of `ty::TyKind::<kind>`
164+
--> $DIR/ty_tykind_usage.rs:49:9
165+
|
166+
LL | TyKind::Placeholder(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
167+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
168+
169+
error: usage of `ty::TyKind::<kind>`
170+
--> $DIR/ty_tykind_usage.rs:50:9
171+
|
172+
LL | TyKind::Infer(..) => (), //~ ERROR usage of `ty::TyKind::<kind>`
173+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
174+
175+
error: usage of `ty::TyKind::<kind>`
176+
--> $DIR/ty_tykind_usage.rs:51:9
177+
|
178+
LL | TyKind::Error => (), //~ ERROR usage of `ty::TyKind::<kind>`
179+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
180+
181+
error: usage of `ty::TyKind::<kind>`
182+
--> $DIR/ty_tykind_usage.rs:56:12
183+
|
184+
LL | if let TyKind::Int(int_ty) = sty {} //~ ERROR usage of `ty::TyKind::<kind>`
185+
| ^^^^^^ help: try using ty::<kind> directly: `ty`
186+
187+
error: usage of `ty::TyKind`
188+
--> $DIR/ty_tykind_usage.rs:58:24
189+
|
190+
LL | fn ty_kind(ty_bad: TyKind<'_>, ty_good: Ty<'_>) {} //~ ERROR usage of `ty::TyKind`
191+
| ^^^^^^^^^^
192+
|
193+
= help: try using `ty::Ty` instead
194+
195+
error: aborting due to 31 previous errors
196+

0 commit comments

Comments
 (0)