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 {
642642 } )
643643 }
644644
645- pub fn generic_params ( & self ) -> Option < & Arc < GenericParams > > {
645+ pub fn generic_params ( & self ) -> Option < & GenericParams > {
646646 self . scopes ( ) . find_map ( |scope| match scope {
647- Scope :: GenericParams { params, .. } => Some ( params) ,
647+ Scope :: GenericParams { params, .. } => Some ( & * * params) ,
648648 _ => None ,
649649 } )
650650 }
Original file line number Diff line number Diff line change @@ -1517,6 +1517,10 @@ impl<'db> SemanticsImpl<'db> {
15171517 self . analyze ( path. syntax ( ) ) ?. resolve_path ( self . db , path)
15181518 }
15191519
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+
15201524 pub fn resolve_mod_path (
15211525 & self ,
15221526 scope : & SyntaxNode ,
Original file line number Diff line number Diff line change @@ -642,6 +642,14 @@ impl SourceAnalyzer {
642642 }
643643 }
644644
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+
645653 pub ( crate ) fn resolve_path (
646654 & self ,
647655 db : & dyn HirDatabase ,
Original file line number Diff line number Diff line change @@ -733,6 +733,12 @@ impl NameRefClass {
733733 }
734734 None
735735 } ,
736+ ast:: UseBoundGenericArgs ( _) => {
737+ sema. resolve_use_type_arg( name_ref)
738+ . map( GenericParam :: TypeParam )
739+ . map( Definition :: GenericParam )
740+ . map( NameRefClass :: Definition )
741+ } ,
736742 ast:: ExternCrate ( extern_crate_ast) => {
737743 let extern_crate = sema. to_def( & extern_crate_ast) ?;
738744 let krate = extern_crate. resolved_crate( sema. db) ?;
@@ -764,6 +770,7 @@ impl NameRefClass {
764770 sema. resolve_label ( lifetime) . map ( Definition :: Label ) . map ( NameRefClass :: Definition )
765771 }
766772 SyntaxKind :: LIFETIME_ARG
773+ | SyntaxKind :: USE_BOUND_GENERIC_ARGS
767774 | SyntaxKind :: SELF_PARAM
768775 | SyntaxKind :: TYPE_BOUND
769776 | SyntaxKind :: WHERE_PRED
Original file line number Diff line number Diff line change @@ -3102,6 +3102,75 @@ fn main() { let _: S; }
31023102 r#"
31033103use lib::S as Baz;
31043104fn 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+ }
31053174"# ,
31063175 ) ;
31073176 }
You can’t perform that action at this time.
0 commit comments