Skip to content

Create Ty type alias in rustc_type_ir - #154270

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Jamesbarford:chore/move-ty-pt1
Mar 31, 2026
Merged

Create Ty type alias in rustc_type_ir#154270
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Jamesbarford:chore/move-ty-pt1

Conversation

@Jamesbarford

@JamesbarfordJamesbarford commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

r? lcnr

Anywhere that required the use of the trait Ty I used ty::Ty<I> otherwise it should be Ty<I>

@rustbotrustbot added 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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Mar 23, 2026
@rust-bors

This comment has been minimized.

/// We can simply cache based on the ty itself, because we use
/// `ty::BoundVarIndexKind::Canonical`.
cache: HashMap<I::Ty, I::Ty>,
cache: HashMap<ty::Ty<I>, ty::Ty<I>>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you also add the lint that we should use Ty without any prefix to the type alias? it should be some attribute on struct Ty, idk if it already works with type aliases.

anyways, please import ty::Ty. There isn't really a good reason for that outside of consistency

@JamesbarfordJamesbarfordMar 24, 2026

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I've tried to do this however I'd need to add another #[rustc_diagnostic_item = "Ty"] which then clashes with the one in rustc_middle. I thought perhaps doing something like #[rustc_diagnostic_item = "IrTy"] may work however it then simply ignored the diagnostic. (I've expanded on this in my comment below)

Comment threadcompiler/rustc_type_ir/src/sty/mod.rs Outdated

@lcnrlcnr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 nice

please also do so for all uses of <whatever as Interner>::Ty

View changes since this review

@Jamesbarford

Copy link
Copy Markdown
ContributorAuthor

Couple of things I found;

  1. For methods like Ty::new_error I've had to prefix it with I::Ty::new_error to prevent the error below, the other option would be to do crate::inherent::Ty::new_error(...).
