Skip to content

Commit be71fd4

Browse files
committed
Auto merge of #125331 - matthiaskrgr:rollup-4kfrh4n, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #124682 (Suggest setting lifetime in borrowck error involving types with elided lifetimes) - #124917 (Check whether the next_node is else-less if in get_return_block) - #125106 (coverage: Memoize and simplify counter expressions) - #125173 (Remove `Rvalue::CheckedBinaryOp`) - #125305 (add some codegen tests for issue 120493) - #125314 ( Add an experimental feature gate for global registration) - #125318 (Migrate `run-make/rustdoc-scrape-examples-whitespace` to `rmake.rs`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 474bee7 + 1640225 commit be71fd4

File tree

159 files changed

+1866
-1759
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+1866
-1759
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
560560
gate_all!(postfix_match, "postfix match is experimental");
561561
gate_all!(mut_ref, "mutable by-reference bindings are experimental");
562562
gate_all!(precise_capturing, "precise captures on `impl Trait` are experimental");
563+
gate_all!(global_registration, "global registration is experimental");
563564

564565
if !visitor.features.never_patterns {
565566
if let Some(spans) = spans.get(&sym::never_patterns) {

compiler/rustc_borrowck/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1312,8 +1312,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13121312
);
13131313
}
13141314

1315-
Rvalue::BinaryOp(_bin_op, box (operand1, operand2))
1316-
| Rvalue::CheckedBinaryOp(_bin_op, box (operand1, operand2)) => {
1315+
Rvalue::BinaryOp(_bin_op, box (operand1, operand2)) => {
13171316
self.consume_operand(location, (operand1, span), flow_state);
13181317
self.consume_operand(location, (operand2, span), flow_state);
13191318
}

compiler/rustc_borrowck/src/polonius/loan_invalidations.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,7 @@ impl<'cx, 'tcx> LoanInvalidationsGenerator<'cx, 'tcx> {
302302
);
303303
}
304304

305-
Rvalue::BinaryOp(_bin_op, box (operand1, operand2))
306-
| Rvalue::CheckedBinaryOp(_bin_op, box (operand1, operand2)) => {
305+
Rvalue::BinaryOp(_bin_op, box (operand1, operand2)) => {
307306
self.consume_operand(location, operand1);
308307
self.consume_operand(location, operand2);
309308
}

compiler/rustc_borrowck/src/type_check/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2417,8 +2417,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24172417
self.check_operand(op, location);
24182418
}
24192419

2420-
Rvalue::BinaryOp(_, box (left, right))
2421-
| Rvalue::CheckedBinaryOp(_, box (left, right)) => {
2420+
Rvalue::BinaryOp(_, box (left, right)) => {
24222421
self.check_operand(left, location);
24232422
self.check_operand(right, location);
24242423
}
@@ -2445,7 +2444,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24452444
| Rvalue::Cast(..)
24462445
| Rvalue::ShallowInitBox(..)
24472446
| Rvalue::BinaryOp(..)
2448-
| Rvalue::CheckedBinaryOp(..)
24492447
| Rvalue::NullaryOp(..)
24502448
| Rvalue::CopyForDeref(..)
24512449
| Rvalue::UnaryOp(..)

compiler/rustc_codegen_cranelift/src/base.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -609,14 +609,11 @@ fn codegen_stmt<'tcx>(
609609
let lhs = codegen_operand(fx, &lhs_rhs.0);
610610
let rhs = codegen_operand(fx, &lhs_rhs.1);
611611

612-
let res = crate::num::codegen_binop(fx, bin_op, lhs, rhs);
613-
lval.write_cvalue(fx, res);
614-
}
615-
Rvalue::CheckedBinaryOp(bin_op, ref lhs_rhs) => {
616-
let lhs = codegen_operand(fx, &lhs_rhs.0);
617-
let rhs = codegen_operand(fx, &lhs_rhs.1);
618-
619-
let res = crate::num::codegen_checked_int_binop(fx, bin_op, lhs, rhs);
612+
let res = if let Some(bin_op) = bin_op.overflowing_to_wrapping() {
613+
crate::num::codegen_checked_int_binop(fx, bin_op, lhs, rhs)
614+
} else {
615+
crate::num::codegen_binop(fx, bin_op, lhs, rhs)
616+
};
620617
lval.write_cvalue(fx, res);
621618
}
622619
Rvalue::UnaryOp(un_op, ref operand) => {

compiler/rustc_codegen_cranelift/src/codegen_i128.rs

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ pub(crate) fn maybe_codegen<'tcx>(
7070
}
7171
BinOp::Lt | BinOp::Le | BinOp::Eq | BinOp::Ge | BinOp::Gt | BinOp::Ne | BinOp::Cmp => None,
7272
BinOp::Shl | BinOp::ShlUnchecked | BinOp::Shr | BinOp::ShrUnchecked => None,
73+
BinOp::AddWithOverflow | BinOp::SubWithOverflow | BinOp::MulWithOverflow => unreachable!(),
7374
}
7475
}
7576

