Skip to content
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

Rollup of 4 pull requests #94120

Closed
wants to merge 8 commits into from
23 changes: 23 additions & 0 deletions compiler/rustc_builtin_macros/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@ pub fn expand_test_or_bench(
"ignore",
cx.expr_bool(sp, should_ignore(&cx.sess, &item)),
),
// ignore_message: Some("...") | None
field(
"ignore_message",
if let Some(msg) = should_ignore_message(cx, &item) {
cx.expr_some(sp, cx.expr_str(sp, msg))
} else {
cx.expr_none(sp)
},
),
// compile_fail: true | false
field("compile_fail", cx.expr_bool(sp, false)),
// no_run: true | false
Expand Down Expand Up @@ -354,6 +363,20 @@ fn should_ignore(sess: &Session, i: &ast::Item) -> bool {
sess.contains_name(&i.attrs, sym::ignore)
}

fn should_ignore_message(cx: &ExtCtxt<'_>, i: &ast::Item) -> Option<Symbol> {
match cx.sess.find_by_name(&i.attrs, sym::ignore) {
Some(attr) => {
match attr.meta_item_list() {
// Handle #[ignore(bar = "foo")]
Some(_) => None,
// Handle #[ignore] and #[ignore = "message"]
None => attr.value_str(),
}
}
None => None,
}
}

fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
match cx.sess.find_by_name(&i.attrs, sym::should_panic) {
Some(attr) => {
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_expand/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ impl<'a> ExtCtxt<'a> {
self.expr_call_global(sp, some, vec![expr])
}

pub fn expr_none(&self, sp: Span) -> P<ast::Expr> {
let none = self.std_path(&[sym::option, sym::Option, sym::None]);
self.expr_path(self.path_global(sp, none))
}
pub fn expr_tuple(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> {
self.expr(sp, ast::ExprKind::Tup(exprs))
}
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ impl<T: ?Sized> Pin<&'static T> {
///
/// This is safe, because `T` is borrowed for the `'static` lifetime, which
/// never ends.
#[unstable(feature = "pin_static_ref", issue = "78186")]
#[stable(feature = "pin_static_ref", since = "1.60.0")]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
pub const fn static_ref(r: &'static T) -> Pin<&'static T> {
// SAFETY: The 'static borrow guarantees the data will not be
Expand Down Expand Up @@ -858,7 +858,7 @@ impl<T: ?Sized> Pin<&'static mut T> {
///
/// This is safe, because `T` is borrowed for the `'static` lifetime, which
/// never ends.
#[unstable(feature = "pin_static_ref", issue = "78186")]
#[stable(feature = "pin_static_ref", since = "1.60.0")]
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
pub const fn static_mut(r: &'static mut T) -> Pin<&'static mut T> {
// SAFETY: The 'static borrow guarantees the data will not be
Expand Down
78 changes: 78 additions & 0 deletions library/core/src/slice/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,84 @@ impl [u8] {
pub fn escape_ascii(&self) -> EscapeAscii<'_> {
EscapeAscii { inner: self.iter().flat_map(EscapeByte) }
}

/// Returns a byte slice with leading ASCII whitespace bytes removed.
///
/// 'Whitespace' refers to the definition used by
/// `u8::is_ascii_whitespace`.
///
/// # Examples
///
/// ```
/// #![feature(byte_slice_trim_ascii)]
///
/// assert_eq!(b" \t hello world\n".trim_ascii_start(), b"hello world\n");
/// assert_eq!(b" ".trim_ascii_start(), b"");
/// assert_eq!(b"".trim_ascii_start(), b"");
/// ```
#[unstable(feature = "byte_slice_trim_ascii", issue = "94035")]
pub const fn trim_ascii_start(&self) -> &[u8] {
let mut bytes = self;
// Note: A pattern matching based approach (instead of indexing) allows
// making the function const.
while let [first, rest @ ..] = bytes {
if first.is_ascii_whitespace() {
bytes = rest;
} else {
break;
}
}
bytes
}

/// Returns a byte slice with trailing ASCII whitespace bytes removed.
///
/// 'Whitespace' refers to the definition used by
/// `u8::is_ascii_whitespace`.
///
/// # Examples
///
/// ```
/// #![feature(byte_slice_trim_ascii)]
///
/// assert_eq!(b"\r hello world\n ".trim_ascii_end(), b"\r hello world");
/// assert_eq!(b" ".trim_ascii_end(), b"");
/// assert_eq!(b"".trim_ascii_end(), b"");
/// ```
#[unstable(feature = "byte_slice_trim_ascii", issue = "94035")]
pub const fn trim_ascii_end(&self) -> &[u8] {
let mut bytes = self;
// Note: A pattern matching based approach (instead of indexing) allows
// making the function const.
while let [rest @ .., last] = bytes {
if last.is_ascii_whitespace() {
bytes = rest;
} else {
break;
}
}
bytes
}

/// Returns a byte slice with leading and trailing ASCII whitespace bytes
/// removed.
///
/// 'Whitespace' refers to the definition used by
/// `u8::is_ascii_whitespace`.
///
/// # Examples
///
/// ```
/// #![feature(byte_slice_trim_ascii)]
///
/// assert_eq!(b"\r hello world\n ".trim_ascii(), b"hello world");
/// assert_eq!(b" ".trim_ascii(), b"");
/// assert_eq!(b"".trim_ascii(), b"");
/// ```
#[unstable(feature = "byte_slice_trim_ascii", issue = "94035")]
pub const fn trim_ascii(&self) -> &[u8] {
self.trim_ascii_start().trim_ascii_end()
}
}

impl_fn_for_zst! {
Expand Down
6 changes: 4 additions & 2 deletions library/std/src/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2472,6 +2472,7 @@ impl<'a, K, V> Entry<'a, K, V> {
/// # Examples
///
/// ```
/// #![feature(entry_insert)]
/// use std::collections::HashMap;
///
/// let mut map: HashMap<&str, String> = HashMap::new();
Expand All @@ -2480,7 +2481,7 @@ impl<'a, K, V> Entry<'a, K, V> {
/// assert_eq!(entry.key(), &"poneyland");
/// ```
#[inline]
#[stable(feature = "entry_insert", since = "1.59.0")]
#[unstable(feature = "entry_insert", issue = "65225")]
pub fn insert_entry(self, value: V) -> OccupiedEntry<'a, K, V> {
match self {
Occupied(mut entry) => {
Expand Down Expand Up @@ -2814,6 +2815,7 @@ impl<'a, K: 'a, V: 'a> VacantEntry<'a, K, V> {
/// # Examples
///
/// ```
/// #![feature(entry_insert)]
/// use std::collections::HashMap;
/// use std::collections::hash_map::Entry;
///
Expand All @@ -2825,7 +2827,7 @@ impl<'a, K: 'a, V: 'a> VacantEntry<'a, K, V> {
/// assert_eq!(map["poneyland"], 37);
/// ```
#[inline]
#[stable(feature = "entry_insert", since = "1.59.0")]
#[unstable(feature = "entry_insert", issue = "65225")]
pub fn insert_entry(self, value: V) -> OccupiedEntry<'a, K, V> {
let base = self.base.insert_entry(value);
OccupiedEntry { base }
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 @@ -311,7 +311,6 @@
#![feature(panic_internals)]
#![feature(panic_can_unwind)]
#![feature(panic_unwind)]
#![feature(pin_static_ref)]
#![feature(platform_intrinsics)]
#![feature(portable_simd)]
#![feature(prelude_import)]
Expand Down
19 changes: 17 additions & 2 deletions library/test/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,32 @@ impl ConsoleTestState {
exec_time: Option<&TestExecTime>,
) -> io::Result<()> {
self.write_log(|| {
let TestDesc {
name,
#[cfg(not(bootstrap))]
ignore_message,
..
} = test;
format!(
"{} {}",
match *result {
TestResult::TrOk => "ok".to_owned(),
TestResult::TrFailed => "failed".to_owned(),
TestResult::TrFailedMsg(ref msg) => format!("failed: {}", msg),
TestResult::TrIgnored => "ignored".to_owned(),
TestResult::TrIgnored => {
#[cfg(not(bootstrap))]
if let Some(msg) = ignore_message {
format!("ignored, {}", msg)
} else {
"ignored".to_owned()
}
#[cfg(bootstrap)]
"ignored".to_owned()
}
TestResult::TrBench(ref bs) => fmt_bench_samples(bs),
TestResult::TrTimedFail => "failed (time limit exceeded)".to_owned(),
},
test.name,
name,
)
})?;
if let Some(exec_time) = exec_time {
Expand Down
38 changes: 38 additions & 0 deletions library/test/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ fn one_ignored_one_unignored_test() -> Vec<TestDescAndFn> {
desc: TestDesc {
name: StaticTestName("1"),
ignore: true,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand All @@ -74,6 +76,8 @@ fn one_ignored_one_unignored_test() -> Vec<TestDescAndFn> {
desc: TestDesc {
name: StaticTestName("2"),
ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand All @@ -95,6 +99,8 @@ pub fn do_not_run_ignored_tests() {
desc: TestDesc {
name: StaticTestName("whatever"),
ignore: true,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand All @@ -117,6 +123,8 @@ pub fn ignored_tests_result_in_ignored() {
desc: TestDesc {
name: StaticTestName("whatever"),
ignore: true,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand All @@ -143,6 +151,8 @@ fn test_should_panic() {
desc: TestDesc {
name: StaticTestName("whatever"),
ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::Yes,
compile_fail: false,
no_run: false,
Expand All @@ -169,6 +179,8 @@ fn test_should_panic_good_message() {
desc: TestDesc {
name: StaticTestName("whatever"),
ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::YesWithMessage("error message"),
compile_fail: false,
no_run: false,
Expand Down Expand Up @@ -200,6 +212,8 @@ fn test_should_panic_bad_message() {
desc: TestDesc {
name: StaticTestName("whatever"),
ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::YesWithMessage(expected),
compile_fail: false,
no_run: false,
Expand Down Expand Up @@ -235,6 +249,8 @@ fn test_should_panic_non_string_message_type() {
desc: TestDesc {
name: StaticTestName("whatever"),
ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::YesWithMessage(expected),
compile_fail: false,
no_run: false,
Expand Down Expand Up @@ -262,6 +278,8 @@ fn test_should_panic_but_succeeds() {
desc: TestDesc {
name: StaticTestName("whatever"),
ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic,
compile_fail: false,
no_run: false,
Expand Down Expand Up @@ -297,6 +315,8 @@ fn report_time_test_template(report_time: bool) -> Option<TestExecTime> {
desc: TestDesc {
name: StaticTestName("whatever"),
ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand Down Expand Up @@ -333,6 +353,8 @@ fn time_test_failure_template(test_type: TestType) -> TestResult {
desc: TestDesc {
name: StaticTestName("whatever"),
ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand Down Expand Up @@ -373,6 +395,8 @@ fn typed_test_desc(test_type: TestType) -> TestDesc {
TestDesc {
name: StaticTestName("whatever"),
ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand Down Expand Up @@ -486,6 +510,8 @@ pub fn exclude_should_panic_option() {
desc: TestDesc {
name: StaticTestName("3"),
ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::Yes,
compile_fail: false,
no_run: false,
Expand All @@ -511,6 +537,8 @@ pub fn exact_filter_match() {
desc: TestDesc {
name: StaticTestName(name),
ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand Down Expand Up @@ -601,6 +629,8 @@ fn sample_tests() -> Vec<TestDescAndFn> {
desc: TestDesc {
name: DynTestName((*name).clone()),
ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand Down Expand Up @@ -753,6 +783,8 @@ pub fn test_bench_no_iter() {
let desc = TestDesc {
name: StaticTestName("f"),
ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand All @@ -776,6 +808,8 @@ pub fn test_bench_iter() {
let desc = TestDesc {
name: StaticTestName("f"),
ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand All @@ -793,6 +827,8 @@ fn should_sort_failures_before_printing_them() {
let test_a = TestDesc {
name: StaticTestName("a"),
ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand All @@ -804,6 +840,8 @@ fn should_sort_failures_before_printing_them() {
let test_b = TestDesc {
name: StaticTestName("b"),
ignore: false,
#[cfg(not(bootstrap))]
ignore_message: None,
should_panic: ShouldPanic::No,
compile_fail: false,
no_run: false,
Expand Down
Loading