Skip to content

Commit

Permalink
feat: Allow warnings by default (#1383)
Browse files Browse the repository at this point in the history
Change allow_warnings to deny_warnings flag
  • Loading branch information
jfecher committed May 23, 2023
1 parent 66744f3 commit e7a0d5c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion crates/nargo_cli/src/cli/check_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ d2 = ["", "", ""]
.join(format!("{TEST_DATA_DIR}/pass_dev_mode"));

let backend = crate::backends::ConcreteBackend::default();
let config = CompileOptions { allow_warnings: true, ..Default::default() };
let config = CompileOptions { deny_warnings: false, ..Default::default() };

let paths = std::fs::read_dir(pass_dir).unwrap();
for path in paths.flatten() {
Expand Down
2 changes: 1 addition & 1 deletion crates/nargo_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn prove_and_verify(proof_name: &str, program_dir: &Path) -> bool {
let compile_options = CompileOptions {
show_ssa: false,
print_acir: false,
allow_warnings: false,
deny_warnings: false,
show_output: false,
experimental_ssa: false,
};
Expand Down
10 changes: 5 additions & 5 deletions crates/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ pub struct CompileOptions {
#[arg(short, long)]
pub print_acir: bool,

/// Issue a warning for each unused variable instead of an error
/// Treat all warnings as errors
#[arg(short, long)]
pub allow_warnings: bool,
pub deny_warnings: bool,

/// Display output of `println` statements
#[arg(long)]
Expand All @@ -62,7 +62,7 @@ impl Default for CompileOptions {
Self {
show_ssa: false,
print_acir: false,
allow_warnings: false,
deny_warnings: false,
show_output: true,
experimental_ssa: false,
}
Expand Down Expand Up @@ -174,7 +174,7 @@ impl Driver {
let mut errs = vec![];
CrateDefMap::collect_defs(LOCAL_CRATE, &mut self.context, &mut errs);
let error_count =
reporter::report_all(&self.context.file_manager, &errs, options.allow_warnings);
reporter::report_all(&self.context.file_manager, &errs, options.deny_warnings);
reporter::finish_report(error_count)
}

Expand Down Expand Up @@ -315,7 +315,7 @@ impl Driver {
// Errors will be shown at the call site without a stacktrace
let file = err.location.map(|loc| loc.file);
let files = &self.context.file_manager;
let error = reporter::report(files, &err.into(), file, options.allow_warnings);
let error = reporter::report(files, &err.into(), file, options.deny_warnings);
reporter::finish_report(error as u32)?;
Err(ReportedError)
}
Expand Down
16 changes: 8 additions & 8 deletions crates/noirc_errors/src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ impl CustomLabel {
pub fn report_all(
files: &fm::FileManager,
diagnostics: &[FileDiagnostic],
allow_warnings: bool,
deny_warnings: bool,
) -> u32 {
diagnostics
.iter()
.map(|error| report(files, &error.diagnostic, Some(error.file_id), allow_warnings) as u32)
.map(|error| report(files, &error.diagnostic, Some(error.file_id), deny_warnings) as u32)
.sum()
}

Expand All @@ -119,24 +119,24 @@ pub fn report(
files: &fm::FileManager,
custom_diagnostic: &CustomDiagnostic,
file: Option<fm::FileId>,
allow_warnings: bool,
deny_warnings: bool,
) -> bool {
let writer = StandardStream::stderr(ColorChoice::Always);
let config = codespan_reporting::term::Config::default();

let diagnostic = convert_diagnostic(custom_diagnostic, file, allow_warnings);
let diagnostic = convert_diagnostic(custom_diagnostic, file, deny_warnings);
term::emit(&mut writer.lock(), &config, files.as_simple_files(), &diagnostic).unwrap();

!allow_warnings || custom_diagnostic.is_error()
deny_warnings || custom_diagnostic.is_error()
}

fn convert_diagnostic(
cd: &CustomDiagnostic,
file: Option<fm::FileId>,
allow_warnings: bool,
deny_warnings: bool,
) -> Diagnostic<usize> {
let diagnostic = match (cd.kind, allow_warnings) {
(DiagnosticKind::Warning, true) => Diagnostic::warning(),
let diagnostic = match (cd.kind, deny_warnings) {
(DiagnosticKind::Warning, false) => Diagnostic::warning(),
_ => Diagnostic::error(),
};

Expand Down

0 comments on commit e7a0d5c

Please sign in to comment.