Skip to content

Commit 4772dc8

Browse files
committed
Auto merge of #58432 - Centril:rollup, r=Centril
Rollup of 10 pull requests Successful merges: - #58110 (libpanic_unwind => 2018) - #58167 (HirId-ify hir::BodyId) - #58202 (Ignore future deprecations in #[deprecated]) - #58272 (Cut down on number formating code size) - #58276 (Improve the error messages for missing stability attributes) - #58354 (Fix ICE and invalid filenames in MIR printing code) - #58381 (Only suggest imports if not imported.) - #58386 (Fix #54242) - #58400 (Fix rustc_driver swallowing errors when compilation is stopped) - #58420 (target/uefi: clarify documentation) Failed merges: r? @ghost
2 parents e544947 + 05cfcb5 commit 4772dc8

File tree

77 files changed

+753
-445
lines changed

Some content is hidden

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

77 files changed

+753
-445
lines changed

src/libcore/fmt/mod.rs

+62-39
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,27 @@ pub fn write(output: &mut dyn Write, args: Arguments) -> Result {
10361036
Ok(())
10371037
}
10381038

1039+
/// Padding after the end of something. Returned by `Formatter::padding`.
1040+
#[must_use = "don't forget to write the post padding"]
1041+
struct PostPadding {
1042+
fill: char,
1043+
padding: usize,
1044+
}
1045+
1046+
impl PostPadding {
1047+
fn new(fill: char, padding: usize) -> PostPadding {
1048+
PostPadding { fill, padding }
1049+
}
1050+
1051+
/// Write this post padding.
1052+
fn write(self, buf: &mut dyn Write) -> Result {
1053+
for _ in 0..self.padding {
1054+
buf.write_char(self.fill)?;
1055+
}
1056+
Ok(())
1057+
}
1058+
}
1059+
10391060
impl<'a> Formatter<'a> {
10401061
fn wrap_buf<'b, 'c, F>(&'b mut self, wrap: F) -> Formatter<'c>
10411062
where 'b: 'c, F: FnOnce(&'b mut (dyn Write+'b)) -> &'c mut (dyn Write+'c)
@@ -1153,47 +1174,56 @@ impl<'a> Formatter<'a> {
11531174
sign = Some('+'); width += 1;
11541175
}
11551176

1156-
let prefixed = self.alternate();
1157-
if prefixed {
1177+
let prefix = if self.alternate() {
11581178
width += prefix.chars().count();
1159-
}
1179+
Some(prefix)
1180+
} else {
1181+
None
1182+
};
11601183

11611184
// Writes the sign if it exists, and then the prefix if it was requested
1162-
let write_prefix = |f: &mut Formatter| {
1185+
#[inline(never)]
1186+
fn write_prefix(f: &mut Formatter, sign: Option<char>, prefix: Option<&str>) -> Result {
11631187
if let Some(c) = sign {
11641188
f.buf.write_char(c)?;
11651189
}
1166-
if prefixed { f.buf.write_str(prefix) }
1167-
else { Ok(()) }
1168-
};
1190+
if let Some(prefix) = prefix {
1191+
f.buf.write_str(prefix)
1192+
} else {
1193+
Ok(())
1194+
}
1195+
}
11691196

11701197
// The `width` field is more of a `min-width` parameter at this point.
11711198
match self.width {
11721199
// If there's no minimum length requirements then we can just
11731200
// write the bytes.
11741201
None => {
1175-
write_prefix(self)?; self.buf.write_str(buf)
1202+
write_prefix(self, sign, prefix)?;
1203+
self.buf.write_str(buf)
11761204
}
11771205
// Check if we're over the minimum width, if so then we can also
11781206
// just write the bytes.
11791207
Some(min) if width >= min => {
1180-
write_prefix(self)?; self.buf.write_str(buf)
1208+
write_prefix(self, sign, prefix)?;
1209+
self.buf.write_str(buf)
11811210
}
11821211
// The sign and prefix goes before the padding if the fill character
11831212
// is zero
11841213
Some(min) if self.sign_aware_zero_pad() => {
11851214
self.fill = '0';
11861215
self.align = rt::v1::Alignment::Right;
1187-
write_prefix(self)?;
1188-
self.with_padding(min - width, rt::v1::Alignment::Right, |f| {
1189-
f.buf.write_str(buf)
1190-
})
1216+
write_prefix(self, sign, prefix)?;
1217+
let post_padding = self.padding(min - width, rt::v1::Alignment::Right)?;
1218+
self.buf.write_str(buf)?;
1219+
post_padding.write(self.buf)
11911220
}
11921221
// Otherwise, the sign and prefix goes after the padding
11931222
Some(min) => {
1194-
self.with_padding(min - width, rt::v1::Alignment::Right, |f| {
1195-
write_prefix(f)?; f.buf.write_str(buf)
1196-
})
1223+
let post_padding = self.padding(min - width, rt::v1::Alignment::Right)?;
1224+
write_prefix(self, sign, prefix)?;
1225+
self.buf.write_str(buf)?;
1226+
post_padding.write(self.buf)
11971227
}
11981228
}
11991229
}
@@ -1264,19 +1294,21 @@ impl<'a> Formatter<'a> {
12641294
// up the minimum width with the specified string + some alignment.
12651295
Some(width) => {
12661296
let align = rt::v1::Alignment::Left;
1267-
self.with_padding(width - s.chars().count(), align, |me| {
1268-
me.buf.write_str(s)
1269-
})
1297+
let post_padding = self.padding(width - s.chars().count(), align)?;
1298+
self.buf.write_str(s)?;
1299+
post_padding.write(self.buf)
12701300
}
12711301
}
12721302
}
12731303

