From 7455f986a8cbf2ee628cf0fb4c164012e9a06031 Mon Sep 17 00:00:00 2001 From: Sangeun Kim Date: Tue, 7 May 2013 16:28:58 +0900 Subject: [PATCH 1/2] Make lint_table static --- src/librustc/middle/lint.rs | 289 ++++++++++++++++++------------------ 1 file changed, 145 insertions(+), 144 deletions(-) diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 265d6b0c7677c..aad64d2ffe368 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -90,156 +90,157 @@ struct LintSpec { pub type LintDict = @HashMap<~str, LintSpec>; +static lint_table: &'static [(&'static str, LintSpec)] = &[ + ("ctypes", + LintSpec { + lint: ctypes, + desc: "proper use of core::libc types in foreign modules", + default: warn + }), + + ("unused_imports", + LintSpec { + lint: unused_imports, + desc: "imports that are never used", + default: warn + }), + + ("while_true", + LintSpec { + lint: while_true, + desc: "suggest using loop { } instead of while(true) { }", + default: warn + }), + + ("path_statement", + LintSpec { + lint: path_statement, + desc: "path statements with no effect", + default: warn + }), + + ("unrecognized_lint", + LintSpec { + lint: unrecognized_lint, + desc: "unrecognized lint attribute", + default: warn + }), + + ("non_implicitly_copyable_typarams", + LintSpec { + lint: non_implicitly_copyable_typarams, + desc: "passing non implicitly copyable types as copy type params", + default: warn + }), + + ("vecs_implicitly_copyable", + LintSpec { + lint: vecs_implicitly_copyable, + desc: "make vecs and strs not implicitly copyable \ + (only checked at top level)", + default: warn + }), + + ("implicit_copies", + LintSpec { + lint: implicit_copies, + desc: "implicit copies of non implicitly copyable data", + default: warn + }), + + ("deprecated_pattern", + LintSpec { + lint: deprecated_pattern, + desc: "warn about deprecated uses of pattern bindings", + default: allow + }), + + ("non_camel_case_types", + LintSpec { + lint: non_camel_case_types, + desc: "types, variants and traits should have camel case names", + default: allow + }), + + ("managed_heap_memory", + LintSpec { + lint: managed_heap_memory, + desc: "use of managed (@ type) heap memory", + default: allow + }), + + ("owned_heap_memory", + LintSpec { + lint: owned_heap_memory, + desc: "use of owned (~ type) heap memory", + default: allow + }), + + ("heap_memory", + LintSpec { + lint: heap_memory, + desc: "use of any (~ type or @ type) heap memory", + default: allow + }), + + ("type_limits", + LintSpec { + lint: type_limits, + desc: "comparisons made useless by limits of the types involved", + default: warn + }), + + ("default_methods", + LintSpec { + lint: default_methods, + desc: "allow default methods", + default: deny + }), + + ("deprecated_mutable_fields", + LintSpec { + lint: deprecated_mutable_fields, + desc: "deprecated mutable fields in structures", + default: deny + }), + + ("unused_unsafe", + LintSpec { + lint: unused_unsafe, + desc: "unnecessary use of an `unsafe` block", + default: warn + }), + + ("unused_variable", + LintSpec { + lint: unused_variable, + desc: "detect variables which are not used in any way", + default: warn + }), + + ("dead_assignment", + LintSpec { + lint: dead_assignment, + desc: "detect assignments that will never be read", + default: warn + }), + + ("unused_mut", + LintSpec { + lint: unused_mut, + desc: "detect mut variables which don't need to be mutable", + default: warn + }), +]; + /* Pass names should not contain a '-', as the compiler normalizes '-' to '_' in command-line flags */ pub fn get_lint_dict() -> LintDict { - let v = ~[ - (~"ctypes", - LintSpec { - lint: ctypes, - desc: "proper use of core::libc types in foreign modules", - default: warn - }), - - (~"unused_imports", - LintSpec { - lint: unused_imports, - desc: "imports that are never used", - default: warn - }), - - (~"while_true", - LintSpec { - lint: while_true, - desc: "suggest using loop { } instead of while(true) { }", - default: warn - }), - - (~"path_statement", - LintSpec { - lint: path_statement, - desc: "path statements with no effect", - default: warn - }), - - (~"unrecognized_lint", - LintSpec { - lint: unrecognized_lint, - desc: "unrecognized lint attribute", - default: warn - }), - - (~"non_implicitly_copyable_typarams", - LintSpec { - lint: non_implicitly_copyable_typarams, - desc: "passing non implicitly copyable types as copy type params", - default: warn - }), - - (~"vecs_implicitly_copyable", - LintSpec { - lint: vecs_implicitly_copyable, - desc: "make vecs and strs not implicitly copyable \ - (only checked at top level)", - default: warn - }), - - (~"implicit_copies", - LintSpec { - lint: implicit_copies, - desc: "implicit copies of non implicitly copyable data", - default: warn - }), - - (~"deprecated_pattern", - LintSpec { - lint: deprecated_pattern, - desc: "warn about deprecated uses of pattern bindings", - default: allow - }), - - (~"non_camel_case_types", - LintSpec { - lint: non_camel_case_types, - desc: "types, variants and traits should have camel case names", - default: allow - }), - - (~"managed_heap_memory", - LintSpec { - lint: managed_heap_memory, - desc: "use of managed (@ type) heap memory", - default: allow - }), - - (~"owned_heap_memory", - LintSpec { - lint: owned_heap_memory, - desc: "use of owned (~ type) heap memory", - default: allow - }), - - (~"heap_memory", - LintSpec { - lint: heap_memory, - desc: "use of any (~ type or @ type) heap memory", - default: allow - }), - - (~"type_limits", - LintSpec { - lint: type_limits, - desc: "comparisons made useless by limits of the types involved", - default: warn - }), - - (~"default_methods", - LintSpec { - lint: default_methods, - desc: "allow default methods", - default: deny - }), - - (~"deprecated_mutable_fields", - LintSpec { - lint: deprecated_mutable_fields, - desc: "deprecated mutable fields in structures", - default: deny - }), - - (~"unused_unsafe", - LintSpec { - lint: unused_unsafe, - desc: "unnecessary use of an `unsafe` block", - default: warn - }), - - (~"unused_variable", - LintSpec { - lint: unused_variable, - desc: "detect variables which are not used in any way", - default: warn - }), - - (~"dead_assignment", - LintSpec { - lint: dead_assignment, - desc: "detect assignments that will never be read", - default: warn - }), - - (~"unused_mut", - LintSpec { - lint: unused_mut, - desc: "detect mut variables which don't need to be mutable", - default: warn - }), - ]; let mut map = HashMap::new(); - do vec::consume(v) |_, (k, v)| { - map.insert(k, v); + for lint_table.each() |&(k, v)| { + map.insert(k.to_str(), v); } return @map; } From 356ebe879276c5627d6010fce9dc8b054165e17b Mon Sep 17 00:00:00 2001 From: Sangeun Kim Date: Wed, 8 May 2013 10:42:47 +0900 Subject: [PATCH 2/2] extranous thing is removed --- src/librustc/middle/lint.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index aad64d2ffe368..59b7a5ff111c9 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -239,7 +239,7 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[ */ pub fn get_lint_dict() -> LintDict { let mut map = HashMap::new(); - for lint_table.each() |&(k, v)| { + for lint_table.each|&(k, v)| { map.insert(k.to_str(), v); } return @map;