Skip to content

Refactor AliasTy & AliasTerm to use Alias#156538

Open
Jamesbarford wants to merge 4 commits into
rust-lang:mainfrom
Jamesbarford:chore/merge-AliasTy-AliasTerm
Open

Refactor AliasTy & AliasTerm to use Alias#156538
Jamesbarford wants to merge 4 commits into
rust-lang:mainfrom
Jamesbarford:chore/merge-AliasTy-AliasTerm

Conversation

@Jamesbarford
Copy link
Copy Markdown
Contributor

Refactors AliasTy & AliasTerm to use Alias. To move around errors I had to manually implement Lift, TypeVisitable and TypeFoldable

Part of #156181

r? @lcnr

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels May 13, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@Jamesbarford Jamesbarford force-pushed the chore/merge-AliasTy-AliasTerm branch from a630681 to 89cd50d Compare May 13, 2026 12:56
@lcnr
Copy link
Copy Markdown
Contributor

lcnr commented May 13, 2026

can you say more about the errors you had to work around? this feels odd to me and something we should fix in the derives instead of requiring manual impls here imo

)]
pub struct AliasTy<I: Interner> {
/// The parameters of the associated or opaque type.
pub struct Alias<I: Interner, K> {
Copy link
Copy Markdown
Contributor

@lcnr lcnr May 13, 2026

Choose a reason for hiding this comment

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

can you move Alias and AliasTerm in a separate rustc_type_ir/ty/alias module?

View changes since the review

Comment thread compiler/rustc_type_ir/src/predicate.rs Outdated
}

impl<I: Interner> Eq for NormalizesTo<I> {}
impl<I: Interner, K: PartialEq> Eq for NormalizesTo<I, K> {}
Copy link
Copy Markdown
Contributor

@lcnr lcnr May 13, 2026

Choose a reason for hiding this comment

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

why not derive_where for Eq? that might be outdated and no longer necessary thanks to ModProg/derive-where#137

View changes since the review

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.

abebd2b 👍

@Jamesbarford
Copy link
Copy Markdown
Contributor Author

Jamesbarford commented May 13, 2026

I've whittled it down to only a manual Lift implementation for Alias as below.

(comments omitted for brevity)

#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner, K)]
#[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)]
#[cfg_attr(
    feature = "nightly",
    derive(Decodable_NoContext, Encodable_NoContext, StableHash_NoContext)
)]
pub struct Alias<I: Interner, K> {
    pub args: I::GenericArgs,

    pub kind: K,

    #[derive_where(skip(Debug))]
    #[type_visitable(ignore)]
    #[type_foldable(identity)]
    pub(crate) _use_alias_new_instead: (),
}

I get 2000+ errors of which fall into the following;

error[E0308]: mismatched types
error[E0521]: borrowed data escapes outside of associated function
error[E0521]: borrowed data escapes outside of function
error[E0521]: borrowed data escapes outside of method

A sample of errors being;

error[E0521]: borrowed data escapes outside of method
   --> compiler/rustc_middle/src/ty/trait_def.rs:229:13
    |
