Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow warnings by default #1383

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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