File tree Expand file tree Collapse file tree 2 files changed +55
-1
lines changed
src/tools/rust-analyzer/crates Expand file tree Collapse file tree 2 files changed +55
-1
lines changed Original file line number Diff line number Diff line change @@ -1047,10 +1047,14 @@ impl HirDisplay for Ty {
1047
1047
) ;
1048
1048
// We print all params except implicit impl Trait params. Still a bit weird; should we leave out parent and self?
1049
1049
if parameters. len ( ) - impl_ > 0 {
1050
+ let params_len = parameters. len ( ) ;
1050
1051
// `parameters` are in the order of fn's params (including impl traits), fn's lifetimes
1051
1052
let parameters =
1052
1053
generic_args_sans_defaults ( f, Some ( generic_def_id) , parameters) ;
1053
- let without_impl = self_param as usize + type_ + const_ + lifetime;
1054
+ assert ! ( params_len >= parameters. len( ) ) ;
1055
+ let defaults = params_len - parameters. len ( ) ;
1056
+ let without_impl =
1057
+ self_param as usize + type_ + const_ + lifetime - defaults;
1054
1058
// parent's params (those from enclosing impl or trait, if any).
1055
1059
let ( fn_params, parent_params) = parameters. split_at ( without_impl + impl_) ;
1056
1060
Original file line number Diff line number Diff line change @@ -9416,3 +9416,53 @@ fn f<T: UnCompat$0>
9416
9416
"# ] ] ,
9417
9417
) ;
9418
9418
}
9419
+
9420
+ #[ test]
9421
+ fn issue_18613 ( ) {
9422
+ check (
9423
+ r#"
9424
+ fn main() {
9425
+ struct S<T, D = bool>();
9426
+ let x$0 = S::<()>;
9427
+ }"# ,
9428
+ expect ! [ [ r#"
9429
+ *x*
9430
+
9431
+ ```rust
9432
+ let x: fn S<()>() -> S<()>
9433
+ ```
9434
+
9435
+ ---
9436
+
9437
+ size = 0, align = 1
9438
+ "# ] ] ,
9439
+ ) ;
9440
+
9441
+ check (
9442
+ r#"
9443
+ pub struct Global;
9444
+ pub struct Box<T, A = Global>(T, A);
9445
+
9446
+ impl<T> Box<T> {
9447
+ pub fn new(x: T) -> Self { loop {} }
9448
+ }
9449
+
9450
+ pub struct String;
9451
+
9452
+ fn main() {
9453
+ let box_value$0 = Box::<String>new();
9454
+ }
9455
+ "# ,
9456
+ expect ! [ [ r#"
9457
+ *box_value*
9458
+
9459
+ ```rust
9460
+ let box_value: fn Box<String>(String, Global) -> Box<String>
9461
+ ```
9462
+
9463
+ ---
9464
+
9465
+ size = 0, align = 1
9466
+ "# ] ] ,
9467
+ ) ;
9468
+ }
You can’t perform that action at this time.
0 commit comments