Skip to content

Commit fe0f6c6

Browse files
committed
Auto merge of #5194 - JohnTitor:rustup-0219, r=matthiaskrgr
Rustup to rust-lang/rust#69181 changelog: none
2 parents 27acea0 + aa4cf72 commit fe0f6c6

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

clippy_lints/src/consts.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
226226
return self.ifthenelse(cond, then, otherwise);
227227
}
228228
match e.kind {
229-
ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id),
229+
ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id, self.tables.expr_ty(e)),
230230
ExprKind::Block(ref block, _) => self.block(block),
231231
ExprKind::Lit(ref lit) => Some(lit_to_constant(&lit.node, self.tables.expr_ty_opt(e))),
232232
ExprKind::Array(ref vec) => self.multi(vec).map(Constant::Vec),
@@ -319,7 +319,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
319319
}
320320

321321
/// Lookup a possibly constant expression from a `ExprKind::Path`.
322-
fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId) -> Option<Constant> {
322+
fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'cc>) -> Option<Constant> {
323323
let res = self.tables.qpath_res(qpath, id);
324324
match res {
325325
Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => {
@@ -334,7 +334,8 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
334334
.lcx
335335
.tcx
336336
.const_eval_resolve(self.param_env, def_id, substs, None, None)
337-
.ok()?;
337+
.ok()
338+
.map(|val| rustc::ty::Const::from_value(self.lcx.tcx, val, ty))?;
338339
let result = miri_to_const(&result);
339340
if result.is_some() {
340341
self.needed_resolution = true;

clippy_lints/src/enum_clike.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
4646
for var in def.variants {
4747
if let Some(anon_const) = &var.disr_expr {
4848
let def_id = cx.tcx.hir().body_owner_def_id(anon_const.body);
49-
let constant = cx.tcx.const_eval_poly(def_id).ok();
49+
let mut ty = cx.tcx.type_of(def_id);
50+
let constant = cx
51+
.tcx
52+
.const_eval_poly(def_id)
53+
.ok()
54+
.map(|val| rustc::ty::Const::from_value(cx.tcx, val, ty));
5055
if let Some(Constant::Int(val)) = constant.and_then(miri_to_const) {
51-
let mut ty = cx.tcx.type_of(def_id);
5256
if let ty::Adt(adt, _) = ty.kind {
5357
if adt.is_enum() {
5458
ty = adt.repr.discr_type().to_ty(cx.tcx);

0 commit comments

Comments
 (0)