Skip to content

Commit

Permalink
Cleanup aided by clippy (#619)
Browse files Browse the repository at this point in the history
Should fix the new lint ci errors due to rust 1.83.0 new clippy lints

On rust 1.83.0 with clippy `cargo clippy -- -D clippy::nursery -A
clippy::use_self`

There are some more places where i could add const (in mut self places)
but thats from 1.83.0 itself and i dont know if you are ok with setting
the MSRV to it, so i didnt add those.
  • Loading branch information
edg-l authored Dec 2, 2024
1 parent 8736ec8 commit 8ce23cf
Show file tree
Hide file tree
Showing 30 changed files with 114 additions and 111 deletions.
2 changes: 1 addition & 1 deletion macro/src/dialect/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Parse for DialectInput {
}

Ok(Self {
name: name.ok_or(input.error("dialect name required"))?,
name: name.ok_or_else(|| input.error("dialect name required"))?,
table_gen,
td_file,
include_directories: includes,
Expand Down
14 changes: 7 additions & 7 deletions macro/src/dialect/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ impl<'a> Operation<'a> {
&self.name
}

pub fn can_infer_type(&self) -> bool {
pub const fn can_infer_type(&self) -> bool {
self.can_infer_type
}

pub fn dialect_name(&self) -> &str {
pub const fn dialect_name(&self) -> &str {
self.dialect_name
}

pub fn operation_name(&self) -> &str {
pub const fn operation_name(&self) -> &str {
self.operation_name
}

Expand Down Expand Up @@ -153,7 +153,7 @@ impl<'a> Operation<'a> {
&self.description
}

pub fn constructor_identifier(&self) -> &Ident {
pub const fn constructor_identifier(&self) -> &Ident {
&self.constructor_identifier
}

Expand Down Expand Up @@ -227,7 +227,7 @@ impl<'a> Operation<'a> {
.chain(self.required_attributes().map(convert))
}

fn collect_successors(definition: Record<'a>) -> Result<Vec<Successor>, Error> {
fn collect_successors(definition: Record<'a>) -> Result<Vec<Successor<'a>>, Error> {
definition
.dag_value("successors")?
.args()
Expand All @@ -242,7 +242,7 @@ impl<'a> Operation<'a> {
.collect()
}

fn collect_regions(definition: Record<'a>) -> Result<Vec<Region>, Error> {
fn collect_regions(definition: Record<'a>) -> Result<Vec<Region<'a>>, Error> {
definition
.dag_value("regions")?
.args()
Expand Down Expand Up @@ -307,7 +307,7 @@ impl<'a> Operation<'a> {
definition: Record<'a>,
same_size: bool,
attribute_sized: bool,
) -> Result<(Vec<OperationResult>, usize), Error> {
) -> Result<(Vec<OperationResult<'a>>, usize), Error> {
Self::collect_elements(
&Self::dag_constraints(definition, "results")?
.into_iter()
Expand Down
4 changes: 2 additions & 2 deletions macro/src/dialect/operation/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ impl<'a> Attribute<'a> {
})
}

pub fn set_identifier(&self) -> &Ident {
pub const fn set_identifier(&self) -> &Ident {
&self.set_identifier
}

pub fn remove_identifier(&self) -> &Ident {
pub const fn remove_identifier(&self) -> &Ident {
&self.remove_identifier
}

Expand Down
6 changes: 3 additions & 3 deletions macro/src/dialect/operation/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ impl<'a> OperationBuilder<'a> {
}
}

pub fn operation(&self) -> &Operation {
pub const fn operation(&self) -> &Operation {
self.operation
}

pub fn identifier(&self) -> &Ident {
pub const fn identifier(&self) -> &Ident {
&self.identifier
}

pub fn type_state(&self) -> &TypeState {
pub const fn type_state(&self) -> &TypeState {
&self.type_state
}

Expand Down
2 changes: 1 addition & 1 deletion macro/src/dialect/operation/builder/type_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct TypeState {
}

impl TypeState {
pub fn new(
pub const fn new(
results: Vec<String>,
operands: Vec<String>,
regions: Vec<String>,
Expand Down
2 changes: 1 addition & 1 deletion macro/src/dialect/operation/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl<'a> Region<'a> {
})
}

pub fn is_variadic(&self) -> bool {
pub const fn is_variadic(&self) -> bool {
self.variadic
}
}
Expand Down
2 changes: 1 addition & 1 deletion macro/src/dialect/operation/successor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl<'a> Successor<'a> {
})
}

pub fn is_variadic(&self) -> bool {
pub const fn is_variadic(&self) -> bool {
self.variadic
}
}
Expand Down
8 changes: 4 additions & 4 deletions macro/src/dialect/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ impl Type {
}
}

pub fn is_optional(&self) -> bool {
pub const fn is_optional(&self) -> bool {
self.optional
}

pub fn is_variadic(&self) -> bool {
pub const fn is_variadic(&self) -> bool {
self.variadic
}

// TODO Support variadic-of-variadic.
#[allow(unused)]
pub fn is_variadic_of_variadic(&self) -> bool {
pub const fn is_variadic_of_variadic(&self) -> bool {
self.variadic_of_variadic
}

pub fn is_unfixed(&self) -> bool {
pub const fn is_unfixed(&self) -> bool {
self.is_variadic() || self.is_optional()
}
}
2 changes: 1 addition & 1 deletion macro/src/dialect/utility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn sanitize_name(name: &str) -> Result<Ident, Error> {

// Try to parse the string as an ident, and prefix the identifier
// with "r#" if it is not a valid identifier.
Ok(syn::parse_str::<Ident>(&name).unwrap_or(format_ident!("r#{}", name)))
Ok(syn::parse_str::<Ident>(&name).unwrap_or_else(|_| format_ident!("r#{}", name)))
}

pub fn sanitize_documentation(string: &str) -> Result<String, Error> {
Expand Down
8 changes: 4 additions & 4 deletions melior/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,19 @@ impl<'c> ContextRef<'c> {
}
}

impl<'c> PartialEq for ContextRef<'c> {
impl PartialEq for ContextRef<'_> {
fn eq(&self, other: &Self) -> bool {
unsafe { mlirContextEqual(self.raw, other.raw) }
}
}

impl<'c> PartialEq<Context> for ContextRef<'c> {
impl PartialEq<Context> for ContextRef<'_> {
fn eq(&self, other: &Context) -> bool {
self == &other.to_ref()
}
}

impl<'c> Eq for ContextRef<'c> {}
impl Eq for ContextRef<'_> {}

#[cfg(test)]
mod tests {
Expand Down Expand Up @@ -320,7 +320,7 @@ mod tests {
fn context_to_ref() {
let ctx = Context::new();
let ctx_ref = ctx.to_ref();
let ctx_ref_to_ref: &Context = unsafe { &ctx_ref.to_ref() };
let ctx_ref_to_ref: &Context = unsafe { ctx_ref.to_ref() };

assert_eq!(&ctx_ref, ctx_ref_to_ref);
}
Expand Down
4 changes: 2 additions & 2 deletions melior/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct Diagnostic<'c> {
phantom: PhantomData<&'c ()>,
}

impl<'c> Diagnostic<'c> {
impl Diagnostic<'_> {
pub fn location(&self) -> Location {
unsafe { Location::from_raw(mlirDiagnosticGetLocation(self.raw)) }
}
Expand Down Expand Up @@ -60,7 +60,7 @@ impl<'c> Diagnostic<'c> {
}
}

impl<'a> Display for Diagnostic<'a> {
impl Display for Diagnostic<'_> {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
let mut data = (formatter, Ok(()));

Expand Down
4 changes: 2 additions & 2 deletions melior/src/dialect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ impl<'c> Dialect<'c> {
}
}

impl<'c> PartialEq for Dialect<'c> {
impl PartialEq for Dialect<'_> {
fn eq(&self, other: &Self) -> bool {
unsafe { mlirDialectEqual(self.raw, other.raw) }
}
}

impl<'c> Eq for Dialect<'c> {}
impl Eq for Dialect<'_> {}

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion melior/src/dialect/llvm/load_store_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<'c> LoadStoreOptions<'c> {
}

/// Sets TBAA metadata.
pub fn tbaa(mut self, tbaa: ArrayAttribute<'c>) -> Self {
pub const fn tbaa(mut self, tbaa: ArrayAttribute<'c>) -> Self {
self.tbaa = Some(tbaa);
self
}
Expand Down
8 changes: 4 additions & 4 deletions melior/src/ir/affine_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ impl<'c> AffineMap<'c> {
}
}

impl<'c> PartialEq for AffineMap<'c> {
impl PartialEq for AffineMap<'_> {
fn eq(&self, other: &Self) -> bool {
unsafe { mlirAffineMapEqual(self.raw, other.raw) }
}
}

impl<'c> Eq for AffineMap<'c> {}
impl Eq for AffineMap<'_> {}

impl<'c> Display for AffineMap<'c> {
impl Display for AffineMap<'_> {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
let mut data = (formatter, Ok(()));

Expand All @@ -67,7 +67,7 @@ impl<'c> Display for AffineMap<'c> {
}
}

impl<'c> Debug for AffineMap<'c> {
impl Debug for AffineMap<'_> {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
Display::fmt(self, formatter)
}
Expand Down
8 changes: 4 additions & 4 deletions melior/src/ir/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ impl<'c> AttributeLike<'c> for Attribute<'c> {
}
}

impl<'c> PartialEq for Attribute<'c> {
impl PartialEq for Attribute<'_> {
fn eq(&self, other: &Self) -> bool {
unsafe { mlirAttributeEqual(self.raw, other.raw) }
}
}

impl<'c> Eq for Attribute<'c> {}
impl Eq for Attribute<'_> {}

impl<'c> Display for Attribute<'c> {
impl Display for Attribute<'_> {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
let mut data = (formatter, Ok(()));

Expand All @@ -116,7 +116,7 @@ impl<'c> Display for Attribute<'c> {
}
}

impl<'c> Debug for Attribute<'c> {
impl Debug for Attribute<'_> {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
Display::fmt(self, formatter)
}
Expand Down
24 changes: 12 additions & 12 deletions melior/src/ir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl<'c> Block<'c> {
}

/// Converts a block into a raw object.
pub fn into_raw(self) -> MlirBlock {
pub const fn into_raw(self) -> MlirBlock {
let block = self.raw;

forget(self);
Expand All @@ -223,21 +223,21 @@ impl<'c> Block<'c> {
}
}

impl<'c> Drop for Block<'c> {
impl Drop for Block<'_> {
fn drop(&mut self) {
unsafe { mlirBlockDestroy(self.raw) };
}
}

impl<'c> PartialEq for Block<'c> {
impl PartialEq for Block<'_> {
fn eq(&self, other: &Self) -> bool {
unsafe { mlirBlockEqual(self.raw, other.raw) }
}
}

impl<'c> Eq for Block<'c> {}
impl Eq for Block<'_> {}

impl<'c> Display for Block<'c> {
impl Display for Block<'_> {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
let mut data = (formatter, Ok(()));

Expand All @@ -253,7 +253,7 @@ impl<'c> Display for Block<'c> {
}
}

impl<'c> Debug for Block<'c> {
impl Debug for Block<'_> {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
writeln!(formatter, "Block(")?;
Display::fmt(self, formatter)?;
Expand All @@ -268,7 +268,7 @@ pub struct BlockRef<'c, 'a> {
_reference: PhantomData<&'a Block<'c>>,
}

impl<'c, 'a> BlockRef<'c, 'a> {
impl BlockRef<'_, '_> {
/// Creates a block reference from a raw object.
///
/// # Safety
Expand All @@ -295,29 +295,29 @@ impl<'c, 'a> BlockRef<'c, 'a> {
}
}

impl<'c, 'a> Deref for BlockRef<'c, 'a> {
impl<'a> Deref for BlockRef<'_, 'a> {
type Target = Block<'a>;

fn deref(&self) -> &Self::Target {
unsafe { transmute(self) }
}
}

impl<'c, 'a> PartialEq for BlockRef<'c, 'a> {
impl PartialEq for BlockRef<'_, '_> {
fn eq(&self, other: &Self) -> bool {
unsafe { mlirBlockEqual(self.raw, other.raw) }
}
}

impl<'c, 'a> Eq for BlockRef<'c, 'a> {}
impl Eq for BlockRef<'_, '_> {}

impl<'c, 'a> Display for BlockRef<'c, 'a> {
impl Display for BlockRef<'_, '_> {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
Display::fmt(self.deref(), formatter)
}
}

impl<'c, 'a> Debug for BlockRef<'c, 'a> {
impl Debug for BlockRef<'_, '_> {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
Debug::fmt(self.deref(), formatter)
}
Expand Down
Loading

0 comments on commit 8ce23cf

Please sign in to comment.