Skip to content

Commit 2f517ce

Browse files
committed
Auto merge of rust-lang#73838 - Manishearth:rollup-jj57e84, r=Manishearth
Rollup of 9 pull requests Successful merges: - rust-lang#73577 (Add partition_point) - rust-lang#73757 (Const prop: erase all block-only locals at the end of every block) - rust-lang#73774 (Make liveness more precise for assignments to fields) - rust-lang#73795 (Add some `const_compare_raw_pointers`-related regression tests) - rust-lang#73800 (Forward Hash::write_iN to Hash::write_uN) - rust-lang#73813 (Rename two `Resolver` traits) - rust-lang#73817 (Rename clashing_extern_decl to clashing_extern_declarations.) - rust-lang#73826 (Fix docstring typo) - rust-lang#73833 (Remove GlobalCtxt::enter_local) Failed merges: r? @ghost
2 parents 25687ca + 117b734 commit 2f517ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+526
-159
lines changed

src/libcore/hash/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -333,31 +333,31 @@ pub trait Hasher {
333333
#[inline]
334334
#[stable(feature = "hasher_write", since = "1.3.0")]
335335
fn write_i16(&mut self, i: i16) {
336-
self.write(&i.to_ne_bytes())
336+
self.write_u16(i as u16)
337337
}
338338
/// Writes a single `i32` into this hasher.
339339
#[inline]
340340
#[stable(feature = "hasher_write", since = "1.3.0")]
341341
fn write_i32(&mut self, i: i32) {
342-
self.write(&i.to_ne_bytes())
342+
self.write_u32(i as u32)
343343
}
344344
/// Writes a single `i64` into this hasher.
345345
#[inline]
346346
#[stable(feature = "hasher_write", since = "1.3.0")]
347347
fn write_i64(&mut self, i: i64) {
348-
self.write(&i.to_ne_bytes())
348+
self.write_u64(i as u64)
349349
}
350350
/// Writes a single `i128` into this hasher.
351351
#[inline]
352352
#[stable(feature = "i128", since = "1.26.0")]
353353
fn write_i128(&mut self, i: i128) {
354-
self.write(&i.to_ne_bytes())
354+
self.write_u128(i as u128)
355355
}
356356
/// Writes a single `isize` into this hasher.
357357
#[inline]
358358
#[stable(feature = "hasher_write", since = "1.3.0")]
359359
fn write_isize(&mut self, i: isize) {
360-
self.write(&i.to_ne_bytes())
360+
self.write_usize(i as usize)
361361
}
362362
}
363363

src/libcore/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,9 @@ pub mod primitive;
279279
// crate uses the this crate as its libcore.
280280
#[path = "../stdarch/crates/core_arch/src/mod.rs"]
281281
#[allow(missing_docs, missing_debug_implementations, dead_code, unused_imports)]
282-
// FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_decl is
282+
// FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is
283283
// merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet.
284-
#[cfg_attr(not(bootstrap), allow(clashing_extern_decl))]
284+
#[cfg_attr(not(bootstrap), allow(clashing_extern_declarations))]
285285
#[unstable(feature = "stdsimd", issue = "48556")]
286286
mod core_arch;
287287

src/libcore/slice/mod.rs

+54
Original file line numberDiff line numberDiff line change
@@ -2663,6 +2663,60 @@ impl<T> [T] {
26632663
{
26642664
self.iter().is_sorted_by_key(f)
26652665
}
2666+
2667+
/// Returns the index of the partition point according to the given predicate
2668+
/// (the index of the first element of the second partition).
2669+
///
2670+
/// The slice is assumed to be partitioned according to the given predicate.
2671+
/// This means that all elements for which the predicate returns true are at the start of the slice
2672+
/// and all elements for which the predicate returns false are at the end.
2673+
/// For example, [7, 15, 3, 5, 4, 12, 6] is a partitioned under the predicate x % 2 != 0
2674+
/// (all odd numbers are at the start, all even at the end).
2675+
///
2676+
/// If this slice is not partitioned, the returned result is unspecified and meaningless,
2677+
/// as this method performs a kind of binary search.
2678+
///
2679+
/// # Examples
2680+
///
2681+
/// ```
2682+
/// #![feature(partition_point)]
2683+
///
2684+
/// let v = [1, 2, 3, 3, 5, 6, 7];
2685+
/// let i = v.partition_point(|&x| x < 5);
2686+
///
2687+
/// assert_eq!(i, 4);
2688+
/// assert!(v[..i].iter().all(|&x| x < 5));
2689+
/// assert!(v[i..].iter().all(|&x| !(x < 5)));
2690+
/// ```
2691+
#[unstable(feature = "partition_point", reason = "new API", issue = "73831")]
2692+
pub fn partition_point<P>(&self, mut pred: P) -> usize
2693+
where
2694+
P: FnMut(&T) -> bool,
2695+
{
2696+
let mut left = 0;
2697+
let mut right = self.len();
2698+
2699+
while left != right {
2700+
let mid = left + (right - left) / 2;
2701+
// SAFETY:
2702+
// When left < right, left <= mid < right.
2703+
// Therefore left always increases and right always decreases,
2704+
// and eigher of them is selected.
2705+
// In both cases left <= right is satisfied.
2706+
// Therefore if left < right in a step,
2707+
// left <= right is satisfied in the next step.
2708+
// Therefore as long as left != right, 0 <= left < right <= len is satisfied
2709+
// and if this case 0 <= mid < len is satisfied too.
2710+
let value = unsafe { self.get_unchecked(mid) };
2711+
if pred(value) {
2712+
left = mid + 1;
2713+
} else {
2714+
right = mid;
2715+
}
2716+
}
2717+
2718+
left
2719+
}
26662720
}
26672721

