Skip to content

remove MutTy - #163327

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
cyrgani:mut-ty
Sep 28, 2026
Merged

rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
cyrgani:mut-ty

Conversation

@cyrgani

@cyrgani cyrgani commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

This PR removes ast::MutTy and hir::MutTy and inlines their two fields directly into their corresponding TypeKind variants. These types probably made sense in pre-1.0 versions where it still had a syntax-level representation with things like [mut T]. Nowadays, it is just a type that is used in some, but not all places to group a type and a mutability together (for example, rustc_type_ir does not include such a wrapper). It also has no methods and just makes some match statements more verbose. Removing it makes them more readable.

@rustbot

rustbot commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

The parser was modified, potentially altering the grammar of (stable) Rust
which would be a breaking change.

cc @fmease

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

clippy is developed in its own repository. If possible, consider making this change to rust-lang/rust-clippy instead.

cc @rust-lang/clippy

rustfmt is developed in its own repository. If possible, consider making this change to rust-lang/rustfmt instead.

cc @rust-lang/rustfmt

Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs

cc @ZuseZ4

HIR ty lowering was modified

cc @fmease

Some changes occurred in compiler/rustc_ast/src/expand/autodiff_attrs.rs

cc @ZuseZ4

@rustbot rustbot added F-autodiff `#![feature(autodiff)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. labels Sep 25, 2026
@rustbot

rustbot commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

r? @mejrs

rustbot has assigned @mejrs.
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
  • compiler expanded to 77 candidates
  • Random selection from 21 candidates

@rust-log-analyzer

This comment has been minimized.

@oli-obk

oli-obk commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Huh I thought we had this before and changed at some point to bundle the pointer with its mutability. Or was that only in TyKind?

Either way, we should keep all three in sync, so also do the change for TyKind::Ref and Ptr, or keep all three in the MutTy system.

@cyrgani

cyrgani commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

It was removed from rustc_type_ir with #122852 and rust-lang/types-team#124.

@mejrs mejrs 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.

Overall the change looks good to me.

I have two thoughts about this (and please disagree if you disagree)

There are many changes like

- let TyKind::Ptr(_) = ret_ty.kind
+ let TyKind::Ptr(..) = ret_ty.kind

The downside of this is that it'll continue to compile if we add or remove fields in the future. It is more robust to do:

- let TyKind::Ptr(_) = ret_ty.kind
+ let TyKind::Ptr(_, _) = ret_ty.kind

(same for the Ref types)

Second, there a couple of cases where this happens:

let ty =...;

let Ptr(ty, _) = ty.kind

// ty is used later

It is rather error prone to alias variables of a same type in this manner. Usually, but not always, the code here chooses a different name to get around this. Can you choose one convention and apply it everywhere? Can be something like pointee_ty, ref_ty, inner_ty, etc, I don't really care about which one.

View changes since this review

@cyrgani

cyrgani commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Regarding 1., I don't see this as much of a downside. It would make refactorings like this one easier and I would expect that if a new field was to be added or removed, these places would mostly not care and ignore the field as well. (And there are already several preexisting cases of Ptr(..) and Ref(..).)

Regarding 2., I'll change this tomorrow.

TyKind::Ptr(MutTy { ty, .. }) => (Pat::Str("*"), ast_ty_search_pat(ty).1),
TyKind::Ref(_, MutTy { ty, .. }) | TyKind::PinnedRef(_, MutTy { ty, .. }) => {
TyKind::Ptr( ty, .. ) => (Pat::Str("*"), ast_ty_search_pat(ty).1),
TyKind::Ref(_, ty, ..) | TyKind::PinnedRef(_, ty, .. ) => {

@cyrgani cyrgani Sep 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

why was this extra whitespace neither detected by x fmt nor in CI?

View changes since the review

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.

X doesn't format clippy, you have to navigate to the clippy folder and use cargo dev fmt

@cyrgani

cyrgani commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

I've changed all the potentially ambiguous ty variable names to inner_ty (except in one case where another variable named inner_ty also already existed; I called it ref_ty there instead).

@mejrs mejrs 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.

@rust-bors

rust-bors Bot commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

📌 Commit ac6f00d has been approved by mejrs

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 28, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 28, 2026
remove `MutTy`

This PR removes `ast::MutTy` and `hir::MutTy` and inlines their two fields directly into their corresponding `TypeKind` variants. These types probably made sense in pre-1.0 versions where it still had a syntax-level representation with things like `[mut T]`. Nowadays, it is just a type that is used in some, but not all places to group a type and a mutability together (for example, `rustc_type_ir` does not include such a wrapper). It also has no methods and just makes some match statements more verbose. Removing it makes them more readable.
rust-bors Bot pushed a commit that referenced this pull request Sep 28, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #163327 (remove `MutTy`)
 - #162910 (Deterministic encoding of `DefPathHashMap`)
 - #163009 (dont store arbitrary parsed attributes in thir)
 - #162683 (Use attribute parser for `#[inline()]` attribute check)
 - #163429 (lint on `Ident::from_str_and_span` taking a string literal)
 - #163431 (Allow `#[repr(simd)]` with `f16b`)
 - #163433 (Support also `try-jobs:` to specify custom try jobs)
