Skip to content

check mut-restriction when tuple constructor is used as a value - #160928

Open
im-lunex wants to merge 2 commits into
rust-lang:mainfrom
im-lunex:fix_#160891
Open

check mut-restriction when tuple constructor is used as a value#160928
im-lunex wants to merge 2 commits into
rust-lang:mainfrom
im-lunex:fix_#160891

Conversation

@im-lunex

@im-lunex im-lunex commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

this fixes a bug where tuple struct constructors could bypass mut field restrictions when used as function values instead of being called directly. right now CheckMutRestriction only checks struct expressions like Wrapper(5). but referencing inner::Wrapper as a value was allowed, which let outsiders construct structs with restricted fields.

Fixes #160891

@rustbot

rustbot commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 11, 2026
@rustbot

rustbot commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

r? @mu001999

rustbot has assigned @mu001999.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, mir, mir-opt
  • compiler, mir, mir-opt expanded to 75 candidates
  • Random selection from 18 candidates

@rust-log-analyzer

This comment has been minimized.

@Urgau Urgau assigned Urgau and unassigned mu001999 Aug 11, 2026

@Urgau Urgau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good. Left some comments.

View changes since this review

Comment on lines +41 to +42
&& let def_kind = self.tcx.def_kind(def_id)
&& let DefKind::Ctor(ctor_of, _) = def_kind

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
&& let def_kind = self.tcx.def_kind(def_id)
&& let DefKind::Ctor(ctor_of, _) = def_kind
&& let DefKind::Ctor(ctor_of, _) = self.tcx.def_kind(def_id)

pub struct Wrapper(pub mut(self) u8);

pub enum EnumTup {
Tup(mut(self) u8),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add more tests. Like making sure one can still construct EnumTup::Foo and that multi fields works as expected.

Suggested change
Tup(mut(self) u8),
Tup(mut(self) u8),
Foo(u8),
Bar(u8, mut(crate) u8),

In general, let's try to be exhaustive.

@Urgau

Urgau commented Aug 11, 2026

Copy link
Copy Markdown
Member

cc @jhpratt @CoCo-Japan-pan
@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 11, 2026
@rustbot

rustbot commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

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

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

5 participants