Skip to content

Commit

Permalink
Use new expect attributes over allow and include reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat-Lafon committed Sep 5, 2024
1 parent dfbc7cc commit eb3bc4c
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 31 deletions.
32 changes: 16 additions & 16 deletions bril-rs/bril2json/src/bril_grammar.lalrpop
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#![allow(clippy::no_effect_underscore_binding)]
#![allow(clippy::unnested_or_patterns)]
#![allow(clippy::trivially_copy_pass_by_ref)]
#![allow(clippy::missing_const_for_fn)]
#![allow(clippy::unnecessary_wraps)]
#![allow(clippy::redundant_pub_crate)]
#![allow(clippy::cloned_instead_of_copied)]
#![allow(clippy::too_many_lines)]
#![allow(clippy::use_self)]
#![allow(clippy::needless_pass_by_value)]
#![allow(clippy::cast_sign_loss)]
#![allow(clippy::must_use_candidate)]
#![allow(clippy::uninlined_format_args)]
#![allow(clippy::match_same_arms)]
#![allow(clippy::option_if_let_else)]
#![allow(clippy::extra_unused_lifetimes)]
#![expect(clippy::no_effect_underscore_binding)]
#![expect(clippy::unnested_or_patterns)]
#![expect(clippy::trivially_copy_pass_by_ref)]
#![expect(clippy::missing_const_for_fn)]
#![expect(clippy::unnecessary_wraps)]
#![expect(clippy::redundant_pub_crate)]
#![expect(clippy::cloned_instead_of_copied)]
#![expect(clippy::too_many_lines)]
#![expect(clippy::use_self)]
#![expect(clippy::needless_pass_by_value)]
#![expect(clippy::cast_sign_loss)]
#![expect(clippy::must_use_candidate)]
#![expect(clippy::uninlined_format_args)]
#![expect(clippy::match_same_arms)]
#![expect(clippy::option_if_let_else)]
#![expect(clippy::extra_unused_lifetimes)]

use std::str::FromStr;
use std::path::PathBuf;
Expand Down
1 change: 1 addition & 0 deletions bril-rs/brild/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use thiserror::Error;

#[expect(clippy::module_name_repetitions, reason = "I allow for the Error suffix on enums")]
#[derive(Error, Debug)]
pub enum BrildError {
#[error("Could not find a complete path for `{0}` from the list of provided libraries")]
Expand Down
2 changes: 1 addition & 1 deletion bril-rs/brild/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo)]
#![warn(missing_docs)]
#![warn(clippy::allow_attributes)]
#![doc = include_str!("../README.md")]
#![allow(clippy::module_name_repetitions)]

#[doc(hidden)]
pub mod cli;
Expand Down
1 change: 1 addition & 0 deletions bril-rs/brillvm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo)]
#![warn(clippy::allow_attributes)]
#![allow(clippy::doc_markdown)] // Not uniform? Just lints on one line
#![allow(clippy::too_many_lines)]
#![allow(clippy::needless_for_each)]
Expand Down
15 changes: 9 additions & 6 deletions bril-rs/brillvm/src/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn build_functiontype<'a>(
.iter()
.map(|t| llvm_type_map(context, t, Into::into))
.collect();
#[allow(clippy::option_if_let_else)] // I think this is more readable
#[expect(clippy::option_if_let_else)] // I think this is more readable
match return_ty {
None => context.void_type().fn_type(&param_types, false),
Some(t) => llvm_type_map(context, t, |t| t.fn_type(&param_types, false)),
Expand Down Expand Up @@ -179,7 +179,7 @@ fn block_map_get<'a>(
}

