Skip to content

Commit e076ce8

Browse files
committed
Address review comments
1 parent 2fe91f2 commit e076ce8

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,6 +2125,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21252125
);
21262126
ty::Const::new_unevaluated(tcx, ty::UnevaluatedConst::new(did, args))
21272127
}
2128+
// FIXME(const_generics): create real const to allow fn items as const paths
21282129
Res::Def(DefKind::Fn | DefKind::AssocFn, _) => ty::Const::new_error_with_message(
21292130
tcx,
21302131
span,
@@ -2170,10 +2171,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21702171
| Res::Local(_)
21712172
| Res::ToolMod
21722173
| Res::NonMacroAttr(_)
2173-
| Res::Err => Const::new_error(
2174-
tcx,
2175-
tcx.dcx().span_delayed_bug(span, "invalid Res for const path"),
2176-
),
2174+
| Res::Err => Const::new_error_with_message(tcx, span, "invalid Res for const path"),
21772175
}
21782176
}
21792177

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ pub fn lower_ty<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
230230
}
231231

232232
/// This is for rustdoc.
233-
pub fn lower_const_arg<'tcx>(
233+
// FIXME(const_generics): having special methods for rustdoc in `rustc_hir_analysis` is cursed
234+
pub fn lower_const_arg_for_rustdoc<'tcx>(
234235
tcx: TyCtxt<'tcx>,
235236
hir_ct: &hir::ConstArg<'tcx>,
236237
feed: FeedConstTy,

compiler/rustc_middle/src/ty/consts.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ impl<'tcx> rustc_type_ir::inherent::Const<TyCtxt<'tcx>> for Const<'tcx> {
185185
}
186186

187187
impl<'tcx> Const<'tcx> {
188+
// FIXME: move this and try_from_lit to hir_ty_lowering like lower_const_arg/from_const_arg
188189
/// Literals and const generic parameters are eagerly converted to a constant, everything else
189190
/// becomes `Unevaluated`.
190191
#[instrument(skip(tcx), level = "debug")]

src/librustdoc/clean/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use rustc_hir::PredicateOrigin;
4343
use rustc_hir::def::{CtorKind, DefKind, Res};
4444
use rustc_hir::def_id::{DefId, DefIdMap, DefIdSet, LOCAL_CRATE, LocalDefId};
4545
use rustc_hir_analysis::hir_ty_lowering::FeedConstTy;
46-
use rustc_hir_analysis::{lower_const_arg, lower_ty};
46+
use rustc_hir_analysis::{lower_const_arg_for_rustdoc, lower_ty};
4747
use rustc_middle::metadata::Reexport;
4848
use rustc_middle::middle::resolve_bound_vars as rbv;
4949
use rustc_middle::ty::{self, AdtKind, GenericArgsRef, Ty, TyCtxt, TypeVisitableExt, TypingMode};
@@ -437,7 +437,7 @@ fn clean_hir_term<'tcx>(term: &hir::Term<'tcx>, cx: &mut DocContext<'tcx>) -> Te
437437
match term {
438438
hir::Term::Ty(ty) => Term::Type(clean_ty(ty, cx)),
439439
hir::Term::Const(c) => {
440-
let ct = lower_const_arg(cx.tcx, c, FeedConstTy::No);
440+
let ct = lower_const_arg_for_rustdoc(cx.tcx, c, FeedConstTy::No);
441441
Term::Constant(clean_middle_const(ty::Binder::dummy(ct), cx))
442442
}
443443
}
@@ -625,8 +625,9 @@ fn clean_generic_param<'tcx>(
625625
hir::GenericParamKind::Const { ty, default, synthetic } => {
626626
(param.name.ident().name, GenericParamDefKind::Const {
627627
ty: Box::new(clean_ty(ty, cx)),
628-
default: default
629-
.map(|ct| Box::new(lower_const_arg(cx.tcx, ct, FeedConstTy::No).to_string())),
628+
default: default.map(|ct| {
629+
Box::new(lower_const_arg_for_rustdoc(cx.tcx, ct, FeedConstTy::No).to_string())
630+
}),
630631
synthetic,
631632
})
632633
}
@@ -1813,7 +1814,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
18131814
// `const_eval_poly` tries to first substitute generic parameters which
18141815
// results in an ICE while manually constructing the constant and using `eval`
18151816
// does nothing for `ConstKind::Param`.
1816-
let ct = lower_const_arg(cx.tcx, const_arg, FeedConstTy::No);
1817+
let ct = lower_const_arg_for_rustdoc(cx.tcx, const_arg, FeedConstTy::No);
18171818
let ct = if let hir::ConstArgKind::Anon(hir::AnonConst { def_id, .. }) =
18181819
const_arg.kind
18191820
{

0 commit comments

Comments
 (0)