Skip to content

refactor TypeRelativePath::AssocItem to use AliasTerm#155323

Open
josetorrs wants to merge 1 commit intorust-lang:mainfrom
josetorrs:remove-new-from-def-id
Open

refactor TypeRelativePath::AssocItem to use AliasTerm#155323
josetorrs wants to merge 1 commit intorust-lang:mainfrom
josetorrs:remove-new-from-def-id

Conversation

@josetorrs
Copy link
Copy Markdown
Contributor

@josetorrs josetorrs commented Apr 15, 2026

r? @WaffleLapkin

related issue: #154941

tackling the task:

  • remove calls to new_from_def_id and alias_ty_kind_from_def_id and replace them with calls to e.g. new_projection directly

  • lower_type_relative_ty_path nows uses alias_term.expect_ty(tcx).to_ty(tcx)

  • lower_type_relative_const_path uses alias_term.expect_ct(tcx).

  • probe_inherent_assoc_item returns AliasTerm<'tcx>

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 15, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 15, 2026

WaffleLapkin is not on the review rotation at the moment.
They may take a while to respond.

Comment thread compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs Outdated
Comment thread compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs Outdated
Comment thread compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs Outdated
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 15, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@josetorrs josetorrs marked this pull request as ready for review April 16, 2026 01:31
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 16, 2026

HIR ty lowering was modified

cc @fmease

@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 Apr 16, 2026
@WaffleLapkin
Copy link
Copy Markdown
Member

r? fmease

@rustbot rustbot assigned fmease and unassigned WaffleLapkin May 1, 2026
@josetorrs josetorrs requested a review from fmease May 3, 2026 16:09
Copy link
Copy Markdown
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

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

Sorry for the delay! Could you apply my suggestions, update PR title and the PR description which seem to be outdated and squash all commits into one? Thanks!

View changes since this review

Comment thread compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs Outdated
Comment on lines +1442 to +1445
let def_id = alias_term.def_id;
self.require_type_const_attribute(def_id, span)?;
let ct = Const::new_unevaluated(tcx, ty::UnevaluatedConst::new(def_id, args));
let ct =
Const::new_unevaluated(tcx, ty::UnevaluatedConst::new(def_id, alias_term.args));
Copy link
Copy Markdown
Member

@fmease fmease May 7, 2026

Choose a reason for hiding this comment

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

Suggested change
let def_id = alias_term.def_id;
self.require_type_const_attribute(def_id, span)?;
let ct = Const::new_unevaluated(tcx, ty::UnevaluatedConst::new(def_id, args));
let ct =
Const::new_unevaluated(tcx, ty::UnevaluatedConst::new(def_id, alias_term.args));
self.require_type_const_attribute(alias_term.def_id, span)?;
let ct = Const::new_unevaluated(tcx, alias_term.expect_ct(tcx));


