diff --git a/compiler/noirc_driver/src/lib.rs b/compiler/noirc_driver/src/lib.rs index d797d498572..44e50f94874 100644 --- a/compiler/noirc_driver/src/lib.rs +++ b/compiler/noirc_driver/src/lib.rs @@ -42,8 +42,12 @@ pub struct CompileOptions { pub print_acir: bool, /// Treat all warnings as errors - #[arg(long)] + #[arg(long, conflicts_with = "silence_warnings")] pub deny_warnings: bool, + + /// Suppress warnings + #[arg(long, conflicts_with = "deny_warnings")] + pub silence_warnings: bool, } /// Helper type used to signify where only warnings are expected in file diagnostics diff --git a/compiler/noirc_errors/src/reporter.rs b/compiler/noirc_errors/src/reporter.rs index ba5ac450f56..cb5abbe2079 100644 --- a/compiler/noirc_errors/src/reporter.rs +++ b/compiler/noirc_errors/src/reporter.rs @@ -115,11 +115,15 @@ pub fn report_all<'files>( files: &'files impl Files<'files, FileId = fm::FileId>, diagnostics: &[FileDiagnostic], deny_warnings: bool, + silence_warnings: bool, ) -> ReportedErrors { // Report warnings before any errors - let (mut diagnostics, mut errors): (Vec<_>, _) = + let (warnings, mut errors): (Vec<_>, _) = diagnostics.iter().partition(|item| item.diagnostic.is_warning()); + + let mut diagnostics = if silence_warnings { Vec::new() } else { warnings }; diagnostics.append(&mut errors); + let error_count = diagnostics.iter().map(|error| error.report(files, deny_warnings) as u32).sum(); diff --git a/tooling/nargo_cli/src/cli/check_cmd.rs b/tooling/nargo_cli/src/cli/check_cmd.rs index 58e0e5d9697..30309f88f32 100644 --- a/tooling/nargo_cli/src/cli/check_cmd.rs +++ b/tooling/nargo_cli/src/cli/check_cmd.rs @@ -51,7 +51,12 @@ pub(crate) fn run( fn check_package(package: &Package, compile_options: &CompileOptions) -> Result<(), CompileError> { let (mut context, crate_id) = prepare_package(package, Box::new(|path| std::fs::read_to_string(path))); - check_crate_and_report_errors(&mut context, crate_id, compile_options.deny_warnings)?; + check_crate_and_report_errors( + &mut context, + crate_id, + compile_options.deny_warnings, + compile_options.silence_warnings, + )?; if package.is_library() || package.is_contract() { // Libraries do not have ABIs while contracts have many, so we cannot generate a `Prover.toml` file. @@ -171,7 +176,13 @@ pub(crate) fn check_crate_and_report_errors( context: &mut Context, crate_id: CrateId, deny_warnings: bool, + silence_warnings: bool, ) -> Result<(), CompileError> { let result = check_crate(context, crate_id, deny_warnings); - super::compile_cmd::report_errors(result, &context.file_manager, deny_warnings) + super::compile_cmd::report_errors( + result, + &context.file_manager, + deny_warnings, + silence_warnings, + ) } diff --git a/tooling/nargo_cli/src/cli/compile_cmd.rs b/tooling/nargo_cli/src/cli/compile_cmd.rs index edbc3e984db..a332d63e062 100644 --- a/tooling/nargo_cli/src/cli/compile_cmd.rs +++ b/tooling/nargo_cli/src/cli/compile_cmd.rs @@ -130,13 +130,23 @@ pub(super) fn compile_workspace( let compiled_programs: Vec = program_results .into_iter() .map(|(file_manager, compilation_result)| { - report_errors(compilation_result, &file_manager, compile_options.deny_warnings) + report_errors( + compilation_result, + &file_manager, + compile_options.deny_warnings, + compile_options.silence_warnings, + ) }) .collect::>()?; let compiled_contracts: Vec = contract_results .into_iter() .map(|(file_manager, compilation_result)| { - report_errors(compilation_result, &file_manager, compile_options.deny_warnings) + report_errors( + compilation_result, + &file_manager, + compile_options.deny_warnings, + compile_options.silence_warnings, + ) }) .collect::>()?; @@ -164,7 +174,12 @@ pub(crate) fn compile_bin_package( &is_opcode_supported, ); - let program = report_errors(compilation_result, &file_manager, compile_options.deny_warnings)?; + let program = report_errors( + compilation_result, + &file_manager, + compile_options.deny_warnings, + compile_options.silence_warnings, + )?; Ok(program) } @@ -323,11 +338,23 @@ pub(crate) fn report_errors( result: CompilationResult, file_manager: &FileManager, deny_warnings: bool, + silence_warnings: bool, ) -> Result { let (t, warnings) = result.map_err(|errors| { - noirc_errors::reporter::report_all(file_manager.as_file_map(), &errors, deny_warnings) + noirc_errors::reporter::report_all( + file_manager.as_file_map(), + &errors, + deny_warnings, + silence_warnings, + ) })?; - noirc_errors::reporter::report_all(file_manager.as_file_map(), &warnings, deny_warnings); + noirc_errors::reporter::report_all( + file_manager.as_file_map(), + &warnings, + deny_warnings, + silence_warnings, + ); + Ok(t) } diff --git a/tooling/nargo_cli/src/cli/fmt_cmd.rs b/tooling/nargo_cli/src/cli/fmt_cmd.rs index bfe0b1948ad..31b45cc092a 100644 --- a/tooling/nargo_cli/src/cli/fmt_cmd.rs +++ b/tooling/nargo_cli/src/cli/fmt_cmd.rs @@ -37,7 +37,12 @@ pub(crate) fn run(_args: FormatCommand, config: NargoConfig) -> Result<(), CliEr }) .collect(); - let _ = super::compile_cmd::report_errors::<()>(Err(errors), &file_manager, false); + let _ = super::compile_cmd::report_errors::<()>( + Err(errors), + &file_manager, + false, + false, + ); return Ok(()); } diff --git a/tooling/nargo_cli/src/cli/test_cmd.rs b/tooling/nargo_cli/src/cli/test_cmd.rs index e281411be8c..4ba2fc35766 100644 --- a/tooling/nargo_cli/src/cli/test_cmd.rs +++ b/tooling/nargo_cli/src/cli/test_cmd.rs @@ -84,7 +84,12 @@ fn run_tests( ) -> Result<(), CliError> { let (mut context, crate_id) = prepare_package(package, Box::new(|path| std::fs::read_to_string(path))); - check_crate_and_report_errors(&mut context, crate_id, compile_options.deny_warnings)?; + check_crate_and_report_errors( + &mut context, + crate_id, + compile_options.deny_warnings, + compile_options.silence_warnings, + )?; let test_functions = context.get_all_test_functions_in_crate_matching(&crate_id, test_name); @@ -119,6 +124,7 @@ fn run_tests( context.file_manager.as_file_map(), &[diag], compile_options.deny_warnings, + compile_options.silence_warnings, ); } failing += 1; @@ -128,6 +134,7 @@ fn run_tests( context.file_manager.as_file_map(), &[err], compile_options.deny_warnings, + compile_options.silence_warnings, ); failing += 1; }