Skip to content

Commit 6ea763b

Browse files
committed
Auto merge of #3624 - rust-lang:rustup-2024-05-23, r=RalfJung
Automatic Rustup
2 parents 04a9a1a + 400835f commit 6ea763b

167 files changed

Lines changed: 1890 additions & 1810 deletions

File tree

Some content is hidden

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

‎compiler/rustc_ast/src/util/classify.rs‎

Lines changed: 91 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,17 @@ pub fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool {
8181
}
8282
}
8383

84+
pubenumTrailingBrace<'a>{
85+
/// Trailing brace in a macro call, like the one in `x as *const brace! {}`.
86+
/// We will suggest changing the macro call to a different delimiter.
87+
MacCall(&'a ast::MacCall),
88+
/// Trailing brace in any other expression, such as `a + B {}`. We will
89+
/// suggest wrapping the innermost expression in parentheses: `a + (B {})`.
90+
Expr(&'a ast::Expr),
91+
}
92+
8493
/// If an expression ends with `}`, returns the innermost expression ending in the `}`
85-
pubfnexpr_trailing_brace(mutexpr:&ast::Expr) -> Option<&ast::Expr>{
94+
pubfnexpr_trailing_brace(mutexpr:&ast::Expr) -> Option<TrailingBrace<'_>>{
8695
loop{
8796
match&expr.kind{
8897
AddrOf(_, _, e)
@@ -111,10 +120,14 @@ pub fn expr_trailing_brace(mut expr: &ast::Expr) -> Option<&ast::Expr> {
111120
| Struct(..)
112121
| TryBlock(..)
113122
| While(..)
114-
| ConstBlock(_) => breakSome(expr),
123+
| ConstBlock(_) => breakSome(TrailingBrace::Expr(expr)),
124+
125+
Cast(_, ty) => {
126+
breaktype_trailing_braced_mac_call(ty).map(TrailingBrace::MacCall);
127+
}
115128

116129
MacCall(mac) => {
117-
break(mac.args.delim == Delimiter::Brace).then_some(expr);
130+
break(mac.args.delim == Delimiter::Brace).then_some(TrailingBrace::MacCall(mac));
118131
}
119132

120133
InlineAsm(_) | OffsetOf(_, _) | IncludedBytes(_) | FormatArgs(_) => {
@@ -131,7 +144,6 @@ pub fn expr_trailing_brace(mut expr: &ast::Expr) -> Option<&ast::Expr> {
131144
| MethodCall(_)
132145
| Tup(_)
133146
| Lit(_)
134-
| Cast(_, _)
135147
| Type(_, _)
136148
| Await(_, _)
137149
| Field(_, _)
@@ -148,3 +160,78 @@ pub fn expr_trailing_brace(mut expr: &ast::Expr) -> Option<&ast::Expr> {
148160
}
149161
}
150162
}
163+
164+
/// If the type's last token is `}`, it must be due to a braced macro call, such
165+
/// as in `*const brace! { ... }`. Returns that trailing macro call.
166+
fntype_trailing_braced_mac_call(mutty:&ast::Ty) -> Option<&ast::MacCall>{
167+
loop{
168+
match&ty.kind{
169+
ast::TyKind::MacCall(mac) => {
170+
break(mac.args.delim == Delimiter::Brace).then_some(mac);
171+
}
172+
173+
ast::TyKind::Ptr(mut_ty) | ast::TyKind::Ref(_, mut_ty) => {
174+
ty = &mut_ty.ty;
175+
}
176+
177+
ast::TyKind::BareFn(fn_ty) => match&fn_ty.decl.output{
178+
ast::FnRetTy::Default(_) => breakNone,
179+
ast::FnRetTy::Ty(ret) => ty = ret,
180+
},
181+
182+
ast::TyKind::Path(_, path) => matchpath_return_type(path){
183+
Some(trailing_ty) => ty = trailing_ty,
184+
None => breakNone,
185+
},
186+
187+
ast::TyKind::TraitObject(bounds, _) | ast::TyKind::ImplTrait(_, bounds, _) => {
188+
match bounds.last(){
189+
Some(ast::GenericBound::Trait(bound, _)) => {
190+
matchpath_return_type(&bound.trait_ref.path){
191+
Some(trailing_ty) => ty = trailing_ty,
192+
None => breakNone,
193+
}
194+
}
195+
Some(ast::GenericBound::Outlives(_)) | None => breakNone,
196+
}
197+
}
198+
199+
ast::TyKind::Slice(..)
200+
| ast::TyKind::Array(..)
201+
| ast::TyKind::Never
202+
| ast::TyKind::Tup(..)
203+
| ast::TyKind::Paren(..)
204+
| ast::TyKind::Typeof(..)
205+
| ast::TyKind::Infer
206+
| ast::TyKind::ImplicitSelf
207+
| ast::TyKind::CVarArgs
208+
| ast::TyKind::Pat(..)
209+
| ast::TyKind::Dummy
210+
| ast::TyKind::Err(..) => breakNone,
211+
212+
// These end in brace, but cannot occur in a let-else statement.
213+
// They are only parsed as fields of a data structure. For the
214+
// purpose of denying trailing braces in the expression of a
215+
// let-else, we can disregard these.
216+
ast::TyKind::AnonStruct(..) | ast::TyKind::AnonUnion(..) => breakNone,
217+
}
218+
}
219+
}
220+
221+
/// Returns the trailing return type in the given path, if it has one.
222+
///
223+
/// ```ignore (illustrative)
224+
/// ::std::ops::FnOnce(&str) -> fn() -> *const c_void
225+
/// ^^^^^^^^^^^^^^^^^^^^^
226+
/// ```
227+
fnpath_return_type(path:&ast::Path) -> Option<&ast::Ty>{
228+
let last_segment = path.segments.last()?;
229+
let args = last_segment.args.as_ref()?;
230+
match&**args {
231+
ast::GenericArgs::Parenthesized(args) => match&args.output{
232+
ast::FnRetTy::Default(_) => None,
233+
ast::FnRetTy::Ty(ret) => Some(ret),
234+
},
235+
ast::GenericArgs::AngleBracketed(_) => None,
236+
}
237+
}

‎compiler/rustc_borrowck/src/type_check/constraint_conversion.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
136136

137137
fnconvert(
138138
&mutself,
139-
predicate: ty::OutlivesPredicate<ty::GenericArg<'tcx>, ty::Region<'tcx>>,
139+
predicate: ty::OutlivesPredicate<'tcx, ty::GenericArg<'tcx>>,
140140
constraint_category:ConstraintCategory<'tcx>,
141141
){
142142
debug!("generate: constraints at: {:#?}",self.locations);
@@ -276,7 +276,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
276276
&self,
277277
ty:Ty<'tcx>,
278278
next_outlives_predicates:&mutVec<(
279-
ty::OutlivesPredicate<ty::GenericArg<'tcx>, ty::Region<'tcx>>,
279+
ty::OutlivesPredicate<'tcx, ty::GenericArg<'tcx>>,
280280
ConstraintCategory<'tcx>,
281281
)>,
282282
) -> Ty<'tcx>{

‎compiler/rustc_codegen_gcc/src/intrinsic/simd.rs‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_codegen_ssa::mir::operand::OperandRef;
1414
use rustc_codegen_ssa::mir::place::PlaceRef;
1515
use rustc_codegen_ssa::traits::{BaseTypeMethods,BuilderMethods};
1616
use rustc_hir as hir;
17+
use rustc_middle::mir::BinOp;
1718
use rustc_middle::span_bug;
1819
use rustc_middle::ty::layout::HasTyCtxt;
1920
use rustc_middle::ty::{self,Ty};
@@ -122,12 +123,12 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
122123
let in_ty = arg_tys[0];
123124

124125
let comparison = match name {
125-
sym::simd_eq => Some(hir::BinOpKind::Eq),
126-
sym::simd_ne => Some(hir::BinOpKind::Ne),
127-
sym::simd_lt => Some(hir::BinOpKind::Lt),
128-
sym::simd_le => Some(hir::BinOpKind::Le),
129-
sym::simd_gt => Some(hir::BinOpKind::Gt),
130-
sym::simd_ge => Some(hir::BinOpKind::Ge),
126+
sym::simd_eq => Some(BinOp::Eq),
127+
sym::simd_ne => Some(BinOp::Ne),
128+
sym::simd_lt => Some(BinOp::Lt),
129+
sym::simd_le => Some(BinOp::Le),
130+
sym::simd_gt => Some(BinOp::Gt),
131+
sym::simd_ge => Some(BinOp::Ge),
131132
_ => None,
132133
};
133134

‎compiler/rustc_codegen_llvm/src/intrinsic.rs‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
1414
use rustc_codegen_ssa::mir::place::PlaceRef;
1515
use rustc_codegen_ssa::traits::*;
1616
use rustc_hir as hir;
17+
use rustc_middle::mir::BinOp;
1718
use rustc_middle::ty::layout::{FnAbiOf,HasTyCtxt,LayoutOf};
1819
use rustc_middle::ty::{self,GenericArgsRef,Ty};
1920
use rustc_middle::{bug, span_bug};
@@ -1104,12 +1105,12 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
11041105
let in_ty = arg_tys[0];
11051106

11061107
let comparison = match name {
1107-
sym::simd_eq => Some(hir::BinOpKind::Eq),
1108-
sym::simd_ne => Some(hir::BinOpKind::Ne),
1109-
sym::simd_lt => Some(hir::BinOpKind::Lt),
1110-
sym::simd_le => Some(hir::BinOpKind::Le),
1111-
sym::simd_gt => Some(hir::BinOpKind::Gt),
1112-
sym::simd_ge => Some(hir::BinOpKind::Ge),
1108+
sym::simd_eq => Some(BinOp::Eq),
1109+
sym::simd_ne => Some(BinOp::Ne),
1110+
sym::simd_lt => Some(BinOp::Lt),
1111+
sym::simd_le => Some(BinOp::Le),
1112+
sym::simd_gt => Some(BinOp::Gt),
1113+
sym::simd_ge => Some(BinOp::Ge),
11131114
_ => None,
11141115
};
11151116

‎compiler/rustc_codegen_ssa/src/base.rs‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
2020
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
2121
use rustc_data_structures::sync::par_map;
2222
use rustc_data_structures::unord::UnordMap;
23-
use rustc_hir as hir;
2423
use rustc_hir::def_id::{DefId,LOCAL_CRATE};
2524
use rustc_hir::lang_items::LangItem;
2625
use rustc_metadata::EncodedMetadata;
@@ -30,6 +29,7 @@ use rustc_middle::middle::debugger_visualizer::{DebuggerVisualizerFile, Debugger
3029
use rustc_middle::middle::exported_symbols;
3130
use rustc_middle::middle::exported_symbols::SymbolExportKind;
3231
use rustc_middle::middle::lang_items;
32+
use rustc_middle::mir::BinOp;
3333
use rustc_middle::mir::mono::{CodegenUnit,CodegenUnitNameBuilder,MonoItem};
3434
use rustc_middle::query::Providers;
3535
use rustc_middle::ty::layout::{HasTyCtxt,LayoutOf,TyAndLayout};
@@ -46,32 +46,32 @@ use std::time::{Duration, Instant};
4646

4747
use itertools::Itertools;
4848

49-
pubfnbin_op_to_icmp_predicate(op:hir::BinOpKind,signed:bool) -> IntPredicate{
49+
pubfnbin_op_to_icmp_predicate(op:BinOp,signed:bool) -> IntPredicate{
5050
match op {
51-
hir::BinOpKind::Eq => IntPredicate::IntEQ,
52-
hir::BinOpKind::Ne => IntPredicate::IntNE,
53-
hir::BinOpKind::Lt => {
51+
BinOp::Eq => IntPredicate::IntEQ,
52+
BinOp::Ne => IntPredicate::IntNE,
53+
BinOp::Lt => {
5454
if signed {
5555
IntPredicate::IntSLT
5656
}else{
5757
IntPredicate::IntULT
5858
}
5959
}
60-
hir::BinOpKind::Le => {
60+
BinOp::Le => {
6161
if signed {
6262
IntPredicate::IntSLE
6363
}else{
6464
IntPredicate::IntULE
6565
}
6666
}
67-
hir::BinOpKind::Gt => {
67+
BinOp::Gt => {
6868
if signed {
6969
IntPredicate::IntSGT
7070
}else{
7171
IntPredicate::IntUGT
7272
}
7373
}
74-
hir::BinOpKind::Ge => {
74+
BinOp::Ge => {
7575
if signed {
7676
IntPredicate::IntSGE
7777
}else{
@@ -86,14 +86,14 @@ pub fn bin_op_to_icmp_predicate(op: hir::BinOpKind, signed: bool) -> IntPredicat
8686
}
8787
}
8888

89-
pubfnbin_op_to_fcmp_predicate(op:hir::BinOpKind) -> RealPredicate{
89+
pubfnbin_op_to_fcmp_predicate(op:BinOp) -> RealPredicate{
9090
match op {
91-
hir::BinOpKind::Eq => RealPredicate::RealOEQ,
92-
hir::BinOpKind::Ne => RealPredicate::RealUNE,
93-
hir::BinOpKind::Lt => RealPredicate::RealOLT,
94-
hir::BinOpKind::Le => RealPredicate::RealOLE,
95-
hir::BinOpKind::Gt => RealPredicate::RealOGT,
96-
hir::BinOpKind::Ge => RealPredicate::RealOGE,
91+
BinOp::Eq => RealPredicate::RealOEQ,
92+
BinOp::Ne => RealPredicate::RealUNE,
93+
BinOp::Lt => RealPredicate::RealOLT,
94+
BinOp::Le => RealPredicate::RealOLE,
95+
BinOp::Gt => RealPredicate::RealOGT,
96+
BinOp::Ge => RealPredicate::RealOGE,
9797
op => {
9898
bug!(
9999
"comparison_op_to_fcmp_predicate: expected comparison operator, \
@@ -110,7 +110,7 @@ pub fn compare_simd_types<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
110110
rhs:Bx::Value,
111111
t:Ty<'tcx>,
112112
ret_ty:Bx::Type,
113-
op:hir::BinOpKind,
113+
op:BinOp,
114114
) -> Bx::Value{
115115
let signed = match t.kind(){
116116
ty::Float(_) => {

‎compiler/rustc_codegen_ssa/src/lib.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ pub enum CodegenErrors {
195195
EmptyVersionNumber,
196196
EncodingVersionMismatch{version_array:String,rlink_version:u32},
197197
RustcVersionMismatch{rustc_version:String},
198+
CorruptFile,
198199
}
199200

200201
pubfnprovide(providers:&mutProviders){
@@ -265,7 +266,9 @@ impl CodegenResults {
265266
});
266267
}
267268

268-
letmut decoder = MemDecoder::new(&data[4..],0);
269+
letOk(mut decoder) = MemDecoder::new(&data[4..],0)else{
270+
returnErr(CodegenErrors::CorruptFile);
271+
};
269272
let rustc_version = decoder.read_str();
270273
if rustc_version != sess.cfg_version{
271274
returnErr(CodegenErrors::RustcVersionMismatch{

‎compiler/rustc_codegen_ssa/src/mir/rvalue.rs‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::common::IntPredicate;
77
usecrate::traits::*;
88
usecrate::MemFlags;
99

10-
use rustc_hir as hir;
1110
use rustc_middle::mir;
1211
use rustc_middle::ty::cast::{CastTy,IntTy};
1312
use rustc_middle::ty::layout::{HasTyCtxt,LayoutOf,TyAndLayout};
@@ -896,9 +895,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
896895
| mir::BinOp::Le
897896
| mir::BinOp::Ge => {
898897
if is_float {
899-
bx.fcmp(base::bin_op_to_fcmp_predicate(op.to_hir_binop()), lhs, rhs)
898+
bx.fcmp(base::bin_op_to_fcmp_predicate(op), lhs, rhs)
900899
}else{
901-
bx.icmp(base::bin_op_to_icmp_predicate(op.to_hir_binop(), is_signed), lhs, rhs)
900+
bx.icmp(base::bin_op_to_icmp_predicate(op, is_signed), lhs, rhs)
902901
}
903902
}
904903
mir::BinOp::Cmp => {
@@ -912,16 +911,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
912911
// `PartialOrd`, so only use it in debug for now. Once LLVM can handle it
913912
// better (see <https://github.com/llvm/llvm-project/issues/73417>), it'll
914913
// be worth trying it in optimized builds as well.
915-
let is_gt = bx.icmp(pred(hir::BinOpKind::Gt), lhs, rhs);
914+
let is_gt = bx.icmp(pred(mir::BinOp::Gt), lhs, rhs);
916915
let gtext = bx.zext(is_gt, bx.type_i8());
917-
let is_lt = bx.icmp(pred(hir::BinOpKind::Lt), lhs, rhs);
916+
let is_lt = bx.icmp(pred(mir::BinOp::Lt), lhs, rhs);
918917
let ltext = bx.zext(is_lt, bx.type_i8());
919918
bx.unchecked_ssub(gtext, ltext)
920919
}else{
921920
// These operations are those expected by `tests/codegen/integer-cmp.rs`,
922921
// from <https://github.com/rust-lang/rust/pull/63767>.
923-
let is_lt = bx.icmp(pred(hir::BinOpKind::Lt), lhs, rhs);
924-
let is_ne = bx.icmp(pred(hir::BinOpKind::Ne), lhs, rhs);
922+
let is_lt = bx.icmp(pred(mir::BinOp::Lt), lhs, rhs);
923+
let is_ne = bx.icmp(pred(mir::BinOp::Ne), lhs, rhs);
925924
let ge = bx.select(
926925
is_ne,
927926
bx.cx().const_i8(Ordering::Greaterasi8),

‎compiler/rustc_const_eval/src/const_eval/machine.rs‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ use rustc_target::spec::abi::Abi as CallAbi;
2525
usecrate::errors::{LongRunning,LongRunningWarn};
2626
usecrate::fluent_generated as fluent;
2727
usecrate::interpret::{
28-
self, compile_time_machine, err_ub, throw_exhaust, throw_inval, throw_ub_custom,
28+
self, compile_time_machine, err_ub, throw_exhaust, throw_inval, throw_ub_custom, throw_unsup,
2929
throw_unsup_format,AllocId,AllocRange,ConstAllocation,CtfeProvenance,FnArg,FnVal,Frame,
30-
ImmTy,InterpCx,InterpResult,MPlaceTy,OpTy,Pointer,PointerArithmetic,Scalar,
30+
GlobalAlloc,ImmTy,InterpCx,InterpResult,MPlaceTy,OpTy,Pointer,PointerArithmetic,Scalar,
3131
};
3232

3333
usesuper::error::*;
@@ -759,11 +759,21 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
759759
ecx:&InterpCx<'mir,'tcx,Self>,
760760
alloc_id:AllocId,
761761
) -> InterpResult<'tcx>{
762+
// Check if this is the currently evaluated static.
762763
ifSome(alloc_id) == ecx.machine.static_root_ids.map(|(id, _)| id){
763-
Err(ConstEvalErrKind::RecursiveStatic.into())
764-
}else{
765-
Ok(())
764+
returnErr(ConstEvalErrKind::RecursiveStatic.into());
766765
}
766+
// If this is another static, make sure we fire off the query to detect cycles.
767+
// But only do that when checks for static recursion are enabled.
768+
if ecx.machine.static_root_ids.is_some(){
769+
ifletSome(GlobalAlloc::Static(def_id)) = ecx.tcx.try_get_global_alloc(alloc_id){
770+
if ecx.tcx.is_foreign_item(def_id){
771+
throw_unsup!(ExternStatic(def_id));
772+
}
773+
ecx.ctfe_query(|tcx| tcx.eval_static_initializer(def_id))?;
774+
}
775+
}
776+
Ok(())
767777
}
768778
}
769779

‎compiler/rustc_const_eval/src/interpret/intrinsics.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
255255
name = intrinsic_name,
256256
);
257257
}
258+
// This will always return 0.
258259
(a, b)
259260
}
260261
(Err(_), _) | (_,Err(_)) => {

0 commit comments

Comments
 (0)