diff options
Diffstat (limited to 'tests/ui/rfcs/rfc-2632-const-trait-impl/effects')
7 files changed, 54 insertions, 101 deletions
diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/const-bound-on-not-const-associated-fn.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/const-bound-on-not-const-associated-fn.rs deleted file mode 100644 index 1e22ddcea..000000000 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/const-bound-on-not-const-associated-fn.rs +++ /dev/null @@ -1,28 +0,0 @@ -#![feature(const_trait_impl, effects)] - -#[const_trait] -trait MyTrait { - fn do_something(&self); -} - -trait OtherTrait { - fn do_something_else() where Self: ~const MyTrait; - //~^ ERROR `~const` is not allowed here -} - -struct MyStruct<T>(T); - -impl const MyTrait for u32 { - fn do_something(&self) {} -} - -impl<T> MyStruct<T> { - pub fn foo(&self) where T: ~const MyTrait { - //~^ ERROR `~const` is not allowed here - self.0.do_something(); - } -} - -fn main() { - MyStruct(0u32).foo(); -} diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/const-bound-on-not-const-associated-fn.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/const-bound-on-not-const-associated-fn.stderr deleted file mode 100644 index 9210f6427..000000000 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/const-bound-on-not-const-associated-fn.stderr +++ /dev/null @@ -1,26 +0,0 @@ -error: `~const` is not allowed here - --> $DIR/const-bound-on-not-const-associated-fn.rs:9:40 - | -LL | fn do_something_else() where Self: ~const MyTrait; - | ^^^^^^^^^^^^^^ - | -note: this function is not `const`, so it cannot have `~const` trait bounds - --> $DIR/const-bound-on-not-const-associated-fn.rs:9:8 - | -LL | fn do_something_else() where Self: ~const MyTrait; - | ^^^^^^^^^^^^^^^^^ - -error: `~const` is not allowed here - --> $DIR/const-bound-on-not-const-associated-fn.rs:20:32 - | -LL | pub fn foo(&self) where T: ~const MyTrait { - | ^^^^^^^^^^^^^^ - | -note: this function is not `const`, so it cannot have `~const` trait bounds - --> $DIR/const-bound-on-not-const-associated-fn.rs:20:12 - | -LL | pub fn foo(&self) where T: ~const MyTrait { - | ^^^ - -error: aborting due to 2 previous errors - diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/const_closure-const_trait_impl-ice-113381.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/const_closure-const_trait_impl-ice-113381.stderr index 002d586ac..413e21702 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/const_closure-const_trait_impl-ice-113381.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/const_closure-const_trait_impl-ice-113381.stderr @@ -6,6 +6,6 @@ LL | (const || { (()).foo() })(); | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -error: aborting due to previous error +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0015`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/effect-param-infer.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/effect-param-infer.rs new file mode 100644 index 000000000..e216f6879 --- /dev/null +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/effect-param-infer.rs @@ -0,0 +1,15 @@ +// Ensure that we don't get a mismatch error when inserting the host param +// at the end of generic args when the generics have defaulted params. +// +// check-pass + +#![feature(const_trait_impl, effects)] + +#[const_trait] +pub trait Foo<Rhs: ?Sized = Self> { + /* stuff */ +} + +impl const Foo for () {} + +fn main() {} diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/helloworld.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/helloworld.rs index e7ba0505d..17f203e15 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/helloworld.rs +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/helloworld.rs @@ -3,15 +3,16 @@ // gate-test-effects // ^ effects doesn't have a gate so we will trick tidy into thinking this is a gate test -#![feature(const_trait_impl, effects, rustc_attrs)] +#![feature(const_trait_impl, effects, core_intrinsics, const_eval_select)] // ensure we are passing in the correct host effect in always const contexts. -pub const fn hmm<T, #[rustc_host] const host: bool = true>() -> usize { - if host { - 1 - } else { - 0 +pub const fn hmm<T>() -> usize { + // FIXME(const_trait_impl): maybe we should have a way to refer to the (hidden) effect param + fn one() -> usize { 1 } + const fn zero() -> usize { 0 } + unsafe { + std::intrinsics::const_eval_select((), zero, one) } } diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.rs index c38b4b3f1..59fb48e79 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.rs +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.rs @@ -1,12 +1,13 @@ +// check-pass + #![crate_type = "lib"] -#![feature(no_core, lang_items, unboxed_closures, auto_traits, intrinsics, rustc_attrs)] +#![feature(no_core, lang_items, unboxed_closures, auto_traits, intrinsics, rustc_attrs, staged_api)] #![feature(fundamental)] #![feature(const_trait_impl, effects, const_mut_refs)] #![allow(internal_features)] #![no_std] #![no_core] - -// known-bug: #110395 +#![stable(feature = "minicore", since = "1.0.0")] #[lang = "sized"] trait Sized {} @@ -21,8 +22,7 @@ trait Add<Rhs = Self> { fn add(self, rhs: Rhs) -> Self::Output; } -// FIXME we shouldn't need to have to specify `Rhs`. -impl const Add<i32> for i32 { +impl const Add for i32 { type Output = i32; fn add(self, rhs: i32) -> i32 { loop {} @@ -83,6 +83,7 @@ trait FnMut<Args: Tuple>: ~const FnOnce<Args> { #[lang = "fn_once"] #[rustc_paren_sugar] trait FnOnce<Args: Tuple> { + #[lang = "fn_once_output"] type Output; extern "rust-call" fn call_once(self, args: Args) -> Self::Output; @@ -94,7 +95,7 @@ struct ConstFnMutClosure<CapturedData, Function> { } #[lang = "tuple_trait"] -pub trait Tuple {} +trait Tuple {} macro_rules! impl_fn_mut_tuple { ($($var:ident)*) => { @@ -344,8 +345,16 @@ trait PartialEq<Rhs: ?Sized = Self> { } } -// FIXME(effects): again, this should not error without Rhs specified -impl PartialEq<str> for str { +impl<A: ?Sized, B: ?Sized> const PartialEq<&B> for &A +where + A: ~const PartialEq<B>, +{ + fn eq(&self, other: &&B) -> bool { + PartialEq::eq(*self, *other) + } +} + +impl PartialEq for str { fn eq(&self, other: &str) -> bool { loop {} } @@ -502,3 +511,17 @@ trait StructuralPartialEq {} trait StructuralEq {} const fn drop<T: ~const Destruct>(_: T) {} + +extern "rust-intrinsic" { + #[rustc_const_stable(feature = "const_eval_select", since = "1.0.0")] + fn const_eval_select<ARG: Tuple, F, G, RET>( + arg: ARG, + called_in_const: F, + called_at_rt: G, + ) -> RET + /* where clauses enforced by built-in method confirmation: + where + F: const FnOnce<Arg, Output = RET>, + G: FnOnce<Arg, Output = RET>, + */; +} diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.stderr deleted file mode 100644 index 024293742..000000000 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.stderr +++ /dev/null @@ -1,32 +0,0 @@ -error[E0369]: cannot add `i32` to `i32` - --> $DIR/minicore.rs:33:20 - | -LL | let x = 42_i32 + 43_i32; - | ------ ^ ------ i32 - | | - | i32 - -error[E0369]: cannot add `i32` to `i32` - --> $DIR/minicore.rs:37:20 - | -LL | let x = 42_i32 + 43_i32; - | ------ ^ ------ i32 - | | - | i32 - -error[E0600]: cannot apply unary operator `!` to type `bool` - --> $DIR/minicore.rs:343:9 - | -LL | !self.eq(other) - | ^^^^^^^^^^^^^^^ cannot apply unary operator `!` - -error[E0600]: cannot apply unary operator `!` to type `bool` - --> $DIR/minicore.rs:365:9 - | -LL | !self - | ^^^^^ cannot apply unary operator `!` - -error: aborting due to 4 previous errors - -Some errors have detailed explanations: E0369, E0600. -For more information about an error, try `rustc --explain E0369`. |