Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ fn mir_promoted(

let const_qualifs = match tcx.def_kind(def) {
DefKind::Fn | DefKind::AssocFn | DefKind::Closure
if tcx.constness(def) == hir::Constness::Const =>
if tcx.hir_body_const_context(def).is_some() =>
{
tcx.mir_const_qualif(def)
}
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/traits/const-traits/issue-153891.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Regression test for issue #153891.
#![feature(const_closures)]

trait Tr {
const fn test() {
//~^ ERROR functions in traits cannot be declared const
(const || {})()
}
}

fn main() {}
12 changes: 12 additions & 0 deletions tests/ui/traits/const-traits/issue-153891.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0379]: functions in traits cannot be declared const
--> $DIR/issue-153891.rs:5:5
|
LL | const fn test() {
| ^^^^^-
| |
| functions in traits cannot be const
| help: remove the `const`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0379`.
Loading