Skip to content

Soundness hole: We don't catch non-const assoc fns in const contexts if the trait isn't #[const_trait] #12

Closed
rust-lang/rust
#132169
@fmease

Description

@fmease
Member

Uplifted from rust-lang/rust#125831 cuz I consider this pretty important.

MCVE:

//@ compile-flags: -Znext-solver
#![feature(effects, const_trait_impl)]
#![crate_type = "lib"]

// #[const_trait] // <-- intentionally absent
trait NonConstTrait {
    fn something();
}

impl NonConstTrait for () {
    fn something() {}
}

const fn f() { <()>::something() } // wrongfully accepted!
                                   // should've raised Unimplemented( (): ~const NonConstTrait )
                                   // or at least rejected this call some other way

Activity

fmease

fmease commented on Oct 25, 2024

@fmease
MemberAuthor

So I haven't dug into details yet as to why it slips up but from a high-level perspective "things" may "generate" Ty: ~const NonConstTrait obligations/goals even if ~const NonConstTrait is ill-formed in the surface language (~const can only be applied to #[const_trait] traits).

compiler-errors

compiler-errors commented on Oct 25, 2024

@compiler-errors
Member
compiler-errors

compiler-errors commented on Oct 25, 2024

@compiler-errors
Member

I'm currently working on improving const validation in MIR, though, so I'll claim this as a placeholder. Thanks for raising this issue, tho.

added a commit that references this issue on Oct 26, 2024

Rollup merge of rust-lang#132169 - fee1-dead-contrib:consttraitsck, r…

18aa883
added 2 commits that reference this issue on Oct 26, 2024

Rollup merge of rust-lang#132169 - fee1-dead-contrib:consttraitsck, r…

569f187

Rollup merge of rust-lang#132169 - fee1-dead-contrib:consttraitsck, r…

bafe790
added a commit that references this issue on Oct 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @compiler-errors@fmease

    Issue actions

      Soundness hole: We don't catch non-const assoc fns in const contexts if the trait isn't `#[const_trait]` · Issue #12 · rust-lang/project-const-traits