Skip to content

Commit 6c5eae4

Browse files
committed
Fix call-generic-method-nonconst test
1 parent b1422da commit 6c5eae4

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

compiler/rustc_hir/src/hir.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3216,7 +3216,7 @@ impl<'hir> Node<'hir> {
32163216
}
32173217
}
32183218

3219-
/// Returns `Constness::Const` when this node is a const fn/impl.
3219+
/// Returns `Constness::Const` when this node is a const fn/impl/item.
32203220
pub fn constness(&self) -> Constness {
32213221
match self {
32223222
Node::Item(Item {
@@ -3233,6 +3233,10 @@ impl<'hir> Node<'hir> {
32333233
})
32343234
| Node::Item(Item { kind: ItemKind::Impl(Impl { constness, .. }), .. }) => *constness,
32353235

3236+
Node::Item(Item { kind: ItemKind::Const(..), .. })
3237+
| Node::TraitItem(TraitItem { kind: TraitItemKind::Const(..), .. })
3238+
| Node::ImplItem(ImplItem { kind: ImplItemKind::Const(..), .. }) => Constness::Const,
3239+
32363240
_ => Constness::NotConst,
32373241
}
32383242
}

src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
// FIXME(jschievink): this is not rejected correctly (only when the non-const impl is actually used)
2-
// ignore-test
3-
41
#![feature(const_trait_impl)]
2+
#![feature(const_fn_trait_bound)]
53

64
struct S;
75

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0277]: can't compare `S` with `S`
2+
--> $DIR/call-generic-method-nonconst.rs:19:34
3+
|
4+
LL | const fn equals_self<T: PartialEq>(t: &T) -> bool {
5+
| --------- required by this bound in `equals_self`
6+
...
7+
LL | pub const EQ: bool = equals_self(&S);
8+
| ^^ no implementation for `S == S`
9+
|
10+
= help: the trait `PartialEq` is not implemented for `S`
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)