Skip to content

Commit 9649c1f

Browse files
committed
Auto merge of rust-lang#55974 - pietroalbini:rollup, r=pietroalbini
Rollup of 17 pull requests Successful merges: - rust-lang#55182 (Redox: Update to new changes) - rust-lang#55211 (Add BufWriter::buffer method) - rust-lang#55507 (Add link to std::mem::size_of to size_of intrinsic documentation) - rust-lang#55530 (Speed up String::from_utf16) - rust-lang#55556 (Use `Mmap` to open the rmeta file.) - rust-lang#55622 (NetBSD: link libstd with librt in addition to libpthread) - rust-lang#55750 (Make `NodeId` and `HirLocalId` `newtype_index`) - rust-lang#55778 (Wrap some query results in `Lrc`.) - rust-lang#55781 (More precise spans for temps and their drops) - rust-lang#55785 (Add mem::forget_unsized() for forgetting unsized values) - rust-lang#55852 (Rewrite `...` as `..=` as a `MachineApplicable` 2018 idiom lint) - rust-lang#55865 (Unix RwLock: avoid racy access to write_locked) - rust-lang#55901 (fix various typos in doc comments) - rust-lang#55926 (Change sidebar selector to fix compatibility with docs.rs) - rust-lang#55930 (A handful of hir tweaks) - rust-lang#55932 (core/char: Speed up `to_digit()` for `radix <= 10`) - rust-lang#55956 (add tests for some fixed ICEs) Failed merges: r? @ghost
2 parents 99e3fca + d0e08ce commit 9649c1f

File tree

120 files changed

+934
-390
lines changed

Some content is hidden

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

120 files changed

+934
-390
lines changed

src/Cargo.lock

+2
Original file line numberDiff line numberDiff line change
@@ -2278,12 +2278,14 @@ version = "0.0.0"
22782278
dependencies = [
22792279
"flate2 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
22802280
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
2281+
"memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
22812282
"proc_macro 0.0.0",
22822283
"rustc 0.0.0",
22832284
"rustc_data_structures 0.0.0",
22842285
"rustc_errors 0.0.0",
22852286
"rustc_target 0.0.0",
22862287
"serialize 0.0.0",
2288+
"stable_deref_trait 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
22872289
"syntax 0.0.0",
22882290
"syntax_ext 0.0.0",
22892291
"syntax_pos 0.0.0",

src/liballoc/collections/btree/node.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct LeafNode<K, V> {
6969

7070
/// This node's index into the parent node's `edges` array.
7171
/// `*node.parent.edges[node.parent_idx]` should be the same thing as `node`.
72-
/// This is only guaranteed to be initialized when `parent` is nonnull.
72+
/// This is only guaranteed to be initialized when `parent` is non-null.
7373
parent_idx: MaybeUninit<u16>,
7474

7575
/// The number of keys and values this node stores.

src/liballoc/raw_vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use boxed::Box;
4444
/// This enables you to use capacity growing logic catch the overflows in your length
4545
/// that might occur with zero-sized types.
4646
///
47-
/// However this means that you need to be careful when roundtripping this type
47+
/// However this means that you need to be careful when round-tripping this type
4848
/// with a `Box<[T]>`: `cap()` won't yield the len. However `with_capacity`,
4949
/// `shrink_to_fit`, and `from_box` will actually set RawVec's private capacity
5050
/// field. This allows zero-sized types to not be special-cased by consumers of

src/liballoc/string.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,15 @@ impl String {
618618
/// ```
619619
#[stable(feature = "rust1", since = "1.0.0")]
620620
pub fn from_utf16(v: &[u16]) -> Result<String, FromUtf16Error> {
621-
decode_utf16(v.iter().cloned()).collect::<Result<_, _>>().map_err(|_| FromUtf16Error(()))
621+
let mut ret = String::with_capacity(v.len());
622+
for c in decode_utf16(v.iter().cloned()) {
623+
if let Ok(c) = c {
624+
ret.push(c);
625+
} else {
626+
return Err(FromUtf16Error(()));
627+
}
628+
}
629+
Ok(ret)
622630
}
623631

624632
/// Decode a UTF-16 encoded slice `v` into a `String`, replacing

src/libcore/benches/char/methods.rs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use test::Bencher;
12+
13+
const CHARS: [char; 9] = ['0', 'x', '2', '5', 'A', 'f', '7', '8', '9'];
14+
const RADIX: [u32; 5] = [2, 8, 10, 16, 32];
15+
16+
#[bench]
17+
fn bench_to_digit_radix_2(b: &mut Bencher) {
18+
b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_digit(2)).min())
19+
}
20+
21+
#[bench]
22+
fn bench_to_digit_radix_10(b: &mut Bencher) {
23+
b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_digit(10)).min())
24+
}
25+
26+
#[bench]
27+
fn bench_to_digit_radix_16(b: &mut Bencher) {
28+
b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_digit(16)).min())
29+
}
30+
31+
#[bench]
32+
fn bench_to_digit_radix_36(b: &mut Bencher) {
33+
b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_digit(36)).min())
34+
}
35+
36+
#[bench]
37+
fn bench_to_digit_radix_var(b: &mut Bencher) {
38+
b.iter(|| CHARS.iter().cycle()
39+
.zip(RADIX.iter().cycle())
40+
.take(10_000)
41+
.map(|(c, radix)| c.to_digit(*radix)).min())
42+
}

