Skip to content

Commit 62b64f5

Browse files
committed
minicore: use core's diagnostic::on_unimplemented messages
1 parent f46ce66 commit 62b64f5

File tree

4 files changed

+58
-21
lines changed

4 files changed

+58
-21
lines changed

‎tests/auxiliary/minicore.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
//! # Important notes
66
//!
77
//! - `minicore` is **only** intended for `core` items, and the stubs should match the actual `core`
8-
//! items.
8+
//! items. For identical error output, any `diagnostic` attributes (e.g. `on_unimplemented`)
9+
//! should also be replicated here.
910
//! - Be careful of adding new features and things that are only available for a subset of targets.
1011
//!
1112
//! # References
@@ -41,12 +42,24 @@ macro_rules! impl_marker_trait {
4142
}
4243

4344
#[lang = "pointee_sized"]
45+
#[diagnostic::on_unimplemented(
46+
message = "values of type `{Self}` may or may not have a size",
47+
label = "may or may not have a known size"
48+
)]
4449
pub trait PointeeSized {}
4550

4651
#[lang = "meta_sized"]
52+
#[diagnostic::on_unimplemented(
53+
message = "the size for values of type `{Self}` cannot be known",
54+
label = "doesn't have a known size"
55+
)]
4756
pub trait MetaSized: PointeeSized {}
4857

4958
#[lang = "sized"]
59+
#[diagnostic::on_unimplemented(
60+
message = "the size for values of type `{Self}` cannot be known at compilation time",
61+
label = "doesn't have a size known at compile-time"
62+
)]
5063
pub trait Sized: MetaSized {}
5164

5265
#[lang = "legacy_receiver"]
@@ -64,6 +77,10 @@ pub trait BikeshedGuaranteedNoDrop {}
6477
pub unsafe auto trait Freeze {}
6578

6679
#[lang = "unpin"]
80+
#[diagnostic::on_unimplemented(
81+
note = "consider using the `pin!` macro\nconsider using `Box::pin` if you need to access the pinned value outside of the current scope",
82+
message = "`{Self}` cannot be unpinned"
83+
)]
6784
pub auto trait Unpin {}
6885

