Skip to content

Commit 670f6dc

Browse files
committed
Fix call-generic-method-nonconst test
1 parent 77f309b commit 670f6dc

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
@@ -3260,7 +3260,7 @@ impl<'hir> Node<'hir> {
32603260
}
32613261
}
32623262

3263-
/// Returns `Constness::Const` when this node is a const fn/impl.
3263+
/// Returns `Constness::Const` when this node is a const fn/impl/item.
32643264
pub fn constness(&self) -> Constness {
32653265
match self {
32663266
Node::Item(Item {
@@ -3277,6 +3277,10 @@ impl<'hir> Node<'hir> {
32773277
})
32783278
| Node::Item(Item { kind: ItemKind::Impl(Impl { constness, .. }), .. }) => *constness,
32793279

3280+
Node::Item(Item { kind: ItemKind::Const(..), .. })
3281+
| Node::TraitItem(TraitItem { kind: TraitItemKind::Const(..), .. })
3282+
| Node::ImplItem(ImplItem { kind: ImplItemKind::Const(..), .. }) => Constness::Const,
3283+
32803284
_ => Constness::NotConst,
32813285
}
32823286
}

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)