Skip to content

Commit 04d65f9

Browse files
committed
Auto merge of rust-lang#148434 - oli-obk:inherent-const-impl, r=fee1-dead
Inherent const impl Some constifications are annoying because we need to repeat `T: Trait` bounds from an impl block on the individual constified `const fn`s as `T: [const] Trait`. We've brainstormed solutions before, and one would be to have separate `const impl` blocks or sth. However the final syntax will look, I decided to just impl this syntax and either have sth nice on nightly to work with or at least move the discussion along. Also interacts with the discussion around `impl const Trait for Type` vs `const impl Trait for Type`, as we may want to use the latter to keep inherent and trait impls in sync (unless we come up with even another scheme). * [ ] rustdoc + tests * [ ] macro stability /regression tests r? `@fee1-dead` cc `@traviscross` `@rust-lang/project-const-traits`
2 parents 9e0f3ec + f893111 commit 04d65f9

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

clippy_lints/src/derivable_impls.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
232232
of_trait: Some(of_trait),
233233
items: [child],
234234
self_ty,
235+
constness,
235236
..
236237
}) = item.kind
237238
&& !cx.tcx.is_automatically_derived(item.owner_id.to_def_id())
@@ -247,7 +248,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
247248
&& !attrs.iter().any(|attr| attr.doc_str().is_some())
248249
&& cx.tcx.hir_attrs(impl_item_hir).is_empty()
249250
{
250-
let is_const = of_trait.constness == hir::Constness::Const;
251+
let is_const = constness == hir::Constness::Const;
251252
if adt_def.is_struct() {
252253
check_struct(
253254
cx,

clippy_utils/src/ast_utils/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,20 +495,22 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
495495
of_trait: lot,
496496
self_ty: lst,
497497
items: li,
498+
constness: lc,
498499
}),
499500
Impl(ast::Impl {
500501
generics: rg,
501502
of_trait: rot,
502503
self_ty: rst,
503504
items: ri,
505+
constness: rc,
504506
}),
505507
) => {
506508
eq_generics(lg, rg)
507509
&& both(lot.as_deref(), rot.as_deref(), |l, r| {
508510
matches!(l.safety, Safety::Default) == matches!(r.safety, Safety::Default)
509511
&& matches!(l.polarity, ImplPolarity::Positive) == matches!(r.polarity, ImplPolarity::Positive)
510512
&& eq_defaultness(l.defaultness, r.defaultness)
511-
&& matches!(l.constness, ast::Const::No) == matches!(r.constness, ast::Const::No)
513+
&& matches!(lc, ast::Const::No) == matches!(rc, ast::Const::No)
512514
&& eq_path(&l.trait_ref.path, &r.trait_ref.path)
513515
})
514516
&& eq_ty(lst, rst)

0 commit comments

Comments
 (0)