@@ -132,6 +133,7 @@ pub(crate) fn maybe_codegen_checked<'tcx>(
132133
Some(out_place.to_cvalue(fx))
133134
}
134135
BinOp::AddUnchecked | BinOp::SubUnchecked | BinOp::MulUnchecked => unreachable!(),
136+
BinOp::AddWithOverflow | BinOp::SubWithOverflow | BinOp::MulWithOverflow => unreachable!(),
135137
BinOp::Offset => unreachable!("offset should only be used on pointers, not 128bit ints"),
136138
BinOp::Div | BinOp::Rem => unreachable!(),
137139
BinOp::Cmp => unreachable!(),

compiler/rustc_codegen_cranelift/src/num.rs

+3
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ pub(crate) fn codegen_int_binop<'tcx>(
179179
}
180180
}
181181
BinOp::Offset => unreachable!("Offset is not an integer operation"),
182+
BinOp::AddWithOverflow | BinOp::SubWithOverflow | BinOp::MulWithOverflow => {
183+
unreachable!("Overflow binops handled by `codegen_checked_int_binop`")
184+
}
182185
// Compare binops handles by `codegen_binop`.
183186
BinOp::Eq | BinOp::Ne | BinOp::Lt | BinOp::Le | BinOp::Gt | BinOp::Ge | BinOp::Cmp => {
184187
unreachable!("{:?}({:?}, {:?})", bin_op, in_lhs.layout().ty, in_rhs.layout().ty);

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

+21-15
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,22 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
576576
}
577577
}
578578

579+
mir::Rvalue::BinaryOp(op_with_overflow, box (ref lhs, ref rhs))
580+
if let Some(op) = op_with_overflow.overflowing_to_wrapping() =>
581+
{
582+
let lhs = self.codegen_operand(bx, lhs);
583+
let rhs = self.codegen_operand(bx, rhs);
584+
let result = self.codegen_scalar_checked_binop(
585+
bx,
586+
op,
587+
lhs.immediate(),
588+
rhs.immediate(),
589+
lhs.layout.ty,
590+
);
591+
let val_ty = op.ty(bx.tcx(), lhs.layout.ty, rhs.layout.ty);
592+
let operand_ty = Ty::new_tup(bx.tcx(), &[val_ty, bx.tcx().types.bool]);
593+
OperandRef { val: result, layout: bx.cx().layout_of(operand_ty) }
594+
}
579595
mir::Rvalue::BinaryOp(op, box (ref lhs, ref rhs)) => {
580596
let lhs = self.codegen_operand(bx, lhs);
581597
let rhs = self.codegen_operand(bx, rhs);
@@ -604,20 +620,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
604620
layout: bx.cx().layout_of(op.ty(bx.tcx(), lhs.layout.ty, rhs.layout.ty)),
605621
}
606622
}
607-
mir::Rvalue::CheckedBinaryOp(op, box (ref lhs, ref rhs)) => {
608-
let lhs = self.codegen_operand(bx, lhs);
609-
let rhs = self.codegen_operand(bx, rhs);
610-
let result = self.codegen_scalar_checked_binop(
611-
bx,
612-
op,
613-
lhs.immediate(),
614-
rhs.immediate(),
615-
lhs.layout.ty,
616-
);
617-
let val_ty = op.ty(bx.tcx(), lhs.layout.ty, rhs.layout.ty);
618-
let operand_ty = Ty::new_tup(bx.tcx(), &[val_ty, bx.tcx().types.bool]);
619-
OperandRef { val: result, layout: bx.cx().layout_of(operand_ty) }
620-
}
621623

