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 9 pull requests #73838

Merged
merged 32 commits into from
Jun 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4c8ce48
Add partition_point
VillSnow Jun 21, 2020
c9b4915
fix: doc test
VillSnow Jun 21, 2020
27b06f1
update: doc comment
VillSnow Jun 22, 2020
8cc6998
add: tests
VillSnow Jun 22, 2020
558c8a8
Handle stores to projections correctly in liveness analysis
ecstatic-morse Jun 26, 2020
2340197
Add peek test for projections
ecstatic-morse Jun 26, 2020
88fe556
Add test for issue-71381
JohnTitor Jun 27, 2020
4c14f9d
Forward Hash::write_iN to Hash::write_uN
nikic Jun 27, 2020
99884bd
Add test for issue-71382
JohnTitor Jun 27, 2020
7125ce7
Add test for issue-71611
JohnTitor Jun 27, 2020
1d16aed
Add test for issue-72352
JohnTitor Jun 27, 2020
ffcfaa1
Fix comment.
ecstatic-morse Jun 27, 2020
6d0e5bf
Rename two `Resolver` traits
petrochenkov Jun 27, 2020
c72a5dd
Rename the lint to clashing_extern_declarations.
jumbatm Jun 28, 2020
8291a22
Fix docstring typo
cjrh Jun 28, 2020
52f9762
Add comment on use of unsafe
VillSnow Jun 28, 2020
9335787
Update src/libcore/slice/mod.rs
VillSnow Jun 28, 2020
83d5998
Merge branch 'master' of https://github.com/VillSnow/rust
VillSnow Jun 28, 2020
d720a19
Update doc comment
VillSnow Jun 28, 2020
60f2ba2
Update tracking issue number
VillSnow Jun 28, 2020
4d978af
Remove GlobalCtxt::enter_local
bjorn3 Jun 28, 2020
b9f4e0d
Erase all block-only locals at the end of every block, even if they h…
oli-obk Jun 26, 2020
6f8ad3b
Update src/libcore/slice/mod.rs
VillSnow Jun 28, 2020
ec48989
Rollup merge of #73577 - VillSnow:master, r=Amanieu
Manishearth Jun 28, 2020
ccc1bf7
Rollup merge of #73757 - oli-obk:const_prop_hardening, r=wesleywiser
Manishearth Jun 28, 2020
3f826a8
Rollup merge of #73774 - ecstatic-morse:liveness-of-projections, r=ol…
Manishearth Jun 28, 2020
2c1b732
Rollup merge of #73795 - JohnTitor:tests-for-const-fn-ptrs, r=oli-obk
Manishearth Jun 28, 2020
95da53f
Rollup merge of #73800 - nikic:hash_i, r=kennytm
Manishearth Jun 28, 2020
dd81139
Rollup merge of #73813 - petrochenkov:restrait, r=davidtwco
Manishearth Jun 28, 2020
8b92eec
Rollup merge of #73817 - jumbatm:rename-to-clashing-extern-declaratio…
Manishearth Jun 28, 2020
5304511
Rollup merge of #73826 - cjrh:cjrh-patch-1, r=jonas-schievink
Manishearth Jun 28, 2020
117b734
Rollup merge of #73833 - bjorn3:remove_gcx_enter_local, r=matthewjasper
Manishearth Jun 28, 2020
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
10 changes: 5 additions & 5 deletions src/libcore/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,31 +333,31 @@ pub trait Hasher {
#[inline]
#[stable(feature = "hasher_write", since = "1.3.0")]
fn write_i16(&mut self, i: i16) {
self.write(&i.to_ne_bytes())
self.write_u16(i as u16)
}
/// Writes a single `i32` into this hasher.
#[inline]
#[stable(feature = "hasher_write", since = "1.3.0")]
fn write_i32(&mut self, i: i32) {
self.write(&i.to_ne_bytes())
self.write_u32(i as u32)
}
/// Writes a single `i64` into this hasher.
#[inline]
#[stable(feature = "hasher_write", since = "1.3.0")]
fn write_i64(&mut self, i: i64) {
self.write(&i.to_ne_bytes())
self.write_u64(i as u64)
}
/// Writes a single `i128` into this hasher.
#[inline]
#[stable(feature = "i128", since = "1.26.0")]
fn write_i128(&mut self, i: i128) {
self.write(&i.to_ne_bytes())
self.write_u128(i as u128)
}
/// Writes a single `isize` into this hasher.
#[inline]
#[stable(feature = "hasher_write", since = "1.3.0")]
fn write_isize(&mut self, i: isize) {
self.write(&i.to_ne_bytes())
self.write_usize(i as usize)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ pub mod primitive;
// crate uses the this crate as its libcore.
#[path = "../stdarch/crates/core_arch/src/mod.rs"]
#[allow(missing_docs, missing_debug_implementations, dead_code, unused_imports)]
// FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_decl is
// FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is
// merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet.
#[cfg_attr(not(bootstrap), allow(clashing_extern_decl))]
#[cfg_attr(not(bootstrap), allow(clashing_extern_declarations))]
#[unstable(feature = "stdsimd", issue = "48556")]
mod core_arch;

Expand Down
54 changes: 54 additions & 0 deletions src/libcore/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2663,6 +2663,60 @@ impl<T> [T] {
{
self.iter().is_sorted_by_key(f)
}

/// Returns the index of the partition point according to the given predicate
/// (the index of the first element of the second partition).
///
/// The slice is assumed to be partitioned according to the given predicate.
/// This means that all elements for which the predicate returns true are at the start of the slice
/// and all elements for which the predicate returns false are at the end.
/// For example, [7, 15, 3, 5, 4, 12, 6] is a partitioned under the predicate x % 2 != 0
/// (all odd numbers are at the start, all even at the end).
///
/// If this slice is not partitioned, the returned result is unspecified and meaningless,
/// as this method performs a kind of binary search.
///
/// # Examples
///
/// ```
/// #![feature(partition_point)]
///
/// let v = [1, 2, 3, 3, 5, 6, 7];
/// let i = v.partition_point(|&x| x < 5);
///
/// assert_eq!(i, 4);
/// assert!(v[..i].iter().all(|&x| x < 5));
/// assert!(v[i..].iter().all(|&x| !(x < 5)));
/// ```
#[unstable(feature = "partition_point", reason = "new API", issue = "73831")]
pub fn partition_point<P>(&self, mut pred: P) -> usize
where
P: FnMut(&T) -> bool,
{
let mut left = 0;
let mut right = self.len();

while left != right {
let mid = left + (right - left) / 2;
// SAFETY:
// When left < right, left <= mid < right.
// Therefore left always increases and right always decreases,
// and eigher of them is selected.
// In both cases left <= right is satisfied.
// Therefore if left < right in a step,
// left <= right is satisfied in the next step.
// Therefore as long as left != right, 0 <= left < right <= len is satisfied
// and if this case 0 <= mid < len is satisfied too.
let value = unsafe { self.get_unchecked(mid) };
if pred(value) {
left = mid + 1;
} else {
right = mid;
}
}

left
}
}

#[lang = "slice_u8"]
Expand Down
1 change: 1 addition & 0 deletions src/libcore/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#![feature(const_forget)]
#![feature(option_unwrap_none)]
#![feature(peekable_next_if)]
#![feature(partition_point)]

extern crate test;

Expand Down
40 changes: 40 additions & 0 deletions src/libcore/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,46 @@ fn test_binary_search_implementation_details() {
assert_eq!(b.binary_search(&3), Ok(8));
}

#[test]
fn test_partition_point() {
let b: [i32; 0] = [];
assert_eq!(b.partition_point(|&x| x < 5), 0);

let b = [4];
assert_eq!(b.partition_point(|&x| x < 3), 0);
assert_eq!(b.partition_point(|&x| x < 4), 0);
assert_eq!(b.partition_point(|&x| x < 5), 1);

let b = [1, 2, 4, 6, 8, 9];
assert_eq!(b.partition_point(|&x| x < 5), 3);
assert_eq!(b.partition_point(|&x| x < 6), 3);
assert_eq!(b.partition_point(|&x| x < 7), 4);
assert_eq!(b.partition_point(|&x| x < 8), 4);

let b = [1, 2, 4, 5, 6, 8];
assert_eq!(b.partition_point(|&x| x < 9), 6);

let b = [1, 2, 4, 6, 7, 8, 9];
assert_eq!(b.partition_point(|&x| x < 6), 3);
assert_eq!(b.partition_point(|&x| x < 5), 3);
assert_eq!(b.partition_point(|&x| x < 8), 5);

let b = [1, 2, 4, 5, 6, 8, 9];
assert_eq!(b.partition_point(|&x| x < 7), 5);
assert_eq!(b.partition_point(|&x| x < 0), 0);

let b = [1, 3, 3, 3, 7];
assert_eq!(b.partition_point(|&x| x < 0), 0);
assert_eq!(b.partition_point(|&x| x < 1), 0);
assert_eq!(b.partition_point(|&x| x < 2), 1);
assert_eq!(b.partition_point(|&x| x < 3), 1);
assert_eq!(b.partition_point(|&x| x < 4), 4);
assert_eq!(b.partition_point(|&x| x < 5), 4);
assert_eq!(b.partition_point(|&x| x < 6), 4);
assert_eq!(b.partition_point(|&x| x < 7), 4);
assert_eq!(b.partition_point(|&x| x < 8), 5);
}

#[test]
fn test_iterator_nth() {
let v: &[_] = &[0, 1, 2, 3, 4];
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_ast_lowering/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ struct LoweringContext<'a, 'hir: 'a> {
/// Used to assign IDs to HIR nodes that do not directly correspond to AST nodes.
sess: &'a Session,

resolver: &'a mut dyn Resolver,
resolver: &'a mut dyn ResolverAstLowering,

/// HACK(Centril): there is a cyclic dependency between the parser and lowering
/// if we don't have this function pointer. To avoid that dependency so that
Expand Down Expand Up @@ -172,7 +172,7 @@ struct LoweringContext<'a, 'hir: 'a> {
allow_gen_future: Option<Lrc<[Symbol]>>,
}

pub trait Resolver {
pub trait ResolverAstLowering {
fn def_key(&mut self, id: DefId) -> DefKey;

fn item_generics_num_lifetimes(&self, def: DefId, sess: &Session) -> usize;
Expand Down Expand Up @@ -299,7 +299,7 @@ impl<'a> ImplTraitContext<'_, 'a> {
pub fn lower_crate<'a, 'hir>(
sess: &'a Session,
krate: &'a Crate,
resolver: &'a mut dyn Resolver,
resolver: &'a mut dyn ResolverAstLowering,
nt_to_tokenstream: NtToTokenstream,
arena: &'hir Arena<'hir>,
) -> hir::Crate<'hir> {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_builtin_macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern crate proc_macro;

use crate::deriving::*;

use rustc_expand::base::{MacroExpanderFn, Resolver, SyntaxExtension, SyntaxExtensionKind};
use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtension, SyntaxExtensionKind};
use rustc_expand::proc_macro::BangProcMacro;
use rustc_span::edition::Edition;
use rustc_span::symbol::{sym, Ident};
Expand Down Expand Up @@ -45,7 +45,7 @@ pub mod proc_macro_harness;
pub mod standard_library_imports;
pub mod test_harness;

pub fn register_builtin_macros(resolver: &mut dyn Resolver, edition: Edition) {
pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand, edition: Edition) {
let mut register = |name, kind| {
resolver.register_builtin_macro(
Ident::with_dummy_span(name),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_builtin_macros/proc_macro_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_ast::expand::is_proc_macro_attr;
use rustc_ast::ptr::P;
use rustc_ast::visit::{self, Visitor};
use rustc_ast_pretty::pprust;
use rustc_expand::base::{ExtCtxt, Resolver};
use rustc_expand::base::{ExtCtxt, ResolverExpand};
use rustc_expand::expand::{AstFragment, ExpansionConfig};
use rustc_session::parse::ParseSess;
use rustc_span::hygiene::AstPass;
Expand Down Expand Up @@ -52,7 +52,7 @@ struct CollectProcMacros<'a> {

pub fn inject(
sess: &ParseSess,
resolver: &mut dyn Resolver,
resolver: &mut dyn ResolverExpand,
mut krate: ast::Crate,
is_proc_macro_crate: bool,
has_proc_macro_decls: bool,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_builtin_macros/standard_library_imports.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_ast::ptr::P;
use rustc_ast::{ast, attr};
use rustc_expand::base::{ExtCtxt, Resolver};
use rustc_expand::base::{ExtCtxt, ResolverExpand};
use rustc_expand::expand::ExpansionConfig;
use rustc_session::parse::ParseSess;
use rustc_span::edition::Edition;
Expand All @@ -10,7 +10,7 @@ use rustc_span::DUMMY_SP;

pub fn inject(
mut krate: ast::Crate,
resolver: &mut dyn Resolver,
resolver: &mut dyn ResolverExpand,
sess: &ParseSess,
alt_std_name: Option<Symbol>,
) -> (ast::Crate, Option<Symbol>) {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_builtin_macros/test_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_ast::attr;
use rustc_ast::entry::{self, EntryPointType};
use rustc_ast::mut_visit::{ExpectOne, *};
use rustc_ast::ptr::P;
use rustc_expand::base::{ExtCtxt, Resolver};
use rustc_expand::base::{ExtCtxt, ResolverExpand};
use rustc_expand::expand::{AstFragment, ExpansionConfig};
use rustc_feature::Features;
use rustc_session::parse::ParseSess;
Expand Down Expand Up @@ -37,7 +37,7 @@ struct TestCtxt<'a> {
// existing main functions, and synthesizing a main test harness
pub fn inject(
sess: &ParseSess,
resolver: &mut dyn Resolver,
resolver: &mut dyn ResolverExpand,
should_test: bool,
krate: &mut ast::Crate,
span_diagnostic: &rustc_errors::Handler,
Expand Down Expand Up @@ -192,7 +192,7 @@ impl MutVisitor for EntryPointCleaner {
/// Crawl over the crate, inserting test reexports and the test main function
fn generate_test_harness(
sess: &ParseSess,
resolver: &mut dyn Resolver,
resolver: &mut dyn ResolverExpand,
reexport_test_harness_main: Option<Symbol>,
krate: &mut ast::Crate,
features: &Features,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_expand/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ pub enum InvocationRes {
/// Error type that denotes indeterminacy.
pub struct Indeterminate;

pub trait Resolver {
pub trait ResolverExpand {
fn next_node_id(&mut self) -> NodeId;

fn resolve_dollar_crates(&mut self);
Expand Down Expand Up @@ -946,7 +946,7 @@ pub struct ExtCtxt<'a> {
pub ecfg: expand::ExpansionConfig<'a>,
pub reduced_recursion_limit: Option<Limit>,
pub root_path: PathBuf,
pub resolver: &'a mut dyn Resolver,
pub resolver: &'a mut dyn ResolverExpand,
pub current_expansion: ExpansionData,
pub expansions: FxHashMap<Span, Vec<String>>,
/// Called directly after having parsed an external `mod foo;` in expansion.
Expand All @@ -957,7 +957,7 @@ impl<'a> ExtCtxt<'a> {
pub fn new(
parse_sess: &'a ParseSess,
ecfg: expand::ExpansionConfig<'a>,
resolver: &'a mut dyn Resolver,
resolver: &'a mut dyn ResolverExpand,
extern_mod_loaded: Option<&'a dyn Fn(&ast::Crate)>,
) -> ExtCtxt<'a> {
ExtCtxt {
Expand Down
36 changes: 17 additions & 19 deletions src/librustc_infer/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ impl<'tcx> fmt::Display for FixupError<'tcx> {
/// Necessary because we can't write the following bound:
/// `F: for<'b, 'tcx> where 'tcx FnOnce(InferCtxt<'b, 'tcx>)`.
pub struct InferCtxtBuilder<'tcx> {
global_tcx: TyCtxt<'tcx>,
tcx: TyCtxt<'tcx>,
fresh_tables: Option<RefCell<ty::TypeckTables<'tcx>>>,
}

Expand All @@ -580,7 +580,7 @@ pub trait TyCtxtInferExt<'tcx> {

impl TyCtxtInferExt<'tcx> for TyCtxt<'tcx> {
fn infer_ctxt(self) -> InferCtxtBuilder<'tcx> {
InferCtxtBuilder { global_tcx: self, fresh_tables: None }
InferCtxtBuilder { tcx: self, fresh_tables: None }
}
}

Expand Down Expand Up @@ -616,24 +616,22 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
}

pub fn enter<R>(&mut self, f: impl for<'a> FnOnce(InferCtxt<'a, 'tcx>) -> R) -> R {
let InferCtxtBuilder { global_tcx, ref fresh_tables } = *self;
let InferCtxtBuilder { tcx, ref fresh_tables } = *self;
let in_progress_tables = fresh_tables.as_ref();
global_tcx.enter_local(|tcx| {
f(InferCtxt {
tcx,
in_progress_tables,
inner: RefCell::new(InferCtxtInner::new()),
lexical_region_resolutions: RefCell::new(None),
selection_cache: Default::default(),
evaluation_cache: Default::default(),
reported_trait_errors: Default::default(),
reported_closure_mismatch: Default::default(),
tainted_by_errors_flag: Cell::new(false),
err_count_on_creation: tcx.sess.err_count(),
in_snapshot: Cell::new(false),
skip_leak_check: Cell::new(false),
universe: Cell::new(ty::UniverseIndex::ROOT),
})
f(InferCtxt {
tcx,
in_progress_tables,
inner: RefCell::new(InferCtxtInner::new()),
lexical_region_resolutions: RefCell::new(None),
selection_cache: Default::default(),
evaluation_cache: Default::default(),
reported_trait_errors: Default::default(),
reported_closure_mismatch: Default::default(),
tainted_by_errors_flag: Cell::new(false),
err_count_on_creation: tcx.sess.err_count(),
in_snapshot: Cell::new(false),
skip_leak_check: Cell::new(false),
universe: Cell::new(ty::UniverseIndex::ROOT),
})
}
}
Expand Down
Loading