diff options
| author | Deadbeef <ent3rm4n@gmail.com> | 2021-07-26 12:06:55 +0800 |
|---|---|---|
| committer | Deadbeef <ent3rm4n@gmail.com> | 2021-08-13 09:28:51 +0000 |
| commit | 6b6ad781f8cae57aef80d35b1c5b7f36f239ed62 (patch) | |
| tree | 5efac6efd2ad2a95bde328e8c6efab6ec92db77f | |
| parent | 7106f8d8ee2574c4fbd9b89e76bc1d177e867876 (diff) | |
| download | rust-6b6ad781f8cae57aef80d35b1c5b7f36f239ed62.tar.gz rust-6b6ad781f8cae57aef80d35b1c5b7f36f239ed62.zip | |
Fix call-generic-method-nonconst test
3 files changed, 20 insertions, 4 deletions
diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 9e655bc4a7e..9fc39afac9f 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -3261,7 +3261,7 @@ impl<'hir> Node<'hir> { } } - /// Returns `Constness::Const` when this node is a const fn/impl. + /// Returns `Constness::Const` when this node is a const fn/impl/item. pub fn constness(&self) -> Constness { match self { Node::Item(Item { @@ -3278,6 +3278,10 @@ impl<'hir> Node<'hir> { }) | Node::Item(Item { kind: ItemKind::Impl(Impl { constness, .. }), .. }) => *constness, + Node::Item(Item { kind: ItemKind::Const(..), .. }) + | Node::TraitItem(TraitItem { kind: TraitItemKind::Const(..), .. }) + | Node::ImplItem(ImplItem { kind: ImplItemKind::Const(..), .. }) => Constness::Const, + _ => Constness::NotConst, } } diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.rs b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.rs index 087f8fbdcd1..8343974f8c7 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.rs @@ -1,7 +1,5 @@ -// FIXME(jschievink): this is not rejected correctly (only when the non-const impl is actually used) -// ignore-test - #![feature(const_trait_impl)] +#![feature(const_fn_trait_bound)] struct S; diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr new file mode 100644 index 00000000000..75c7cab3621 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr @@ -0,0 +1,14 @@ +error[E0277]: can't compare `S` with `S` + --> $DIR/call-generic-method-nonconst.rs:19:34 + | +LL | const fn equals_self<T: PartialEq>(t: &T) -> bool { + | --------- required by this bound in `equals_self` +... +LL | pub const EQ: bool = equals_self(&S); + | ^^ no implementation for `S == S` + | + = help: the trait `PartialEq` is not implemented for `S` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. |
