Skip to content

Commit 32b86a8

Browse files
authored
Merge pull request #18884 from Veykril/push-xwqkorxozzkq
fix: Fix `env`/`option_env` macro check disregarding macro_rules definitions
2 parents 1e975d6 + acccd4b commit 32b86a8

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
lines changed

crates/hir/src/lib.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -3046,14 +3046,23 @@ impl Macro {
30463046
MacroId::Macro2Id(it) => {
30473047
matches!(it.lookup(db.upcast()).expander, MacroExpander::BuiltInEager(eager) if eager.is_env_or_option_env())
30483048
}
3049-
MacroId::MacroRulesId(_) | MacroId::ProcMacroId(_) => false,
3049+
MacroId::MacroRulesId(it) => {
3050+
matches!(it.lookup(db.upcast()).expander, MacroExpander::BuiltInEager(eager) if eager.is_env_or_option_env())
3051+
}
3052+
MacroId::ProcMacroId(_) => false,
30503053
}
30513054
}
30523055

30533056
pub fn is_asm_or_global_asm(&self, db: &dyn HirDatabase) -> bool {
3054-
matches!(self.id, MacroId::Macro2Id(it) if {
3055-
matches!(it.lookup(db.upcast()).expander, MacroExpander::BuiltIn(m) if m.is_asm())
3056-
})
3057+
match self.id {
3058+
MacroId::Macro2Id(it) => {
3059+
matches!(it.lookup(db.upcast()).expander, MacroExpander::BuiltIn(m) if m.is_asm())
3060+
}
3061+
MacroId::MacroRulesId(it) => {
3062+
matches!(it.lookup(db.upcast()).expander, MacroExpander::BuiltIn(m) if m.is_asm())
3063+
}
3064+
MacroId::ProcMacroId(_) => false,
3065+
}
30573066
}
30583067

30593068
pub fn is_attr(&self, db: &dyn HirDatabase) -> bool {

crates/ide-completion/src/completions/env_vars.rs

+27-30
Original file line numberDiff line numberDiff line change
@@ -68,43 +68,40 @@ pub(crate) fn complete_cargo_env_vars(
6868
mod tests {
6969
use crate::tests::{check_edit, completion_list};
7070

71-
fn check(macro_name: &str) {
71+
#[test]
72+
fn completes_env_variable_in_env() {
7273
check_edit(
7374
"CARGO_BIN_NAME",
74-
&format!(
75-
r#"
76-
#[rustc_builtin_macro]
77-
macro {macro_name} {{
78-
($var:literal) => {{ 0 }}
79-
}}
80-
81-
fn main() {{
82-
let foo = {macro_name}!("CAR$0");
83-
}}
84-
"#
85-
),
86-
&format!(
87-
r#"
88-
#[rustc_builtin_macro]
89-
macro {macro_name} {{
90-
($var:literal) => {{ 0 }}
91-
}}
92-
93-
fn main() {{
94-
let foo = {macro_name}!("CARGO_BIN_NAME");
95-
}}
96-
"#
97-
),
75+
r#"
76+
//- minicore: env
77+
fn main() {
78+
let foo = env!("CAR$0");
79+
}
80+
"#,
81+
r#"
82+
fn main() {
83+
let foo = env!("CARGO_BIN_NAME");
84+
}
85+
"#,
9886
);
9987
}
100-
#[test]
101-
fn completes_env_variable_in_env() {
102-
check("env")
103-
}
10488

10589
#[test]
10690
fn completes_env_variable_in_option_env() {
107-
check("option_env");
91+
check_edit(
92+
"CARGO_BIN_NAME",
93+
r#"
94+
//- minicore: env
95+
fn main() {
96+
let foo = option_env!("CAR$0");
97+
}
98+
"#,
99+
r#"
100+
fn main() {
101+
let foo = option_env!("CARGO_BIN_NAME");
102+
}
103+
"#,
104+
);
108105
}
109106

110107
#[test]

0 commit comments

Comments
 (0)