Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #58432

Merged
merged 37 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
da5a0cd
De-duplicate number formatting implementations for smaller code size
fitzgen Feb 7, 2019
ed2157a
De-duplicate write_prefix lambda in pad_integral
fitzgen Feb 7, 2019
e633f15
Un-monomorphize and inline formatting with padding
fitzgen Feb 7, 2019
05f0dee
Improve the error messages for missing stability attributes
varkor Feb 7, 2019
c104b5c
Also de-duplicate 32- and 64-bit number formatting on wasm32
fitzgen Feb 7, 2019
05df9ff
Add a wasm code size test for stringifying numbers
fitzgen Feb 7, 2019
8fea705
Use write_char for writing padding characters
fitzgen Feb 8, 2019
f00f0e6
Don't shadow the provided `stringify!` macro in a wasm code size test…
fitzgen Feb 8, 2019
03d4fd9
Use descriptive variant name
varkor Feb 8, 2019
bb1eed0
Correct descriptive item name for impl
varkor Feb 8, 2019
18089df
Fix ICE and invalid filenames in MIR printing code
matthewjasper Feb 10, 2019
d7afd3e
Add test for MIR printing changes
matthewjasper Feb 10, 2019
3737d4d
Do not apply future deprecation warning for #[deprecated]
varkor Feb 5, 2019
87cd09b
Don't display "Deprecated since" for non-rustc deprecated items
varkor Feb 5, 2019
2a8a25b
Display "Deprecation planned" in rustdoc for future rustc deprecations
varkor Feb 5, 2019
3dc660f
Update existing rustdoc test
varkor Feb 6, 2019
01df8fe
Add a rustdoc test for future rustc_deprecated attributes
varkor Feb 6, 2019
c875241
Add rustdoc index page test for future deprecation attributes
varkor Feb 6, 2019
b5fa870
Add a test for rustc_deprecated
varkor Feb 11, 2019
48b0c9d
Only suggest imports if not imported.
davidtwco Feb 11, 2019
ddb6c4f
Set the query in the ImplicitCtxt before trying to mark it green
Zoxc Feb 12, 2019
3a8448c
Fix rustc_driver swallowing errors when compilation is stopped
gnzlbg Feb 12, 2019
eac43cc
HirId-ify hir::BodyId
ljedrz Feb 4, 2019
15e4bd3
target/uefi: clarify documentation
dvdhrm Feb 13, 2019
f2fe12a
libpanic_unwind => 2018
Centril Feb 2, 2019
f9e9c91
libpanic_unwind => 2018: fix ICEs.
Centril Feb 12, 2019
bb08499
libpanic_unwind => 2018: remove unused extern crate.
Centril Feb 13, 2019
78c60bb
Rollup merge of #58110 - Centril:libpanic_unwind-2018, r=oli-obk
Centril Feb 13, 2019
adb2bb6
Rollup merge of #58167 - ljedrz:HirIdify_body_id, r=Zoxc
Centril Feb 13, 2019
193c377
Rollup merge of #58202 - varkor:deprecated-future-external, r=Guillau…
Centril Feb 13, 2019
c0d507d
Rollup merge of #58272 - fitzgen:num-format-code-size, r=Mark-Simulacrum
Centril Feb 13, 2019
c6590e7
Rollup merge of #58276 - varkor:missing-stability-attr-top-level, r=d…
Centril Feb 13, 2019
b39b625
Rollup merge of #58354 - matthewjasper:mir-dump-fixes, r=wesleywiser
Centril Feb 13, 2019
8a4f8e6
Rollup merge of #58381 - davidtwco:issue-42944, r=estebank
Centril Feb 13, 2019
fceb169
Rollup merge of #58386 - Zoxc:fix-54242, r=michaelwoerister
Centril Feb 13, 2019
0178f31
Rollup merge of #58400 - gnzlbg:fix_driver, r=oli-obk
Centril Feb 13, 2019
05cfcb5
Rollup merge of #58420 - dvdhrm:target-uefi-comments, r=nagisa
Centril Feb 13, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 62 additions & 39 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,27 @@ pub fn write(output: &mut dyn Write, args: Arguments) -> Result {
Ok(())
}

/// Padding after the end of something. Returned by `Formatter::padding`.
#[must_use = "don't forget to write the post padding"]
struct PostPadding {
fill: char,
padding: usize,
}

