Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scripts generated by sea-orm-cli cannot pass clippy #296

Closed
YoshieraHuang opened this issue Nov 6, 2021 · 5 comments · Fixed by #303
Closed

scripts generated by sea-orm-cli cannot pass clippy #296

YoshieraHuang opened this issue Nov 6, 2021 · 5 comments · Fixed by #303
Assignees

Comments

@YoshieraHuang
Copy link
Contributor

This is typical script generated by sea-orm-cli without existing relation:

//! SeaORM Entity. Generated by sea-orm-codegen 0.3.2

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "posts")]
pub struct Model {
    #[sea_orm(primary_key)]
    #[serde(skip_deserializing)]
    pub id: i32,
    pub title: String,
    #[sea_orm(column_type = "Text")]
    pub text: String,
}

#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {}

impl RelationTrait for Relation {
    fn def(&self) -> RelationDef {
        match self {
            _ => panic!("No RelationDef"),
        }
    }
}

impl ActiveModelBehavior for ActiveModel {}

When I run cargo cilppy, there is a warning:

warning: this match could be replaced by its body itself
  --> src/post.rs:22:9
   |
22 | /         match self {
23 | |             _ => panic!("No RelationDef"),
24 | |         }
   | |_________^ help: consider using the match body instead: `panic!("No RelationDef")`
   |
   = note: `#[warn(clippy::match_single_binding)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_single_binding

Could someone fix it?

@billy1624
Copy link
Member

Hi @YoshieraHuang, thanks for pointing that out! We could fix it for sure.

@billy1624 billy1624 self-assigned this Nov 6, 2021
@tyt2y3
Copy link
Member

tyt2y3 commented Nov 6, 2021

Hi, it seems that you are not using DeriveRelation, it shouldn't warn when it is expanded inside the derive macro.

Or is it really how we generate the entity for now? @billy1624

@billy1624
Copy link
Member

billy1624 commented Nov 6, 2021

Or is it really how we generate the entity for now? @billy1624

Yes! It's generated by codegen not derived by derive macros

@tyt2y3
Copy link
Member

tyt2y3 commented Nov 6, 2021

Yes! It's generated by codegen not derived by derive macros

Oh, the following shouldn't warn:

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

// no need for impl RelationTrait for Relation

@billy1624
Copy link
Member

Yes! It's generated by codegen not derived by derive macros

Oh, the following shouldn't warn:

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

// no need for impl RelationTrait for Relation

Correct, but the point is codegen with expanded flag will generate the following...

#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {}

impl RelationTrait for Relation {
    fn def(&self) -> RelationDef {
        match self {
            _ => panic!("No RelationDef"),
        }
    }
}

I will fix it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants