Skip to content

Commit f39206f

Browse files
internal: minicore: add the Hash derive macro to the prelude
This commit adds the core::hash::Hash derive macro to the prelude, just like rustc does. They define the macro in a private core::hash::macros module, presumably to differentiate between the macro and trait (who otherwise share the same path). Only the macro is in the prelude, which minicore now mirrors. I've also added support for multiple "line regions" in minicore, as the prelude re-export needs both "hash" and "derive". The syntax looks as follows: "// :hash, derive".
1 parent 5b7c812 commit f39206f

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

crates/test-utils/src/fixture.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,12 @@ impl MiniCore {
427427
continue;
428428
}
429429

430-
let mut line_region = false;
430+
let mut line_regions = 0;
431431
if let Some(idx) = trimmed.find("// :") {
432-
line_region = true;
433-
active_regions.push(&trimmed[idx + "// :".len()..]);
432+
for region in trimmed[idx + "// :".len()..].split(", ") {
433+
active_regions.push(region);
434+
line_regions += 1;
435+
}
434436
}
435437

436438
let mut keep = true;
@@ -444,9 +446,8 @@ impl MiniCore {
444446
if keep {
445447
buf.push_str(line);
446448
}
447-
if line_region {
448-
active_regions.pop().unwrap();
449-
}
449+
450+
active_regions.truncate(active_regions.len() - line_regions);
450451
}
451452

452453
if !active_regions.is_empty() {

crates/test-utils/src/minicore.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,12 @@ pub mod hash {
199199
}
200200

201201
// region:derive
202-
#[rustc_builtin_macro]
203-
pub macro Hash($item:item) {}
202+
pub(crate) mod macros {
203+
#[rustc_builtin_macro]
204+
pub macro Hash($item:item) {}
205+
}
206+
207+
pub use macros::Hash;
204208
// endregion:derive
205209
}
206210
// endregion:hash
@@ -1678,6 +1682,7 @@ pub mod prelude {
16781682
convert::AsRef, // :as_ref
16791683
convert::{From, Into}, // :from
16801684
default::Default, // :default
1685+
hash::macros::Hash, // :hash, derive
16811686
iter::{IntoIterator, Iterator}, // :iterator
16821687
macros::builtin::{derive, derive_const}, // :derive
16831688
marker::Copy, // :copy

0 commit comments

Comments
 (0)