Rollup merge of #102647 - oli-obk:tilde_const_bounds, r=fee1-dead
Only allow ~const bounds for traits with #[const_trait] r? `@fee1-dead`
This commit is contained in:
commit
f55fef165e
35 changed files with 217 additions and 119 deletions
|
@ -191,32 +191,6 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> {
|
|||
self.tcx.hir()
|
||||
}
|
||||
|
||||
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
|
||||
let tcx = self.tcx;
|
||||
if let hir::ItemKind::Impl(hir::Impl {
|
||||
constness: hir::Constness::Const,
|
||||
of_trait: Some(trait_ref),
|
||||
..
|
||||
}) = item.kind
|
||||
&& let Some(def_id) = trait_ref.trait_def_id()
|
||||
{
|
||||
let source_map = tcx.sess.source_map();
|
||||
if !tcx.has_attr(def_id, sym::const_trait) {
|
||||
tcx.sess
|
||||
.struct_span_err(
|
||||
source_map.guess_head_span(item.span),
|
||||
"const `impl`s must be for traits marked with `#[const_trait]`",
|
||||
)
|
||||
.span_note(
|
||||
source_map.guess_head_span(tcx.def_span(def_id)),
|
||||
"this trait must be annotated with `#[const_trait]`",
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
intravisit::walk_item(self, item);
|
||||
}
|
||||
|
||||
fn visit_anon_const(&mut self, anon: &'tcx hir::AnonConst) {
|
||||
let kind = Some(hir::ConstContext::Const);
|
||||
self.recurse_into(kind, None, |this| intravisit::walk_anon_const(this, anon));
|
||||
|
|
|
@ -308,6 +308,32 @@ impl<'tcx> WfPredicates<'tcx> {
|
|||
let obligations = if trait_pred.constness == ty::BoundConstness::NotConst {
|
||||
self.nominal_obligations_without_const(trait_ref.def_id, trait_ref.substs)
|
||||
} else {
|
||||
if !tcx.has_attr(trait_ref.def_id, rustc_span::sym::const_trait) {
|
||||
if let Some(item) = self.item &&
|
||||
let hir::ItemKind::Impl(impl_) = item.kind &&
|
||||
let Some(trait_) = &impl_.of_trait &&
|
||||
let Some(def_id) = trait_.trait_def_id() &&
|
||||
def_id == trait_ref.def_id
|
||||
{
|
||||
let trait_name = tcx.item_name(def_id);
|
||||
let mut err = tcx.sess.struct_span_err(
|
||||
self.span,
|
||||
&format!("const `impl` for trait `{trait_name}` which is not marked with `#[const_trait]`"),
|
||||
);
|
||||
if def_id.is_local() {
|
||||
let sp = tcx.def_span(def_id).shrink_to_lo();
|
||||
err.span_suggestion(sp, &format!("mark `{trait_name}` as const"), "#[const_trait]", rustc_errors::Applicability::MachineApplicable);
|
||||
}
|
||||
err.note("marking a trait with `#[const_trait]` ensures all default method bodies are `const`");
|
||||
err.note("adding a non-const method body in the future would be a breaking change");
|
||||
err.emit();
|
||||
} else {
|
||||
tcx.sess.span_err(
|
||||
self.span,
|
||||
"~const can only be applied to `#[const_trait]` traits",
|
||||
);
|
||||
}
|
||||
}
|
||||
self.nominal_obligations(trait_ref.def_id, trait_ref.substs)
|
||||
};
|
||||
|
||||
|
|
|
@ -264,7 +264,7 @@ pub trait IntoIterator {
|
|||
|
||||
#[rustc_const_unstable(feature = "const_intoiterator_identity", issue = "90603")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<I: ~const Iterator> const IntoIterator for I {
|
||||
impl<I: Iterator> const IntoIterator for I {
|
||||
type Item = I::Item;
|
||||
type IntoIter = I;
|
||||
|
||||
|
|
|
@ -799,6 +799,7 @@ impl<T: ?Sized> Unpin for *mut T {}
|
|||
#[unstable(feature = "const_trait_impl", issue = "67792")]
|
||||
#[lang = "destruct"]
|
||||
#[rustc_on_unimplemented(message = "can't drop `{Self}`", append_const_msg)]
|
||||
#[const_trait]
|
||||
pub trait Destruct {}
|
||||
|
||||
/// A marker for tuple types.
|
||||
|
|
|
@ -22,8 +22,8 @@ LL | for i in 0..x {
|
|||
note: impl defined here, but it is not `const`
|
||||
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
|
||||
|
|
||||
LL | impl<I: ~const Iterator> const IntoIterator for I {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | impl<I: Iterator> const IntoIterator for I {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||
|
||||
error[E0658]: mutable references are not allowed in constant functions
|
||||
|
|
|
@ -7,8 +7,8 @@ LL | for _ in 0..5 {}
|
|||
note: impl defined here, but it is not `const`
|
||||
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
|
||||
|
|
||||
LL | impl<I: ~const Iterator> const IntoIterator for I {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | impl<I: Iterator> const IntoIterator for I {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
|
||||
|
||||
error[E0015]: cannot call non-const fn `<std::ops::Range<i32> as Iterator>::next` in constants
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#![feature(const_trait_impl, generic_const_exprs)]
|
||||
|
||||
#[const_trait]
|
||||
pub trait Tr {
|
||||
fn a() -> usize;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ LL | #![feature(const_trait_impl, generic_const_exprs)]
|
|||
= note: `#[warn(incomplete_features)]` on by default
|
||||
|
||||
error[E0080]: evaluation of `foo::<()>::{constant#0}` failed
|
||||
--> $DIR/constifconst-call-in-const-position.rs:15:38
|
||||
--> $DIR/constifconst-call-in-const-position.rs:16:38
|
||||
|
|
||||
LL | const fn foo<T: ~const Tr>() -> [u8; T::a()] {
|
||||
| ^^^^^^ calling non-const function `<() as Tr>::a`
|
||||
|
|
|
@ -47,8 +47,8 @@ LL | [(); { for _ in 0usize.. {}; 0}];
|
|||
note: impl defined here, but it is not `const`
|
||||
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
|
||||
|
|
||||
LL | impl<I: ~const Iterator> const IntoIterator for I {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | impl<I: Iterator> const IntoIterator for I {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
|
||||
|
||||
error[E0658]: mutable references are not allowed in constants
|
||||
|
|
|
@ -2,13 +2,18 @@
|
|||
|
||||
struct S;
|
||||
|
||||
impl PartialEq for S {
|
||||
#[const_trait]
|
||||
trait Foo {
|
||||
fn eq(&self, _: &Self) -> bool;
|
||||
}
|
||||
|
||||
impl Foo for S {
|
||||
fn eq(&self, _: &S) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
const fn equals_self<T: ~const PartialEq>(t: &T) -> bool {
|
||||
const fn equals_self<T: ~const Foo>(t: &T) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
|
|
|
@ -1,26 +1,21 @@
|
|||
error[E0277]: can't compare `S` with `S` in const contexts
|
||||
--> $DIR/call-generic-method-nonconst.rs:18:34
|
||||
error[E0277]: the trait bound `S: ~const Foo` is not satisfied
|
||||
--> $DIR/call-generic-method-nonconst.rs:23:34
|
||||
|
|
||||
LL | pub const EQ: bool = equals_self(&S);
|
||||
| ----------- ^^ no implementation for `S == S`
|
||||
| ----------- ^^ the trait `~const Foo` is not implemented for `S`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
|
|
||||
= help: the trait `~const PartialEq` is not implemented for `S`
|
||||
note: the trait `PartialEq` is implemented for `S`, but that implementation is not `const`
|
||||
--> $DIR/call-generic-method-nonconst.rs:18:34
|
||||
note: the trait `Foo` is implemented for `S`, but that implementation is not `const`
|
||||
--> $DIR/call-generic-method-nonconst.rs:23:34
|
||||
|
|
||||
LL | pub const EQ: bool = equals_self(&S);
|
||||
| ^^
|
||||
note: required by a bound in `equals_self`
|
||||
--> $DIR/call-generic-method-nonconst.rs:11:25
|
||||
|
|
||||
LL | const fn equals_self<T: ~const PartialEq>(t: &T) -> bool {
|
||||
| ^^^^^^^^^^^^^^^^ required by this bound in `equals_self`
|
||||
help: consider annotating `S` with `#[derive(PartialEq)]`
|
||||
|
|
||||
LL | #[derive(PartialEq)]
|
||||
--> $DIR/call-generic-method-nonconst.rs:16:25
|
||||
|
|
||||
LL | const fn equals_self<T: ~const Foo>(t: &T) -> bool {
|
||||
| ^^^^^^^^^^ required by this bound in `equals_self`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error[E0277]: can't drop `NonTrivialDrop` in const contexts
|
||||
--> $DIR/const-drop-fail.rs:43:5
|
||||
--> $DIR/const-drop-fail.rs:44:5
|
||||
|
|
||||
LL | const _: () = check($exp);
|
||||
| ----- required by a bound introduced by this call
|
||||
|
@ -9,7 +9,7 @@ LL | NonTrivialDrop,
|
|||
|
|
||||
= note: the trait bound `NonTrivialDrop: ~const Destruct` is not satisfied
|
||||
note: required by a bound in `check`
|
||||
--> $DIR/const-drop-fail.rs:34:19
|
||||
--> $DIR/const-drop-fail.rs:35:19
|
||||
|
|
||||
LL | const fn check<T: ~const Destruct>(_: T) {}
|
||||
| ^^^^^^^^^^^^^^^ required by this bound in `check`
|
||||
|
@ -21,7 +21,7 @@ LL | &mut NonTrivialDrop,
|
|||
| ++++
|
||||
|
||||
error[E0277]: can't drop `NonTrivialDrop` in const contexts
|
||||
--> $DIR/const-drop-fail.rs:45:5
|
||||
--> $DIR/const-drop-fail.rs:46:5
|
||||
|
|
||||
LL | const _: () = check($exp);
|
||||
| ----- required by a bound introduced by this call
|
||||
|
@ -30,7 +30,7 @@ LL | ConstImplWithDropGlue(NonTrivialDrop),
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `ConstImplWithDropGlue`, the trait `~const Destruct` is not implemented for `NonTrivialDrop`
|
||||
|
|
||||
note: the trait `Destruct` is implemented for `NonTrivialDrop`, but that implementation is not `const`
|
||||
--> $DIR/const-drop-fail.rs:45:5
|
||||
--> $DIR/const-drop-fail.rs:46:5
|
||||
|
|
||||
LL | ConstImplWithDropGlue(NonTrivialDrop),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -40,13 +40,13 @@ note: required because it appears within the type `ConstImplWithDropGlue`
|
|||
LL | struct ConstImplWithDropGlue(NonTrivialDrop);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
note: required by a bound in `check`
|
||||
--> $DIR/const-drop-fail.rs:34:19
|
||||
--> $DIR/const-drop-fail.rs:35:19
|
||||
|
|
||||
LL | const fn check<T: ~const Destruct>(_: T) {}
|
||||
| ^^^^^^^^^^^^^^^ required by this bound in `check`
|
||||
|
||||
error[E0277]: the trait bound `ConstDropImplWithBounds<NonTrivialDrop>: ~const Destruct` is not satisfied
|
||||
--> $DIR/const-drop-fail.rs:47:5
|
||||
--> $DIR/const-drop-fail.rs:48:5
|
||||
|
|
||||
LL | const _: () = check($exp);
|
||||
| ----- required by a bound introduced by this call
|
||||
|
@ -55,14 +55,14 @@ LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `~const Destruct` is not implemented for `ConstDropImplWithBounds<NonTrivialDrop>`
|
||||
|
|
||||
note: required for `ConstDropImplWithBounds<NonTrivialDrop>` to implement `~const Destruct`
|
||||
--> $DIR/const-drop-fail.rs:28:25
|
||||
--> $DIR/const-drop-fail.rs:29:25
|
||||
|
|
||||
LL | impl<T: ~const A> const Drop for ConstDropImplWithBounds<T> {
|
||||
| ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: 1 redundant requirement hidden
|
||||
= note: required for `ConstDropImplWithBounds<NonTrivialDrop>` to implement `~const Destruct`
|
||||
note: required by a bound in `check`
|
||||
--> $DIR/const-drop-fail.rs:34:19
|
||||
--> $DIR/const-drop-fail.rs:35:19
|
||||
|
|
||||
LL | const fn check<T: ~const Destruct>(_: T) {}
|
||||
| ^^^^^^^^^^^^^^^ required by this bound in `check`
|
||||
|
|
|
@ -19,7 +19,8 @@ impl const Drop for ConstImplWithDropGlue {
|
|||
fn drop(&mut self) {}
|
||||
}
|
||||
|
||||
trait A { fn a() { println!("A"); } }
|
||||
#[const_trait]
|
||||
trait A { fn a() { } }
|
||||
|
||||
impl A for NonTrivialDrop {}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error[E0277]: can't drop `NonTrivialDrop` in const contexts
|
||||
--> $DIR/const-drop-fail.rs:43:5
|
||||
--> $DIR/const-drop-fail.rs:44:5
|
||||
|
|
||||
LL | const _: () = check($exp);
|
||||
| ----- required by a bound introduced by this call
|
||||
|
@ -9,7 +9,7 @@ LL | NonTrivialDrop,
|
|||
|
|
||||
= note: the trait bound `NonTrivialDrop: ~const Destruct` is not satisfied
|
||||
note: required by a bound in `check`
|
||||
--> $DIR/const-drop-fail.rs:34:19
|
||||
--> $DIR/const-drop-fail.rs:35:19
|
||||
|
|
||||
LL | const fn check<T: ~const Destruct>(_: T) {}
|
||||
| ^^^^^^^^^^^^^^^ required by this bound in `check`
|
||||
|
@ -21,7 +21,7 @@ LL | &mut NonTrivialDrop,
|
|||
| ++++
|
||||
|
||||
error[E0277]: can't drop `NonTrivialDrop` in const contexts
|
||||
--> $DIR/const-drop-fail.rs:45:5
|
||||
--> $DIR/const-drop-fail.rs:46:5
|
||||
|
|
||||
LL | const _: () = check($exp);
|
||||
| ----- required by a bound introduced by this call
|
||||
|
@ -30,7 +30,7 @@ LL | ConstImplWithDropGlue(NonTrivialDrop),
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `ConstImplWithDropGlue`, the trait `~const Destruct` is not implemented for `NonTrivialDrop`
|
||||
|
|
||||
note: the trait `Destruct` is implemented for `NonTrivialDrop`, but that implementation is not `const`
|
||||
--> $DIR/const-drop-fail.rs:45:5
|
||||
--> $DIR/const-drop-fail.rs:46:5
|
||||
|
|
||||
LL | ConstImplWithDropGlue(NonTrivialDrop),
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -40,13 +40,13 @@ note: required because it appears within the type `ConstImplWithDropGlue`
|
|||
LL | struct ConstImplWithDropGlue(NonTrivialDrop);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
note: required by a bound in `check`
|
||||
--> $DIR/const-drop-fail.rs:34:19
|
||||
--> $DIR/const-drop-fail.rs:35:19
|
||||
|
|
||||
LL | const fn check<T: ~const Destruct>(_: T) {}
|
||||
| ^^^^^^^^^^^^^^^ required by this bound in `check`
|
||||
|
||||
error[E0277]: the trait bound `ConstDropImplWithBounds<NonTrivialDrop>: ~const Destruct` is not satisfied
|
||||
--> $DIR/const-drop-fail.rs:47:5
|
||||
--> $DIR/const-drop-fail.rs:48:5
|
||||
|
|
||||
LL | const _: () = check($exp);
|
||||
| ----- required by a bound introduced by this call
|
||||
|
@ -55,14 +55,14 @@ LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `~const Destruct` is not implemented for `ConstDropImplWithBounds<NonTrivialDrop>`
|
||||
|
|
||||
note: required for `ConstDropImplWithBounds<NonTrivialDrop>` to implement `~const Destruct`
|
||||
--> $DIR/const-drop-fail.rs:28:25
|
||||
--> $DIR/const-drop-fail.rs:29:25
|
||||
|
|
||||
LL | impl<T: ~const A> const Drop for ConstDropImplWithBounds<T> {
|
||||
| ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: 1 redundant requirement hidden
|
||||
= note: required for `ConstDropImplWithBounds<NonTrivialDrop>` to implement `~const Destruct`
|
||||
note: required by a bound in `check`
|
||||
--> $DIR/const-drop-fail.rs:34:19
|
||||
--> $DIR/const-drop-fail.rs:35:19
|
||||
|
|
||||
LL | const fn check<T: ~const Destruct>(_: T) {}
|
||||
| ^^^^^^^^^^^^^^^ required by this bound in `check`
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#![feature(const_trait_impl)]
|
||||
|
||||
pub trait A {}
|
||||
//~^ NOTE: this trait must be annotated with `#[const_trait]`
|
||||
//~^ HELP: mark `A` as const
|
||||
|
||||
impl const A for () {}
|
||||
//~^ ERROR: const `impl`s must be for traits marked with `#[const_trait]`
|
||||
//~^ ERROR: const `impl` for trait `A` which is not marked with `#[const_trait]`
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
error: const `impl`s must be for traits marked with `#[const_trait]`
|
||||
--> $DIR/const-impl-requires-const-trait.rs:6:1
|
||||
|
|
||||
LL | impl const A for () {}
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: this trait must be annotated with `#[const_trait]`
|
||||
--> $DIR/const-impl-requires-const-trait.rs:3:1
|
||||
error: const `impl` for trait `A` which is not marked with `#[const_trait]`
|
||||
--> $DIR/const-impl-requires-const-trait.rs:6:12
|
||||
|
|
||||
LL | pub trait A {}
|
||||
| ^^^^^^^^^^^
|
||||
| - help: mark `A` as const: `#[const_trait]`
|
||||
...
|
||||
LL | impl const A for () {}
|
||||
| ^
|
||||
|
|
||||
= note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
|
||||
= note: adding a non-const method body in the future would be a breaking change
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#![feature(const_trait_impl)]
|
||||
|
||||
#[const_trait]
|
||||
trait Tr {}
|
||||
impl Tr for () {}
|
||||
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
error[E0277]: the trait bound `(): ~const Tr` is not satisfied
|
||||
--> $DIR/default-method-body-is-const-body-checking.rs:11:15
|
||||
--> $DIR/default-method-body-is-const-body-checking.rs:12:15
|
||||
|
|
||||
LL | foo::<()>();
|
||||
| ^^ the trait `~const Tr` is not implemented for `()`
|
||||
|
|
||||
note: the trait `Tr` is implemented for `()`, but that implementation is not `const`
|
||||
--> $DIR/default-method-body-is-const-body-checking.rs:11:15
|
||||
--> $DIR/default-method-body-is-const-body-checking.rs:12:15
|
||||
|
|
||||
LL | foo::<()>();
|
||||
| ^^
|
||||
note: required by a bound in `foo`
|
||||
--> $DIR/default-method-body-is-const-body-checking.rs:6:28
|
||||
--> $DIR/default-method-body-is-const-body-checking.rs:7:28
|
||||
|
|
||||
LL | const fn foo<T>() where T: ~const Tr {}
|
||||
| ^^^^^^^^^ required by this bound in `foo`
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/super-traits-fail-2.rs:11:12
|
||||
|
|
||||
LL | trait Bar: ~const Foo {}
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/super-traits-fail-2.rs:11:12
|
||||
|
|
||||
LL | trait Bar: ~const Foo {}
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
|
@ -1,14 +1,19 @@
|
|||
#![feature(const_trait_impl)]
|
||||
|
||||
// revisions: yy yn ny nn
|
||||
|
||||
#[cfg_attr(any(yy, yn), const_trait)]
|
||||
trait Foo {
|
||||
fn a(&self);
|
||||
}
|
||||
|
||||
#[cfg_attr(any(yy, ny), const_trait)]
|
||||
trait Bar: ~const Foo {}
|
||||
//[ny,nn]~^ ERROR: ~const can only be applied to `#[const_trait]`
|
||||
|
||||
const fn foo<T: Bar>(x: &T) {
|
||||
x.a();
|
||||
//~^ ERROR the trait bound
|
||||
//~| ERROR cannot call
|
||||
//[yn,yy]~^ ERROR the trait bound
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
error[E0277]: the trait bound `T: ~const Foo` is not satisfied
|
||||
--> $DIR/super-traits-fail-2.rs:9:7
|
||||
|
|
||||
LL | x.a();
|
||||
| ^^^ the trait `~const Foo` is not implemented for `T`
|
||||
|
|
||||
note: the trait `Foo` is implemented for `T`, but that implementation is not `const`
|
||||
--> $DIR/super-traits-fail-2.rs:9:7
|
||||
|
|
||||
LL | x.a();
|
||||
| ^^^
|
||||
|
||||
error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
|
||||
--> $DIR/super-traits-fail-2.rs:9:7
|
||||
|
|
||||
LL | x.a();
|
||||
| ^^^
|
||||
|
|
||||
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0015, E0277.
|
||||
For more information about an error, try `rustc --explain E0015`.
|
|
@ -0,0 +1,21 @@
|
|||
error[E0277]: the trait bound `T: ~const Foo` is not satisfied
|
||||
--> $DIR/super-traits-fail-2.rs:15:5
|
||||
|
|
||||
LL | x.a();
|
||||
| ^ - required by a bound introduced by this call
|
||||
| |
|
||||
| the trait `~const Foo` is not implemented for `T`
|
||||
|
|
||||
note: the trait `Foo` is implemented for `T`, but that implementation is not `const`
|
||||
--> $DIR/super-traits-fail-2.rs:15:5
|
||||
|
|
||||
LL | x.a();
|
||||
| ^
|
||||
help: consider further restricting this bound
|
||||
|
|
||||
LL | const fn foo<T: Bar + ~const Foo>(x: &T) {
|
||||
| ++++++++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
|
@ -0,0 +1,21 @@
|
|||
error[E0277]: the trait bound `T: ~const Foo` is not satisfied
|
||||
--> $DIR/super-traits-fail-2.rs:15:5
|
||||
|
|
||||
LL | x.a();
|
||||
| ^ - required by a bound introduced by this call
|
||||
| |
|
||||
| the trait `~const Foo` is not implemented for `T`
|
||||
|
|
||||
note: the trait `Foo` is implemented for `T`, but that implementation is not `const`
|
||||
--> $DIR/super-traits-fail-2.rs:15:5
|
||||
|
|
||||
LL | x.a();
|
||||
| ^
|
||||
help: consider further restricting this bound
|
||||
|
|
||||
LL | const fn foo<T: Bar + ~const Foo>(x: &T) {
|
||||
| ++++++++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
|
@ -0,0 +1,14 @@
|
|||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/super-traits-fail-3.rs:12:12
|
||||
|
|
||||
LL | trait Bar: ~const Foo {}
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/super-traits-fail-3.rs:15:17
|
||||
|
|
||||
LL | const fn foo<T: ~const Bar>(x: &T) {
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/super-traits-fail-3.rs:12:12
|
||||
|
|
||||
LL | trait Bar: ~const Foo {}
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
20
src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.rs
Normal file
20
src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
#![feature(const_trait_impl)]
|
||||
|
||||
// revisions: yy yn ny nn
|
||||
//[yy] check-pass
|
||||
|
||||
#[cfg_attr(any(yy, yn), const_trait)]
|
||||
trait Foo {
|
||||
fn a(&self);
|
||||
}
|
||||
|
||||
#[cfg_attr(any(yy, ny), const_trait)]
|
||||
trait Bar: ~const Foo {}
|
||||
//[ny,nn]~^ ERROR: ~const can only be applied to `#[const_trait]`
|
||||
|
||||
const fn foo<T: ~const Bar>(x: &T) {
|
||||
//[yn,nn]~^ ERROR: ~const can only be applied to `#[const_trait]`
|
||||
x.a();
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,8 @@
|
|||
error: ~const can only be applied to `#[const_trait]` traits
|
||||
--> $DIR/super-traits-fail-3.rs:15:17
|
||||
|
|
||||
LL | const fn foo<T: ~const Bar>(x: &T) {
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
#![feature(const_trait_impl)]
|
||||
#![feature(associated_type_bounds)]
|
||||
|
||||
#[const_trait]
|
||||
trait T {}
|
||||
struct S;
|
||||
impl T for S {}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: `~const` is not allowed here
|
||||
--> $DIR/tilde-const-invalid-places.rs:8:19
|
||||
--> $DIR/tilde-const-invalid-places.rs:9:19
|
||||
|
|
||||
LL | fn rpit() -> impl ~const T { S }
|
||||
| ^^^^^^^^
|
||||
|
@ -7,7 +7,7 @@ LL | fn rpit() -> impl ~const T { S }
|
|||
= note: only allowed on bounds on functions, traits' associated types and functions, const impls and its associated functions
|
||||
|
||||
error: `~const` is not allowed here
|
||||
--> $DIR/tilde-const-invalid-places.rs:11:17
|
||||
--> $DIR/tilde-const-invalid-places.rs:12:17
|
||||
|
|
||||
LL | fn apit(_: impl ~const T) {}
|
||||
| ^^^^^^^^
|
||||
|
@ -15,7 +15,7 @@ LL | fn apit(_: impl ~const T) {}
|
|||
= note: only allowed on bounds on functions, traits' associated types and functions, const impls and its associated functions
|
||||
|
||||
error: `~const` is not allowed here
|
||||
--> $DIR/tilde-const-invalid-places.rs:14:50
|
||||
--> $DIR/tilde-const-invalid-places.rs:15:50
|
||||
|
|
||||
LL | fn rpit_assoc_bound() -> impl IntoIterator<Item: ~const T> { Some(S) }
|
||||
| ^^^^^^^^
|
||||
|
@ -23,7 +23,7 @@ LL | fn rpit_assoc_bound() -> impl IntoIterator<Item: ~const T> { Some(S) }
|
|||
= note: only allowed on bounds on functions, traits' associated types and functions, const impls and its associated functions
|
||||
|
||||
error: `~const` is not allowed here
|
||||
--> $DIR/tilde-const-invalid-places.rs:17:48
|
||||
--> $DIR/tilde-const-invalid-places.rs:18:48
|
||||
|
|
||||
LL | fn apit_assoc_bound(_: impl IntoIterator<Item: ~const T>) {}
|
||||
| ^^^^^^^^
|
||||
|
@ -31,7 +31,7 @@ LL | fn apit_assoc_bound(_: impl IntoIterator<Item: ~const T>) {}
|
|||
= note: only allowed on bounds on functions, traits' associated types and functions, const impls and its associated functions
|
||||
|
||||
error: `~const` and `?` are mutually exclusive
|
||||
--> $DIR/tilde-const-invalid-places.rs:20:25
|
||||
--> $DIR/tilde-const-invalid-places.rs:21:25
|
||||
|
|
||||
LL | struct TildeQuestion<T: ~const ?Sized>(std::marker::PhantomData<T>);
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
|
@ -4,8 +4,10 @@
|
|||
// test is not enough.
|
||||
#![feature(const_trait_impl)]
|
||||
|
||||
#[const_trait]
|
||||
trait Bar {}
|
||||
|
||||
#[const_trait]
|
||||
trait Foo {
|
||||
fn a();
|
||||
fn b() where Self: ~const Bar;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
error[E0277]: the trait bound `T: ~const Bar` is not satisfied
|
||||
--> $DIR/trait-where-clause-const.rs:17:5
|
||||
--> $DIR/trait-where-clause-const.rs:19:5
|
||||
|
|
||||
LL | T::b();
|
||||
| ^^^^^^ the trait `~const Bar` is not implemented for `T`
|
||||
|
|
||||
note: the trait `Bar` is implemented for `T`, but that implementation is not `const`
|
||||
--> $DIR/trait-where-clause-const.rs:17:5
|
||||
--> $DIR/trait-where-clause-const.rs:19:5
|
||||
|
|
||||
LL | T::b();
|
||||
| ^^^^^^
|
||||
|
@ -15,13 +15,13 @@ LL | const fn test1<T: ~const Foo + Bar + ~const Bar>() {
|
|||
| ++++++++++++
|
||||
|
||||
error[E0277]: the trait bound `T: ~const Bar` is not satisfied
|
||||
--> $DIR/trait-where-clause-const.rs:19:5
|
||||
--> $DIR/trait-where-clause-const.rs:21:5
|
||||
|
|
||||
LL | T::c::<T>();
|
||||
| ^^^^^^^^^^^ the trait `~const Bar` is not implemented for `T`
|
||||
|
|
||||
note: the trait `Bar` is implemented for `T`, but that implementation is not `const`
|
||||
--> $DIR/trait-where-clause-const.rs:19:5
|
||||
--> $DIR/trait-where-clause-const.rs:21:5
|
||||
|
|
||||
LL | T::c::<T>();
|
||||
| ^^^^^^^^^^^
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#![feature(const_trait_impl)]
|
||||
|
||||
#[const_trait]
|
||||
trait Foo {
|
||||
fn bar() where Self: ~const Foo;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#![feature(const_trait_impl)]
|
||||
|
||||
#[const_trait]
|
||||
trait Bar {}
|
||||
|
||||
trait Foo {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
error[E0277]: the trait bound `T: Bar` is not satisfied
|
||||
--> $DIR/trait-where-clause.rs:13:5
|
||||
--> $DIR/trait-where-clause.rs:14:5
|
||||
|
|
||||
LL | T::b();
|
||||
| ^^^^ the trait `Bar` is not implemented for `T`
|
||||
|
|
||||
note: required by a bound in `Foo::b`
|
||||
--> $DIR/trait-where-clause.rs:7:24
|
||||
--> $DIR/trait-where-clause.rs:8:24
|
||||
|
|
||||
LL | fn b() where Self: ~const Bar;
|
||||
| ^^^^^^^^^^ required by this bound in `Foo::b`
|
||||
|
@ -15,13 +15,13 @@ LL | fn test1<T: Foo + Bar>() {
|
|||
| +++++
|
||||
|
||||
error[E0277]: the trait bound `T: Bar` is not satisfied
|
||||
--> $DIR/trait-where-clause.rs:15:12
|
||||
--> $DIR/trait-where-clause.rs:16:12
|
||||
|
|
||||
LL | T::c::<T>();
|
||||
| ^ the trait `Bar` is not implemented for `T`
|
||||
|
|
||||
note: required by a bound in `Foo::c`
|
||||
--> $DIR/trait-where-clause.rs:8:13
|
||||
--> $DIR/trait-where-clause.rs:9:13
|
||||
|
|
||||
LL | fn c<T: ~const Bar>();
|
||||
| ^^^^^^^^^^ required by this bound in `Foo::c`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue