Skip to content

Commit 4c27d34

Browse files
committed
directly use ConstValue for single literals in blocks
1 parent cc65bf3 commit 4c27d34

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

compiler/rustc_middle/src/ty/consts.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ impl<'tcx> Const<'tcx> {
3636
Self::from_opt_const_arg_anon_const(tcx, ty::WithOptConstParam::unknown(def_id))
3737
}
3838

39+
#[instrument(skip(tcx), level = "debug")]
3940
pub fn from_opt_const_arg_anon_const(
4041
tcx: TyCtxt<'tcx>,
4142
def: ty::WithOptConstParam<LocalDefId>,
@@ -53,6 +54,7 @@ impl<'tcx> Const<'tcx> {
5354
};
5455

5556
let expr = &tcx.hir().body(body_id).value;
57+
debug!(?expr);
5658

5759
let ty = tcx.type_of(def.def_id_for_type_of());
5860

@@ -69,11 +71,21 @@ impl<'tcx> Const<'tcx> {
6971
}
7072
}
7173

74+
#[instrument(skip(tcx), level = "debug")]
7275
fn try_eval_lit_or_param(
7376
tcx: TyCtxt<'tcx>,
7477
ty: Ty<'tcx>,
7578
expr: &'tcx hir::Expr<'tcx>,
7679
) -> Option<&'tcx Self> {
80+
// Unwrap a block, so that e.g. `{ P }` is recognised as a parameter. Const arguments
81+
// currently have to be wrapped in curly brackets, so it's necessary to special-case.
82+
let expr = match &expr.kind {
83+
hir::ExprKind::Block(block, _) if block.stmts.is_empty() && block.expr.is_some() => {
84+
block.expr.as_ref().unwrap()
85+
}
86+
_ => expr,
87+
};
88+
7789
let lit_input = match expr.kind {
7890
hir::ExprKind::Lit(ref lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: false }),
7991
hir::ExprKind::Unary(hir::UnOp::Neg, ref expr) => match expr.kind {
@@ -95,15 +107,6 @@ impl<'tcx> Const<'tcx> {
95107
}
96108
}
97109

98-
// Unwrap a block, so that e.g. `{ P }` is recognised as a parameter. Const arguments
99-
// currently have to be wrapped in curly brackets, so it's necessary to special-case.
100-
let expr = match &expr.kind {
101-
hir::ExprKind::Block(block, _) if block.stmts.is_empty() && block.expr.is_some() => {
102-
block.expr.as_ref().unwrap()
103-
}
104-
_ => expr,
105-
};
106-
107110
use hir::{def::DefKind::ConstParam, def::Res, ExprKind, Path, QPath};
108111
match expr.kind {
109112
ExprKind::Path(QPath::Resolved(_, &Path { res: Res::Def(ConstParam, def_id), .. })) => {

compiler/rustc_trait_selection/src/traits/coherence.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub fn add_placeholder_note(err: &mut rustc_errors::DiagnosticBuilder<'_>) {
5353
/// If there are types that satisfy both impls, invokes `on_overlap`
5454
/// with a suitably-freshened `ImplHeader` with those types
5555
/// substituted. Otherwise, invokes `no_overlap`.
56+
#[instrument(skip(tcx, skip_leak_check, on_overlap, no_overlap), level = "debug")]
5657
pub fn overlapping_impls<F1, F2, R>(
5758
tcx: TyCtxt<'_>,
5859
impl1_def_id: DefId,
@@ -65,12 +66,6 @@ where
6566
F1: FnOnce(OverlapResult<'_>) -> R,
6667
F2: FnOnce() -> R,
6768
{
68-
debug!(
69-
"overlapping_impls(\
70-
impl1_def_id={:?}, \
71-
impl2_def_id={:?})",
72-
impl1_def_id, impl2_def_id,
73-
);
7469
// Before doing expensive operations like entering an inference context, do
7570
// a quick check via fast_reject to tell if the impl headers could possibly
7671
// unify.
@@ -85,6 +80,7 @@ where
8580
.any(|(ty1, ty2)| {
8681
let t1 = fast_reject::simplify_type(tcx, ty1, SimplifyParams::No, StripReferences::No);
8782
let t2 = fast_reject::simplify_type(tcx, ty2, SimplifyParams::No, StripReferences::No);
83+
8884
if let (Some(t1), Some(t2)) = (t1, t2) {
8985
// Simplified successfully
9086
t1 != t2

compiler/rustc_trait_selection/src/traits/specialize/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,8 @@ pub fn translate_substs<'a, 'tcx>(
117117
/// Specialization is determined by the sets of types to which the impls apply;
118118
/// `impl1` specializes `impl2` if it applies to a subset of the types `impl2` applies
119119
/// to.
120+
#[instrument(skip(tcx), level = "debug")]
120121
pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId, DefId)) -> bool {
121-
debug!("specializes({:?}, {:?})", impl1_def_id, impl2_def_id);
122-
123122
// The feature gate should prevent introducing new specializations, but not
124123
// taking advantage of upstream ones.
125124
let features = tcx.features();

0 commit comments

Comments
 (0)