Skip to content

Commit bf5492f

Browse files
committed
Auto merge of #12671 - flodiebold:test-for-12669, r=flodiebold
Add tests for #12669
2 parents 994f3cf + c69e07f commit bf5492f

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

crates/hir-ty/src/tests/macros.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,3 +1274,64 @@ impl S {
12741274
"#]],
12751275
);
12761276
}
1277+
1278+
fn infer_in_unexpandable_attr_proc_macro_1() {
1279+
check_types(
1280+
r#"
1281+
//- /main.rs crate:main deps:mac
1282+
#[mac::attr_macro]
1283+
fn foo() {
1284+
let xxx = 1;
1285+
//^^^ i32
1286+
}
1287+
1288+
//- /mac.rs crate:mac
1289+
#![crate_type="proc-macro"]
1290+
#[proc_macro_attribute]
1291+
pub fn attr_macro() {}
1292+
"#,
1293+
);
1294+
}
1295+
1296+
#[test]
1297+
fn infer_in_unexpandable_attr_proc_macro_in_impl() {
1298+
check_types(
1299+
r#"
1300+
//- /main.rs crate:main deps:mac
1301+
struct Foo;
1302+
impl Foo {
1303+
#[mac::attr_macro]
1304+
fn foo() {
1305+
let xxx = 1;
1306+
//^^^ i32
1307+
}
1308+
}
1309+
1310+
//- /mac.rs crate:mac
1311+
#![crate_type="proc-macro"]
1312+
#[proc_macro_attribute]
1313+
pub fn attr_macro() {}
1314+
"#,
1315+
);
1316+
}
1317+
1318+
#[test]
1319+
fn infer_in_unexpandable_attr_proc_macro_in_trait() {
1320+
check_types(
1321+
r#"
1322+
//- /main.rs crate:main deps:mac
1323+
trait Foo {
1324+
#[mac::attr_macro]
1325+
fn foo() {
1326+
let xxx = 1;
1327+
//^^^ i32
1328+
}
1329+
}
1330+
1331+
//- /mac.rs crate:mac
1332+
#![crate_type="proc-macro"]
1333+
#[proc_macro_attribute]
1334+
pub fn attr_macro() {}
1335+
"#,
1336+
);
1337+
}

crates/ide-diagnostics/src/handlers/inactive_code.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,25 @@ fn f() {
104104
);
105105
}
106106

107+
#[test]
108+
#[should_panic] // currently doesn't work
109+
fn inactive_assoc_item() {
110+
check(
111+
r#"
112+
struct Foo;
113+
impl Foo {
114+
#[cfg(any())] pub fn f() {}
115+
//^^^^^^^^^^^^^^^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives
116+
}
117+
118+
trait Bar {
119+
#[cfg(any())] pub fn f() {}
120+
//^^^^^^^^^^^^^^^^^^^^^^^^^^^ weak: code is inactive due to #[cfg] directives
121+
}
122+
"#,
123+
);
124+
}
125+
107126
/// Tests that `cfg` attributes behind `cfg_attr` is handled properly.
108127
#[test]
109128
fn inactive_via_cfg_attr() {

0 commit comments

Comments
 (0)