rustc: Add a flag '--warn-unused-imports'

Followup of issue #889
This commit is contained in:
Haitao Li 2011-11-17 12:23:43 +08:00 committed by Marijn Haverbeke
parent fe6484d3e6
commit 388eed383f
5 changed files with 16 additions and 4 deletions

View File

@ -123,6 +123,9 @@ Build a test harness.
.TP
\fB--stack-growth\fR:
\fBEXPERIMENTAL\fR. Perform stack growth checks.
.TP
\fB--warn-unused-imports\fR:
Warn about unnecessary imports.
.SH "BUGS"
See \fBhttps://github.com/graydon/rust/issues\fR for a list of known bugs.
.SH "AUTHOR"

View File

@ -274,6 +274,8 @@ options:
--test build test harness
--gc garbage collect shared data (experimental/temporary)
--stack-growth perform stack checks (experimental)
--warn-unused-imports
warn about unnecessary imports
");
}
@ -397,6 +399,7 @@ fn build_session_options(match: getopts::match)
let test = opt_present(match, "test");
let do_gc = opt_present(match, "gc");
let stack_growth = opt_present(match, "stack-growth");
let warn_unused_imports = opt_present(match, "warn-unused-imports");
let sopts: @session::options =
@{library: library,
static: static,
@ -417,7 +420,8 @@ fn build_session_options(match: getopts::match)
no_trans: no_trans,
do_gc: do_gc,
stack_growth: stack_growth,
no_asm_comments: no_asm_comments};
no_asm_comments: no_asm_comments,
warn_unused_imports: warn_unused_imports};
ret sopts;
}
@ -457,7 +461,8 @@ fn opts() -> [getopts::opt] {
optmulti("cfg"), optflag("test"),
optflag("lib"), optflag("static"), optflag("gc"),
optflag("stack-growth"),
optflag("no-asm-comments")];
optflag("no-asm-comments"),
optflag("warn-unused-imports")];
}
fn build_output_filenames(ifile: str, ofile: option::t<str>,

View File

@ -43,7 +43,8 @@ type options =
no_trans: bool,
do_gc: bool,
stack_growth: bool,
no_asm_comments: bool};
no_asm_comments: bool,
warn_unused_imports: bool};
type crate_metadata = {name: str, data: [u8]};

View File

@ -139,7 +139,9 @@ fn resolve_crate(sess: session, amap: ast_map::map, crate: @ast::crate) ->
check_for_collisions(e, *crate);
check_bad_exports(e);
resolve_names(e, crate);
check_unused_imports(e);
if sess.get_opts().warn_unused_imports {
check_unused_imports(e);
}
ret {def_map: e.def_map, ext_map: e.ext_map};
}

View File

@ -1,4 +1,5 @@
// error-pattern:unused import
// compile-flags:--warn-unused-imports
import cal = bar::c::cc;
mod foo {