Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 11 additions & 9 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1344,15 +1344,17 @@ fn warn_on_confusing_output_filename_flag(
|| config::CG_OPTIONS.iter().any(|option| eq_ignore_separators(option.name(), filename))
|| fake_args.iter().any(|arg| eq_ignore_separators(arg, filename))
{
early_dcx.early_warn(
"option `-o` has no space between flag name and value, which can be confusing",
);
early_dcx.early_note(format!(
"output filename `-o {name}` is applied instead of a flag named `o{name}`"
));
early_dcx.early_help(format!(
"insert a space between `-o` and `{name}` if this is intentional: `-o {name}`"
));
early_dcx
.early_struct_warn(
"option `-o` has no space between flag name and value, which can be confusing",
)
.with_note(format!(
"output filename `-o {name}` is applied instead of a flag named `o{name}`"
))
.with_help(format!(
"insert a space between `-o` and `{name}` if this is intentional: `-o {name}`"
))
.emit();
}
}
}
Expand Down
39 changes: 19 additions & 20 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3194,29 +3194,28 @@ pub mod nightly_options {
if really_allows_unstable_options {
continue;
}
match opt.stability {
OptionStability::Unstable => {
nightly_options_on_stable += 1;
let msg = format!(
"the option `{}` is only accepted on the nightly compiler",
opt.name
);
// The non-zero nightly_options_on_stable will force an early_fatal eventually.
let _ = early_dcx.early_err(msg);
}
OptionStability::Stable => {}
}

nightly_options_on_stable += 1;
let msg = format!("the option `{}` is only accepted on the nightly compiler", opt.name);
// The non-zero nightly_options_on_stable will force an early_fatal eventually.
let _ = early_dcx.early_err(msg);
}

if nightly_options_on_stable > 0 {
early_dcx
.early_help("consider switching to a nightly toolchain: `rustup default nightly`");
early_dcx.early_note("selecting a toolchain with `+toolchain` arguments require a rustup proxy; see <https://rust-lang.github.io/rustup/concepts/index.html>");
early_dcx.early_note("for more information about Rust's stability policy, see <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html#unstable-features>");
early_dcx.early_fatal(format!(
"{} nightly option{} were parsed",
nightly_options_on_stable,
if nightly_options_on_stable > 1 { "s" } else { "" }
let (s, were) = if nightly_options_on_stable > 1 { ("s", "were") } else { ("", "was") };
let mut err = early_dcx.early_struct_fatal(format!(
"{nightly_options_on_stable} nightly option{s} {were} parsed",
));
err.help("consider switching to a nightly toolchain: `rustup default nightly`");
err.note(
"selecting a toolchain with `+toolchain` arguments require a rustup proxy; \
see <https://rust-lang.github.io/rustup/concepts/index.html>",
);
err.note(
"for more information about Rust's stability policy, see \
<https://doc.rust-lang.org/book/appendix-07-nightly-rust.html#unstable-features>",
);
err.emit();
}
}
}
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1789,14 +1789,6 @@ impl EarlyDiagCtxt {
self.dcx = DiagCtxt::new(emitter);
}

pub fn early_note(&self, msg: impl Into<DiagMessage>) {
self.dcx.handle().note(msg)
}

pub fn early_help(&self, msg: impl Into<DiagMessage>) {
self.dcx.handle().struct_help(msg).emit()
}

