Skip to content

Create Ty type alias in rustc_type_ir#154270

Open
Jamesbarford wants to merge 1 commit intorust-lang:mainfrom
Jamesbarford:chore/move-ty-pt1
Open

Create Ty type alias in rustc_type_ir#154270
Jamesbarford wants to merge 1 commit intorust-lang:mainfrom
Jamesbarford:chore/move-ty-pt1

Conversation

@Jamesbarford
Copy link
Copy Markdown
Contributor

@Jamesbarford Jamesbarford commented Mar 23, 2026

r? lcnr

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

@rustbot rustbot 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

Copy link
Copy Markdown
Contributor Author

@Jamesbarford Jamesbarford Mar 24, 2026

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)

Copy link
Copy Markdown
Contributor

@lcnr lcnr left a comment

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
Contributor Author

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))]
use crate::inherent::Ty as _;
  1. To prevent ty::Ty the correct thing to do is;
// in compiler/rustc_type_ir/src/sty/mod.rs
#[rustc_diagnostic_item = "Ty"]
pub type Ty ...

// 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
Copy link
Copy Markdown
Contributor

lcnr commented Mar 24, 2026

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
Contributor Author

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

Copy link
Copy Markdown
Contributor

@lcnr lcnr left a comment

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
@rustbot rustbot 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
Contributor Author

@bors r=lcnr

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Mar 30, 2026

@Jamesbarford: 🔑 Insufficient privileges: not in review users

@lcnr
Copy link
Copy Markdown
Contributor

lcnr commented Mar 30, 2026

@bors r+ rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Mar 30, 2026

📌 Commit 17e0cc3 has been approved by lcnr

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 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-bors bot 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-bors bot 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants