File tree Expand file tree Collapse file tree 5 files changed +90
-2
lines changed
src/tools/rust-analyzer/crates Expand file tree Collapse file tree 5 files changed +90
-2
lines changed Original file line number Diff line number Diff line change @@ -642,9 +642,9 @@ impl Resolver {
642
642
} )
643
643
}
644
644
645
- pub fn generic_params ( & self ) -> Option < & Arc < GenericParams > > {
645
+ pub fn generic_params ( & self ) -> Option < & GenericParams > {
646
646
self . scopes ( ) . find_map ( |scope| match scope {
647
- Scope :: GenericParams { params, .. } => Some ( params) ,
647
+ Scope :: GenericParams { params, .. } => Some ( & * * params) ,
648
648
_ => None ,
649
649
} )
650
650
}
Original file line number Diff line number Diff line change @@ -1517,6 +1517,10 @@ impl<'db> SemanticsImpl<'db> {
1517
1517
self . analyze ( path. syntax ( ) ) ?. resolve_path ( self . db , path)
1518
1518
}
1519
1519
1520
+ pub fn resolve_use_type_arg ( & self , name : & ast:: NameRef ) -> Option < TypeParam > {
1521
+ self . analyze ( name. syntax ( ) ) ?. resolve_use_type_arg ( name)
1522
+ }
1523
+
1520
1524
pub fn resolve_mod_path (
1521
1525
& self ,
1522
1526
scope : & SyntaxNode ,
Original file line number Diff line number Diff line change @@ -642,6 +642,14 @@ impl SourceAnalyzer {
642
642
}
643
643
}
644
644
645
+ pub ( crate ) fn resolve_use_type_arg ( & self , name : & ast:: NameRef ) -> Option < crate :: TypeParam > {
646
+ let name = name. as_name ( ) ;
647
+ self . resolver
648
+ . all_generic_params ( )
649
+ . find_map ( |( params, parent) | params. find_type_by_name ( & name, * parent) )
650
+ . map ( crate :: TypeParam :: from)
651
+ }
652
+
645
653
pub ( crate ) fn resolve_path (
646
654
& self ,
647
655
db : & dyn HirDatabase ,
Original file line number Diff line number Diff line change @@ -733,6 +733,12 @@ impl NameRefClass {
733
733
}
734
734
None
735
735
} ,
736
+ ast:: UseBoundGenericArgs ( _) => {
737
+ sema. resolve_use_type_arg( name_ref)
738
+ . map( GenericParam :: TypeParam )
739
+ . map( Definition :: GenericParam )
740
+ . map( NameRefClass :: Definition )
741
+ } ,
736
742
ast:: ExternCrate ( extern_crate_ast) => {
737
743
let extern_crate = sema. to_def( & extern_crate_ast) ?;
738
744
let krate = extern_crate. resolved_crate( sema. db) ?;
@@ -764,6 +770,7 @@ impl NameRefClass {
764
770
sema. resolve_label ( lifetime) . map ( Definition :: Label ) . map ( NameRefClass :: Definition )
765
771
}
766
772
SyntaxKind :: LIFETIME_ARG
773
+ | SyntaxKind :: USE_BOUND_GENERIC_ARGS
767
774
| SyntaxKind :: SELF_PARAM
768
775
| SyntaxKind :: TYPE_BOUND
769
776
| SyntaxKind :: WHERE_PRED
Original file line number Diff line number Diff line change @@ -3102,6 +3102,75 @@ fn main() { let _: S; }
3102
3102
r#"
3103
3103
use lib::S as Baz;
3104
3104
fn main() { let _: Baz; }
3105
+ "# ,
3106
+ ) ;
3107
+ }
3108
+
3109
+ #[ test]
3110
+ fn rename_type_param_ref_in_use_bound ( ) {
3111
+ check (
3112
+ "U" ,
3113
+ r#"
3114
+ fn foo<T>() -> impl use<T$0> Trait {}
3115
+ "# ,
3116
+ r#"
3117
+ fn foo<U>() -> impl use<U> Trait {}
3118
+ "# ,
3119
+ ) ;
3120
+ }
3121
+
3122
+ #[ test]
3123
+ fn rename_type_param_in_use_bound ( ) {
3124
+ check (
3125
+ "U" ,
3126
+ r#"
3127
+ fn foo<T$0>() -> impl use<T> Trait {}
3128
+ "# ,
3129
+ r#"
3130
+ fn foo<U>() -> impl use<U> Trait {}
3131
+ "# ,
3132
+ ) ;
3133
+ }
3134
+
3135
+ #[ test]
3136
+ fn rename_lifetime_param_ref_in_use_bound ( ) {
3137
+ check (
3138
+ "u" ,
3139
+ r#"
3140
+ fn foo<'t>() -> impl use<'t$0> Trait {}
3141
+ "# ,
3142
+ r#"
3143
+ fn foo<'u>() -> impl use<'u> Trait {}
3144
+ "# ,
3145
+ ) ;
3146
+ }
3147
+
3148
+ #[ test]
3149
+ fn rename_lifetime_param_in_use_bound ( ) {
3150
+ check (
3151
+ "u" ,
3152
+ r#"
3153
+ fn foo<'t$0>() -> impl use<'t> Trait {}
3154
+ "# ,
3155
+ r#"
3156
+ fn foo<'u>() -> impl use<'u> Trait {}
3157
+ "# ,
3158
+ ) ;
3159
+ }
3160
+
3161
+ #[ test]
3162
+ fn rename_parent_type_param_in_use_bound ( ) {
3163
+ check (
3164
+ "U" ,
3165
+ r#"
3166
+ trait Trait<T> {
3167
+ fn foo() -> impl use<T$0> Trait {}
3168
+ }
3169
+ "# ,
3170
+ r#"
3171
+ trait Trait<U> {
3172
+ fn foo() -> impl use<U> Trait {}
3173
+ }
3105
3174
"# ,
3106
3175
) ;
3107
3176
}
You can’t perform that action at this time.
0 commit comments