1
Fork 0

Fix assoc-type test

This commit is contained in:
Deadbeef 2021-07-26 11:13:23 +08:00
parent 01bb3710b5
commit bcf0e2f528
No known key found for this signature in database
GPG key ID: 027DF9338862ADDD
3 changed files with 29 additions and 5 deletions

View file

@ -1,3 +1,6 @@
use rustc_hir as hir;
use rustc_middle::ty::PredicateKind;
use crate::infer::canonical::OriginalQueryValues;
use crate::infer::InferCtxt;
use crate::traits::{
@ -46,6 +49,12 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
&self,
obligation: &PredicateObligation<'tcx>,
) -> bool {
if let PredicateKind::Trait(pred) = obligation.predicate.kind().skip_binder() {
if let hir::Constness::Const = pred.constness {
// do not evaluate to holds when we have a const predicate.
return false;
}
}
self.evaluate_obligation_no_overflow(obligation).must_apply_considering_regions()
}

View file

@ -1,8 +1,4 @@
// ignore-test
//
// FIXME: This test should fail since, within a const impl of `Foo`, the bound on `Foo::Bar` should
// require a const impl of `Add` for the associated type.
// FIXME(fee1-dead): this should have a better error message
#![feature(const_trait_impl)]
struct NonConstAdd(i32);
@ -21,6 +17,7 @@ trait Foo {
impl const Foo for NonConstAdd {
type Bar = NonConstAdd;
//~^ ERROR
}
fn main() {}

View file

@ -0,0 +1,18 @@
error[E0277]: cannot add `NonConstAdd` to `NonConstAdd`
--> $DIR/assoc-type.rs:19:5
|
LL | type Bar: std::ops::Add;
| ------------- required by this bound in `Foo::Bar`
...
LL | type Bar = NonConstAdd;
| ^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `NonConstAdd + NonConstAdd`
|
= help: the trait `Add` is not implemented for `NonConstAdd`
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
|
LL | impl const Foo for NonConstAdd where NonConstAdd: Add {
| ^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.