Skip to content

Commit 03a7b9f

Browse files
authored
Merge pull request #4420 from rust-lang/rustup-2025-06-29
Automatic Rustup
2 parents 40ec147 + 7b985d5 commit 03a7b9f

File tree

67 files changed

+1357
-267
lines changed

Some content is hidden

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

67 files changed

+1357
-267
lines changed

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,18 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
407407
source_info.span,
408408
)
409409
}
410+
AssertKind::InvalidEnumConstruction(source) => {
411+
let source = codegen_operand(fx, source).load_scalar(fx);
412+
let location = fx.get_caller_location(source_info).load_scalar(fx);
413+
414+
codegen_panic_inner(
415+
fx,
416+
rustc_hir::LangItem::PanicInvalidEnumConstruction,
417+
&[source, location],
418+
*unwind,
419+
source_info.span,
420+
)
421+
}
410422
_ => {
411423
let location = fx.get_caller_location(source_info).load_scalar(fx);
412424

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
776776
// `#[track_caller]` adds an implicit argument.
777777
(LangItem::PanicNullPointerDereference, vec![location])
778778
}
779+
AssertKind::InvalidEnumConstruction(source) => {
780+
let source = self.codegen_operand(bx, source).immediate();
781+
// It's `fn panic_invalid_enum_construction(source: u128)`,
782+
// `#[track_caller]` adds an implicit argument.
783+
(LangItem::PanicInvalidEnumConstruction, vec![source, location])
784+
}
779785
_ => {
780786
// It's `pub fn panic_...()` and `#[track_caller]` adds an implicit argument.
781787
(msg.panic_function(), vec![location])

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
508508
found: eval_to_int(found)?,
509509
},
510510
NullPointerDereference => NullPointerDereference,
511+
InvalidEnumConstruction(source) => InvalidEnumConstruction(eval_to_int(source)?),
511512
};
512513
Err(ConstEvalErrKind::AssertFailure(err)).into()
513514
}

compiler/rustc_const_eval/src/util/caller_location.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ fn alloc_caller_location<'tcx>(
2121
assert!(!filename.as_str().as_bytes().contains(&0));
2222

2323
let loc_details = ecx.tcx.sess.opts.unstable_opts.location_detail;
24-
let file_wide_ptr = {
24+
let filename = {
2525
let filename = if loc_details.file { filename.as_str() } else { "<redacted>" };
2626
let filename_with_nul = filename.to_owned() + "\0";
2727
// This can fail if rustc runs out of memory right here. Trying to emit an error would be
2828
// pointless, since that would require allocating more memory than these short strings.
2929
let file_ptr = ecx.allocate_bytes_dedup(filename_with_nul.as_bytes()).unwrap();
30-
Immediate::new_slice(file_ptr.into(), filename_with_nul.len().try_into().unwrap(), ecx)
30+
let file_len = u64::try_from(filename.len()).unwrap();
31+
Immediate::new_slice(file_ptr.into(), file_len, ecx)
3132
};
3233
let line = if loc_details.line { Scalar::from_u32(line) } else { Scalar::from_u32(0) };
3334
let col = if loc_details.column { Scalar::from_u32(col) } else { Scalar::from_u32(0) };
@@ -41,11 +42,8 @@ fn alloc_caller_location<'tcx>(
4142
let location = ecx.allocate(loc_layout, MemoryKind::CallerLocation).unwrap();
4243

4344
// Initialize fields.
44-
ecx.write_immediate(
45-
file_wide_ptr,
46-
&ecx.project_field(&location, FieldIdx::from_u32(0)).unwrap(),
47-
)
48-
.expect("writing to memory we just allocated cannot fail");
45+
ecx.write_immediate(filename, &ecx.project_field(&location, FieldIdx::from_u32(0)).unwrap())
46+
.expect("writing to memory we just allocated cannot fail");
4947
ecx.write_scalar(line, &ecx.project_field(&location, FieldIdx::from_u32(1)).unwrap())
5048
.expect("writing to memory we just allocated cannot fail");
5149
ecx.write_scalar(col, &ecx.project_field(&location, FieldIdx::from_u32(2)).unwrap())

compiler/rustc_hir/src/lang_items.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ language_item_table! {
312312
PanicAsyncGenFnResumedPanic, sym::panic_const_async_gen_fn_resumed_panic, panic_const_async_gen_fn_resumed_panic, Target::Fn, GenericRequirement::None;
313313
PanicGenFnNonePanic, sym::panic_const_gen_fn_none_panic, panic_const_gen_fn_none_panic, Target::Fn, GenericRequirement::None;
314314
PanicNullPointerDereference, sym::panic_null_pointer_dereference, panic_null_pointer_dereference, Target::Fn, GenericRequirement::None;
315+
PanicInvalidEnumConstruction, sym::panic_invalid_enum_construction, panic_invalid_enum_construction, Target::Fn, GenericRequirement::None;
315316
PanicCoroutineResumedDrop, sym::panic_const_coroutine_resumed_drop, panic_const_coroutine_resumed_drop, Target::Fn, GenericRequirement::None;
316317
PanicAsyncFnResumedDrop, sym::panic_const_async_fn_resumed_drop, panic_const_async_fn_resumed_drop, Target::Fn, GenericRequirement::None;
317318
PanicAsyncGenFnResumedDrop, sym::panic_const_async_gen_fn_resumed_drop, panic_const_async_gen_fn_resumed_drop, Target::Fn, GenericRequirement::None;

compiler/rustc_macros/src/symbols.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,6 @@ fn symbols_with_errors(input: TokenStream) -> (TokenStream, Vec<syn::Error>) {
190190
let mut symbols_stream = quote! {};
191191
let mut prefill_stream = quote! {};
192192
let mut entries = Entries::with_capacity(input.keywords.len() + input.symbols.len() + 10);
193-
let mut prev_key: Option<(Span, String)> = None;
194-
195-
let mut check_order = |span: Span, s: &str, errors: &mut Errors| {
196-
if let Some((prev_span, ref prev_str)) = prev_key {
197-
if s < prev_str {
198-
errors.error(span, format!("Symbol `{s}` must precede `{prev_str}`"));
199-
errors.error(prev_span, format!("location of previous symbol `{prev_str}`"));
200-
}
201-
}
202-
prev_key = Some((span, s.to_string()));
203-
};
204193

205194
// Generate the listed keywords.
206195
for keyword in input.keywords.iter() {
@@ -219,7 +208,6 @@ fn symbols_with_errors(input: TokenStream) -> (TokenStream, Vec<syn::Error>) {
219208
// Generate the listed symbols.
220209
for symbol in input.symbols.iter() {
221210
let name = &symbol.name;
222-
check_order(symbol.name.span(), &name.to_string(), &mut errors);
223211

224212
let value = match &symbol.value {
225213
Value::SameAsName => name.to_string(),

compiler/rustc_macros/src/symbols/tests.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,3 @@ fn check_dup_symbol_and_keyword() {
8484
};
8585
test_symbols_macro(input, &["Symbol `splat` is duplicated", "location of previous definition"]);
8686
}
87-
88-
#[test]
89-
fn check_symbol_order() {
90-
let input = quote! {
91-
Keywords {}
92-
Symbols {
93-
zebra,
94-
aardvark,
95-
}
96-
};
97-
test_symbols_macro(
98-
input,
99-
&["Symbol `aardvark` must precede `zebra`", "location of previous symbol `zebra`"],
100-
);
101-
}

compiler/rustc_middle/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ middle_assert_gen_resume_after_drop = `gen` fn or block cannot be further iterat
1717
1818
middle_assert_gen_resume_after_panic = `gen` fn or block cannot be further iterated on after it panicked
1919
20+
middle_assert_invalid_enum_construction =
21+
trying to construct an enum from an invalid value `{$source}`
22+
2023
middle_assert_misaligned_ptr_deref =
2124
misaligned pointer dereference: address must be a multiple of {$required} but is {$found}
2225

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,7 @@ pub enum AssertKind<O> {
10751075
ResumedAfterDrop(CoroutineKind),
10761076
MisalignedPointerDereference { required: O, found: O },
10771077
NullPointerDereference,
1078+
InvalidEnumConstruction(O),
10781079
}
10791080

10801081
#[derive(Clone, Debug, PartialEq, TyEncodable, TyDecodable, Hash, HashStable)]

compiler/rustc_middle/src/mir/terminator.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ impl<O> AssertKind<O> {
208208
LangItem::PanicGenFnNonePanic
209209
}
210210
NullPointerDereference => LangItem::PanicNullPointerDereference,
211+
InvalidEnumConstruction(_) => LangItem::PanicInvalidEnumConstruction,
211212
ResumedAfterDrop(CoroutineKind::Coroutine(_)) => LangItem::PanicCoroutineResumedDrop,
212213
ResumedAfterDrop(CoroutineKind::Desugared(CoroutineDesugaring::Async, _)) => {
213214
LangItem::PanicAsyncFnResumedDrop
@@ -284,6 +285,9 @@ impl<O> AssertKind<O> {
284285
)
285286
}
286287
NullPointerDereference => write!(f, "\"null pointer dereference occurred\""),
288+
InvalidEnumConstruction(source) => {
289+
write!(f, "\"trying to construct an enum from an invalid value {{}}\", {source:?}")
290+
}
287291
ResumedAfterReturn(CoroutineKind::Coroutine(_)) => {
288292
write!(f, "\"coroutine resumed after completion\"")
289293
}
@@ -367,6 +371,7 @@ impl<O> AssertKind<O> {
367371
middle_assert_coroutine_resume_after_panic
368372
}
369373
NullPointerDereference => middle_assert_null_ptr_deref,
374+
InvalidEnumConstruction(_) => middle_assert_invalid_enum_construction,
370375
ResumedAfterDrop(CoroutineKind::Desugared(CoroutineDesugaring::Async, _)) => {
371376
middle_assert_async_resume_after_drop
372377
}
@@ -420,6 +425,9 @@ impl<O> AssertKind<O> {
420425
add!("required", format!("{required:#?}"));
421426
add!("found", format!("{found:#?}"));
422427
}
428+
InvalidEnumConstruction(source) => {
429+
add!("source", format!("{source:#?}"));
430+
}
423431
}
424432
}
425433
}

0 commit comments

Comments
 (0)