Skip to content

Commit 86500fb

Browse files
committed
auto merge of #6297 : sammykim/rust/static-lint-table, r=luqmana
2 parents 5a1afaf + 356ebe8 commit 86500fb

File tree

1 file changed

+145
-144
lines changed

1 file changed

+145
-144
lines changed

src/librustc/middle/lint.rs

Lines changed: 145 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -90,156 +90,157 @@ struct LintSpec {
9090

9191
pub type LintDict = @HashMap<~str, LintSpec>;
9292

93+
static lint_table: &'static [(&'static str, LintSpec)] = &[
94+
("ctypes",
95+
LintSpec {
96+
lint: ctypes,
97+
desc: "proper use of core::libc types in foreign modules",
98+
default: warn
99+
}),
100+
101+
("unused_imports",
102+
LintSpec {
103+
lint: unused_imports,
104+
desc: "imports that are never used",
105+
default: warn
106+
}),
107+
108+
("while_true",
109+
LintSpec {
110+
lint: while_true,
111+
desc: "suggest using loop { } instead of while(true) { }",
112+
default: warn
113+
}),
114+
115+
("path_statement",
116+
LintSpec {
117+
lint: path_statement,
118+
desc: "path statements with no effect",
119+
default: warn
120+
}),
121+
122+
("unrecognized_lint",
123+
LintSpec {
124+
lint: unrecognized_lint,
125+
desc: "unrecognized lint attribute",
126+
default: warn
127+
}),
128+
129+
("non_implicitly_copyable_typarams",
130+
LintSpec {
131+
lint: non_implicitly_copyable_typarams,
132+
desc: "passing non implicitly copyable types as copy type params",
133+
default: warn
134+
}),
135+
136+
("vecs_implicitly_copyable",
137+
LintSpec {
138+
lint: vecs_implicitly_copyable,
139+
desc: "make vecs and strs not implicitly copyable \
140+
(only checked at top level)",
141+
default: warn
142+
}),
143+
144+
("implicit_copies",
145+
LintSpec {
146+
lint: implicit_copies,
147+
desc: "implicit copies of non implicitly copyable data",
148+
default: warn
149+
}),
150+
151+
("deprecated_pattern",
152+
LintSpec {
153+
lint: deprecated_pattern,
154+
desc: "warn about deprecated uses of pattern bindings",
155+
default: allow
156+
}),
157+
158+
("non_camel_case_types",
159+
LintSpec {
160+
lint: non_camel_case_types,
161+
desc: "types, variants and traits should have camel case names",
162+
default: allow
163+
}),
164+
165+
("managed_heap_memory",
166+
LintSpec {
167+
lint: managed_heap_memory,
168+
desc: "use of managed (@ type) heap memory",
169+
default: allow
170+
}),
171+
172+
("owned_heap_memory",
173+
LintSpec {
174+
lint: owned_heap_memory,
175+
desc: "use of owned (~ type) heap memory",
176+
default: allow
177+
}),
178+
179+
("heap_memory",
180+
LintSpec {
181+
lint: heap_memory,
182+
desc: "use of any (~ type or @ type) heap memory",
183+
default: allow
184+
}),
185+
186+
("type_limits",
187+
LintSpec {
188+
lint: type_limits,
189+
desc: "comparisons made useless by limits of the types involved",
190+
default: warn
191+
}),
192+
193+
("default_methods",
194+
LintSpec {
195+
lint: default_methods,
196+
desc: "allow default methods",
197+
default: deny
198+
}),
199+
200+
("deprecated_mutable_fields",
201+
LintSpec {
202+
lint: deprecated_mutable_fields,
203+
desc: "deprecated mutable fields in structures",
204+
default: deny
205+
}),
206+
207+
("unused_unsafe",
208+
LintSpec {
209+
lint: unused_unsafe,
210+
desc: "unnecessary use of an `unsafe` block",
211+
default: warn
212+
}),
213+
214+
("unused_variable",
215+
LintSpec {
216+
lint: unused_variable,
217+
desc: "detect variables which are not used in any way",
218+
default: warn
219+
}),
220+
221+
("dead_assignment",
222+
LintSpec {
223+
lint: dead_assignment,
224+
desc: "detect assignments that will never be read",
225+
default: warn
226+
}),
227+
228+
("unused_mut",
229+
LintSpec {
230+
lint: unused_mut,
231+
desc: "detect mut variables which don't need to be mutable",
232+
default: warn
233+
}),
234+
];
235+
93236
/*
94237
Pass names should not contain a '-', as the compiler normalizes
95238
'-' to '_' in command-line flags
96239
*/
97240
pub fn get_lint_dict() -> LintDict {
98-
let v = ~[
99-
(~"ctypes",
100-
LintSpec {
101-
lint: ctypes,
102-
desc: "proper use of core::libc types in foreign modules",
103-
default: warn
104-
}),
105-
106-
(~"unused_imports",
107-
LintSpec {
108-
lint: unused_imports,
109-
desc: "imports that are never used",
110-
default: warn
111-
}),
112-
113-
(~"while_true",
114-
LintSpec {
115-
lint: while_true,
116-
desc: "suggest using loop { } instead of while(true) { }",
117-
default: warn
118-
}),
119-
120-
(~"path_statement",
121-
LintSpec {
122-
lint: path_statement,
123-
desc: "path statements with no effect",
124-
default: warn
125-
}),
126-
127-
(~"unrecognized_lint",
128-
LintSpec {
129-
lint: unrecognized_lint,
130-
desc: "unrecognized lint attribute",
131-
default: warn
132-
}),
133-
134-
(~"non_implicitly_copyable_typarams",
135-
LintSpec {
136-
lint: non_implicitly_copyable_typarams,
137-
desc: "passing non implicitly copyable types as copy type params",
138-
default: warn
139-
}),
140-
141-
(~"vecs_implicitly_copyable",
142-
LintSpec {
143-
lint: vecs_implicitly_copyable,
144-
desc: "make vecs and strs not implicitly copyable \
145-
(only checked at top level)",
146-
default: warn
147-
}),
148-
149-
(~"implicit_copies",
150-
LintSpec {
151-
lint: implicit_copies,
152-
desc: "implicit copies of non implicitly copyable data",
153-
default: warn
154-
}),
155-
156-
(~"deprecated_pattern",
157-
LintSpec {
158-
lint: deprecated_pattern,
159-
desc: "warn about deprecated uses of pattern bindings",
160-
default: allow
161-
}),
162-
163-
(~"non_camel_case_types",
164-
LintSpec {
165-
lint: non_camel_case_types,
166-
desc: "types, variants and traits should have camel case names",
167-
default: allow
168-
}),
169-
170-
(~"managed_heap_memory",
171-
LintSpec {
172-
lint: managed_heap_memory,
173-
desc: "use of managed (@ type) heap memory",
174-
default: allow
175-
}),
176-
177-
(~"owned_heap_memory",
178-
LintSpec {
179-
lint: owned_heap_memory,
180-
desc: "use of owned (~ type) heap memory",
181-
default: allow
182-
}),
183-
184-
(~"heap_memory",
185-
LintSpec {
186-
lint: heap_memory,
187-
desc: "use of any (~ type or @ type) heap memory",
188-
default: allow
189-
}),
190-
191-
(~"type_limits",
192-
LintSpec {
193-
lint: type_limits,
194-
desc: "comparisons made useless by limits of the types involved",
195-
default: warn
196-
}),
197-
198-
(~"default_methods",
199-
LintSpec {
200-
lint: default_methods,
201-
desc: "allow default methods",
202-
default: deny
203-
}),
204-
205-
(~"deprecated_mutable_fields",
206-
LintSpec {
207-
lint: deprecated_mutable_fields,
208-
desc: "deprecated mutable fields in structures",
209-
default: deny
210-
}),
211-
212-
(~"unused_unsafe",
213-
LintSpec {
214-
lint: unused_unsafe,
215-
desc: "unnecessary use of an `unsafe` block",
216-
default: warn
217-
}),
218-
219-
(~"unused_variable",
220-
LintSpec {
221-
lint: unused_variable,
222-
desc: "detect variables which are not used in any way",
223-
default: warn
224-
}),
225-
226-
(~"dead_assignment",
227-
LintSpec {
228-
lint: dead_assignment,
229-
desc: "detect assignments that will never be read",
230-
default: warn
231-
}),
232-
233-
(~"unused_mut",
234-
LintSpec {
235-
lint: unused_mut,
236-
desc: "detect mut variables which don't need to be mutable",
237-
default: warn
238-
}),
239-
];
240241
let mut map = HashMap::new();
241-
do vec::consume(v) |_, (k, v)| {
242-
map.insert(k, v);
242+
for lint_table.each|&(k, v)| {
243+
map.insert(k.to_str(), v);
243244
}
244245
return @map;
245246
}

0 commit comments

Comments
 (0)