// The workhorse of converting a Bril Instruction to an LLVM Instruction
#[allow(clippy::too_many_arguments)]
#[expect(clippy::too_many_arguments)]
fn build_instruction<'a, 'b>(
i: &'b Instruction,
context: &'a Context,
Expand All @@ -198,7 +198,7 @@ fn build_instruction<'a, 'b>(
const_type: Type::Float,
value: Literal::Int(i),
} => {
#[allow(clippy::cast_precision_loss)]
#[expect(clippy::cast_precision_loss)]
builder
.build_store(
heap.get(dest).ptr,
Expand All @@ -212,7 +212,7 @@ fn build_instruction<'a, 'b>(
const_type: _,
value: Literal::Int(i),
} => {
#[allow(clippy::cast_sign_loss)]
#[expect(clippy::cast_sign_loss, reason = "u64 because of the C++/C API")]
builder
.build_store(
heap.get(dest).ptr,
Expand Down Expand Up @@ -1237,7 +1237,10 @@ pub fn create_module_from_program<'a>(
let mut fresh = Fresh::new();

// Add all functions to the module, initialize all variables in the heap, and setup for the second phase
#[allow(clippy::needless_collect)]
#[expect(
clippy::needless_collect,
reason = "Important to collect, can't be done lazily because we need all functions to be loaded in before a call instruction of a function is processed."
)]
let funcs: Vec<_> = functions
.iter()
.map(
Expand Down Expand Up @@ -1297,7 +1300,7 @@ pub fn create_module_from_program<'a>(
(llvm_func, instrs, block, heap)
},
)
.collect(); // Important to collect, can't be done lazily because we need all functions to be loaded in before a call instruction of a function is processed.
.collect();

// Now actually build each function
funcs
Expand Down
1 change: 1 addition & 0 deletions bril-rs/rs2bril/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo)]
#![warn(missing_docs)]
#![warn(clippy::allow_attributes)]
#![doc = include_str!("../README.md")]
#![allow(clippy::too_many_lines)]
#![allow(clippy::cognitive_complexity)]
Expand Down
5 changes: 4 additions & 1 deletion bril-rs/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ const pos: Option<Position> = None;
// todo Should this also wrap Serde errors? In this case, maybe change the name from ConversionError
// Having the #[error(...)] for all variants derives the Display trait as well
#[derive(Error, Debug)]
#[allow(clippy::module_name_repetitions)]
#[expect(
clippy::module_name_repetitions,
reason = "I allow the `Error` suffix for enums"
)]
pub enum ConversionError {
/// Expected a primitive type like int or bool, found {0}"
#[error("Expected a primitive type like int or bool, found {0}")]
Expand Down
1 change: 1 addition & 0 deletions bril-rs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo)]
#![warn(missing_docs)]
#![warn(clippy::allow_attributes)]
#![doc = include_str!("../README.md")]
#![allow(clippy::too_many_lines)]

Expand Down
3 changes: 1 addition & 2 deletions brilirs/src/basic_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ fn get_num_from_map(
// A map from variables to numbers
num_var_map: &mut FxHashMap<String, usize>,
) -> usize {
// https://github.com/rust-lang/rust-clippy/issues/8346
#[allow(clippy::option_if_let_else)]
#[expect(clippy::option_if_let_else, reason = "https://github.com/rust-lang/rust-clippy/issues/8346")]
if let Some(i) = num_var_map.get(variable_name) {
*i
} else {
Expand Down
3 changes: 1 addition & 2 deletions brilirs/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ fn update_env<'a>(
dest: &'a str,
typ: &'a Type,
) -> Result<(), InterpError> {
// https://github.com/rust-lang/rust-clippy/issues/8346
#[allow(clippy::option_if_let_else)]
#[expect(clippy::option_if_let_else, reason = "https://github.com/rust-lang/rust-clippy/issues/8346")]
if let Some(current_typ) = env.get(dest) {
check_asmt_type(current_typ, typ)
} else {
Expand Down
7 changes: 4 additions & 3 deletions brilirs/src/interp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,10 @@ fn execute<'a, T: std::io::Write>(
// Integer literals can be promoted to Floating point
if const_type == &bril_rs::Type::Float {
match value {
// So yes, as clippy points out, you technically lose precision here on the `*i as f64` cast. On the other hand, you already give up precision when you start using floats and I haven't been able to find a case where you are giving up precision in the cast that you don't already lose by using floating points.
// So it's probably fine unless proven otherwise.
#[allow(clippy::cast_precision_loss)]
#[expect(
clippy::cast_precision_loss,
reason = "So yes, as clippy points out, you technically lose precision here on the `*i as f64` cast. On the other hand, you already give up precision when you start using floats and I haven't been able to find a case where you are giving up precision in the cast that you don't already lose by using floating points. So it's probably fine unless proven otherwise."
)]
bril_rs::Literal::Int(i) => state
.env
.set(numified_code.dest.unwrap(), Value::Float(*i as f64)),
Expand Down
1 change: 1 addition & 0 deletions brilirs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo)]
#![warn(missing_docs)]
#![warn(clippy::allow_attributes)]
#![allow(clippy::float_cmp)]
#![allow(clippy::similar_names)]
#![allow(clippy::too_many_lines)]
Expand Down

0 comments on commit eb3bc4c

Please sign in to comment.