26682722
#[lang = "slice_u8"]

src/libcore/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#![feature(const_forget)]
4545
#![feature(option_unwrap_none)]
4646
#![feature(peekable_next_if)]
47+
#![feature(partition_point)]
4748

4849
extern crate test;
4950

src/libcore/tests/slice.rs

+40
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,46 @@ fn test_binary_search_implementation_details() {
8181
assert_eq!(b.binary_search(&3), Ok(8));
8282
}
8383

84+
#[test]
85+
fn test_partition_point() {
86+
let b: [i32; 0] = [];
87+
assert_eq!(b.partition_point(|&x| x < 5), 0);
88+
89+
let b = [4];
90+
assert_eq!(b.partition_point(|&x| x < 3), 0);
91+
assert_eq!(b.partition_point(|&x| x < 4), 0);
92+
assert_eq!(b.partition_point(|&x| x < 5), 1);
93+
94+
let b = [1, 2, 4, 6, 8, 9];
95+
assert_eq!(b.partition_point(|&x| x < 5), 3);
96+
assert_eq!(b.partition_point(|&x| x < 6), 3);
97+
assert_eq!(b.partition_point(|&x| x < 7), 4);
98+
assert_eq!(b.partition_point(|&x| x < 8), 4);
99+
100+
let b = [1, 2, 4, 5, 6, 8];
101+
assert_eq!(b.partition_point(|&x| x < 9), 6);
102+
103+
let b = [1, 2, 4, 6, 7, 8, 9];
104+
assert_eq!(b.partition_point(|&x| x < 6), 3);
105+
assert_eq!(b.partition_point(|&x| x < 5), 3);
106+
assert_eq!(b.partition_point(|&x| x < 8), 5);
107+
108+
let b = [1, 2, 4, 5, 6, 8, 9];
109+
assert_eq!(b.partition_point(|&x| x < 7), 5);
110+
assert_eq!(b.partition_point(|&x| x < 0), 0);
111+
112+
let b = [1, 3, 3, 3, 7];
113+
assert_eq!(b.partition_point(|&x| x < 0), 0);
114+
assert_eq!(b.partition_point(|&x| x < 1), 0);
115+
assert_eq!(b.partition_point(|&x| x < 2), 1);
116+
assert_eq!(b.partition_point(|&x| x < 3), 1);
117+
assert_eq!(b.partition_point(|&x| x < 4), 4);
118+
assert_eq!(b.partition_point(|&x| x < 5), 4);
119+
assert_eq!(b.partition_point(|&x| x < 6), 4);
120+
assert_eq!(b.partition_point(|&x| x < 7), 4);
121+
assert_eq!(b.partition_point(|&x| x < 8), 5);
122+
}
123+
84124
#[test]
85125
fn test_iterator_nth() {
86126
let v: &[_] = &[0, 1, 2, 3, 4];

src/librustc_ast_lowering/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ struct LoweringContext<'a, 'hir: 'a> {
9191
/// Used to assign IDs to HIR nodes that do not directly correspond to AST nodes.
9292
sess: &'a Session,
9393

94-
resolver: &'a mut dyn Resolver,
94+
resolver: &'a mut dyn ResolverAstLowering,
9595

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

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

178178
fn item_generics_num_lifetimes(&self, def: DefId, sess: &Session) -> usize;
@@ -299,7 +299,7 @@ impl<'a> ImplTraitContext<'_, 'a> {
299299
pub fn lower_crate<'a, 'hir>(
300300
sess: &'a Session,
301301
krate: &'a Crate,
302-
resolver: &'a mut dyn Resolver,
302+
resolver: &'a mut dyn ResolverAstLowering,
303303
nt_to_tokenstream: NtToTokenstream,
304304
arena: &'hir Arena<'hir>,
305305
) -> hir::Crate<'hir> {

src/librustc_builtin_macros/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extern crate proc_macro;
1515

1616
use crate::deriving::*;
1717

18-
use rustc_expand::base::{MacroExpanderFn, Resolver, SyntaxExtension, SyntaxExtensionKind};
18+
use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtension, SyntaxExtensionKind};
1919
use rustc_expand::proc_macro::BangProcMacro;
2020
use rustc_span::edition::Edition;
2121
use rustc_span::symbol::{sym, Ident};
@@ -45,7 +45,7 @@ pub mod proc_macro_harness;
4545
pub mod standard_library_imports;
4646
pub mod test_harness;
4747

