Skip to content

Commit 61885df

Browse files
committed
Auto merge of #87980 - Manishearth:rollup-vkuix3y, r=Manishearth
Rollup of 4 pull requests Successful merges: - #87916 (Implement `black_box` using intrinsic) - #87922 (Add c_enum_min_bits target spec field, use for arm-none and thumb-none targets) - #87953 (Improve formatting of closure capture migration suggestion for multi-line closures.) - #87965 (Silence non_fmt_panic from external macros.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0fa3190 + 2d27976 commit 61885df

34 files changed

+667
-113
lines changed

compiler/rustc_lint/src/non_fmt_panic.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{LateContext, LateLintPass, LintContext};
22
use rustc_ast as ast;
33
use rustc_errors::{pluralize, Applicability};
44
use rustc_hir as hir;
5+
use rustc_middle::lint::in_external_macro;
56
use rustc_middle::ty;
67
use rustc_parse_format::{ParseMode, Parser, Piece};
78
use rustc_session::lint::FutureIncompatibilityReason;
@@ -75,6 +76,11 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
7576

7677
let (span, panic, symbol_str) = panic_call(cx, f);
7778

79+
if in_external_macro(cx.sess(), span) {
80+
// Nothing that can be done about it in the current crate.
81+
return;
82+
}
83+
7884
// Find the span of the argument to `panic!()`, before expansion in the
7985
// case of `panic!(some_macro!())`.
8086
// We don't use source_callsite(), because this `panic!(..)` might itself
@@ -152,6 +158,13 @@ fn check_panic_str<'tcx>(
152158
return;
153159
}
154160

161+
let (span, _, _) = panic_call(cx, f);
162+
163+
if in_external_macro(cx.sess(), span) && in_external_macro(cx.sess(), arg.span) {
164+
// Nothing that can be done about it in the current crate.
165+
return;
166+
}
167+
155168
let fmt_span = arg.span.source_callsite();
156169

157170
let (snippet, style) = match cx.sess().parse_sess.source_map().span_to_snippet(fmt_span) {
@@ -167,8 +180,6 @@ fn check_panic_str<'tcx>(
167180
Parser::new(fmt.as_ref(), style, snippet.clone(), false, ParseMode::Format);
168181
let n_arguments = (&mut fmt_parser).filter(|a| matches!(a, Piece::NextArgument(_))).count();
169182

170-
let (span, _, _) = panic_call(cx, f);
171-
172183
if n_arguments > 0 && fmt_parser.errors.is_empty() {
173184
let arg_spans: Vec<_> = match &fmt_parser.arg_places[..] {
174185
[] => vec![fmt_span],

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,6 @@ impl IntegerExt for Integer {
112112
let unsigned_fit = Integer::fit_unsigned(cmp::max(min as u128, max as u128));
113113
let signed_fit = cmp::max(Integer::fit_signed(min), Integer::fit_signed(max));
114114

115-
let mut min_from_extern = None;
116-
let min_default = I8;
117-
118115
if let Some(ity) = repr.int {
119116
let discr = Integer::from_attr(&tcx, ity);
120117
let fit = if ity.is_signed() { signed_fit } else { unsigned_fit };
@@ -128,19 +125,14 @@ impl IntegerExt for Integer {
128125
return (discr, ity.is_signed());
129126
}
130127

131-
if repr.c() {
132-
match &tcx.sess.target.arch[..] {
133-
"hexagon" => min_from_extern = Some(I8),
134-
// WARNING: the ARM EABI has two variants; the one corresponding
135-
// to `at_least == I32` appears to be used on Linux and NetBSD,
136-
// but some systems may use the variant corresponding to no
137-
// lower bound. However, we don't run on those yet...?
138-
"arm" => min_from_extern = Some(I32),
139-
_ => min_from_extern = Some(I32),
140-
}
141-
}
142-
143-
let at_least = min_from_extern.unwrap_or(min_default);
128+
let at_least = if repr.c() {
129+
// This is usually I32, however it can be different on some platforms,
130+
// notably hexagon and arm-none/thumb-none
131+
tcx.data_layout().c_enum_min_size
132+
} else {
133+
// repr(Rust) enums try to be as small as possible
134+
I8
135+
};
144136

145137
// If there are no negative values, we can use the unsigned fit.
146138
if min >= 0 {

compiler/rustc_target/src/abi/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ pub struct TargetDataLayout {
3636
pub vector_align: Vec<(Size, AbiAndPrefAlign)>,
3737

3838
pub instruction_address_space: AddressSpace,
39+
40+
/// Minimum size of #[repr(C)] enums (default I32 bits)
41+
pub c_enum_min_size: Integer,
3942
}
4043

4144
impl Default for TargetDataLayout {
@@ -60,6 +63,7 @@ impl Default for TargetDataLayout {
6063
(Size::from_bits(128), AbiAndPrefAlign::new(align(128))),
6164
],
6265
instruction_address_space: AddressSpace::DATA,
66+
c_enum_min_size: Integer::I32,
6367
}
6468
}
6569
}
@@ -173,6 +177,8 @@ impl TargetDataLayout {
173177
));
174178
}
175179

180+
dl.c_enum_min_size = Integer::from_size(Size::from_bits(target.c_enum_min_bits))?;
181+
176182
Ok(dl)
177183
}
178184

@@ -610,6 +616,17 @@ impl Integer {
610616
}
611617
I8
612618
}
619+
620+
fn from_size(size: Size) -> Result<Self, String> {
621+
match size.bits() {
622+
8 => Ok(Integer::I8),
623+
16 => Ok(Integer::I16),
624+
32 => Ok(Integer::I32),
625+
64 => Ok(Integer::I64),
626+
128 => Ok(Integer::I128),
627+
_ => Err(format!("rust does not support integers with {} bits", size.bits())),
628+
}
629+
}
613630
}
614631

615632
/// Fundamental unit of memory access and layout.

compiler/rustc_target/src/spec/armebv7r_none_eabi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub fn target() -> Target {
2020
panic_strategy: PanicStrategy::Abort,
2121
max_atomic_width: Some(32),
2222
emit_debug_gdb_scripts: false,
23+
// GCC and Clang default to 8 for arm-none here
24+
c_enum_min_bits: 8,
2325
..Default::default()
2426
},
2527
}

compiler/rustc_target/src/spec/armebv7r_none_eabihf.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ pub fn target() -> Target {
2121
features: "+vfp3,-d32,-fp16".to_string(),
2222
max_atomic_width: Some(32),
2323
emit_debug_gdb_scripts: false,
24+
// GCC and Clang default to 8 for arm-none here
25+
c_enum_min_bits: 8,
2426
..Default::default()
2527
},
2628
}

compiler/rustc_target/src/spec/armv7a_none_eabi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub fn target() -> Target {
2828
max_atomic_width: Some(64),
2929
panic_strategy: PanicStrategy::Abort,
3030
emit_debug_gdb_scripts: false,
31+
c_enum_min_bits: 8,
3132
..Default::default()
3233
};
3334
Target {

compiler/rustc_target/src/spec/armv7a_none_eabihf.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub fn target() -> Target {
1919
max_atomic_width: Some(64),
2020
panic_strategy: PanicStrategy::Abort,
2121
emit_debug_gdb_scripts: false,
22+
// GCC and Clang default to 8 for arm-none here
23+
c_enum_min_bits: 8,
2224
..Default::default()
2325
};
2426
Target {

compiler/rustc_target/src/spec/armv7r_none_eabi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub fn target() -> Target {
1919
panic_strategy: PanicStrategy::Abort,
2020
max_atomic_width: Some(32),
2121
emit_debug_gdb_scripts: false,
22+
// GCC and Clang default to 8 for arm-none here
23+
c_enum_min_bits: 8,
2224
..Default::default()
2325
},
2426
}

compiler/rustc_target/src/spec/armv7r_none_eabihf.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub fn target() -> Target {
2020
features: "+vfp3,-d32,-fp16".to_string(),
2121
max_atomic_width: Some(32),
2222
emit_debug_gdb_scripts: false,
23+
// GCC and Clang default to 8 for arm-none here
24+
c_enum_min_bits: 8,
2325
..Default::default()
2426
},
2527
}

compiler/rustc_target/src/spec/hexagon_unknown_linux_musl.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ pub fn target() -> Target {
1313
base.dynamic_linking = true;
1414
base.executables = true;
1515

16+
base.c_enum_min_bits = 8;
17+
1618
Target {
1719
llvm_target: "hexagon-unknown-linux-musl".to_string(),
1820
pointer_width: 32,

0 commit comments

Comments
 (0)