Skip to content

Commit c6ce6c6

Browse files
committed
Partially fix parent_args handling for assoc const
1 parent f9bae3b commit c6ce6c6

File tree

1 file changed

+13
-8
lines changed
  • compiler/rustc_hir_analysis/src/hir_ty_lowering

1 file changed

+13
-8
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -621,15 +621,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
621621
(args, arg_count)
622622
}
623623

624-
#[instrument(level = "debug", skip_all)]
624+
#[instrument(level = "debug", skip(self))]
625625
pub fn lower_generic_args_of_assoc_item(
626626
&self,
627627
span: Span,
628628
item_def_id: DefId,
629629
item_segment: &hir::PathSegment<'tcx>,
630630
parent_args: GenericArgsRef<'tcx>,
631631
) -> GenericArgsRef<'tcx> {
632-
debug!(?span, ?item_def_id, ?item_segment);
633632
let (args, _) =
634633
self.lower_generic_args_of_path(span, item_def_id, parent_args, item_segment, None);
635634
if let Some(c) = item_segment.args().constraints.first() {
@@ -2210,7 +2209,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
22102209
}
22112210
}
22122211

2213-
#[instrument(level = "debug", skip(self))]
2212+
#[instrument(level = "debug", skip(self), ret)]
22142213
pub fn lower_const_assoc_path(
22152214
&self,
22162215
hir_ref_id: HirId,
@@ -2259,7 +2258,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
22592258
.collect::<Vec<_>>();
22602259
match &candidates[..] {
22612260
[] => {}
2262-
[assoc] => return self.lower_assoc_const(span, assoc.def_id, assoc_segment),
2261+
[assoc] => {
2262+
// FIXME: this is not necessarily correct.
2263+
// adapted from other code that also had a fixme about it being temporary.
2264+
let parent_args =
2265+
ty::GenericArgs::identity_for_item(tcx, tcx.parent(assoc.def_id));
2266+
return self.lower_assoc_const(span, assoc.def_id, assoc_segment, parent_args);
2267+
}
22632268
[..] => {
22642269
return Const::new_error_with_message(tcx, span, "ambiguous assoc const path");
22652270
}
@@ -2318,19 +2323,19 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
23182323
let assoc_const = self
23192324
.probe_assoc_item(assoc_ident, ty::AssocKind::Const, hir_ref_id, span, trait_did)
23202325
.expect("failed to find associated const");
2321-
self.lower_assoc_const(span, assoc_const.def_id, assoc_segment)
2326+
// TODO: don't use no_bound_vars probably
2327+
let trait_ref_args = bound.no_bound_vars().unwrap().args;
2328+
self.lower_assoc_const(span, assoc_const.def_id, assoc_segment, trait_ref_args)
23222329
}
23232330

23242331
fn lower_assoc_const(
23252332
&self,
23262333
span: Span,
23272334
item_def_id: DefId,
23282335
item_segment: &hir::PathSegment<'tcx>,
2336+
parent_args: GenericArgsRef<'tcx>,
23292337
) -> Const<'tcx> {
23302338
let tcx = self.tcx();
2331-
// FIXME: this is not necessarily correct.
2332-
// adapted from other code that also had a fixme about it being temporary.
2333-
let parent_args = ty::GenericArgs::identity_for_item(tcx, tcx.parent(item_def_id));
23342339
let args =
23352340
self.lower_generic_args_of_assoc_item(span, item_def_id, item_segment, parent_args);
23362341
let uv = ty::UnevaluatedConst::new(item_def_id, args);

0 commit comments

Comments
 (0)