48-
pub fn register_builtin_macros(resolver: &mut dyn Resolver, edition: Edition) {
48+
pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand, edition: Edition) {
4949
let mut register = |name, kind| {
5050
resolver.register_builtin_macro(
5151
Ident::with_dummy_span(name),

src/librustc_builtin_macros/proc_macro_harness.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_ast::expand::is_proc_macro_attr;
66
use rustc_ast::ptr::P;
77
use rustc_ast::visit::{self, Visitor};
88
use rustc_ast_pretty::pprust;
9-
use rustc_expand::base::{ExtCtxt, Resolver};
9+
use rustc_expand::base::{ExtCtxt, ResolverExpand};
1010
use rustc_expand::expand::{AstFragment, ExpansionConfig};
1111
use rustc_session::parse::ParseSess;
1212
use rustc_span::hygiene::AstPass;
@@ -52,7 +52,7 @@ struct CollectProcMacros<'a> {
5252

5353
pub fn inject(
5454
sess: &ParseSess,
55-
resolver: &mut dyn Resolver,
55+
resolver: &mut dyn ResolverExpand,
5656
mut krate: ast::Crate,
5757
is_proc_macro_crate: bool,
5858
has_proc_macro_decls: bool,

src/librustc_builtin_macros/standard_library_imports.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_ast::ptr::P;
22
use rustc_ast::{ast, attr};
3-
use rustc_expand::base::{ExtCtxt, Resolver};
3+
use rustc_expand::base::{ExtCtxt, ResolverExpand};
44
use rustc_expand::expand::ExpansionConfig;
55
use rustc_session::parse::ParseSess;
66
use rustc_span::edition::Edition;
@@ -10,7 +10,7 @@ use rustc_span::DUMMY_SP;
1010

1111
pub fn inject(
1212
mut krate: ast::Crate,
13-
resolver: &mut dyn Resolver,
13+
resolver: &mut dyn ResolverExpand,
1414
sess: &ParseSess,
1515
alt_std_name: Option<Symbol>,
1616
) -> (ast::Crate, Option<Symbol>) {

src/librustc_builtin_macros/test_harness.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_ast::attr;
66
use rustc_ast::entry::{self, EntryPointType};
77
use rustc_ast::mut_visit::{ExpectOne, *};
88
use rustc_ast::ptr::P;
9-
use rustc_expand::base::{ExtCtxt, Resolver};
9+
use rustc_expand::base::{ExtCtxt, ResolverExpand};
1010
use rustc_expand::expand::{AstFragment, ExpansionConfig};
1111
use rustc_feature::Features;
1212
use rustc_session::parse::ParseSess;
@@ -37,7 +37,7 @@ struct TestCtxt<'a> {
3737
// existing main functions, and synthesizing a main test harness
3838
pub fn inject(
3939
sess: &ParseSess,
40-
resolver: &mut dyn Resolver,
40+
resolver: &mut dyn ResolverExpand,
4141
should_test: bool,
4242
krate: &mut ast::Crate,
4343
span_diagnostic: &rustc_errors::Handler,
@@ -192,7 +192,7 @@ impl MutVisitor for EntryPointCleaner {
192192
/// Crawl over the crate, inserting test reexports and the test main function
193193
fn generate_test_harness(
194194
sess: &ParseSess,
195-
resolver: &mut dyn Resolver,
195+
resolver: &mut dyn ResolverExpand,
196196
reexport_test_harness_main: Option<Symbol>,
197197
krate: &mut ast::Crate,
198198
features: &Features,

src/librustc_expand/base.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ pub enum InvocationRes {
889889
/// Error type that denotes indeterminacy.
890890
pub struct Indeterminate;
891891

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

895895
fn resolve_dollar_crates(&mut self);
@@ -946,7 +946,7 @@ pub struct ExtCtxt<'a> {
946946
pub ecfg: expand::ExpansionConfig<'a>,
947947
pub reduced_recursion_limit: Option<Limit>,
948948
pub root_path: PathBuf,
949-
pub resolver: &'a mut dyn Resolver,
949+
pub resolver: &'a mut dyn ResolverExpand,
950950
pub current_expansion: ExpansionData,
951951
pub expansions: FxHashMap<Span, Vec<String>>,
952952
/// Called directly after having parsed an external `mod foo;` in expansion.
@@ -957,7 +957,7 @@ impl<'a> ExtCtxt<'a> {
957957
pub fn new(
958958
parse_sess: &'a ParseSess,
959959
ecfg: expand::ExpansionConfig<'a>,
960-
resolver: &'a mut dyn Resolver,
960+
resolver: &'a mut dyn ResolverExpand,
961961
extern_mod_loaded: Option<&'a dyn Fn(&ast::Crate)>,
962962
) -> ExtCtxt<'a> {
963963
ExtCtxt {

src/librustc_infer/infer/mod.rs

+17-19
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ impl<'tcx> fmt::Display for FixupError<'tcx> {
570570
/// Necessary because we can't write the following bound:
571571
/// `F: for<'b, 'tcx> where 'tcx FnOnce(InferCtxt<'b, 'tcx>)`.
572572
pub struct InferCtxtBuilder<'tcx> {
573-
global_tcx: TyCtxt<'tcx>,
573+
tcx: TyCtxt<'tcx>,
574574
fresh_tables: Option<RefCell<ty::TypeckTables<'tcx>>>,
575575
}
576576

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

581581
impl TyCtxtInferExt<'tcx> for TyCtxt<'tcx> {
582582
fn infer_ctxt(self) -> InferCtxtBuilder<'tcx> {
583-
InferCtxtBuilder { global_tcx: self, fresh_tables: None }
583+
InferCtxtBuilder { tcx: self, fresh_tables: None }
584584
}
585585
}
586586

@@ -616,24 +616,22 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
616616
}
617617

618618
pub fn enter<R>(&mut self, f: impl for<'a> FnOnce(InferCtxt<'a, 'tcx>) -> R) -> R {
619-
let InferCtxtBuilder { global_tcx, ref fresh_tables } = *self;
619+
let InferCtxtBuilder { tcx, ref fresh_tables } = *self;
620620
let in_progress_tables = fresh_tables.as_ref();
621-
global_tcx.enter_local(|tcx| {
622-
f(InferCtxt {
623-
tcx,
624-
in_progress_tables,
625-
inner: RefCell::new(InferCtxtInner::new()),
626-
lexical_region_resolutions: RefCell::new(None),
627-
selection_cache: Default::default(),
628-
evaluation_cache: Default::default(),
629-
reported_trait_errors: Default::default(),
630-
reported_closure_mismatch: Default::default(),
631-
tainted_by_errors_flag: Cell::new(false),
632-
err_count_on_creation: tcx.sess.err_count(),
633-
in_snapshot: Cell::new(false),
634-
skip_leak_check: Cell::new(false),
635-
universe: Cell::new(ty::UniverseIndex::ROOT),
636-
})
621+
f(InferCtxt {
622+
tcx,
623+
in_progress_tables,
624+
inner: RefCell::new(InferCtxtInner::new()),
625+
lexical_region_resolutions: RefCell::new(None),
626+
selection_cache: Default::default(),
627+
evaluation_cache: Default::default(),
628+
reported_trait_errors: Default::default(),
629+
reported_closure_mismatch: Default::default(),
630+
tainted_by_errors_flag: Cell::new(false),
631+
err_count_on_creation: tcx.sess.err_count(),
632+
in_snapshot: Cell::new(false),
633+
skip_leak_check: Cell::new(false),
634+
universe: Cell::new(ty::UniverseIndex::ROOT),
637635
})
638636
}
639637
}

0 commit comments

Comments
 (0)