Upgrade from our standard lints v4 -> v6 (#861)

This commit is contained in:
Johan Andersson 2022-04-17 12:16:59 +02:00 committed by GitHub
parent 7a2bb3606b
commit 132b960e83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 173 additions and 166 deletions

View File

@ -1,2 +1,85 @@
[alias] [alias]
compiletest = "run --release -p compiletests --" compiletest = "run --release -p compiletests --"
[target.'cfg(all())']
rustflags = [
# BEGIN - Embark standard lints v6 for Rust 1.55+
# do not change or add/remove here, but one can add exceptions after this section
# for more info see: <https://github.com/EmbarkStudios/rust-ecosystem/issues/59>
"-Dunsafe_code",
"-Wclippy::all",
"-Wclippy::await_holding_lock",
"-Wclippy::char_lit_as_u8",
"-Wclippy::checked_conversions",
"-Wclippy::dbg_macro",
"-Wclippy::debug_assert_with_mut_call",
"-Wclippy::doc_markdown",
"-Wclippy::empty_enum",
"-Wclippy::enum_glob_use",
"-Wclippy::exit",
"-Wclippy::expl_impl_clone_on_copy",
"-Wclippy::explicit_deref_methods",
"-Wclippy::explicit_into_iter_loop",
"-Wclippy::fallible_impl_from",
"-Wclippy::filter_map_next",
"-Wclippy::flat_map_option",
"-Wclippy::float_cmp_const",
"-Wclippy::fn_params_excessive_bools",
"-Wclippy::from_iter_instead_of_collect",
"-Wclippy::if_let_mutex",
"-Wclippy::implicit_clone",
"-Wclippy::imprecise_flops",
"-Wclippy::inefficient_to_string",
"-Wclippy::invalid_upcast_comparisons",
"-Wclippy::large_digit_groups",
"-Wclippy::large_stack_arrays",
"-Wclippy::large_types_passed_by_value",
"-Wclippy::let_unit_value",
"-Wclippy::linkedlist",
"-Wclippy::lossy_float_literal",
"-Wclippy::macro_use_imports",
"-Wclippy::manual_ok_or",
"-Wclippy::map_err_ignore",
"-Wclippy::map_flatten",
"-Wclippy::map_unwrap_or",
"-Wclippy::match_on_vec_items",
"-Wclippy::match_same_arms",
"-Wclippy::match_wild_err_arm",
"-Wclippy::match_wildcard_for_single_variants",
"-Wclippy::mem_forget",
"-Wclippy::mismatched_target_os",
"-Wclippy::missing_enforced_import_renames",
"-Wclippy::mut_mut",
"-Wclippy::mutex_integer",
"-Wclippy::needless_borrow",
"-Wclippy::needless_continue",
"-Wclippy::needless_for_each",
"-Wclippy::option_option",
"-Wclippy::path_buf_push_overwrite",
"-Wclippy::ptr_as_ptr",
"-Wclippy::rc_mutex",
"-Wclippy::ref_option_ref",
"-Wclippy::rest_pat_in_fully_bound_structs",
"-Wclippy::same_functions_in_if_condition",
"-Wclippy::semicolon_if_nothing_returned",
"-Wclippy::single_match_else",
"-Wclippy::string_add_assign",
"-Wclippy::string_add",
"-Wclippy::string_lit_as_bytes",
"-Wclippy::string_to_string",
"-Wclippy::todo",
"-Wclippy::trait_duplication_in_bounds",
"-Wclippy::unimplemented",
"-Wclippy::unnested_or_patterns",
"-Wclippy::unused_self",
"-Wclippy::useless_transmute",
"-Wclippy::verbose_file_reads",
"-Wclippy::zero_sized_map_values",
"-Wfuture_incompatible",
"-Wnonstandard_style",
"-Wrust_2018_idioms",
# END - Embark standard lints v6 for Rust 1.55+
# repo specific lints
"-Aunsafe_code",
]

View File

@ -72,7 +72,7 @@ impl<'a> Trie<'a> {
children.sort_unstable_by(|(k1, _), (k2, _)| k1.cmp(k2)); children.sort_unstable_by(|(k1, _), (k2, _)| k1.cmp(k2));
for (child_name, child) in children { for (child_name, child) in children {
let full_child_name = if full_name.is_empty() { let full_child_name = if full_name.is_empty() {
child_name.to_string() (*child_name).to_string()
} else { } else {
format!("{}::{}", full_name, child_name) format!("{}::{}", full_name, child_name)
}; };

View File

@ -2134,18 +2134,15 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
return_type, return_type,
arguments, arguments,
} => ( } => (
match callee.kind { if let SpirvValueKind::FnAddr { function } = callee.kind {
SpirvValueKind::FnAddr { function } => { assert_ty_eq!(self, callee_ty, pointee);
assert_ty_eq!(self, callee_ty, pointee); function
function }
} // Truly indirect call.
else {
// Truly indirect call. let fn_ptr_val = callee.def(self);
_ => { self.zombie(fn_ptr_val, "indirect calls are not supported in SPIR-V");
let fn_ptr_val = callee.def(self); fn_ptr_val
self.zombie(fn_ptr_val, "indirect calls are not supported in SPIR-V");
fn_ptr_val
}
}, },
return_type, return_type,
arguments, arguments,

View File

@ -14,13 +14,12 @@ pub struct ExtInst {
impl ExtInst { impl ExtInst {
pub fn import_glsl<'a, 'tcx>(&mut self, bx: &Builder<'a, 'tcx>) -> Word { pub fn import_glsl<'a, 'tcx>(&mut self, bx: &Builder<'a, 'tcx>) -> Word {
match self.glsl { if let Some(id) = self.glsl {
Some(id) => id, id
None => { } else {
let id = bx.emit_global().ext_inst_import(GLSL_STD_450); let id = bx.emit_global().ext_inst_import(GLSL_STD_450);
self.glsl = Some(id); self.glsl = Some(id);
id id
}
} }
} }

View File

@ -427,19 +427,16 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
Some(result_id) => result_id, Some(result_id) => result_id,
None => return, None => return,
}; };
match tokens.next() { if let Some(Token::Word("=")) = tokens.next() {
Some(Token::Word("=")) => (), } else {
_ => { self.err("expected equals after result id specifier");
self.err("expected equals after result id specifier"); return;
return;
}
} }
first_token = match tokens.next() { first_token = if let Some(tok) = tokens.next() {
Some(tok) => tok, tok
None => { } else {
self.err("expected instruction after equals"); self.err("expected instruction after equals");
return; return;
}
}; };
Some(result_id) Some(result_id)
} else { } else {
@ -461,12 +458,11 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
let inst_class = inst_name let inst_class = inst_name
.strip_prefix("Op") .strip_prefix("Op")
.and_then(|n| self.instruction_table.table.get(n)); .and_then(|n| self.instruction_table.table.get(n));
let inst_class = match inst_class { let inst_class = if let Some(inst) = inst_class {
Some(inst) => inst, inst
None => { } else {
self.err(&format!("unknown spirv instruction {}", inst_name)); self.err(&format!("unknown spirv instruction {}", inst_name));
return; return;
}
}; };
let result_id = match out_register { let result_id = match out_register {
Some(OutRegister::Regular(reg)) => Some(reg), Some(OutRegister::Regular(reg)) => Some(reg),
@ -808,19 +804,20 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
token: Token<'a, 'cx, 'tcx>, token: Token<'a, 'cx, 'tcx>,
) -> Option<OutRegister<'a>> { ) -> Option<OutRegister<'a>> {
match token { match token {
Token::Word(word) => match word.strip_prefix('%') { Token::Word(word) => {
Some(id) => Some(OutRegister::Regular({ if let Some(id) = word.strip_prefix('%') {
let num = *id_map.entry(id).or_insert_with(|| self.emit().id()); Some(OutRegister::Regular({
if !defined_ids.insert(num) { let num = *id_map.entry(id).or_insert_with(|| self.emit().id());
self.err(&format!("%{} is defined more than once", id)); if !defined_ids.insert(num) {
} self.err(&format!("%{} is defined more than once", id));
num }
})), num
None => { }))
} else {
self.err("expected ID"); self.err("expected ID");
None None
} }
}, }
Token::String(_) => { Token::String(_) => {
self.err("expected ID, not string"); self.err("expected ID, not string");
None None
@ -896,13 +893,14 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
token: Token<'a, 'cx, 'tcx>, token: Token<'a, 'cx, 'tcx>,
) -> Option<Word> { ) -> Option<Word> {
match token { match token {
Token::Word(word) => match word.strip_prefix('%') { Token::Word(word) => {
Some(id) => Some(*id_map.entry(id).or_insert_with(|| self.emit().id())), if let Some(id) = word.strip_prefix('%') {
None => { Some(*id_map.entry(id).or_insert_with(|| self.emit().id()))
} else {
self.err("expected ID"); self.err("expected ID");
None None
} }
}, }
Token::String(_) => { Token::String(_) => {
self.err("expected ID, not string"); self.err("expected ID, not string");
None None

View File

@ -33,14 +33,13 @@ impl<'tcx> CodegenCx<'tcx> {
) { ) {
let span = self.tcx.def_span(instance.def_id()); let span = self.tcx.def_span(instance.def_id());
let hir_params = { let hir_params = {
let fn_local_def_id = match instance.def_id().as_local() { let fn_local_def_id = if let Some(id) = instance.def_id().as_local() {
Some(id) => id, id
None => { } else {
self.tcx self.tcx
.sess .sess
.span_err(span, &format!("Cannot declare {} as an entry point", name)); .span_err(span, &format!("Cannot declare {} as an entry point", name));
return; return;
}
}; };
let fn_hir_id = self.tcx.hir().local_def_id_to_hir_id(fn_local_def_id); let fn_hir_id = self.tcx.hir().local_def_id_to_hir_id(fn_local_def_id);
let body = self.tcx.hir().body(self.tcx.hir().body_owned_by(fn_hir_id)); let body = self.tcx.hir().body(self.tcx.hir().body_owned_by(fn_hir_id));

View File

@ -18,75 +18,6 @@
#![feature(rustc_private)] #![feature(rustc_private)]
#![feature(assert_matches)] #![feature(assert_matches)]
#![feature(once_cell)] #![feature(once_cell)]
// BEGIN - Embark standard lints v0.4
// do not change or add/remove here, but one can add exceptions after this section
// for more info see: <https://github.com/EmbarkStudios/rust-ecosystem/issues/59>
#![deny(unsafe_code)]
#![warn(
clippy::all,
clippy::await_holding_lock,
clippy::char_lit_as_u8,
clippy::checked_conversions,
clippy::dbg_macro,
clippy::debug_assert_with_mut_call,
clippy::doc_markdown,
clippy::empty_enum,
clippy::enum_glob_use,
clippy::exit,
clippy::expl_impl_clone_on_copy,
clippy::explicit_deref_methods,
clippy::explicit_into_iter_loop,
clippy::fallible_impl_from,
clippy::filter_map_next,
clippy::float_cmp_const,
clippy::fn_params_excessive_bools,
clippy::if_let_mutex,
clippy::implicit_clone,
clippy::imprecise_flops,
clippy::inefficient_to_string,
clippy::invalid_upcast_comparisons,
clippy::large_types_passed_by_value,
clippy::let_unit_value,
clippy::linkedlist,
clippy::lossy_float_literal,
clippy::macro_use_imports,
clippy::manual_ok_or,
clippy::map_err_ignore,
clippy::map_flatten,
clippy::map_unwrap_or,
clippy::match_on_vec_items,
clippy::match_same_arms,
clippy::match_wildcard_for_single_variants,
clippy::mem_forget,
clippy::mismatched_target_os,
clippy::mut_mut,
clippy::mutex_integer,
clippy::needless_borrow,
clippy::needless_continue,
clippy::option_option,
clippy::path_buf_push_overwrite,
clippy::ptr_as_ptr,
clippy::ref_option_ref,
clippy::rest_pat_in_fully_bound_structs,
clippy::same_functions_in_if_condition,
clippy::semicolon_if_nothing_returned,
clippy::string_add_assign,
clippy::string_add,
clippy::string_lit_as_bytes,
clippy::string_to_string,
clippy::todo,
clippy::trait_duplication_in_bounds,
clippy::unimplemented,
clippy::unnested_or_patterns,
clippy::unused_self,
clippy::useless_transmute,
clippy::verbose_file_reads,
clippy::zero_sized_map_values,
future_incompatible,
nonstandard_style,
rust_2018_idioms
)]
// END - Embark standard lints v0.4
// crate-specific exceptions: // crate-specific exceptions:
#![allow( #![allow(
unsafe_code, // rustc_codegen_ssa requires unsafe functions in traits to be impl'd unsafe_code, // rustc_codegen_ssa requires unsafe functions in traits to be impl'd

View File

@ -544,9 +544,10 @@ struct RustcOutput {
fn get_last_artifact(out: &str) -> Option<PathBuf> { fn get_last_artifact(out: &str) -> Option<PathBuf> {
let last = out let last = out
.lines() .lines()
.filter_map(|line| match serde_json::from_str::<RustcOutput>(line) { .filter_map(|line| {
Ok(line) => Some(line), if let Ok(line) = serde_json::from_str::<RustcOutput>(line) {
Err(_) => { Some(line)
} else {
// Pass through invalid lines // Pass through invalid lines
println!("{}", line); println!("{}", line);
None None

View File

@ -21,36 +21,35 @@ impl SpirvBuilder {
} }
let metadata_result = crate::invoke_rustc(&self); let metadata_result = crate::invoke_rustc(&self);
// Load the dependencies of the thing // Load the dependencies of the thing
let metadata_file = match metadata_result { let metadata_file = if let Ok(path) = metadata_result {
Ok(path) => path, path
Err(_) => { } else {
let (tx, rx) = sync_channel(0); let (tx, rx) = sync_channel(0);
// Fall back to watching from the crate root if the inital compilation fails // Fall back to watching from the crate root if the inital compilation fails
let mut watcher = let mut watcher =
notify::recommended_watcher(move |event: notify::Result<Event>| match event { notify::recommended_watcher(move |event: notify::Result<Event>| match event {
Ok(e) => match e.kind { Ok(e) => match e.kind {
notify::EventKind::Access(_) => (), notify::EventKind::Access(_) => (),
notify::EventKind::Any notify::EventKind::Any
| notify::EventKind::Create(_) | notify::EventKind::Create(_)
| notify::EventKind::Modify(_) | notify::EventKind::Modify(_)
| notify::EventKind::Remove(_) | notify::EventKind::Remove(_)
| notify::EventKind::Other => { | notify::EventKind::Other => {
let _ = tx.try_send(()); let _ = tx.try_send(());
} }
}, },
Err(e) => println!("notify error: {:?}", e), Err(e) => println!("notify error: {:?}", e),
}) })
.expect("Could create watcher"); .expect("Could create watcher");
// This is likely to notice changes in the `target` dir, however, given that `cargo watch` doesn't seem to handle that, // This is likely to notice changes in the `target` dir, however, given that `cargo watch` doesn't seem to handle that,
watcher watcher
.watch(&self.path_to_crate, RecursiveMode::Recursive) .watch(&self.path_to_crate, RecursiveMode::Recursive)
.expect("Could watch crate root"); .expect("Could watch crate root");
loop { loop {
rx.recv().expect("Watcher still alive"); rx.recv().expect("Watcher still alive");
let metadata_file = crate::invoke_rustc(&self); let metadata_file = crate::invoke_rustc(&self);
if let Ok(f) = metadata_file { if let Ok(f) = metadata_file {
break f; break f;
}
} }
} }
}; };

View File

@ -1,3 +1,3 @@
fn main() { fn main() {
example_runner_wgpu::main() example_runner_wgpu::main();
} }

View File

@ -323,6 +323,7 @@ fn create_pipeline(
}) })
} }
#[allow(clippy::match_wild_err_arm)]
pub fn start(options: &Options) { pub fn start(options: &Options) {
// Build the shader before we pop open a window, since it might take a while. // Build the shader before we pop open a window, since it might take a while.
let event_loop = EventLoop::with_user_event(); let event_loop = EventLoop::with_user_event();
@ -332,7 +333,7 @@ pub fn start(options: &Options) {
Some(Box::new(move |res| match proxy.send_event(res) { Some(Box::new(move |res| match proxy.send_event(res) {
Ok(it) => it, Ok(it) => it,
// ShaderModuleDescriptor is not `Debug`, so can't use unwrap/expect // ShaderModuleDescriptor is not `Debug`, so can't use unwrap/expect
Err(_) => panic!("Event loop dead"), Err(_err) => panic!("Event loop dead"),
})), })),
); );

View File

@ -7,8 +7,6 @@
// HACK(eddyb) can't easily see warnings otherwise from `spirv-builder` builds. // HACK(eddyb) can't easily see warnings otherwise from `spirv-builder` builds.
#![deny(warnings)] #![deny(warnings)]
extern crate spirv_std;
use glam::UVec3; use glam::UVec3;
use spirv_std::glam; use spirv_std::glam;
#[cfg(not(target_arch = "spirv"))] #[cfg(not(target_arch = "spirv"))]

View File

@ -94,6 +94,7 @@ struct Runner {
impl Runner { impl Runner {
/// Runs the given `mode` on the directory that matches that name, using the /// Runs the given `mode` on the directory that matches that name, using the
/// backend provided by `codegen_backend_path`. /// backend provided by `codegen_backend_path`.
#[allow(clippy::string_add)]
fn run_mode(&self, mode: &'static str) { fn run_mode(&self, mode: &'static str) {
/// RUSTFLAGS passed to all test files. /// RUSTFLAGS passed to all test files.
fn test_rustc_flags( fn test_rustc_flags(