Skip to content

Commit 33232af

Browse files
authored
Rollup merge of rust-lang#144291 - oli-obk:const_trait_alias, r=fee1-dead
Constify trait aliases Allow `const trait Foo = Bar + [const] Baz;` trait alias declarations. Their rules are the same as with super traits of const traits. So `[const] Baz` or `const Baz` is only required for `[const] Foo` or `const Foo` bounds respectively. tracking issue rust-lang#41517 (part of the general trait alias feature gate, but I can split it out into a separate const trait alias feature gate. I just assumed that const traits would stabilize before trait aliases, and we'd want to stabilize trait aliases together with const trait aliases at the same time) r? ``@compiler-errors`` ``@fee1-dead``
2 parents 52fa003 + 3f5ea6b commit 33232af

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

clippy_lints/src/item_name_repetitions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ impl LateLintPass<'_> for ItemNameRepetitions {
528528
| ItemKind::Macro(ident, ..)
529529
| ItemKind::Static(_, ident, ..)
530530
| ItemKind::Trait(_, _, _, ident, ..)
531-
| ItemKind::TraitAlias(ident, ..)
531+
| ItemKind::TraitAlias(_, ident, ..)
532532
| ItemKind::TyAlias(ident, ..)
533533
| ItemKind::Union(ident, ..)
534534
| ItemKind::Use(_, UseKind::Single(ident)) => ident,

clippy_utils/src/ast_utils/mod.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,24 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
473473
&& over(lb, rb, eq_generic_bound)
474474
&& over(lis, ris, |l, r| eq_item(l, r, eq_assoc_item_kind))
475475
},
476-
(TraitAlias(li, lg, lb), TraitAlias(ri, rg, rb)) => {
477-
eq_id(*li, *ri) && eq_generics(lg, rg) && over(lb, rb, eq_generic_bound)
476+
(
477+
TraitAlias(box ast::TraitAlias {
478+
ident: li,
479+
generics: lg,
480+
bounds: lb,
481+
constness: lc,
482+
}),
483+
TraitAlias(box ast::TraitAlias {
484+
ident: ri,
485+
generics: rg,
486+
bounds: rb,
487+
constness: rc,
488+
}),
489+
) => {
490+
matches!(lc, ast::Const::No) == matches!(rc, ast::Const::No)
491+
&& eq_id(*li, *ri)
492+
&& eq_generics(lg, rg)
493+
&& over(lb, rb, eq_generic_bound)
478494
},
479495
(
480496
Impl(ast::Impl {

0 commit comments

Comments
 (0)