Skip to content

Commit 55c398d

Browse files
committed
rollup merge of #23752: alexcrichton/remove-should-fail
This attribute has been deprecated in favor of #[should_panic]. This also updates rustdoc to no longer accept the `should_fail` directive and instead renames it to `should_panic`.
2 parents 88c3a0f + 3752958 commit 55c398d

File tree

12 files changed

+24
-33
lines changed

12 files changed

+24
-33
lines changed

src/doc/trpl/documentation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ Here’s an example of documenting a macro:
352352
/// # }
353353
/// ```
354354
///
355-
/// ```should_fail
355+
/// ```should_panic
356356
/// # #[macro_use] extern crate foo;
357357
/// # fn main() {
358358
/// panic_unless!(true == false, “I’m broken.”);

src/libcore/option.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl<T> Option<T> {
320320
/// assert_eq!(x.expect("the world is ending"), "value");
321321
/// ```
322322
///
323-
/// ```{.should_fail}
323+
/// ```{.should_panic}
324324
/// let x: Option<&str> = None;
325325
/// x.expect("the world is ending"); // panics with `world is ending`
326326
/// ```
@@ -352,7 +352,7 @@ impl<T> Option<T> {
352352
/// assert_eq!(x.unwrap(), "air");
353353
/// ```
354354
///
355-
/// ```{.should_fail}
355+
/// ```{.should_panic}
356356
/// let x: Option<&str> = None;
357357
/// assert_eq!(x.unwrap(), "air"); // fails
358358
/// ```

src/libcore/result.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ impl<T, E: fmt::Debug> Result<T, E> {
762762
/// assert_eq!(x.unwrap(), 2);
763763
/// ```
764764
///
765-
/// ```{.should_fail}
765+
/// ```{.should_panic}
766766
/// let x: Result<u32, &str> = Err("emergency failure");
767767
/// x.unwrap(); // panics with `emergency failure`
768768
/// ```
@@ -788,7 +788,7 @@ impl<T: fmt::Debug, E> Result<T, E> {
788788
///
789789
/// # Examples
790790
///
791-
/// ```{.should_fail}
791+
/// ```{.should_panic}
792792
/// let x: Result<u32, &str> = Ok(2);
793793
/// x.unwrap_err(); // panics with `2`
794794
/// ```

src/librustdoc/html/markdown.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
356356
});
357357
let text = lines.collect::<Vec<&str>>().connect("\n");
358358
tests.add_test(text.to_string(),
359-
block_info.should_fail, block_info.no_run,
359+
block_info.should_panic, block_info.no_run,
360360
block_info.ignore, block_info.test_harness);
361361
}
362362
}
@@ -397,7 +397,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
397397

