Skip to content

Rollup of 8 pull requests #93499

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 18 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
c8198a6
Improve suggestion for escaping reserved keywords
camelid Jan 27, 2022
0189a21
Document `SystemTime` platform precision
ChrisDenton Jan 29, 2022
d70b9c0
unix: Use metadata for `DirEntry::file_type` fallback
cuviper Jan 30, 2022
105a746
Remove deprecated and unstable slice_partition_at_index functions
est31 Jan 30, 2022
cde240c
core: Remove some redundant {}s from the sorting code
est31 Jan 30, 2022
1dd02e3
Add regression test for issue 93274
dtolnay Jan 29, 2022
47f92a5
Accommodate yield points in the format_args expansion
dtolnay Jan 29, 2022
858d6a0
Mac calls
dtolnay Jan 30, 2022
78efb07
review the total_cmp documentation
nagisa Jan 28, 2022
09233ce
kmc-solid: Inherit the calling task's base priority in `Thread::new`
kawadakk Jan 28, 2022
2f4602a
Rollup merge of #93395 - camelid:reserved-sugg, r=davidtwco
matthiaskrgr Jan 31, 2022
8fd2ff5
Rollup merge of #93403 - nagisa:total-cmp-review, r=joshtriplett
matthiaskrgr Jan 31, 2022
c1e2948
Rollup merge of #93461 - dtolnay:fmtyield, r=davidtwco
matthiaskrgr Jan 31, 2022
bc2c4fe
Rollup merge of #93462 - ChrisDenton:systime-doc, r=joshtriplett
matthiaskrgr Jan 31, 2022
cd27f1b
Rollup merge of #93471 - cuviper:direntry-file_type-stat, r=the8472
matthiaskrgr Jan 31, 2022
b0cdf7e
Rollup merge of #93480 - est31:remove_unstable_deprecated, r=Mark-Sim…
matthiaskrgr Jan 31, 2022
24737bd
Rollup merge of #93485 - est31:remove_curly, r=joshtriplett
matthiaskrgr Jan 31, 2022
4757a93
Rollup merge of #93494 - solid-rs:fix-kmc-solid-spawned-task-priority…
matthiaskrgr Jan 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 51 additions & 4 deletions compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use Position::*;
use rustc_ast as ast;
use rustc_ast::ptr::P;
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::visit::{self, Visitor};
use rustc_ast::{token, BlockCheckMode, UnsafeSource};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::{pluralize, Applicability, DiagnosticBuilder};
Expand Down Expand Up @@ -788,17 +789,31 @@ impl<'a, 'b> Context<'a, 'b> {
// the order provided to fmt::Arguments. When arguments are repeated, we
// want the expression evaluated only once.
//
// Thus in the not nicely ordered case we emit the following instead:
// Further, if any arg _after the first one_ contains a yield point such
// as `await` or `yield`, the above short form is inconvenient for the
// caller because it would keep a temporary of type ArgumentV1 alive
// across the yield point. ArgumentV1 can't implement Send since it
// holds a type-erased arbitrary type.
//
// Thus in the not nicely ordered case, and in the yielding case, we
// emit the following instead:
//
// match (&$arg0, &$arg1, …) {
// args => [ArgumentV1::new(args.$i, …), ArgumentV1::new(args.$j, …), …]
// }
//
// for the sequence of indices $i, $j, … governed by fmt_arg_index_and_ty.
// This more verbose representation ensures that all arguments are
// evaluated a single time each, in the order written by the programmer,
// and that the surrounding future/generator (if any) is Send whenever
// possible.
let no_need_for_match =
nicely_ordered && !original_args.iter().skip(1).any(|e| may_contain_yield_point(e));

for (arg_index, arg_ty) in fmt_arg_index_and_ty {
let e = &mut original_args[arg_index];
let span = e.span;
let arg = if nicely_ordered {
let arg = if no_need_for_match {
let expansion_span = e.span.with_ctxt(self.macsp.ctxt());
// The indices are strictly ordered so e has not been taken yet.
self.ecx.expr_addr_of(expansion_span, P(e.take()))
Expand All @@ -814,10 +829,10 @@ impl<'a, 'b> Context<'a, 'b> {
let args_array = self.ecx.expr_vec(self.macsp, fmt_args);
let args_slice = self.ecx.expr_addr_of(
self.macsp,
if nicely_ordered {
if no_need_for_match {
args_array
} else {
// In the !nicely_ordered case, none of the exprs were moved
// In the !no_need_for_match case, none of the exprs were moved
// away in the previous loop.
//
// This uses the arg span for `&arg` so that borrowck errors
Expand Down Expand Up @@ -1226,3 +1241,35 @@ pub fn expand_preparsed_format_args(

cx.into_expr()
}

fn may_contain_yield_point(e: &ast::Expr) -> bool {
struct MayContainYieldPoint(bool);

impl Visitor<'_> for MayContainYieldPoint {
fn visit_expr(&mut self, e: &ast::Expr) {
if let ast::ExprKind::Await(_) | ast::ExprKind::Yield(_) = e.kind {
self.0 = true;
} else {
visit::walk_expr(self, e);
}
}

fn visit_mac_call(&mut self, _: &ast::MacCall) {
self.0 = true;
}

fn visit_attribute(&mut self, _: &ast::Attribute) {
// Conservatively assume this may be a proc macro attribute in
// expression position.
self.0 = true;
}

fn visit_item(&mut self, _: &ast::Item) {
// Do not recurse into nested items.
}
}

let mut visitor = MayContainYieldPoint(false);
visitor.visit_expr(e);
visitor.0
}
8 changes: 4 additions & 4 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ impl<'a> Parser<'a> {
if ident.is_raw_guess()
&& self.look_ahead(1, |t| valid_follow.contains(&t.kind)) =>
{
err.span_suggestion(
ident.span,
"you can escape reserved keywords to use them as identifiers",
format!("r#{}", ident.name),
err.span_suggestion_verbose(
ident.span.shrink_to_lo(),
&format!("escape `{}` to use it as an identifier", ident.name),
"r#".to_owned(),
Applicability::MaybeIncorrect,
);
}
Expand Down
46 changes: 27 additions & 19 deletions library/core/src/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,29 +1008,37 @@ impl f32 {
Self::from_bits(u32::from_ne_bytes(bytes))
}

/// Returns an ordering between self and other values.
/// Return the ordering between `self` and `other`.
///
/// Unlike the standard partial comparison between floating point numbers,
/// this comparison always produces an ordering in accordance to
/// the totalOrder predicate as defined in IEEE 754 (2008 revision)
/// floating point standard. The values are ordered in following order:
/// - Negative quiet NaN
/// - Negative signaling NaN
/// - Negative infinity
/// - Negative numbers
/// - Negative subnormal numbers
/// - Negative zero
/// - Positive zero
/// - Positive subnormal numbers
/// - Positive numbers
/// - Positive infinity
/// - Positive signaling NaN
/// - Positive quiet NaN
///
/// Note that this function does not always agree with the [`PartialOrd`]
/// and [`PartialEq`] implementations of `f32`. In particular, they regard
/// negative and positive zero as equal, while `total_cmp` doesn't.
/// the `totalOrder` predicate as defined in the IEEE 754 (2008 revision)
/// floating point standard. The values are ordered in the following sequence:
///
/// - negative quiet NaN
/// - negative signaling NaN
/// - negative infinity
/// - negative numbers
/// - negative subnormal numbers
/// - negative zero
/// - positive zero
/// - positive subnormal numbers
/// - positive numbers
/// - positive infinity
/// - positive signaling NaN
/// - positive quiet NaN.
///
/// The ordering established by this function does not always agree with the
/// [`PartialOrd`] and [`PartialEq`] implementations of `f32`. For example,
/// they consider negative and positive zero equal, while `total_cmp`
/// doesn't.
///
/// The interpretation of the signaling NaN bit follows the definition in
/// the IEEE 754 standard, which may not match the interpretation by some of
/// the older, non-conformant (e.g. MIPS) hardware implementations.
///
/// # Example
///
/// ```
/// #![feature(total_cmp)]
/// struct GoodBoy {
Expand Down
46 changes: 27 additions & 19 deletions library/core/src/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,29 +1024,37 @@ impl f64 {
Self::from_bits(u64::from_ne_bytes(bytes))
}

/// Returns an ordering between self and other values.
/// Return the ordering between `self` and `other`.
///
/// Unlike the standard partial comparison between floating point numbers,
/// this comparison always produces an ordering in accordance to
/// the totalOrder predicate as defined in IEEE 754 (2008 revision)
/// floating point standard. The values are ordered in following order:
/// - Negative quiet NaN
/// - Negative signaling NaN
/// - Negative infinity
/// - Negative numbers
/// - Negative subnormal numbers
/// - Negative zero
/// - Positive zero
/// - Positive subnormal numbers
/// - Positive numbers
/// - Positive infinity
/// - Positive signaling NaN
/// - Positive quiet NaN
///
/// Note that this function does not always agree with the [`PartialOrd`]
/// and [`PartialEq`] implementations of `f64`. In particular, they regard
/// negative and positive zero as equal, while `total_cmp` doesn't.
/// the `totalOrder` predicate as defined in the IEEE 754 (2008 revision)
/// floating point standard. The values are ordered in the following sequence:
///
/// - negative quiet NaN
/// - negative signaling NaN
/// - negative infinity
/// - negative numbers
/// - negative subnormal numbers
/// - negative zero
/// - positive zero
/// - positive subnormal numbers
/// - positive numbers
/// - positive infinity
/// - positive signaling NaN
/// - positive quiet NaN.
///
/// The ordering established by this function does not always agree with the
/// [`PartialOrd`] and [`PartialEq`] implementations of `f64`. For example,
/// they consider negative and positive zero equal, while `total_cmp`
/// doesn't.
///
/// The interpretation of the signaling NaN bit follows the definition in
/// the IEEE 754 standard, which may not match the interpretation by some of
/// the older, non-conformant (e.g. MIPS) hardware implementations.
///
/// # Example
///
/// ```
/// #![feature(total_cmp)]
/// struct GoodBoy {
Expand Down
44 changes: 0 additions & 44 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2558,50 +2558,6 @@ impl<T> [T] {
sort::quicksort(self, |a, b| f(a).lt(&f(b)));
}

/// Reorder the slice such that the element at `index` is at its final sorted position.
#[unstable(feature = "slice_partition_at_index", issue = "55300")]
#[rustc_deprecated(since = "1.49.0", reason = "use the select_nth_unstable() instead")]
#[inline]
pub fn partition_at_index(&mut self, index: usize) -> (&mut [T], &mut T, &mut [T])
where
T: Ord,
{
self.select_nth_unstable(index)
}

/// Reorder the slice with a comparator function such that the element at `index` is at its
/// final sorted position.
#[unstable(feature = "slice_partition_at_index", issue = "55300")]
#[rustc_deprecated(since = "1.49.0", reason = "use select_nth_unstable_by() instead")]
#[inline]
pub fn partition_at_index_by<F>(
&mut self,
index: usize,
compare: F,
) -> (&mut [T], &mut T, &mut [T])
where
F: FnMut(&T, &T) -> Ordering,
{
self.select_nth_unstable_by(index, compare)
}

/// Reorder the slice with a key extraction function such that the element at `index` is at its
/// final sorted position.
#[unstable(feature = "slice_partition_at_index", issue = "55300")]
#[rustc_deprecated(since = "1.49.0", reason = "use the select_nth_unstable_by_key() instead")]
#[inline]
pub fn partition_at_index_by_key<K, F>(
&mut self,
index: usize,
f: F,
) -> (&mut [T], &mut T, &mut [T])
where
F: FnMut(&T) -> K,
K: Ord,
{
self.select_nth_unstable_by_key(index, f)
}

/// Reorder the slice such that the element at `index` is at its final sorted position.
///
/// This reordering has the additional property that any value at position `i < index` will be
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/slice/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ where
let mid = partition_equal(v, pivot, is_less);

// Continue sorting elements greater than the pivot.
v = &mut { v }[mid..];
v = &mut v[mid..];
continue;
}
}
Expand All @@ -784,7 +784,7 @@ where
was_partitioned = was_p;

// Split the slice into `left`, `pivot`, and `right`.
let (left, right) = { v }.split_at_mut(mid);
let (left, right) = v.split_at_mut(mid);
let (pivot, right) = right.split_at_mut(1);
let pivot = &pivot[0];

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

// Split the slice into `left`, `pivot`, and `right`.
let (left, right) = { v }.split_at_mut(mid);
let (left, right) = v.split_at_mut(mid);
let (pivot, right) = right.split_at_mut(1);
let pivot = &pivot[0];

Expand Down
1 change: 0 additions & 1 deletion library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
#![feature(is_sorted)]
#![feature(pattern)]
#![feature(sort_internals)]
#![feature(slice_partition_at_index)]
#![feature(slice_take)]
#![feature(maybe_uninit_uninit_array)]
#![feature(maybe_uninit_array_assume_init)]
Expand Down
7 changes: 2 additions & 5 deletions library/std/src/sys/itron/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ impl Thread {
///
/// See `thread::Builder::spawn_unchecked` for safety requirements.
pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
// Inherit the current task's priority
let current_task = task::try_current_task_id().map_err(|e| e.as_io_error())?;
let priority = task::try_task_priority(current_task).map_err(|e| e.as_io_error())?;

let inner = Box::new(ThreadInner {
start: UnsafeCell::new(ManuallyDrop::new(p)),
lifecycle: AtomicUsize::new(LIFECYCLE_INIT),
Expand Down Expand Up @@ -175,7 +171,8 @@ impl Thread {
exinf: inner_ptr as abi::EXINF,
// The entry point
task: Some(trampoline),
itskpri: priority,
// Inherit the calling task's base priority
itskpri: abi::TPRI_SELF,
stksz: stack,
// Let the kernel allocate the stack,
stk: crate::ptr::null_mut(),
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/sys/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ impl DirEntry {
target_os = "vxworks"
))]
pub fn file_type(&self) -> io::Result<FileType> {
lstat(&self.path()).map(|m| m.file_type())
self.metadata().map(|m| m.file_type())
}

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

Expand Down
7 changes: 6 additions & 1 deletion library/std/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@ pub struct Instant(time::Instant);
/// }
/// ```
///
/// # Underlying System calls
/// # Platform-specific behavior
///
/// The precision of `SystemTime` can depend on the underlying OS-specific time format.
/// For example, on Windows the time is represented in 100 nanosecond intervals whereas Linux
/// can represent nanosecond intervals.
///
/// Currently, the following system calls are being used to get the current time using `now()`:
///
/// | Platform | System call |
Expand Down
Loading