Skip to content

Commit 9ddb958

Browse files
committed
Fix assoc-type test
1 parent 25c3534 commit 9ddb958

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use rustc_hir as hir;
2+
use rustc_middle::ty::PredicateKind;
3+
14
use crate::infer::canonical::OriginalQueryValues;
25
use crate::infer::InferCtxt;
36
use crate::traits::{
@@ -46,6 +49,12 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
4649
&self,
4750
obligation: &PredicateObligation<'tcx>,
4851
) -> bool {
52+
if let PredicateKind::Trait(pred) = obligation.predicate.kind().skip_binder() {
53+
if let hir::Constness::Const = pred.constness {
54+
// do not evaluate to holds when we have a const predicate.
55+
return false;
56+
}
57+
}
4958
self.evaluate_obligation_no_overflow(obligation).must_apply_considering_regions()
5059
}
5160

src/test/ui/rfc-2632-const-trait-impl/assoc-type.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
// ignore-test
2-
//
3-
// FIXME: This test should fail since, within a const impl of `Foo`, the bound on `Foo::Bar` should
4-
// require a const impl of `Add` for the associated type.
5-
1+
// FIXME(fee1-dead): this should have a better error message
62
#![feature(const_trait_impl)]
73

84
struct NonConstAdd(i32);
@@ -21,6 +17,7 @@ trait Foo {
2117

2218
impl const Foo for NonConstAdd {
2319
type Bar = NonConstAdd;
20+
//~^ ERROR
2421
}
2522

2623
fn main() {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0277]: cannot add `NonConstAdd` to `NonConstAdd`
2+
--> $DIR/assoc-type.rs:19:5
3+
|
4+
LL | type Bar: std::ops::Add;
5+
| ------------- required by this bound in `Foo::Bar`
6+
...
7+
LL | type Bar = NonConstAdd;
8+
| ^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `NonConstAdd + NonConstAdd`
9+
|
10+
= help: the trait `Add` is not implemented for `NonConstAdd`
11+
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
12+
|
13+
LL | impl const Foo for NonConstAdd where NonConstAdd: Add {
14+
| ^^^^^^^^^^^^^^^^^^^^^^
15+
16+
error: aborting due to previous error
17+
18+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)