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 #58426

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b91ccc3
On return type `impl Trait` for block with no expr point at last semi
estebank Feb 5, 2019
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
0afda05
Add fixme
estebank 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
9cb5831
Rollup merge of #58167 - ljedrz:HirIdify_body_id, r=Zoxc
Centril Feb 13, 2019
a603e2a
Rollup merge of #58202 - varkor:deprecated-future-external, r=Guillau…
Centril Feb 13, 2019
7579ba9
Rollup merge of #58204 - estebank:impl-trait-semi, r=zackmdavis
Centril Feb 13, 2019
dfd8454
Rollup merge of #58272 - fitzgen:num-format-code-size, r=Mark-Simulacrum
Centril Feb 13, 2019
d18e4f0
Rollup merge of #58276 - varkor:missing-stability-attr-top-level, r=d…
Centril Feb 13, 2019
e35e9ee
Rollup merge of #58354 - matthewjasper:mir-dump-fixes, r=wesleywiser
Centril Feb 13, 2019
2a61352
Rollup merge of #58381 - davidtwco:issue-42944, r=estebank
Centril Feb 13, 2019
61caf1f
Rollup merge of #58386 - Zoxc:fix-54242, r=michaelwoerister
Centril Feb 13, 2019
df020a7
Rollup merge of #58400 - gnzlbg:fix_driver, r=oli-obk
Centril Feb 13, 2019
01533d4
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);
29 changes: 24 additions & 5 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ impl<'hir> Entry<'hir> {
}
}

fn is_body_owner(self, node_id: NodeId) -> bool {
fn is_body_owner(self, hir_id: HirId) -> bool {
match self.associated_body() {
Some(b) => b.node_id == node_id,
Some(b) => b.hir_id == hir_id,
None => false,
}
}
Expand Down Expand Up @@ -438,7 +438,7 @@ impl<'hir> Map<'hir> {
}

pub fn body(&self, id: BodyId) -> &'hir Body {
self.read(id.node_id);
self.read_by_hir_id(id.hir_id);

// N.B., intentionally bypass `self.forest.krate()` so that we
// do not trigger a read of the whole krate here
Expand All @@ -462,9 +462,10 @@ impl<'hir> Map<'hir> {
/// Returns the `NodeId` that corresponds to the definition of
/// which this is the body of, i.e., a `fn`, `const` or `static`
/// item (possibly associated), a closure, or a `hir::AnonConst`.
pub fn body_owner(&self, BodyId { node_id }: BodyId) -> NodeId {
pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> NodeId {
let node_id = self.hir_to_node_id(hir_id);
let parent = self.get_parent_node(node_id);
assert!(self.map[parent.as_usize()].map_or(false, |e| e.is_body_owner(node_id)));
assert!(self.map[parent.as_usize()].map_or(false, |e| e.is_body_owner(hir_id)));
parent
}

Expand All @@ -488,6 +489,12 @@ impl<'hir> Map<'hir> {
}
}

// FIXME(@ljedrz): replace the NodeId variant
pub fn maybe_body_owned_by_by_hir_id(&self, id: HirId) -> Option<BodyId> {
let node_id = self.hir_to_node_id(id);
self.maybe_body_owned_by(node_id)
}

/// Given a body owner's id, returns the `BodyId` associated with it.
pub fn body_owned_by(&self, id: NodeId) -> BodyId {
self.maybe_body_owned_by(id).unwrap_or_else(|| {
Expand Down Expand Up @@ -521,6 +528,12 @@ impl<'hir> Map<'hir> {
}
}

// FIXME(@ljedrz): replace the NodeId variant
pub fn body_owner_kind_by_hir_id(&self, id: HirId) -> BodyOwnerKind {
let node_id = self.hir_to_node_id(id);
self.body_owner_kind(node_id)
}

pub fn ty_param_owner(&self, id: NodeId) -> NodeId {
match self.get(id) {
Node::Item(&Item { node: ItemKind::Trait(..), .. }) => id,
Expand Down Expand Up @@ -837,6 +850,12 @@ impl<'hir> Map<'hir> {
self.local_def_id(self.get_module_parent_node(id))
}

// FIXME(@ljedrz): replace the NodeId variant
pub fn get_module_parent_by_hir_id(&self, id: HirId) -> DefId {
let node_id = self.hir_to_node_id(id);
self.get_module_parent(node_id)
}

/// Returns the `NodeId` of `id`'s nearest module parent, or `id` itself if no
/// module parent is in this map.
pub fn get_module_parent_node(&self, id: NodeId) -> NodeId {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub mod print;
/// the `local_id` part of the `HirId` changing, which is a very useful property in
/// incremental compilation where we have to persist things through changes to
/// the code base.
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)]
pub struct HirId {
pub owner: DefIndex,
pub local_id: ItemLocalId,
Expand Down Expand Up @@ -1234,7 +1234,7 @@ pub enum UnsafeSource {

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct BodyId {
pub node_id: NodeId,
pub hir_id: HirId,
}

/// The body of a function, closure, or constant value. In the case of
Expand Down Expand Up @@ -1268,7 +1268,7 @@ pub struct Body {
impl Body {
pub fn id(&self) -> BodyId {
BodyId {
node_id: self.value.id
hir_id: self.value.hir_id,
}
}
}
Expand Down Expand Up @@ -2290,7 +2290,7 @@ impl ItemKind {
ItemKind::Union(..) => "union",
ItemKind::Trait(..) => "trait",
ItemKind::TraitAlias(..) => "trait alias",
ItemKind::Impl(..) => "item",
ItemKind::Impl(..) => "impl",
}
}

Expand Down
Loading