Skip to content

Rollup of 5 pull requests #115204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 25, 2023
Merged
18 changes: 16 additions & 2 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,31 +197,45 @@ impl CodeSuggestion {

use rustc_span::{CharPos, Pos};

/// Append to a buffer the remainder of the line of existing source code, and return the
/// count of lines that have been added for accurate highlighting.
/// Extracts a substring from the provided `line_opt` based on the specified low and high indices,
/// appends it to the given buffer `buf`, and returns the count of newline characters in the substring
/// for accurate highlighting.
/// If `line_opt` is `None`, a newline character is appended to the buffer, and 0 is returned.
///
/// ## Returns
///
/// The count of newline characters in the extracted substring.
fn push_trailing(
buf: &mut String,
line_opt: Option<&Cow<'_, str>>,
lo: &Loc,
hi_opt: Option<&Loc>,
) -> usize {
let mut line_count = 0;
// Convert CharPos to Usize, as CharPose is character offset
// Extract low index and high index
let (lo, hi_opt) = (lo.col.to_usize(), hi_opt.map(|hi| hi.col.to_usize()));
if let Some(line) = line_opt {
if let Some(lo) = line.char_indices().map(|(i, _)| i).nth(lo) {
// Get high index while account for rare unicode and emoji with char_indices
let hi_opt = hi_opt.and_then(|hi| line.char_indices().map(|(i, _)| i).nth(hi));
match hi_opt {
// If high index exist, take string from low to high index
Some(hi) if hi > lo => {
// count how many '\n' exist
line_count = line[lo..hi].matches('\n').count();
buf.push_str(&line[lo..hi])
}
Some(_) => (),
// If high index absence, take string from low index till end string.len
None => {
// count how many '\n' exist
line_count = line[lo..].matches('\n').count();
buf.push_str(&line[lo..])
}
}
}
// If high index is None
if hi_opt.is_none() {
buf.push('\n');
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_span/src/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1291,11 +1291,11 @@ pub fn register_expn_id(
let expn_id = ExpnId { krate, local_id };
HygieneData::with(|hygiene_data| {
let _old_data = hygiene_data.foreign_expn_data.insert(expn_id, data);
debug_assert!(_old_data.is_none());
debug_assert!(_old_data.is_none() || cfg!(parallel_compiler));
let _old_hash = hygiene_data.foreign_expn_hashes.insert(expn_id, hash);
debug_assert!(_old_hash.is_none());
debug_assert!(_old_hash.is_none() || _old_hash == Some(hash));
let _old_id = hygiene_data.expn_hash_to_expn_id.insert(hash, expn_id);
debug_assert!(_old_id.is_none());
debug_assert!(_old_id.is_none() || _old_id == Some(expn_id));
});
expn_id
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ fn encode_ty<'tcx>(
typeid.push('b');
}

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

// Rust's f32 and f64 single (32-bit) and double (64-bit) precision floating-point types
// have IEEE-754 binary32 and binary64 floating-point layouts, respectively.
//
// (See https://rust-lang.github.io/unsafe-code-guidelines/layout/scalars.html#fixed-width-floating-point-types.)
ty::Float(float_ty) => {
typeid.push(match float_ty {
FloatTy::F32 => 'f',
FloatTy::F64 => 'd',
});
}

ty::Char => {
// u4char as vendor extended type
let mut s = String::from("u4char");
Expand Down
4 changes: 3 additions & 1 deletion library/std/src/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,9 @@ impl f32 {
unsafe { cmath::tgammaf(self) }
}

/// Returns the natural logarithm of the gamma function.
/// Natural logarithm of the absolute value of the gamma function
///
/// The integer part of the tuple indicates the sign of the gamma function.
///
/// # Examples
///
Expand Down
4 changes: 3 additions & 1 deletion library/std/src/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,9 @@ impl f64 {
unsafe { cmath::tgamma(self) }
}

/// Returns the natural logarithm of the gamma function.
/// Natural logarithm of the absolute value of the gamma function
///
/// The integer part of the tuple indicates the sign of the gamma function.
///
/// # Examples
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,12 +500,12 @@ pub fn foo149(_: Type14<Bar>, _: Type14<Bar>, _: Type14<Bar>) { }
// CHECK: ![[TYPE45]] = !{i64 0, !"_ZTSFvu5usizeE"}
// CHECK: ![[TYPE46]] = !{i64 0, !"_ZTSFvu5usizeS_E"}
// CHECK: ![[TYPE47]] = !{i64 0, !"_ZTSFvu5usizeS_S_E"}
// CHECK: ![[TYPE48]] = !{i64 0, !"_ZTSFvu3f32E"}
// CHECK: ![[TYPE49]] = !{i64 0, !"_ZTSFvu3f32S_E"}
// CHECK: ![[TYPE50]] = !{i64 0, !"_ZTSFvu3f32S_S_E"}
// CHECK: ![[TYPE51]] = !{i64 0, !"_ZTSFvu3f64E"}
// CHECK: ![[TYPE52]] = !{i64 0, !"_ZTSFvu3f64S_E"}
// CHECK: ![[TYPE53]] = !{i64 0, !"_ZTSFvu3f64S_S_E"}
// CHECK: ![[TYPE48]] = !{i64 0, !"_ZTSFvfE"}
// CHECK: ![[TYPE49]] = !{i64 0, !"_ZTSFvffE"}
// CHECK: ![[TYPE50]] = !{i64 0, !"_ZTSFvfffE"}
// CHECK: ![[TYPE51]] = !{i64 0, !"_ZTSFvdE"}
// CHECK: ![[TYPE52]] = !{i64 0, !"_ZTSFvddE"}
// CHECK: ![[TYPE53]] = !{i64 0, !"_ZTSFvdddE"}
// CHECK: ![[TYPE54]] = !{i64 0, !"_ZTSFvu4charE"}
// CHECK: ![[TYPE55]] = !{i64 0, !"_ZTSFvu4charS_E"}
// CHECK: ![[TYPE56]] = !{i64 0, !"_ZTSFvu4charS_S_E"}
Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/pre-codegen/chained_comparison.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// compile-flags: -O -Zmir-opt-level=2 -Cdebuginfo=2
// ignore-debug

#![crate_type = "lib"]

Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/pre-codegen/checked_ops.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// compile-flags: -O -Zmir-opt-level=2 -Cdebuginfo=2
// needs-unwind
// ignore-debug
// only-x86_64

#![crate_type = "lib"]
Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/pre-codegen/intrinsics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2
// only-64bit
// ignore-debug

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

Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/pre-codegen/loops.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// compile-flags: -O -Zmir-opt-level=2 -g
// needs-unwind
// ignore-debug

#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/pre-codegen/mem_replace.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2
// only-64bit
// ignore-debug
// ignore-debug the standard library debug assertions leak into this test

#![crate_type = "lib"]

Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/pre-codegen/range_iter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2
// only-64bit
// ignore-debug
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY

#![crate_type = "lib"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
fn ezmap(_1: Option<i32>) -> Option<i32> {
debug x => _1;
let mut _0: std::option::Option<i32>;
scope 1 (inlined map::<i32, i32, [closure@$DIR/simple_option_map.rs:18:12: 18:15]>) {
scope 1 (inlined map::<i32, i32, [closure@$DIR/simple_option_map.rs:17:12: 17:15]>) {
debug slf => _1;
debug f => const ZeroSized: [closure@$DIR/simple_option_map.rs:18:12: 18:15];
debug f => const ZeroSized: [closure@$DIR/simple_option_map.rs:17:12: 17:15];
let mut _2: isize;
let _3: i32;
let mut _4: i32;
Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/pre-codegen/simple_option_map.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2
// only-64bit
// ignore-debug

#[inline(always)]
fn map<T, U, F>(slf: Option<T>, f: F) -> Option<U>
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/pre-codegen/slice_index.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2
// only-64bit
// ignore-debug
// ignore-debug the standard library debug assertions leak into this test
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY

#![crate_type = "lib"]
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/pre-codegen/slice_iter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2
// only-64bit
// ignore-debug
// ignore-debug the standard library debug assertions leak into this test
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY

#![crate_type = "lib"]
Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/pre-codegen/try_identity.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2
// only-64bit
// ignore-debug

// Track the status of MIR optimizations simplifying `Ok(res?)` for both the old and new desugarings
// of that syntax.
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/consts/std/alloc.32bit.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value
--> $DIR/alloc.rs:12:1
--> $DIR/alloc.rs:11:1
|
LL | const LAYOUT_INVALID_ZERO: Layout = unsafe { Layout::from_size_align_unchecked(0x1000, 0x00) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .align.0.<enum-tag>: encountered 0x00000000, but expected a valid enum tag
Expand All @@ -10,7 +10,7 @@ LL | const LAYOUT_INVALID_ZERO: Layout = unsafe { Layout::from_size_align_unchec
}

error[E0080]: it is undefined behavior to use this value
--> $DIR/alloc.rs:16:1
--> $DIR/alloc.rs:15:1
|
LL | const LAYOUT_INVALID_THREE: Layout = unsafe { Layout::from_size_align_unchecked(9, 3) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .align.0.<enum-tag>: encountered 0x00000003, but expected a valid enum tag
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/consts/std/alloc.64bit.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0080]: it is undefined behavior to use this value
--> $DIR/alloc.rs:12:1
--> $DIR/alloc.rs:11:1
|
LL | const LAYOUT_INVALID_ZERO: Layout = unsafe { Layout::from_size_align_unchecked(0x1000, 0x00) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .align.0.<enum-tag>: encountered 0x0000000000000000, but expected a valid enum tag
Expand All @@ -10,7 +10,7 @@ LL | const LAYOUT_INVALID_ZERO: Layout = unsafe { Layout::from_size_align_unchec
}

error[E0080]: it is undefined behavior to use this value
--> $DIR/alloc.rs:16:1
--> $DIR/alloc.rs:15:1
|
LL | const LAYOUT_INVALID_THREE: Layout = unsafe { Layout::from_size_align_unchecked(9, 3) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .align.0.<enum-tag>: encountered 0x0000000000000003, but expected a valid enum tag
Expand Down
1 change: 0 additions & 1 deletion tests/ui/consts/std/alloc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// stderr-per-bitwidth
// ignore-debug (the debug assertions change the error)
// Strip out raw byte dumps to make comparison platform-independent:
// normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)"
// normalize-stderr-test "([0-9a-f][0-9a-f] |╾─*a(lloc)?[0-9]+(\+[a-z0-9]+)?─*╼ )+ *│.*" -> "HEX_DUMP"
Expand Down