#[must_use = "raise_fatal must be called on the returned ErrorGuaranteed in order to exit with a non-zero status code"]
pub fn early_err(&self, msg: impl Into<DiagMessage>) -> ErrorGuaranteed {
self.dcx.handle().err(msg)
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_target/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,9 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("a", Stable, &["zaamo", "zalrsc"]),
("b", Stable, &["zba", "zbb", "zbs"]),
("c", Stable, &["zca"]),
("d", Unstable(sym::riscv_target_feature), &["f"]),
("e", Unstable(sym::riscv_target_feature), &[]),
("f", Unstable(sym::riscv_target_feature), &["zicsr"]),
("d", Stable, &["f"]),
("e", Unstable(sym::riscv_target_feature), &[]), // negative feature! needs special care.
("f", Stable, &["zicsr"]),
(
"forced-atomics",
// Not implied by any CPU model or other feature.
Expand Down
1 change: 0 additions & 1 deletion library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@
#![feature(derive_const)]
#![feature(diagnostic_on_move)]
#![feature(dispatch_from_dyn)]
#![feature(drop_guard)]
#![feature(ergonomic_clones)]
#![feature(error_generic_member_access)]
#![feature(exact_size_is_empty)]
Expand Down
1 change: 0 additions & 1 deletion library/alloctests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#![feature(const_try)]
#![feature(copied_into_inner)]
#![feature(core_intrinsics)]
#![feature(drop_guard)]
#![feature(exact_size_is_empty)]
#![feature(extend_one)]
#![feature(extend_one_unchecked)]
Expand Down
18 changes: 8 additions & 10 deletions library/core/src/mem/drop_guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::ops::{Deref, DerefMut};
///
/// ```rust
/// # #![allow(unused)]
/// #![feature(drop_guard)]
///
/// use std::mem::DropGuard;
///
Expand All @@ -28,7 +27,7 @@ use crate::ops::{Deref, DerefMut};
/// // "Chashu likes tuna!!!"
/// }
/// ```
#[unstable(feature = "drop_guard", issue = "144426")]
#[stable(feature = "drop_guard", since = "CURRENT_RUSTC_VERSION")]
#[doc(alias = "ScopeGuard")]
#[doc(alias = "defer")]
pub struct DropGuard<T, F>
Expand All @@ -49,14 +48,14 @@ where
///
/// ```rust
/// # #![allow(unused)]
/// #![feature(drop_guard)]
///
/// use std::mem::DropGuard;
///
/// let value = String::from("Chashu likes tuna");
/// let guard = DropGuard::new(value, |s| println!("{s}"));
/// ```
#[unstable(feature = "drop_guard", issue = "144426")]
#[stable(feature = "drop_guard", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_drop_guard", issue = "none")]
#[must_use]
pub const fn new(inner: T, f: F) -> Self {
Self { inner: ManuallyDrop::new(inner), f: ManuallyDrop::new(f) }
Expand All @@ -73,15 +72,14 @@ where
///
/// ```rust
/// # #![allow(unused)]
/// #![feature(drop_guard)]
///
/// use std::mem::DropGuard;
///
/// let value = String::from("Nori likes chicken");
/// let guard = DropGuard::new(value, |s| println!("{s}"));
/// assert_eq!(DropGuard::dismiss(guard), "Nori likes chicken");
/// ```
#[unstable(feature = "drop_guard", issue = "144426")]
#[stable(feature = "drop_guard", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_drop_guard", issue = "none")]
#[inline]
pub const fn dismiss(guard: Self) -> T
Expand All @@ -107,7 +105,7 @@ where
}
}

#[unstable(feature = "drop_guard", issue = "144426")]
#[stable(feature = "drop_guard", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl<T, F> Deref for DropGuard<T, F>
where
Expand All @@ -120,7 +118,7 @@ where
}
}

#[unstable(feature = "drop_guard", issue = "144426")]
#[stable(feature = "drop_guard", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
const impl<T, F> DerefMut for DropGuard<T, F>
where
Expand All @@ -131,7 +129,7 @@ where
}
}

#[unstable(feature = "drop_guard", issue = "144426")]
#[stable(feature = "drop_guard", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_drop_guard", issue = "none")]
const impl<T, F> Drop for DropGuard<T, F>
where
Expand All @@ -148,7 +146,7 @@ where
}
}

#[unstable(feature = "drop_guard", issue = "144426")]
#[stable(feature = "drop_guard", since = "CURRENT_RUSTC_VERSION")]
impl<T, F> Debug for DropGuard<T, F>
where
T: Debug,
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ mod transmutability;
pub use transmutability::{Assume, TransmuteFrom};

mod drop_guard;
#[unstable(feature = "drop_guard", issue = "144426")]
#[stable(feature = "drop_guard", since = "CURRENT_RUSTC_VERSION")]
pub use drop_guard::DropGuard;

// This one has to be a re-export (rather than wrapping the underlying intrinsic) so that we can do
Expand Down
71 changes: 38 additions & 33 deletions library/core/src/slice/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ where
R: ops::RangeBounds<usize>,
{
let len = bounds.end;
try_into_slice_range(len, (range.start_bound().copied(), range.end_bound().copied()))
try_into_slice_range(len, (range.start_bound().copied(), range.end_bound().copied())).ok()
}

/// Converts a pair of `ops::Bound`s into `ops::Range` without performing any
Expand All @@ -961,69 +961,74 @@ pub(crate) const fn into_range_unchecked(
start..end
}

#[derive(Clone, Copy)]
pub(crate) enum RangeError {
EndPastLen { end: usize },
StartPastEnd { start: usize, end: usize },
}

impl RangeError {
#[cfg_attr(not(panic = "immediate-abort"), inline(never), cold)]
#[cfg_attr(panic = "immediate-abort", inline)]
#[track_caller]
const fn report(self, len: usize) -> ! {
match self {
Self::EndPastLen { end } => slice_index_fail(0, end, len),
Self::StartPastEnd { start, end } => slice_index_fail(start, end, len),
}
}
}

