mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-10-31 12:04:43 +00:00 
			
		
		
		
	fix: Fix env/option_env macro check disregarding macro_rules definitions
				
					
				
			This commit is contained in:
		
							parent
							
								
									fff668052b
								
							
						
					
					
						commit
						acccd4bde6
					
				
					 2 changed files with 41 additions and 35 deletions
				
			
		|  | @ -3046,14 +3046,23 @@ impl Macro { | ||||||
|             MacroId::Macro2Id(it) => { |             MacroId::Macro2Id(it) => { | ||||||
|                 matches!(it.lookup(db.upcast()).expander, MacroExpander::BuiltInEager(eager) if eager.is_env_or_option_env()) |                 matches!(it.lookup(db.upcast()).expander, MacroExpander::BuiltInEager(eager) if eager.is_env_or_option_env()) | ||||||
|             } |             } | ||||||
|             MacroId::MacroRulesId(_) | MacroId::ProcMacroId(_) => false, |             MacroId::MacroRulesId(it) => { | ||||||
|  |                 matches!(it.lookup(db.upcast()).expander, MacroExpander::BuiltInEager(eager) if eager.is_env_or_option_env()) | ||||||
|  |             } | ||||||
|  |             MacroId::ProcMacroId(_) => false, | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub fn is_asm_or_global_asm(&self, db: &dyn HirDatabase) -> bool { |     pub fn is_asm_or_global_asm(&self, db: &dyn HirDatabase) -> bool { | ||||||
|         matches!(self.id, MacroId::Macro2Id(it) if { |         match self.id { | ||||||
|             matches!(it.lookup(db.upcast()).expander, MacroExpander::BuiltIn(m) if m.is_asm()) |             MacroId::Macro2Id(it) => { | ||||||
|         }) |                 matches!(it.lookup(db.upcast()).expander, MacroExpander::BuiltIn(m) if m.is_asm()) | ||||||
|  |             } | ||||||
|  |             MacroId::MacroRulesId(it) => { | ||||||
|  |                 matches!(it.lookup(db.upcast()).expander, MacroExpander::BuiltIn(m) if m.is_asm()) | ||||||
|  |             } | ||||||
|  |             MacroId::ProcMacroId(_) => false, | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub fn is_attr(&self, db: &dyn HirDatabase) -> bool { |     pub fn is_attr(&self, db: &dyn HirDatabase) -> bool { | ||||||
|  |  | ||||||
|  | @ -68,43 +68,40 @@ pub(crate) fn complete_cargo_env_vars( | ||||||
| mod tests { | mod tests { | ||||||
|     use crate::tests::{check_edit, completion_list}; |     use crate::tests::{check_edit, completion_list}; | ||||||
| 
 | 
 | ||||||
|     fn check(macro_name: &str) { |  | ||||||
|         check_edit( |  | ||||||
|             "CARGO_BIN_NAME", |  | ||||||
|             &format!( |  | ||||||
|                 r#" |  | ||||||
|             #[rustc_builtin_macro] |  | ||||||
|             macro {macro_name} {{ |  | ||||||
|                 ($var:literal) => {{ 0 }} |  | ||||||
|             }} |  | ||||||
| 
 |  | ||||||
|             fn main() {{ |  | ||||||
|                 let foo = {macro_name}!("CAR$0"); |  | ||||||
|             }} |  | ||||||
|         "#
 |  | ||||||
|             ), |  | ||||||
|             &format!( |  | ||||||
|                 r#" |  | ||||||
|             #[rustc_builtin_macro] |  | ||||||
|             macro {macro_name} {{ |  | ||||||
|                 ($var:literal) => {{ 0 }} |  | ||||||
|             }} |  | ||||||
| 
 |  | ||||||
|             fn main() {{ |  | ||||||
|                 let foo = {macro_name}!("CARGO_BIN_NAME"); |  | ||||||
|             }} |  | ||||||
|         "#
 |  | ||||||
|             ), |  | ||||||
|         ); |  | ||||||
|     } |  | ||||||
|     #[test] |     #[test] | ||||||
|     fn completes_env_variable_in_env() { |     fn completes_env_variable_in_env() { | ||||||
|         check("env") |         check_edit( | ||||||
|  |             "CARGO_BIN_NAME", | ||||||
|  |             r#" | ||||||
|  | //- minicore: env
 | ||||||
|  | fn main() { | ||||||
|  |     let foo = env!("CAR$0"); | ||||||
|  | } | ||||||
|  |         "#,
 | ||||||
|  |             r#" | ||||||
|  | fn main() { | ||||||
|  |     let foo = env!("CARGO_BIN_NAME"); | ||||||
|  | } | ||||||
|  |         "#,
 | ||||||
|  |         ); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #[test] |     #[test] | ||||||
|     fn completes_env_variable_in_option_env() { |     fn completes_env_variable_in_option_env() { | ||||||
|         check("option_env"); |         check_edit( | ||||||
|  |             "CARGO_BIN_NAME", | ||||||
|  |             r#" | ||||||
|  | //- minicore: env
 | ||||||
|  | fn main() { | ||||||
|  |     let foo = option_env!("CAR$0"); | ||||||
|  | } | ||||||
|  |         "#,
 | ||||||
|  |             r#" | ||||||
|  | fn main() { | ||||||
|  |     let foo = option_env!("CARGO_BIN_NAME"); | ||||||
|  | } | ||||||
|  |         "#,
 | ||||||
|  |         ); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #[test] |     #[test] | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lukas Wirth
						Lukas Wirth