Rollup merge of #131152 - fee1-dead-contrib:fxdiag, r=compiler-errors

Improve const traits diagnostics for new desugaring

r? project-const-traits
This commit is contained in:
Matthias Krüger 2024-10-02 17:10:47 +02:00 committed by GitHub
commit b38f7ad9b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 224 additions and 168 deletions

View File

@ -67,7 +67,7 @@ macro_rules! TrivialLiftImpls {
};
}
/// Used for types that are `Copy` and which **do not care arena
/// Used for types that are `Copy` and which **do not care about arena
/// allocated data** (i.e., don't need to be folded).
#[macro_export]
macro_rules! TrivialTypeTraversalImpls {

View File

@ -1951,19 +1951,18 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
fn pretty_print_bound_constness(
&mut self,
trait_ref: ty::TraitRef<'tcx>,
constness: ty::BoundConstness,
) -> Result<(), PrintError> {
define_scoped_cx!(self);
let Some(idx) = self.tcx().generics_of(trait_ref.def_id).host_effect_index else {
return Ok(());
};
let arg = trait_ref.args.const_at(idx);
if arg == self.tcx().consts.false_ {
p!("const ");
} else if arg != self.tcx().consts.true_ && !arg.has_infer() {
p!("~const ");
match constness {
ty::BoundConstness::NotConst => {}
ty::BoundConstness::Const => {
p!("const ");
}
ty::BoundConstness::ConstIfConst => {
p!("~const ");
}
}
Ok(())
}
@ -2948,6 +2947,15 @@ impl<'tcx> ty::TraitPredicate<'tcx> {
}
}
#[derive(Copy, Clone, TypeFoldable, TypeVisitable, Lift)]
pub struct TraitPredPrintWithBoundConstness<'tcx>(ty::TraitPredicate<'tcx>, ty::BoundConstness);
impl<'tcx> fmt::Debug for TraitPredPrintWithBoundConstness<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(self, f)
}
}
#[extension(pub trait PrintPolyTraitPredicateExt<'tcx>)]
impl<'tcx> ty::PolyTraitPredicate<'tcx> {
fn print_modifiers_and_trait_path(
@ -2955,6 +2963,13 @@ impl<'tcx> ty::PolyTraitPredicate<'tcx> {
) -> ty::Binder<'tcx, TraitPredPrintModifiersAndPath<'tcx>> {
self.map_bound(TraitPredPrintModifiersAndPath)
}
fn print_with_bound_constness(
self,
constness: ty::BoundConstness,
) -> ty::Binder<'tcx, TraitPredPrintWithBoundConstness<'tcx>> {
self.map_bound(|trait_pred| TraitPredPrintWithBoundConstness(trait_pred, constness))
}
}
#[derive(Debug, Copy, Clone, Lift)]
@ -3052,7 +3067,6 @@ define_print! {
ty::TraitPredicate<'tcx> {
p!(print(self.trait_ref.self_ty()), ": ");
p!(pretty_print_bound_constness(self.trait_ref));
if let ty::PredicatePolarity::Negative = self.polarity {
p!("!");
}
@ -3184,13 +3198,21 @@ define_print_and_forward_display! {
}
TraitPredPrintModifiersAndPath<'tcx> {
p!(pretty_print_bound_constness(self.0.trait_ref));
if let ty::PredicatePolarity::Negative = self.0.polarity {
p!("!")
}
p!(print(self.0.trait_ref.print_trait_sugared()));
}
TraitPredPrintWithBoundConstness<'tcx> {
p!(print(self.0.trait_ref.self_ty()), ": ");
p!(pretty_print_bound_constness(self.1));
if let ty::PredicatePolarity::Negative = self.0.polarity {
p!("!");
}
p!(print(self.0.trait_ref.print_trait_sugared()))
}
PrintClosureAsImpl<'tcx> {
p!(pretty_closure_as_impl(self.closure))
}

View File

