Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 490b1dd

Browse files
committedOct 31, 2024·
Fix minicore, add tests based off of it
1 parent 07ffa36 commit 490b1dd

File tree

6 files changed

+127
-130
lines changed

6 files changed

+127
-130
lines changed
 

‎tests/ui/traits/const-traits/effects/minicore.rs ‎tests/ui/traits/const-traits/effects/auxiliary/minicore.rs

+54-117
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
1-
//@ known-bug: #110395
2-
//@ failure-status: 101
3-
//@ normalize-stderr-test: ".*note: .*\n\n" -> ""
4-
//@ normalize-stderr-test: "thread 'rustc' panicked.*:\n.*\n" -> ""
5-
//@ rustc-env:RUST_BACKTRACE=0
6-
// FIXME(effects) check-pass
71
//@ compile-flags: -Znext-solver
82

93
#![crate_type = "lib"]
10-
#![feature(no_core, lang_items, unboxed_closures, auto_traits, intrinsics, rustc_attrs, staged_api)]
11-
#![feature(fundamental, marker_trait_attr)]
12-
#![feature(const_trait_impl, effects)]
4+
#![feature(
5+
no_core,
6+
lang_items,
7+
unboxed_closures,
8+
auto_traits,
9+
intrinsics,
10+
rustc_attrs,
11+
fundamental,
12+
marker_trait_attr,
13+
const_trait_impl,
14+
effects
15+
)]
1316
#![allow(internal_features, incomplete_features)]
1417
#![no_std]
1518
#![no_core]
16-
#![stable(feature = "minicore", since = "1.0.0")]
1719

1820
#[lang = "sized"]
19-
trait Sized {}
21+
pub trait Sized {}
2022
#[lang = "copy"]
21-
trait Copy {}
23+
pub trait Copy {}
24+
25+
impl Copy for bool {}
26+
impl Copy for u8 {}
27+
impl<T: ?Sized> Copy for &T {}
2228

