Trait LintPass `fn name(&self) -> &'static str` can refactor to `const NAME: &'static = unimplment!()` since 1.57+ support panic on const

I think compiler/rustc_lint_defs/src/lib.rs

pub trait LintPass { fn name(&self) -> &'static str; }

can use const name

pub trait LintPass { const NAME: &'static str = unimplment!(); }

use unimplment!() to force each impl of LintPass to set the const NAME

trait LintPass {
    const NAME: &'static str;
}

has been supported since rust 1.20.

There is however one problem. EarlyLintPassObject and LateLintPassObject which both use LintPass need to be turned into trait objects. For this LintPass needs to be object safe. Traits constaining consts aren't object safe.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.