From ef24de24a82fe681581cc130f342363c47c0969a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 7 Jun 2024 07:48:48 +0200 Subject: Merging upstream version 1.75.0+dfsg1. Signed-off-by: Daniel Baumann --- .../assoc-type-const-bound-usage.stderr | 14 +- .../rfc-2632-const-trait-impl/const-impl-trait.rs | 1 - .../const-impl-trait.stderr | 10 +- ...default-method-body-is-const-with-staged-api.rs | 2 +- .../effects/auxiliary/cross-crate.rs | 12 + .../const-bound-on-not-const-associated-fn.rs | 28 ++ .../const-bound-on-not-const-associated-fn.stderr | 26 ++ .../const_closure-const_trait_impl-ice-113381.rs | 15 + ...onst_closure-const_trait_impl-ice-113381.stderr | 11 + .../ice-113375-index-out-of-bounds-generics.rs | 18 + .../rfc-2632-const-trait-impl/effects/minicore.rs | 504 +++++++++++++++++++++ .../effects/minicore.stderr | 32 ++ .../no-explicit-const-params-cross-crate.rs | 18 + .../no-explicit-const-params-cross-crate.stderr | 59 +++ .../effects/no-explicit-const-params.rs | 27 ++ .../effects/no-explicit-const-params.stderr | 69 +++ .../rfc-2632-const-trait-impl/effects/project.rs | 11 + .../rfc-2632-const-trait-impl/issue-102156.stderr | 1 + .../super-traits-fail-2.nn.stderr | 2 + .../super-traits-fail-2.ny.stderr | 2 + .../super-traits-fail-3.nn.stderr | 2 + .../super-traits-fail-3.ny.stderr | 2 + .../tilde-const-and-const-params.rs | 9 +- .../tilde-const-and-const-params.stderr | 20 +- .../trait-where-clause-const.stderr | 34 +- .../trait-where-clause.rs | 2 + .../trait-where-clause.stderr | 32 +- 27 files changed, 912 insertions(+), 51 deletions(-) create mode 100644 tests/ui/rfcs/rfc-2632-const-trait-impl/effects/auxiliary/cross-crate.rs create mode 100644 tests/ui/rfcs/rfc-2632-const-trait-impl/effects/const-bound-on-not-const-associated-fn.rs create mode 100644 tests/ui/rfcs/rfc-2632-const-trait-impl/effects/const-bound-on-not-const-associated-fn.stderr create mode 100644 tests/ui/rfcs/rfc-2632-const-trait-impl/effects/const_closure-const_trait_impl-ice-113381.rs create mode 100644 tests/ui/rfcs/rfc-2632-const-trait-impl/effects/const_closure-const_trait_impl-ice-113381.stderr create mode 100644 tests/ui/rfcs/rfc-2632-const-trait-impl/effects/ice-113375-index-out-of-bounds-generics.rs create mode 100644 tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.rs create mode 100644 tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.stderr create mode 100644 tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params-cross-crate.rs create mode 100644 tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params-cross-crate.stderr create mode 100644 tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params.rs create mode 100644 tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params.stderr create mode 100644 tests/ui/rfcs/rfc-2632-const-trait-impl/effects/project.rs (limited to 'tests/ui/rfcs/rfc-2632-const-trait-impl') diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/assoc-type-const-bound-usage.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/assoc-type-const-bound-usage.stderr index ad11c090f..6d436018b 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/assoc-type-const-bound-usage.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/assoc-type-const-bound-usage.stderr @@ -1,14 +1,12 @@ -error[E0277]: the trait bound `T: Foo` is not satisfied - --> $DIR/assoc-type-const-bound-usage.rs:12:6 +error[E0308]: mismatched types + --> $DIR/assoc-type-const-bound-usage.rs:12:5 | LL | ::Assoc::foo(); - | ^ the trait `Foo` is not implemented for `T` + | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `host`, found `true` | -help: consider further restricting this bound - | -LL | const fn foo() { - | +++++ + = note: expected constant `host` + found constant `true` error: aborting due to previous error -For more information about this error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.rs index f396deff4..8e4de57b0 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.rs +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.rs @@ -4,7 +4,6 @@ associated_type_bounds, const_trait_impl, const_cmp, - return_position_impl_trait_in_trait, )] use std::marker::Destruct; diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.stderr index f9078e227..4a9090d0b 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.stderr @@ -5,31 +5,31 @@ LL | const_cmp, | ^^^^^^^^^ error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/const-impl-trait.rs:12:30 + --> $DIR/const-impl-trait.rs:11:30 | LL | const fn cmp(a: &impl ~const PartialEq) -> bool { | ^^^^^^^^^ error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/const-impl-trait.rs:16:30 + --> $DIR/const-impl-trait.rs:15:30 | LL | const fn wrap(x: impl ~const PartialEq + ~const Destruct) | ^^^^^^^^^ error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/const-impl-trait.rs:17:20 + --> $DIR/const-impl-trait.rs:16:20 | LL | -> impl ~const PartialEq + ~const Destruct | ^^^^^^^^^ error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/const-impl-trait.rs:24:29 + --> $DIR/const-impl-trait.rs:23:29 | LL | fn huh() -> impl ~const PartialEq + ~const Destruct + Copy; | ^^^^^^^^^ error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/const-impl-trait.rs:28:29 + --> $DIR/const-impl-trait.rs:27:29 | LL | fn huh() -> impl ~const PartialEq + ~const Destruct + Copy { | ^^^^^^^^^ diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/default-method-body-is-const-with-staged-api.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/default-method-body-is-const-with-staged-api.rs index 1b45cd9aa..13881e042 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/default-method-body-is-const-with-staged-api.rs +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/default-method-body-is-const-with-staged-api.rs @@ -7,7 +7,7 @@ #![feature(staged_api)] #![feature(const_trait_impl)] -#![stable(since = "1", feature = "foo")] +#![stable(feature = "foo", since = "3.3.3")] #[const_trait] trait Tr { diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/auxiliary/cross-crate.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/auxiliary/cross-crate.rs new file mode 100644 index 000000000..a74c50cc8 --- /dev/null +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/auxiliary/cross-crate.rs @@ -0,0 +1,12 @@ +#![feature(const_trait_impl, effects)] + +pub const fn foo() {} + +#[const_trait] +pub trait Bar { + fn bar(); +} + +impl Bar for () { + fn bar() {} +} 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 new file mode 100644 index 000000000..1e22ddcea --- /dev/null +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/const-bound-on-not-const-associated-fn.rs @@ -0,0 +1,28 @@ +#![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); + +impl const MyTrait for u32 { + fn do_something(&self) {} +} + +impl MyStruct { + 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 new file mode 100644 index 000000000..9210f6427 --- /dev/null +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/const-bound-on-not-const-associated-fn.stderr @@ -0,0 +1,26 @@ +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.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/const_closure-const_trait_impl-ice-113381.rs new file mode 100644 index 000000000..6598d1da0 --- /dev/null +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/const_closure-const_trait_impl-ice-113381.rs @@ -0,0 +1,15 @@ +#![feature(const_closures, const_trait_impl, effects)] +#![allow(incomplete_features)] + +trait Foo { + fn foo(&self); +} + +impl Foo for () { + fn foo(&self) {} +} + +fn main() { + (const || { (()).foo() })(); + //~^ ERROR: cannot call non-const fn +} 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 new file mode 100644 index 000000000..002d586ac --- /dev/null +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/const_closure-const_trait_impl-ice-113381.stderr @@ -0,0 +1,11 @@ +error[E0015]: cannot call non-const fn `<() as Foo>::foo` in constant functions + --> $DIR/const_closure-const_trait_impl-ice-113381.rs:13:22 + | +LL | (const || { (()).foo() })(); + | ^^^^^ + | + = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0015`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/ice-113375-index-out-of-bounds-generics.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/ice-113375-index-out-of-bounds-generics.rs new file mode 100644 index 000000000..1954d2942 --- /dev/null +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/ice-113375-index-out-of-bounds-generics.rs @@ -0,0 +1,18 @@ +// check-pass + +// effects ice https://github.com/rust-lang/rust/issues/113375 index out of bounds + +#![allow(incomplete_features, unused)] +#![feature(effects, adt_const_params)] + +struct Bar(T); + +impl Bar { + const fn value() -> usize { + 42 + } +} + +struct Foo::value()]>; + +pub fn main() {} 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 new file mode 100644 index 000000000..c38b4b3f1 --- /dev/null +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.rs @@ -0,0 +1,504 @@ +#![crate_type = "lib"] +#![feature(no_core, lang_items, unboxed_closures, auto_traits, intrinsics, rustc_attrs)] +#![feature(fundamental)] +#![feature(const_trait_impl, effects, const_mut_refs)] +#![allow(internal_features)] +#![no_std] +#![no_core] + +// known-bug: #110395 + +#[lang = "sized"] +trait Sized {} +#[lang = "copy"] +trait Copy {} + +#[lang = "add"] +#[const_trait] +trait Add { + type Output; + + fn add(self, rhs: Rhs) -> Self::Output; +} + +// FIXME we shouldn't need to have to specify `Rhs`. +impl const Add for i32 { + type Output = i32; + fn add(self, rhs: i32) -> i32 { + loop {} + } +} + +fn foo() { + let x = 42_i32 + 43_i32; +} + +const fn bar() { + let x = 42_i32 + 43_i32; +} + + +#[lang = "Try"] +#[const_trait] +trait Try: FromResidual { + type Output; + type Residual; + + #[lang = "from_output"] + fn from_output(output: Self::Output) -> Self; + + #[lang = "branch"] + fn branch(self) -> ControlFlow; +} + +// FIXME +// #[const_trait] +trait FromResidual::Residual> { + #[lang = "from_residual"] + fn from_residual(residual: R) -> Self; +} + +enum ControlFlow { + #[lang = "Continue"] + Continue(C), + #[lang = "Break"] + Break(B), +} + +#[const_trait] +#[lang = "fn"] +#[rustc_paren_sugar] +trait Fn: ~const FnMut { + extern "rust-call" fn call(&self, args: Args) -> Self::Output; +} + +#[const_trait] +#[lang = "fn_mut"] +#[rustc_paren_sugar] +trait FnMut: ~const FnOnce { + extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output; +} + +#[const_trait] +#[lang = "fn_once"] +#[rustc_paren_sugar] +trait FnOnce { + type Output; + + extern "rust-call" fn call_once(self, args: Args) -> Self::Output; +} + +struct ConstFnMutClosure { + data: CapturedData, + func: Function, +} + +#[lang = "tuple_trait"] +pub trait Tuple {} + +macro_rules! impl_fn_mut_tuple { + ($($var:ident)*) => { + impl<'a, $($var,)* ClosureArguments: Tuple, Function, ClosureReturnValue> const + FnOnce for ConstFnMutClosure<($(&'a mut $var),*), Function> + where + Function: ~const Fn(($(&mut $var),*), ClosureArguments) -> ClosureReturnValue, + Function: ~const Destruct, + { + type Output = ClosureReturnValue; + + extern "rust-call" fn call_once(mut self, args: ClosureArguments) -> Self::Output { + self.call_mut(args) + } + } + impl<'a, $($var,)* ClosureArguments: Tuple, Function, ClosureReturnValue> const + FnMut for ConstFnMutClosure<($(&'a mut $var),*), Function> + where + Function: ~const Fn(($(&mut $var),*), ClosureArguments)-> ClosureReturnValue, + Function: ~const Destruct, + { + extern "rust-call" fn call_mut(&mut self, args: ClosureArguments) -> Self::Output { + #[allow(non_snake_case)] + let ($($var),*) = &mut self.data; + (self.func)(($($var),*), args) + } + } + }; +} +//impl_fn_mut_tuple!(A); +//impl_fn_mut_tuple!(A B); +//impl_fn_mut_tuple!(A B C); +//impl_fn_mut_tuple!(A B C D); +//impl_fn_mut_tuple!(A B C D E); + +#[lang = "receiver"] +trait Receiver {} + +impl Receiver for &T {} + +impl Receiver for &mut T {} + +#[lang = "destruct"] +#[const_trait] +trait Destruct {} + +#[lang = "freeze"] +unsafe auto trait Freeze {} + +#[lang = "drop"] +#[const_trait] +trait Drop { + fn drop(&mut self); +} + +/* +#[const_trait] +trait Residual { + type TryType: ~const Try + Try; +} +*/ + +const fn size_of() -> usize { + 42 +} + +impl Copy for u8 {} + +impl usize { + #[rustc_allow_incoherent_impl] + const fn repeat_u8(x: u8) -> usize { + usize::from_ne_bytes([x; size_of::()]) + } + #[rustc_allow_incoherent_impl] + const fn from_ne_bytes(bytes: [u8; size_of::()]) -> Self { + loop {} + } +} + +#[rustc_do_not_const_check] // hooked by const-eval +const fn panic_display() { + panic_fmt(); +} + +fn panic_fmt() {} + +#[lang = "index"] +#[const_trait] +trait Index { + type Output: ?Sized; + + fn index(&self, index: Idx) -> &Self::Output; +} + + +#[const_trait] +unsafe trait SliceIndex { + type Output: ?Sized; + fn index(self, slice: &T) -> &Self::Output; +} + +impl const Index for [T] +where + I: ~const SliceIndex<[T]>, +{ + type Output = I::Output; + + #[inline] + fn index(&self, index: I) -> &I::Output { + index.index(self) + } +} +/* FIXME +impl const Index for [T; N] +where + [T]: ~const Index, +{ + type Output = <[T] as Index>::Output; + + #[inline] + // FIXME: make `Self::Output` act like `>::Output` + fn index(&self, index: I) -> &<[T] as Index>::Output { + Index::index(self as &[T], index) + } +} +*/ + +#[lang = "unsize"] +trait Unsize { +} + +#[lang = "coerce_unsized"] +trait CoerceUnsized { +} + +impl<'a, 'b: 'a, T: ?Sized + Unsize, U: ?Sized> CoerceUnsized<&'a U> for &'b T {} + + +#[lang = "deref"] +// #[const_trait] FIXME +trait Deref { + #[lang = "deref_target"] + type Target: ?Sized; + + fn deref(&self) -> &Self::Target; +} + + +impl /* const */ Deref for &T { + type Target = T; + + fn deref(&self) -> &T { + *self + } +} + +impl /* const */ Deref for &mut T { + type Target = T; + + fn deref(&self) -> &T { + *self + } +} + +enum Option { + #[lang = "None"] + None, + #[lang = "Some"] + Some(T), +} + +impl Option { + const fn as_ref(&self) -> Option<&T> { + match *self { + Some(ref x) => Some(x), + None => None, + } + } + + const fn as_mut(&mut self) -> Option<&mut T> { + match *self { + Some(ref mut x) => Some(x), + None => None, + } + } +} + +use Option::*; + +/* +const fn as_deref(opt: &Option) -> Option<&T::Target> +where + T: ~const Deref, +{ + match opt { + Option::Some(t) => Option::Some(t.deref()), + Option::None => Option::None, + } +} +*/ + +#[const_trait] +trait Into: Sized { + fn into(self) -> T; +} + +#[const_trait] +trait From: Sized { + fn from(value: T) -> Self; +} + +impl const Into for T +where + U: ~const From, +{ + fn into(self) -> U { + U::from(self) + } +} + +impl const From for T { + fn from(t: T) -> T { + t + } +} + +enum Result { + Ok(T), + Err(E), +} +use Result::*; + +fn from_str(s: &str) -> Result { + match s { + "true" => Ok(true), + "false" => Ok(false), + _ => Err(()), + } +} + +#[lang = "eq"] +#[const_trait] +trait PartialEq { + fn eq(&self, other: &Rhs) -> bool; + fn ne(&self, other: &Rhs) -> bool { + !self.eq(other) + } +} + +// FIXME(effects): again, this should not error without Rhs specified +impl PartialEq for str { + fn eq(&self, other: &str) -> bool { + loop {} + } +} + + +#[lang = "not"] +#[const_trait] +trait Not { + type Output; + fn not(self) -> Self::Output; +} + +impl const Not for bool { + type Output = bool; + fn not(self) -> bool { + !self + } +} + +impl Copy for bool {} +impl<'a> Copy for &'a str {} + +#[lang = "pin"] +#[fundamental] +#[repr(transparent)] +struct Pin

{ + pointer: P, +} + +impl

Pin

{ + #[lang = "new_unchecked"] + const unsafe fn new_unchecked(pointer: P) -> Pin

{ + Pin { pointer } + } +} + +impl<'a, T: ?Sized> Pin<&'a T> { + const fn get_ref(self) -> &'a T { + self.pointer + } +} + + +impl Pin

{ + /* const */ fn as_ref(&self) -> Pin<&P::Target> + where + P: /* ~const */ Deref, + { + unsafe { Pin::new_unchecked(&*self.pointer) } + } +} + + +impl<'a, T: ?Sized> Pin<&'a mut T> { + const unsafe fn get_unchecked_mut(self) -> &'a mut T { + self.pointer + } +} +/* FIXME lol +impl Option { + const fn as_pin_ref(self: Pin<&Self>) -> Option> { + match Pin::get_ref(self).as_ref() { + Some(x) => unsafe { Some(Pin::new_unchecked(x)) }, + None => None, + } + } + + const fn as_pin_mut(self: Pin<&mut Self>) -> Option> { + unsafe { + match Pin::get_unchecked_mut(self).as_mut() { + Some(x) => Some(Pin::new_unchecked(x)), + None => None, + } + } + } +} +*/ + +impl /* const */ Deref for Pin

{ + type Target = P::Target; + fn deref(&self) -> &P::Target { + Pin::get_ref(Pin::as_ref(self)) + } +} + +impl /* const */ Deref for Option { + type Target = T; + fn deref(&self) -> &T { + loop {} + } +} + +impl Receiver for Pin

{} + +impl Clone for RefCell { + fn clone(&self) -> RefCell { + RefCell::new(self.borrow().clone()) + } +} + +struct RefCell { + borrow: UnsafeCell<()>, + value: UnsafeCell, +} +impl RefCell { + const fn new(value: T) -> RefCell { + loop {} + } +} +impl RefCell { + fn borrow(&self) -> Ref<'_, T> { + loop {} + } +} + +#[lang = "unsafe_cell"] +#[repr(transparent)] +struct UnsafeCell { + value: T, +} + +struct Ref<'b, T: ?Sized + 'b> { + value: *const T, + borrow: &'b UnsafeCell<()>, +} + +impl Deref for Ref<'_, T> { + type Target = T; + + #[inline] + fn deref(&self) -> &T { + loop {} + } +} + +#[lang = "clone"] +#[rustc_trivial_field_reads] +#[const_trait] +trait Clone: Sized { + fn clone(&self) -> Self; + fn clone_from(&mut self, source: &Self) + where + Self: ~const Destruct, + { + *self = source.clone() + } +} + +#[lang = "structural_peq"] +trait StructuralPartialEq {} + +#[lang = "structural_teq"] +trait StructuralEq {} + +const fn drop(_: T) {} 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 new file mode 100644 index 000000000..024293742 --- /dev/null +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/minicore.stderr @@ -0,0 +1,32 @@ +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`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params-cross-crate.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params-cross-crate.rs new file mode 100644 index 000000000..8e4850197 --- /dev/null +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params-cross-crate.rs @@ -0,0 +1,18 @@ +// aux-build: cross-crate.rs +extern crate cross_crate; + +use cross_crate::{Bar, foo}; + +fn main() { + foo::(); + //~^ ERROR: function takes 0 generic arguments but 1 generic argument was supplied + <() as Bar>::bar(); + //~^ ERROR: trait takes 0 generic arguments but 1 generic argument was supplied +} + +const FOO: () = { + foo::(); + //~^ ERROR: function takes 0 generic arguments but 1 generic argument was supplied + <() as Bar>::bar(); + //~^ ERROR: trait takes 0 generic arguments but 1 generic argument was supplied +}; diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params-cross-crate.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params-cross-crate.stderr new file mode 100644 index 000000000..cc870ad33 --- /dev/null +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params-cross-crate.stderr @@ -0,0 +1,59 @@ +error[E0107]: function takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/no-explicit-const-params-cross-crate.rs:14:5 + | +LL | foo::(); + | ^^^--------- help: remove these generics + | | + | expected 0 generic arguments + | +note: function defined here, with 0 generic parameters + --> $DIR/auxiliary/cross-crate.rs:3:14 + | +LL | pub const fn foo() {} + | ^^^ + +error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/no-explicit-const-params-cross-crate.rs:16:12 + | +LL | <() as Bar>::bar(); + | ^^^------- help: remove these generics + | | + | expected 0 generic arguments + | +note: trait defined here, with 0 generic parameters + --> $DIR/auxiliary/cross-crate.rs:6:11 + | +LL | pub trait Bar { + | ^^^ + +error[E0107]: function takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/no-explicit-const-params-cross-crate.rs:7:5 + | +LL | foo::(); + | ^^^-------- help: remove these generics + | | + | expected 0 generic arguments + | +note: function defined here, with 0 generic parameters + --> $DIR/auxiliary/cross-crate.rs:3:14 + | +LL | pub const fn foo() {} + | ^^^ + +error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/no-explicit-const-params-cross-crate.rs:9:12 + | +LL | <() as Bar>::bar(); + | ^^^------ help: remove these generics + | | + | expected 0 generic arguments + | +note: trait defined here, with 0 generic parameters + --> $DIR/auxiliary/cross-crate.rs:6:11 + | +LL | pub trait Bar { + | ^^^ + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0107`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params.rs new file mode 100644 index 000000000..929da1ca8 --- /dev/null +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params.rs @@ -0,0 +1,27 @@ +#![feature(const_trait_impl, effects)] + +const fn foo() {} + +#[const_trait] +trait Bar { + fn bar(); +} + +impl Bar for () { + fn bar() {} +} + +fn main() { + foo::(); + //~^ ERROR: function takes 0 generic arguments but 1 generic argument was supplied + <() as Bar>::bar(); + //~^ ERROR: trait takes 0 generic arguments but 1 generic argument was supplied +} + +const FOO: () = { + foo::(); + //~^ ERROR: function takes 0 generic arguments but 1 generic argument was supplied + <() as Bar>::bar(); + //~^ ERROR: trait takes 0 generic arguments but 1 generic argument was supplied + //~| ERROR: mismatched types +}; diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params.stderr new file mode 100644 index 000000000..0745d0304 --- /dev/null +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/no-explicit-const-params.stderr @@ -0,0 +1,69 @@ +error[E0107]: function takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/no-explicit-const-params.rs:22:5 + | +LL | foo::(); + | ^^^--------- help: remove these generics + | | + | expected 0 generic arguments + | +note: function defined here, with 0 generic parameters + --> $DIR/no-explicit-const-params.rs:3:10 + | +LL | const fn foo() {} + | ^^^ + +error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/no-explicit-const-params.rs:24:12 + | +LL | <() as Bar>::bar(); + | ^^^------- help: remove these generics + | | + | expected 0 generic arguments + | +note: trait defined here, with 0 generic parameters + --> $DIR/no-explicit-const-params.rs:6:7 + | +LL | trait Bar { + | ^^^ + +error[E0308]: mismatched types + --> $DIR/no-explicit-const-params.rs:24:5 + | +LL | <() as Bar>::bar(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `false`, found `true` + | + = note: expected constant `false` + found constant `true` + +error[E0107]: function takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/no-explicit-const-params.rs:15:5 + | +LL | foo::(); + | ^^^-------- help: remove these generics + | | + | expected 0 generic arguments + | +note: function defined here, with 0 generic parameters + --> $DIR/no-explicit-const-params.rs:3:10 + | +LL | const fn foo() {} + | ^^^ + +error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/no-explicit-const-params.rs:17:12 + | +LL | <() as Bar>::bar(); + | ^^^------ help: remove these generics + | | + | expected 0 generic arguments + | +note: trait defined here, with 0 generic parameters + --> $DIR/no-explicit-const-params.rs:6:7 + | +LL | trait Bar { + | ^^^ + +error: aborting due to 5 previous errors + +Some errors have detailed explanations: E0107, E0308. +For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/project.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/project.rs new file mode 100644 index 000000000..b30d7743e --- /dev/null +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/project.rs @@ -0,0 +1,11 @@ +// check-pass +#![feature(const_trait_impl, effects)] + +pub trait Owo::T> {} + +#[const_trait] +pub trait Uwu: Owo { + type T; +} + +fn main() {} diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-102156.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-102156.stderr index 8bf00eaff..e8ae7e4e3 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-102156.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/issue-102156.stderr @@ -13,6 +13,7 @@ LL | use core::convert::{From, TryFrom}; | ^^^^ maybe a missing crate `core`? | = help: consider adding `extern crate core` to use the `core` crate + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: aborting due to 2 previous errors diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits-fail-2.nn.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits-fail-2.nn.stderr index 97f346e8c..b60399c57 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits-fail-2.nn.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits-fail-2.nn.stderr @@ -9,6 +9,8 @@ error: ~const can only be applied to `#[const_trait]` traits | LL | trait Bar: ~const Foo {} | ^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: aborting due to 2 previous errors diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits-fail-2.ny.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits-fail-2.ny.stderr index 97f346e8c..b60399c57 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits-fail-2.ny.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits-fail-2.ny.stderr @@ -9,6 +9,8 @@ error: ~const can only be applied to `#[const_trait]` traits | LL | trait Bar: ~const Foo {} | ^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: aborting due to 2 previous errors diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits-fail-3.nn.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits-fail-3.nn.stderr index 2897eabb0..eb12a236d 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits-fail-3.nn.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits-fail-3.nn.stderr @@ -9,6 +9,8 @@ error: ~const can only be applied to `#[const_trait]` traits | LL | trait Bar: ~const Foo {} | ^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: ~const can only be applied to `#[const_trait]` traits --> $DIR/super-traits-fail-3.rs:17:24 diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits-fail-3.ny.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits-fail-3.ny.stderr index 9839a4f24..cd0ee7327 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits-fail-3.ny.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/super-traits-fail-3.ny.stderr @@ -9,6 +9,8 @@ error: ~const can only be applied to `#[const_trait]` traits | LL | trait Bar: ~const Foo {} | ^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error: aborting due to 2 previous errors diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-and-const-params.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-and-const-params.rs index 89d74cecf..4b720b534 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-and-const-params.rs +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-and-const-params.rs @@ -7,7 +7,8 @@ struct Foo; impl Foo { fn add(self) -> Foo<{ A::add(N) }> { - //~^ ERROR mismatched types + //~^ ERROR `~const` is not allowed here + //~| ERROR mismatched types Foo } } @@ -30,7 +31,7 @@ fn bar(_: Foo) -> Foo<{ A::add(N) }> { } fn main() { - let foo = Foo::<0>; - let foo = bar::<(), _>(foo); - let _foo = bar::<(), _>(foo); + let foo = Foo::<0>; + let foo = bar::<(), _>(foo); + let _foo = bar::<(), _>(foo); } diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-and-const-params.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-and-const-params.stderr index ec5d21d33..be7a83dc1 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-and-const-params.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/tilde-const-and-const-params.stderr @@ -1,17 +1,29 @@ error: `~const` is not allowed here - --> $DIR/tilde-const-and-const-params.rs:26:11 + --> $DIR/tilde-const-and-const-params.rs:9:15 + | +LL | fn add(self) -> Foo<{ A::add(N) }> { + | ^^^^^^^^^^^^ + | +note: this function is not `const`, so it cannot have `~const` trait bounds + --> $DIR/tilde-const-and-const-params.rs:9:8 + | +LL | fn add(self) -> Foo<{ A::add(N) }> { + | ^^^ + +error: `~const` is not allowed here + --> $DIR/tilde-const-and-const-params.rs:27:11 | LL | fn bar(_: Foo) -> Foo<{ A::add(N) }> { | ^^^^^^^^^^^^ | note: this function is not `const`, so it cannot have `~const` trait bounds - --> $DIR/tilde-const-and-const-params.rs:26:4 + --> $DIR/tilde-const-and-const-params.rs:27:4 | LL | fn bar(_: Foo) -> Foo<{ A::add(N) }> { | ^^^ error[E0308]: mismatched types - --> $DIR/tilde-const-and-const-params.rs:26:61 + --> $DIR/tilde-const-and-const-params.rs:27:61 | LL | fn bar(_: Foo) -> Foo<{ A::add(N) }> { | ^^^^^^^^^ expected `false`, found `true` @@ -28,6 +40,6 @@ LL | fn add(self) -> Foo<{ A::add(N) }> { = note: expected constant `false` found constant `true` -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/trait-where-clause-const.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/trait-where-clause-const.stderr index c94563d35..2a9647da7 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/trait-where-clause-const.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/trait-where-clause-const.stderr @@ -1,35 +1,21 @@ -error[E0277]: the trait bound `T: ~const Bar` is not satisfied +error[E0308]: mismatched types --> $DIR/trait-where-clause-const.rs:21:5 | LL | T::b(); - | ^ the trait `Bar` is not implemented for `T` + | ^^^^^^ expected `host`, found `true` | -note: required by a bound in `Foo::b` - --> $DIR/trait-where-clause-const.rs:15:24 - | -LL | fn b() where Self: ~const Bar; - | ^^^^^^^^^^ required by this bound in `Foo::b` -help: consider further restricting this bound - | -LL | const fn test1() { - | +++++ + = note: expected constant `host` + found constant `true` -error[E0277]: the trait bound `T: ~const Bar` is not satisfied - --> $DIR/trait-where-clause-const.rs:23:12 +error[E0308]: mismatched types + --> $DIR/trait-where-clause-const.rs:23:5 | LL | T::c::(); - | ^ the trait `Bar` is not implemented for `T` - | -note: required by a bound in `Foo::c` - --> $DIR/trait-where-clause-const.rs:16:13 - | -LL | fn c(); - | ^^^^^^^^^^ required by this bound in `Foo::c` -help: consider further restricting this bound + | ^^^^^^^^^^^ expected `host`, found `true` | -LL | const fn test1() { - | +++++ + = note: expected constant `host` + found constant `true` error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/trait-where-clause.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/trait-where-clause.rs index 85ca5fc90..11f353f3f 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/trait-where-clause.rs +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/trait-where-clause.rs @@ -6,7 +6,9 @@ trait Bar {} trait Foo { fn a(); fn b() where Self: ~const Bar; + //~^ ERROR `~const` is not allowed here fn c(); + //~^ ERROR `~const` is not allowed here } fn test1() { diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/trait-where-clause.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/trait-where-clause.stderr index 255878e17..3d6fedbab 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/trait-where-clause.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/trait-where-clause.stderr @@ -1,5 +1,29 @@ +error: `~const` is not allowed here + --> $DIR/trait-where-clause.rs:8:24 + | +LL | fn b() where Self: ~const Bar; + | ^^^^^^^^^^ + | +note: this function is not `const`, so it cannot have `~const` trait bounds + --> $DIR/trait-where-clause.rs:8:8 + | +LL | fn b() where Self: ~const Bar; + | ^ + +error: `~const` is not allowed here + --> $DIR/trait-where-clause.rs:10:13 + | +LL | fn c(); + | ^^^^^^^^^^ + | +note: this function is not `const`, so it cannot have `~const` trait bounds + --> $DIR/trait-where-clause.rs:10:8 + | +LL | fn c(); + | ^ + error[E0277]: the trait bound `T: Bar` is not satisfied - --> $DIR/trait-where-clause.rs:14:5 + --> $DIR/trait-where-clause.rs:16:5 | LL | T::b(); | ^ the trait `Bar` is not implemented for `T` @@ -15,13 +39,13 @@ LL | fn test1() { | +++++ error[E0277]: the trait bound `T: Bar` is not satisfied - --> $DIR/trait-where-clause.rs:16:12 + --> $DIR/trait-where-clause.rs:18:12 | LL | T::c::(); | ^ the trait `Bar` is not implemented for `T` | note: required by a bound in `Foo::c` - --> $DIR/trait-where-clause.rs:9:13 + --> $DIR/trait-where-clause.rs:10:13 | LL | fn c(); | ^^^^^^^^^^ required by this bound in `Foo::c` @@ -30,6 +54,6 @@ help: consider further restricting this bound LL | fn test1() { | +++++ -error: aborting due to 2 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0277`. -- cgit v1.2.3