Skip to content

Commit 6b6ad78

Browse files
committed
Fix call-generic-method-nonconst test
1 parent 7106f8d commit 6b6ad78

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

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

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

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)