mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-10-31 12:04:43 +00:00 
			
		
		
		
	Merge pull request #19094 from ChayimFriedman2/use-body
fix: Fix IDE resolution of `use` inside a body
This commit is contained in:
		
						commit
						2ad4ec5b73
					
				
					 3 changed files with 43 additions and 3 deletions
				
			
		|  | @ -1252,7 +1252,11 @@ fn scope_for( | ||||||
|     node: InFile<&SyntaxNode>, |     node: InFile<&SyntaxNode>, | ||||||
| ) -> Option<ScopeId> { | ) -> Option<ScopeId> { | ||||||
|     node.ancestors_with_macros(db.upcast()) |     node.ancestors_with_macros(db.upcast()) | ||||||
|         .take_while(|it| !ast::Item::can_cast(it.kind()) || ast::MacroCall::can_cast(it.kind())) |         .take_while(|it| { | ||||||
|  |             !ast::Item::can_cast(it.kind()) | ||||||
|  |                 || ast::MacroCall::can_cast(it.kind()) | ||||||
|  |                 || ast::Use::can_cast(it.kind()) | ||||||
|  |         }) | ||||||
|         .filter_map(|it| it.map(ast::Expr::cast).transpose()) |         .filter_map(|it| it.map(ast::Expr::cast).transpose()) | ||||||
|         .filter_map(|it| source_map.node_expr(it.as_ref())?.as_expr()) |         .filter_map(|it| source_map.node_expr(it.as_ref())?.as_expr()) | ||||||
|         .find_map(|it| scopes.scope_for(it)) |         .find_map(|it| scopes.scope_for(it)) | ||||||
|  |  | ||||||
|  | @ -3268,6 +3268,24 @@ impl core::fmt::Display for A { | ||||||
| } | } | ||||||
| fn f() { | fn f() { | ||||||
|     A.to_string$0(); |     A.to_string$0(); | ||||||
|  | } | ||||||
|  |         "#,
 | ||||||
|  |         ); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     #[test] | ||||||
|  |     fn use_inside_body() { | ||||||
|  |         check( | ||||||
|  |             r#" | ||||||
|  | fn main() { | ||||||
|  |     mod nice_module { | ||||||
|  |         pub(super) struct NiceStruct; | ||||||
|  |                        // ^^^^^^^^^^
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     use nice_module::NiceStruct$0; | ||||||
|  | 
 | ||||||
|  |     let _ = NiceStruct; | ||||||
| } | } | ||||||
|     "#,
 |     "#,
 | ||||||
|         ); |         ); | ||||||
|  |  | ||||||
|  | @ -2001,19 +2001,37 @@ impl Foo { | ||||||
|             "foo", |             "foo", | ||||||
|             r#" |             r#" | ||||||
| fn f($0self) -> i32 { | fn f($0self) -> i32 { | ||||||
|     use self as _; |  | ||||||
|     self.i |     self.i | ||||||
| } | } | ||||||
| "#,
 | "#,
 | ||||||
|             r#" |             r#" | ||||||
| fn f(foo: _) -> i32 { | fn f(foo: _) -> i32 { | ||||||
|     use self as _; |  | ||||||
|     foo.i |     foo.i | ||||||
| } | } | ||||||
| "#,
 | "#,
 | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     #[test] | ||||||
|  |     fn no_type_value_ns_confuse() { | ||||||
|  |         // Test that we don't rename items from different namespaces.
 | ||||||
|  |         check( | ||||||
|  |             "bar", | ||||||
|  |             r#" | ||||||
|  | struct foo {} | ||||||
|  | fn f(foo$0: i32) -> i32 { | ||||||
|  |     use foo as _; | ||||||
|  | } | ||||||
|  | "#,
 | ||||||
|  |             r#" | ||||||
|  | struct foo {} | ||||||
|  | fn f(bar: i32) -> i32 { | ||||||
|  |     use foo as _; | ||||||
|  | } | ||||||
|  | "#,
 | ||||||
|  |         ); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     #[test] |     #[test] | ||||||
|     fn test_self_in_path_to_parameter() { |     fn test_self_in_path_to_parameter() { | ||||||
|         check( |         check( | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Laurențiu Nicola
						Laurențiu Nicola