Skip to content

Commit

Permalink
Spruce up the docs of several queries related to the type/trait syste…
Browse files Browse the repository at this point in the history
…m and const eval
  • Loading branch information
fmease committed Dec 26, 2024
1 parent f334342 commit 8d08447
Show file tree
Hide file tree
Showing 2 changed files with 194 additions and 101 deletions.
14 changes: 4 additions & 10 deletions compiler/rustc_const_eval/src/const_eval/fn_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,14 @@ fn parent_impl_constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness
}
}

/// Checks whether an item is considered to be `const`. If it is a constructor, it is const.
/// If it is an assoc method or function,
/// return if it has a `const` modifier. If it is an intrinsic, report whether said intrinsic
/// has a `rustc_const_{un,}stable` attribute. Otherwise, panic.
/// Checks whether a function-like definition is considered to be `const`.
fn constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {
let node = tcx.hir_node_by_def_id(def_id);

match node {
hir::Node::Ctor(hir::VariantData::Tuple(..))
| hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Const(..), .. }) => {
hir::Constness::Const
}
hir::Node::ForeignItem(_) => {
// Foreign items cannot be evaluated at compile-time.
hir::Node::Ctor(hir::VariantData::Tuple(..)) => hir::Constness::Const,
hir::Node::ForeignItem(item) if let hir::ForeignItemKind::Fn(..) = item.kind => {
// Foreign functions cannot be evaluated at compile-time.
hir::Constness::NotConst
}
hir::Node::Expr(e) if let hir::ExprKind::Closure(c) = e.kind => c.constness,
Expand Down
Loading

0 comments on commit 8d08447

Please sign in to comment.