// FIXME(inherent_associated_types, #106719): Support self types other than ADTs.
if let Some((did, args)) = self.probe_inherent_assoc_item(
if let Some((def_id, args)) = self.probe_inherent_assoc_item(
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.

Could you make probe_inherent_assoc_item return an AliasTerm? So return a Result<Option<ty::AliasTerm<'tcx>>, ErrorGuaranteed>?

Additionally you could make lower_assoc_item_path return an AliasTerm directly to mirror the inherent counterpart but it's probably not worth it.

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.

okay I think I got everything. I looked at implementing the lower_assoc_item_path suggestion and personally prefer the type clarity with AliasTerm but like you said not sure if it's worth it. though if you have second thoughts, then I would be happy to make the change

@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 7, 2026
@rust-log-analyzer

This comment has been minimized.

…erent_assoc_item` returns `AliasTerm` based fmease suggestins
@josetorrs josetorrs force-pushed the remove-new-from-def-id branch from 7c65730 to 1d2a312 Compare May 9, 2026 16:09
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 9, 2026

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.

@josetorrs josetorrs changed the title removing new_from_def_id and alias_ty_kind_from_def_id methods, small refactor to TypeRelativePath::AssocItem refactor TypeRelativePath::AssocItem to use AliasTerm May 9, 2026
@rust-log-analyzer
Copy link
Copy Markdown
Collaborator

The job aarch64-gnu-llvm-21-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
Executing "/scripts/stage_2_test_set1.sh"
+ /scripts/stage_2_test_set1.sh
PR_CI_JOB set; skipping tidy
+ '[' 1 == 1 ']'
+ echo 'PR_CI_JOB set; skipping tidy'
+ SKIP_TIDY='--skip tidy'
+ ../x.py --stage 2 test --skip tidy --skip compiler --skip src
##[group]Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.04s
##[endgroup]
downloading https://static.rust-lang.org/dist/2026-04-14/rustfmt-nightly-aarch64-unknown-linux-gnu.tar.xz
---
---- [ui] tests/ui/const-generics/gca/path-to-non-type-inherent-associated-const.rs stdout ----

error: Error: expected failure status (Some(1)) but received status Some(101).
status: exit status: 101
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/const-generics/gca/path-to-non-type-inherent-associated-const.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/const-generics/gca/path-to-non-type-inherent-associated-const" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-Znext-solver"
stdout: none
--- stderr -------------------------------
##[error]error: internal compiler error: compiler/rustc_middle/src/ty/context.rs:2168:17: args not compatible with generics for StructImpl::INHERENT: args=[
                                    StructImpl,
                                ], generics=[]


thread 'rustc' (52203) panicked at compiler/rustc_middle/src/ty/context.rs:2168:17:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: <rustc_middle::ty::context::TyCtxt>::debug_assert_args_compatible
   7: <rustc_type_ir::predicate::AliasTerm<rustc_middle::ty::context::TyCtxt>>::new_from_def_id
   8: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::lower_type_relative_path
   9: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::lower_type_relative_const_path
  10: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::lower_const_arg
  11: <rustc_hir_typeck::fn_ctxt::FnCtxt>::lower_const_arg
  12: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::instantiate_value_path::CtorGenericArgsCtxt as rustc_hir_analysis::hir_ty_lowering::GenericArgsLowerer>::provided_kind
  13: rustc_hir_analysis::hir_ty_lowering::generics::lower_generic_args::<<rustc_hir_typeck::fn_ctxt::FnCtxt>::instantiate_value_path::CtorGenericArgsCtxt>
  14: <rustc_hir_typeck::fn_ctxt::FnCtxt>::instantiate_value_path
  15: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_path
  16: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  17: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation
  18: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_decl
  19: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_block
  20: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_kind
  21: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  22: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation
  23: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_or_body_tail
  24: rustc_hir_typeck::check::check_fn
  25: rustc_hir_typeck::typeck_with_inspect
      [... omitted 2 frames ...]
  26: <rustc_middle::query::plumbing::TyCtxtEnsureOk>::typeck::<rustc_span::def_id::LocalDefId>
  27: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis::check_crate::{closure#1}>::{closure#0}
  28: std::panicking::catch_unwind::<(), core::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures::sync::parallel::par_for_each_in<&rustc_span::def_id::LocalDefId, &[rustc_span::def_id::LocalDefId], <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners<rustc_hir_analysis::check_crate::{closure#1}>::{closure#0}>::{closure#0}::{closure#1}::{closure#0}>>
  29: rustc_data_structures::sync::parallel::par_for_each_in::<&rustc_span::def_id::LocalDefId, &[rustc_span::def_id::LocalDefId], <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners<rustc_hir_analysis::check_crate::{closure#1}>::{closure#0}>
  30: rustc_hir_analysis::check_crate
  31: rustc_interface::passes::analysis
      [... omitted 2 frames ...]
  32: std::panicking::catch_unwind::<core::option::Option<rustc_interface::queries::Linker>, core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}>>
  33: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}, core::option::Option<rustc_interface::queries::Linker>>::{closure#1}, core::option::Option<rustc_interface::queries::Linker>>::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>
  34: <rustc_middle::ty::context::TyCtxt>::create_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}>
  35: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  36: std::panicking::catch_unwind::<(), core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}::{closure#0}>>
  37: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
  38: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>
  39: rustc_span::create_session_globals_then::<(), rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}>
---
note: please make sure that you have updated to the latest nightly

note: rustc 1.97.0-nightly (8dad82d9e 2026-05-09) running on aarch64-unknown-linux-gnu

note: compiler flags: -Z threads=1 -Z simulate-remapped-rust-src-base=/rustc/FAKE_PREFIX -Z translate-remapped-path-to-local-path=no -Z ignore-directory-in-diagnostics-source-blocks=/cargo -Z ignore-directory-in-diagnostics-source-blocks=/checkout/vendor -C codegen-units=1 -Z ui-testing -Z deduplicate-diagnostics=no -Z write-long-types-to-disk=no -C strip=debuginfo -C prefer-dynamic -C rpath -C debuginfo=0 -Z next-solver

query stack during panic:
#0 [typeck_root] type-checking `main`
#1 [analysis] running analysis passes on crate `path_to_non_type_inherent_associated_const`
end of query stack
error: aborting due to 1 previous error
------------------------------------------

---- [ui] tests/ui/const-generics/gca/path-to-non-type-inherent-associated-const.rs stdout end ----

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

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler 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