Skip to content

Commit 7055784

Browse files
committed
Fix review comments
1 parent 5dc27d2 commit 7055784

File tree

3 files changed

+10
-48
lines changed

3 files changed

+10
-48
lines changed

compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,11 @@ fn anon_const_type_of<'tcx>(icx: &ItemCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx
354354
hir_id: arg_hir_id,
355355
kind: ConstArgKind::Anon(&AnonConst { hir_id: anon_hir_id, .. }),
356356
..
357-
}) if anon_hir_id == hir_id => const_arg_anon_type_of(icx, arg_hir_id, span),
357+
}) if anon_hir_id == hir_id => Ty::new_error_with_message(
358+
tcx,
359+
span,
360+
"`type_of` called on const argument's anon const before the const argument was lowered",
361+
),
358362

359363
Node::Variant(Variant { disr_expr: Some(e), .. }) if e.hir_id == hir_id => {
360364
tcx.adt_def(tcx.hir_get_parent_item(hir_id)).repr().discr_type().to_ty(tcx)
@@ -374,42 +378,6 @@ fn anon_const_type_of<'tcx>(icx: &ItemCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx
374378
}
375379
}
376380

377-
fn const_arg_anon_type_of<'tcx>(icx: &ItemCtxt<'tcx>, arg_hir_id: HirId, span: Span) -> Ty<'tcx> {
378-
use hir::*;
379-
use rustc_middle::ty::Ty;
380-
381-
let tcx = icx.tcx;
382-
383-
match tcx.parent_hir_node(arg_hir_id) {
384-
// Array length const arguments do not have `type_of` fed as there is never a corresponding
385-
// generic parameter definition.
386-
Node::Ty(&hir::Ty { kind: TyKind::Array(_, ref constant), .. })
387-
| Node::Expr(&Expr { kind: ExprKind::Repeat(_, ref constant), .. })
388-
if constant.hir_id == arg_hir_id =>
389-
{
390-
tcx.types.usize
391-
}
392-
393-
Node::TyPat(pat) => {
394-
let node = match tcx.parent_hir_node(pat.hir_id) {
395-
// Or patterns can be nested one level deep
396-
Node::TyPat(p) => tcx.parent_hir_node(p.hir_id),
397-
other => other,
398-
};
399-
let hir::TyKind::Pat(ty, _) = node.expect_ty().kind else { bug!() };
400-
icx.lower_ty(ty)
401-
}
402-
403-
// This is not a `bug!` as const arguments in path segments that did not resolve to anything
404-
// will result in `type_of` never being fed.
405-
_ => Ty::new_error_with_message(
406-
tcx,
407-
span,
408-
"`type_of` called on const argument's anon const before the const argument was lowered",
409-
),
410-
}
411-
}
412-
413381
fn infer_placeholder_type<'tcx>(
414382
cx: &dyn HirTyLowerer<'tcx>,
415383
def_id: LocalDefId,

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
12831283
)
12841284
});
12851285

1286+
// FIXME(mgca): code duplication with other places we lower
1287+
// the rhs' of associated const bindings
12861288
let ty = projection_term.map_bound(|alias| {
12871289
tcx.type_of(alias.def_id).instantiate(tcx, alias.args)
12881290
});

src/librustdoc/clean/mod.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -468,19 +468,13 @@ fn clean_middle_term<'tcx>(
468468
fn clean_hir_term<'tcx>(
469469
assoc_item: Option<DefId>,
470470
term: &hir::Term<'tcx>,
471-
span: rustc_span::Span,
472471
cx: &mut DocContext<'tcx>,
473472
) -> Term {
474473
match term {
475474
hir::Term::Ty(ty) => Term::Type(clean_ty(ty, cx)),
476475
hir::Term::Const(c) => {
477-
let ty = if let Some(assoc_item) = assoc_item {
478-
// FIXME(generic_const_items): this should instantiate with the alias item's args
479-
cx.tcx.type_of(assoc_item).instantiate_identity()
480-
} else {
481-
Ty::new_error_with_message(cx.tcx, span, "cannot find the associated constant")
482-
};
483-
476+
// FIXME(generic_const_items): this should instantiate with the alias item's args
477+
let ty = cx.tcx.type_of(assoc_item.unwrap()).instantiate_identity();
484478
let ct = lower_const_arg_for_rustdoc(cx.tcx, c, ty);
485479
Term::Constant(clean_middle_const(ty::Binder::dummy(ct), cx))
486480
}
@@ -3164,9 +3158,7 @@ fn clean_assoc_item_constraint<'tcx>(
31643158
.associated_items(trait_did)
31653159
.find_by_ident_and_kind(cx.tcx, constraint.ident, assoc_tag, trait_did)
31663160
.map(|item| item.def_id);
3167-
AssocItemConstraintKind::Equality {
3168-
term: clean_hir_term(assoc_item, term, constraint.span, cx),
3169-
}
3161+
AssocItemConstraintKind::Equality { term: clean_hir_term(assoc_item, term, cx) }
31703162
}
31713163
hir::AssocItemConstraintKind::Bound { bounds } => AssocItemConstraintKind::Bound {
31723164
bounds: bounds.iter().filter_map(|b| clean_generic_bound(b, cx)).collect(),

0 commit comments

Comments
 (0)