Skip to content

Rollup of 11 pull requests #102448

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

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c846a2a
Make `std::os::fd` public.
sunfishcode Jun 14, 2022
09bbc42
Update asrawfd.js.
sunfishcode Jun 22, 2022
bda1262
Clarify that the `fd` module is supported on Unix and WASI.
sunfishcode Jun 30, 2022
7d80510
Re-introduce `unstable` attributes.
sunfishcode Aug 23, 2022
a7f3ba9
Fix compilation of the doc tests on Windows.
sunfishcode Sep 2, 2022
f9ef7e2
code refactoring smart_resolve_report_errors
chenyukang Sep 20, 2022
7adfb44
add trivial comments
chenyukang Sep 21, 2022
fdda7e0
more code refactor on smart_resolve_report_errors
chenyukang Sep 25, 2022
db0877f
trivial fix on fallback
chenyukang Sep 25, 2022
356a52c
add regression test
Rageking8 Sep 28, 2022
4fdc78e
account for use of index-based lifetime names in print of binder
b-naber Sep 28, 2022
a670897
add test
b-naber Sep 28, 2022
9ccb851
update fixme
lcnr Sep 28, 2022
a913277
Add a niche to `Duration`, unix `SystemTime`, and non-apple `Instant`
beetrees Sep 14, 2022
5baceaf
env::temp_dir: fix a typo
RalfJung Sep 28, 2022
b707eff
rustdoc: cut margin-top from first header in docblock
notriddle Sep 28, 2022
f55ea41
rustdoc: clean up "normalize.css 8" input override CSS
notriddle Sep 28, 2022
3f21f07
rustdoc: remove bad CSS font-weight on `.impl`, `.method`, etc
notriddle Sep 28, 2022
d412bdc
rustdoc: add method spacing to trait methods
notriddle Sep 29, 2022
2c6feff
Rollup merge of #98368 - sunfishcode:sunfishcode/std-os-fd, r=joshtri…
JohnTitor Sep 29, 2022
5aff82b
Rollup merge of #102085 - chenyukang:code-refactor, r=cjgillot
JohnTitor Sep 29, 2022
df81a06
Rollup merge of #102368 - beetrees:nano-niche, r=joshtriplett
JohnTitor Sep 29, 2022
2b11e5b
Rollup merge of #102393 - Rageking8:add-regression-test-for-issue-949…
JohnTitor Sep 29, 2022
6643aad
Rollup merge of #102399 - b-naber:binder-print-ice, r=lcnr
JohnTitor Sep 29, 2022
c1a0455
Rollup merge of #102416 - lcnr:specialization-fixme, r=compiler-errors
JohnTitor Sep 29, 2022
bfeaba9
Rollup merge of #102433 - RalfJung:temp-dir-typo, r=thomcc
JohnTitor Sep 29, 2022
952d88c
Rollup merge of #102436 - notriddle:notriddle/normalize-form, r=Guill…
JohnTitor Sep 29, 2022
149691c
Rollup merge of #102437 - notriddle:notriddle/margin-top-h2, r=jsha
JohnTitor Sep 29, 2022
65d1c7f
Rollup merge of #102442 - notriddle:notriddle/header-weight, r=Guilla…
JohnTitor Sep 29, 2022
b1bded7
Rollup merge of #102447 - notriddle:notriddle/method-toggle, r=jsha
JohnTitor Sep 29, 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
14 changes: 10 additions & 4 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2173,10 +2173,16 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {

let mut region_index = self.region_index;
let mut next_name = |this: &Self| {
let name = name_by_region_index(region_index, &mut available_names, num_available);
debug!(?name);
region_index += 1;
assert!(!this.used_region_names.contains(&name));
let mut name;

loop {
name = name_by_region_index(region_index, &mut available_names, num_available);
region_index += 1;

if !this.used_region_names.contains(&name) {
break;
}
}

name
};
Expand Down
613 changes: 366 additions & 247 deletions compiler/rustc_resolve/src/late/diagnostics.rs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1737,12 +1737,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {

(&ImplCandidate(other_def), &ImplCandidate(victim_def)) => {
// See if we can toss out `victim` based on specialization.
// This requires us to know *for sure* that the `other` impl applies
// i.e., `EvaluatedToOk`.
// While this requires us to know *for sure* that the `other` impl applies
// we still use modulo regions here.
//
// FIXME(@lcnr): Using `modulo_regions` here seems kind of scary
// to me but is required for `std` to compile, so I didn't change it
// for now.
// This is fine as specialization currently assumes that specializing
// impls have to be always applicable, meaning that the only allowed
// region constraints may be constraints also present on the default impl.
let tcx = self.tcx();
if other.evaluation.must_apply_modulo_regions() {
if tcx.specializes((other_def, victim_def)) {
Expand Down
98 changes: 52 additions & 46 deletions library/core/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ const NANOS_PER_MICRO: u32 = 1_000;
const MILLIS_PER_SEC: u64 = 1_000;
const MICROS_PER_SEC: u64 = 1_000_000;

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
#[rustc_layout_scalar_valid_range_start(0)]
#[rustc_layout_scalar_valid_range_end(999_999_999)]
struct Nanoseconds(u32);

impl Default for Nanoseconds {
#[inline]
fn default() -> Self {
// SAFETY: 0 is within the valid range
unsafe { Nanoseconds(0) }
}
}

/// A `Duration` type to represent a span of time, typically used for system
/// timeouts.
///
Expand Down Expand Up @@ -71,7 +85,7 @@ const MICROS_PER_SEC: u64 = 1_000_000;
#[cfg_attr(not(test), rustc_diagnostic_item = "Duration")]
pub struct Duration {
secs: u64,
nanos: u32, // Always 0 <= nanos < NANOS_PER_SEC
nanos: Nanoseconds, // Always 0 <= nanos < NANOS_PER_SEC
}

impl Duration {
Expand Down Expand Up @@ -188,7 +202,8 @@ impl Duration {
None => panic!("overflow in Duration::new"),
};
let nanos = nanos % NANOS_PER_SEC;
Duration { secs, nanos }
// SAFETY: nanos % NANOS_PER_SEC < NANOS_PER_SEC, therefore nanos is within the valid range
Duration { secs, nanos: unsafe { Nanoseconds(nanos) } }
}

/// Creates a new `Duration` from the specified number of whole seconds.
Expand All @@ -208,7 +223,7 @@ impl Duration {
#[inline]
#[rustc_const_stable(feature = "duration_consts", since = "1.32.0")]
pub const fn from_secs(secs: u64) -> Duration {
Duration { secs, nanos: 0 }
Duration::new(secs, 0)
}

/// Creates a new `Duration` from the specified number of milliseconds.
Expand All @@ -228,10 +243,7 @@ impl Duration {
#[inline]
#[rustc_const_stable(feature = "duration_consts", since = "1.32.0")]
pub const fn from_millis(millis: u64) -> Duration {
Duration {
secs: millis / MILLIS_PER_SEC,
nanos: ((millis % MILLIS_PER_SEC) as u32) * NANOS_PER_MILLI,
}
Duration::new(millis / MILLIS_PER_SEC, ((millis % MILLIS_PER_SEC) as u32) * NANOS_PER_MILLI)
}

/// Creates a new `Duration` from the specified number of microseconds.
Expand All @@ -251,10 +263,7 @@ impl Duration {
#[inline]
#[rustc_const_stable(feature = "duration_consts", since = "1.32.0")]
pub const fn from_micros(micros: u64) -> Duration {
Duration {
secs: micros / MICROS_PER_SEC,
nanos: ((micros % MICROS_PER_SEC) as u32) * NANOS_PER_MICRO,
}
Duration::new(micros / MICROS_PER_SEC, ((micros % MICROS_PER_SEC) as u32) * NANOS_PER_MICRO)
}

/// Creates a new `Duration` from the specified number of nanoseconds.
Expand All @@ -274,10 +283,7 @@ impl Duration {
#[inline]
#[rustc_const_stable(feature = "duration_consts", since = "1.32.0")]
pub const fn from_nanos(nanos: u64) -> Duration {
Duration {
secs: nanos / (NANOS_PER_SEC as u64),
nanos: (nanos % (NANOS_PER_SEC as u64)) as u32,
}
Duration::new(nanos / (NANOS_PER_SEC as u64), (nanos % (NANOS_PER_SEC as u64)) as u32)
}

/// Returns true if this `Duration` spans no time.
Expand All @@ -301,7 +307,7 @@ impl Duration {
#[rustc_const_stable(feature = "duration_zero", since = "1.53.0")]
#[inline]
pub const fn is_zero(&self) -> bool {
self.secs == 0 && self.nanos == 0
self.secs == 0 && self.nanos.0 == 0
}

/// Returns the number of _whole_ seconds contained by this `Duration`.
Expand Down Expand Up @@ -352,7 +358,7 @@ impl Duration {
#[must_use]
#[inline]
pub const fn subsec_millis(&self) -> u32 {
self.nanos / NANOS_PER_MILLI
self.nanos.0 / NANOS_PER_MILLI
}

/// Returns the fractional part of this `Duration`, in whole microseconds.
Expand All @@ -375,7 +381,7 @@ impl Duration {
#[must_use]
#[inline]
pub const fn subsec_micros(&self) -> u32 {
self.nanos / NANOS_PER_MICRO
self.nanos.0 / NANOS_PER_MICRO
}

/// Returns the fractional part of this `Duration`, in nanoseconds.
Expand All @@ -398,7 +404,7 @@ impl Duration {
#[must_use]
#[inline]
pub const fn subsec_nanos(&self) -> u32 {
self.nanos
self.nanos.0
}

/// Returns the total number of whole milliseconds contained by this `Duration`.
Expand All @@ -416,7 +422,7 @@ impl Duration {
#[must_use]
#[inline]
pub const fn as_millis(&self) -> u128 {
self.secs as u128 * MILLIS_PER_SEC as u128 + (self.nanos / NANOS_PER_MILLI) as u128
self.secs as u128 * MILLIS_PER_SEC as u128 + (self.nanos.0 / NANOS_PER_MILLI) as u128
}

/// Returns the total number of whole microseconds contained by this `Duration`.
Expand All @@ -434,7 +440,7 @@ impl Duration {
#[must_use]
#[inline]
pub const fn as_micros(&self) -> u128 {
self.secs as u128 * MICROS_PER_SEC as u128 + (self.nanos / NANOS_PER_MICRO) as u128
self.secs as u128 * MICROS_PER_SEC as u128 + (self.nanos.0 / NANOS_PER_MICRO) as u128
}

/// Returns the total number of nanoseconds contained by this `Duration`.
Expand All @@ -452,7 +458,7 @@ impl Duration {
#[must_use]
#[inline]
pub const fn as_nanos(&self) -> u128 {
self.secs as u128 * NANOS_PER_SEC as u128 + self.nanos as u128
self.secs as u128 * NANOS_PER_SEC as u128 + self.nanos.0 as u128
}

/// Checked `Duration` addition. Computes `self + other`, returning [`None`]
Expand All @@ -475,7 +481,7 @@ impl Duration {
#[rustc_const_stable(feature = "duration_consts_2", since = "1.58.0")]
pub const fn checked_add(self, rhs: Duration) -> Option<Duration> {
if let Some(mut secs) = self.secs.checked_add(rhs.secs) {
let mut nanos = self.nanos + rhs.nanos;
let mut nanos = self.nanos.0 + rhs.nanos.0;
if nanos >= NANOS_PER_SEC {
nanos -= NANOS_PER_SEC;
if let Some(new_secs) = secs.checked_add(1) {
Expand All @@ -485,7 +491,7 @@ impl Duration {
}
}
debug_assert!(nanos < NANOS_PER_SEC);
Some(Duration { secs, nanos })
Some(Duration::new(secs, nanos))
} else {
None
}
Expand Down Expand Up @@ -535,16 +541,16 @@ impl Duration {
#[rustc_const_stable(feature = "duration_consts_2", since = "1.58.0")]
pub const fn checked_sub(self, rhs: Duration) -> Option<Duration> {
if let Some(mut secs) = self.secs.checked_sub(rhs.secs) {
let nanos = if self.nanos >= rhs.nanos {
self.nanos - rhs.nanos
let nanos = if self.nanos.0 >= rhs.nanos.0 {
self.nanos.0 - rhs.nanos.0
} else if let Some(sub_secs) = secs.checked_sub(1) {
secs = sub_secs;
self.nanos + NANOS_PER_SEC - rhs.nanos
self.nanos.0 + NANOS_PER_SEC - rhs.nanos.0
} else {
return None;
};
debug_assert!(nanos < NANOS_PER_SEC);
Some(Duration { secs, nanos })
Some(Duration::new(secs, nanos))
} else {
None
}
Expand Down Expand Up @@ -593,13 +599,13 @@ impl Duration {
#[rustc_const_stable(feature = "duration_consts_2", since = "1.58.0")]
pub const fn checked_mul(self, rhs: u32) -> Option<Duration> {
// Multiply nanoseconds as u64, because it cannot overflow that way.
let total_nanos = self.nanos as u64 * rhs as u64;
let total_nanos = self.nanos.0 as u64 * rhs as u64;
let extra_secs = total_nanos / (NANOS_PER_SEC as u64);
let nanos = (total_nanos % (NANOS_PER_SEC as u64)) as u32;
if let Some(s) = self.secs.checked_mul(rhs as u64) {
if let Some(secs) = s.checked_add(extra_secs) {
debug_assert!(nanos < NANOS_PER_SEC);
return Some(Duration { secs, nanos });
return Some(Duration::new(secs, nanos));
}
}
None
Expand Down Expand Up @@ -653,9 +659,9 @@ impl Duration {
let secs = self.secs / (rhs as u64);
let carry = self.secs - secs * (rhs as u64);
let extra_nanos = carry * (NANOS_PER_SEC as u64) / (rhs as u64);
let nanos = self.nanos / rhs + (extra_nanos as u32);
let nanos = self.nanos.0 / rhs + (extra_nanos as u32);
debug_assert!(nanos < NANOS_PER_SEC);
Some(Duration { secs, nanos })
Some(Duration::new(secs, nanos))
} else {
None
}
Expand All @@ -677,7 +683,7 @@ impl Duration {
#[inline]
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
pub const fn as_secs_f64(&self) -> f64 {
(self.secs as f64) + (self.nanos as f64) / (NANOS_PER_SEC as f64)
(self.secs as f64) + (self.nanos.0 as f64) / (NANOS_PER_SEC as f64)
}

/// Returns the number of seconds contained by this `Duration` as `f32`.
Expand All @@ -696,7 +702,7 @@ impl Duration {
#[inline]
#[rustc_const_unstable(feature = "duration_consts_float", issue = "72440")]
pub const fn as_secs_f32(&self) -> f32 {
(self.secs as f32) + (self.nanos as f32) / (NANOS_PER_SEC as f32)
(self.secs as f32) + (self.nanos.0 as f32) / (NANOS_PER_SEC as f32)
}

/// Creates a new `Duration` from the specified number of seconds represented
Expand Down Expand Up @@ -987,21 +993,21 @@ macro_rules! sum_durations {
for entry in $iter {
total_secs =
total_secs.checked_add(entry.secs).expect("overflow in iter::sum over durations");
total_nanos = match total_nanos.checked_add(entry.nanos as u64) {
total_nanos = match total_nanos.checked_add(entry.nanos.0 as u64) {
Some(n) => n,
None => {
total_secs = total_secs
.checked_add(total_nanos / NANOS_PER_SEC as u64)
.expect("overflow in iter::sum over durations");
(total_nanos % NANOS_PER_SEC as u64) + entry.nanos as u64
(total_nanos % NANOS_PER_SEC as u64) + entry.nanos.0 as u64
}
};
}
total_secs = total_secs
.checked_add(total_nanos / NANOS_PER_SEC as u64)
.expect("overflow in iter::sum over durations");
total_nanos = total_nanos % NANOS_PER_SEC as u64;
Duration { secs: total_secs, nanos: total_nanos as u32 }
Duration::new(total_secs, total_nanos as u32)
}};
}

Expand Down Expand Up @@ -1166,27 +1172,27 @@ impl fmt::Debug for Duration {
let prefix = if f.sign_plus() { "+" } else { "" };

if self.secs > 0 {
fmt_decimal(f, self.secs, self.nanos, NANOS_PER_SEC / 10, prefix, "s")
} else if self.nanos >= NANOS_PER_MILLI {
fmt_decimal(f, self.secs, self.nanos.0, NANOS_PER_SEC / 10, prefix, "s")
} else if self.nanos.0 >= NANOS_PER_MILLI {
fmt_decimal(
f,
(self.nanos / NANOS_PER_MILLI) as u64,
self.nanos % NANOS_PER_MILLI,
(self.nanos.0 / NANOS_PER_MILLI) as u64,
self.nanos.0 % NANOS_PER_MILLI,
NANOS_PER_MILLI / 10,
prefix,
"ms",
)
} else if self.nanos >= NANOS_PER_MICRO {
} else if self.nanos.0 >= NANOS_PER_MICRO {
fmt_decimal(
f,
(self.nanos / NANOS_PER_MICRO) as u64,
self.nanos % NANOS_PER_MICRO,
(self.nanos.0 / NANOS_PER_MICRO) as u64,
self.nanos.0 % NANOS_PER_MICRO,
NANOS_PER_MICRO / 10,
prefix,
"µs",
)
} else {
fmt_decimal(f, self.nanos as u64, 0, 1, prefix, "ns")
fmt_decimal(f, self.nanos.0 as u64, 0, 1, prefix, "ns")
}
}
}
Expand Down Expand Up @@ -1317,7 +1323,7 @@ macro_rules! try_from_secs {
return Err(FromFloatSecsError { kind: FromFloatSecsErrorKind::OverflowOrNan });
};

Ok(Duration { secs, nanos })
Ok(Duration::new(secs, nanos))
}};
}

Expand Down
2 changes: 1 addition & 1 deletion library/std/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ pub fn home_dir() -> Option<PathBuf> {
/// # Platform-specific behavior
///
/// On Unix, returns the value of the `TMPDIR` environment variable if it is
/// set, otherwise for non-Android it returns `/tmp`. If Android, since there
/// set, otherwise for non-Android it returns `/tmp`. On Android, since there
/// is no global temporary folder (it is usually allocated per-app), it returns
/// `/data/local/tmp`.
/// On Windows, the behavior is equivalent to that of [`GetTempPath2`][GetTempPath2] /
Expand Down
13 changes: 11 additions & 2 deletions library/std/src/os/fd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
//! Owned and borrowed Unix-like file descriptors.
//!
//! This module is supported on Unix platforms and WASI, which both use a
//! similar file descriptor system for referencing OS resources.

#![stable(feature = "io_safety", since = "1.63.0")]
#![deny(unsafe_op_in_unsafe_fn)]

// `RawFd`, `AsRawFd`, etc.
pub mod raw;
mod raw;

// `OwnedFd`, `AsFd`, etc.
pub mod owned;
mod owned;

// Implementations for `AsRawFd` etc. for network types.
mod net;

#[cfg(test)]
mod tests;

// Export the types and traits for the public API.
#[unstable(feature = "os_fd", issue = "98699")]
pub use owned::*;
#[unstable(feature = "os_fd", issue = "98699")]
pub use raw::*;
6 changes: 2 additions & 4 deletions library/std/src/os/fd/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,8 @@ pub trait AsFd {
/// ```rust,no_run
/// use std::fs::File;
/// # use std::io;
/// # #[cfg(target_os = "wasi")]
/// # use std::os::wasi::io::{AsFd, BorrowedFd};
/// # #[cfg(unix)]
/// # use std::os::unix::io::{AsFd, BorrowedFd};
/// # #[cfg(any(unix, target_os = "wasi"))]
/// # use std::os::fd::{AsFd, BorrowedFd};
///
/// let mut f = File::open("foo.txt")?;
/// # #[cfg(any(unix, target_os = "wasi"))]
Expand Down
Loading