Skip to content

Commit ae7c585

Browse files
committed
Don't resolve impl Trait in function def constants to the concrete type
1 parent 54802fa commit ae7c585

File tree

5 files changed

+11
-14
lines changed

5 files changed

+11
-14
lines changed

src/librustc/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,7 @@ impl<'tcx> Operand<'tcx> {
21052105
span,
21062106
ty,
21072107
user_ty: None,
2108-
literal: ty::Const::zero_sized(tcx, tcx.param_env(def_id).and(ty)),
2108+
literal: ty::Const::fn_def(tcx, ty),
21092109
})
21102110
}
21112111

src/librustc/ty/sty.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,12 +2000,10 @@ impl<'tcx> Const<'tcx> {
20002000
}
20012001

20022002
#[inline]
2003-
pub fn zero_sized(tcx: TyCtxt<'_, '_, 'tcx>, ty: ParamEnvAnd<'tcx, Ty<'tcx>>,) -> &'tcx Self {
2004-
let ty = tcx.lift_to_global(&ty).unwrap();
2005-
let layout = tcx.layout_of(ty).unwrap_or_else(|e| {
2006-
panic!("could not compute layout for {:?}: {:?}", ty, e)
2007-
});
2008-
Self::from_bytes(tcx, &[], layout)
2003+
pub fn fn_def(tcx: TyCtxt<'_, '_, 'tcx>, ty: Ty<'tcx>) -> &'tcx Self {
2004+
let alloc = Allocation::from_bytes(&[], ty::layout::Align::from_bytes(1, 1).unwrap());
2005+
let const_val = ConstValue::from_allocation(tcx, alloc);
2006+
Self::from_const_value(tcx, const_val, ty)
20092007
}
20102008

20112009
#[inline]

src/librustc_mir/hair/cx/expr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ fn method_callee<'a, 'gcx, 'tcx>(
851851
ty,
852852
span,
853853
kind: ExprKind::Literal {
854-
literal: ty::Const::zero_sized(cx.tcx(), cx.param_env.and(ty)),
854+
literal: ty::Const::fn_def(cx.tcx(), ty),
855855
user_ty,
856856
},
857857
}
@@ -910,9 +910,9 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
910910
Def::SelfCtor(..) => {
911911
let user_ty = user_substs_applied_to_def(cx, expr.hir_id, &def);
912912
ExprKind::Literal {
913-
literal: ty::Const::zero_sized(
913+
literal: ty::Const::fn_def(
914914
cx.tcx,
915-
cx.param_env.and(cx.tables().node_id_to_type(expr.hir_id)),
915+
cx.tables().node_id_to_type(expr.hir_id),
916916
),
917917
user_ty,
918918
}

src/librustc_mir/hair/cx/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
221221
if item.kind == ty::AssociatedKind::Method && item.ident.name == method_name {
222222
let method_ty = self.tcx.type_of(item.def_id);
223223
let method_ty = method_ty.subst(self.tcx, substs);
224-
return (method_ty, ty::Const::zero_sized(self.tcx, self.param_env.and(method_ty)));
224+
return (method_ty, ty::Const::fn_def(self.tcx, method_ty));
225225
}
226226
}
227227

src/librustc_mir/shim.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
445445
span: self.span,
446446
ty: func_ty,
447447
user_ty: None,
448-
literal: ty::Const::zero_sized(self.tcx, self.tcx.param_env(self.def_id).and(func_ty)),
448+
literal: ty::Const::fn_def(self.tcx, func_ty),
449449
});
450450

451451
let ref_loc = self.make_place(
@@ -688,7 +688,6 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
688688
let sig = tcx.fn_sig(def_id);
689689
let sig = tcx.erase_late_bound_regions(&sig);
690690
let span = tcx.def_span(def_id);
691-
let param_env = tcx.param_env(def_id);
692691

693692
debug!("build_call_shim: sig={:?}", sig);
694693

@@ -734,7 +733,7 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
734733
span,
735734
ty,
736735
user_ty: None,
737-
literal: ty::Const::zero_sized(tcx, param_env.and(ty)),
736+
literal: ty::Const::fn_def(tcx, ty),
738737
}),
739738
vec![rcvr])
740739
}

0 commit comments

Comments
 (0)