Skip to content

Commit

Permalink
clippy works again. enable it and fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
vaivaswatha committed Jan 25, 2025
1 parent 8012a99 commit 6f83c66
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ jobs:
- name: Tests (Release)
run: cargo test --release --workspace --verbose

# - name: Clippy
# run: cargo clippy --workspace -- -D warnings
- name: Clippy
run: cargo clippy --workspace -- -D warnings

- name: Format
run: cargo fmt --check
Expand Down
2 changes: 1 addition & 1 deletion pliron-derive/src/derive_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ trait ParsableBuilder<State: Default> {
fn build_body(input: &FmtInput, state: &mut State) -> Result<TokenStream> {
if let FmtData::Enum(r#enum) = &input.data {
let enum_name = r#enum.name.clone();
assert!(r#enum.variants.len() > 0, "Enum has no variants");
assert!(!r#enum.variants.is_empty(), "Enum has no variants");
let variant_name_parsed = quote! {
let variant_name_parsed =
::pliron::identifier::Identifier::parser(()).
Expand Down
4 changes: 1 addition & 3 deletions pliron-derive/src/irfmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ impl Enum {
}
// parse the variant's format string given as an attribute
let fmt_str = v
.attrs
.iter()
.next()
.attrs.first()
.map(|attr| {
if attr.path().is_ident("format") {
attr.parse_args::<LitStr>()
Expand Down
2 changes: 1 addition & 1 deletion pliron-llvm/tests/compile_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use assert_cmd::Command;
use expect_test::expect;
use tempfile::{tempdir, TempDir};

const CLANG_BINARY: &'static str = "clang-18";
const CLANG_BINARY: &str = "clang-18";

static RESOURCES_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
[env!("CARGO_MANIFEST_DIR"), "tests", "resources"]
Expand Down
6 changes: 3 additions & 3 deletions src/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct Iter<'a, T: LinkedList> {
ctx: &'a Context,
}

impl<'a, T: LinkedList> Clone for Iter<'a, T> {
impl<T: LinkedList> Clone for Iter<'_, T> {
fn clone(&self) -> Self {
Self {
next: self.next,
Expand All @@ -63,7 +63,7 @@ impl<'a, T: LinkedList> Clone for Iter<'a, T> {
}
}

impl<'a, T: LinkedList> Iterator for Iter<'a, T> {
impl<T: LinkedList> Iterator for Iter<'_, T> {
type Item = Ptr<T>;

fn next(&mut self) -> Option<Self::Item> {
Expand All @@ -86,7 +86,7 @@ impl<'a, T: LinkedList> Iterator for Iter<'a, T> {
}
}

impl<'a, T: LinkedList> DoubleEndedIterator for Iter<'a, T> {
impl<T: LinkedList> DoubleEndedIterator for Iter<'_, T> {
fn next_back(&mut self) -> Option<Self::Item> {
self.next_back.inspect(|curr| {
if *curr == self.next.expect("Some(next_back) => Some(next) violated") {
Expand Down
2 changes: 1 addition & 1 deletion src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ pub fn canonical_syntax_print(
op_type.disp(ctx),
)?;

if op.regions.len() > 0 {
if !op.regions.is_empty() {
regions.fmt(ctx, state, f)?;
}
Ok(())
Expand Down
26 changes: 13 additions & 13 deletions src/parsable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,19 @@ impl<'a> State<'a> {
}
}

impl<'a> Drop for State<'a> {
impl Drop for State<'_> {
// Ensure that `parent_for_regions` doesn't have any regions left and erase it.
fn drop(&mut self) {
let parent_for_regions = self.parent_for_regions;
// This assert is disabled because, if the parser fails, then we could have
// regions that were constructed but not moved to their parents.
assert!(
true || parent_for_regions.deref(self.ctx).num_regions() == 0,
"Regions constructed during parsing must be moved to \
their respective parents before the end of parsing"
);
/*
assert!(
parent_for_regions.deref(self.ctx).num_regions() == 0,
"Regions constructed during parsing must be moved to \
their respective parents before the end of parsing"
);
*/
Operation::erase(parent_for_regions, self.ctx);
}
}
Expand All @@ -78,7 +80,7 @@ impl<'a> Drop for State<'a> {
/// Buffering and positioning are automatically handled hereafter.
pub struct CharIterator<'a>(Box<dyn Iterator<Item = char> + 'a>);

impl<'a> Iterator for CharIterator<'a> {
impl Iterator for CharIterator<'_> {
type Item = char;

fn next(&mut self) -> Option<Self::Item> {
Expand All @@ -97,7 +99,7 @@ pub type StateStream<'a> = Stream<
State<'a>,
>;

impl<'a> Located for StateStream<'a> {
impl Located for StateStream<'_> {
fn loc(&self) -> location::Location {
location::Location::SrcPos {
src: self.state.src,
Expand Down Expand Up @@ -227,7 +229,7 @@ impl<'a, T> IntoParseResult<'a, T> for Result<T> {
}
}

impl<'a> From<result::Error> for ParseError<StateStream<'a>> {
impl From<result::Error> for ParseError<StateStream<'_>> {
fn from(value: result::Error) -> Self {
let position = if let Location::SrcPos { pos, .. } = value.loc {
pos
Expand All @@ -238,11 +240,9 @@ impl<'a> From<result::Error> for ParseError<StateStream<'a>> {
}
}

impl<'a> From<result::Error>
for combine::error::Commit<Tracked<Errors<char, char, SourcePosition>>>
{
impl From<result::Error> for combine::error::Commit<Tracked<Errors<char, char, SourcePosition>>> {
fn from(value: result::Error) -> Self {
let res: StdParseResult2<(), ParseError<StateStream<'a>>> =
let res: StdParseResult2<(), ParseError<StateStream<'_>>> =
combine::ParseResult::CommitErr(value.into()).into();
res.err().unwrap()
}
Expand Down
4 changes: 2 additions & 2 deletions src/printable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct Displayable<'t, 'c, T: Printable + ?Sized> {
state: State,
}

impl<'t, 'c, T: Printable + ?Sized> Display for Displayable<'t, 'c, T> {
impl<T: Printable + ?Sized> Display for Displayable<'_, '_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.t.fmt(self.ctx, &self.state, f)
}
Expand Down Expand Up @@ -179,7 +179,7 @@ impl_printable_for_display!(&str);
impl_printable_for_display!(String);
impl_printable_for_display!(u64);

impl<'a, T: Printable + ?Sized> Printable for &'a T {
impl<T: Printable + ?Sized> Printable for &T {
fn fmt(&self, ctx: &Context, state: &State, f: &mut fmt::Formatter<'_>) -> fmt::Result {
(*self).fmt(ctx, state, f)
}
Expand Down
6 changes: 3 additions & 3 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ impl Ptr<BasicBlock> {
// We do not check [Self::get_defnode_ref].uses here because
// we'd have to go through them all. We do not have a Use<_>
// object to directly check membership.
pred.deref(ctx).get_tail().map_or(false, |pred_term| {
pred_term.deref(ctx).successors().any(|succ| self == &succ)
})
pred.deref(ctx)
.get_tail()
.is_some_and(|pred_term| pred_term.deref(ctx).successors().any(|succ| self == &succ))
}
/// Retarget predecessors (that satisfy pred) to `other`.
pub fn retarget_some_preds_to<P: Fn(&Context, Ptr<BasicBlock>) -> bool>(
Expand Down

0 comments on commit 6f83c66

Please sign in to comment.