TODO: implement promoted constant
(
&mut self,
// _user_ty: Option<UserTypeAnnotationIndex>, // TODO: Is this argument useful?
literal: &Const<'tcx>,
)
| 725 | |
| 726 | // TODO: implement promoted constant |
| 727 | fn visit_constant( |
| 728 | &mut self, |
| 729 | // _user_ty: Option<UserTypeAnnotationIndex>, // TODO: Is this argument useful? |
| 730 | literal: &Const<'tcx>, |
| 731 | ) -> Rc<SymbolicValue> { |
| 732 | let mut kind = literal.kind(); |
| 733 | // let lty = literal.ty(); |
| 734 | // let mut val = literal.val; |
| 735 | // let ty = literal.ty; |
| 736 | |
| 737 | if let rustc_middle::ty::ConstKind::Unevaluated(_unevaluated) = &kind { |
| 738 | let infcx = self |
| 739 | .body_visitor |
| 740 | .context |
| 741 | .tcx |
| 742 | .infer_ctxt() |
| 743 | .build(TypingMode::non_body_analysis()); |
| 744 | kind = rustc_trait_selection::traits::evaluate_const( |
| 745 | &infcx, |
| 746 | *literal, |
| 747 | self.body_visitor.type_visitor.get_param_env(), |
| 748 | ) |
| 749 | .kind() |
| 750 | } |
| 751 | |
| 752 | let result; |
| 753 | |
| 754 | match &kind { |
| 755 | rustc_middle::ty::ConstKind::Param(ParamConst { index, .. }) => { |
| 756 | if let Some(gen_args) = self.body_visitor.type_visitor.generic_arguments { |
| 757 | if let Some(arg_val) = gen_args.as_ref().get(*index as usize) { |
| 758 | return self.visit_constant(&arg_val.expect_const()); |
| 759 | } |
| 760 | } else { |
| 761 | return symbolic_value::BOTTOM.into(); |
| 762 | } |
| 763 | unreachable!( |
| 764 | "reference to unmatched generic constant argument {:?} {:?}", |
| 765 | literal, self.body_visitor.current_span |
| 766 | ); |
| 767 | } |
| 768 | // ZSTs, integers, `bool`, `char` and small structs are represented as scalars. |
| 769 | // See the `ScalarInt` documentation for how `ScalarInt` guarantees that equal values |
| 770 | // of these types have the same representation. |
| 771 | rustc_middle::ty::ConstKind::Value(lty, ValTree::Leaf(scalar_int)) => { |
| 772 | let (data, size) = Self::get_scalar_int_data(scalar_int); |
| 773 | result = self.get_constant_from_scalar(*lty, data, size); |
| 774 | // self.get_constant_value_from_scalar(lty, data, size) |
| 775 | } |
| 776 | // The fields of any kind of aggregate. Structs, tuples and arrays are represented by |
| 777 | // listing their fields' values in order. |
| 778 | // Enums are represented by storing their discriminant as a field, followed by all |
| 779 | // the fields of the variant. |
| 780 | rustc_middle::ty::ConstKind::Value(lty, val_tree) => { |
| 781 | let heap_block = self.get_heap_block_and_path(*lty, val_tree); |
| 782 | // self.deserialize_val_tree(val_tree, heap_path, lty); |
| 783 | return heap_block; |
| 784 | } |
no test coverage detected