impl PostPadding {
fn new(fill: char, padding: usize) -> PostPadding {
PostPadding { fill, padding }
}

/// Write this post padding.
fn write(self, buf: &mut dyn Write) -> Result {
for _ in 0..self.padding {
buf.write_char(self.fill)?;
}
Ok(())
}
}

impl<'a> Formatter<'a> {
fn wrap_buf<'b, 'c, F>(&'b mut self, wrap: F) -> Formatter<'c>
where 'b: 'c, F: FnOnce(&'b mut (dyn Write+'b)) -> &'c mut (dyn Write+'c)
Expand Down Expand Up @@ -1153,47 +1174,56 @@ impl<'a> Formatter<'a> {
sign = Some('+'); width += 1;
}

let prefixed = self.alternate();
if prefixed {
let prefix = if self.alternate() {
width += prefix.chars().count();
}
Some(prefix)
} else {
None
};

// Writes the sign if it exists, and then the prefix if it was requested
let write_prefix = |f: &mut Formatter| {
#[inline(never)]
fn write_prefix(f: &mut Formatter, sign: Option<char>, prefix: Option<&str>) -> Result {
if let Some(c) = sign {
f.buf.write_char(c)?;
}
if prefixed { f.buf.write_str(prefix) }
else { Ok(()) }
};
if let Some(prefix) = prefix {
f.buf.write_str(prefix)
} else {
Ok(())
}
}

// The `width` field is more of a `min-width` parameter at this point.
match self.width {
// If there's no minimum length requirements then we can just
// write the bytes.
None => {
write_prefix(self)?; self.buf.write_str(buf)
write_prefix(self, sign, prefix)?;
self.buf.write_str(buf)
}
// Check if we're over the minimum width, if so then we can also
// just write the bytes.
Some(min) if width >= min => {
write_prefix(self)?; self.buf.write_str(buf)
write_prefix(self, sign, prefix)?;
self.buf.write_str(buf)
}
// The sign and prefix goes before the padding if the fill character
// is zero
Some(min) if self.sign_aware_zero_pad() => {
self.fill = '0';
self.align = rt::v1::Alignment::Right;
write_prefix(self)?;
self.with_padding(min - width, rt::v1::Alignment::Right, |f| {
f.buf.write_str(buf)
})
write_prefix(self, sign, prefix)?;
let post_padding = self.padding(min - width, rt::v1::Alignment::Right)?;
self.buf.write_str(buf)?;
post_padding.write(self.buf)
}
// Otherwise, the sign and prefix goes after the padding
Some(min) => {
self.with_padding(min - width, rt::v1::Alignment::Right, |f| {
write_prefix(f)?; f.buf.write_str(buf)
})
let post_padding = self.padding(min - width, rt::v1::Alignment::Right)?;
write_prefix(self, sign, prefix)?;
self.buf.write_str(buf)?;
post_padding.write(self.buf)
}
}
}
Expand Down Expand Up @@ -1264,19 +1294,21 @@ impl<'a> Formatter<'a> {
// up the minimum width with the specified string + some alignment.
Some(width) => {
let align = rt::v1::Alignment::Left;
self.with_padding(width - s.chars().count(), align, |me| {
me.buf.write_str(s)
})
let post_padding = self.padding(width - s.chars().count(), align)?;
self.buf.write_str(s)?;
post_padding.write(self.buf)
}
}
}

