Skip to content

Commit c38e1e9

Browse files
committed
Auto merge of rust-lang#2250 - rust-lang:gesundheit, r=oli-obk
Require local annotations for local diagnostics if/when we get flaky diagnostics we can revisit and add more helpers for those
2 parents 655eed3 + c4ffe68 commit c38e1e9

18 files changed

+33
-54
lines changed

tests/fail/abort-terminator.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
// error-pattern: the program aborted
21
#![feature(c_unwind)]
32

4-
extern "C" fn panic_abort() {
3+
extern "C" fn panic_abort() { //~ ERROR: the program aborted
54
panic!()
65
}
76

tests/fail/concurrency/too_few_args.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
2-
// error-pattern: callee has fewer arguments than expected
32

43
//! The thread function must have exactly one argument.
54
@@ -10,7 +9,7 @@ extern crate libc;
109
use std::{mem, ptr};
1110

1211
extern "C" fn thread_start() -> *mut libc::c_void {
13-
panic!()
12+
panic!() //~ ERROR: callee has fewer arguments than expected
1413
}
1514

1615
fn main() {

tests/fail/concurrency/too_many_args.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
2-
// error-pattern: callee has more arguments than expected
32

43
//! The thread function must have exactly one argument.
54
@@ -10,7 +9,7 @@ extern crate libc;
109
use std::{mem, ptr};
1110

1211
extern "C" fn thread_start(_null: *mut libc::c_void, _x: i32) -> *mut libc::c_void {
13-
panic!()
12+
panic!() //~ ERROR: callee has more arguments than expected
1413
}
1514

1615
fn main() {

tests/fail/concurrency/unwind_top_of_stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// ignore-windows: Concurrency on Windows is not supported yet.
22
// compile-flags: -Zmiri-disable-abi-check
3-
// error-pattern: unwinding past the topmost frame of the stack
43

54
//! Unwinding past the top frame of a stack is Undefined Behavior.
65
@@ -11,6 +10,7 @@ extern crate libc;
1110
use std::{mem, ptr};
1211

1312
extern "C-unwind" fn thread_start(_null: *mut libc::c_void) -> *mut libc::c_void {
13+
//~^ ERROR unwinding past the topmost frame of the stack
1414
panic!()
1515
}
1616

tests/fail/concurrency/unwind_top_of_stack.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error: Undefined Behavior: unwinding past the topmost frame of the stack
44
--> $DIR/unwind_top_of_stack.rs:LL:CC
55
|
66
LL | / extern "C-unwind" fn thread_start(_null: *mut libc::c_void) -> *mut libc::c_void {
7+
LL | |
78
LL | | panic!()
89
LL | | }
910
| |_^ unwinding past the topmost frame of the stack

tests/fail/intrinsics/overflowing-unchecked-rsh.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
use std::intrinsics::*;
44

5-
// error-pattern: overflowing shift by 64 in `unchecked_shr`
6-
75
fn main() {
86
unsafe {
97
let _n = unchecked_shr(1i64, 64);
8+
//~^ ERROR: overflowing shift by 64 in `unchecked_shr`
109
}
1110
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// error-pattern: attempted to instantiate uninhabited type `!`
21
#![feature(never_type)]
32

43
#[allow(deprecated, invalid_value)]
54
fn main() {
65
unsafe { std::mem::uninitialized::<!>() };
6+
//~^ ERROR: attempted to instantiate uninhabited type `!`
77
}

tests/fail/intrinsics/zero_fn_ptr.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// error-pattern: attempted to zero-initialize type `fn()`, which is invalid
2-
31
#[allow(deprecated, invalid_value)]
42
fn main() {
53
unsafe { std::mem::zeroed::<fn()>() };
4+
//~^ ERROR: attempted to zero-initialize type `fn()`, which is invalid
65
}

tests/fail/panic/bad_unwind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// error-pattern: unwinding past a stack frame that does not allow unwinding
21
#![feature(c_unwind)]
32

43
//! Unwinding when the caller ABI is "C" (without "-unwind") is UB.
@@ -11,4 +10,5 @@ fn main() {
1110
let unwind: extern "C-unwind" fn() = unwind;
1211
let unwind: extern "C" fn() = unsafe { std::mem::transmute(unwind) };
1312
std::panic::catch_unwind(|| unwind()).unwrap_err();
13+
//~^ ERROR: unwinding past a stack frame that does not allow unwinding
1414
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// ignore-windows: No libc on Windows
2-
// error-pattern: deadlock
32

43
#![feature(rustc_private)]
54

@@ -9,6 +8,6 @@ fn main() {
98
let rw = std::cell::UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER);
109
unsafe {
1110
assert_eq!(libc::pthread_rwlock_rdlock(rw.get()), 0);
12-
libc::pthread_rwlock_wrlock(rw.get());
11+
libc::pthread_rwlock_wrlock(rw.get()); //~ ERROR: deadlock
1312
}
1413
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// ignore-windows: No libc on Windows
2-
// error-pattern: deadlock
32

43
#![feature(rustc_private)]
54

@@ -9,6 +8,6 @@ fn main() {
98
let rw = std::cell::UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER);
109
unsafe {
1110
assert_eq!(libc::pthread_rwlock_wrlock(rw.get()), 0);
12-
libc::pthread_rwlock_rdlock(rw.get());
11+
libc::pthread_rwlock_rdlock(rw.get()); //~ ERROR: deadlock
1312
}
1413
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// ignore-windows: No libc on Windows
2-
// error-pattern: deadlock
32

43
#![feature(rustc_private)]
54

@@ -9,6 +8,6 @@ fn main() {
98
let rw = std::cell::UnsafeCell::new(libc::PTHREAD_RWLOCK_INITIALIZER);
109
unsafe {
1110
assert_eq!(libc::pthread_rwlock_wrlock(rw.get()), 0);
12-
libc::pthread_rwlock_wrlock(rw.get());
11+
libc::pthread_rwlock_wrlock(rw.get()); //~ ERROR: deadlock
1312
}
1413
}

tests/fail/transmute_fat1.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
// error-pattern: type validation failed: encountered a pointer
2-
// normalize-stderr-test: "\[u8; (08|16)\]" -> "$$ARRAY"
1+
#[cfg(target_pointer_width = "64")]
2+
const N: usize = 16;
3+
4+
#[cfg(target_pointer_width = "32")]
5+
const N: usize = 8;
36

47
fn main() {
5-
#[cfg(target_pointer_width = "64")]
6-
let bad = unsafe { std::mem::transmute::<&[u8], [u8; 16]>(&[1u8]) };
7-
#[cfg(target_pointer_width = "32")]
8-
let bad = unsafe { std::mem::transmute::<&[u8], [u8; 08]>(&[1u8]) };
8+
let bad = unsafe {
9+
std::mem::transmute::<&[u8], [u8; N]>(&[1u8])
10+
//~^ ERROR: type validation failed: encountered a pointer
11+
};
912
let _val = bad[0] + bad[bad.len() - 1];
1013
}

tests/fail/transmute_fat1.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: type validation failed: encountered a pointer, but expected plain (non-pointer) bytes
22
--> $DIR/transmute_fat1.rs:LL:CC
33
|
4-
LL | let bad = unsafe { std::mem::transmute::<&[u8], $ARRAY>(&[1u8]) };
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected plain (non-pointer) bytes
4+
LL | std::mem::transmute::<&[u8], [u8; N]>(&[1u8])
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer, but expected plain (non-pointer) bytes
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
// error-pattern: but alignment 4 is required
2-
// normalize-stderr-test: "\.add\(1\)" -> " "
1+
// normalize-stderr-test: "\| +\^+" -> "| ^"
32

43
fn main() {
54
// No retry needed, this fails reliably.
65

76
let mut x = [0u8; 20];
87
let x_ptr: *mut u8 = x.as_mut_ptr();
9-
// At least one of these is definitely unaligned.
8+
#[rustfmt::skip]
109
unsafe {
11-
*(x_ptr as *mut u32) = 42;
12-
*(x_ptr.add(1) as *mut u32) = 42;
13-
}
10+
// At least one of these is definitely unaligned.
11+
*(x_ptr as *mut u32) = 42; *(x_ptr.add(1) as *mut u32) = 42;
12+
//~^ ERROR: but alignment 4 is required
13+
};
1414
}

tests/fail/unaligned_pointers/alignment.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Undefined Behavior: accessing memory with alignment ALIGN, but alignment ALIGN is required
22
--> $DIR/alignment.rs:LL:CC
33
|
4-
LL | *(x_ptr as *mut u32) = 42;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
4+
LL | *(x_ptr as *mut u32) = 42; *(x_ptr.add(1) as *mut u32) = 42;
5+
| ^ accessing memory with alignment ALIGN, but alignment ALIGN is required
66
|
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

ui_test/src/lib.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,6 @@ fn check_annotations(
374374
comments: &Comments,
375375
) {
376376
if let Some((ref error_pattern, definition_line)) = comments.error_pattern {
377-
let mut found = false;
378-
379377
// first check the diagnostics messages outside of our file. We check this first, so that
380378
// you can mix in-file annotations with // error-pattern annotations, even if there is overlap
381379
// in the messages.
@@ -384,22 +382,7 @@ fn check_annotations(
384382
.position(|msg| msg.message.contains(error_pattern))
385383
{
386384
messages_from_unknown_file_or_line.remove(i);
387-
found = true;
388-
}
389-
390-
// if nothing was found, check the ones inside our file. We permit this because some tests may have
391-
// flaky line numbers for their messages.
392-
if !found {
393-
for line in &mut messages {
394-
if let Some(i) = line.iter().position(|msg| msg.message.contains(error_pattern)) {
395-
line.remove(i);
396-
found = true;
397-
break;
398-
}
399-
}
400-
}
401-
402-
if !found {
385+
} else {
403386
errors.push(Error::PatternNotFound {
404387
pattern: error_pattern.to_string(),
405388
definition_line,

ui_test/src/rustc_stderr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl Span {
116116
}
117117

118118
pub(crate) fn filter_annotations_from_rendered(rendered: &str) -> std::borrow::Cow<'_, str> {
119-
let annotations = Regex::new(r"\s*//~.*").unwrap();
119+
let annotations = Regex::new(r"\s*//(\[[^\]]\])?~.*").unwrap();
120120
annotations.replace_all(&rendered, "")
121121
}
122122

0 commit comments

Comments
 (0)