Skip to content

Commit e715195

Browse files
committed
Add tests for rust-lang#12669
1 parent 994f3cf commit e715195

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

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

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

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+
fn inactive_assoc_item() {
109+
// FIXME these currently don't work, hence the *
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)