Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

New compiler flags: -W all -W no-all -W err-all #2453

Closed
wants to merge 1 commit into from

2 participants

@bstrie
Collaborator

Use RUST_LOG=rustc::driver=2 to see the effect of the new options.

When rustc is invoked with -W all, it sets the lint flags equal to the keys of the master lint flags hashtable. As per the convention of the individual lint flags, using -W no-all will do the same, but prepends each lint flag with no-, thereby disabling it. Using -W err-all prepends all lint flags with err- to abort compilation upon a lint warning.

Here's the test file I used:

use std;
import std::bitv;  // unused-import warning

fn main() {
    while true {  // while-true warning
        io::println("hello");
        log(error, "world");  // old-vecs warning
        #error("%?", "again!");  // lots of old-vecs warnings
        break;
    }
}
@bstrie bstrie New compiler flags: -W all -W no-all -W err-all
Use RUST_LOG=rustc::driver=2 to see the effect of the new options.
ad69e23
@brson
Owner

This looks good, but I would like to do this in a slightly different way. Instead of creating command line flags can we just create lint checks called 'all' and 'err-all'? That way they can also be activated via the crate warn attributes (#[warn(all)]). The lint pass itself can interpret 'all', 'no_all' and 'err_all' specially to flip all the checks on/off, etc.

In general we want compile options to be specified via attributes, and only secondarily via the command line.

@bstrie
Collaborator

Can do.

@brson
Owner

@msullivan and @nikomatsakis have been eyeing the lint pass as well lately.

@brson
Owner

Closing this.

@brson brson closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 26, 2012
  1. @bstrie

    New compiler flags: -W all -W no-all -W err-all

    bstrie authored
    Use RUST_LOG=rustc::driver=2 to see the effect of the new options.
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 2 deletions.
  1. +16 −2 src/rustc/driver/driver.rs
  2. +3 −0  src/rustc/driver/rustc.rs
View
18 src/rustc/driver/driver.rs
@@ -13,6 +13,7 @@ import std::getopts;
import io::{reader_util, writer_util};
import getopts::{optopt, optmulti, optflag, optflagopt, opt_present};
import back::{x86, x86_64};
+import std::map::hashmap;
enum pp_mode {ppm_normal, ppm_expanded, ppm_typed, ppm_identified,
ppm_expanded_identified }
@@ -399,9 +400,22 @@ fn build_session_options(match: getopts::match,
let parse_only = opt_present(match, "parse-only");
let no_trans = opt_present(match, "no-trans");
- let lint_flags = (getopts::opt_strs(match, "W")
- + getopts::opt_strs(match, "warn"));
+ let mut lint_flags = (getopts::opt_strs(match, "W")
+ + getopts::opt_strs(match, "warn"));
let lint_dict = lint::get_lint_dict();
+ #info("Given lint flags: %?", lint_flags);
+ let exhaustive_flags = ["all", "no-all", "err-all"];
+ alt lint_flags.find({|elt| exhaustive_flags.contains(elt)}) {
+ some(all_flag) {
+ lint_flags = [];
+ let lint_prefix = str::replace(all_flag, "all", "");
+ for lint_dict.each_key {|key|
+ lint_flags += [lint_prefix + key];
+ }
+ }
+ none {}
+ }
+ #info("Processed lint flags: %?", lint_flags);
let lint_opts = vec::map(lint_flags) {|flag|
alt lint::lookup_lint(lint_dict, flag) {
none { early_error(demitter, #fmt("unknown warning: %s", flag)) }
View
3  src/rustc/driver/rustc.rs
@@ -67,6 +67,9 @@ Options:
-W <foo> enable warning <foo>
-W no-<foo> disable warning <foo>
-W err-<foo> enable warning <foo> as an error
+ -W all enable all warnings
+ -W no-all disable all warnings
+ -W err-all enable all warnings as errors
-W help Print available warnings and default settings
-Z help list internal options for debugging rustc
Something went wrong with that request. Please try again.