/// Runs a callback, emitting the correct padding either before or
/// afterwards depending on whether right or left alignment is requested.
fn with_padding<F>(&mut self, padding: usize, default: rt::v1::Alignment,
f: F) -> Result
where F: FnOnce(&mut Formatter) -> Result,
{
/// Write the pre-padding and return the unwritten post-padding. Callers are
/// responsible for ensuring post-padding is written after the thing that is
/// being padded.
fn padding(
&mut self,
padding: usize,
default: rt::v1::Alignment
) -> result::Result<PostPadding, Error> {
let align = match self.align {
rt::v1::Alignment::Unknown => default,
_ => self.align
Expand All @@ -1289,20 +1321,11 @@ impl<'a> Formatter<'a> {
rt::v1::Alignment::Center => (padding / 2, (padding + 1) / 2),
};

let mut fill = [0; 4];
let fill = self.fill.encode_utf8(&mut fill);

for _ in 0..pre_pad {
self.buf.write_str(fill)?;
}

f(self)?;

for _ in 0..post_pad {
self.buf.write_str(fill)?;
self.buf.write_char(self.fill)?;
}

Ok(())
Ok(PostPadding::new(self.fill, post_pad))
}

/// Takes the formatted parts and applies the padding.
Expand Down Expand Up @@ -1334,9 +1357,9 @@ impl<'a> Formatter<'a> {
let ret = if width <= len { // no padding
self.write_formatted_parts(&formatted)
} else {
self.with_padding(width - len, align, |f| {
f.write_formatted_parts(&formatted)
})
let post_padding = self.padding(width - len, align)?;
self.write_formatted_parts(&formatted)?;
post_padding.write(self.buf)
};
self.fill = old_fill;
self.align = old_align;
Expand Down
87 changes: 52 additions & 35 deletions src/libcore/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,45 +178,36 @@ integer! { i32, u32 }
integer! { i64, u64 }
integer! { i128, u128 }

const DEC_DIGITS_LUT: &'static[u8] =

static DEC_DIGITS_LUT: &[u8; 200] =
b"0001020304050607080910111213141516171819\
2021222324252627282930313233343536373839\
4041424344454647484950515253545556575859\
6061626364656667686970717273747576777879\
8081828384858687888990919293949596979899";

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

unsafe {
// need at least 16 bits for the 4-characters-at-a-time to work.
if ::mem::size_of::<$t>() >= 2 {
// eagerly decode 4 characters at a time
while n >= 10000 {
let rem = (n % 10000) as isize;
n /= 10000;

let d1 = (rem / 100) << 1;
let d2 = (rem % 100) << 1;
curr -= 4;
ptr::copy_nonoverlapping(lut_ptr.offset(d1), buf_ptr.offset(curr), 2);
ptr::copy_nonoverlapping(lut_ptr.offset(d2), buf_ptr.offset(curr + 2), 2);
}
assert!(::mem::size_of::<$u>() >= 2);

// eagerly decode 4 characters at a time
while n >= 10000 {
let rem = (n % 10000) as isize;
n /= 10000;

let d1 = (rem / 100) << 1;
let d2 = (rem % 100) << 1;
curr -= 4;
ptr::copy_nonoverlapping(lut_ptr.offset(d1), buf_ptr.offset(curr), 2);
ptr::copy_nonoverlapping(lut_ptr.offset(d2), buf_ptr.offset(curr + 2), 2);
}

// if we reach here numbers are <= 9999, so at most 4 chars long
Expand Down Expand Up @@ -247,15 +238,41 @@ macro_rules! impl_Display {
};
f.pad_integral(is_nonnegative, "", buf_slice)
}
})*);

$(
#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Display for $t {
#[allow(unused_comparisons)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let is_nonnegative = *self >= 0;
let n = if is_nonnegative {
self.$conv_fn()
} else {
// convert the negative num to positive by summing 1 to it's 2 complement
(!self.$conv_fn()).wrapping_add(1)
};
$name(n, is_nonnegative, f)
}
})*
};
}

// Include wasm32 in here since it doesn't reflect the native pointer size, and
// often cares strongly about getting a smaller code size.
#[cfg(any(target_pointer_width = "64", target_arch = "wasm32"))]
mod imp {
use super::*;
impl_Display!(
i8, u8, i16, u16, i32, u32, i64, u64, usize, isize
as u64 via to_u64 named fmt_u64
);
}

#[cfg(not(any(target_pointer_width = "64", target_arch = "wasm32")))]
mod imp {
use super::*;
impl_Display!(i8, u8, i16, u16, i32, u32, isize, usize as u32 via to_u32 named fmt_u32);
impl_Display!(i64, u64 as u64 via to_u64 named fmt_u64);
}

impl_Display!(i8, u8, i16, u16, i32, u32: to_u32);
impl_Display!(i64, u64: to_u64);
impl_Display!(i128, u128: to_u128);
#[cfg(target_pointer_width = "16")]
impl_Display!(isize, usize: to_u16);
#[cfg(target_pointer_width = "32")]
impl_Display!(isize, usize: to_u32);
#[cfg(target_pointer_width = "64")]
impl_Display!(isize, usize: to_u64);
impl_Display!(i128, u128 as u128 via to_u128 named fmt_u128);
1 change: 1 addition & 0 deletions src/libpanic_unwind/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
authors = ["The Rust Project Developers"]
name = "panic_unwind"
version = "0.0.0"
edition = "2018"