398398
#[derive(Eq, PartialEq, Clone, Debug)]
399399
struct LangString {
400-
should_fail: bool,
400+
should_panic: bool,
401401
no_run: bool,
402402
ignore: bool,
403403
rust: bool,
@@ -407,7 +407,7 @@ struct LangString {
407407
impl LangString {
408408
fn all_false() -> LangString {
409409
LangString {
410-
should_fail: false,
410+
should_panic: false,
411411
no_run: false,
412412
ignore: false,
413413
rust: true, // NB This used to be `notrust = false`
@@ -427,7 +427,7 @@ impl LangString {
427427
for token in tokens {
428428
match token {
429429
"" => {},
430-
"should_fail" => { data.should_fail = true; seen_rust_tags = true; },
430+
"should_panic" => { data.should_panic = true; seen_rust_tags = true; },
431431
"no_run" => { data.no_run = true; seen_rust_tags = true; },
432432
"ignore" => { data.ignore = true; seen_rust_tags = true; },
433433
"rust" => { data.rust = true; seen_rust_tags = true; },
@@ -528,26 +528,26 @@ mod tests {
528528
#[test]
529529
fn test_lang_string_parse() {
530530
fn t(s: &str,
531-
should_fail: bool, no_run: bool, ignore: bool, rust: bool, test_harness: bool) {
531+
should_panic: bool, no_run: bool, ignore: bool, rust: bool, test_harness: bool) {
532532
assert_eq!(LangString::parse(s), LangString {
533-
should_fail: should_fail,
533+
should_panic: should_panic,
534534
no_run: no_run,
535535
ignore: ignore,
536536
rust: rust,
537537
test_harness: test_harness,
538538
})
539539
}
540540

541-
// marker | should_fail | no_run | ignore | rust | test_harness
541+
// marker | should_panic| no_run | ignore | rust | test_harness
542542
t("", false, false, false, true, false);
543543
t("rust", false, false, false, true, false);
544544
t("sh", false, false, false, false, false);
545545
t("ignore", false, false, true, true, false);
546-
t("should_fail", true, false, false, true, false);
546+
t("should_panic", true, false, false, true, false);
547547
t("no_run", false, true, false, true, false);
548548
t("test_harness", false, false, false, true, true);
549549
t("{.no_run .example}", false, true, false, true, false);
550-
t("{.sh .should_fail}", true, false, false, true, false);
550+
t("{.sh .should_panic}", true, false, false, true, false);
551551
t("{.example .rust}", false, false, false, true, false);
552552
t("{.test_harness .rust}", false, false, false, true, true);
553553
}

src/libstd/io/buffered.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ mod tests {
681681
}
682682

683683
#[test]
684-
#[should_fail]
684+
#[should_panic]
685685
fn dont_panic_in_drop_on_panicked_flush() {
686686
struct FailFlushWriter;
687687

src/libstd/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
///
2929
/// # Examples
3030
///
31-
/// ```should_fail
31+
/// ```should_panic
3232
/// # #![allow(unreachable_code)]
3333
/// panic!();
3434
/// panic!("this is a terrible mistake!");

src/libstd/old_io/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl File {
105105
///
106106
/// # Examples
107107
///
108-
/// ```rust,should_fail
108+
/// ```rust,should_panic
109109
/// # #![feature(old_io, old_path)]
110110
/// use std::old_io::*;
111111
/// use std::old_path::Path;

src/libstd/old_io/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use thread;
6060
///
6161
/// # Examples
6262
///
63-
/// ```should_fail
63+
/// ```should_panic
6464
/// # #![feature(old_io)]
6565
/// use std::old_io::*;
6666
///

src/libstd/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use thread;
3737
///
3838
/// # Examples
3939
///
40-
/// ```should_fail
40+
/// ```should_panic
4141
/// # #![feature(process)]
4242
///
4343
/// use std::process::Command;

src/libstd/thread/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,13 +870,13 @@ mod test {
870870
}
871871

872872
#[test]
873-
#[should_fail]
873+
#[should_panic]
874874
fn test_scoped_panic() {
875875
thread::scoped(|| panic!()).join();
876876
}
877877

878878
#[test]
879-
#[should_fail]
879+
#[should_panic]
880880
fn test_scoped_implicit_panic() {
881881
let _ = thread::scoped(|| panic!());
882882
}

src/libsyntax/feature_gate.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
202202
("no_mangle", Normal),
203203
("no_link", Normal),
204204
("derive", Normal),
205-
("should_fail", Normal),
206205
("should_panic", Normal),
207206
("ignore", Normal),
208207
("no_implicit_prelude", Normal),

src/libsyntax/test.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
134134
path: self.cx.path.clone(),
135135
bench: is_bench_fn(&self.cx, &*i),
136136
ignore: is_ignored(&*i),
137-
should_panic: should_panic(&*i, self.cx.span_diagnostic)
137+
should_panic: should_panic(&*i)
138138
};
139139
self.cx.testfns.push(test);
140140
self.tests.push(i.ident);
@@ -386,16 +386,8 @@ fn is_ignored(i: &ast::Item) -> bool {
386386
i.attrs.iter().any(|attr| attr.check_name("ignore"))
387387
}
388388

389-
fn should_panic(i: &ast::Item, diag: &diagnostic::SpanHandler) -> ShouldPanic {
390-
match i.attrs.iter().find(|attr| {
391-
if attr.check_name("should_panic") { return true; }
392-
if attr.check_name("should_fail") {
393-
diag.span_warn(attr.span, "`#[should_fail]` is deprecated. Use `#[should_panic]` \
394-
instead");
395-
return true;
396-
}
397-
false
398-
}) {
389+
fn should_panic(i: &ast::Item) -> ShouldPanic {
390+
match i.attrs.iter().find(|attr| attr.check_name("should_panic")) {
399391
Some(attr) => {
400392
let msg = attr.meta_item_list()
401393
.and_then(|list| list.iter().find(|mi| mi.check_name("expected")))

0 commit comments

Comments
 (0)