src/libcore/benches/char/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
mod methods;

src/libcore/benches/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ extern crate core;
1515
extern crate test;
1616

1717
mod any;
18+
mod char;
1819
mod hash;
1920
mod iter;
2021
mod num;

src/libcore/char/methods.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,24 @@ impl char {
121121
#[stable(feature = "rust1", since = "1.0.0")]
122122
#[inline]
123123
pub fn to_digit(self, radix: u32) -> Option<u32> {
124-
if radix > 36 {
125-
panic!("to_digit: radix is too high (maximum 36)");
126-
}
127-
let val = match self {
128-
'0' ..= '9' => self as u32 - '0' as u32,
129-
'a' ..= 'z' => self as u32 - 'a' as u32 + 10,
130-
'A' ..= 'Z' => self as u32 - 'A' as u32 + 10,
131-
_ => return None,
124+
assert!(radix <= 36, "to_digit: radix is too high (maximum 36)");
125+
126+
// the code is split up here to improve execution speed for cases where
127+
// the `radix` is constant and 10 or smaller
128+
let val = if radix <= 10 {
129+
match self {
130+
'0' ..= '9' => self as u32 - '0' as u32,
131+
_ => return None,
132+
}
133+
} else {
134+
match self {
135+
'0'..='9' => self as u32 - '0' as u32,
136+
'a'..='z' => self as u32 - 'a' as u32 + 10,
137+
'A'..='Z' => self as u32 - 'A' as u32 + 10,
138+
_ => return None,
139+
}
132140
};
141+
133142
if val < radix { Some(val) }
134143
else { None }
135144
}

src/libcore/intrinsics.rs

+7
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,9 @@ extern "rust-intrinsic" {
672672
///
673673
/// More specifically, this is the offset in bytes between successive
674674
/// items of the same type, including alignment padding.
675+
///
676+
/// The stabilized version of this intrinsic is
677+
/// [`std::mem::size_of`](../../std/mem/fn.size_of.html).
675678
pub fn size_of<T>() -> usize;
676679

677680
/// Moves a value to an uninitialized memory location.
@@ -714,6 +717,10 @@ extern "rust-intrinsic" {
714717
/// initialize memory previous set to the result of `uninit`.
715718
pub fn uninit<T>() -> T;
716719

720+
/// Moves a value out of scope without running drop glue.
721+
#[cfg(not(stage0))]
722+
pub fn forget<T: ?Sized>(_: T);
723+
717724
/// Reinterprets the bits of a value of one type as another type.
718725
///
719726
/// Both types must have the same size. Neither the original, nor the result,

src/libcore/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
#![feature(staged_api)]
107107
#![feature(stmt_expr_attributes)]
108108
#![feature(unboxed_closures)]
109+
#![feature(unsized_locals)]
109110
#![feature(untagged_unions)]
110111
#![feature(unwind_attributes)]
111112
#![feature(doc_alias)]

src/libcore/mem.rs

+13
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,19 @@ pub fn forget<T>(t: T) {
143143
ManuallyDrop::new(t);
144144
}
145145

146+
/// Like [`forget`], but also accepts unsized values.
147+
///
148+
/// This function is just a shim intended to be removed when the `unsized_locals` feature gets
149+
/// stabilized.
150+
///
151+
/// [`forget`]: fn.forget.html
152+
#[inline]
153+
#[cfg(not(stage0))]
154+
#[unstable(feature = "forget_unsized", issue = "0")]
155+
pub fn forget_unsized<T: ?Sized>(t: T) {
156+
unsafe { intrinsics::forget(t) }
157+
}
158+
146159
/// Returns the size of a type in bytes.
147160
///
148161
/// More specifically, this is the offset in bytes between successive elements

src/libcore/num/f32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ impl f32 {
445445
/// signaling NaNs on MIPS are quiet NaNs on x86, and vice-versa.
446446
///
447447
/// Rather than trying to preserve signaling-ness cross-platform, this
448-
/// implementation favours preserving the exact bits. This means that
448+
/// implementation favors preserving the exact bits. This means that
449449
/// any payloads encoded in NaNs will be preserved even if the result of
450450
/// this method is sent over the network from an x86 machine to a MIPS one.
451451
///

src/libcore/task/wake.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl Drop for Waker {
108108
/// is ready to be run.
109109
///
110110
/// This is similar to the `Waker` type, but cannot be sent across threads.
111-
/// Task executors can use this type to implement more optimized singlethreaded wakeup
111+
/// Task executors can use this type to implement more optimized single-threaded wakeup
112112
/// behavior.
113113
#[repr(transparent)]
114114
#[derive(Clone)]

src/libproc_macro/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ impl TokenTree {
535535
}
536536
}
537537

538-
/// Prints token treee in a form convenient for debugging.
538+
/// Prints token tree in a form convenient for debugging.
539539
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
540540
impl fmt::Debug for TokenTree {
541541
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -730,7 +730,7 @@ impl fmt::Debug for Group {
730730

731731
/// An `Punct` is an single punctuation character like `+`, `-` or `#`.
732732
///
733-
/// Multicharacter operators like `+=` are represented as two instances of `Punct` with different
733+
/// Multi-character operators like `+=` are represented as two instances of `Punct` with different
734734
/// forms of `Spacing` returned.
735735
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
736736
#[derive(Clone)]
@@ -788,7 +788,7 @@ impl Punct {
788788

789789
/// Returns the spacing of this punctuation character, indicating whether it's immediately
790790
/// followed by another `Punct` in the token stream, so they can potentially be combined into
791-
/// a multicharacter operator (`Joint`), or it's followed by some other token or whitespace
791+
/// a multi-character operator (`Joint`), or it's followed by some other token or whitespace
792792
/// (`Alone`) so the operator has certainly ended.
793793
#[stable(feature = "proc_macro_lib2", since = "1.29.0")]
794794
pub fn spacing(&self) -> Spacing {
@@ -947,7 +947,7 @@ macro_rules! suffixed_int_literals {
947947
/// This function will create an integer like `1u32` where the integer
948948
/// value specified is the first part of the token and the integral is
949949
/// also suffixed at the end.
950-
/// Literals created from negative numbers may not survive rountrips through
950+
/// Literals created from negative numbers may not survive round-trips through
951951
/// `TokenStream` or strings and may be broken into two tokens (`-` and positive literal).
952952
///
953953
/// Literals created through this method have the `Span::call_site()`
@@ -1047,7 +1047,7 @@ impl Literal {
10471047

10481048
/// Creates a new suffixed floating-point literal.
10491049
///
1050-
/// This consturctor will create a literal like `1.0f32` where the value
1050+
/// This constructor will create a literal like `1.0f32` where the value
10511051
/// specified is the preceding part of the token and `f32` is the suffix of
10521052
/// the token. This token will always be inferred to be an `f32` in the
10531053
/// compiler.
@@ -1096,7 +1096,7 @@ impl Literal {
10961096

10971097
/// Creates a new suffixed floating-point literal.
10981098
///
1099-
/// This consturctor will create a literal like `1.0f64` where the value
1099+
/// This constructor will create a literal like `1.0f64` where the value
11001100
/// specified is the preceding part of the token and `f64` is the suffix of
11011101
/// the token. This token will always be inferred to be an `f64` in the
11021102
/// compiler.

src/librustc/dep_graph/cgu_reuse_tracker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
//! Some facilities for tracking how codegen-units are reused during incremental
12-
//! compilition. This is used for incremental compiliation tests and debug
12+
//! compilation. This is used for incremental compilation tests and debug
1313
//! output.
1414
1515
use session::Session;

src/librustc/dep_graph/dep_node.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
use mir::interpret::GlobalId;
6464
use hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX};
6565
use hir::map::DefPathHash;
66-
use hir::{HirId, ItemLocalId};
66+
use hir::HirId;
6767

6868
use ich::{Fingerprint, StableHashingContext};
6969
use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
@@ -790,11 +790,11 @@ impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for HirId {
790790
fn to_fingerprint(&self, tcx: TyCtxt<'_, '_, '_>) -> Fingerprint {
791791
let HirId {
792792
owner,
793-
local_id: ItemLocalId(local_id),
793+
local_id,
794794
} = *self;
795795

796796
let def_path_hash = tcx.def_path_hash(DefId::local(owner));
797-
let local_id = Fingerprint::from_smaller_hash(local_id as u64);
797+
let local_id = Fingerprint::from_smaller_hash(local_id.as_u32().into());
798798

799799
def_path_hash.0.combine(local_id)
800800
}

src/librustc/hir/def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub enum NonMacroAttrKind {
3636
Tool,
3737
/// Single-segment custom attribute registered by a derive macro (`#[serde(default)]`).
3838
DeriveHelper,
39-
/// Single-segment custom attriubte registered by a legacy plugin (`register_attribute`).
39+
/// Single-segment custom attribute registered by a legacy plugin (`register_attribute`).
4040
LegacyPluginHelper,
4141
/// Single-segment custom attribute not registered in any way (`#[my_attr]`).
4242
Custom,

src/librustc/hir/intravisit.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ use hir::map::{self, Map};
4949
use super::itemlikevisit::DeepVisitor;
5050

5151
use std::cmp;
52-
use std::u32;
5352

5453
#[derive(Copy, Clone)]
5554
pub enum FnKind<'a> {
@@ -1152,8 +1151,8 @@ pub struct IdRange {
11521151
impl IdRange {
11531152
pub fn max() -> IdRange {
11541153
IdRange {
1155-
min: NodeId::from_u32(u32::MAX),
1156-
max: NodeId::from_u32(u32::MIN),
1154+
min: NodeId::MAX,
1155+
max: NodeId::from_u32(0),
11571156
}
11581157
}
11591158

src/librustc/hir/lowering.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ impl<'a> LoweringContext<'a> {
588588
*local_id_counter += 1;
589589
hir::HirId {
590590
owner: def_index,
591-
local_id: hir::ItemLocalId(local_id),
591+
local_id: hir::ItemLocalId::from_u32(local_id),
592592
}
593593
})
594594
}
@@ -616,7 +616,7 @@ impl<'a> LoweringContext<'a> {
616616

617617
hir::HirId {
618618
owner: def_index,
619-
local_id: hir::ItemLocalId(local_id),
619+
local_id: hir::ItemLocalId::from_u32(local_id),
620620
}
621621
})
622622
}

src/librustc/hir/map/hir_id_validator.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> {
101101
if max != self.hir_ids_seen.len() - 1 {
102102
// Collect the missing ItemLocalIds
103103
let missing: Vec<_> = (0 .. max as u32 + 1)
104-
.filter(|&i| !self.hir_ids_seen.contains_key(&ItemLocalId(i)))
104+
.filter(|&i| !self.hir_ids_seen.contains_key(&ItemLocalId::from_u32(i)))
105105
.collect();
106106

107107
// Try to map those to something more useful
@@ -110,7 +110,7 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> {
110110
for local_id in missing {
111111
let hir_id = HirId {
112112
owner: owner_def_index,
113-
local_id: ItemLocalId(local_id as u32),
113+
local_id: ItemLocalId::from_u32(local_id),
114114
};
115115

116116
trace!("missing hir id {:#?}", hir_id);
@@ -124,7 +124,7 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> {
124124
.enumerate()
125125
.find(|&(_, &entry)| hir_id == entry)
126126
.expect("no node_to_hir_id entry");
127-
let node_id = NodeId::new(node_id);
127+
let node_id = NodeId::from_usize(node_id);
128128
missing_items.push(format!("[local_id: {}, node:{}]",
129129
local_id,
130130
self.hir_map.node_to_string(node_id)));

0 commit comments

Comments
 (0)