forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Const-eval more constants during MIR building
- Loading branch information
Showing
2 changed files
with
23 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -514,17 +514,29 @@ fn convert_arm<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, arm: &'tcx hir::Arm) -> Arm< | |
|
||
fn convert_path_expr<'a, 'tcx: 'a>(cx: &mut Cx<'a, 'tcx>, expr: &'tcx hir::Expr) -> ExprKind<'tcx> { | ||
let substs = cx.tcx.mk_substs(cx.tcx.node_id_item_substs(expr.id).substs); | ||
match cx.tcx.def_map.borrow()[&expr.id].full_def() { | ||
// Otherwise there may be def_map borrow conflicts | ||
let def = { cx.tcx.def_map.borrow()[&expr.id].full_def() }; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
nagisa
Author
Owner
|
||
match def { | ||
def::DefVariant(_, def_id, false) | | ||
def::DefStruct(def_id) | | ||
def::DefFn(def_id, _) | | ||
def::DefConst(def_id) | | ||
def::DefMethod(def_id) | | ||
def::DefAssociatedConst(def_id) => | ||
def::DefMethod(def_id) => | ||
ExprKind::Literal { | ||
literal: Literal::Item { def_id: def_id, substs: substs } | ||
}, | ||
|
||
def::DefConst(def_id) | | ||
def::DefAssociatedConst(def_id) => { | ||
if let Some(v) = cx.try_const_eval_literal(expr) { | ||
ExprKind::Literal { literal: v } | ||
} else { | ||
ExprKind::Literal { | ||
literal: Literal::Item { def_id: def_id, substs: substs } | ||
} | ||
} | ||
} | ||
|
||
|
||
def::DefStatic(node_id, _) => | ||
ExprKind::StaticRef { | ||
id: node_id, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Nit: braces are not needed, just the
let
will do.