Skip to content

Commit 711ead6

Browse files
authored
Merge pull request #22784 from ChayimFriedman2/no-stdlib-macrouse
fix: Do not `#[macro_use]` the sysroot crates
2 parents 5f8f3ea + 2a422f9 commit 711ead6

3 files changed

Lines changed: 17 additions & 43 deletions

File tree

crates/hir-def/src/nameres/collector.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,26 +1877,13 @@ impl ModCollector<'_, '_> {
18771877
}
18781878

18791879
fn collect(&mut self, items: &[ModItemId], container: ItemContainerId) {
1880-
let krate = self.def_collector.def_map.krate;
18811880
let is_crate_root = self.module_id == self.def_collector.def_map.root
18821881
&& self.def_collector.def_map.block.is_none();
18831882

18841883
// Note: don't assert that inserted value is fresh: it's simply not true
18851884
// for macros.
18861885
self.def_collector.mod_dirs.insert(self.module_id, self.mod_dir.clone());
18871886

1888-
// Prelude module is always considered to be `#[macro_use]`.
1889-
if let Some((prelude_module, _use)) = self.def_collector.def_map.prelude {
1890-
// Don't insert macros from the prelude into blocks, as they can be shadowed by other macros.
1891-
if is_crate_root && prelude_module.krate(self.def_collector.db) != krate {
1892-
cov_mark::hit!(prelude_is_macro_use);
1893-
self.def_collector.import_macros_from_extern_crate(
1894-
prelude_module.krate(self.def_collector.db),
1895-
None,
1896-
None,
1897-
);
1898-
}
1899-
}
19001887
let db = self.def_collector.db;
19011888
let module_id = self.module_id;
19021889
let consider_deferred_derives =

crates/hir-def/src/nameres/tests/macros.rs

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -339,36 +339,19 @@ macro_rules! baz3 { () => { struct OkBaz3; } }
339339
}
340340

341341
#[test]
342-
fn prelude_is_macro_use() {
343-
cov_mark::check!(prelude_is_macro_use);
342+
fn prelude_is_not_macro_use() {
344343
check(
345344
r#"
346345
//- /main.rs edition:2018 crate:main deps:std
347346
structs!(Foo);
348-
structs_priv!(Bar);
349-
structs_outside!(Out);
350-
crate::structs!(MacroNotResolved2);
351-
352-
mod bar;
353-
354-
//- /bar.rs
355-
structs!(Baz);
356-
crate::structs!(MacroNotResolved3);
347+
structs_outside!(MacroNotResolved);
357348
358349
//- /lib.rs crate:std
359350
pub mod prelude {
360351
pub mod rust_2018 {
361-
#[macro_export]
362-
macro_rules! structs {
352+
pub macro structs {
363353
($i:ident) => { struct $i; }
364354
}
365-
366-
mod priv_mod {
367-
#[macro_export]
368-
macro_rules! structs_priv {
369-
($i:ident) => { struct $i; }
370-
}
371-
}
372355
}
373356
}
374357
@@ -379,13 +362,7 @@ macro_rules! structs_outside {
379362
"#,
380363
expect![[r#"
381364
crate
382-
- Bar : type value
383365
- Foo : type value
384-
- Out : type value
385-
- bar : type
386-
387-
crate::bar
388-
- Baz : type value
389366
"#]],
390367
);
391368
}
@@ -743,12 +720,11 @@ foo!();
743720
pub use core::foo;
744721
745722
pub mod prelude {
746-
pub mod rust_2018 {}
723+
pub mod rust_2018 {
724+
pub use crate::foo;
725+
}
747726
}
748727
749-
#[macro_use]
750-
mod std_macros;
751-
752728
//- /core.rs crate:core
753729
#[macro_export]
754730
macro_rules! foo {

crates/test-utils/src/minicore.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,6 +2515,7 @@ macro_rules! matches {
25152515

25162516
pub mod prelude {
25172517
pub mod v1 {
2518+
#[rustfmt::skip]
25182519
pub use crate::{
25192520
clone::Clone, // :clone
25202521
cmp::{Eq, PartialEq}, // :eq
@@ -2541,6 +2542,16 @@ pub mod prelude {
25412542
panic, // :panic
25422543
result::Result::{self, Err, Ok}, // :result
25432544
str::FromStr, // :str
2545+
write, writeln, // :write
2546+
assert, // :assert
2547+
format_args, format_args_nl, const_format_args, print, // :fmt
2548+
todo, // :todo
2549+
unimplemented, // :unimplemented
2550+
include, // :include
2551+
include_bytes, // :include_bytes
2552+
concat, // :concat
2553+
env, option_env, // :env
2554+
matches, // :matches
25442555
};
25452556
}
25462557

0 commit comments

Comments
 (0)