Skip to content

Commit

Permalink
rustc: Add a flag '--warn-unused-imports'
Browse files Browse the repository at this point in the history
Followup of issue rust-lang#889
  • Loading branch information
lht authored and marijnh committed Nov 17, 2011
1 parent fe6484d commit 388eed3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions man/rustc.1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 7 additions & 2 deletions src/comp/driver/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
");
}
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}

Expand Down Expand Up @@ -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>,
Expand Down
3 changes: 2 additions & 1 deletion src/comp/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]};

Expand Down
4 changes: 3 additions & 1 deletion src/comp/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}

Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/unused-imports-warn.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// error-pattern:unused import
// compile-flags:--warn-unused-imports
import cal = bar::c::cc;

mod foo {
Expand Down

0 comments on commit 388eed3

Please sign in to comment.