Skip to content

Miri engine is too permissive with type-changing MIR assignments #70405

Description

@oli-obk

src.layout.details == dest.layout.details,
just checks whether the layout of the target and value of an assignment is the same. The only time the types can differ is when assigning a &mut T to a &T variable. We should instead employ a function like

fn mir_assign_valid_types(dst: Ty<'tcx>, src: Ty<'tcx>) {
    dst == src || match (&dst.kind, &src.kind) {
        (ty::Ref(_, _, dst_pointee), ty::Ref(_, _, src_pointee)) => dst_pointee == src_pointee,
        _ => false,
    }
}

(source #69700 (comment))

be sure to also add appropriate mutability checks to the patterns (mutable for the source, immutable for the dest)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions