Skip to content

Commit 143ce09

Browse files
committed
Auto merge of #132877 - matthiaskrgr:rollup-hbxg7p0, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - #131781 (Stabilize Arm64EC inline assembly) - #132426 (Prefer `pub(super)` in `unreachable_pub` lint suggestion) - #132866 (Break from review rotation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2128d8d + bf62717 commit 143ce09

File tree

11 files changed

+314
-49
lines changed

11 files changed

+314
-49
lines changed

Diff for: compiler/rustc_ast_lowering/src/asm.rs

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
4545
| asm::InlineAsmArch::X86_64
4646
| asm::InlineAsmArch::Arm
4747
| asm::InlineAsmArch::AArch64
48+
| asm::InlineAsmArch::Arm64EC
4849
| asm::InlineAsmArch::RiscV32
4950
| asm::InlineAsmArch::RiscV64
5051
| asm::InlineAsmArch::LoongArch64

Diff for: compiler/rustc_lint/src/builtin.rs

+18
Original file line numberDiff line numberDiff line change
@@ -1298,12 +1298,30 @@ impl UnreachablePub {
12981298
let mut applicability = Applicability::MachineApplicable;
12991299
if cx.tcx.visibility(def_id).is_public() && !cx.effective_visibilities.is_reachable(def_id)
13001300
{
1301+
// prefer suggesting `pub(super)` instead of `pub(crate)` when possible,
1302+
// except when `pub(super) == pub(crate)`
1303+
let new_vis = if let Some(ty::Visibility::Restricted(restricted_did)) =
1304+
cx.effective_visibilities.effective_vis(def_id).map(|effective_vis| {
1305+
effective_vis.at_level(rustc_middle::middle::privacy::Level::Reachable)
1306+
})
1307+
&& let parent_parent = cx.tcx.parent_module_from_def_id(
1308+
cx.tcx.parent_module_from_def_id(def_id.into()).into(),
1309+
)
1310+
&& *restricted_did == parent_parent.to_local_def_id()
1311+
&& !restricted_did.to_def_id().is_crate_root()
1312+
{
1313+
"pub(super)"
1314+
} else {
1315+
"pub(crate)"
1316+
};
1317+
13011318
if vis_span.from_expansion() {
13021319
applicability = Applicability::MaybeIncorrect;
13031320
}
13041321
let def_span = cx.tcx.def_span(def_id);
13051322
cx.emit_span_lint(UNREACHABLE_PUB, def_span, BuiltinUnreachablePub {
13061323
what,
1324+
new_vis,
13071325
suggestion: (vis_span, applicability),
13081326
help: exportable,
13091327
});

Diff for: compiler/rustc_lint/src/lints.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ impl<'a> LintDiagnostic<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> {
254254
#[diag(lint_builtin_unreachable_pub)]
255255
pub(crate) struct BuiltinUnreachablePub<'a> {
256256
pub what: &'a str,
257-
#[suggestion(code = "pub(crate)")]
257+
pub new_vis: &'a str,
258+
#[suggestion(code = "{new_vis}")]
258259
pub suggestion: (Span, Applicability),
259260
#[help]
260261
pub help: bool,

Diff for: src/doc/unstable-book/src/language-features/asm-experimental-arch.md

+2-30
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ This feature tracks `asm!` and `global_asm!` support for the following architect
1818
- MSP430
1919
- M68k
2020
- CSKY
21-
- Arm64EC
2221
- SPARC
2322

2423
## Register classes
@@ -53,9 +52,6 @@ This feature tracks `asm!` and `global_asm!` support for the following architect
5352
| CSKY | `freg` | `f[0-31]` | `f` |
5453
| SPARC | `reg` | `r[2-29]` | `r` |
5554
| SPARC | `yreg` | `y` | Only clobbers |
56-
| Arm64EC | `reg` | `x[0-12]`, `x[15-22]`, `x[25-27]`, `x30` | `r` |
57-
| Arm64EC | `vreg` | `v[0-15]` | `w` |
58-
| Arm64EC | `vreg_low16` | `v[0-15]` | `x` |
5955

6056
> **Notes**:
6157
> - NVPTX doesn't have a fixed register set, so named registers are not supported.
@@ -92,8 +88,6 @@ This feature tracks `asm!` and `global_asm!` support for the following architect
9288
| CSKY | `freg` | None | `f32`, |
9389
| SPARC | `reg` | None | `i8`, `i16`, `i32`, `i64` (SPARC64 only) |
9490
| SPARC | `yreg` | N/A | Only clobbers |
95-
| Arm64EC | `reg` | None | `i8`, `i16`, `i32`, `f32`, `i64`, `f64` |
96-
| Arm64EC | `vreg` | None | `i8`, `i16`, `i32`, `f32`, `i64`, `f64`, <br> `i8x8`, `i16x4`, `i32x2`, `i64x1`, `f32x2`, `f64x1`, <br> `i8x16`, `i16x8`, `i32x4`, `i64x2`, `f32x4`, `f64x2` |
9791

9892
## Register aliases
9993

@@ -134,12 +128,6 @@ This feature tracks `asm!` and `global_asm!` support for the following architect
134128
| SPARC | `r[8-15]` | `o[0-7]` |
135129
| SPARC | `r[16-23]` | `l[0-7]` |
136130
| SPARC | `r[24-31]` | `i[0-7]` |
137-
| Arm64EC | `x[0-30]` | `w[0-30]` |
138-
| Arm64EC | `x29` | `fp` |
139-
| Arm64EC | `x30` | `lr` |
140-
| Arm64EC | `sp` | `wsp` |
141-
| Arm64EC | `xzr` | `wzr` |
142-
| Arm64EC | `v[0-15]` | `b[0-15]`, `h[0-15]`, `s[0-15]`, `d[0-15]`, `q[0-15]` |
143131

144132
> **Notes**:
145133
> - TI does not mandate a frame pointer for MSP430, but toolchains are allowed
@@ -150,8 +138,8 @@ This feature tracks `asm!` and `global_asm!` support for the following architect
150138
| Architecture | Unsupported register | Reason |
151139
| ------------ | --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
152140
| All | `sp`, `r14`/`o6` (SPARC) | The stack pointer must be restored to its original value at the end of an asm code block. |
153-
| All | `fr` (Hexagon), `fp` (PowerPC), `$fp` (MIPS), `Y` (AVR), `r4` (MSP430), `a6` (M68k), `r30`/`i6` (SPARC), `x29` (Arm64EC) | The frame pointer cannot be used as an input or output. |
154-
| All | `r19` (Hexagon), `r29` (PowerPC), `r30` (PowerPC), `x19` (Arm64EC) | These are used internally by LLVM as "base pointer" for functions with complex stack frames. |
141+
| All | `fr` (Hexagon), `fp` (PowerPC), `$fp` (MIPS), `Y` (AVR), `r4` (MSP430), `a6` (M68k), `r30`/`i6` (SPARC) | The frame pointer cannot be used as an input or output. |
142+
| All | `r19` (Hexagon), `r29` (PowerPC), `r30` (PowerPC) | These are used internally by LLVM as "base pointer" for functions with complex stack frames. |
155143
| MIPS | `$0` or `$zero` | This is a constant zero register which can't be modified. |
156144
| MIPS | `$1` or `$at` | Reserved for assembler. |
157145
| MIPS | `$26`/`$k0`, `$27`/`$k1` | OS-reserved registers. |
@@ -176,9 +164,6 @@ This feature tracks `asm!` and `global_asm!` support for the following architect
176164
| SPARC | `r5`/`g5` | Reserved for system. (SPARC32 only) |
177165
| SPARC | `r6`/`g6`, `r7`/`g7` | Reserved for system. |
178166
| SPARC | `r31`/`i7` | Return address cannot be used as inputs or outputs. |
179-
| Arm64EC | `xzr` | This is a constant zero register which can't be modified. |
180-
| Arm64EC | `x18` | This is an OS-reserved register. |
181-
| Arm64EC | `x13`, `x14`, `x23`, `x24`, `x28`, `v[16-31]` | These are AArch64 registers that are not supported for Arm64EC. |
182167

183168

184169
## Template modifiers
@@ -197,16 +182,6 @@ This feature tracks `asm!` and `global_asm!` support for the following architect
197182
| SPARC | `reg` | None | `%o0` | None |
198183
| CSKY | `reg` | None | `r0` | None |
199184
| CSKY | `freg` | None | `f0` | None |
200-
| Arm64EC | `reg` | None | `x0` | `x` |
201-
| Arm64EC | `reg` | `w` | `w0` | `w` |
202-
| Arm64EC | `reg` | `x` | `x0` | `x` |
203-
| Arm64EC | `vreg` | None | `v0` | None |
204-
| Arm64EC | `vreg` | `v` | `v0` | None |
205-
| Arm64EC | `vreg` | `b` | `b0` | `b` |
206-
| Arm64EC | `vreg` | `h` | `h0` | `h` |
207-
| Arm64EC | `vreg` | `s` | `s0` | `s` |
208-
| Arm64EC | `vreg` | `d` | `d0` | `d` |
209-
| Arm64EC | `vreg` | `q` | `q0` | `q` |
210185

211186
# Flags covered by `preserves_flags`
212187

@@ -220,6 +195,3 @@ These flags registers must be restored upon exiting the asm block if the `preser
220195
- SPARC
221196
- Integer condition codes (`icc` and `xcc`)
222197
- Floating-point condition codes (`fcc[0-3]`)
223-
- Arm64EC
224-
- Condition flags (`NZCV` register).
225-
- Floating-point status (`FPSR` register).

Diff for: tests/assembly/asm/aarch64-types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//@ [arm64ec] needs-llvm-components: aarch64
77
//@ compile-flags: -Zmerge-functions=disabled
88

9-
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_experimental_arch, f16, f128)]
9+
#![feature(no_core, lang_items, rustc_attrs, repr_simd, f16, f128)]
1010
#![crate_type = "rlib"]
1111
#![no_core]
1212
#![allow(asm_sub_register, non_camel_case_types)]

Diff for: tests/codegen/asm/arm64ec-clobbers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//@ needs-llvm-components: aarch64
44

55
#![crate_type = "rlib"]
6-
#![feature(no_core, rustc_attrs, lang_items, asm_experimental_arch)]
6+
#![feature(no_core, rustc_attrs, lang_items)]
77
#![no_core]
88

99
#[lang = "sized"]

Diff for: tests/ui/asm/aarch64/arm64ec-sve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//@ needs-llvm-components: aarch64
44

55
#![crate_type = "rlib"]
6-
#![feature(no_core, rustc_attrs, lang_items, asm_experimental_arch)]
6+
#![feature(no_core, rustc_attrs, lang_items)]
77
#![no_core]
88

99
// SVE cannot be used for Arm64EC

Diff for: tests/ui/lint/unreachable_pub.fixed

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
//@ check-pass
2+
//@ edition: 2018
3+
//@ run-rustfix
4+
5+
#![allow(unused)]
6+
#![warn(unreachable_pub)]
7+
8+
mod private_mod {
9+
// non-leaked `pub` items in private module should be linted
10+
pub(crate) use std::fmt; //~ WARNING unreachable_pub
11+
pub(crate) use std::env::{Args}; // braced-use has different item spans than unbraced
12+
//~^ WARNING unreachable_pub
13+
14+
// we lint on struct definition
15+
pub(crate) struct Hydrogen { //~ WARNING unreachable_pub
16+
// but not on fields, even if they are `pub` as putting `pub(crate)`
17+
// it would clutter the source code for little value
18+
pub neutrons: usize,
19+
pub(crate) electrons: usize
20+
}
21+
pub(crate) struct Calcium {
22+
pub neutrons: usize,
23+
}
24+
impl Hydrogen {
25+
// impls, too
26+
pub(crate) fn count_neutrons(&self) -> usize { self.neutrons } //~ WARNING unreachable_pub
27+
pub(crate) fn count_electrons(&self) -> usize { self.electrons }
28+
}
29+
impl Clone for Hydrogen {
30+
fn clone(&self) -> Hydrogen {
31+
Hydrogen { neutrons: self.neutrons, electrons: self.electrons }
32+
}
33+
}
34+
35+
pub(crate) enum Helium {} //~ WARNING unreachable_pub
36+
pub(crate) union Lithium { c1: usize, c2: u8 } //~ WARNING unreachable_pub
37+
pub(crate) fn beryllium() {} //~ WARNING unreachable_pub
38+
pub(crate) trait Boron {} //~ WARNING unreachable_pub
39+
pub(crate) const CARBON: usize = 1; //~ WARNING unreachable_pub
40+
pub(crate) static NITROGEN: usize = 2; //~ WARNING unreachable_pub
41+
pub(crate) type Oxygen = bool; //~ WARNING unreachable_pub
42+
43+
macro_rules! define_empty_struct_with_visibility {
44+
($visibility: vis, $name: ident) => { $visibility struct $name {} }
45+
//~^ WARNING unreachable_pub
46+
}
47+
define_empty_struct_with_visibility!(pub(crate), Fluorine);
48+
49+
extern "C" {
50+
pub(crate) fn catalyze() -> bool; //~ WARNING unreachable_pub
51+
}
52+
53+
mod private_in_private {
54+
pub(super) enum Helium {} //~ WARNING unreachable_pub
55+
pub(super) fn beryllium() {} //~ WARNING unreachable_pub
56+
}
57+
58+
pub(crate) mod crate_in_private {
59+
pub(crate) const CARBON: usize = 1; //~ WARNING unreachable_pub
60+
}
61+
62+
pub(crate) mod pub_in_private { //~ WARNING unreachable_pub
63+
pub(crate) static NITROGEN: usize = 2; //~ WARNING unreachable_pub
64+
}
65+
66+
fn foo() {
67+
const {
68+
pub(crate) struct Foo; //~ WARNING unreachable_pub
69+
};
70+
}
71+
72+
enum Weird {
73+
Variant = {
74+
pub(crate) struct Foo; //~ WARNING unreachable_pub
75+
76+
mod tmp {
77+
pub(crate) struct Bar; //~ WARNING unreachable_pub
78+
}
79+
80+
let _ = tmp::Bar;
81+
82+
0
83+
},
84+
}
85+
86+
pub(crate) use fpu_precision::set_precision; //~ WARNING unreachable_pub
87+
88+
mod fpu_precision {
89+
pub(crate) fn set_precision<T>() {} //~ WARNING unreachable_pub
90+
pub(super) fn set_micro_precision<T>() {} //~ WARNING unreachable_pub
91+
}
92+
93+
// items leaked through signatures (see `get_neon` below) are OK
94+
pub struct Neon {}
95+
96+
// crate-visible items are OK
97+
pub(crate) struct Sodium {}
98+
}
99+
100+
pub mod public_mod {
101+
// module is public: these are OK, too
102+
pub struct Magnesium {}
103+
pub(crate) struct Aluminum {}
104+
}
105+
106+
pub fn get_neon() -> private_mod::Neon {
107+
private_mod::Neon {}
108+
}
109+
110+
fn main() {
111+
let _ = get_neon();
112+
let _ = private_mod::beryllium();
113+
let _ = private_mod::crate_in_private::CARBON;
114+
let _ = private_mod::pub_in_private::NITROGEN;
115+
let _ = unsafe { private_mod::catalyze() };
116+
}

Diff for: tests/ui/lint/unreachable_pub.rs

+46
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//@ check-pass
2+
//@ edition: 2018
3+
//@ run-rustfix
24

35
#![allow(unused)]
46
#![warn(unreachable_pub)]
@@ -48,6 +50,46 @@ mod private_mod {
4850
pub fn catalyze() -> bool; //~ WARNING unreachable_pub
4951
}
5052

53+
mod private_in_private {
54+
pub enum Helium {} //~ WARNING unreachable_pub
55+
pub fn beryllium() {} //~ WARNING unreachable_pub
56+
}
57+
58+
pub(crate) mod crate_in_private {
59+
pub const CARBON: usize = 1; //~ WARNING unreachable_pub
60+
}
61+
62+
pub mod pub_in_private { //~ WARNING unreachable_pub
63+
pub static NITROGEN: usize = 2; //~ WARNING unreachable_pub
64+
}
65+
66+
fn foo() {
67+
const {
68+
pub struct Foo; //~ WARNING unreachable_pub
69+
};
70+
}
71+
72+
enum Weird {
73+
Variant = {
74+
pub struct Foo; //~ WARNING unreachable_pub
75+
76+
mod tmp {
77+
pub struct Bar; //~ WARNING unreachable_pub
78+
}
79+
80+
let _ = tmp::Bar;
81+
82+
0
83+
},
84+
}
85+
86+
pub use fpu_precision::set_precision; //~ WARNING unreachable_pub
87+
88+
mod fpu_precision {
89+
pub fn set_precision<T>() {} //~ WARNING unreachable_pub
90+
pub fn set_micro_precision<T>() {} //~ WARNING unreachable_pub
91+
}
92+
5193
// items leaked through signatures (see `get_neon` below) are OK
5294
pub struct Neon {}
5395

@@ -67,4 +109,8 @@ pub fn get_neon() -> private_mod::Neon {
67109

68110
fn main() {
69111
let _ = get_neon();
112+
let _ = private_mod::beryllium();
113+
let _ = private_mod::crate_in_private::CARBON;
114+
let _ = private_mod::pub_in_private::NITROGEN;
115+
let _ = unsafe { private_mod::catalyze() };
70116
}

0 commit comments

Comments
 (0)