181 | impl<'tcx> TyCtxt<'tcx> {
    |      ---- lifetime `'tcx` defined here
...
223 |         self,
    |         ---- `self` is a reference that is only valid in the method body
...
229 |             fast_reject::simplify_type(self, self_ty, TreatParams::InstantiateWithInfer)
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |             |
    |             `self` escapes the method body here
    |             argument requires that `'tcx` must outlive `'static`
    |
    = note: requirement occurs because of the type `context::TyCtxt<'_>`, which makes the generic argument `'_` invariant
    = note: the struct `context::TyCtxt<'tcx>` is invariant over the parameter `'tcx`
    = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
note: due to a current limitation of the type system, this implies a `'static` lifetime
   --> compiler/rustc_middle/src/ty/print/mod.rs:416:15
    |
416 |     T: Copy + for<'a, 'tcx> Lift<TyCtxt<'tcx>, Lifted: Print<FmtPrinter<'a, 'tcx>>>,
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

...

error[E0308]: mismatched types
   --> compiler/rustc_middle/src/ty/trait_def.rs:229:13
    |
229 |             fast_reject::simplify_type(self, self_ty, TreatParams::InstantiateWithInfer)
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
    |
    = note: expected enum `rustc_type_ir::AliasTyKind<context::TyCtxt<'tcx>>`
               found enum `rustc_type_ir::AliasTyKind<context::TyCtxt<'_>>`
note: the lifetime requirement is introduced here
   --> compiler/rustc_type_ir/src/interner.rs:25:7
    |
 25 |     + IrPrint<ty::AliasTy<Self>>
    |       ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: implementation of `Interner` is not general enough
   --> compiler/rustc_middle/src/ty/trait_def.rs:229:13
    |
229 |             fast_reject::simplify_type(self, self_ty, TreatParams::InstantiateWithInfer)
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Interner` is not general enough
    |
    = note: `Interner` would have to be implemented for the type `context::TyCtxt<'tcx>`
    = note: ...but `Interner` is actually implemented for the type `context::TyCtxt<'0>`, for some specific lifetime `'0`


...pub struct Placeholder

error[E0308]: mismatched types
   --> compiler/rustc_middle/src/ty/trait_def.rs:229:13
    |
229 |             fast_reject::simplify_type(self, self_ty, TreatParams::InstantiateWithInfer)
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
    |
    = note: expected enum `rustc_type_ir::AliasTermKind<context::TyCtxt<'tcx>>`
               found enum `rustc_type_ir::AliasTermKind<context::TyCtxt<'_>>`
note: the lifetime requirement is introduced here
   --> compiler/rustc_type_ir/src/interner.rs:33:7
    |
 33 |     + IrPrint<ty::NormalizesTo<Self>>
    |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

...

error[E0308]: mismatched types
   --> compiler/rustc_middle/src/ty/relate.rs:55:12
    |
 55 | impl<'tcx> Relate<TyCtxt<'tcx>> for &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>> {
    |            ^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
    |
    = note: expected enum `rustc_type_ir::AliasTermKind<context::TyCtxt<'tcx>>`
               found enum `rustc_type_ir::AliasTermKind<context::TyCtxt<'tcx>>`
note: the required lifetime does not necessarily outlive the lifetime `'tcx` as defined here
   --> compiler/rustc_middle/src/ty/relate.rs:55:6
    |
 55 | impl<'tcx> Relate<TyCtxt<'tcx>> for &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>> {
    |      ^^^^
note: the lifetime requirement is introduced here
   --> compiler/rustc_type_ir/src/relate.rs:116:21
    |
116 | pub trait Relate<I: Interner>: TypeFoldable<I> + PartialEq + Copy {
    |                     ^^^^^^^^

And so on... This was similar to pub struct Placeholder<I: Interner, T> where I think the the generic parameter T required manually implementing Lift. Though this is a superficial understanding

@rust-log-analyzer
Copy link
Copy Markdown
Collaborator

The job x86_64-gnu-gcc failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
---- [run-make] tests/run-make-cargo/rustc-crates-on-stable stdout ----

error: rmake recipe failed to complete
status: exit status: 1
command: cd "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-cargo/rustc-crates-on-stable/rmake_out" && env -u RUSTFLAGS -u __RUSTC_DEBUG_ASSERTIONS_ENABLED -u __STD_DEBUG_ASSERTIONS_ENABLED -u __STD_REMAP_DEBUGINFO_ENABLED AR="ar" BUILD_ROOT="/checkout/obj/build/x86_64-unknown-linux-gnu" CARGO="/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools-bin/cargo" CC="cc" CC_DEFAULT_FLAGS="-ffunction-sections -fdata-sections -fPIC -m64" CXX="c++" CXX_DEFAULT_FLAGS="-ffunction-sections -fdata-sections -fPIC -m64" HOST_RUSTC_DYLIB_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" LD_LIBRARY_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/bootstrap-tools/x86_64-unknown-linux-gnu/release/deps:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib" LD_LIB_PATH_ENVVAR="LD_LIBRARY_PATH" LLVM_BIN_DIR="/checkout/obj/build/x86_64-unknown-linux-gnu/ci-llvm/bin" LLVM_COMPONENTS="aarch64 aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils abi aggressiveinstcombine all all-targets amdgpu amdgpuasmparser amdgpucodegen amdgpudesc amdgpudisassembler amdgpuinfo amdgputargetmca amdgpuutils analysis arm armasmparser armcodegen armdesc armdisassembler arminfo armutils asmparser asmprinter avr avrasmparser avrcodegen avrdesc avrdisassembler avrinfo binaryformat bitreader bitstreamreader bitwriter bpf bpfasmparser bpfcodegen bpfdesc bpfdisassembler bpfinfo cas cfguard cgdata codegen codegentypes core coroutines coverage csky cskyasmparser cskycodegen cskydesc cskydisassembler cskyinfo debuginfobtf debuginfocodeview debuginfodwarf debuginfodwarflowlevel debuginfogsym debuginfologicalview debuginfomsf debuginfopdb demangle dlltooldriver dtlto dwarfcfichecker dwarflinker dwarflinkerclassic dwarflinkerparallel dwp engine executionengine extensions filecheck frontendatomic frontenddirective frontenddriver frontendhlsl frontendoffloading frontendopenacc frontendopenmp fuzzercli fuzzmutate globalisel hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo hipstdpar instcombine instrumentation interfacestub interpreter ipo irprinter irreader jitlink libdriver lineeditor linker loongarch loongarchasmparser loongarchcodegen loongarchdesc loongarchdisassembler loongarchinfo lto m68k m68kasmparser m68kcodegen m68kdesc m68kdisassembler m68kinfo mc mca mcdisassembler mcjit mcparser mips mipsasmparser mipscodegen mipsdesc mipsdisassembler mipsinfo mirparser msp430 msp430asmparser msp430codegen msp430desc msp430disassembler msp430info native nativecodegen nvptx nvptxcodegen nvptxdesc nvptxinfo objcarcopts objcopy object objectyaml option orcdebugging orcjit orcshared orctargetprocess passes plugins powerpc powerpcasmparser powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata remarks riscv riscvasmparser riscvcodegen riscvdesc riscvdisassembler riscvinfo riscvtargetmca runtimedyld sandboxir scalaropts selectiondag sparc sparcasmparser sparccodegen sparcdesc sparcdisassembler sparcinfo support supportlsp symbolize systemz systemzasmparser systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target targetparser telemetry textapi textapibinaryreader transformutils vectorize webassembly webassemblyasmparser webassemblycodegen webassemblydesc webassemblydisassembler webassemblyinfo webassemblyutils windowsdriver windowsmanifest x86 x86asmparser x86codegen x86desc x86disassembler x86info x86targetmca xray xtensa xtensaasmparser xtensacodegen xtensadesc xtensadisassembler xtensainfo" LLVM_FILECHECK="/checkout/obj/build/x86_64-unknown-linux-gnu/ci-llvm/bin/FileCheck" PYTHON="/usr/bin/python3" RUSTC="/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" RUSTDOC="/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustdoc" SOURCE_ROOT="/checkout" TARGET="x86_64-unknown-linux-gnu" TARGET_EXE_DYLIB_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" __BOOTSTRAP_JOBS="4" __RMAKE_VERBOSE_SUBPROCESS_OUTPUT="1" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-cargo/rustc-crates-on-stable/rmake"
stdout: none
--- stderr -------------------------------
command failed at line 41
LD_LIBRARY_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-cargo/rustc-crates-on-stable/rmake_out:/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib:/checkout/obj/build/x86_64-unknown-linux-gnu/bootstrap-tools/x86_64-unknown-linux-gnu/release/deps:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib" RUSTC="/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" RUSTC_STAGE="0" RUSTFLAGS="-D warnings -Zallow-features=" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools-bin/cargo" "build" "--manifest-path" "/checkout/Cargo.toml" "--no-default-features" "--target-dir" "target" "-p" "rustc_type_ir" "-p" "rustc_next_trait_solver" "-p" "rustc_pattern_analysis" "-p" "rustc_lexer" "-p" "rustc_abi" "-p" "rustc_parse_format" "-p" "rustc_hashes"
output status: `exit status: 101`
=== STDOUT ===



=== STDERR ===
   Compiling unicode-ident v1.0.22

For more information how to resolve CI failures of this job, visit this link.

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

Labels

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

4 participants