[lib]
path = "lib.rs"
Expand Down
6 changes: 3 additions & 3 deletions src/libpanic_unwind/dwarf/eh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#![allow(non_upper_case_globals)]
#![allow(unused)]

use dwarf::DwarfReader;
use crate::dwarf::DwarfReader;
use core::mem;

pub const DW_EH_PE_omit: u8 = 0xFF;
Expand Down Expand Up @@ -51,7 +51,7 @@ pub enum EHAction {

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

pub unsafe fn find_eh_action(lsda: *const u8, context: &EHContext)
pub unsafe fn find_eh_action(lsda: *const u8, context: &EHContext<'_>)
-> Result<EHAction, ()>
{
if lsda.is_null() {
Expand Down Expand Up @@ -145,7 +145,7 @@ fn round_up(unrounded: usize, align: usize) -> Result<usize, ()> {
}

unsafe fn read_encoded_pointer(reader: &mut DwarfReader,
context: &EHContext,
context: &EHContext<'_>,
encoding: u8)
-> Result<usize, ()> {
if encoding == DW_EH_PE_omit {
Expand Down
2 changes: 1 addition & 1 deletion src/libpanic_unwind/emcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

use core::any::Any;
use core::ptr;
use core::mem;
use alloc::boxed::Box;
use libc::{self, c_int};
use unwind as uw;
use core::mem;

pub fn payload() -> *mut u8 {
ptr::null_mut()
Expand Down
2 changes: 1 addition & 1 deletion src/libpanic_unwind/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use alloc::boxed::Box;

use unwind as uw;
use libc::{c_int, uintptr_t};
use dwarf::eh::{self, EHContext, EHAction};
use crate::dwarf::eh::{self, EHContext, EHAction};

#[repr(C)]
struct Exception {
Expand Down
9 changes: 3 additions & 6 deletions src/libpanic_unwind/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/",
issue_tracker_base_url = "/~https://github.com/rust-lang/rust/issues/")]

#![deny(rust_2018_idioms)]

#![feature(allocator_api)]
#![feature(alloc)]
#![feature(core_intrinsics)]
Expand All @@ -32,11 +34,6 @@
#![panic_runtime]
#![feature(panic_runtime)]

extern crate alloc;
extern crate libc;
#[cfg(not(any(target_env = "msvc", all(windows, target_arch = "x86_64", target_env = "gnu"))))]
extern crate unwind;

use alloc::boxed::Box;
use core::intrinsics;
use core::mem;
Expand Down Expand Up @@ -87,7 +84,7 @@ pub unsafe extern "C" fn __rust_maybe_catch_panic(f: fn(*mut u8),
vtable_ptr: *mut usize)
-> u32 {
let mut payload = imp::payload();
if intrinsics::try(f, data, &mut payload as *mut _ as *mut _) == 0 {
if intrinsics::r#try(f, data, &mut payload as *mut _ as *mut _) == 0 {
0
} else {
let obj = mem::transmute::<_, raw::TraitObject>(imp::cleanup(payload));
Expand Down
4 changes: 2 additions & 2 deletions src/libpanic_unwind/seh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use core::any::Any;
use core::mem;
use core::raw;

use windows as c;
use crate::windows as c;
use libc::{c_int, c_uint};

// First up, a whole bunch of type definitions. There's a few platform-specific
Expand Down Expand Up @@ -301,5 +301,5 @@ pub unsafe fn cleanup(payload: [u64; 2]) -> Box<dyn Any + Send> {
#[lang = "eh_personality"]
#[cfg(not(test))]
fn rust_eh_personality() {
unsafe { ::core::intrinsics::abort() }
unsafe { core::intrinsics::abort() }
}
4 changes: 2 additions & 2 deletions src/libpanic_unwind/seh64_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use alloc::boxed::Box;
use core::any::Any;
use core::intrinsics;
use core::ptr;
use dwarf::eh::{EHContext, EHAction, find_eh_action};
use windows as c;
use crate::dwarf::eh::{EHContext, EHAction, find_eh_action};
use crate::windows as c;

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