Skip to content

Commit da1e442

Browse files
committed
Auto merge of #140838 - Zalathar:rollup-13hybry, r=Zalathar
Rollup of 5 pull requests Successful merges: - #140801 (Use span before macro expansion in lint for-loops-over-falibles) - #140804 (add signed ints to unn- transmutes to ensure feature parity) - #140812 (Fix `tests/rustdoc-json` triagebot message path) - #140817 (bootstrap: more consistent use of `...` when citing configuration snippets) - #140828 (Enable non-leaf Frame Pointers for Arm64 Windows) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a7b1b24 + d91e86e commit da1e442

File tree

11 files changed

+137
-23
lines changed

11 files changed

+137
-23
lines changed

compiler/rustc_lint/src/for_loops_over_fallibles.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ impl<'tcx> LateLintPass<'tcx> for ForLoopsOverFallibles {
4949
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
5050
let Some((pat, arg)) = extract_for_loop(expr) else { return };
5151

52+
let arg_span = arg.span.source_callsite();
53+
5254
let ty = cx.typeck_results().expr_ty(arg);
5355

5456
let (adt, args, ref_mutability) = match ty.kind() {
@@ -78,27 +80,27 @@ impl<'tcx> LateLintPass<'tcx> for ForLoopsOverFallibles {
7880
&& let Ok(recv_snip) = cx.sess().source_map().span_to_snippet(recv.span)
7981
{
8082
ForLoopsOverFalliblesLoopSub::RemoveNext {
81-
suggestion: recv.span.between(arg.span.shrink_to_hi()),
83+
suggestion: recv.span.between(arg_span.shrink_to_hi()),
8284
recv_snip,
8385
}
8486
} else {
8587
ForLoopsOverFalliblesLoopSub::UseWhileLet {
8688
start_span: expr.span.with_hi(pat.span.lo()),
87-
end_span: pat.span.between(arg.span),
89+
end_span: pat.span.between(arg_span),
8890
var,
8991
}
9092
};
9193
let question_mark = suggest_question_mark(cx, adt, args, expr.span)
92-
.then(|| ForLoopsOverFalliblesQuestionMark { suggestion: arg.span.shrink_to_hi() });
94+
.then(|| ForLoopsOverFalliblesQuestionMark { suggestion: arg_span.shrink_to_hi() });
9395
let suggestion = ForLoopsOverFalliblesSuggestion {
9496
var,
9597
start_span: expr.span.with_hi(pat.span.lo()),
96-
end_span: pat.span.between(arg.span),
98+
end_span: pat.span.between(arg_span),
9799
};
98100

99101
cx.emit_span_lint(
100102
FOR_LOOPS_OVER_FALLIBLES,
101-
arg.span,
103+
arg_span,
102104
ForLoopsOverFalliblesDiag { article, ref_prefix, ty, sub, question_mark, suggestion },
103105
);
104106
}

compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs

+27
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,45 @@ impl<'a, 'tcx> UnnecessaryTransmuteChecker<'a, 'tcx> {
5555
},
5656
// char → u32
5757
(Char, Uint(UintTy::U32)) => err(format!("u32::from({arg})")),
58+
// char (→ u32) → i32
59+
(Char, Int(IntTy::I32)) => err(format!("u32::from({arg}).cast_signed()")),
5860
// u32 → char
5961
(Uint(UintTy::U32), Char) => Error {
6062
sugg: format!("char::from_u32_unchecked({arg})"),
6163
help: Some("consider `char::from_u32(…).unwrap()`"),
6264
span,
6365
},
66+
// i32 → char
67+
(Int(IntTy::I32), Char) => Error {
68+
sugg: format!("char::from_u32_unchecked(i32::cast_unsigned({arg}))"),
69+
help: Some("consider `char::from_u32(i32::cast_unsigned(…)).unwrap()`"),
70+
span,
71+
},
6472
// uNN → iNN
6573
(Uint(ty), Int(_)) => err(format!("{}::cast_signed({arg})", ty.name_str())),
6674
// iNN → uNN
6775
(Int(ty), Uint(_)) => err(format!("{}::cast_unsigned({arg})", ty.name_str())),
76+
// fNN → xsize
77+
(Float(ty), Uint(UintTy::Usize)) => {
78+
err(format!("{}::to_bits({arg}) as usize", ty.name_str()))
79+
}
80+
(Float(ty), Int(IntTy::Isize)) => {
81+
err(format!("{}::to_bits({arg}) as isize", ty.name_str()))
82+
}
83+
// fNN (→ uNN) → iNN
84+
(Float(ty), Int(..)) => err(format!("{}::to_bits({arg}).cast_signed()", ty.name_str())),
6885
// fNN → uNN
6986
(Float(ty), Uint(..)) => err(format!("{}::to_bits({arg})", ty.name_str())),
87+
// xsize → fNN
88+
(Uint(UintTy::Usize) | Int(IntTy::Isize), Float(ty)) => {
89+
err(format!("{}::from_bits({arg} as _)", ty.name_str(),))
90+
}
91+
// iNN (→ uNN) → fNN
92+
(Int(int_ty), Float(ty)) => err(format!(
93+
"{}::from_bits({}::cast_unsigned({arg}))",
94+
ty.name_str(),
95+
int_ty.name_str()
96+
)),
7097
// uNN → fNN
7198
(Uint(_), Float(ty)) => err(format!("{}::from_bits({arg})", ty.name_str())),
7299
// bool → { x8 }

compiler/rustc_target/src/spec/targets/aarch64_pc_windows_msvc.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
use crate::spec::{LinkerFlavor, Lld, Target, TargetMetadata, base};
1+
use crate::spec::{FramePointer, LinkerFlavor, Lld, Target, TargetMetadata, base};
22

33
pub(crate) fn target() -> Target {
44
let mut base = base::windows_msvc::opts();
55
base.max_atomic_width = Some(128);
66
base.features = "+v8a,+neon,+fp-armv8".into();
77

8+
// Microsoft recommends enabling frame pointers on Arm64 Windows.
9+
// From https://learn.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=msvc-170#integer-registers
10+
// "The frame pointer (x29) is required for compatibility with fast stack walking used by ETW
11+
// and other services. It must point to the previous {x29, x30} pair on the stack."
12+
base.frame_pointer = FramePointer::NonLeaf;
13+
814
// MSVC emits a warning about code that may trip "Cortex-A53 MPCore processor bug #843419" (see
915
// https://developer.arm.com/documentation/epm048406/latest) which is sometimes emitted by LLVM.
1016
// Since Arm64 Windows 10+ isn't supported on that processor, it's safe to disable the warning.

src/bootstrap/src/bin/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ fn check_version(config: &Config) -> Option<String> {
163163
msg.push_str("WARNING: The `change-id` is missing in the `bootstrap.toml`. This means that you will not be able to track the major changes made to the bootstrap configurations.\n");
164164
msg.push_str("NOTE: to silence this warning, ");
165165
msg.push_str(&format!(
166-
"add `change-id = {latest_change_id}` or change-id = \"ignore\" at the top of `bootstrap.toml`"
166+
"add `change-id = {latest_change_id}` or `change-id = \"ignore\"` at the top of `bootstrap.toml`"
167167
));
168168
return Some(msg);
169169
}
@@ -195,7 +195,7 @@ fn check_version(config: &Config) -> Option<String> {
195195

196196
msg.push_str("NOTE: to silence this warning, ");
197197
msg.push_str(&format!(
198-
"update `bootstrap.toml` to use `change-id = {latest_change_id}` or change-id = \"ignore\" instead"
198+
"update `bootstrap.toml` to use `change-id = {latest_change_id}` or `change-id = \"ignore\"` instead"
199199
));
200200

201201
if io::stdout().is_terminal() {

src/tools/miri/tests/pass/shims/x86/intrinsics-x86-sse2.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// We're testing x86 target specific features
22
//@only-target: x86_64 i686
3+
#![allow(unnecessary_transmutes)]
34

45
#[cfg(target_arch = "x86")]
56
use std::arch::x86::*;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![forbid(for_loops_over_fallibles)]
2+
3+
fn main() {
4+
macro_rules! x {
5+
() => {
6+
None::<i32>
7+
};
8+
}
9+
for _ in x! {} {} //~ ERROR for loop over an `Option`. This is more readably written as an `if let` statement [for_loops_over_fallibles]
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error: for loop over an `Option`. This is more readably written as an `if let` statement
2+
--> $DIR/macro-issue-140747.rs:9:14
3+
|
4+
LL | for _ in x! {} {}
5+
| ^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/macro-issue-140747.rs:1:11
9+
|
10+
LL | #![forbid(for_loops_over_fallibles)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^
12+
help: to check pattern in a loop use `while let`
13+
|
14+
LL - for _ in x! {} {}
15+
LL + while let Some(_) = x! {} {}
16+
|
17+
help: consider using `if let` to clear intent
18+
|
19+
LL - for _ in x! {} {}
20+
LL + if let Some(_) = x! {} {}
21+
|
22+
23+
error: aborting due to 1 previous error
24+

tests/ui/transmute/unnecessary-transmutation.fixed

+9
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ fn main() {
4949
//~^ ERROR
5050
let y: char = char::from_u32_unchecked(y);
5151
//~^ ERROR
52+
let y: i32 = u32::from('🐱').cast_signed();
53+
//~^ ERROR
54+
let y: char = char::from_u32_unchecked(i32::cast_unsigned(y));
55+
//~^ ERROR
5256

5357
let x: u16 = i16::cast_unsigned(8i16);
5458
//~^ ERROR
@@ -72,6 +76,11 @@ fn main() {
7276
let y: u64 = f64::to_bits(2.0);
7377
//~^ ERROR
7478

79+
let y: f64 = f64::from_bits(i64::cast_unsigned(1i64));
80+
//~^ ERROR
81+
let y: i64 = f64::to_bits(1f64).cast_signed();
82+
//~^ ERROR
83+
7584
let z: bool = (1u8 == 1);
7685
//~^ ERROR
7786
let z: u8 = (z) as u8;

tests/ui/transmute/unnecessary-transmutation.rs

+9
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ fn main() {
4949
//~^ ERROR
5050
let y: char = transmute(y);
5151
//~^ ERROR
52+
let y: i32 = transmute('🐱');
53+
//~^ ERROR
54+
let y: char = transmute(y);
55+
//~^ ERROR
5256

5357
let x: u16 = transmute(8i16);
5458
//~^ ERROR
@@ -72,6 +76,11 @@ fn main() {
7276
let y: u64 = transmute(2.0);
7377
//~^ ERROR
7478

79+
let y: f64 = transmute(1i64);
80+
//~^ ERROR
81+
let y: i64 = transmute(1f64);
82+
//~^ ERROR
83+
7584
let z: bool = transmute(1u8);
7685
//~^ ERROR
7786
let z: u8 = transmute(z);

tests/ui/transmute/unnecessary-transmutation.stderr

+40-14
Original file line numberDiff line numberDiff line change
@@ -154,82 +154,108 @@ LL | let y: char = transmute(y);
154154
= help: consider `char::from_u32(…).unwrap()`
155155

156156
error: unnecessary transmute
157-
--> $DIR/unnecessary-transmutation.rs:53:22
157+
--> $DIR/unnecessary-transmutation.rs:52:22
158+
|
159+
LL | let y: i32 = transmute('🐱');
160+
| ^^^^^^^^^^^^^^^ help: replace this with: `u32::from('🐱').cast_signed()`
161+
162+
error: unnecessary transmute
163+
--> $DIR/unnecessary-transmutation.rs:54:23
164+
|
165+
LL | let y: char = transmute(y);
166+
| ^^^^^^^^^^^^ help: replace this with: `char::from_u32_unchecked(i32::cast_unsigned(y))`
167+
|
168+
= help: consider `char::from_u32(i32::cast_unsigned(…)).unwrap()`
169+
170+
error: unnecessary transmute
171+
--> $DIR/unnecessary-transmutation.rs:57:22
158172
|
159173
LL | let x: u16 = transmute(8i16);
160174
| ^^^^^^^^^^^^^^^ help: replace this with: `i16::cast_unsigned(8i16)`
161175

162176
error: unnecessary transmute
163-
--> $DIR/unnecessary-transmutation.rs:55:22
177+
--> $DIR/unnecessary-transmutation.rs:59:22
164178
|
165179
LL | let x: i16 = transmute(x);
166180
| ^^^^^^^^^^^^ help: replace this with: `u16::cast_signed(x)`
167181

168182
error: unnecessary transmute
169-
--> $DIR/unnecessary-transmutation.rs:57:22
183+
--> $DIR/unnecessary-transmutation.rs:61:22
170184
|
171185
LL | let x: u32 = transmute(4i32);
172186
| ^^^^^^^^^^^^^^^ help: replace this with: `i32::cast_unsigned(4i32)`
173187

174188
error: unnecessary transmute
175-
--> $DIR/unnecessary-transmutation.rs:59:22
189+
--> $DIR/unnecessary-transmutation.rs:63:22
176190
|
177191
LL | let x: i32 = transmute(x);
178192
| ^^^^^^^^^^^^ help: replace this with: `u32::cast_signed(x)`
179193

180194
error: unnecessary transmute
181-
--> $DIR/unnecessary-transmutation.rs:61:22
195+
--> $DIR/unnecessary-transmutation.rs:65:22
182196
|
183197
LL | let x: u64 = transmute(7i64);
184198
| ^^^^^^^^^^^^^^^ help: replace this with: `i64::cast_unsigned(7i64)`
185199

186200
error: unnecessary transmute
187-
--> $DIR/unnecessary-transmutation.rs:63:22
201+
--> $DIR/unnecessary-transmutation.rs:67:22
188202
|
189203
LL | let x: i64 = transmute(x);
190204
| ^^^^^^^^^^^^ help: replace this with: `u64::cast_signed(x)`
191205

192206
error: unnecessary transmute
193-
--> $DIR/unnecessary-transmutation.rs:66:22
207+
--> $DIR/unnecessary-transmutation.rs:70:22
194208
|
195209
LL | let y: f32 = transmute(1u32);
196210
| ^^^^^^^^^^^^^^^ help: replace this with: `f32::from_bits(1u32)`
197211

198212
error: unnecessary transmute
199-
--> $DIR/unnecessary-transmutation.rs:68:22
213+
--> $DIR/unnecessary-transmutation.rs:72:22
200214
|
201215
LL | let y: u32 = transmute(y);
202216
| ^^^^^^^^^^^^ help: replace this with: `f32::to_bits(y)`
203217

204218
error: unnecessary transmute
205-
--> $DIR/unnecessary-transmutation.rs:70:22
219+
--> $DIR/unnecessary-transmutation.rs:74:22
206220
|
207221
LL | let y: f64 = transmute(3u64);
208222
| ^^^^^^^^^^^^^^^ help: replace this with: `f64::from_bits(3u64)`
209223

210224
error: unnecessary transmute
211-
--> $DIR/unnecessary-transmutation.rs:72:22
225+
--> $DIR/unnecessary-transmutation.rs:76:22
212226
|
213227
LL | let y: u64 = transmute(2.0);
214228
| ^^^^^^^^^^^^^^ help: replace this with: `f64::to_bits(2.0)`
215229

216230
error: unnecessary transmute
217-
--> $DIR/unnecessary-transmutation.rs:75:23
231+
--> $DIR/unnecessary-transmutation.rs:79:22
232+
|
233+
LL | let y: f64 = transmute(1i64);
234+
| ^^^^^^^^^^^^^^^ help: replace this with: `f64::from_bits(i64::cast_unsigned(1i64))`
235+
236+
error: unnecessary transmute
237+
--> $DIR/unnecessary-transmutation.rs:81:22
238+
|
239+
LL | let y: i64 = transmute(1f64);
240+
| ^^^^^^^^^^^^^^^ help: replace this with: `f64::to_bits(1f64).cast_signed()`
241+
242+
error: unnecessary transmute
243+
--> $DIR/unnecessary-transmutation.rs:84:23
218244
|
219245
LL | let z: bool = transmute(1u8);
220246
| ^^^^^^^^^^^^^^ help: replace this with: `(1u8 == 1)`
221247

222248
error: unnecessary transmute
223-
--> $DIR/unnecessary-transmutation.rs:77:21
249+
--> $DIR/unnecessary-transmutation.rs:86:21
224250
|
225251
LL | let z: u8 = transmute(z);
226252
| ^^^^^^^^^^^^ help: replace this with: `(z) as u8`
227253

228254
error: unnecessary transmute
229-
--> $DIR/unnecessary-transmutation.rs:82:21
255+
--> $DIR/unnecessary-transmutation.rs:91:21
230256
|
231257
LL | let z: i8 = transmute(z);
232258
| ^^^^^^^^^^^^ help: replace this with: `(z) as i8`
233259

234-
error: aborting due to 32 previous errors
260+
error: aborting due to 36 previous errors
235261

triagebot.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ message = "This PR changes a file inside `tests/crashes`. If a crash was fixed,
10021002

10031003
[mentions."tests/rustdoc-json"]
10041004
message = """
1005-
These commits modify `test/rustdoc-json`.
1005+
These commits modify `tests/rustdoc-json`.
10061006
rustdoc-json is a **public** (but unstable) interface.
10071007
10081008
Please ensure that if you've changed the output:

0 commit comments

Comments
 (0)