Skip to content

Commit 82d9d62

Browse files
Add test for NumBuffer compilation error
1 parent a7a14d5 commit 82d9d62

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

tests/ui/numeric/fmt.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Test to ensure that if you use a `NumBuffer` with a too small integer, it
2+
// will fail at compilation time.
3+
4+
//@ build-fail
5+
//@ ignore-pass
6+
7+
#![feature(int_format_into)]
8+
9+
use std::fmt::NumBuffer;
10+
11+
fn main() {
12+
let x = 0u32;
13+
let mut buf = NumBuffer::<u8>::new();
14+
x.format_into(&mut buf);
15+
}
16+
17+
//~? ERROR evaluation panicked

tests/ui/numeric/fmt.stderr

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0080]: evaluation panicked: buffer is not big enough
2+
--> $SRC_DIR/core/src/fmt/num.rs:LL:COL
3+
::: $SRC_DIR/core/src/fmt/num.rs:LL:COL
4+
|
5+
= note: evaluation of `core::fmt::num::imp::<impl u32>::format_into::<u8>::{constant#0}` failed here
6+
|
7+
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `impl_Display` (in Nightly builds, run with -Z macro-backtrace for more info)
8+
9+
note: erroneous constant encountered
10+
--> $SRC_DIR/core/src/fmt/num.rs:LL:COL
11+
|
12+
= note: this note originates in the macro `impl_Display` (in Nightly builds, run with -Z macro-backtrace for more info)
13+
14+
note: the above error was encountered while instantiating `fn core::fmt::num::imp::<impl u32>::format_into::<u8>`
15+
--> $DIR/fmt.rs:14:5
16+
|
17+
LL | x.format_into(&mut buf);
18+
| ^^^^^^^^^^^^^^^^^^^^^^^
19+
20+
error: aborting due to 1 previous error
21+
22+
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)