error[E0283]: type annotations needed
--> compiler/rustc_type_ir/src/ty_kind/closure.rs:486:40
|
486 | ty::ClosureKind::FnOnce => Ty::new_tup_from_iter(
| ^^ cannot infer type for type parameter `I` declared on the type alias `Ty`
|
= note: cannot satisfy `_: interner::Interner`
= note: associated types cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl`
help: use the fully qualified path to an implementation
  1. To be able to access the traits methods like ty.is_fresh(...) I've done;
#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))]usecrate::inherent::Tyas _;
  1. To prevent ty::Ty the correct thing to do is;
// in compiler/rustc_type_ir/src/sty/mod.rs#[rustc_diagnostic_item = "Ty"]pubtypeTy ...// in compiler/rustc_type_ir/src/lib.rs
#![deny(rustc::usage_of_qualified_ty)]

However I then get the below error, so I've not added it. But we should add it when we delete the struct from rustc_middle.

error: duplicate diagnostic item in crate `rustc_middle`: `Ty`
--> compiler/rustc_middle/src/ty/mod.rs:431:1
|
431 | pub struct Ty<'tcx>(Interned<'tcx, WithCachedTypeInfo<TyKind<'tcx>>>);
| ^^^^^^^^^^^^^^^^^^^
|
= note: the diagnostic item is first defined in crate `rustc_type_ir`
error: could not compile `rustc_middle` (lib) due to 1 previous error
  1. In compiler/rustc_type_ir/src/inherent.rs I import Ty as IrTy to prevent clashing with the trait definition. Seeing as we hope to delete the trait I didn't think it was too bad.

@lcnr

lcnr commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

That is really annoying, didn't consider that... I guess let's keep ty::Ty for now 🤔 this does mean any future PR will have to remove the ty:: at that point, but that should be a single (probably even separate commit which just does a find-and-replace)

@Jamesbarford

Copy link
Copy Markdown
ContributorAuthor

That is really annoying, didn't consider that... I guess let's keep ty::Ty for now 🤔 this does mean any future PR will have to remove the ty:: at that point, but that should be a single (probably even separate commit which just does a find-and-replace)

👍 b95801f

use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable};
use crate::{
self as ty, ClauseKind, CollectAndApply, FieldInfo, Interner, PredicateKind, UpcastFrom,
self as ty, ClauseKind, CollectAndApply, FieldInfo, Interner, PredicateKind, Ty as IrTy,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

prefer just not importing Ty and using ty::Ty<I> i think

@lcnrlcnr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

final nit, then r=me

View changes since this review

@Jamesbarford
Jamesbarford marked this pull request as ready for review March 30, 2026 11:42
@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 30, 2026
@Jamesbarford

Copy link
Copy Markdown
ContributorAuthor

@bors r=lcnr

@rust-bors

rust-borsBot commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

@Jamesbarford: 🔑 Insufficient privileges: not in review users

@lcnr

lcnr commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-borsBot commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 17e0cc3 has been approved by lcnr

It is now in the queue for this repository.

@rust-borsrust-borsBot 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 Mar 30, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 30, 2026
…lcnr
Create `Ty` type alias in `rustc_type_ir`
r? lcnr
Anywhere that required the use of the trait `Ty` I used `ty::Ty<I>` otherwise it should be `Ty<I>`
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 30, 2026
…lcnr
Create `Ty` type alias in `rustc_type_ir`
r? lcnr
Anywhere that required the use of the trait `Ty` I used `ty::Ty<I>` otherwise it should be `Ty<I>`
rust-borsBot pushed a commit that referenced this pull request Mar 30, 2026
…uwer
Rollup of 5 pull requests
Successful merges:
- #154582 (miri subtree update)
- #154270 (Create `Ty` type alias in `rustc_type_ir`)
- #154574 (delete several `ui/consts` tests)
- #154577 (Update `mir-opt` 64-bit panic-abort tests for `Alignment` rename)
- #154579 (remove debug requirement from hooks)
rust-borsBot pushed a commit that referenced this pull request Mar 30, 2026
…uwer
Rollup of 5 pull requests
Successful merges:
- #154582 (miri subtree update)
- #154270 (Create `Ty` type alias in `rustc_type_ir`)
- #154574 (delete several `ui/consts` tests)
- #154577 (Update `mir-opt` 64-bit panic-abort tests for `Alignment` rename)
- #154579 (remove debug requirement from hooks)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 31, 2026
…lcnr
Create `Ty` type alias in `rustc_type_ir`
r? lcnr
Anywhere that required the use of the trait `Ty` I used `ty::Ty<I>` otherwise it should be `Ty<I>`
This was referenced Mar 31, 2026
rust-borsBot pushed a commit that referenced this pull request Mar 31, 2026
…uwer
Rollup of 12 pull requests
Successful merges:
- #154419 (Take first task group for further execution)
- #154569 (Fix type alias where clause suggestion spacing issue)
- #154617 (Update flate2 users to use zlib-rs)
- #154618 (Fix AtomicPtr::update's cfg gate)
- #154620 (stabilize new Range type and iterator)
- #151932 (refactor: remove `Adjust::ReborrowPin`)
- #153980 (refactor: move doc(rust_logo) check to parser)
- #154134 (fix: guard paren-sugar pretty-printing on short trait args)
- #154270 (Create `Ty` type alias in `rustc_type_ir`)
- #154580 (Split AttributeParserError Diagnostic implementation into subfunctions)
- #154606 (misc test cleanups)
- #154612 (Add a test for a now fixed ICE with `offset_of!()`)
@rust-bors
rust-borsBot merged commit 2862633 into rust-lang:mainMar 31, 2026
11 checks passed
@rustbotrustbot added this to the 1.96.0 milestone Mar 31, 2026
rust-timer added a commit that referenced this pull request Mar 31, 2026
Rollup merge of #154270 - Jamesbarford:chore/move-ty-pt1, r=lcnr
Create `Ty` type alias in `rustc_type_ir`
r? lcnr
Anywhere that required the use of the trait `Ty` I used `ty::Ty<I>` otherwise it should be `Ty<I>`
github-actionsBot pushed a commit to rust-lang/compiler-builtins that referenced this pull request Mar 31, 2026
…uwer
Rollup of 12 pull requests
Successful merges:
- rust-lang/rust#154419 (Take first task group for further execution)
- rust-lang/rust#154569 (Fix type alias where clause suggestion spacing issue)
- rust-lang/rust#154617 (Update flate2 users to use zlib-rs)
- rust-lang/rust#154618 (Fix AtomicPtr::update's cfg gate)
- rust-lang/rust#154620 (stabilize new Range type and iterator)
- rust-lang/rust#151932 (refactor: remove `Adjust::ReborrowPin`)
- rust-lang/rust#153980 (refactor: move doc(rust_logo) check to parser)
- rust-lang/rust#154134 (fix: guard paren-sugar pretty-printing on short trait args)
- rust-lang/rust#154270 (Create `Ty` type alias in `rustc_type_ir`)
- rust-lang/rust#154580 (Split AttributeParserError Diagnostic implementation into subfunctions)
- rust-lang/rust#154606 (misc test cleanups)
- rust-lang/rust#154612 (Add a test for a now fixed ICE with `offset_of!()`)
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Apr 1, 2026
…uwer
Rollup of 12 pull requests
Successful merges:
- rust-lang/rust#154419 (Take first task group for further execution)
- rust-lang/rust#154569 (Fix type alias where clause suggestion spacing issue)
- rust-lang/rust#154617 (Update flate2 users to use zlib-rs)
- rust-lang/rust#154618 (Fix AtomicPtr::update's cfg gate)
- rust-lang/rust#154620 (stabilize new Range type and iterator)
- rust-lang/rust#151932 (refactor: remove `Adjust::ReborrowPin`)
- rust-lang/rust#153980 (refactor: move doc(rust_logo) check to parser)
- rust-lang/rust#154134 (fix: guard paren-sugar pretty-printing on short trait args)
- rust-lang/rust#154270 (Create `Ty` type alias in `rustc_type_ir`)
- rust-lang/rust#154580 (Split AttributeParserError Diagnostic implementation into subfunctions)
- rust-lang/rust#154606 (misc test cleanups)
- rust-lang/rust#154612 (Add a test for a now fixed ICE with `offset_of!()`)
@Zalathar

Copy link
Copy Markdown
Member

This PR turns out to trigger a large number of bogus compile errors in rust-analyzer, due to some kind of confusion between rustc_type_ir::sty::Ty and rustc_middle::ty::Ty.

(Zulip thread)

After some experimentation, I found that these bogus RA errors can be avoided by renaming rustc_type_ir::sty::Ty to something other than Ty.

I'm not sure how this fits into larger plans to migrate Ty, but the bogus RA errors are a pretty large contributor roadblock at the moment, so I'd like to find an agreeable way to merge a workaround.

@Jamesbarford
Jamesbarford deleted the chore/move-ty-pt1 branch April 2, 2026 07:24
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 2, 2026
…alias, r=lcnr
Revert `Ty` type alias in `rustc_type_ir`
Reverting (rust-lang#154270) the creation and use of `Ty` type alias in `rustc_type_ir` that was causing problems with Rust Analyser, see [discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/.23154270.20.28Ty.20alias.29.20triggers.20many.20bogus.20RA.20errors/with/583209227) for more
r? @lcnr
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 2, 2026
…alias, r=lcnr
Revert `Ty` type alias in `rustc_type_ir`
Reverting (rust-lang#154270) the creation and use of `Ty` type alias in `rustc_type_ir` that was causing problems with Rust Analyser, see [discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/.23154270.20.28Ty.20alias.29.20triggers.20many.20bogus.20RA.20errors/with/583209227) for more
r? @lcnr
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 2, 2026
…alias, r=lcnr
Revert `Ty` type alias in `rustc_type_ir`
Reverting (rust-lang#154270) the creation and use of `Ty` type alias in `rustc_type_ir` that was causing problems with Rust Analyser, see [discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/.23154270.20.28Ty.20alias.29.20triggers.20many.20bogus.20RA.20errors/with/583209227) for more
r? @lcnr
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 2, 2026
…alias, r=lcnr
Revert `Ty` type alias in `rustc_type_ir`
Reverting (rust-lang#154270) the creation and use of `Ty` type alias in `rustc_type_ir` that was causing problems with Rust Analyser, see [discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/.23154270.20.28Ty.20alias.29.20triggers.20many.20bogus.20RA.20errors/with/583209227) for more
r? @lcnr
rust-timer added a commit that referenced this pull request Apr 2, 2026
Rollup merge of #154709 - Jamesbarford:chore/revert-ty-type-alias, r=lcnr
Revert `Ty` type alias in `rustc_type_ir`
Reverting (#154270) the creation and use of `Ty` type alias in `rustc_type_ir` that was causing problems with Rust Analyser, see [discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/.23154270.20.28Ty.20alias.29.20triggers.20many.20bogus.20RA.20errors/with/583209227) for more
r? @lcnr
github-actionsBot pushed a commit to rust-lang/miri that referenced this pull request Apr 3, 2026
…lcnr
Revert `Ty` type alias in `rustc_type_ir`
Reverting (rust-lang/rust#154270) the creation and use of `Ty` type alias in `rustc_type_ir` that was causing problems with Rust Analyser, see [discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/.23154270.20.28Ty.20alias.29.20triggers.20many.20bogus.20RA.20errors/with/583209227) for more
r? @lcnr
github-actionsBot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Apr 6, 2026
…uwer
Rollup of 12 pull requests
Successful merges:
- rust-lang/rust#154419 (Take first task group for further execution)
- rust-lang/rust#154569 (Fix type alias where clause suggestion spacing issue)
- rust-lang/rust#154617 (Update flate2 users to use zlib-rs)
- rust-lang/rust#154618 (Fix AtomicPtr::update's cfg gate)
- rust-lang/rust#154620 (stabilize new Range type and iterator)
- rust-lang/rust#151932 (refactor: remove `Adjust::ReborrowPin`)
- rust-lang/rust#153980 (refactor: move doc(rust_logo) check to parser)
- rust-lang/rust#154134 (fix: guard paren-sugar pretty-printing on short trait args)
- rust-lang/rust#154270 (Create `Ty` type alias in `rustc_type_ir`)
- rust-lang/rust#154580 (Split AttributeParserError Diagnostic implementation into subfunctions)
- rust-lang/rust#154606 (misc test cleanups)
- rust-lang/rust#154612 (Add a test for a now fixed ICE with `offset_of!()`)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@Jamesbarford@lcnr@Zalathar@rustbot