1274-
/// Runs a callback, emitting the correct padding either before or
1275-
/// afterwards depending on whether right or left alignment is requested.
1276-
fn with_padding<F>(&mut self, padding: usize, default: rt::v1::Alignment,
1277-
f: F) -> Result
1278-
where F: FnOnce(&mut Formatter) -> Result,
1279-
{
1304+
/// Write the pre-padding and return the unwritten post-padding. Callers are
1305+
/// responsible for ensuring post-padding is written after the thing that is
1306+
/// being padded.
1307+
fn padding(
1308+
&mut self,
1309+
padding: usize,
1310+
default: rt::v1::Alignment
1311+
) -> result::Result<PostPadding, Error> {
12801312
let align = match self.align {
12811313
rt::v1::Alignment::Unknown => default,
12821314
_ => self.align
@@ -1289,20 +1321,11 @@ impl<'a> Formatter<'a> {
12891321
rt::v1::Alignment::Center => (padding / 2, (padding + 1) / 2),
12901322
};
12911323

1292-
let mut fill = [0; 4];
1293-
let fill = self.fill.encode_utf8(&mut fill);
1294-
12951324
for _ in 0..pre_pad {
1296-
self.buf.write_str(fill)?;
1297-
}
1298-
1299-
f(self)?;
1300-
1301-
for _ in 0..post_pad {
1302-
self.buf.write_str(fill)?;
1325+
self.buf.write_char(self.fill)?;
13031326
}
13041327

1305-
Ok(())
1328+
Ok(PostPadding::new(self.fill, post_pad))
13061329
}
13071330

13081331
/// Takes the formatted parts and applies the padding.
@@ -1334,9 +1357,9 @@ impl<'a> Formatter<'a> {
13341357
let ret = if width <= len { // no padding
13351358
self.write_formatted_parts(&formatted)
13361359
} else {
1337-
self.with_padding(width - len, align, |f| {
1338-
f.write_formatted_parts(&formatted)
1339-
})
1360+
let post_padding = self.padding(width - len, align)?;
1361+
self.write_formatted_parts(&formatted)?;
1362+
post_padding.write(self.buf)
13401363
};
13411364
self.fill = old_fill;
13421365
self.align = old_align;

src/libcore/fmt/num.rs

+52-35
Original file line numberDiff line numberDiff line change
@@ -178,45 +178,36 @@ integer! { i32, u32 }
178178
integer! { i64, u64 }
179179
integer! { i128, u128 }
180180

181-
const DEC_DIGITS_LUT: &'static[u8] =
181+
182+
static DEC_DIGITS_LUT: &[u8; 200] =
182183
b"0001020304050607080910111213141516171819\
183184
2021222324252627282930313233343536373839\
184185
4041424344454647484950515253545556575859\
185186
6061626364656667686970717273747576777879\
186187
8081828384858687888990919293949596979899";
187188

188189
macro_rules! impl_Display {
189-
($($t:ident),*: $conv_fn:ident) => ($(
190-
#[stable(feature = "rust1", since = "1.0.0")]
191-
impl fmt::Display for $t {
192-
#[allow(unused_comparisons)]
193-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
194-
let is_nonnegative = *self >= 0;
195-
let mut n = if is_nonnegative {
196-
self.$conv_fn()
197-
} else {
198-
// convert the negative num to positive by summing 1 to it's 2 complement
199-
(!self.$conv_fn()).wrapping_add(1)
200-
};
190+
($($t:ident),* as $u:ident via $conv_fn:ident named $name:ident) => {
191+
fn $name(mut n: $u, is_nonnegative: bool, f: &mut fmt::Formatter) -> fmt::Result {
201192
let mut buf = uninitialized_array![u8; 39];
202193
let mut curr = buf.len() as isize;
203194
let buf_ptr = MaybeUninit::first_ptr_mut(&mut buf);
204195
let lut_ptr = DEC_DIGITS_LUT.as_ptr();
205196

206197
unsafe {
207198
// need at least 16 bits for the 4-characters-at-a-time to work.
208-
if ::mem::size_of::<$t>() >= 2 {
209-
// eagerly decode 4 characters at a time
210-
while n >= 10000 {
211-
let rem = (n % 10000) as isize;
212-
n /= 10000;
213-
214-
let d1 = (rem / 100) << 1;
215-
let d2 = (rem % 100) << 1;
216-
curr -= 4;
217-
ptr::copy_nonoverlapping(lut_ptr.offset(d1), buf_ptr.offset(curr), 2);
218-
ptr::copy_nonoverlapping(lut_ptr.offset(d2), buf_ptr.offset(curr + 2), 2);
219-
}
199+
assert!(::mem::size_of::<$u>() >= 2);
200+
201+
// eagerly decode 4 characters at a time
202+
while n >= 10000 {
203+
let rem = (n % 10000) as isize;
204+
n /= 10000;
205+
206+
let d1 = (rem / 100) << 1;
207+
let d2 = (rem % 100) << 1;
208+
curr -= 4;
209+
ptr::copy_nonoverlapping(lut_ptr.offset(d1), buf_ptr.offset(curr), 2);
210+
ptr::copy_nonoverlapping(lut_ptr.offset(d2), buf_ptr.offset(curr + 2), 2);
220211
}
221212

222213
// if we reach here numbers are <= 9999, so at most 4 chars long
@@ -247,15 +238,41 @@ macro_rules! impl_Display {
247238
};
248239
f.pad_integral(is_nonnegative, "", buf_slice)
249240
}
250-
})*);
241+
242+
$(
243+
#[stable(feature = "rust1", since = "1.0.0")]
244+
impl fmt::Display for $t {
245+
#[allow(unused_comparisons)]
246+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
247+
let is_nonnegative = *self >= 0;
248+
let n = if is_nonnegative {
249+
self.$conv_fn()
250+
} else {
251+
// convert the negative num to positive by summing 1 to it's 2 complement
252+
(!self.$conv_fn()).wrapping_add(1)
253+
};
254+
$name(n, is_nonnegative, f)
255+
}
256+
})*
257+
};
258+
}
259+
260+
// Include wasm32 in here since it doesn't reflect the native pointer size, and
261+
// often cares strongly about getting a smaller code size.
262+
#[cfg(any(target_pointer_width = "64", target_arch = "wasm32"))]
263+
mod imp {
264+
use super::*;
265+
impl_Display!(
266+
i8, u8, i16, u16, i32, u32, i64, u64, usize, isize
267+
as u64 via to_u64 named fmt_u64
268+
);
269+
}
270+
271+
#[cfg(not(any(target_pointer_width = "64", target_arch = "wasm32")))]
272+
mod imp {
273+
use super::*;
274+
impl_Display!(i8, u8, i16, u16, i32, u32, isize, usize as u32 via to_u32 named fmt_u32);
275+
impl_Display!(i64, u64 as u64 via to_u64 named fmt_u64);
251276
}
252277

253-
impl_Display!(i8, u8, i16, u16, i32, u32: to_u32);
254-
impl_Display!(i64, u64: to_u64);
255-
impl_Display!(i128, u128: to_u128);
256-
#[cfg(target_pointer_width = "16")]
257-
impl_Display!(isize, usize: to_u16);
258-
#[cfg(target_pointer_width = "32")]
259-
impl_Display!(isize, usize: to_u32);
260-
#[cfg(target_pointer_width = "64")]
261-
impl_Display!(isize, usize: to_u64);
278+
impl_Display!(i128, u128 as u128 via to_u128 named fmt_u128);

src/libpanic_unwind/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
authors = ["The Rust Project Developers"]
33
name = "panic_unwind"
44
version = "0.0.0"
5+
edition = "2018"
56

67
[lib]
78
path = "lib.rs"

src/libpanic_unwind/dwarf/eh.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#![allow(non_upper_case_globals)]
1212
#![allow(unused)]
1313

14-
use dwarf::DwarfReader;
14+
use crate::dwarf::DwarfReader;
1515
use core::mem;
1616

1717
pub const DW_EH_PE_omit: u8 = 0xFF;
@@ -51,7 +51,7 @@ pub enum EHAction {
5151

5252
pub const USING_SJLJ_EXCEPTIONS: bool = cfg!(all(target_os = "ios", target_arch = "arm"));
5353

54-
pub unsafe fn find_eh_action(lsda: *const u8, context: &EHContext)
54+
pub unsafe fn find_eh_action(lsda: *const u8, context: &EHContext<'_>)
5555
-> Result<EHAction, ()>
5656
{
5757
if lsda.is_null() {
@@ -145,7 +145,7 @@ fn round_up(unrounded: usize, align: usize) -> Result<usize, ()> {
145145
}
146146

147147
unsafe fn read_encoded_pointer(reader: &mut DwarfReader,
148-
context: &EHContext,
148+
context: &EHContext<'_>,
149149
encoding: u8)
150150
-> Result<usize, ()> {
151151
if encoding == DW_EH_PE_omit {

src/libpanic_unwind/emcc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
use core::any::Any;
1212
use core::ptr;
13+
use core::mem;
1314
use alloc::boxed::Box;
1415
use libc::{self, c_int};
1516
use unwind as uw;
16-
use core::mem;
1717

1818
pub fn payload() -> *mut u8 {
1919
ptr::null_mut()

src/libpanic_unwind/gcc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use alloc::boxed::Box;
5252

5353
use unwind as uw;
5454
use libc::{c_int, uintptr_t};
55-
use dwarf::eh::{self, EHContext, EHAction};
55+
use crate::dwarf::eh::{self, EHContext, EHAction};
5656

5757
#[repr(C)]
5858
struct Exception {

src/libpanic_unwind/lib.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/",
1818
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")]
1919

20+
#![deny(rust_2018_idioms)]
21+
2022
#![feature(allocator_api)]
2123
#![feature(alloc)]
2224
#![feature(core_intrinsics)]
@@ -32,11 +34,6 @@
3234
#![panic_runtime]
3335
#![feature(panic_runtime)]
3436

35-
extern crate alloc;
36-
extern crate libc;
37-
#[cfg(not(any(target_env = "msvc", all(windows, target_arch = "x86_64", target_env = "gnu"))))]
38-
extern crate unwind;
39-
4037
use alloc::boxed::Box;
4138
use core::intrinsics;
4239
use core::mem;
@@ -87,7 +84,7 @@ pub unsafe extern "C" fn __rust_maybe_catch_panic(f: fn(*mut u8),
8784
vtable_ptr: *mut usize)
8885
-> u32 {
8986
let mut payload = imp::payload();
90-
if intrinsics::try(f, data, &mut payload as *mut _ as *mut _) == 0 {
87+
if intrinsics::r#try(f, data, &mut payload as *mut _ as *mut _) == 0 {
9188
0
9289
} else {
9390
let obj = mem::transmute::<_, raw::TraitObject>(imp::cleanup(payload));

src/libpanic_unwind/seh.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use core::any::Any;
5252
use core::mem;
5353
use core::raw;
5454

55-
use windows as c;
55+
use crate::windows as c;
5656
use libc::{c_int, c_uint};
5757

5858
// First up, a whole bunch of type definitions. There's a few platform-specific
@@ -301,5 +301,5 @@ pub unsafe fn cleanup(payload: [u64; 2]) -> Box<dyn Any + Send> {
301301
#[lang = "eh_personality"]
302302
#[cfg(not(test))]
303303
fn rust_eh_personality() {
304-
unsafe { ::core::intrinsics::abort() }
304+
unsafe { core::intrinsics::abort() }
305305
}

src/libpanic_unwind/seh64_gnu.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use alloc::boxed::Box;
99
use core::any::Any;
1010
use core::intrinsics;
1111
use core::ptr;
12-
use dwarf::eh::{EHContext, EHAction, find_eh_action};
13-
use windows as c;
12+
use crate::dwarf::eh::{EHContext, EHAction, find_eh_action};
13+
use crate::windows as c;
1414

1515
// Define our exception codes:
1616
// according to http://msdn.microsoft.com/en-us/library/het71c37(v=VS.80).aspx,

0 commit comments

Comments
 (0)