@@ -1301,6 +1301,7 @@ impl Clean<Constant> for hir::ConstArg {
13011301 type_ : cx. tcx . type_of ( cx. tcx . hir ( ) . body_owner_def_id ( self . value . body ) ) . clean ( cx) ,
13021302 expr : print_const_expr ( cx, self . value . body ) ,
13031303 value : None ,
1304+ is_literal : is_literal_expr ( cx, self . value . body . hir_id ) ,
13041305 }
13051306 }
13061307}
@@ -3276,6 +3277,7 @@ impl<'tcx> Clean<Constant> for ty::Const<'tcx> {
32763277 type_ : self . ty . clean ( cx) ,
32773278 expr : format ! ( "{}" , self ) ,
32783279 value : None ,
3280+ is_literal : false ,
32793281 }
32803282 }
32813283}
@@ -3834,11 +3836,13 @@ pub struct Constant {
38343836 pub type_ : Type ,
38353837 pub expr : String ,
38363838 pub value : Option < String > ,
3839+ pub is_literal : bool ,
38373840}
38383841
38393842impl Clean < Item > for doctree:: Constant < ' _ > {
38403843 fn clean ( & self , cx : & DocContext < ' _ > ) -> Item {
38413844 let def_id = cx. tcx . hir ( ) . local_def_id ( self . id ) ;
3845+
38423846 Item {
38433847 name : Some ( self . name . clean ( cx) ) ,
38443848 attrs : self . attrs . clean ( cx) ,
@@ -3851,6 +3855,7 @@ impl Clean<Item> for doctree::Constant<'_> {
38513855 type_ : self . type_ . clean ( cx) ,
38523856 expr : print_const_expr ( cx, self . expr ) ,
38533857 value : print_evaluated_const ( cx, def_id) ,
3858+ is_literal : is_literal_expr ( cx, self . expr . hir_id ) ,
38543859 } ) ,
38553860 }
38563861 }
@@ -4248,6 +4253,7 @@ pub fn print_evaluated_const(cx: &DocContext<'_>, def_id: DefId) -> Option<Strin
42484253 let value = cx. tcx . const_eval ( param_env. and ( cid) ) . ok ( ) . and_then ( |value| {
42494254 match ( value. val , & value. ty . kind ) {
42504255 ( _, ty:: Ref ( ..) ) => None ,
4256+ ( ty:: ConstKind :: Value ( ConstValue :: Scalar ( _) ) , ty:: Adt ( _, _) ) => None ,
42514257 ( ty:: ConstKind :: Value ( ConstValue :: Scalar ( _) ) , _) =>
42524258 Some ( print_const_with_custom_print_scalar ( cx, value) ) ,
42534259 _ => None ,
@@ -4310,6 +4316,22 @@ fn print_const_expr(cx: &DocContext<'_>, body: hir::BodyId) -> String {
43104316 cx. tcx . hir ( ) . hir_to_pretty_string ( body. hir_id )
43114317}
43124318
4319+ fn is_literal_expr ( cx : & DocContext < ' _ > , hir_id : hir:: HirId ) -> bool {
4320+ if let hir:: Node :: Expr ( expr) = cx. tcx . hir ( ) . get ( hir_id) {
4321+ if let hir:: ExprKind :: Lit ( _) = & expr. kind {
4322+ return true ;
4323+ }
4324+
4325+ if let hir:: ExprKind :: Unary ( hir:: UnOp :: UnNeg , expr) = & expr. kind {
4326+ if let hir:: ExprKind :: Lit ( _) = & expr. kind {
4327+ return true ;
4328+ }
4329+ }
4330+ }
4331+
4332+ false
4333+ }
4334+
43134335/// Given a type Path, resolve it to a Type using the TyCtxt
43144336fn resolve_type ( cx : & DocContext < ' _ > ,
43154337 path : Path ,
0 commit comments