mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-11-03 13:13:18 +00:00 
			
		
		
		
	Fix fixes for unused raw variables
Example
---
```
fn main() {
    let $0r#type = 2;
}
```
**Before this PR**:
```rust
fn main() {
    let _r#type = 2;
}
```
**After this PR**:
```rust
fn main() {
    let _type = 2;
}
```
			
			
This commit is contained in:
		
							parent
							
								
									bbb6459dc4
								
							
						
					
					
						commit
						4353624cc0
					
				@ -6,7 +6,7 @@ use ide_db::{
 | 
				
			|||||||
    label::Label,
 | 
					    label::Label,
 | 
				
			||||||
    source_change::SourceChange,
 | 
					    source_change::SourceChange,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use syntax::{AstNode, Edition, TextRange};
 | 
					use syntax::{AstNode, Edition, TextRange, ToSmolStr};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};
 | 
					use crate::{Diagnostic, DiagnosticCode, DiagnosticsContext};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -73,7 +73,8 @@ fn fixes(
 | 
				
			|||||||
    if is_in_marco {
 | 
					    if is_in_marco {
 | 
				
			||||||
        return None;
 | 
					        return None;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    let name = var_name.display(db, edition);
 | 
					    let name = var_name.display(db, edition).to_smolstr();
 | 
				
			||||||
 | 
					    let name = name.strip_prefix("r#").unwrap_or(&name);
 | 
				
			||||||
    let new_name = if is_shorthand_field { format!("{name}: _{name}") } else { format!("_{name}") };
 | 
					    let new_name = if is_shorthand_field { format!("{name}: _{name}") } else { format!("_{name}") };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Some(vec![Assist {
 | 
					    Some(vec![Assist {
 | 
				
			||||||
@ -231,6 +232,19 @@ fn main() {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					"#,
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        check_fix(
 | 
				
			||||||
 | 
					            r#"
 | 
				
			||||||
 | 
					fn main() {
 | 
				
			||||||
 | 
					    let $0r#type = 2;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					"#,
 | 
				
			||||||
 | 
					            r#"
 | 
				
			||||||
 | 
					fn main() {
 | 
				
			||||||
 | 
					    let _type = 2;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
"#,
 | 
					"#,
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user