/// Converts pair of `ops::Bound`s into `ops::Range`.
/// Returns `None` on overflowing indices.
#[rustc_const_unstable(feature = "const_range", issue = "none")]
#[inline]
pub(crate) const fn try_into_slice_range(
len: usize,
(start, end): (ops::Bound<usize>, ops::Bound<usize>),
) -> Option<ops::Range<usize>> {
) -> Result<ops::Range<usize>, RangeError> {
let end = match end {
ops::Bound::Included(end) if end >= len => return None,
ops::Bound::Included(end) if end >= len => return Err(RangeError::EndPastLen { end }),
// Cannot overflow because `end < len` implies `end < usize::MAX`.
ops::Bound::Included(end) => end + 1,

ops::Bound::Excluded(end) if end > len => return None,
ops::Bound::Excluded(end) if end > len => return Err(RangeError::EndPastLen { end }),
ops::Bound::Excluded(end) => end,

ops::Bound::Unbounded => len,
};

let start = match start {
ops::Bound::Excluded(start) if start >= end => return None,
ops::Bound::Excluded(start) if start >= end => {
return Err(RangeError::StartPastEnd { start, end });
}
// Cannot overflow because `start < end` implies `start < usize::MAX`.
ops::Bound::Excluded(start) => start + 1,

ops::Bound::Included(start) if start > end => return None,
ops::Bound::Included(start) if start > end => {
return Err(RangeError::StartPastEnd { start, end });
}
ops::Bound::Included(start) => start,

ops::Bound::Unbounded => 0,
};

Some(start..end)
Ok(start..end)
}

/// Converts pair of `ops::Bound`s into `ops::Range`.
/// Panics on overflowing indices.
#[inline]
#[track_caller]
#[rustc_const_unstable(feature = "const_range", issue = "none")]
pub(crate) const fn into_slice_range(
len: usize,
(start, end): (ops::Bound<usize>, ops::Bound<usize>),
bounds: (ops::Bound<usize>, ops::Bound<usize>),
) -> ops::Range<usize> {
let end = match end {
ops::Bound::Included(end) if end >= len => slice_index_fail(0, end, len),
// Cannot overflow because `end < len` implies `end < usize::MAX`.
ops::Bound::Included(end) => end + 1,

ops::Bound::Excluded(end) if end > len => slice_index_fail(0, end, len),
ops::Bound::Excluded(end) => end,

ops::Bound::Unbounded => len,
};

let start = match start {
ops::Bound::Excluded(start) if start >= end => slice_index_fail(start, end, len),
// Cannot overflow because `start < end` implies `start < usize::MAX`.
ops::Bound::Excluded(start) => start + 1,

ops::Bound::Included(start) if start > end => slice_index_fail(start, end, len),
ops::Bound::Included(start) => start,

ops::Bound::Unbounded => 0,
};

start..end
match try_into_slice_range(len, bounds) {
Ok(range) => range,
Err(e) => e.report(len),
}
}

#[stable(feature = "slice_index_with_ops_bound_pair", since = "1.53.0")]
Expand All @@ -1032,13 +1037,13 @@ unsafe impl<T> SliceIndex<[T]> for (ops::Bound<usize>, ops::Bound<usize>) {

#[inline]
fn get(self, slice: &[T]) -> Option<&Self::Output> {
try_into_slice_range(slice.len(), self)?.get(slice)
try_into_slice_range(slice.len(), self).ok()?.get(slice)
}

#[inline]
#[rustc_no_writable]
fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::Output> {
try_into_slice_range(slice.len(), self)?.get_mut(slice)
try_into_slice_range(slice.len(), self).ok()?.get_mut(slice)
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/str/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,12 @@ unsafe impl SliceIndex<str> for (ops::Bound<usize>, ops::Bound<usize>) {

#[inline]
fn get(self, slice: &str) -> Option<&str> {
crate::slice::index::try_into_slice_range(slice.len(), self)?.get(slice)
crate::slice::index::try_into_slice_range(slice.len(), self).ok()?.get(slice)
}

#[inline]
fn get_mut(self, slice: &mut str) -> Option<&mut str> {
crate::slice::index::try_into_slice_range(slice.len(), self)?.get_mut(slice)
crate::slice::index::try_into_slice_range(slice.len(), self).ok()?.get_mut(slice)
}

#[inline]
Expand Down
1 change: 0 additions & 1 deletion library/coretests/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
#![feature(cstr_display)]
#![feature(debug_closure_helpers)]
#![feature(dec2flt)]
#![feature(drop_guard)]
#![feature(duration_constants)]
#![feature(duration_constructors)]
#![feature(exact_div)]
Expand Down
1 change: 0 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@
#![feature(cstr_display)]
#![feature(cursor_split)]
#![feature(derive_const)]
#![feature(drop_guard)]
#![feature(duration_constants)]
#![feature(error_generic_member_access)]
#![feature(error_iter)]
Expand Down
Loading
Loading