@ -19,8 +19,8 @@ use rustc_middle::ty::abstract_const::NotConstEvaluatable;
use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::fold::{TypeFolder, TypeSuperFoldable};
use rustc_middle::ty::print::{
FmtPrinter, Print, PrintTraitPredicateExt as _, PrintTraitRefExt as _,
with_forced_trimmed_paths,
FmtPrinter, Print, PrintPolyTraitPredicateExt, PrintTraitPredicateExt as _,
PrintTraitRefExt as _, with_forced_trimmed_paths,
};
use rustc_middle::ty::{
self, ToPolyTraitRef, TraitRef, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, Upcast,
@ -154,6 +154,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
} else {
(leaf_trait_predicate, &obligation)
};
let (main_trait_predicate, leaf_trait_predicate, predicate_constness) = self.get_effects_trait_pred_override(main_trait_predicate, leaf_trait_predicate, span);
let main_trait_ref = main_trait_predicate.to_poly_trait_ref();
let leaf_trait_ref = leaf_trait_predicate.to_poly_trait_ref();
@ -164,9 +167,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
return guar;
}
// FIXME(effects)
let predicate_is_const = false;
if let Err(guar) = leaf_trait_predicate.error_reported()
{
return guar;
@ -227,7 +227,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
let err_msg = self.get_standard_error_message(
main_trait_predicate,
message,
predicate_is_const,
predicate_constness,
append_const_msg,
post_message,
);
@ -286,7 +286,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}
if tcx.is_lang_item(leaf_trait_ref.def_id(), LangItem::Drop)
&& predicate_is_const
&& matches!(predicate_constness, ty::BoundConstness::ConstIfConst | ty::BoundConstness::Const)
{
err.note("`~const Drop` was renamed to `~const Destruct`");
err.note("See <https://github.com/rust-lang/rust/pull/94901> for more details");
@ -2187,29 +2187,34 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
&self,
trait_predicate: ty::PolyTraitPredicate<'tcx>,
message: Option<String>,
predicate_is_const: bool,
predicate_constness: ty::BoundConstness,
append_const_msg: Option<AppendConstMessage>,
post_message: String,
) -> String {
message
.and_then(|cannot_do_this| {
match (predicate_is_const, append_const_msg) {
match (predicate_constness, append_const_msg) {
// do nothing if predicate is not const
(false, _) => Some(cannot_do_this),
(ty::BoundConstness::NotConst, _) => Some(cannot_do_this),
// suggested using default post message
(true, Some(AppendConstMessage::Default)) => {
Some(format!("{cannot_do_this} in const contexts"))
}
(
ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst,
Some(AppendConstMessage::Default),
) => Some(format!("{cannot_do_this} in const contexts")),
// overridden post message
(true, Some(AppendConstMessage::Custom(custom_msg, _))) => {
Some(format!("{cannot_do_this}{custom_msg}"))
}
(
ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst,
Some(AppendConstMessage::Custom(custom_msg, _)),
) => Some(format!("{cannot_do_this}{custom_msg}")),
// fallback to generic message
(true, None) => None,
(ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst, None) => None,
}
})
.unwrap_or_else(|| {
format!("the trait bound `{trait_predicate}` is not satisfied{post_message}")
format!(
"the trait bound `{}` is not satisfied{post_message}",
trait_predicate.print_with_bound_constness(predicate_constness)
)
})
}
@ -2333,6 +2338,51 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
}
}
/// For effects predicates such as `<u32 as Add>::Effects: Compat<host>`, pretend that the
/// predicate that failed was `u32: Add`. Return the constness of such predicate to later
/// print as `u32: ~const Add`.
fn get_effects_trait_pred_override(
&self,
p: ty::PolyTraitPredicate<'tcx>,
leaf: ty::PolyTraitPredicate<'tcx>,
span: Span,
) -> (ty::PolyTraitPredicate<'tcx>, ty::PolyTraitPredicate<'tcx>, ty::BoundConstness) {
let trait_ref = p.to_poly_trait_ref();
if !self.tcx.is_lang_item(trait_ref.def_id(), LangItem::EffectsCompat) {
return (p, leaf, ty::BoundConstness::NotConst);
}
let Some(ty::Alias(ty::AliasTyKind::Projection, projection)) =
trait_ref.self_ty().no_bound_vars().map(Ty::kind)
else {
return (p, leaf, ty::BoundConstness::NotConst);
};
let constness = trait_ref.skip_binder().args.const_at(1);
let constness = if constness == self.tcx.consts.true_ || constness.is_ct_infer() {
ty::BoundConstness::NotConst
} else if constness == self.tcx.consts.false_ {
ty::BoundConstness::Const
} else if matches!(constness.kind(), ty::ConstKind::Param(_)) {
ty::BoundConstness::ConstIfConst
} else {
self.dcx().span_bug(span, format!("Unknown constness argument: {constness:?}"));
};
let new_pred = p.map_bound(|mut trait_pred| {
trait_pred.trait_ref = projection.trait_ref(self.tcx);
trait_pred
});
let new_leaf = leaf.map_bound(|mut trait_pred| {
trait_pred.trait_ref = projection.trait_ref(self.tcx);
trait_pred
});
(new_pred, new_leaf, constness)
}
fn add_tuple_trait_message(
&self,
obligation_cause_code: &ObligationCauseCode<'tcx>,

View File

@ -755,3 +755,10 @@ impl fmt::Display for BoundConstness {
}
}
}
impl<I> Lift<I> for BoundConstness {
type Lifted = BoundConstness;
fn lift_to_interner(self, _: I) -> Option<Self::Lifted> {
Some(self)
}
}

