Skip to content

Commit 6ee27ce

Browse files
authored
Rollup merge of #165487 - fmease:built-in-macro-to-internal-syntax, r=mati865
Migrate built-in macros `pattern_type` & `view_type` to macros 2.0 that expand to internal syntax Part of MCP-approved #110680. Best reviewed commit by commit. Please see individual commit messages for further details. Pinging owner of pattern types @oli-obk & owner of view types @scrabsha for visibility. <sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
2 parents 1c88d5b + d965694 commit 6ee27ce

126 files changed

Lines changed: 366 additions & 561 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎compiler/rustc_ast_passes/src/feature_gate.rs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
241241
// Function pointers cannot be `const`
242242
self.check_late_bound_lifetime_defs(&fn_ptr_ty.generic_params);
243243
}
244-
ast::TyKind::Pat(..) => {
245-
gate!(self, pattern_types, ty.span, "pattern types are unstable");
246-
}
247-
ast::TyKind::View(..) => {
248-
gate!(self, view_types, ty.span, "view types are unstable");
249-
}
250244
_ => {}
251245
}
252246
visit::walk_ty(self, ty)
@@ -469,7 +463,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
469463
gate_all!(unnamed_enum_variants, "unnamed enum variants are experimental");
470464
gate_all!(unsafe_binders, "unsafe binder types are experimental");
471465
gate_all!(unsafe_fields, "`unsafe` fields are experimental");
472-
gate_all!(view_types, "view types are experimental");
473466
gate_all!(where_clause_attrs, "attributes in `where` clause are unstable");
474467
gate_all!(yeet_expr, "`do yeet` expression is experimental");
475468
// tidy-alphabetical-end

‎compiler/rustc_ast_pretty/src/pprust/state.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,9 +1437,12 @@ impl<'a> State<'a> {
14371437
self.word("...");
14381438
}
14391439
ast::TyKind::Pat(ty, pat) => {
1440+
self.word("k#pattern_type");
1441+
self.popen();
14401442
self.print_type(ty);
14411443
self.word(" is ");
14421444
self.print_ty_pat(pat);
1445+
self.pclose();
14431446
}
14441447
ast::TyKind::FieldOf(ty, variant, field) => {
14451448
self.word("k#field_of");
@@ -1459,8 +1462,11 @@ impl<'a> State<'a> {
14591462
self.pclose();
14601463
}
14611464
ast::TyKind::View(ty, fields) => {
1465+
self.word("k#view_type");
1466+
self.popen();
14621467
self.print_type(ty);
14631468
self.print_view(fields);
1469+
self.pclose();
14641470
}
14651471
ast::TyKind::GcaMacro(expr) => {
14661472
self.word_nbsp("core::gca!");

‎compiler/rustc_ast_pretty/src/pprust/tests.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,6 @@ fn test_field_view() {
8080
};
8181

8282
let ty_str = ty_to_string(&ty);
83-
assert_eq!(ty_str, "(/*DUMMY*/).{ milhouse, apu }");
83+
assert_eq!(ty_str, "k#view_type((/*DUMMY*/).{ milhouse, apu })");
8484
});
8585
}

‎compiler/rustc_builtin_macros/src/lib.rs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,11 @@ mod global_allocator;
4545
mod iter;
4646
mod log_syntax;
4747
mod offload;
48-
mod pattern_type;
4948
mod rustdoc_skip_body;
5049
mod source_util;
5150
mod test;
5251
mod test_binder_constraints;
5352
mod trace_macros;
54-
mod view_type;
5553

5654
pub mod asm;
5755
pub mod cmdline_attrs;
@@ -100,13 +98,11 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
10098
module_path: source_util::expand_mod,
10199
naked_asm: asm::expand_naked_asm,
102100
option_env: env::expand_option_env,
103-
pattern_type: pattern_type::expand,
104101
std_panic: edition_panic::expand_panic,
105102
stringify: source_util::expand_stringify,
106103
test_binder_constraints: test_binder_constraints::expand,
107104
trace_macros: trace_macros::expand_trace_macros,
108105
unreachable: edition_panic::expand_unreachable,
109-
view_type: view_type::expand,
110106
// tidy-alphabetical-end
111107
}
112108

‎compiler/rustc_builtin_macros/src/pattern_type.rs‎

Lines changed: 0 additions & 75 deletions
This file was deleted.

‎compiler/rustc_builtin_macros/src/view_type.rs‎

Lines changed: 0 additions & 47 deletions
This file was deleted.

‎compiler/rustc_codegen_cranelift/example/mini_core.rs‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
extern_types,
77
decl_macro,
88
rustc_attrs,
9+
allow_internal_unstable,
10+
forced_keywords,
911
rustc_private,
1012
transparent_unions,
11-
pattern_types,
1213
auto_traits,
1314
freeze_impls
1415
)]
@@ -591,12 +592,9 @@ pub trait Deref {
591592
fn deref(&self) -> &Self::Target;
592593
}
593594

594-
#[rustc_builtin_macro(pattern_type)]
595-
#[macro_export]
596-
macro_rules! pattern_type {
597-
($($arg:tt)*) => {
598-
/* compiler built-in */
599-
};
595+
#[allow_internal_unstable(internal_syntax)]
596+
pub macro pattern_type($($arg:tt)*) {
597+
k#pattern_type($($arg)*)
600598
}
601599

602600
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<pattern_type!(*const U is !null)> for pattern_type!(*const T is !null) where

‎compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
#![feature(
2-
no_core,
3-
lang_items,
4-
extern_types,
5-
thread_local,
6-
repr_simd,
7-
pattern_types,
8-
rustc_private
9-
)]
1+
#![feature(no_core, lang_items, extern_types, thread_local, repr_simd, rustc_private)]
102
#![cfg_attr(not(any(jit, target_vendor = "apple", windows)), feature(linkage))]
113
#![no_core]
124
#![allow(dead_code, non_camel_case_types, internal_features)]

‎compiler/rustc_codegen_gcc/build_system/src/test.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ fn mini_tests(env: &Env, args: &TestArg) -> Result<(), String> {
247247
&"mini_core",
248248
&"--crate-type",
249249
&crate_types,
250+
&"--edition",
251+
&"2024",
250252
&"--target",
251253
&args.config_info.target_triple,
252254
]);

‎compiler/rustc_codegen_gcc/example/mini_core.rs‎

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
extern_types,
77
decl_macro,
88
rustc_attrs,
9+
allow_internal_unstable,
10+
forced_keywords,
911
transparent_unions,
1012
auto_traits,
1113
freeze_impls,
12-
pattern_types,
1314
thread_local,
1415
rustc_private
1516
)]
@@ -40,9 +41,9 @@ unsafe extern "C" {
4041
type VTable;
4142
}
4243

43-
#[no_mangle]
44+
#[unsafe(no_mangle)]
4445
unsafe extern "C" fn _Unwind_Resume() {
45-
intrinsics::unreachable();
46+
unsafe { intrinsics::unreachable(); }
4647
}
4748

4849
#[lang = "pointee_sized"]
@@ -607,12 +608,9 @@ impl Allocator for Global {}
607608
#[rustc_nonnull_optimization_guaranteed]
608609
pub struct NonNull<T: PointeeSized>(pub pattern_type!(*const T is !null));
609610

610-
#[rustc_builtin_macro(pattern_type)]
611-
#[macro_export]
612-
macro_rules! pattern_type {
613-
($($arg:tt)*) => {
614-
/* compiler built-in */
615-
};
611+
#[allow_internal_unstable(internal_syntax)]
612+
pub macro pattern_type($($arg:tt)*) {
613+
k#pattern_type($($arg)*)
616614
}
617615

618616
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<pattern_type!(*const U is !null)> for pattern_type!(*const T is !null) where
@@ -703,19 +701,19 @@ pub mod intrinsics {
703701
#[rustc_intrinsic]
704702
pub const fn size_of<T>() -> usize;
705703
#[rustc_intrinsic]
706-
pub unsafe fn size_of_val<T: ?::Sized>(val: *const T) -> usize;
704+
pub unsafe fn size_of_val<T: ?crate::Sized>(val: *const T) -> usize;
707705
#[rustc_intrinsic]
708706
pub const fn align_of<T>() -> usize;
709707
#[rustc_intrinsic]
710-
pub unsafe fn align_of_val<T: ?::Sized>(val: *const T) -> usize;
708+
pub unsafe fn align_of_val<T: ?crate::Sized>(val: *const T) -> usize;
711709
#[rustc_intrinsic]
712710
pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize);
713711
#[rustc_intrinsic]
714712
pub unsafe fn transmute<T, U>(e: T) -> U;
715713
#[rustc_intrinsic]
716714
pub unsafe fn ctlz_nonzero<T>(x: T) -> u32;
717715
#[rustc_intrinsic]
718-
pub const fn needs_drop<T: ?::Sized>() -> bool;
716+
pub const fn needs_drop<T: ?crate::Sized>() -> bool;
719717
#[rustc_intrinsic]
720718
pub fn bitreverse<T>(x: T) -> T;
721719
#[rustc_intrinsic]
@@ -728,7 +726,7 @@ pub mod intrinsics {
728726

729727
pub mod libc {
730728
#[link(name = "c")]
731-
extern "C" {
729+
unsafe extern "C" {
732730
pub fn puts(s: *const u8) -> i32;
733731
pub fn printf(format: *const i8, ...) -> i32;
734732
pub fn malloc(size: usize) -> *mut u8;
@@ -783,7 +781,7 @@ impl<T> Index<usize> for [T] {
783781
}
784782
}
785783

786-
extern "C" {
784+
unsafe extern "C" {
787785
type VaListImpl;
788786
}
789787

@@ -824,7 +822,7 @@ struct PanicLocation {
824822
column: u32,
825823
}
826824

827-
#[no_mangle]
825+
#[unsafe(no_mangle)]
828826
pub fn get_tls() -> u8 {
829827
#[thread_local]
830828
static A: u8 = 42;

0 commit comments

Comments
 (0)