Skip to content

#![feature(mut_restriction)] wrongly permits using tuple constructor #160891

Description

@jhpratt

Consider the following code.

#![feature(mut_restriction)]

mod inner {
    pub(crate) struct Wrapper(#[expect(dead_code)] pub(crate) mut(self) u8);
}

fn param_is_fn(_: fn(u8) -> inner::Wrapper) {}
fn param_impl_fn(_: impl Fn(u8) -> inner::Wrapper) {}
fn param_impl_fn_once(_: impl FnOnce(u8) -> inner::Wrapper) {}
fn param_impl_fn_mut(_: impl FnMut(u8) -> inner::Wrapper) {}

fn main() {
    let _ = inner::Wrapper;
    param_is_fn(inner::Wrapper);
    param_impl_fn(inner::Wrapper);
    param_impl_fn_once(inner::Wrapper);
    param_impl_fn_mut(inner::Wrapper);
}

Every line in main should result in a compiler error because it is not permitted to construct Wrapper directly outside of inner. I believe the simplest way to approach this is to exclude any situation where the auto-generated constructor/function is an expression.

cc @CoCo-Japan-pan @Urgau

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-mut_restriction`#![feature(mut_restriction)]`T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions