Skip to content

Commit 415c9f9

Browse files
committed
Auto merge of #93499 - matthiaskrgr:rollup-icdex11, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #93395 (Improve suggestion for escaping reserved keywords) - #93403 (review the total_cmp documentation) - #93461 (Accommodate yield points in the format_args expansion) - #93462 (Document `SystemTime` platform precision) - #93471 (unix: Use metadata for `DirEntry::file_type` fallback) - #93480 (Remove deprecated and unstable slice_partition_at_index functions) - #93485 (core: Remove some redundant {}s from the sorting code) - #93494 (kmc-solid: Inherit the calling task's base priority in `Thread::new`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents bb549e5 + 4757a93 commit 415c9f9

File tree

61 files changed

+285
-232
lines changed

Some content is hidden

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

61 files changed

+285
-232
lines changed

compiler/rustc_builtin_macros/src/format.rs

+51-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use Position::*;
44
use rustc_ast as ast;
55
use rustc_ast::ptr::P;
66
use rustc_ast::tokenstream::TokenStream;
7+
use rustc_ast::visit::{self, Visitor};
78
use rustc_ast::{token, BlockCheckMode, UnsafeSource};
89
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
910
use rustc_errors::{pluralize, Applicability, DiagnosticBuilder};
@@ -788,17 +789,31 @@ impl<'a, 'b> Context<'a, 'b> {
788789
// the order provided to fmt::Arguments. When arguments are repeated, we
789790
// want the expression evaluated only once.
790791
//
791-
// Thus in the not nicely ordered case we emit the following instead:
792+
// Further, if any arg _after the first one_ contains a yield point such
793+
// as `await` or `yield`, the above short form is inconvenient for the
794+
// caller because it would keep a temporary of type ArgumentV1 alive
795+
// across the yield point. ArgumentV1 can't implement Send since it
796+
// holds a type-erased arbitrary type.
797+
//
798+
// Thus in the not nicely ordered case, and in the yielding case, we
799+
// emit the following instead:
792800
//
793801
// match (&$arg0, &$arg1, …) {
794802
// args => [ArgumentV1::new(args.$i, …), ArgumentV1::new(args.$j, …), …]
795803
// }
796804
//
797805
// for the sequence of indices $i, $j, … governed by fmt_arg_index_and_ty.
806+
// This more verbose representation ensures that all arguments are
807+
// evaluated a single time each, in the order written by the programmer,
808+
// and that the surrounding future/generator (if any) is Send whenever
809+
// possible.
810+
let no_need_for_match =
811+
nicely_ordered && !original_args.iter().skip(1).any(|e| may_contain_yield_point(e));
812+
798813
for (arg_index, arg_ty) in fmt_arg_index_and_ty {
799814
let e = &mut original_args[arg_index];
800815
let span = e.span;
801-
let arg = if nicely_ordered {
816+
let arg = if no_need_for_match {
802817
let expansion_span = e.span.with_ctxt(self.macsp.ctxt());
803818
// The indices are strictly ordered so e has not been taken yet.
804819
self.ecx.expr_addr_of(expansion_span, P(e.take()))
@@ -814,10 +829,10 @@ impl<'a, 'b> Context<'a, 'b> {
814829
let args_array = self.ecx.expr_vec(self.macsp, fmt_args);
815830
let args_slice = self.ecx.expr_addr_of(
816831
self.macsp,
817-
if nicely_ordered {
832+
if no_need_for_match {
818833
args_array
819834
} else {
820-
// In the !nicely_ordered case, none of the exprs were moved
835+
// In the !no_need_for_match case, none of the exprs were moved
821836
// away in the previous loop.
822837
//
823838
// This uses the arg span for `&arg` so that borrowck errors
@@ -1226,3 +1241,35 @@ pub fn expand_preparsed_format_args(
12261241

12271242
cx.into_expr()
12281243
}
1244+
1245+
fn may_contain_yield_point(e: &ast::Expr) -> bool {
1246+
struct MayContainYieldPoint(bool);
1247+
1248+
impl Visitor<'_> for MayContainYieldPoint {
1249+
fn visit_expr(&mut self, e: &ast::Expr) {
1250+
if let ast::ExprKind::Await(_) | ast::ExprKind::Yield(_) = e.kind {
1251+
self.0 = true;
1252+
} else {
1253+
visit::walk_expr(self, e);
1254+
}
1255+
}
1256+
1257+
fn visit_mac_call(&mut self, _: &ast::MacCall) {
1258+
self.0 = true;
1259+
}
1260+
1261+
fn visit_attribute(&mut self, _: &ast::Attribute) {
1262+
// Conservatively assume this may be a proc macro attribute in
1263+
// expression position.
1264+
self.0 = true;
1265+
}
1266+
1267+
fn visit_item(&mut self, _: &ast::Item) {
1268+
// Do not recurse into nested items.
1269+
}
1270+
}
1271+
1272+
let mut visitor = MayContainYieldPoint(false);
1273+
visitor.visit_expr(e);
1274+
visitor.0
1275+
}

compiler/rustc_parse/src/parser/diagnostics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,10 @@ impl<'a> Parser<'a> {
192192
if ident.is_raw_guess()
193193
&& self.look_ahead(1, |t| valid_follow.contains(&t.kind)) =>
194194
{
195-
err.span_suggestion(
196-
ident.span,
197-
"you can escape reserved keywords to use them as identifiers",
198-
format!("r#{}", ident.name),
195+
err.span_suggestion_verbose(
196+
ident.span.shrink_to_lo(),
197+
&format!("escape `{}` to use it as an identifier", ident.name),
198+
"r#".to_owned(),
199199
Applicability::MaybeIncorrect,
200200
);
201201
}

library/core/src/num/f32.rs

+27-19
Original file line numberDiff line numberDiff line change
@@ -1008,29 +1008,37 @@ impl f32 {
10081008
Self::from_bits(u32::from_ne_bytes(bytes))
10091009
}
10101010

1011-
/// Returns an ordering between self and other values.
1011+
/// Return the ordering between `self` and `other`.
1012+
///
10121013
/// Unlike the standard partial comparison between floating point numbers,
10131014
/// this comparison always produces an ordering in accordance to
1014-
/// the totalOrder predicate as defined in IEEE 754 (2008 revision)
1015-
/// floating point standard. The values are ordered in following order:
1016-
/// - Negative quiet NaN
1017-
/// - Negative signaling NaN
1018-
/// - Negative infinity
1019-
/// - Negative numbers
1020-
/// - Negative subnormal numbers
1021-
/// - Negative zero
1022-
/// - Positive zero
1023-
/// - Positive subnormal numbers
1024-
/// - Positive numbers
1025-
/// - Positive infinity
1026-
/// - Positive signaling NaN
1027-
/// - Positive quiet NaN
1028-
///
1029-
/// Note that this function does not always agree with the [`PartialOrd`]
1030-
/// and [`PartialEq`] implementations of `f32`. In particular, they regard
1031-
/// negative and positive zero as equal, while `total_cmp` doesn't.
1015+
/// the `totalOrder` predicate as defined in the IEEE 754 (2008 revision)
1016+
/// floating point standard. The values are ordered in the following sequence:
1017+
///
1018+
/// - negative quiet NaN
1019+
/// - negative signaling NaN
1020+
/// - negative infinity
1021+
/// - negative numbers
1022+
/// - negative subnormal numbers
1023+
/// - negative zero
1024+
/// - positive zero
1025+
/// - positive subnormal numbers
1026+
/// - positive numbers
1027+
/// - positive infinity
1028+
/// - positive signaling NaN
1029+
/// - positive quiet NaN.
1030+
///
1031+
/// The ordering established by this function does not always agree with the
1032+
/// [`PartialOrd`] and [`PartialEq`] implementations of `f32`. For example,
1033+
/// they consider negative and positive zero equal, while `total_cmp`
1034+
/// doesn't.
1035+
///
1036+
/// The interpretation of the signaling NaN bit follows the definition in
1037+
/// the IEEE 754 standard, which may not match the interpretation by some of
1038+
/// the older, non-conformant (e.g. MIPS) hardware implementations.
10321039
///
10331040
/// # Example
1041+
///
10341042
/// ```
10351043
/// #![feature(total_cmp)]
10361044
/// struct GoodBoy {

library/core/src/num/f64.rs

+27-19
Original file line numberDiff line numberDiff line change
@@ -1024,29 +1024,37 @@ impl f64 {
10241024
Self::from_bits(u64::from_ne_bytes(bytes))
10251025
}
10261026

1027-
/// Returns an ordering between self and other values.
1027+
/// Return the ordering between `self` and `other`.
1028+
///
10281029
/// Unlike the standard partial comparison between floating point numbers,
10291030
/// this comparison always produces an ordering in accordance to
1030-
/// the totalOrder predicate as defined in IEEE 754 (2008 revision)
1031-
/// floating point standard. The values are ordered in following order:
1032-
/// - Negative quiet NaN
1033-
/// - Negative signaling NaN
1034-
/// - Negative infinity
1035-
/// - Negative numbers
1036-
/// - Negative subnormal numbers
1037-
/// - Negative zero
1038-
/// - Positive zero
1039-
/// - Positive subnormal numbers
1040-
/// - Positive numbers
1041-
/// - Positive infinity
1042-
/// - Positive signaling NaN
1043-
/// - Positive quiet NaN
1044-
///
1045-
/// Note that this function does not always agree with the [`PartialOrd`]
1046-
/// and [`PartialEq`] implementations of `f64`. In particular, they regard
1047-
/// negative and positive zero as equal, while `total_cmp` doesn't.
1031+
/// the `totalOrder` predicate as defined in the IEEE 754 (2008 revision)
1032+
/// floating point standard. The values are ordered in the following sequence:
1033+
///
1034+
/// - negative quiet NaN
1035+
/// - negative signaling NaN
1036+
/// - negative infinity
1037+
/// - negative numbers
1038+
/// - negative subnormal numbers
1039+
/// - negative zero
1040+
/// - positive zero
1041+
/// - positive subnormal numbers
1042+
/// - positive numbers
1043+
/// - positive infinity
1044+
/// - positive signaling NaN
1045+
/// - positive quiet NaN.
1046+
///
1047+
/// The ordering established by this function does not always agree with the
1048+
/// [`PartialOrd`] and [`PartialEq`] implementations of `f64`. For example,
1049+
/// they consider negative and positive zero equal, while `total_cmp`
1050+
/// doesn't.
1051+
///
1052+
/// The interpretation of the signaling NaN bit follows the definition in
1053+
/// the IEEE 754 standard, which may not match the interpretation by some of
1054+
/// the older, non-conformant (e.g. MIPS) hardware implementations.
10481055
///
10491056
/// # Example
1057+
///
10501058
/// ```
10511059
/// #![feature(total_cmp)]
10521060
/// struct GoodBoy {

library/core/src/slice/mod.rs

-44
Original file line numberDiff line numberDiff line change
@@ -2558,50 +2558,6 @@ impl<T> [T] {
25582558
sort::quicksort(self, |a, b| f(a).lt(&f(b)));
25592559
}
25602560

2561-
/// Reorder the slice such that the element at `index` is at its final sorted position.
2562-
#[unstable(feature = "slice_partition_at_index", issue = "55300")]
2563-
#[rustc_deprecated(since = "1.49.0", reason = "use the select_nth_unstable() instead")]
2564-
#[inline]
2565-
pub fn partition_at_index(&mut self, index: usize) -> (&mut [T], &mut T, &mut [T])
2566-
where
2567-
T: Ord,
2568-
{
2569-
self.select_nth_unstable(index)
2570-
}
2571-
2572-
/// Reorder the slice with a comparator function such that the element at `index` is at its
2573-
/// final sorted position.
2574-
#[unstable(feature = "slice_partition_at_index", issue = "55300")]
2575-
#[rustc_deprecated(since = "1.49.0", reason = "use select_nth_unstable_by() instead")]
2576-
#[inline]
2577-
pub fn partition_at_index_by<F>(
2578-
&mut self,
2579-
index: usize,
2580-
compare: F,
2581-
) -> (&mut [T], &mut T, &mut [T])
2582-
where
2583-
F: FnMut(&T, &T) -> Ordering,
2584-
{
2585-
self.select_nth_unstable_by(index, compare)
2586-
}
2587-
2588-
/// Reorder the slice with a key extraction function such that the element at `index` is at its
2589-
/// final sorted position.
2590-
#[unstable(feature = "slice_partition_at_index", issue = "55300")]
2591-
#[rustc_deprecated(since = "1.49.0", reason = "use the select_nth_unstable_by_key() instead")]
2592-
#[inline]
2593-
pub fn partition_at_index_by_key<K, F>(
2594-
&mut self,
2595-
index: usize,
2596-
f: F,
2597-
) -> (&mut [T], &mut T, &mut [T])
2598-
where
2599-
F: FnMut(&T) -> K,
2600-
K: Ord,
2601-
{
2602-
self.select_nth_unstable_by_key(index, f)
2603-
}
2604-
26052561
/// Reorder the slice such that the element at `index` is at its final sorted position.
26062562
///
26072563
/// This reordering has the additional property that any value at position `i < index` will be

library/core/src/slice/sort.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ where
773773
let mid = partition_equal(v, pivot, is_less);
774774

775775
// Continue sorting elements greater than the pivot.
776-
v = &mut { v }[mid..];
776+
v = &mut v[mid..];
777777
continue;
778778
}
779779
}
@@ -784,7 +784,7 @@ where
784784
was_partitioned = was_p;
785785

786786
// Split the slice into `left`, `pivot`, and `right`.
787-
let (left, right) = { v }.split_at_mut(mid);
787+
let (left, right) = v.split_at_mut(mid);
788788
let (pivot, right) = right.split_at_mut(1);
789789
let pivot = &pivot[0];
790790

@@ -860,7 +860,7 @@ fn partition_at_index_loop<'a, T, F>(
860860
let (mid, _) = partition(v, pivot, is_less);
861861

862862
// Split the slice into `left`, `pivot`, and `right`.
863-
let (left, right) = { v }.split_at_mut(mid);
863+
let (left, right) = v.split_at_mut(mid);
864864
let (pivot, right) = right.split_at_mut(1);
865865
let pivot = &pivot[0];
866866

library/core/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
#![feature(is_sorted)]
4747
#![feature(pattern)]
4848
#![feature(sort_internals)]
49-
#![feature(slice_partition_at_index)]
5049
#![feature(slice_take)]
5150
#![feature(maybe_uninit_uninit_array)]
5251
#![feature(maybe_uninit_array_assume_init)]

library/std/src/sys/itron/thread.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ impl Thread {
8484
///
8585
/// See `thread::Builder::spawn_unchecked` for safety requirements.
8686
pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
87-
// Inherit the current task's priority
88-
let current_task = task::try_current_task_id().map_err(|e| e.as_io_error())?;
89-
let priority = task::try_task_priority(current_task).map_err(|e| e.as_io_error())?;
90-
9187
let inner = Box::new(ThreadInner {
9288
start: UnsafeCell::new(ManuallyDrop::new(p)),
9389
lifecycle: AtomicUsize::new(LIFECYCLE_INIT),
@@ -175,7 +171,8 @@ impl Thread {
175171
exinf: inner_ptr as abi::EXINF,
176172
// The entry point
177173
task: Some(trampoline),
178-
itskpri: priority,
174+
// Inherit the calling task's base priority
175+
itskpri: abi::TPRI_SELF,
179176
stksz: stack,
180177
// Let the kernel allocate the stack,
181178
stk: crate::ptr::null_mut(),

library/std/src/sys/unix/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ impl DirEntry {
598598
target_os = "vxworks"
599599
))]
600600
pub fn file_type(&self) -> io::Result<FileType> {
601-
lstat(&self.path()).map(|m| m.file_type())
601+
self.metadata().map(|m| m.file_type())
602602
}
603603

604604
#[cfg(not(any(
@@ -616,7 +616,7 @@ impl DirEntry {
616616
libc::DT_SOCK => Ok(FileType { mode: libc::S_IFSOCK }),
617617
libc::DT_DIR => Ok(FileType { mode: libc::S_IFDIR }),
618618
libc::DT_BLK => Ok(FileType { mode: libc::S_IFBLK }),
619-
_ => lstat(&self.path()).map(|m| m.file_type()),
619+
_ => self.metadata().map(|m| m.file_type()),
620620
}
621621
}
622622

library/std/src/time.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,12 @@ pub struct Instant(time::Instant);
176176
/// }
177177
/// ```
178178
///
179-
/// # Underlying System calls
179+
/// # Platform-specific behavior
180+
///
181+
/// The precision of `SystemTime` can depend on the underlying OS-specific time format.
182+
/// For example, on Windows the time is represented in 100 nanosecond intervals whereas Linux
183+
/// can represent nanosecond intervals.
184+
///
180185
/// Currently, the following system calls are being used to get the current time using `now()`:
181186
///
182187
/// | Platform | System call |

0 commit comments

Comments
 (0)