1
Fork 0

Auto merge of #106090 - WaffleLapkin:dereffffffffff, r=Nilstrieb

Remove some `ref` patterns from the compiler

Previous PR: https://github.com/rust-lang/rust/pull/105368

r? `@Nilstrieb`
This commit is contained in:
bors 2023-01-20 04:52:28 +00:00
commit 56ee85274e
53 changed files with 524 additions and 587 deletions

View file

@ -86,10 +86,10 @@ pub(super) fn build_custom_mir<'tcx>(
block_map: FxHashMap::default(),
};
let res = (|| {
let res: PResult<_> = try {
pctxt.parse_args(&params)?;
pctxt.parse_body(expr)
})();
pctxt.parse_body(expr)?;
};
if let Err(err) = res {
tcx.sess.diagnostic().span_fatal(
err.span,

View file

@ -113,7 +113,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
//
// it is usually better to focus on `the_value` rather
// than the entirety of block(s) surrounding it.
let adjusted_span = (|| {
let adjusted_span =
if let ExprKind::Block { block } = expr.kind
&& let Some(tail_ex) = this.thir[block].expr
{
@ -135,10 +135,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
tail_result_is_ignored: true,
span: expr.span,
});
return Some(expr.span);
}
None
})();
Some(expr.span)
} else {
None
};
let temp =
unpack!(block = this.as_temp(block, statement_scope, expr, Mutability::Not));

View file

@ -141,27 +141,22 @@ impl IntRange {
) -> Option<IntRange> {
let ty = value.ty();
if let Some((target_size, bias)) = Self::integral_size_and_signed_bias(tcx, ty) {
let val = (|| {
match value {
mir::ConstantKind::Val(ConstValue::Scalar(scalar), _) => {
// For this specific pattern we can skip a lot of effort and go
// straight to the result, after doing a bit of checking. (We
// could remove this branch and just fall through, which
// is more general but much slower.)
return scalar.to_bits_or_ptr_internal(target_size).unwrap().left();
}
mir::ConstantKind::Ty(c) => match c.kind() {
ty::ConstKind::Value(_) => bug!(
"encountered ConstValue in mir::ConstantKind::Ty, whereas this is expected to be in ConstantKind::Val"
),
_ => {}
},
_ => {}
let val = if let mir::ConstantKind::Val(ConstValue::Scalar(scalar), _) = value {
// For this specific pattern we can skip a lot of effort and go
// straight to the result, after doing a bit of checking. (We
// could remove this branch and just fall through, which
// is more general but much slower.)
scalar.to_bits_or_ptr_internal(target_size).unwrap().left()?
} else {
if let mir::ConstantKind::Ty(c) = value
&& let ty::ConstKind::Value(_) = c.kind()
{
bug!("encountered ConstValue in mir::ConstantKind::Ty, whereas this is expected to be in ConstantKind::Val");
}
// This is a more general form of the previous case.
value.try_eval_bits(tcx, param_env, ty)
})()?;
value.try_eval_bits(tcx, param_env, ty)?
};
let val = val ^ bias;
Some(IntRange { range: val..=val, bias })
} else {