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 7 pull requests #48744

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e822e62
Suggest type for overflowing bin/hex-literals
flip1995 Feb 22, 2018
19c4771
Implementing requested changes
flip1995 Feb 22, 2018
5c70619
Rewrite error reporting as requested
flip1995 Feb 24, 2018
f45f760
Adapt stderr of UI test to PR #48449
flip1995 Mar 1, 2018
08504fb
Optimize str::repeat
sinkuu Mar 2, 2018
15ecf06
Remove isize test
flip1995 Mar 2, 2018
fc33b25
Improve getting literal representation
flip1995 Mar 3, 2018
683bdc7
Add comments
sinkuu Mar 4, 2018
3d58543
Avoid unnecessary calculation
sinkuu Mar 4, 2018
0b0e1b7
Refactor contrived match.
leoyvens Mar 4, 2018
16ac85c
Remove useless powerpc64 entry from ARCH_TABLE, closes #47737
debris Mar 4, 2018
6fdf637
Fixed #48425
PramodBisht Feb 27, 2018
72231a4
rustc: Migrate to `termcolor` crate from `term`
alexcrichton Feb 27, 2018
c6706ea
Expand items before their `#[derive]`s.
jseyfried Apr 2, 2017
09e45bd
Rollup merge of #48432 - flip1995:lit_diag, r=oli-obk
Manishearth Mar 5, 2018
397ed19
Rollup merge of #48465 - abonander:expansion_order, r=petrochenkov
Manishearth Mar 5, 2018
c8f1f2e
Rollup merge of #48588 - alexcrichton:termcolor, r=BurntSushi
Manishearth Mar 5, 2018
4fcc87a
Rollup merge of #48651 - PramodBisht:issues/48425, r=oli-obk
Manishearth Mar 5, 2018
aff626a
Rollup merge of #48657 - sinkuu:opt_str_repeat, r=dtolnay
Manishearth Mar 5, 2018
6b4a9c1
Rollup merge of #48727 - leodasvacas:refactor-contrived-match, r=rkruppe
Manishearth Mar 5, 2018
895ab22
Rollup merge of #48732 - debris:remove_powerpc64, r=alexcrichton
Manishearth Mar 5, 2018
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
2 changes: 2 additions & 0 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
#![feature(allocator_internals)]
#![feature(on_unimplemented)]
#![feature(exact_chunks)]
#![feature(pointer_methods)]

#![cfg_attr(not(test), feature(fused, fn_traits, placement_new_protocol, swap_with_slice, i128))]
#![cfg_attr(test, feature(test, box_heap))]
Expand Down
57 changes: 54 additions & 3 deletions src/liballoc/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use core::str as core_str;
use core::str::pattern::Pattern;
use core::str::pattern::{Searcher, ReverseSearcher, DoubleEndedSearcher};
use core::mem;
use core::ptr;
use core::iter::FusedIterator;
use std_unicode::str::{UnicodeStr, Utf16Encoder};

Expand Down Expand Up @@ -2066,9 +2067,59 @@ impl str {
/// ```
#[stable(feature = "repeat_str", since = "1.16.0")]
pub fn repeat(&self, n: usize) -> String {
let mut s = String::with_capacity(self.len() * n);
s.extend((0..n).map(|_| self));
s
if n == 0 {
return String::new();
}

// If `n` is larger than zero, it can be split as
// `n = 2^expn + rem (2^expn > rem, expn >= 0, rem >= 0)`.
// `2^expn` is the number represented by the leftmost '1' bit of `n`,
// and `rem` is the remaining part of `n`.

// Using `Vec` to access `set_len()`.
let mut buf = Vec::with_capacity(self.len() * n);

// `2^expn` repetition is done by doubling `buf` `expn`-times.
buf.extend(self.as_bytes());
{
let mut m = n >> 1;
// If `m > 0`, there are remaining bits up to the leftmost '1'.
while m > 0 {
// `buf.extend(buf)`:
unsafe {
ptr::copy_nonoverlapping(
buf.as_ptr(),
(buf.as_mut_ptr() as *mut u8).add(buf.len()),
buf.len(),
);
// `buf` has capacity of `self.len() * n`.
let buf_len = buf.len();
buf.set_len(buf_len * 2);
}

m >>= 1;
}
}

// `rem` (`= n - 2^expn`) repetition is done by copying
// first `rem` repetitions from `buf` itself.
let rem_len = self.len() * n - buf.len(); // `self.len() * rem`
if rem_len > 0 {
// `buf.extend(buf[0 .. rem_len])`:
unsafe {
// This is non-overlapping since `2^expn > rem`.
ptr::copy_nonoverlapping(
buf.as_ptr(),
(buf.as_mut_ptr() as *mut u8).add(buf.len()),
rem_len,
);
// `buf.len() + rem_len` equals to `buf.capacity()` (`= self.len() * n`).
let buf_cap = buf.capacity();
buf.set_len(buf_cap);
}
}

unsafe { String::from_utf8_unchecked(buf) }
}

/// Checks if all characters in this string are within the ASCII range.
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
}

let pointee = tcx.normalize_associated_type_in_env(&pointee, param_env);
if pointee.is_sized(tcx, param_env, DUMMY_SP) {
if pointee.is_sized(tcx.at(DUMMY_SP), param_env) {
return Ok(tcx.intern_layout(LayoutDetails::scalar(self, data_ptr)));
}

Expand Down Expand Up @@ -1428,7 +1428,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
let param_env = tcx.param_env(def.did);
let last_field = def.variants[v].fields.last().unwrap();
let always_sized = tcx.type_of(last_field.did)
.is_sized(tcx, param_env, DUMMY_SP);
.is_sized(tcx.at(DUMMY_SP), param_env);
if !always_sized { StructKind::MaybeUnsized }
else { StructKind::AlwaysSized }
};
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use traits::{self, Reveal};
use ty::{self, Ty, TyCtxt, TypeFoldable};
use ty::fold::TypeVisitor;
use ty::subst::{Subst, UnpackedKind};
use ty::maps::TyCtxtAt;
use ty::TypeVariants::*;
use util::common::ErrorReported;
use middle::lang_items;
Expand Down Expand Up @@ -864,11 +865,10 @@ impl<'a, 'tcx> ty::TyS<'tcx> {
}

pub fn is_sized(&'tcx self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
span: Span)-> bool
tcx_at: TyCtxtAt<'a, 'tcx, 'tcx>,
param_env: ty::ParamEnv<'tcx>)-> bool
{
tcx.at(span).is_sized_raw(param_env.and(self))
tcx_at.is_sized_raw(param_env.and(self))
}

pub fn is_freeze(&'tcx self,
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ serialize = { path = "../libserialize" }
syntax_pos = { path = "../libsyntax_pos" }
rustc_data_structures = { path = "../librustc_data_structures" }
unicode-width = "0.1.4"
atty = "0.2"
termcolor = "0.3"
Loading