622624
mir::Rvalue::UnaryOp(op, ref operand) => {
623625
let operand = self.codegen_operand(bx, operand);
@@ -928,6 +930,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
928930
bx.select(is_lt, bx.cx().const_i8(Ordering::Less as i8), ge)
929931
}
930932
}
933+
mir::BinOp::AddWithOverflow
934+
| mir::BinOp::SubWithOverflow
935+
| mir::BinOp::MulWithOverflow => {
936+
bug!("{op:?} needs to return a pair, so call codegen_scalar_checked_binop instead")
937+
}
931938
}
932939
}
933940

@@ -1040,7 +1047,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10401047
mir::Rvalue::Cast(..) | // (*)
10411048
mir::Rvalue::ShallowInitBox(..) | // (*)
10421049
mir::Rvalue::BinaryOp(..) |
1043-
mir::Rvalue::CheckedBinaryOp(..) |
10441050
mir::Rvalue::UnaryOp(..) |
10451051
mir::Rvalue::Discriminant(..) |
10461052
mir::Rvalue::NullaryOp(..) |

compiler/rustc_const_eval/src/interpret/step.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
167167
let left = self.read_immediate(&self.eval_operand(left, layout)?)?;
168168
let layout = util::binop_right_homogeneous(bin_op).then_some(left.layout);
169169
let right = self.read_immediate(&self.eval_operand(right, layout)?)?;
170-
self.binop_ignore_overflow(bin_op, &left, &right, &dest)?;
171-
}
172-
173-
CheckedBinaryOp(bin_op, box (ref left, ref right)) => {
174-
// Due to the extra boolean in the result, we can never reuse the `dest.layout`.
175-
let left = self.read_immediate(&self.eval_operand(left, None)?)?;
176-
let layout = util::binop_right_homogeneous(bin_op).then_some(left.layout);
177-
let right = self.read_immediate(&self.eval_operand(right, layout)?)?;
178-
self.binop_with_overflow(bin_op, &left, &right, &dest)?;
170+
if let Some(bin_op) = bin_op.overflowing_to_wrapping() {
171+
self.binop_with_overflow(bin_op, &left, &right, &dest)?;
172+
} else {
173+
self.binop_ignore_overflow(bin_op, &left, &right, &dest)?;
174+
}
179175
}
180176

181177
UnaryOp(un_op, ref operand) => {

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
580580
}
581581
}
582582

