Skip to content

Commit 66428d9

Browse files
committed
Auto merge of #149682 - matthiaskrgr:rollup-serlk7i, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - #148662 (alloc: Document panics when allocations will exceed max) - #148811 (core docs: rewrite `panic::Location::caller` with visual line/column numbers) - #149101 (Improve mutable-binding suggestion to include name) - #149477 (float::maximum/minimum: make docs more streamlined) - #149547 (library: Rename `IterRange*` to `Range*Iter`) - #149548 (Generate delegation error body when delegation is not resolved) - #149630 (Check identifiers defined in macros when suggesting identifiers hidden by hygiene) - #149647 (Add regression test for 141845) - #149661 (Fix for LLVM22 making lowering decisions dependent on RuntimeLibraryInfo.) - #149666 (Add perma-unstable `--print=backend-has-zstd` for use by compiletest) - #149671 (interpret: test SNaN handling of float min/max and update comments) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 97b131c + a43b30c commit 66428d9

File tree

49 files changed

+561
-310
lines changed

Some content is hidden

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

49 files changed

+561
-310
lines changed

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
9696
let generics = self.lower_delegation_generics(span);
9797
DelegationResults { body_id, sig, ident, generics }
9898
}
99-
Err(err) => self.generate_delegation_error(err, span),
99+
Err(err) => self.generate_delegation_error(err, span, delegation),
100100
}
101101
}
102102

@@ -404,6 +404,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
404404
&mut self,
405405
err: ErrorGuaranteed,
406406
span: Span,
407+
delegation: &Delegation,
407408
) -> DelegationResults<'hir> {
408409
let generics = self.lower_delegation_generics(span);
409410

@@ -418,8 +419,41 @@ impl<'hir> LoweringContext<'_, 'hir> {
418419
let header = self.generate_header_error();
419420
let sig = hir::FnSig { decl, header, span };
420421

