File tree 3 files changed +43
-6
lines changed 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;
52
52
use la_arena:: { Arena , Idx } ;
53
53
use mir:: { MirEvalError , VTableMap } ;
54
54
use rustc_hash:: FxHashSet ;
55
+ use syntax:: AstNode ;
55
56
use traits:: FnTrait ;
56
57
use triomphe:: Arc ;
57
58
use utils:: Generics ;
@@ -723,12 +724,12 @@ where
723
724
724
725
pub fn known_const_to_string ( konst : & Const , db : & dyn HirDatabase ) -> Option < String > {
725
726
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
+ _ => ( ) ,
732
733
}
733
734
}
734
735
Some ( konst. display ( db) . to_string ( ) )
Original file line number Diff line number Diff line change @@ -532,6 +532,41 @@ impl m::Foo for () {
532
532
)
533
533
}
534
534
535
+ #[ test]
536
+ fn test_const_substitution_with_defaults_3 ( ) {
537
+ check_assist (
538
+ add_missing_default_members,
539
+ r#"
540
+ mod m {
541
+ pub const VAL: usize = 0;
542
+
543
+ pub trait Foo<const N: usize = {40 + 2}, const M: usize = {VAL + 1}> {
544
+ fn get_n(&self) -> usize { N }
545
+ fn get_m(&self) -> usize { M }
546
+ }
547
+ }
548
+
549
+ impl m::Foo for () {
550
+ $0
551
+ }"# ,
552
+ r#"
553
+ mod m {
554
+ pub const VAL: usize = 0;
555
+
556
+ pub trait Foo<const N: usize = {40 + 2}, const M: usize = {VAL + 1}> {
557
+ fn get_n(&self) -> usize { N }
558
+ fn get_m(&self) -> usize { M }
559
+ }
560
+ }
561
+
562
+ impl m::Foo for () {
563
+ $0fn get_n(&self) -> usize { {40 + 2} }
564
+
565
+ fn get_m(&self) -> usize { {m::VAL + 1} }
566
+ }"# ,
567
+ )
568
+ }
569
+
535
570
#[ test]
536
571
fn test_cursor_after_empty_impl_def ( ) {
537
572
check_assist (
Original file line number Diff line number Diff line change @@ -156,6 +156,7 @@ impl<'a> PathTransform<'a> {
156
156
// is a standalone statement or a part of another expresson)
157
157
// and sometimes require slight modifications; see
158
158
// https://doc.rust-lang.org/reference/statements.html#expression-statements
159
+ // (default values in curly brackets can cause the same problem)
159
160
const_substs. insert ( k, expr. syntax ( ) . clone ( ) ) ;
160
161
}
161
162
}
You can’t perform that action at this time.
0 commit comments