Skip to content

Commit 8a7fd4a

Browse files
committed
Support general warnings and errors in lint pass via flags and attrs. Close rust-lang#1543.
1 parent 7b3cb05 commit 8a7fd4a

File tree

11 files changed

+269
-126
lines changed

11 files changed

+269
-126
lines changed

src/librustsyntax/ext/expand.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,7 @@ fn expand_mod_items(exts: hashmap<str, syntax_extension>, cx: ext_ctxt,
7676
ast::meta_list(n, _) { n }
7777
};
7878
alt exts.find(mname) {
79-
none { items }
80-
81-
some(normal(_)) | some(macro_defining(_)) {
82-
cx.span_err(
83-
attr.span,
84-
#fmt["%s cannot be used as a decorator", mname]);
79+
none | some(normal(_)) | some(macro_defining(_)) {
8580
items
8681
}
8782

src/rustc/driver/driver.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,16 @@ fn build_session_options(match: getopts::match,
366366

367367
let parse_only = opt_present(match, "parse-only");
368368
let no_trans = opt_present(match, "no-trans");
369-
let mut lint_opts = [];
370-
if opt_present(match, "no-lint-ctypes") {
371-
lint_opts += [(lint::ctypes, false)];
372-
}
369+
370+
let lint_flags = (getopts::opt_strs(match, "W")
371+
+ getopts::opt_strs(match, "warn"));
372+
let lint_dict = lint::get_lint_dict();
373+
let lint_opts = vec::map(lint_flags) {|flag|
374+
alt lint::lookup_lint(lint_dict, flag) {
375+
none { early_error(demitter, #fmt("unknown warning: %s", flag)) }
376+
some(x) { x }
377+
}
378+
};
373379

374380
let output_type =
375381
if parse_only || no_trans {
@@ -426,7 +432,6 @@ fn build_session_options(match: getopts::match,
426432
let addl_lib_search_paths = getopts::opt_strs(match, "L");
427433
let cfg = parse_cfgspecs(getopts::opt_strs(match, "cfg"));
428434
let test = opt_present(match, "test");
429-
let warn_unused_imports = opt_present(match, "warn-unused-imports");
430435
let sopts: @session::options =
431436
@{crate_type: crate_type,
432437
static: static,
@@ -448,8 +453,7 @@ fn build_session_options(match: getopts::match,
448453
test: test,
449454
parse_only: parse_only,
450455
no_trans: no_trans,
451-
no_asm_comments: no_asm_comments,
452-
warn_unused_imports: warn_unused_imports};
456+
no_asm_comments: no_asm_comments};
453457
ret sopts;
454458
}
455459

@@ -521,11 +525,12 @@ fn opts() -> [getopts::opt] {
521525
optflag("time-passes"), optflag("time-llvm-passes"),
522526
optflag("count-llvm-insns"),
523527
optflag("no-verify"),
524-
optflag("no-lint-ctypes"),
528+
529+
optmulti("W"), optmulti("warn"),
530+
525531
optmulti("cfg"), optflag("test"),
526532
optflag("lib"), optflag("bin"), optflag("static"), optflag("gc"),
527533
optflag("no-asm-comments"),
528-
optflag("warn-unused-imports"),
529534
optflag("enforce-mut-vars")];
530535
}
531536

src/rustc/driver/rustc.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ Options:
3939
--lib Compile a library crate
4040
--ls List the symbols defined by a compiled library crate
4141
--no-asm-comments Do not add comments into the assembly source
42-
--no-lint-ctypes Suppress warnings for possibly incorrect ctype usage
4342
--no-trans Run all passes except translation; no output
4443
--no-verify Suppress LLVM verification step (slight speedup)
4544
(see http://llvm.org/docs/Passes.html for detail)
@@ -65,13 +64,15 @@ Options:
6564
(see http://sources.redhat.com/autobook/autobook/
6665
autobook_17.html for detail)
6766
67+
-W <foo> enable warning <foo>
68+
-W no-<foo> disable warning <foo>
69+
-W err-<foo> enable warning <foo> as an error
70+
6871
--time-passes Time the individual phases of the compiler
6972
--time-llvm-passes Time the individual phases of the LLVM backend
7073
--count-llvm-insns Count and categorize generated LLVM instructions
71-
-v --version Print version info and exit
72-
--warn-unused-imports
73-
Warn about unnecessary imports
7474
75+
-v --version Print version info and exit
7576
");
7677
}
7778

src/rustc/driver/session.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type options =
3131
debuginfo: bool,
3232
extra_debuginfo: bool,
3333
verify: bool,
34-
lint_opts: [(lint::option, bool)],
34+
lint_opts: [(lint::lint, lint::level)],
3535
save_temps: bool,
3636
stats: bool,
3737
time_passes: bool,
@@ -45,8 +45,7 @@ type options =
4545
test: bool,
4646
parse_only: bool,
4747
no_trans: bool,
48-
no_asm_comments: bool,
49-
warn_unused_imports: bool};
48+
no_asm_comments: bool};
5049

5150
type crate_metadata = {name: str, data: [u8]};
5251

0 commit comments

Comments
 (0)