View File

@ -3,11 +3,11 @@ error: using `#![feature(effects)]` without enabling next trait solver globally
= note: the next trait solver must be enabled globally for the effects feature to work correctly
= help: use `-Znext-solver` to enable
error[E0277]: the trait bound `Trait::{synthetic#0}: Compat` is not satisfied
error[E0277]: the trait bound `<T as Trait>::Assoc: Trait` is not satisfied
--> $DIR/assoc-type-const-bound-usage-0.rs:13:5
|
LL | T::Assoc::func()
| ^^^^^^^^ the trait `Compat` is not implemented for `Trait::{synthetic#0}`
| ^^^^^^^^ the trait `Trait` is not implemented for `<T as Trait>::Assoc`
|
note: required by a bound in `Trait::func`
--> $DIR/assoc-type-const-bound-usage-0.rs:6:1
@ -17,12 +17,16 @@ LL | #[const_trait]
...
LL | fn func() -> i32;
| ---- required by a bound in this associated function
help: consider further restricting the associated type
|
LL | const fn unqualified<T: ~const Trait>() -> i32 where <T as Trait>::Assoc: Trait {
| ++++++++++++++++++++++++++++++++
error[E0277]: the trait bound `Trait::{synthetic#0}: Compat` is not satisfied
error[E0277]: the trait bound `<T as Trait>::Assoc: Trait` is not satisfied
--> $DIR/assoc-type-const-bound-usage-0.rs:17:5
|
LL | <T as Trait>::Assoc::func()
| ^^^^^^^^^^^^^^^^^^^ the trait `Compat` is not implemented for `Trait::{synthetic#0}`
| ^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `<T as Trait>::Assoc`
|
note: required by a bound in `Trait::func`
--> $DIR/assoc-type-const-bound-usage-0.rs:6:1
@ -32,6 +36,10 @@ LL | #[const_trait]
...
LL | fn func() -> i32;
| ---- required by a bound in this associated function
help: consider further restricting the associated type
|
LL | const fn qualified<T: ~const Trait>() -> i32 where <T as Trait>::Assoc: Trait {
| ++++++++++++++++++++++++++++++++
error: aborting due to 3 previous errors

View File

@ -3,11 +3,11 @@ error: using `#![feature(effects)]` without enabling next trait solver globally
= note: the next trait solver must be enabled globally for the effects feature to work correctly
= help: use `-Znext-solver` to enable
error[E0277]: the trait bound `Trait::{synthetic#0}: Compat` is not satisfied
error[E0277]: the trait bound `<T as Trait>::Assoc: Trait` is not satisfied
--> $DIR/assoc-type-const-bound-usage-1.rs:15:44
|
LL | fn unqualified<T: const Trait>() -> Type<{ T::Assoc::func() }> {
| ^^^^^^^^ the trait `Compat` is not implemented for `Trait::{synthetic#0}`
| ^^^^^^^^ the trait `Trait` is not implemented for `<T as Trait>::Assoc`
|
note: required by a bound in `Trait::func`
--> $DIR/assoc-type-const-bound-usage-1.rs:7:1
@ -17,12 +17,16 @@ LL | #[const_trait]
...
LL | fn func() -> i32;
| ---- required by a bound in this associated function
help: consider further restricting the associated type
|
LL | fn unqualified<T: const Trait>() -> Type<{ T::Assoc::func() }> where <T as Trait>::Assoc: Trait {
| ++++++++++++++++++++++++++++++++
error[E0277]: the trait bound `Trait::{synthetic#0}: Compat` is not satisfied
error[E0277]: the trait bound `<T as Trait>::Assoc: Trait` is not satisfied
--> $DIR/assoc-type-const-bound-usage-1.rs:19:42
|
LL | fn qualified<T: const Trait>() -> Type<{ <T as Trait>::Assoc::func() }> {
| ^^^^^^^^^^^^^^^^^^^ the trait `Compat` is not implemented for `Trait::{synthetic#0}`
| ^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `<T as Trait>::Assoc`
|
note: required by a bound in `Trait::func`
--> $DIR/assoc-type-const-bound-usage-1.rs:7:1
@ -32,6 +36,10 @@ LL | #[const_trait]
...
LL | fn func() -> i32;
| ---- required by a bound in this associated function
help: consider further restricting the associated type
|
LL | fn qualified<T: const Trait>() -> Type<{ <T as Trait>::Assoc::func() }> where <T as Trait>::Assoc: Trait {
| ++++++++++++++++++++++++++++++++
error: aborting due to 3 previous errors

View File

@ -1,4 +1,6 @@
#![feature(const_trait_impl, effects)] //~ WARN the feature `effects` is incomplete
//@ compile-flags: -Znext-solver
#![allow(incomplete_features)]
#![feature(const_trait_impl, effects)]
#[const_trait]
pub trait Plus {
@ -23,7 +25,7 @@ pub const fn add_i32(a: i32, b: i32) -> i32 {
pub const fn add_u32(a: u32, b: u32) -> u32 {
a.plus(b)
//~^ ERROR the trait bound
//~^ ERROR the trait bound `u32: ~const Plus`
}
fn main() {}

View File

@ -1,33 +1,22 @@
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/call-const-trait-method-fail.rs:1:30
|
LL | #![feature(const_trait_impl, effects)]
| ^^^^^^^
|
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
= note: `#[warn(incomplete_features)]` on by default
error: using `#![feature(effects)]` without enabling next trait solver globally
|
= note: the next trait solver must be enabled globally for the effects feature to work correctly
= help: use `-Znext-solver` to enable
error[E0277]: the trait bound `Runtime: ~const Compat` is not satisfied
--> $DIR/call-const-trait-method-fail.rs:25:5
error[E0277]: the trait bound `u32: ~const Plus` is not satisfied
--> $DIR/call-const-trait-method-fail.rs:27:5
|
LL | a.plus(b)
| ^ the trait `~const Compat` is not implemented for `Runtime`
| ^ the trait `Plus` is not implemented for `u32`
|
= help: the trait `Compat` is implemented for `Runtime`
note: required by a bound in `Plus::plus`
--> $DIR/call-const-trait-method-fail.rs:3:1
--> $DIR/call-const-trait-method-fail.rs:5:1
|
LL | #[const_trait]
| ^^^^^^^^^^^^^^ required by this bound in `Plus::plus`
LL | pub trait Plus {
LL | fn plus(self, rhs: Self) -> Self;
| ---- required by a bound in this associated function
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
LL | pub const fn add_u32(a: u32, b: u32) -> u32 where u32: Plus {
| +++++++++++++++
error: aborting due to 2 previous errors; 1 warning emitted
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.

View File

@ -1,4 +1,6 @@
#![feature(const_trait_impl, effects)] //~ WARN the feature `effects` is incomplete
//@ compile-flags: -Znext-solver
#![allow(incomplete_features)]
#![feature(const_trait_impl, effects)]
struct S;
@ -21,7 +23,6 @@ const fn equals_self<T: ~const Foo>(t: &T) -> bool {
// it not using the impl.
pub const EQ: bool = equals_self(&S);
//~^ ERROR: the trait bound `Runtime: const Compat` is not satisfied
// FIXME(effects) diagnostic
//~^ ERROR: the trait bound `S: const Foo` is not satisfied
fn main() {}

View File

@ -1,32 +1,21 @@
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/call-generic-method-nonconst.rs:1:30
|
LL | #![feature(const_trait_impl, effects)]
| ^^^^^^^
|
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
= note: `#[warn(incomplete_features)]` on by default
error: using `#![feature(effects)]` without enabling next trait solver globally
|
= note: the next trait solver must be enabled globally for the effects feature to work correctly
= help: use `-Znext-solver` to enable
error[E0277]: the trait bound `Runtime: const Compat` is not satisfied
--> $DIR/call-generic-method-nonconst.rs:23:34
error[E0277]: the trait bound `S: const Foo` is not satisfied
--> $DIR/call-generic-method-nonconst.rs:25:34
|
LL | pub const EQ: bool = equals_self(&S);
| ----------- ^^ the trait `const Compat` is not implemented for `Runtime`
| ----------- ^^ the trait `Foo` is not implemented for `S`
| |
| required by a bound introduced by this call
|
= help: the trait `Compat` is implemented for `Runtime`
note: required by a bound in `equals_self`
--> $DIR/call-generic-method-nonconst.rs:16:25
--> $DIR/call-generic-method-nonconst.rs:18:25
|
LL | const fn equals_self<T: ~const Foo>(t: &T) -> bool {
| ^^^^^^^^^^ required by this bound in `equals_self`
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
LL | pub const EQ: bool where S: Foo = equals_self(&S);
| ++++++++++++
error: aborting due to 2 previous errors; 1 warning emitted
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.

View File

@ -1,4 +1,6 @@
#![feature(const_trait_impl, effects)] //~ WARN the feature `effects` is incomplete
//@ compile-flags: -Znext-solver
#![allow(incomplete_features)]
#![feature(const_trait_impl, effects)]
#[const_trait]
trait ConstDefaultFn: Sized {
@ -22,7 +24,7 @@ impl const ConstDefaultFn for ConstImpl {
const fn test() {
NonConstImpl.a();
//~^ ERROR the trait bound
//~^ ERROR the trait bound `NonConstImpl: ~const ConstDefaultFn` is not satisfied
ConstImpl.a();
}

View File

@ -1,33 +1,22 @@
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/const-default-method-bodies.rs:1:30
|
LL | #![feature(const_trait_impl, effects)]
| ^^^^^^^
|
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
= note: `#[warn(incomplete_features)]` on by default
error: using `#![feature(effects)]` without enabling next trait solver globally
|
= note: the next trait solver must be enabled globally for the effects feature to work correctly
= help: use `-Znext-solver` to enable
error[E0277]: the trait bound `Runtime: ~const Compat` is not satisfied
--> $DIR/const-default-method-bodies.rs:24:18
error[E0277]: the trait bound `NonConstImpl: ~const ConstDefaultFn` is not satisfied
--> $DIR/const-default-method-bodies.rs:26:18
|
LL | NonConstImpl.a();
| ^ the trait `~const Compat` is not implemented for `Runtime`
| ^ the trait `ConstDefaultFn` is not implemented for `NonConstImpl`
|
= help: the trait `Compat` is implemented for `Runtime`
note: required by a bound in `ConstDefaultFn::a`
--> $DIR/const-default-method-bodies.rs:3:1
--> $DIR/const-default-method-bodies.rs:5:1
|
LL | #[const_trait]
| ^^^^^^^^^^^^^^ required by this bound in `ConstDefaultFn::a`
...
LL | fn a(self) {
| - required by a bound in this associated function
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
LL | const fn test() where NonConstImpl: ConstDefaultFn {
| ++++++++++++++++++++++++++++++++++
error: aborting due to 2 previous errors; 1 warning emitted
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.

View File

@ -1,8 +1,8 @@
error[E0277]: the trait bound `FnOnce<()>::{synthetic#0}: const Compat` is not satisfied
error[E0277]: the trait bound `fn() {foo}: const FnOnce()` is not satisfied
--> $DIR/const-fns-are-early-bound.rs:31:17
|
LL | is_const_fn(foo);
| ----------- ^^^ the trait `const Compat` is not implemented for `FnOnce<()>::{synthetic#0}`
| ----------- ^^^ the trait `FnOnce()` is not implemented for fn item `fn() {foo}`
| |
| required by a bound introduced by this call
|

View File

@ -1,8 +1,8 @@
error[E0277]: the trait bound `cross_crate::MyTrait::{synthetic#0}: ~const Compat` is not satisfied
error[E0277]: the trait bound `cross_crate::NonConst: ~const cross_crate::MyTrait` is not satisfied
--> $DIR/cross-crate.rs:19:14
|
LL | NonConst.func();
| ^^^^ the trait `~const Compat` is not implemented for `cross_crate::MyTrait::{synthetic#0}`
| ^^^^ the trait `cross_crate::MyTrait` is not implemented for `cross_crate::NonConst`
|
note: required by a bound in `func`
--> $DIR/auxiliary/cross-crate.rs:5:1
@ -12,6 +12,10 @@ LL | #[const_trait]
...
LL | fn func(self);
| ---- required by a bound in this associated function
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
LL | const fn const_context() where cross_crate::NonConst: cross_crate::MyTrait {
| +++++++++++++++++++++++++++++++++++++++++++++++++
error: aborting due to 1 previous error

View File

@ -1,4 +1,6 @@
#![feature(const_trait_impl, effects)] //~ WARN the feature `effects` is incomplete
//@ compile-flags: -Znext-solver
#![allow(incomplete_features)]
#![feature(const_trait_impl, effects)]
#[const_trait]
pub trait Tr {
@ -6,7 +8,7 @@ pub trait Tr {
fn b(&self) {
().a()
//~^ ERROR the trait bound
//~^ ERROR the trait bound `(): ~const Tr` is not satisfied
}
}

View File

@ -1,33 +1,22 @@
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/default-method-body-is-const-same-trait-ck.rs:1:30
|
LL | #![feature(const_trait_impl, effects)]
| ^^^^^^^
|
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
= note: `#[warn(incomplete_features)]` on by default
error: using `#![feature(effects)]` without enabling next trait solver globally
|
= note: the next trait solver must be enabled globally for the effects feature to work correctly
= help: use `-Znext-solver` to enable
error[E0277]: the trait bound `Runtime: ~const Compat` is not satisfied
--> $DIR/default-method-body-is-const-same-trait-ck.rs:8:12
error[E0277]: the trait bound `(): ~const Tr` is not satisfied
--> $DIR/default-method-body-is-const-same-trait-ck.rs:10:12
|
LL | ().a()
| ^ the trait `~const Compat` is not implemented for `Runtime`
| ^ the trait `Tr` is not implemented for `()`
|
= help: the trait `Compat` is implemented for `Runtime`
note: required by a bound in `Tr::a`
--> $DIR/default-method-body-is-const-same-trait-ck.rs:3:1
--> $DIR/default-method-body-is-const-same-trait-ck.rs:5:1
|
LL | #[const_trait]
| ^^^^^^^^^^^^^^ required by this bound in `Tr::a`
LL | pub trait Tr {
LL | fn a(&self) {}
| - required by a bound in this associated function
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
LL | pub trait Tr where (): Tr {
| ++++++++++++
error: aborting due to 2 previous errors; 1 warning emitted
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.

View File

@ -17,8 +17,7 @@ trait Bar: ~const Foo {}
const fn foo<T: Bar>(x: &T) {
x.a();
//[yy,yn]~^ ERROR the trait bound
// FIXME(effects) diagnostic
//[yy,yn]~^ ERROR the trait bound `T: ~const Foo`
}
fn main() {}

View File

@ -10,11 +10,11 @@ note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bou
LL | trait Bar: ~const Foo {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
error[E0277]: the trait bound `Foo::{synthetic#0}: ~const Compat` is not satisfied
error[E0277]: the trait bound `T: ~const Foo` is not satisfied
--> $DIR/super-traits-fail-2.rs:19:7
|
LL | x.a();
| ^ the trait `~const Compat` is not implemented for `Foo::{synthetic#0}`
| ^ the trait `Foo` is not implemented for `T`
|
note: required by a bound in `Foo::a`
--> $DIR/super-traits-fail-2.rs:6:25
@ -24,10 +24,10 @@ LL | #[cfg_attr(any(yy, yn), const_trait)]
LL | trait Foo {
LL | fn a(&self);
| - required by a bound in this associated function
help: consider further restricting the associated type
help: consider further restricting this bound
|
LL | const fn foo<T: Bar>(x: &T) where Foo::{synthetic#0}: ~const Compat {
| +++++++++++++++++++++++++++++++++++++++
LL | const fn foo<T: Bar + Foo>(x: &T) {
| +++++
error: aborting due to 2 previous errors

View File

@ -1,8 +1,8 @@
error[E0277]: the trait bound `Foo::{synthetic#0}: ~const Compat` is not satisfied
error[E0277]: the trait bound `T: ~const Foo` is not satisfied
--> $DIR/super-traits-fail-2.rs:19:7
|
LL | x.a();
| ^ the trait `~const Compat` is not implemented for `Foo::{synthetic#0}`
| ^ the trait `Foo` is not implemented for `T`
|
note: required by a bound in `Foo::a`
--> $DIR/super-traits-fail-2.rs:6:25
@ -12,10 +12,10 @@ LL | #[cfg_attr(any(yy, yn), const_trait)]
LL | trait Foo {
LL | fn a(&self);
| - required by a bound in this associated function
help: consider further restricting the associated type
help: consider further restricting this bound
|
LL | const fn foo<T: Bar>(x: &T) where Foo::{synthetic#0}: ~const Compat {
| +++++++++++++++++++++++++++++++++++++++
LL | const fn foo<T: Bar + Foo>(x: &T) {
| +++++
error: aborting due to 1 previous error

View File

@ -20,7 +20,7 @@ trait Bar: ~const Foo {}
const fn foo<T: ~const Bar>(x: &T) {
//[yn,nn]~^ ERROR: `~const` can only be applied to `#[const_trait]`
x.a();
//[yn]~^ ERROR: the trait bound
//[yn]~^ ERROR: the trait bound `T: ~const Foo` is not satisfied
}
fn main() {}

View File

@ -16,11 +16,11 @@ error: `~const` can only be applied to `#[const_trait]` traits
LL | const fn foo<T: ~const Bar>(x: &T) {
| ^^^
error[E0277]: the trait bound `Foo::{synthetic#0}: ~const Compat` is not satisfied
error[E0277]: the trait bound `T: ~const Foo` is not satisfied
--> $DIR/super-traits-fail-3.rs:22:7
|
LL | x.a();
| ^ the trait `~const Compat` is not implemented for `Foo::{synthetic#0}`
| ^ the trait `Foo` is not implemented for `T`
|
note: required by a bound in `Foo::a`
--> $DIR/super-traits-fail-3.rs:8:25
@ -30,10 +30,10 @@ LL | #[cfg_attr(any(yy, yn), const_trait)]
LL | trait Foo {
LL | fn a(&self);
| - required by a bound in this associated function
help: consider further restricting the associated type
help: consider further restricting this bound
|
LL | const fn foo<T: ~const Bar>(x: &T) where Foo::{synthetic#0}: ~const Compat {
| +++++++++++++++++++++++++++++++++++++++
LL | const fn foo<T: ~const Bar + Foo>(x: &T) {
| +++++
error: aborting due to 3 previous errors

View File

@ -1,8 +1,8 @@
error[E0277]: the trait bound `Foo::{synthetic#0}: Compat` is not satisfied
error[E0277]: the trait bound `T: Foo` is not satisfied
--> $DIR/trait-where-clause-const.rs:22:5
|
LL | T::b();
| ^ the trait `Compat` is not implemented for `Foo::{synthetic#0}`
| ^ the trait `Foo` is not implemented for `T`
|
note: required by a bound in `Foo::b`
--> $DIR/trait-where-clause-const.rs:13:1
@ -12,10 +12,6 @@ LL | #[const_trait]
...
LL | fn b() where Self: ~const Bar;
| - required by a bound in this associated function
help: consider further restricting the associated type
|
LL | const fn test1<T: ~const Foo + Bar>() where Foo::{synthetic#0}: Compat {
| ++++++++++++++++++++++++++++++++
error[E0308]: mismatched types
--> $DIR/trait-where-clause-const.rs:22:5
@ -26,11 +22,11 @@ LL | T::b();
= note: expected constant `host`
found constant `true`
error[E0277]: the trait bound `Foo::{synthetic#0}: Compat` is not satisfied
error[E0277]: the trait bound `T: Foo` is not satisfied
--> $DIR/trait-where-clause-const.rs:25:5
|
LL | T::c::<T>();
| ^ the trait `Compat` is not implemented for `Foo::{synthetic#0}`
| ^ the trait `Foo` is not implemented for `T`
|
note: required by a bound in `Foo::c`
--> $DIR/trait-where-clause-const.rs:13:1
@ -40,10 +36,6 @@ LL | #[const_trait]
...
LL | fn c<T: ~const Bar>();
| - required by a bound in this associated function
help: consider further restricting the associated type
|
LL | const fn test1<T: ~const Foo + Bar>() where Foo::{synthetic#0}: Compat {
| ++++++++++++++++++++++++++++++++
error[E0308]: mismatched types
--> $DIR/trait-where-clause-const.rs:25:5

View File

@ -19,7 +19,6 @@ impl Trait for Ty {
}
fn main() {
// FIXME(effects): improve diagnostics on this
require::<Ty>();
}

View File

@ -7,7 +7,7 @@ LL | #![feature(const_trait_impl, effects, generic_const_exprs)]
= help: remove one of these features
error[E0308]: mismatched types
--> $DIR/unsatisfied-const-trait-bound.rs:30:37
--> $DIR/unsatisfied-const-trait-bound.rs:29:37
|
LL | fn accept0<T: Trait>(_: Container<{ T::make() }>) {}
| ^^^^^^^^^ expected `false`, found `true`
@ -16,7 +16,7 @@ LL | fn accept0<T: Trait>(_: Container<{ T::make() }>) {}
found constant `true`
error[E0308]: mismatched types
--> $DIR/unsatisfied-const-trait-bound.rs:34:50
--> $DIR/unsatisfied-const-trait-bound.rs:33:50
|
LL | const fn accept1<T: ~const Trait>(_: Container<{ T::make() }>) {}
| ^^^^^^^^^ expected `false`, found `host`
@ -24,17 +24,21 @@ LL | const fn accept1<T: ~const Trait>(_: Container<{ T::make() }>) {}
= note: expected constant `false`
found constant `host`
error[E0277]: the trait bound `Trait::{synthetic#0}: const Compat` is not satisfied
--> $DIR/unsatisfied-const-trait-bound.rs:23:15
error[E0277]: the trait bound `Ty: const Trait` is not satisfied
--> $DIR/unsatisfied-const-trait-bound.rs:22:15
|
LL | require::<Ty>();
| ^^ the trait `const Compat` is not implemented for `Trait::{synthetic#0}`
| ^^ the trait `Trait` is not implemented for `Ty`
|
note: required by a bound in `require`
--> $DIR/unsatisfied-const-trait-bound.rs:8:15
|
LL | fn require<T: const Trait>() {}
| ^^^^^^^^^^^ required by this bound in `require`
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
LL | fn main() where Ty: Trait {
| +++++++++++++++
error: aborting due to 4 previous errors