Semantic check of mut restrictions - #159906
Conversation
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
mut restrictions
| // MIR-level lints. | ||
| &Lint(check_inline::CheckForceInline), | ||
| &Lint(check_call_recursion::CheckCallRecursion), | ||
| &Lint(check_packed_ref::CheckPackedRef), | ||
| &Lint(check_const_item_mutation::CheckConstItemMutation), | ||
| &Lint(check_mut_restriction::CheckMutRestriction), | ||
| &Lint(function_item_references::FunctionItemReferences), |
There was a problem hiding this comment.
(Not for this PR) Most of those so called "MIR lints" actually emit hard errors of an lint. We should find another name as it's quite confusing to see a "lint" emit a hard errors.
| fn change_fooe(foo: &mut foo::bar::FooE) { | ||
| match foo { | ||
| foo::bar::FooE::Default => {} | ||
| foo::bar::FooE::Var { | ||
| alpha, //[e2015]~ ERROR field cannot be mutated outside `foo::bar` | ||
| //[e2018]~^ ERROR field cannot be mutated outside `crate::foo::bar` | ||
| beta, //[e2015]~ ERROR field cannot be mutated outside `foo` | ||
| //[e2018]~^ ERROR field cannot be mutated outside `crate::foo` | ||
| gamma, // ok | ||
| } => { | ||
| *alpha = 1; | ||
| *beta = 1; | ||
| *gamma = 1; | ||
| } | ||
| foo::bar::FooE::Tup( | ||
| alpha, //[e2015]~ ERROR field cannot be mutated outside `foo::bar` | ||
| //[e2018]~^ ERROR field cannot be mutated outside `crate::foo::bar` | ||
| beta, //[e2015]~ ERROR field cannot be mutated outside `foo` | ||
| //[e2018]~^ ERROR field cannot be mutated outside `crate::foo` | ||
| gamma, // ok | ||
| ) => { | ||
| *alpha = 1; | ||
| *beta = 1; | ||
| *gamma = 1; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
@Nadrieril, can you think of another match related tests we should be testing regarding mut-restrictions?
|
cc @cjgillot for the MIR related part since you know more about it than me |
|
@rustbot ready |
This comment has been minimized.
This comment has been minimized.
f99a126 to
673a9db
Compare
|
I was just thinking of something, we should probably remove the incompleteness of the feature. |
This comment has been minimized.
This comment has been minimized.
673a9db to
490f95c
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
I'll review this PR this weekend. |
|
Squashed the commits, and removed the incompleteness marker. |
View all comments
This PR implements semantic checks for
mutrestrictions proposed in RFC 3323, as part of the related GSoC project.It lowers field restriction information from HIR into
rustc_middle::ty::FieldDefand adds a MIR-level lint that rejects restricted field mutations and struct expressions. As parsing (#156824) and path resolution (#159125) have already been implemented, this PR provides a working implementation ofmutrestrictions.Tracking issue: #105077
r? @Urgau
cc @jhpratt