@rust-bors
rust-bors Bot merged commit 9e293c7 into rust-lang:main Sep 28, 2026
13 checks passed
rust-bors Bot pushed a commit that referenced this pull request Sep 28, 2026
Rollup merge of #163327 - cyrgani:mut-ty, r=mejrs

remove `MutTy`

This PR removes `ast::MutTy` and `hir::MutTy` and inlines their two fields directly into their corresponding `TypeKind` variants. These types probably made sense in pre-1.0 versions where it still had a syntax-level representation with things like `[mut T]`. Nowadays, it is just a type that is used in some, but not all places to group a type and a mutability together (for example, `rustc_type_ir` does not include such a wrapper). It also has no methods and just makes some match statements more verbose. Removing it makes them more readable.
@rustbot rustbot added this to the 1.101.0 milestone Sep 28, 2026
@cyrgani
cyrgani deleted the mut-ty branch September 28, 2026 19:12
pull Bot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request Sep 29, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#163327 (remove `MutTy`)
 - rust-lang/rust#162910 (Deterministic encoding of `DefPathHashMap`)
 - rust-lang/rust#163009 (dont store arbitrary parsed attributes in thir)
 - rust-lang/rust#162683 (Use attribute parser for `#[inline()]` attribute check)
 - rust-lang/rust#163429 (lint on `Ident::from_str_and_span` taking a string literal)
 - rust-lang/rust#163431 (Allow `#[repr(simd)]` with `f16b`)
 - rust-lang/rust#163433 (Support also `try-jobs:` to specify custom try jobs)
flip1995 pushed a commit to flip1995/rust that referenced this pull request Oct 1, 2026
…nathanBrouwer

Rollup of 7 pull requests

Successful merges:

 - rust-lang#163327 (remove `MutTy`)
 - rust-lang#162910 (Deterministic encoding of `DefPathHashMap`)
 - rust-lang#163009 (dont store arbitrary parsed attributes in thir)
 - rust-lang#162683 (Use attribute parser for `#[inline()]` attribute check)
 - rust-lang#163429 (lint on `Ident::from_str_and_span` taking a string literal)
 - rust-lang#163431 (Allow `#[repr(simd)]` with `f16b`)
 - rust-lang#163433 (Support also `try-jobs:` to specify custom try jobs)
AzureXuanVerse pushed a commit to AzureXuanVerse/rustfmt that referenced this pull request Oct 7, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#163327 (remove `MutTy`)
 - rust-lang/rust#162910 (Deterministic encoding of `DefPathHashMap`)
 - rust-lang/rust#163009 (dont store arbitrary parsed attributes in thir)
 - rust-lang/rust#162683 (Use attribute parser for `#[inline()]` attribute check)
 - rust-lang/rust#163429 (lint on `Ident::from_str_and_span` taking a string literal)
 - rust-lang/rust#163431 (Allow `#[repr(simd)]` with `f16b`)
 - rust-lang/rust#163433 (Support also `try-jobs:` to specify custom try jobs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-autodiff `#![feature(autodiff)]` S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants