Skip to content

Commit 4535d33

Browse files
committed
Auto merge of #115204 - matthiaskrgr:rollup-avsp3t3, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #114754 (Name what ln_gamma does) - #115081 (Allow overwriting ExpnId for concurrent decoding) - #115151 (Fix CFI: f32 and f64 are encoded incorrectly for cross-language CFI) - #115169 (remove some unnecessary ignore-debug clauses) - #115190 (Add comment to the push_trailing function) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c9228ae + 021e882 commit 4535d33

20 files changed

+53
-34
lines changed

Diff for: compiler/rustc_errors/src/lib.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -197,31 +197,45 @@ impl CodeSuggestion {
197197

198198
use rustc_span::{CharPos, Pos};
199199

200-
/// Append to a buffer the remainder of the line of existing source code, and return the
201-
/// count of lines that have been added for accurate highlighting.
200+
/// Extracts a substring from the provided `line_opt` based on the specified low and high indices,
201+
/// appends it to the given buffer `buf`, and returns the count of newline characters in the substring
202+
/// for accurate highlighting.
203+
/// If `line_opt` is `None`, a newline character is appended to the buffer, and 0 is returned.
204+
///
205+
/// ## Returns
206+
///
207+
/// The count of newline characters in the extracted substring.
202208
fn push_trailing(
203209
buf: &mut String,
204210
line_opt: Option<&Cow<'_, str>>,
205211
lo: &Loc,
206212
hi_opt: Option<&Loc>,
207213
) -> usize {
208214
let mut line_count = 0;
215+
// Convert CharPos to Usize, as CharPose is character offset
216+
// Extract low index and high index
209217
let (lo, hi_opt) = (lo.col.to_usize(), hi_opt.map(|hi| hi.col.to_usize()));
210218
if let Some(line) = line_opt {
211219
if let Some(lo) = line.char_indices().map(|(i, _)| i).nth(lo) {
220+
// Get high index while account for rare unicode and emoji with char_indices
212221
let hi_opt = hi_opt.and_then(|hi| line.char_indices().map(|(i, _)| i).nth(hi));
213222
match hi_opt {
223+
// If high index exist, take string from low to high index
214224
Some(hi) if hi > lo => {
225+
// count how many '\n' exist
215226
line_count = line[lo..hi].matches('\n').count();
216227
buf.push_str(&line[lo..hi])
217228
}
218229
Some(_) => (),
230+
// If high index absence, take string from low index till end string.len
219231
None => {
232+
// count how many '\n' exist
220233
line_count = line[lo..].matches('\n').count();
221234
buf.push_str(&line[lo..])
222235
}
223236
}
224237
}
238+
// If high index is None
225239
if hi_opt.is_none() {
226240
buf.push('\n');
227241
}

Diff for: compiler/rustc_span/src/hygiene.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1291,11 +1291,11 @@ pub fn register_expn_id(
12911291
let expn_id = ExpnId { krate, local_id };
12921292
HygieneData::with(|hygiene_data| {
12931293
let _old_data = hygiene_data.foreign_expn_data.insert(expn_id, data);
1294-
debug_assert!(_old_data.is_none());
1294+
debug_assert!(_old_data.is_none() || cfg!(parallel_compiler));
12951295
let _old_hash = hygiene_data.foreign_expn_hashes.insert(expn_id, hash);
1296-
debug_assert!(_old_hash.is_none());
1296+
debug_assert!(_old_hash.is_none() || _old_hash == Some(hash));
12971297
let _old_id = hygiene_data.expn_hash_to_expn_id.insert(hash, expn_id);
1298-
debug_assert!(_old_id.is_none());
1298+
debug_assert!(_old_id.is_none() || _old_id == Some(expn_id));
12991299
});
13001300
expn_id
13011301
}

Diff for: compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ fn encode_ty<'tcx>(
447447
typeid.push('b');
448448
}
449449

450-
ty::Int(..) | ty::Uint(..) | ty::Float(..) => {
450+
ty::Int(..) | ty::Uint(..) => {
451451
// u<length><type-name> as vendor extended type
452452
let mut s = String::from(match ty.kind() {
453453
ty::Int(IntTy::I8) => "u2i8",
@@ -462,14 +462,23 @@ fn encode_ty<'tcx>(
462462
ty::Uint(UintTy::U64) => "u3u64",
463463
ty::Uint(UintTy::U128) => "u4u128",
464464
ty::Uint(UintTy::Usize) => "u5usize",
465-
ty::Float(FloatTy::F32) => "u3f32",
466-
ty::Float(FloatTy::F64) => "u3f64",
467-
_ => "",
465+
_ => bug!("encode_ty: unexpected `{:?}`", ty.kind()),
468466
});
469467
compress(dict, DictKey::Ty(ty, TyQ::None), &mut s);
470468
typeid.push_str(&s);
471469
}
472470

471+
// Rust's f32 and f64 single (32-bit) and double (64-bit) precision floating-point types
472+
// have IEEE-754 binary32 and binary64 floating-point layouts, respectively.
473+
//
474+
// (See https://rust-lang.github.io/unsafe-code-guidelines/layout/scalars.html#fixed-width-floating-point-types.)
475+
ty::Float(float_ty) => {
476+
typeid.push(match float_ty {
477+
FloatTy::F32 => 'f',
478+
FloatTy::F64 => 'd',
479+
});
480+
}
481+
473482
ty::Char => {
474483
// u4char as vendor extended type
475484
let mut s = String::from("u4char");

Diff for: library/std/src/f32.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,9 @@ impl f32 {
989989
unsafe { cmath::tgammaf(self) }
990990
}
991991

992-
/// Returns the natural logarithm of the gamma function.
992+
/// Natural logarithm of the absolute value of the gamma function
993+
///
994+
/// The integer part of the tuple indicates the sign of the gamma function.
993995
///
994996
/// # Examples
995997
///

Diff for: library/std/src/f64.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,9 @@ impl f64 {
989989
unsafe { cmath::tgamma(self) }
990990
}
991991

992-
/// Returns the natural logarithm of the gamma function.
992+
/// Natural logarithm of the absolute value of the gamma function
993+
///
994+
/// The integer part of the tuple indicates the sign of the gamma function.
993995
///
994996
/// # Examples
995997
///

Diff for: tests/codegen/sanitizer/cfi-emit-type-metadata-id-itanium-cxx-abi.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,12 @@ pub fn foo149(_: Type14<Bar>, _: Type14<Bar>, _: Type14<Bar>) { }
500500
// CHECK: ![[TYPE45]] = !{i64 0, !"_ZTSFvu5usizeE"}
501501
// CHECK: ![[TYPE46]] = !{i64 0, !"_ZTSFvu5usizeS_E"}
502502
// CHECK: ![[TYPE47]] = !{i64 0, !"_ZTSFvu5usizeS_S_E"}
503-
// CHECK: ![[TYPE48]] = !{i64 0, !"_ZTSFvu3f32E"}
504-
// CHECK: ![[TYPE49]] = !{i64 0, !"_ZTSFvu3f32S_E"}
505-
// CHECK: ![[TYPE50]] = !{i64 0, !"_ZTSFvu3f32S_S_E"}
506-
// CHECK: ![[TYPE51]] = !{i64 0, !"_ZTSFvu3f64E"}
507-
// CHECK: ![[TYPE52]] = !{i64 0, !"_ZTSFvu3f64S_E"}
508-
// CHECK: ![[TYPE53]] = !{i64 0, !"_ZTSFvu3f64S_S_E"}
503+
// CHECK: ![[TYPE48]] = !{i64 0, !"_ZTSFvfE"}
504+
// CHECK: ![[TYPE49]] = !{i64 0, !"_ZTSFvffE"}
505+
// CHECK: ![[TYPE50]] = !{i64 0, !"_ZTSFvfffE"}
506+
// CHECK: ![[TYPE51]] = !{i64 0, !"_ZTSFvdE"}
507+
// CHECK: ![[TYPE52]] = !{i64 0, !"_ZTSFvddE"}
508+
// CHECK: ![[TYPE53]] = !{i64 0, !"_ZTSFvdddE"}
509509
// CHECK: ![[TYPE54]] = !{i64 0, !"_ZTSFvu4charE"}
510510
// CHECK: ![[TYPE55]] = !{i64 0, !"_ZTSFvu4charS_E"}
511511
// CHECK: ![[TYPE56]] = !{i64 0, !"_ZTSFvu4charS_S_E"}

Diff for: tests/mir-opt/pre-codegen/chained_comparison.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// compile-flags: -O -Zmir-opt-level=2 -Cdebuginfo=2
2-
// ignore-debug
32

43
#![crate_type = "lib"]
54

Diff for: tests/mir-opt/pre-codegen/checked_ops.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// compile-flags: -O -Zmir-opt-level=2 -Cdebuginfo=2
22
// needs-unwind
3-
// ignore-debug
43
// only-x86_64
54

65
#![crate_type = "lib"]

Diff for: tests/mir-opt/pre-codegen/intrinsics.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2
22
// only-64bit
3-
// ignore-debug
43

54
// Checks that we do not have any branches in the MIR for the two tested functions.
65

Diff for: tests/mir-opt/pre-codegen/loops.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// compile-flags: -O -Zmir-opt-level=2 -g
22
// needs-unwind
3-
// ignore-debug
43

54
#![crate_type = "lib"]
65

Diff for: tests/mir-opt/pre-codegen/mem_replace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2
22
// only-64bit
3-
// ignore-debug
3+
// ignore-debug the standard library debug assertions leak into this test
44

55
#![crate_type = "lib"]
66

Diff for: tests/mir-opt/pre-codegen/range_iter.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2
22
// only-64bit
3-
// ignore-debug
43
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
54

65
#![crate_type = "lib"]

Diff for: tests/mir-opt/pre-codegen/simple_option_map.ezmap.PreCodegen.after.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
fn ezmap(_1: Option<i32>) -> Option<i32> {
44
debug x => _1;
55
let mut _0: std::option::Option<i32>;
6-
scope 1 (inlined map::<i32, i32, [closure@$DIR/simple_option_map.rs:18:12: 18:15]>) {
6+
scope 1 (inlined map::<i32, i32, [closure@$DIR/simple_option_map.rs:17:12: 17:15]>) {
77
debug slf => _1;
8-
debug f => const ZeroSized: [closure@$DIR/simple_option_map.rs:18:12: 18:15];
8+
debug f => const ZeroSized: [closure@$DIR/simple_option_map.rs:17:12: 17:15];
99
let mut _2: isize;
1010
let _3: i32;
1111
let mut _4: i32;

Diff for: tests/mir-opt/pre-codegen/simple_option_map.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2
22
// only-64bit
3-
// ignore-debug
43

54
#[inline(always)]
65
fn map<T, U, F>(slf: Option<T>, f: F) -> Option<U>

Diff for: tests/mir-opt/pre-codegen/slice_index.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2
22
// only-64bit
3-
// ignore-debug
3+
// ignore-debug the standard library debug assertions leak into this test
44
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
55

66
#![crate_type = "lib"]

Diff for: tests/mir-opt/pre-codegen/slice_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2
22
// only-64bit
3-
// ignore-debug
3+
// ignore-debug the standard library debug assertions leak into this test
44
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
55

66
#![crate_type = "lib"]

Diff for: tests/mir-opt/pre-codegen/try_identity.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2
22
// only-64bit
3-
// ignore-debug
43

54
// Track the status of MIR optimizations simplifying `Ok(res?)` for both the old and new desugarings
65
// of that syntax.

Diff for: tests/ui/consts/std/alloc.32bit.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0080]: it is undefined behavior to use this value
2-
--> $DIR/alloc.rs:12:1
2+
--> $DIR/alloc.rs:11:1
33
|
44
LL | const LAYOUT_INVALID_ZERO: Layout = unsafe { Layout::from_size_align_unchecked(0x1000, 0x00) };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .align.0.<enum-tag>: encountered 0x00000000, but expected a valid enum tag
@@ -10,7 +10,7 @@ LL | const LAYOUT_INVALID_ZERO: Layout = unsafe { Layout::from_size_align_unchec
1010
}
1111

1212
error[E0080]: it is undefined behavior to use this value
13-
--> $DIR/alloc.rs:16:1
13+
--> $DIR/alloc.rs:15:1
1414
|
1515
LL | const LAYOUT_INVALID_THREE: Layout = unsafe { Layout::from_size_align_unchecked(9, 3) };
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .align.0.<enum-tag>: encountered 0x00000003, but expected a valid enum tag

Diff for: tests/ui/consts/std/alloc.64bit.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0080]: it is undefined behavior to use this value
2-
--> $DIR/alloc.rs:12:1
2+
--> $DIR/alloc.rs:11:1
33
|
44
LL | const LAYOUT_INVALID_ZERO: Layout = unsafe { Layout::from_size_align_unchecked(0x1000, 0x00) };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .align.0.<enum-tag>: encountered 0x0000000000000000, but expected a valid enum tag
@@ -10,7 +10,7 @@ LL | const LAYOUT_INVALID_ZERO: Layout = unsafe { Layout::from_size_align_unchec
1010
}
1111

1212
error[E0080]: it is undefined behavior to use this value
13-
--> $DIR/alloc.rs:16:1
13+
--> $DIR/alloc.rs:15:1
1414
|
1515
LL | const LAYOUT_INVALID_THREE: Layout = unsafe { Layout::from_size_align_unchecked(9, 3) };
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .align.0.<enum-tag>: encountered 0x0000000000000003, but expected a valid enum tag

Diff for: tests/ui/consts/std/alloc.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// stderr-per-bitwidth
2-
// ignore-debug (the debug assertions change the error)
32
// Strip out raw byte dumps to make comparison platform-independent:
43
// normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)"
54
// normalize-stderr-test "([0-9a-f][0-9a-f] |╾─*a(lloc)?[0-9]+(\+[a-z0-9]+)?─*╼ )+ *│.*" -> "HEX_DUMP"

0 commit comments

Comments
 (0)