583-
Rvalue::BinaryOp(op, box (lhs, rhs)) | Rvalue::CheckedBinaryOp(op, box (lhs, rhs)) => {
583+
Rvalue::BinaryOp(op, box (lhs, rhs)) => {
584584
let lhs_ty = lhs.ty(self.body, self.tcx);
585585
let rhs_ty = rhs.ty(self.body, self.tcx);
586586

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ where
261261
| Rvalue::Cast(_, operand, _)
262262
| Rvalue::ShallowInitBox(operand, _) => in_operand::<Q, _>(cx, in_local, operand),
263263

264-
Rvalue::BinaryOp(_, box (lhs, rhs)) | Rvalue::CheckedBinaryOp(_, box (lhs, rhs)) => {
264+
Rvalue::BinaryOp(_, box (lhs, rhs)) => {
265265
in_operand::<Q, _>(cx, in_local, lhs) || in_operand::<Q, _>(cx, in_local, rhs)
266266
}
267267

compiler/rustc_const_eval/src/transform/check_consts/resolver.rs

-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ where
200200
| mir::Rvalue::Repeat(..)
201201
| mir::Rvalue::Len(..)
202202
| mir::Rvalue::BinaryOp(..)
203-
| mir::Rvalue::CheckedBinaryOp(..)
204203
| mir::Rvalue::NullaryOp(..)
205204
| mir::Rvalue::UnaryOp(..)
206205
| mir::Rvalue::Discriminant(..)

compiler/rustc_const_eval/src/transform/validate.rs

+2-27
Original file line numberDiff line numberDiff line change
@@ -1037,8 +1037,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
10371037
)
10381038
}
10391039
}
1040-
AddUnchecked | SubUnchecked | MulUnchecked | Shl | ShlUnchecked | Shr
1041-
| ShrUnchecked => {
1040+
AddUnchecked | AddWithOverflow | SubUnchecked | SubWithOverflow
1041+
| MulUnchecked | MulWithOverflow | Shl | ShlUnchecked | Shr | ShrUnchecked => {
10421042
for x in [a, b] {
10431043
check_kinds!(
10441044
x,
@@ -1067,31 +1067,6 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
10671067
}
10681068
}
10691069
}
1070-
Rvalue::CheckedBinaryOp(op, vals) => {
1071-
use BinOp::*;
1072-
let a = vals.0.ty(&self.body.local_decls, self.tcx);
1073-
let b = vals.1.ty(&self.body.local_decls, self.tcx);
1074-
match op {
1075-
Add | Sub | Mul => {
1076-
for x in [a, b] {
1077-
check_kinds!(
1078-
x,
1079-
"Cannot perform checked arithmetic on type {:?}",
1080-
ty::Uint(..) | ty::Int(..)
1081-
)
1082-
}
1083-
if a != b {
1084-
self.fail(
1085-
location,
1086-
format!(
1087-
"Cannot perform checked arithmetic on unequal types {a:?} and {b:?}"
1088-
),
1089-
);
1090-
}
1091-
}
1092-
_ => self.fail(location, format!("There is no checked version of {op:?}")),
1093-
}
1094-
}
10951070
Rvalue::UnaryOp(op, operand) => {
10961071
let a = operand.ty(&self.body.local_decls, self.tcx);
10971072
match op {

compiler/rustc_const_eval/src/util/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ pub fn binop_left_homogeneous(op: mir::BinOp) -> bool {
1919
match op {
2020
Add | AddUnchecked | Sub | SubUnchecked | Mul | MulUnchecked | Div | Rem | BitXor
2121
| BitAnd | BitOr | Offset | Shl | ShlUnchecked | Shr | ShrUnchecked => true,
22-
Eq | Ne | Lt | Le | Gt | Ge | Cmp => false,
22+
AddWithOverflow | SubWithOverflow | MulWithOverflow | Eq | Ne | Lt | Le | Gt | Ge | Cmp => {
23+
false
24+
}
2325
}
2426
}
2527

@@ -29,8 +31,9 @@ pub fn binop_left_homogeneous(op: mir::BinOp) -> bool {
2931
pub fn binop_right_homogeneous(op: mir::BinOp) -> bool {
3032
use rustc_middle::mir::BinOp::*;
3133
match op {
32-
Add | AddUnchecked | Sub | SubUnchecked | Mul | MulUnchecked | Div | Rem | BitXor
33-
| BitAnd | BitOr | Eq | Ne | Lt | Le | Gt | Ge | Cmp => true,
34+
Add | AddUnchecked | AddWithOverflow | Sub | SubUnchecked | SubWithOverflow | Mul
35+
| MulUnchecked | MulWithOverflow | Div | Rem | BitXor | BitAnd | BitOr | Eq | Ne | Lt
36+
| Le | Gt | Ge | Cmp => true,
3437
Offset | Shl | ShlUnchecked | Shr | ShrUnchecked => false,
3538
}
3639
}

compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ declare_features! (
489489
(incomplete, generic_const_exprs, "1.56.0", Some(76560)),
490490
/// Allows generic parameters and where-clauses on free & associated const items.
491491
(incomplete, generic_const_items, "1.73.0", Some(113521)),
492+
/// Allows registering static items globally, possibly across crates, to iterate over at runtime.
493+
(unstable, global_registration, "CURRENT_RUSTC_VERSION", Some(125119)),
492494
/// Allows using `..=X` as a patterns in slices.
493495
(unstable, half_open_range_patterns_in_slices, "1.66.0", Some(67264)),
494496
/// Allows `if let` guard in match arms.

compiler/rustc_infer/messages.ftl

+4-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ infer_label_bad = {$bad_kind ->
164164
infer_lf_bound_not_satisfied = lifetime bound not satisfied
165165
infer_lifetime_mismatch = lifetime mismatch
166166
167-
infer_lifetime_param_suggestion = consider introducing a named lifetime parameter{$is_impl ->
167+
infer_lifetime_param_suggestion = consider {$is_reuse ->
168+
[true] reusing
169+
*[false] introducing
170+
} a named lifetime parameter{$is_impl ->
168171
[true] {" "}and update trait if needed
169172
*[false] {""}
170173
}

0 commit comments

Comments
 (0)