File tree Expand file tree Collapse file tree 3 files changed +43
-6
lines changed Expand file tree Collapse file tree 3 files changed +43
-6
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ use hir_expand::name;
5252use la_arena:: { Arena , Idx } ;
5353use mir:: { MirEvalError , VTableMap } ;
5454use rustc_hash:: FxHashSet ;
55+ use syntax:: AstNode ;
5556use traits:: FnTrait ;
5657use triomphe:: Arc ;
5758use utils:: Generics ;
@@ -723,12 +724,12 @@ where
723724
724725pub fn known_const_to_string ( konst : & Const , db : & dyn HirDatabase ) -> Option < String > {
725726 if let ConstValue :: Concrete ( c) = & konst. interned ( ) . value {
726- if let ConstScalar :: UnevaluatedConst ( GeneralConstId :: InTypeConstId ( _ ) , _ ) = & c. interned {
727- // FIXME: stringify the block expression
728- return None ;
729- }
730- if c . interned == ConstScalar :: Unknown {
731- return None ;
727+ match c. interned {
728+ ConstScalar :: UnevaluatedConst ( GeneralConstId :: InTypeConstId ( cid ) , _ ) => {
729+ return Some ( cid . source ( db . upcast ( ) ) . syntax ( ) . to_string ( ) ) ;
730+ }
731+ ConstScalar :: Unknown => return None ,
732+ _ => ( ) ,
732733 }
733734 }
734735 Some ( konst. display ( db) . to_string ( ) )
Original file line number Diff line number Diff line change @@ -549,6 +549,41 @@ impl m::Foo for () {
549549 )
550550 }
551551
552+ #[ test]
553+ fn test_const_substitution_with_defaults_3 ( ) {
554+ check_assist (
555+ add_missing_default_members,
556+ r#"
557+ mod m {
558+ pub const VAL: usize = 0;
559+
560+ pub trait Foo<const N: usize = {40 + 2}, const M: usize = {VAL + 1}> {
561+ fn get_n(&self) -> usize { N }
562+ fn get_m(&self) -> usize { M }
563+ }
564+ }
565+
566+ impl m::Foo for () {
567+ $0
568+ }"# ,
569+ r#"
570+ mod m {
571+ pub const VAL: usize = 0;
572+
573+ pub trait Foo<const N: usize = {40 + 2}, const M: usize = {VAL + 1}> {
574+ fn get_n(&self) -> usize { N }
575+ fn get_m(&self) -> usize { M }
576+ }
577+ }
578+
579+ impl m::Foo for () {
580+ $0fn get_n(&self) -> usize { {40 + 2} }
581+
582+ fn get_m(&self) -> usize { {m::VAL + 1} }
583+ }"# ,
584+ )
585+ }
586+
552587 #[ test]
553588 fn test_cursor_after_empty_impl_def ( ) {
554589 check_assist (
Original file line number Diff line number Diff line change @@ -156,6 +156,7 @@ impl<'a> PathTransform<'a> {
156156 // is a standalone statement or a part of another expresson)
157157 // and sometimes require slight modifications; see
158158 // https://doc.rust-lang.org/reference/statements.html#expression-statements
159+ // (default values in curly brackets can cause the same problem)
159160 const_substs. insert ( k, expr. syntax ( ) . clone ( ) ) ;
160161 }
161162 }
You can’t perform that action at this time.
0 commit comments