421-
let ident = Ident::dummy();
422-
let body_id = self.lower_body(|this| (&[], this.mk_expr(hir::ExprKind::Err(err), span)));
422+
let ident = self.lower_ident(delegation.ident);
423+
424+
let body_id = self.lower_body(|this| {
425+
let body_expr = match delegation.body.as_ref() {
426+
Some(box block) => {
427+
// Generates a block when we failed to resolve delegation, where a target expression is its only statement,
428+
// thus there will be no ICEs on further stages of analysis (see #144594)
429+
430+
// As we generate a void function we want to convert target expression to statement to avoid additional
431+
// errors, such as mismatched return type
432+
let stmts = this.arena.alloc_from_iter([hir::Stmt {
433+
hir_id: this.next_id(),
434+
kind: rustc_hir::StmtKind::Semi(
435+
this.arena.alloc(this.lower_target_expr(block)),
436+
),
437+
span,
438+
}]);
439+
440+
let block = this.arena.alloc(hir::Block {
441+
stmts,
442+
expr: None,
443+
hir_id: this.next_id(),
444+
rules: hir::BlockCheckMode::DefaultBlock,
445+
span,
446+
targeted_by_break: false,
447+
});
448+
449+
hir::ExprKind::Block(block, None)
450+
}
451+
None => hir::ExprKind::Err(err),
452+
};
453+
454+
(&[], this.mk_expr(body_expr, span))
455+
});
456+
423457
DelegationResults { ident, generics, body_id, sig }
424458
}
425459

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3940,13 +3940,30 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
39403940
if let Some(decl) = local_decl
39413941
&& decl.can_be_made_mutable()
39423942
{
3943+
let is_for_loop = matches!(
3944+
decl.local_info(),
3945+
LocalInfo::User(BindingForm::Var(VarBindingForm {
3946+
opt_match_place: Some((_, match_span)),
3947+
..
3948+
})) if matches!(match_span.desugaring_kind(), Some(DesugaringKind::ForLoop))
3949+
);
3950+
let message = if is_for_loop
3951+
&& let Ok(binding_name) =
3952+
self.infcx.tcx.sess.source_map().span_to_snippet(decl.source_info.span)
3953+
{
3954+
format!("(mut {}) ", binding_name)
3955+
} else {
3956+
"mut ".to_string()
3957+
};
39433958
err.span_suggestion_verbose(
39443959
decl.source_info.span.shrink_to_lo(),
39453960
"consider making this binding mutable",
3946-
"mut ".to_string(),
3961+
message,
39473962
Applicability::MachineApplicable,
39483963
);
3964+
39493965
if !from_arg
3966+
&& !is_for_loop
39503967
&& matches!(
39513968
decl.local_info(),
39523969
LocalInfo::User(BindingForm::Var(VarBindingForm {

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn write_output_file<'ll>(
7575
let result = unsafe {
7676
let pm = llvm::LLVMCreatePassManager();
7777
llvm::LLVMAddAnalysisPasses(target, pm);
78-
llvm::LLVMRustAddLibraryInfo(pm, m, no_builtins);
78+
llvm::LLVMRustAddLibraryInfo(target, pm, m, no_builtins);
7979
llvm::LLVMRustWriteOutputFile(
8080
target,
8181
pm,

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ impl CodegenBackend for LlvmCodegenBackend {
257257
}
258258
writeln!(out).unwrap();
259259
}
260+
PrintKind::BackendHasZstd => {
261+
let has_zstd = llvm::LLVMRustLLVMHasZstdCompression();
262+
writeln!(out, "{has_zstd}").unwrap();
263+
}
260264
PrintKind::CodeModels => {
261265
writeln!(out, "Available code models:").unwrap();
262266
for name in &["tiny", "small", "kernel", "medium", "large"] {

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,6 +2379,7 @@ unsafe extern "C" {
23792379
) -> *mut TargetMachine;
23802380

23812381
pub(crate) fn LLVMRustAddLibraryInfo<'a>(
2382+
T: &TargetMachine,
23822383
PM: &PassManager<'a>,
23832384
M: &'a Module,
23842385
DisableSimplifyLibCalls: bool,

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,20 @@ pub(crate) enum MinMax {
4040
/// In particular, `-0.0` is considered smaller than `+0.0` and
4141
/// if either input is NaN, the result is NaN.
4242
Minimum,
43-
/// The IEEE-2008 `minNum` operation - see `f32::min` etc.
43+
/// The IEEE-2008 `minNum` operation with the SNaN handling of the
44+
/// IEEE-2019 `minimumNumber` operation - see `f32::min` etc.
4445
/// In particular, if the inputs are `-0.0` and `+0.0`, the result is non-deterministic,
45-
/// and if one argument is NaN, the other one is returned.
46-
MinNum,
46+
/// and if one argument is NaN (quiet or signaling), the other one is returned.
47+
MinimumNumber,
4748
/// The IEEE-2019 `maximum` operation - see `f32::maximum` etc.
4849
/// In particular, `-0.0` is considered smaller than `+0.0` and
4950
/// if either input is NaN, the result is NaN.
5051
Maximum,
51-
/// The IEEE-2008 `maxNum` operation - see `f32::max` etc.
52+
/// The IEEE-2008 `maxNum` operation with the SNaN handling of the
53+
/// IEEE-2019 `maximumNumber` operation - see `f32::max` etc.
5254
/// In particular, if the inputs are `-0.0` and `+0.0`, the result is non-deterministic,
53-
/// and if one argument is NaN, the other one is returned.
54-
MaxNum,
55+
/// and if one argument is NaN (quiet or signaling), the other one is returned.
56+
MaximumNumber,
5557
}
5658

5759
/// Directly returns an `Allocation` containing an absolute path representation of the given type.
@@ -524,10 +526,18 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
524526
self.write_scalar(Scalar::from_target_usize(align.bytes(), self), dest)?;
525527
}
526528

527-
sym::minnumf16 => self.float_minmax_intrinsic::<Half>(args, MinMax::MinNum, dest)?,
528-
sym::minnumf32 => self.float_minmax_intrinsic::<Single>(args, MinMax::MinNum, dest)?,
529-
sym::minnumf64 => self.float_minmax_intrinsic::<Double>(args, MinMax::MinNum, dest)?,
530-
sym::minnumf128 => self.float_minmax_intrinsic::<Quad>(args, MinMax::MinNum, dest)?,
529+
sym::minnumf16 => {
530+
self.float_minmax_intrinsic::<Half>(args, MinMax::MinimumNumber, dest)?
531+
}
532+
sym::minnumf32 => {
533+
self.float_minmax_intrinsic::<Single>(args, MinMax::MinimumNumber, dest)?
534+
}
535+
sym::minnumf64 => {
536+
self.float_minmax_intrinsic::<Double>(args, MinMax::MinimumNumber, dest)?
537+
}
538+
sym::minnumf128 => {
539+
self.float_minmax_intrinsic::<Quad>(args, MinMax::MinimumNumber, dest)?
540+
}
531541

532542
sym::minimumf16 => self.float_minmax_intrinsic::<Half>(args, MinMax::Minimum, dest)?,
533543
sym::minimumf32 => {
@@ -538,10 +548,18 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
538548
}
539549
sym::minimumf128 => self.float_minmax_intrinsic::<Quad>(args, MinMax::Minimum, dest)?,
540550

541-
sym::maxnumf16 => self.float_minmax_intrinsic::<Half>(args, MinMax::MaxNum, dest)?,
542-
sym::maxnumf32 => self.float_minmax_intrinsic::<Single>(args, MinMax::MaxNum, dest)?,
543-
sym::maxnumf64 => self.float_minmax_intrinsic::<Double>(args, MinMax::MaxNum, dest)?,
544-
sym::maxnumf128 => self.float_minmax_intrinsic::<Quad>(args, MinMax::MaxNum, dest)?,
551+
sym::maxnumf16 => {
552+
self.float_minmax_intrinsic::<Half>(args, MinMax::MaximumNumber, dest)?
553+
}
554+
sym::maxnumf32 => {
555+
self.float_minmax_intrinsic::<Single>(args, MinMax::MaximumNumber, dest)?
556+
}
557+
sym::maxnumf64 => {
558+
self.float_minmax_intrinsic::<Double>(args, MinMax::MaximumNumber, dest)?
559+
}
560+
sym::maxnumf128 => {
561+
self.float_minmax_intrinsic::<Quad>(args, MinMax::MaximumNumber, dest)?
562+
}
545563

546564
sym::maximumf16 => self.float_minmax_intrinsic::<Half>(args, MinMax::Maximum, dest)?,
547565
sym::maximumf32 => {
@@ -966,16 +984,16 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
966984
{
967985
let a: F = a.to_float()?;
968986
let b: F = b.to_float()?;
969-
let res = if matches!(op, MinMax::MinNum | MinMax::MaxNum) && a == b {
987+
let res = if matches!(op, MinMax::MinimumNumber | MinMax::MaximumNumber) && a == b {
970988
// They are definitely not NaN (those are never equal), but they could be `+0` and `-0`.
971989
// Let the machine decide which one to return.
972990
M::equal_float_min_max(self, a, b)
973991
} else {
974992
let result = match op {
975993
MinMax::Minimum => a.minimum(b),
976-
MinMax::MinNum => a.min(b),
994+
MinMax::MinimumNumber => a.min(b),
977995
MinMax::Maximum => a.maximum(b),
978-
MinMax::MaxNum => a.max(b),
996+
MinMax::MaximumNumber => a.max(b),
979997
};
980998
self.adjust_nan(result, &[a, b])
981999
};

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
202202
sym::simd_le => Op::MirOp(BinOp::Le),
203203
sym::simd_gt => Op::MirOp(BinOp::Gt),
204204
sym::simd_ge => Op::MirOp(BinOp::Ge),
205-
sym::simd_fmax => Op::FMinMax(MinMax::MaxNum),
206-
sym::simd_fmin => Op::FMinMax(MinMax::MinNum),
205+
sym::simd_fmax => Op::FMinMax(MinMax::MaximumNumber),
206+
sym::simd_fmin => Op::FMinMax(MinMax::MinimumNumber),
207207
sym::simd_saturating_add => Op::SaturatingOp(BinOp::Add),
208208
sym::simd_saturating_sub => Op::SaturatingOp(BinOp::Sub),
209209
sym::simd_arith_offset => Op::WrappingOffset,
@@ -295,8 +295,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
295295
sym::simd_reduce_xor => Op::MirOp(BinOp::BitXor),
296296
sym::simd_reduce_any => Op::MirOpBool(BinOp::BitOr),
297297
sym::simd_reduce_all => Op::MirOpBool(BinOp::BitAnd),
298-
sym::simd_reduce_max => Op::MinMax(MinMax::MaxNum),
299-
sym::simd_reduce_min => Op::MinMax(MinMax::MinNum),
298+
sym::simd_reduce_max => Op::MinMax(MinMax::MaximumNumber),
299+
sym::simd_reduce_min => Op::MinMax(MinMax::MinimumNumber),
300300
_ => unreachable!(),
301301
};
302302

@@ -320,8 +320,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
320320
} else {
321321
// Just boring integers, no NaNs to worry about.
322322
let mirop = match mmop {
323-
MinMax::MinNum | MinMax::Minimum => BinOp::Le,
324-
MinMax::MaxNum | MinMax::Maximum => BinOp::Ge,
323+
MinMax::MinimumNumber | MinMax::Minimum => BinOp::Le,
324+
MinMax::MaximumNumber | MinMax::Maximum => BinOp::Ge,
325325
};
326326
if self.binary_op(mirop, &res, &op)?.to_scalar().to_bool()? {
327327
res

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ fn print_crate_info(
799799
println_info!("{}", calling_conventions.join("\n"));
800800
}
801801
RelocationModels
802+
| BackendHasZstd
802803
| CodeModels
803804
| TlsModels
804805
| TargetCPUs

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#include "llvm/ADT/SmallVector.h"
77
#include "llvm/Analysis/Lint.h"
88
#include "llvm/Analysis/TargetLibraryInfo.h"
9+
#if LLVM_VERSION_GE(22, 0)
10+
#include "llvm/Analysis/RuntimeLibcallInfo.h"
11+
#endif
912
#include "llvm/Bitcode/BitcodeWriter.h"
1013
#include "llvm/Bitcode/BitcodeWriterPass.h"
1114
#include "llvm/CodeGen/CommandFlags.h"
@@ -379,13 +382,20 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
379382

380383
// Unfortunately, the LLVM C API doesn't provide a way to create the
381384
// TargetLibraryInfo pass, so we use this method to do so.
382-
extern "C" void LLVMRustAddLibraryInfo(LLVMPassManagerRef PMR, LLVMModuleRef M,
385+
extern "C" void LLVMRustAddLibraryInfo(LLVMTargetMachineRef T,
386+
LLVMPassManagerRef PMR, LLVMModuleRef M,
383387
bool DisableSimplifyLibCalls) {
384388
auto TargetTriple = Triple(unwrap(M)->getTargetTriple());
389+
TargetOptions *Options = &unwrap(T)->Options;
385390
auto TLII = TargetLibraryInfoImpl(TargetTriple);
386391
if (DisableSimplifyLibCalls)
387392
TLII.disableAllFunctions();
388393
unwrap(PMR)->add(new TargetLibraryInfoWrapperPass(TLII));
394+
#if LLVM_VERSION_GE(22, 0)
395+
unwrap(PMR)->add(new RuntimeLibraryInfoWrapper(
396+
TargetTriple, Options->ExceptionModel, Options->FloatABIType,
397+
Options->EABIVersion, Options->MCOptions.ABIName, Options->VecLib));
398+
#endif
389399
}
390400

391401
extern "C" void LLVMRustSetLLVMOptions(int Argc, char **Argv) {

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
11551155
let callsite_span = span.source_callsite();
11561156
for rib in self.ribs[ValueNS].iter().rev() {
11571157
for (binding_ident, _) in &rib.bindings {
1158+
// Case 1: the identifier is defined in the same scope as the macro is called
11581159
if binding_ident.name == ident.name
11591160
&& !binding_ident.span.eq_ctxt(span)
11601161
&& !binding_ident.span.from_expansion()
@@ -1166,6 +1167,19 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
11661167
);
11671168
return;
11681169
}
1170+
1171+
// Case 2: the identifier is defined in a macro call in the same scope
1172+
if binding_ident.name == ident.name
1173+
&& binding_ident.span.from_expansion()
1174+
&& binding_ident.span.source_callsite().eq_ctxt(callsite_span)
1175+
&& binding_ident.span.source_callsite().lo() < callsite_span.lo()
1176+
{
1177+
err.span_help(
1178+
binding_ident.span,
1179+
"an identifier with the same name is defined here, but is not accessible due to macro hygiene",
1180+
);
1181+
return;
1182+
}
11691183
}
11701184
}
11711185
}

0 commit comments

Comments
 (0)