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 11 pull requests #58831

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1fd2f16
Have all methods of Filter and FilterMap use internal iteration
timvermeulen Feb 25, 2019
d89c2f6
Use informational target machine for metadata
nagisa Feb 20, 2019
8884771
Add relevant benchmarks
timvermeulen Feb 27, 2019
ec2e4ba
Improve existing benchmarks to prevent extreme optimizations
timvermeulen Feb 27, 2019
88bd624
Add trailing newline
timvermeulen Feb 27, 2019
932fe17
rust-lldb: fix crash when printing empty string
euclio Feb 22, 2019
4e7d4c7
ManuallyDrop != MaybeUninit
RalfJung Feb 27, 2019
b70a953
Replace `s` with `self` in docs for str methods taking self.
tspiteri Feb 20, 2019
f92c204
improve readability
RalfJung Feb 27, 2019
a046c38
Make migrate mode work at item level granularity
matthewjasper Feb 27, 2019
a998b1f
allow specifying attributes for tool lints
euclio Feb 27, 2019
fc4b916
Add a test for #10876
varkor Feb 25, 2019
e206d4e
Add tests for #26448
varkor Feb 25, 2019
93ff7dc
Add a test for #26619
varkor Feb 25, 2019
987d71f
Add a test for #44127
varkor Feb 25, 2019
bdd3826
Add a test for #44255
varkor Feb 25, 2019
36b1326
Add a test for #46101
varkor Feb 25, 2019
1068424
Add a test for #55731
varkor Feb 25, 2019
525dc46
Add a test for #57781
varkor Feb 25, 2019
5fb2d8b
Add a test for #22892
varkor Feb 25, 2019
0976e5e
Add a test for #28587
varkor Feb 25, 2019
42a89c6
Add a test for #26577
varkor Feb 25, 2019
0df193f
Add a test for #27054
varkor Feb 25, 2019
70b853d
Update test for issue #55731
varkor Feb 26, 2019
797d8ea
Make `Unique::as_ptr`, `NonNull::dangling` and `NonNull::cast` const
Feb 28, 2019
0c1a38c
Update src/libcore/mem.rs
Centril Feb 28, 2019
96be181
Fixed a syntax error in the pin docs
Feb 28, 2019
3391f6c
tidy: deny(rust_2018_idioms)
Centril Mar 1, 2019
059121b
Rollup merge of #58605 - nagisa:fix-the-metadata, r=michaelwoerister
pietroalbini Mar 1, 2019
cb09ce2
Rollup merge of #58629 - euclio:debug-empty-str, r=alexcrichton
pietroalbini Mar 1, 2019
11e7256
Rollup merge of #58730 - timvermeulen:internal_iteration, r=scottmcm
pietroalbini Mar 1, 2019
fcf734c
Rollup merge of #58743 - varkor:bulk-needstest-1, r=alexcrichton
pietroalbini Mar 1, 2019
faeba62
Rollup merge of #58750 - TimDiekmann:master, r=oli-obk
pietroalbini Mar 1, 2019
20409cc
Rollup merge of #58780 - RalfJung:manually-drop, r=nagisa
pietroalbini Mar 1, 2019
15c1c1f
Rollup merge of #58782 - tspiteri:str-escape-self, r=kennytm
pietroalbini Mar 1, 2019
9bbd413
Rollup merge of #58785 - euclio:tool-lint-attrs, r=estebank
pietroalbini Mar 1, 2019
ba87c3d
Rollup merge of #58788 - matthewjasper:compare-children, r=pnkfelix
pietroalbini Mar 1, 2019
583bea5
Rollup merge of #58821 - alex:patch-1, r=Centril
pietroalbini Mar 1, 2019
5de3f96
Rollup merge of #58830 - Centril:rust_2018_idioms-tidy, r=oli-obk
pietroalbini Mar 1, 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
2 changes: 2 additions & 0 deletions src/etc/lldb_rust_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ def render_element(i):


def read_utf8_string(ptr_val, byte_count):
if byte_count == 0:
return '""'
error = lldb.SBError()
process = ptr_val.get_wrapped_value().GetProcess()
data = process.ReadMemory(ptr_val.as_integer(), byte_count, error)
Expand Down
32 changes: 30 additions & 2 deletions src/libcore/benches/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ bench_sums! {
bench_sums! {
bench_filter_sum,
bench_filter_ref_sum,
(0i64..1000000).filter(|x| x % 2 == 0)
(0i64..1000000).filter(|x| x % 3 == 0)
}

bench_sums! {
bench_filter_chain_sum,
bench_filter_chain_ref_sum,
(0i64..1000000).chain(0..1000000).filter(|x| x % 2 == 0)
(0i64..1000000).chain(0..1000000).filter(|x| x % 3 == 0)
}

bench_sums! {
Expand Down Expand Up @@ -306,3 +306,31 @@ fn bench_skip_then_zip(b: &mut Bencher) {
assert_eq!(s, 2009900);
});
}