2329
#[lang = "add"]
2430
#[const_trait]
25-
trait Add<Rhs = Self> {
31+
pub trait Add<Rhs = Self> {
2632
type Output;
2733

2834
fn add(self, rhs: Rhs) -> Self::Output;
@@ -43,10 +49,9 @@ const fn bar() {
4349
let x = 42_i32 + 43_i32;
4450
}
4551

46-
4752
#[lang = "Try"]
4853
#[const_trait]
49-
trait Try: FromResidual<Self::Residual> {
54+
pub trait Try: FromResidual<Self::Residual> {
5055
type Output;
5156
type Residual;
5257

@@ -57,9 +62,8 @@ trait Try: FromResidual<Self::Residual> {
5762
fn branch(self) -> ControlFlow<Self::Residual, Self::Output>;
5863
}
5964

60-
// FIXME
61-
// #[const_trait]
62-
trait FromResidual<R = <Self as /* FIXME: ~const */ Try>::Residual> {
65+
#[const_trait]
66+
pub trait FromResidual<R = <Self as Try>::Residual> {
6367
#[lang = "from_residual"]
6468
fn from_residual(residual: R) -> Self;
6569
}
@@ -74,102 +78,59 @@ enum ControlFlow<B, C = ()> {
7478
#[const_trait]
7579
#[lang = "fn"]
7680
#[rustc_paren_sugar]
77-
trait Fn<Args: Tuple>: ~const FnMut<Args> {
81+
pub trait Fn<Args: Tuple>: ~const FnMut<Args> {
7882
extern "rust-call" fn call(&self, args: Args) -> Self::Output;
7983
}
8084

8185
#[const_trait]
8286
#[lang = "fn_mut"]
8387
#[rustc_paren_sugar]
84-
trait FnMut<Args: Tuple>: ~const FnOnce<Args> {
88+
pub trait FnMut<Args: Tuple>: ~const FnOnce<Args> {
8589
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
8690
}
8791

8892
#[const_trait]
8993
#[lang = "fn_once"]
9094
#[rustc_paren_sugar]
91-
trait FnOnce<Args: Tuple> {
95+
pub trait FnOnce<Args: Tuple> {
9296
#[lang = "fn_once_output"]
9397
type Output;
9498

9599
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
96100
}
97101

98-
struct ConstFnMutClosure<CapturedData, Function> {
99-
data: CapturedData,
100-
func: Function,
101-
}
102-
103102
#[lang = "tuple_trait"]
104-
trait Tuple {}
105-
106-
macro_rules! impl_fn_mut_tuple {
107-
($($var:ident)*) => {
108-
impl<'a, $($var,)* ClosureArguments: Tuple, Function, ClosureReturnValue> const
109-
FnOnce<ClosureArguments> for ConstFnMutClosure<($(&'a mut $var),*), Function>
110-
where
111-
Function: ~const Fn(($(&mut $var),*), ClosureArguments) -> ClosureReturnValue,
112-
Function: ~const Destruct,
113-
{
114-
type Output = ClosureReturnValue;
115-
116-
extern "rust-call" fn call_once(mut self, args: ClosureArguments) -> Self::Output {
117-
self.call_mut(args)
118-
}
119-
}
120-
impl<'a, $($var,)* ClosureArguments: Tuple, Function, ClosureReturnValue> const
121-
FnMut<ClosureArguments> for ConstFnMutClosure<($(&'a mut $var),*), Function>
122-
where
123-
Function: ~const Fn(($(&mut $var),*), ClosureArguments)-> ClosureReturnValue,
124-
Function: ~const Destruct,
125-
{
126-
extern "rust-call" fn call_mut(&mut self, args: ClosureArguments) -> Self::Output {
127-
#[allow(non_snake_case)]
128-
let ($($var),*) = &mut self.data;
129-
(self.func)(($($var),*), args)
130-
}
131-
}
132-
};
133-
}
134-
//impl_fn_mut_tuple!(A);
135-
//impl_fn_mut_tuple!(A B);
136-
//impl_fn_mut_tuple!(A B C);
137-
//impl_fn_mut_tuple!(A B C D);
138-
//impl_fn_mut_tuple!(A B C D E);
103+
pub trait Tuple {}
139104

140105
#[lang = "legacy_receiver"]
141-
trait LegacyReceiver {}
106+
pub trait LegacyReceiver {}
142107

143108
impl<T: ?Sized> LegacyReceiver for &T {}
144109

145110
impl<T: ?Sized> LegacyReceiver for &mut T {}
146111

147112
#[lang = "destruct"]
148113
#[const_trait]
149-
trait Destruct {}
114+
pub trait Destruct {}
150115

151116
#[lang = "freeze"]
152-
unsafe auto trait Freeze {}
117+
pub unsafe auto trait Freeze {}
153118

154119
#[lang = "drop"]
155120
#[const_trait]
156-
trait Drop {
121+
pub trait Drop {
157122
fn drop(&mut self);
158123
}
159124

160-
/*
161125
#[const_trait]
162-
trait Residual<O> {
126+
pub trait Residual<O> {
163127
type TryType: ~const Try<Output = O, Residual = Self> + Try<Output = O, Residual = Self>;
164128
}
165-
*/
166129

167130
const fn size_of<T>() -> usize {
168131
42
169132
}
170133

171-
impl Copy for u8 {}
172-
173134
impl usize {
174135
#[rustc_allow_incoherent_impl]
175136
const fn repeat_u8(x: u8) -> usize {
@@ -190,15 +151,14 @@ fn panic_fmt() {}
190151

191152
#[lang = "index"]
192153
#[const_trait]
193-
trait Index<Idx: ?Sized> {
154+
pub trait Index<Idx: ?Sized> {
194155
type Output: ?Sized;
195156

196157
fn index(&self, index: Idx) -> &Self::Output;
197158
}
198159

199-
200160
#[const_trait]
201-
unsafe trait SliceIndex<T: ?Sized> {
161+
pub unsafe trait SliceIndex<T: ?Sized> {
202162
type Output: ?Sized;
203163
fn index(self, slice: &T) -> &Self::Output;
204164
}
@@ -214,51 +174,45 @@ where
214174
index.index(self)
215175
}
216176
}
217-
/* FIXME
177+
218178
impl<T, I, const N: usize> const Index<I> for [T; N]
219179
where
220180
[T]: ~const Index<I>,
221181
{
222182
type Output = <[T] as Index<I>>::Output;
223183

224184
#[inline]
225-
// FIXME: make `Self::Output` act like `<Self as ~const Index<I>>::Output`
226185
fn index(&self, index: I) -> &<[T] as Index<I>>::Output {
227186
Index::index(self as &[T], index)
228187
}
229188
}
230-
*/
231189

232190
#[lang = "unsize"]
233-
trait Unsize<T: ?Sized> {
234-
}
191+
pub trait Unsize<T: ?Sized> {}
235192

236193
#[lang = "coerce_unsized"]
237-
trait CoerceUnsized<T: ?Sized> {
238-
}
194+
pub trait CoerceUnsized<T: ?Sized> {}
239195

240196
impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
241197

242-
243198
#[lang = "deref"]
244-
// #[const_trait] FIXME
245-
trait Deref {
199+
#[const_trait]
200+
pub trait Deref {
246201
#[lang = "deref_target"]
247202
type Target: ?Sized;
248203

249204
fn deref(&self) -> &Self::Target;
250205
}
251206

252-
253-
impl<T: ?Sized> /* const */ Deref for &T {
207+
impl<T: ?Sized> const Deref for &T {
254208
type Target = T;
255209

256210
fn deref(&self) -> &T {
257211
*self
258212
}
259213
}
260214

261-
impl<T: ?Sized> /* const */ Deref for &mut T {
215+
impl<T: ?Sized> const Deref for &mut T {
262216
type Target = T;
263217

264218
fn deref(&self) -> &T {
@@ -291,7 +245,6 @@ impl<T> Option<T> {
291245

292246
use Option::*;
293247

294-
/*
295248
const fn as_deref<T>(opt: &Option<T>) -> Option<&T::Target>
296249
where
297250
T: ~const Deref,
@@ -301,15 +254,14 @@ where
301254
Option::None => Option::None,
302255
}
303256
}
304-
*/
305257

306258
#[const_trait]
307-
trait Into<T>: Sized {
259+
pub trait Into<T>: Sized {
308260
fn into(self) -> T;
309261
}
310262

311263
#[const_trait]
312-
trait From<T>: Sized {
264+
pub trait From<T>: Sized {
313265
fn from(value: T) -> Self;
314266
}
315267

@@ -344,7 +296,7 @@ fn from_str(s: &str) -> Result<bool, ()> {
344296

345297
#[lang = "eq"]
346298
#[const_trait]
347-
trait PartialEq<Rhs: ?Sized = Self> {
299+
pub trait PartialEq<Rhs: ?Sized = Self> {
348300
fn eq(&self, other: &Rhs) -> bool;
349301
fn ne(&self, other: &Rhs) -> bool {
350302
!self.eq(other)
@@ -366,10 +318,9 @@ impl PartialEq for str {
366318
}
367319
}
368320

369-
370321
#[lang = "not"]
371322
#[const_trait]
372-
trait Not {
323+
pub trait Not {
373324
type Output;
374325
fn not(self) -> Self::Output;
375326
}
@@ -381,9 +332,6 @@ impl const Not for bool {
381332
}
382333
}
383334

384-
impl Copy for bool {}
385-
impl<'a> Copy for &'a str {}
386-
387335
#[lang = "pin"]
388336
#[fundamental]
389337
#[repr(transparent)]
@@ -404,23 +352,21 @@ impl<'a, T: ?Sized> Pin<&'a T> {
404352
}
405353
}
406354

407-
408355
impl<P: Deref> Pin<P> {
409-
/* const */ fn as_ref(&self) -> Pin<&P::Target>
356+
const fn as_ref(&self) -> Pin<&P::Target>
410357
where
411-
P: /* ~const */ Deref,
358+
P: ~const Deref,
412359
{
413360
unsafe { Pin::new_unchecked(&*self.pointer) }
414361
}
415362
}
416363

417-
418364
impl<'a, T: ?Sized> Pin<&'a mut T> {
419365
const unsafe fn get_unchecked_mut(self) -> &'a mut T {
420366
self.pointer
421367
}
422368
}
423-
/* FIXME lol
369+
424370
impl<T> Option<T> {
425371
const fn as_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>> {
426372
match Pin::get_ref(self).as_ref() {
@@ -438,16 +384,15 @@ impl<T> Option<T> {
438384
}
439385
}
440386
}
441-
*/
442387

443-
impl<P: /* ~const */ Deref> /* const */ Deref for Pin<P> {
388+
impl<P: ~const Deref> const Deref for Pin<P> {
444389
type Target = P::Target;
445390
fn deref(&self) -> &P::Target {
446391
Pin::get_ref(Pin::as_ref(self))
447392
}
448393
}
449394

450-
impl<T> /* const */ Deref for Option<T> {
395+
impl<T> const Deref for Option<T> {
451396
type Target = T;
452397
fn deref(&self) -> &T {
453398
loop {}
@@ -499,23 +444,22 @@ impl<T: ?Sized> Deref for Ref<'_, T> {
499444

500445
#[lang = "clone"]
501446
#[rustc_trivial_field_reads]
502-
#[const_trait]
503-
trait Clone: Sized {
447+
// FIXME: #[const_trait]
448+
pub trait Clone: Sized {
504449
fn clone(&self) -> Self;
505450
fn clone_from(&mut self, source: &Self)
506451
where
507-
Self: ~const Destruct,
452+
// FIXME: Self: ~const Destruct,
508453
{
509454
*self = source.clone()
510455
}
511456
}
512457

513458
#[lang = "structural_peq"]
514-
trait StructuralPartialEq {}
459+
pub trait StructuralPartialEq {}
515460

516-
const fn drop<T: ~const Destruct>(_: T) {}
461+
// FIXME: const fn drop<T: ~const Destruct>(_: T) {}
517462

518-
#[rustc_const_stable_indirect]
519463
#[rustc_intrinsic_must_be_overridden]
520464
#[rustc_intrinsic]
521465
const fn const_eval_select<ARG: Tuple, F, G, RET>(
@@ -529,10 +473,3 @@ where
529473
{
530474
loop {}
531475
}
532-
533-
fn test_const_eval_select() {
534-
const fn const_fn() {}
535-
fn rt_fn() {}
536-
537-
const_eval_select((), const_fn, rt_fn);
538-
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ aux-build:minicore.rs
2+
//@ compile-flags: --crate-type=lib -Znext-solver
3+
4+
#![feature(no_core, const_trait_impl, effects)]
5+
//~^ WARN the feature `effects` is incomplete
6+
#![no_std]
7+
#![no_core]
8+
9+
extern crate minicore;
10+
use minicore::*;
11+
12+
struct Ty;
13+
impl Deref for Ty {
14+
type Target = ();
15+
fn deref(&self) -> &Self::Target { &() }
16+
}
17+
18+
const fn foo() {
19+
*Ty;
20+
//~^ ERROR the trait bound `Ty: ~const minicore::Deref` is not satisfied
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/minicore-deref-fail.rs:4:39
3+
|
4+
LL | #![feature(no_core, const_trait_impl, effects)]
5+
| ^^^^^^^
6+
|
7+
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error[E0277]: the trait bound `Ty: ~const minicore::Deref` is not satisfied
11+
--> $DIR/minicore-deref-fail.rs:19:5
12+
|
13+
LL | *Ty;
14+
| ^^^
15+
16+
error: aborting due to 1 previous error; 1 warning emitted
17+
18+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ aux-build:minicore.rs
2+
//@ compile-flags: --crate-type=lib -Znext-solver
3+
//@ check-pass
4+
5+
#![feature(no_core)]
6+
#![no_std]
7+
#![no_core]
8+
#![feature(const_trait_impl, effects)]
9+
//~^ WARN the feature `effects` is incomplete and may not be safe
10+
11+
extern crate minicore;
12+
use minicore::*;
13+
14+
struct Custom;
15+
impl const Add for Custom {
16+
type Output = ();
17+
fn add(self, _other: Self) {}
18+
}
19+
20+
const fn test_op() {
21+
let _x = Add::add(1, 2);
22+
let _y = Custom + Custom;
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/minicore-works.rs:8:30
3+
|
4+
LL | #![feature(const_trait_impl, effects)]
5+
| ^^^^^^^
6+
|
7+
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+

‎tests/ui/traits/const-traits/effects/minicore.stderr

-13
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.