Skip to content
Merged
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
6 changes: 2 additions & 4 deletions compiler/rustc_middle/src/hir/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,9 @@ impl<'tcx> TyCtxt<'tcx> {
BodyOwnerKind::Static(mutability) => ConstContext::Static(mutability),

BodyOwnerKind::Fn if self.is_constructor(def_id) => return None,
// Const closures use their parent's const context
BodyOwnerKind::Closure if self.is_const_fn(def_id) => {
return self.hir_body_const_context(self.local_parent(local_def_id));
BodyOwnerKind::Fn | BodyOwnerKind::Closure if self.is_const_fn(def_id) => {
ConstContext::ConstFn
}
BodyOwnerKind::Fn if self.is_const_fn(def_id) => ConstContext::ConstFn,
BodyOwnerKind::Fn | BodyOwnerKind::Closure | BodyOwnerKind::GlobalAsm => return None,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0277]: the trait bound `(): const Bar` is not satisfied
error[E0277]: the trait bound `(): [const] Bar` is not satisfied
--> $DIR/call-const-closure.rs:16:18
|
LL | (const || ().foo())();
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/traits/const-traits/call-const-closure.old.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0277]: the trait bound `(): const Bar` is not satisfied
error[E0277]: the trait bound `(): [const] Bar` is not satisfied
--> $DIR/call-const-closure.rs:16:18
|
LL | (const || ().foo())();
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/traits/const-traits/call-const-closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl Bar for () {

const FOO: () = {
(const || ().foo())();
//~^ ERROR the trait bound `(): const Bar` is not satisfied
//~^ ERROR the trait bound `(): [const] Bar` is not satisfied
};

fn main() {}
11 changes: 11 additions & 0 deletions tests/ui/traits/const-traits/const-closure-fn-ptr-const-item.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//@ run-pass

// Regression test for https://github.com/rust-lang/rust/issues/155803

#![feature(const_closures, const_trait_impl)]

const F: fn() -> i32 = const || 42;

fn main() {
assert_eq!(F(), 42);
}
12 changes: 12 additions & 0 deletions tests/ui/traits/const-traits/const-closure-link-dead-code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@ build-pass
//@ compile-flags: -Clink-dead-code=true

// Regression test for https://github.com/rust-lang/rust/issues/155803

#![feature(const_closures, const_trait_impl)]

const _: () = {
assert!((const || true)());
};

fn main() {}
Loading