#[bench]
fn bench_filter_count(b: &mut Bencher) {
b.iter(|| {
(0i64..1000000).map(black_box).filter(|x| x % 3 == 0).count()
})
}

#[bench]
fn bench_filter_ref_count(b: &mut Bencher) {
b.iter(|| {
(0i64..1000000).map(black_box).by_ref().filter(|x| x % 3 == 0).count()
})
}

#[bench]
fn bench_filter_chain_count(b: &mut Bencher) {
b.iter(|| {
(0i64..1000000).chain(0..1000000).map(black_box).filter(|x| x % 3 == 0).count()
})
}

#[bench]
fn bench_filter_chain_ref_count(b: &mut Bencher) {
b.iter(|| {
(0i64..1000000).chain(0..1000000).map(black_box).by_ref().filter(|x| x % 3 == 0).count()
})
}
37 changes: 7 additions & 30 deletions src/libcore/iter/adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,12 +681,7 @@ impl<I: Iterator, P> Iterator for Filter<I, P> where P: FnMut(&I::Item) -> bool

#[inline]
fn next(&mut self) -> Option<I::Item> {
for x in &mut self.iter {
if (self.predicate)(&x) {
return Some(x);
}
}
None
self.try_for_each(Err).err()
}

#[inline]
Expand All @@ -707,12 +702,9 @@ impl<I: Iterator, P> Iterator for Filter<I, P> where P: FnMut(&I::Item) -> bool
// Using the branchless version will also simplify the LLVM byte code, thus
// leaving more budget for LLVM optimizations.
#[inline]
fn count(mut self) -> usize {
let mut count = 0;
for x in &mut self.iter {
count += (self.predicate)(&x) as usize;
}
count
fn count(self) -> usize {
let mut predicate = self.predicate;
self.iter.map(|x| predicate(&x) as usize).sum()
}

#[inline]
Expand Down Expand Up @@ -746,12 +738,7 @@ impl<I: DoubleEndedIterator, P> DoubleEndedIterator for Filter<I, P>
{
#[inline]
fn next_back(&mut self) -> Option<I::Item> {
for x in self.iter.by_ref().rev() {
if (self.predicate)(&x) {
return Some(x);
}
}
None
self.try_rfold((), |_, x| Err(x)).err()
}

#[inline]
Expand Down Expand Up @@ -820,12 +807,7 @@ impl<B, I: Iterator, F> Iterator for FilterMap<I, F>

#[inline]
fn next(&mut self) -> Option<B> {
for x in self.iter.by_ref() {
if let Some(y) = (self.f)(x) {
return Some(y);
}
}
None
self.try_for_each(Err).err()
}

#[inline]
Expand Down Expand Up @@ -863,12 +845,7 @@ impl<B, I: DoubleEndedIterator, F> DoubleEndedIterator for FilterMap<I, F>
{
#[inline]
fn next_back(&mut self) -> Option<B> {
for x in self.iter.by_ref().rev() {
if let Some(y) = (self.f)(x) {
return Some(y);
}
}
None
self.try_rfold((), |_, x| Err(x)).err()
}

#[inline]
Expand Down
8 changes: 8 additions & 0 deletions src/libcore/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,10 +900,16 @@ pub fn discriminant<T>(v: &T) -> Discriminant<T> {
}
}

// FIXME: Reference `MaybeUninit` from these docs, once that is stable.
/// A wrapper to inhibit compiler from automatically calling `T`’s destructor.
///
/// This wrapper is 0-cost.
///
/// `ManuallyDrop<T>` is subject to the same layout optimizations as `T`.
/// As a consequence, it has *no effect* on the assumptions that the compiler makes
/// about all values being initialized at their type. In particular, initializing
/// a `ManuallyDrop<&mut T>` with [`mem::zeroed`] is undefined behavior.
///
/// # Examples
///
/// This wrapper helps with explicitly documenting the drop order dependencies between fields of
Expand Down Expand Up @@ -935,6 +941,8 @@ pub fn discriminant<T>(v: &T) -> Discriminant<T> {
/// }
/// }
/// ```
///
/// [`mem::zeroed`]: fn.zeroed.html
#[stable(feature = "manually_drop", since = "1.20.0")]
#[lang = "manually_drop"]
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
//! had a method `fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut T>`.
//! Then we could do the following:
//! ```compile_fail
//! fn exploit_ref_cell<T>(rc: Pin<&mut RefCell<T>) {
//! fn exploit_ref_cell<T>(rc: Pin<&mut RefCell<T>>) {
//! { let p = rc.as_mut().get_pin_mut(); } // Here we get pinned access to the `T`.
//! let rc_shr: &RefCell<T> = rc.into_ref().get_ref();
//! let b = rc_shr.borrow_mut();
Expand Down
8 changes: 5 additions & 3 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2790,7 +2790,7 @@ impl<T: ?Sized> Unique<T> {
}

/// Acquires the underlying `*mut` pointer.
pub fn as_ptr(self) -> *mut T {
pub const fn as_ptr(self) -> *mut T {
self.pointer as *mut T
}

Expand Down Expand Up @@ -2903,7 +2903,8 @@ impl<T: Sized> NonNull<T> {
/// some other means.
#[stable(feature = "nonnull", since = "1.25.0")]
#[inline]
pub fn dangling() -> Self {
#[cfg_attr(not(stage0), rustc_const_unstable(feature = "const_ptr_nonnull"))]
pub const fn dangling() -> Self {
unsafe {
let ptr = mem::align_of::<T>() as *mut T;
NonNull::new_unchecked(ptr)
Expand Down Expand Up @@ -2966,7 +2967,8 @@ impl<T: ?Sized> NonNull<T> {
/// Cast to a pointer of another type
#[stable(feature = "nonnull_cast", since = "1.27.0")]
#[inline]
pub fn cast<U>(self) -> NonNull<U> {
#[cfg_attr(not(stage0), rustc_const_unstable(feature = "const_ptr_nonnull"))]
pub const fn cast<U>(self) -> NonNull<U> {
unsafe {
NonNull::new_unchecked(self.as_ptr() as *mut U)
}
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3965,7 +3965,7 @@ impl str {
me.make_ascii_lowercase()
}

/// Return an iterator that escapes each char in `s` with [`char::escape_debug`].
/// Return an iterator that escapes each char in `self` with [`char::escape_debug`].
///
/// Note: only extended grapheme codepoints that begin the string will be
/// escaped.
Expand Down Expand Up @@ -4013,7 +4013,7 @@ impl str {
}
}

/// Return an iterator that escapes each char in `s` with [`char::escape_default`].
/// Return an iterator that escapes each char in `self` with [`char::escape_default`].
///
/// [`char::escape_default`]: ../std/primitive.char.html#method.escape_default
///
Expand Down Expand Up @@ -4051,7 +4051,7 @@ impl str {
EscapeDefault { inner: self.chars().flat_map(CharEscapeDefault) }
}

/// Return an iterator that escapes each char in `s` with [`char::escape_unicode`].
/// Return an iterator that escapes each char in `self` with [`char::escape_unicode`].
///
/// [`char::escape_unicode`]: ../std/primitive.char.html#method.escape_unicode
///
Expand Down
20 changes: 14 additions & 6 deletions src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,22 @@ macro_rules! declare_lint {

#[macro_export]
macro_rules! declare_tool_lint {
($vis: vis $tool: ident ::$NAME: ident, $Level: ident, $desc: expr) => (
declare_tool_lint!{$vis $tool::$NAME, $Level, $desc, false}
(
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level: ident, $desc: expr
) => (
declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, false}
);
($vis: vis $tool: ident ::$NAME: ident, $Level: ident, $desc: expr,
report_in_external_macro: $rep: expr) => (
declare_tool_lint!{$vis $tool::$NAME, $Level, $desc, $rep}
(
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
report_in_external_macro: $rep:expr
) => (
declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, $rep}
);
($vis: vis $tool: ident ::$NAME: ident, $Level: ident, $desc: expr, $external: expr) => (
(
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
$external:expr
) => (
$(#[$attr])*
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
name: &concat!(stringify!($tool), "::", stringify!($NAME)),
default_level: $crate::lint::$Level,
Expand Down
8 changes: 6 additions & 2 deletions src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ pub trait Delegate<'tcx> {
assignment_span: Span,
assignee_cmt: &mc::cmt_<'tcx>,
mode: MutateMode);

// A nested closure or generator - only one layer deep.
fn nested_body(&mut self, _body_id: hir::BodyId) {}
}

#[derive(Copy, Clone, PartialEq, Debug)]
Expand Down Expand Up @@ -532,8 +535,9 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
self.consume_expr(&base);
}

hir::ExprKind::Closure(.., fn_decl_span, _) => {
self.walk_captures(expr, fn_decl_span)
hir::ExprKind::Closure(_, _, body_id, fn_decl_span, _) => {
self.delegate.nested_body(body_id);
self.walk_captures(expr, fn_decl_span);
}

hir::ExprKind::Box(ref base) => {
Expand Down
16 changes: 16 additions & 0 deletions src/librustc_borrowck/borrowck/check_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> {
}

fn decl_without_init(&mut self, _id: ast::NodeId, _span: Span) { }

fn nested_body(&mut self, body_id: hir::BodyId) {
// rust-lang/rust#58776: MIR and AST borrow check disagree on where
// certain closure errors are reported. As such migrate borrowck has to
// operate at the level of items, rather than bodies. Check if the
// contained closure had any errors and set `signalled_any_error` if it
// has.
let bccx = self.bccx;
if bccx.tcx.migrate_borrowck() {
if let SignalledError::NoErrorsSeen = bccx.signalled_any_error.get() {
let closure_def_id = bccx.tcx.hir().body_owner_def_id(body_id);

bccx.signalled_any_error.set(bccx.tcx.borrowck(closure_def_id).signalled_any_error);
}
}
}
}

pub fn check_loans<'a, 'b, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
Expand Down
10 changes: 0 additions & 10 deletions src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ use crate::common;
use crate::LlvmCodegenBackend;
use rustc_codegen_ssa::back::write::{CodegenContext, ModuleConfig, run_assembler};
use rustc_codegen_ssa::traits::*;
use rustc::hir::def_id::LOCAL_CRATE;
use rustc::session::config::{self, OutputType, Passes, Lto};
use rustc::session::Session;
use rustc::ty::TyCtxt;
use rustc_codegen_ssa::{ModuleCodegen, CompiledModule};
use rustc::util::common::time_ext;
use rustc_fs_util::{path_to_c_string, link_or_copy};
Expand Down Expand Up @@ -82,14 +80,6 @@ pub fn write_output_file(
}
}

pub fn create_target_machine(
tcx: TyCtxt<'_, '_, '_>,
find_features: bool,
) -> &'static mut llvm::TargetMachine {
target_machine_factory(tcx.sess, tcx.backend_optimization_level(LOCAL_CRATE), find_features)()
.unwrap_or_else(|err| llvm_err(tcx.sess.diagnostic(), &err).raise() )
}

pub fn create_informational_target_machine(
sess: &Session,
find_features: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub unsafe fn create_module(

// Ensure the data-layout values hardcoded remain the defaults.
if sess.target.target.options.is_builtin {
let tm = crate::back::write::create_target_machine(tcx, false);
let tm = crate::back::write::create_informational_target_machine(&tcx.sess, false);
llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, tm);
llvm::LLVMRustDisposeTargetMachine(tm);

Expand Down
10 changes: 5 additions & 5 deletions src/librustc_codegen_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#![deny(rust_2018_idioms)]
#![allow(explicit_outlives_requirements)]

use back::write::create_target_machine;
use back::write::create_informational_target_machine;
use syntax_pos::symbol::Symbol;

extern crate flate2;
Expand Down Expand Up @@ -114,8 +114,9 @@ pub struct LlvmCodegenBackend(());

impl ExtraBackendMethods for LlvmCodegenBackend {
fn new_metadata(&self, tcx: TyCtxt<'_, '_, '_>, mod_name: &str) -> ModuleLlvm {
ModuleLlvm::new(tcx, mod_name)
ModuleLlvm::new_metadata(tcx, mod_name)
}

fn write_metadata<'b, 'gcx>(
&self,
tcx: TyCtxt<'b, 'gcx, 'gcx>,
Expand Down Expand Up @@ -366,15 +367,14 @@ unsafe impl Send for ModuleLlvm { }
unsafe impl Sync for ModuleLlvm { }

impl ModuleLlvm {
fn new(tcx: TyCtxt<'_, '_, '_>, mod_name: &str) -> Self {
fn new_metadata(tcx: TyCtxt<'_, '_, '_>, mod_name: &str) -> Self {
unsafe {
let llcx = llvm::LLVMRustContextCreate(tcx.sess.fewer_names());
let llmod_raw = context::create_module(tcx, llcx, mod_name) as *const _;

ModuleLlvm {
llmod_raw,
llcx,
tm: create_target_machine(tcx, false),
tm: create_informational_target_machine(&tcx.sess, false),
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,13 @@ fn start_executing_work<B: ExtraBackendMethods>(
None
};

let ol = tcx.backend_optimization_level(LOCAL_CRATE);
let ol = if tcx.sess.opts.debugging_opts.no_codegen
|| !tcx.sess.opts.output_types.should_codegen() {
// If we know that we won’t be doing codegen, create target machines without optimisation.
config::OptLevel::No
} else {
tcx.backend_optimization_level(LOCAL_CRATE)
};
let cgcx = CodegenContext::<B> {
backend: backend.clone(),
crate_types: sess.crate_types.borrow().clone(),
Expand Down
Loading