6986
impl_marker_trait!(
@@ -110,6 +127,7 @@ pub struct UnsafeCell<T: PointeeSized> {
110127
impl<T: PointeeSized> !Freeze for UnsafeCell<T> {}
111128

112129
#[lang = "tuple_trait"]
130+
#[diagnostic::on_unimplemented(message = "`{Self}` is not a tuple")]
113131
pub trait Tuple {}
114132

115133
#[rustc_builtin_macro]

‎tests/ui/abi/debug.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//@ add-core-stubs
12
//@ normalize-stderr: "(abi|pref|unadjusted_abi_align): Align\([1-8] bytes\)" -> "$1: $$SOME_ALIGN"
23
//@ normalize-stderr: "randomization_seed: \d+" -> "randomization_seed: $$SEED"
34
//@ normalize-stderr: "(size): Size\([48] bytes\)" -> "$1: $$SOME_SIZE"
@@ -9,17 +10,26 @@
910
//@ compile-flags: -O
1011
#![feature(rustc_attrs)]
1112
#![crate_type = "lib"]
13+
#![feature(no_core)]
14+
#![no_std]
15+
#![no_core]
16+
17+
extern crate minicore;
18+
use minicore::*;
1219

1320
struct S(u16);
1421

1522
#[rustc_abi(debug)]
16-
fn test(_x: u8) -> bool { true } //~ ERROR: fn_abi
23+
fn test(_x: u8) -> bool {
24+
//~^ ERROR: fn_abi
25+
true
26+
}
1727

1828
#[rustc_abi(debug)]
1929
type TestFnPtr = fn(bool) -> u8; //~ ERROR: fn_abi
2030

2131
#[rustc_abi(debug)]
22-
fn test_generic<T>(_x: *const T) { } //~ ERROR: fn_abi
32+
fn test_generic<T>(_x: *const T) {} //~ ERROR: fn_abi
2333

2434
#[rustc_abi(debug)]
2535
const C: () = (); //~ ERROR: can only be applied to
@@ -31,7 +41,7 @@ impl S {
3141

3242
impl S {
3343
#[rustc_abi(debug)]
34-
fn assoc_test(&self) { } //~ ERROR: fn_abi
44+
fn assoc_test(&self) {} //~ ERROR: fn_abi
3545
}
3646

3747
#[rustc_abi(assert_eq)]

‎tests/ui/abi/debug.stderr

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ error: fn_abi_of(test) = FnAbi {
8989
conv: Rust,
9090
can_unwind: $SOME_BOOL,
9191
}
92-
--> $DIR/debug.rs:16:1
92+
--> $DIR/debug.rs:23:1
9393
|
94-
LL | fn test(_x: u8) -> bool { true }
94+
LL | fn test(_x: u8) -> bool {
9595
| ^^^^^^^^^^^^^^^^^^^^^^^
9696

9797
error: fn_abi_of(TestFnPtr) = FnAbi {
@@ -185,7 +185,7 @@ error: fn_abi_of(TestFnPtr) = FnAbi {
185185
conv: Rust,
186186
can_unwind: $SOME_BOOL,
187187
}
188-
--> $DIR/debug.rs:19:1
188+
--> $DIR/debug.rs:29:1
189189
|
190190
LL | type TestFnPtr = fn(bool) -> u8;
191191
| ^^^^^^^^^^^^^^
@@ -263,13 +263,13 @@ error: fn_abi_of(test_generic) = FnAbi {
263263
conv: Rust,
264264
can_unwind: $SOME_BOOL,
265265
}
266-
--> $DIR/debug.rs:22:1
266+
--> $DIR/debug.rs:32:1
267267
|
268-
LL | fn test_generic<T>(_x: *const T) { }
268+
LL | fn test_generic<T>(_x: *const T) {}
269269
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
270270

271271
error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions
272-
--> $DIR/debug.rs:25:1
272+
--> $DIR/debug.rs:35:1
273273
|
274274
LL | const C: () = ();
275275
| ^^^^^^^^^^^
@@ -419,7 +419,7 @@ error: ABIs are not compatible
419419
conv: Rust,
420420
can_unwind: $SOME_BOOL,
421421
}
422-
--> $DIR/debug.rs:41:1
422+
--> $DIR/debug.rs:51:1
423423
|
424424
LL | type TestAbiNe = (fn(u8), fn(u32));
425425
| ^^^^^^^^^^^^^^
@@ -571,7 +571,7 @@ error: ABIs are not compatible
571571
conv: Rust,
572572
can_unwind: $SOME_BOOL,
573573
}
574-
--> $DIR/debug.rs:44:1
574+
--> $DIR/debug.rs:54:1
575575
|
576576
LL | type TestAbiNeLarger = (fn([u8; 32]), fn([u32; 32]));
577577
| ^^^^^^^^^^^^^^^^^^^^
@@ -720,7 +720,7 @@ error: ABIs are not compatible
720720
conv: Rust,
721721
can_unwind: $SOME_BOOL,
722722
}
723-
--> $DIR/debug.rs:47:1
723+
--> $DIR/debug.rs:57:1
724724
|
725725
LL | type TestAbiNeFloat = (fn(f32), fn(u32));
726726
| ^^^^^^^^^^^^^^^^^^^
@@ -870,13 +870,13 @@ error: ABIs are not compatible
870870
conv: Rust,
871871
can_unwind: $SOME_BOOL,
872872
}
873-
--> $DIR/debug.rs:51:1
873+
--> $DIR/debug.rs:61:1
874874
|
875875
LL | type TestAbiNeSign = (fn(i32), fn(u32));
876876
| ^^^^^^^^^^^^^^^^^^
877877

878878
error[E0277]: the size for values of type `str` cannot be known at compilation time
879-
--> $DIR/debug.rs:54:46
879+
--> $DIR/debug.rs:64:46
880880
|
881881
LL | type TestAbiEqNonsense = (fn((str, str)), fn((str, str)));
882882
| ^^^^^^^^^^ doesn't have a size known at compile-time
@@ -885,13 +885,13 @@ LL | type TestAbiEqNonsense = (fn((str, str)), fn((str, str)));
885885
= note: only the last element of a tuple may have a dynamically sized type
886886

887887
error: unrecognized argument
888-
--> $DIR/debug.rs:56:13
888+
--> $DIR/debug.rs:66:13
889889
|
890890
LL | #[rustc_abi("assert_eq")]
891891
| ^^^^^^^^^^^
892892

893893
error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions
894-
--> $DIR/debug.rs:29:5
894+
--> $DIR/debug.rs:39:5
895895
|
896896
LL | const C: () = ();
897897
| ^^^^^^^^^^^
@@ -981,9 +981,9 @@ error: fn_abi_of(assoc_test) = FnAbi {
981981
conv: Rust,
982982
can_unwind: $SOME_BOOL,
983983
}
984-
--> $DIR/debug.rs:34:5
984+
--> $DIR/debug.rs:44:5
985985
|
986-
LL | fn assoc_test(&self) { }
986+
LL | fn assoc_test(&self) {}
987987
| ^^^^^^^^^^^^^^^^^^^^
988988

989989
error: aborting due to 12 previous errors
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
//@build-pass
2-
//@compile-flags: -Clink-dead-code=true --crate-type lib
1+
//@ add-core-stubs
2+
//@ build-pass
3+
//@ compile-flags: -Clink-dead-code=true
34
// We used to not handle all "rustic" ABIs in a (relatively) uniform way,
45
// so we failed to fix up arguments for actually passing through the ABI...
56
#![feature(rust_cold_cc)]
7+
#![crate_type = "lib"]
8+
#![feature(no_core)]
9+
#![no_std]
10+
#![no_core]
11+
12+
extern crate minicore;
13+
use minicore::*;
14+
615
pub extern "rust-cold" fn foo(_: [usize; 3]) {}

0 commit comments

Comments
 (0)