Skip to content

Commit 72b2bd5

Browse files
committed
Auto merge of rust-lang#68067 - JohnTitor:rollup-vsj5won, r=JohnTitor
Rollup of 10 pull requests Successful merges: - rust-lang#66254 (Make Layout::new const) - rust-lang#67122 (Do not deduplicate diagnostics in UI tests) - rust-lang#67358 (Add HashSet::get_or_insert_owned) - rust-lang#67725 (Simplify into_key_slice_mut) - rust-lang#67935 (Relax the Sized bounds on Pin::map_unchecked(_mut)) - rust-lang#67967 (Delay bug to prevent ICE in MIR borrowck) - rust-lang#67975 (Export public scalar statics in wasm) - rust-lang#68006 (Recognise riscv64 in compiletest) - rust-lang#68040 (Cleanup) - rust-lang#68054 (doc: add Null-unchecked version section to mut pointer as_mut method) Failed merges: - rust-lang#67258 (Introduce `X..`, `..X`, and `..=X` range patterns) r? @ghost
2 parents 59eb49d + 9e83df0 commit 72b2bd5

File tree

235 files changed

+3078
-418
lines changed

Some content is hidden

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

235 files changed

+3078
-418
lines changed

Cargo.lock

-10
Original file line numberDiff line numberDiff line change
@@ -3079,8 +3079,6 @@ dependencies = [
30793079
"graphviz",
30803080
"jobserver",
30813081
"log",
3082-
"measureme",
3083-
"num_cpus",
30843082
"parking_lot",
30853083
"polonius-engine",
30863084
"rustc-rayon",
@@ -3090,7 +3088,6 @@ dependencies = [
30903088
"rustc_error_codes",
30913089
"rustc_errors",
30923090
"rustc_feature",
3093-
"rustc_fs_util",
30943091
"rustc_hir",
30953092
"rustc_index",
30963093
"rustc_macros",
@@ -3278,7 +3275,6 @@ dependencies = [
32783275
"jemalloc-sys",
32793276
"rustc_codegen_ssa",
32803277
"rustc_driver",
3281-
"rustc_target",
32823278
]
32833279

32843280
[[package]]
@@ -3409,7 +3405,6 @@ dependencies = [
34093405
"rustc_codegen_utils",
34103406
"rustc_data_structures",
34113407
"rustc_errors",
3412-
"rustc_expand",
34133408
"rustc_feature",
34143409
"rustc_fs_util",
34153410
"rustc_hir",
@@ -3497,7 +3492,6 @@ name = "rustc_driver"
34973492
version = "0.0.0"
34983493
dependencies = [
34993494
"env_logger 0.7.1",
3500-
"graphviz",
35013495
"lazy_static 1.3.0",
35023496
"log",
35033497
"rustc",
@@ -3513,7 +3507,6 @@ dependencies = [
35133507
"rustc_mir",
35143508
"rustc_parse",
35153509
"rustc_plugin_impl",
3516-
"rustc_resolve",
35173510
"rustc_save_analysis",
35183511
"rustc_span",
35193512
"rustc_target",
@@ -3660,7 +3653,6 @@ dependencies = [
36603653
"log",
36613654
"rustc",
36623655
"rustc_data_structures",
3663-
"rustc_error_codes",
36643656
"rustc_feature",
36653657
"rustc_hir",
36663658
"rustc_index",
@@ -4464,8 +4456,6 @@ dependencies = [
44644456
name = "syntax"
44654457
version = "0.0.0"
44664458
dependencies = [
4467-
"bitflags",
4468-
"lazy_static 1.3.0",
44694459
"log",
44704460
"rustc_data_structures",
44714461
"rustc_error_codes",

src/liballoc/collections/btree/node.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> {
397397

398398
/// Borrows a view into the values stored in the node.
399399
/// The caller must ensure that the node is not the shared root.
400+
/// This function is not public, so doesn't have to support shared roots like `keys` does.
400401
fn vals(&self) -> &[V] {
401402
self.reborrow().into_val_slice()
402403
}
@@ -514,6 +515,7 @@ impl<'a, K, V, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
514515
}
515516

516517
/// The caller must ensure that the node is not the shared root.
518+
/// This function is not public, so doesn't have to support shared roots like `keys` does.
517519
fn keys_mut(&mut self) -> &mut [K] {
518520
unsafe { self.reborrow_mut().into_key_slice_mut() }
519521
}
@@ -589,20 +591,15 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
589591
unsafe { &mut *(self.root as *mut Root<K, V>) }
590592
}
591593

594+
/// The caller must ensure that the node is not the shared root.
592595
fn into_key_slice_mut(mut self) -> &'a mut [K] {
593-
// Same as for `into_key_slice` above, we try to avoid a run-time check.
594-
if (mem::align_of::<NodeHeader<K, V, K>>() > mem::align_of::<NodeHeader<K, V>>()
595-
|| mem::size_of::<NodeHeader<K, V, K>>() != mem::size_of::<NodeHeader<K, V>>())
596-
&& self.is_shared_root()
597-
{
598-
&mut []
599-
} else {
600-
unsafe {
601-
slice::from_raw_parts_mut(
602-
MaybeUninit::first_ptr_mut(&mut (*self.as_leaf_mut()).keys),
603-
self.len(),
604-
)
605-
}
596+
debug_assert!(!self.is_shared_root());
597+
// We cannot be the shared root, so `as_leaf_mut` is okay.
598+
unsafe {
599+
slice::from_raw_parts_mut(
600+
MaybeUninit::first_ptr_mut(&mut (*self.as_leaf_mut()).keys),
601+
self.len(),
602+
)
606603
}
607604
}
608605

src/liballoc/collections/btree/search.rs

+11
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ where
4646
}
4747
}
4848

49+
/// Returns the index in the node at which the key (or an equivalent) exists
50+
/// or could exist, and whether it exists in the node itself. If it doesn't
51+
/// exist in the node itself, it may exist in the subtree with that index
52+
/// (if the node has subtrees). If the key doesn't exist in node or subtree,
53+
/// the returned index is the position or subtree to insert at.
4954
pub fn search_linear<BorrowType, K, V, Type, Q: ?Sized>(
5055
node: &NodeRef<BorrowType, K, V, Type>,
5156
key: &Q,
@@ -54,6 +59,12 @@ where
5459
Q: Ord,
5560
K: Borrow<Q>,
5661
{
62+
// This function is defined over all borrow types (immutable, mutable, owned),
63+
// and may be called on the shared root in each case.
64+
// Crucially, we use `keys()` here, i.e., we work with immutable data.
65+
// `keys_mut()` does not support the shared root, so we cannot use it.
66+
// Using `keys()` is fine here even if BorrowType is mutable, as all we return
67+
// is an index -- not a reference.
5768
for (i, k) in node.keys().iter().enumerate() {
5869
match key.cmp(k.borrow()) {
5970
Ordering::Greater => {}

src/libcore/alloc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::usize;
1717
#[derive(Debug)]
1818
pub struct Excess(pub NonNull<u8>, pub usize);
1919

20-
fn size_align<T>() -> (usize, usize) {
20+
const fn size_align<T>() -> (usize, usize) {
2121
(mem::size_of::<T>(), mem::align_of::<T>())
2222
}
2323

@@ -120,14 +120,14 @@ impl Layout {
120120

121121
/// Constructs a `Layout` suitable for holding a value of type `T`.
122122
#[stable(feature = "alloc_layout", since = "1.28.0")]
123+
#[rustc_const_stable(feature = "alloc_layout_const_new", since = "1.42.0")]
123124
#[inline]
124-
pub fn new<T>() -> Self {
125+
pub const fn new<T>() -> Self {
125126
let (size, align) = size_align::<T>();
126127
// Note that the align is guaranteed by rustc to be a power of two and
127128
// the size+align combo is guaranteed to fit in our address space. As a
128129
// result use the unchecked constructor here to avoid inserting code
129130
// that panics if it isn't optimized well enough.
130-
debug_assert!(Layout::from_size_align(size, align).is_ok());
131131
unsafe { Layout::from_size_align_unchecked(size, align) }
132132
}
133133

src/libcore/pin.rs

+2
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ impl<'a, T: ?Sized> Pin<&'a T> {
672672
#[stable(feature = "pin", since = "1.33.0")]
673673
pub unsafe fn map_unchecked<U, F>(self, func: F) -> Pin<&'a U>
674674
where
675+
U: ?Sized,
675676
F: FnOnce(&T) -> &U,
676677
{
677678
let pointer = &*self.pointer;
@@ -763,6 +764,7 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
763764
#[stable(feature = "pin", since = "1.33.0")]
764765
pub unsafe fn map_unchecked_mut<U, F>(self, func: F) -> Pin<&'a mut U>
765766
where
767+
U: ?Sized,
766768
F: FnOnce(&mut T) -> &mut U,
767769
{
768770
let pointer = Pin::get_unchecked_mut(self);

src/libcore/ptr/mut_ptr.rs

+14
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,20 @@ impl<T: ?Sized> *mut T {
250250
/// *first_value = 4;
251251
/// println!("{:?}", s); // It'll print: "[4, 2, 3]".
252252
/// ```
253+
///
254+
/// # Null-unchecked version
255+
///
256+
/// If you are sure the pointer can never be null and are looking for some kind of
257+
/// `as_mut_unchecked` that returns the `&mut T` instead of `Option<&mut T>`, know that
258+
/// you can dereference the pointer directly.
259+
///
260+
/// ```
261+
/// let mut s = [1, 2, 3];
262+
/// let ptr: *mut u32 = s.as_mut_ptr();
263+
/// let first_value = unsafe { &mut *ptr };
264+
/// *first_value = 4;
265+
/// println!("{:?}", s); // It'll print: "[4, 2, 3]".
266+
/// ```
253267
#[stable(feature = "ptr_as_ref", since = "1.9.0")]
254268
#[inline]
255269
pub unsafe fn as_mut<'a>(self) -> Option<&'a mut T> {

src/librustc/Cargo.toml

-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ bitflags = "1.2.1"
1515
fmt_macros = { path = "../libfmt_macros" }
1616
graphviz = { path = "../libgraphviz" }
1717
jobserver = "0.1"
18-
num_cpus = "1.0"
1918
scoped-tls = "1.0"
2019
log = { version = "0.4", features = ["release_max_level_info", "std"] }
2120
rustc-rayon = "0.3.0"
@@ -36,8 +35,6 @@ backtrace = "0.3.40"
3635
parking_lot = "0.9"
3736
byteorder = { version = "1.3" }
3837
chalk-engine = { version = "0.9.0", default-features=false }
39-
rustc_fs_util = { path = "../librustc_fs_util" }
4038
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
41-
measureme = "0.5"
4239
rustc_error_codes = { path = "../librustc_error_codes" }
4340
rustc_session = { path = "../librustc_session" }

src/librustc/ty/mod.rs

-7
Original file line numberDiff line numberDiff line change
@@ -808,13 +808,6 @@ pub struct UpvarBorrow<'tcx> {
808808
pub type UpvarListMap = FxHashMap<DefId, FxIndexMap<hir::HirId, UpvarId>>;
809809
pub type UpvarCaptureMap<'tcx> = FxHashMap<UpvarId, UpvarCapture<'tcx>>;
810810

811-
#[derive(Copy, Clone, TypeFoldable)]
812-
pub struct ClosureUpvar<'tcx> {
813-
pub res: Res,
814-
pub span: Span,
815-
pub ty: Ty<'tcx>,
816-
}
817-
818811
#[derive(Clone, Copy, PartialEq, Eq)]
819812
pub enum IntVarValue {
820813
IntType(ast::IntTy),

src/librustc/ty/structural_impls.rs

-6
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ impl fmt::Debug for ty::AdtDef {
4545
}
4646
}
4747

48-
impl fmt::Debug for ty::ClosureUpvar<'tcx> {
49-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50-
write!(f, "ClosureUpvar({:?},{:?})", self.res, self.ty)
51-
}
52-
}
53-
5448
impl fmt::Debug for ty::UpvarId {
5549
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5650
let name = ty::tls::with(|tcx| tcx.hir().name(self.var_path.hir_id));

src/librustc_codegen_llvm/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,4 @@ rustc_session = { path = "../librustc_session" }
3131
rustc_target = { path = "../librustc_target" }
3232
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
3333
syntax = { path = "../libsyntax" }
34-
rustc_expand = { path = "../librustc_expand" }
3534
rustc_span = { path = "../librustc_span" }

src/librustc_codegen_ssa/back/symbol_export.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ fn symbol_export_level(tcx: TyCtxt<'_>, sym_def_id: DefId) -> SymbolExportLevel
345345
if is_extern && !std_internal {
346346
let target = &tcx.sess.target.target.llvm_target;
347347
// WebAssembly cannot export data symbols, so reduce their export level
348-
if target.contains("wasm32") || target.contains("emscripten") {
348+
if target.contains("emscripten") {
349349
if let Some(Node::Item(&hir::Item { kind: hir::ItemKind::Static(..), .. })) =
350350
tcx.hir().get_if_local(sym_def_id)
351351
{

src/librustc_driver/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ path = "lib.rs"
1010
crate-type = ["dylib"]
1111

1212
[dependencies]
13-
graphviz = { path = "../libgraphviz" }
1413
lazy_static = "1.0"
1514
log = "0.4"
1615
env_logger = { version = "0.7", default-features = false }
@@ -30,7 +29,6 @@ rustc_codegen_utils = { path = "../librustc_codegen_utils" }
3029
rustc_error_codes = { path = "../librustc_error_codes" }
3130
rustc_interface = { path = "../librustc_interface" }
3231
rustc_serialize = { path = "../libserialize", package = "serialize" }
33-
rustc_resolve = { path = "../librustc_resolve" }
3432
syntax = { path = "../libsyntax" }
3533
rustc_span = { path = "../librustc_span" }
3634

src/librustc_lint/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ rustc_span = { path = "../librustc_span" }
1919
rustc_data_structures = { path = "../librustc_data_structures" }
2020
rustc_feature = { path = "../librustc_feature" }
2121
rustc_index = { path = "../librustc_index" }
22-
rustc_error_codes = { path = "../librustc_error_codes" }
2322
rustc_session = { path = "../librustc_session" }

src/librustc_mir/transform/elaborate_drops.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ impl<'tcx> MirPass<'tcx> for ElaborateDrops {
2828
let param_env = tcx.param_env(src.def_id()).with_reveal_all();
2929
let move_data = match MoveData::gather_moves(body, tcx, param_env) {
3030
Ok(move_data) => move_data,
31-
Err(_) => bug!("No `move_errors` should be allowed in MIR borrowck"),
31+
Err((move_data, _)) => {
32+
tcx.sess.delay_span_bug(
33+
body.span,
34+
"No `move_errors` should be allowed in MIR borrowck",
35+
);
36+
move_data
37+
}
3238
};
3339
let elaborate_patch = {
3440
let body = &*body;

src/librustc_typeck/check/upvar.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
212212
}
213213
}
214214

215-
// Returns a list of `ClosureUpvar`s for each upvar.
215+
// Returns a list of `Ty`s for each upvar.
216216
fn final_upvar_tys(&self, closure_id: hir::HirId) -> Vec<Ty<'tcx>> {
217217
// Presently an unboxed closure type cannot "escape" out of a
218218
// function, so we will only encounter ones that originated in the

src/libstd/collections/hash/set.rs

+32
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,38 @@ where
631631
self.map.raw_entry_mut().from_key(&value).or_insert(value, ()).0
632632
}
633633

634+
/// Inserts an owned copy of the given `value` into the set if it is not
635+
/// present, then returns a reference to the value in the set.
636+
///
637+
/// # Examples
638+
///
639+
/// ```
640+
/// #![feature(hash_set_entry)]
641+
///
642+
/// use std::collections::HashSet;
643+
///
644+
/// let mut set: HashSet<String> = ["cat", "dog", "horse"]
645+
/// .iter().map(|&pet| pet.to_owned()).collect();
646+
///
647+
/// assert_eq!(set.len(), 3);
648+
/// for &pet in &["cat", "dog", "fish"] {
649+
/// let value = set.get_or_insert_owned(pet);
650+
/// assert_eq!(value, pet);
651+
/// }
652+
/// assert_eq!(set.len(), 4); // a new "fish" was inserted
653+
/// ```
654+
#[inline]
655+
#[unstable(feature = "hash_set_entry", issue = "60896")]
656+
pub fn get_or_insert_owned<Q: ?Sized>(&mut self, value: &Q) -> &T
657+
where
658+
T: Borrow<Q>,
659+
Q: Hash + Eq + ToOwned<Owned = T>,
660+
{
661+
// Although the raw entry gives us `&mut T`, we only return `&T` to be consistent with
662+
// `get`. Key mutation is "raw" because you're not supposed to affect `Eq` or `Hash`.
663+
self.map.raw_entry_mut().from_key(value).or_insert_with(|| (value.to_owned(), ())).0
664+
}
665+
634666
/// Inserts a value computed from `f` into the set if the given `value` is
635667
/// not present, then returns a reference to the value in the set.
636668
///

src/libsyntax/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ path = "lib.rs"
1010
doctest = false
1111

1212
[dependencies]
13-
bitflags = "1.2.1"
1413
rustc_serialize = { path = "../libserialize", package = "serialize" }
1514
log = "0.4"
1615
scoped-tls = "1.0"
17-
lazy_static = "1.0.0"
1816
rustc_span = { path = "../librustc_span" }
1917
errors = { path = "../librustc_errors", package = "rustc_errors" }
2018
rustc_data_structures = { path = "../librustc_data_structures" }

src/rustc/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ name = "rustc_binary"
99
path = "rustc.rs"
1010

1111
[dependencies]
12-
rustc_target = { path = "../librustc_target" }
1312
rustc_driver = { path = "../librustc_driver" }
1413

1514
# Make sure rustc_codegen_ssa ends up in the sysroot, because this

src/test/compile-fail/consts/const-fn-error.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const fn f(x: usize) -> usize {
66
let mut sum = 0;
77
for i in 0..x {
88
//~^ ERROR E0015
9+
//~| ERROR E0015
910
//~| ERROR E0658
1011
//~| ERROR E0080
1112
//~| ERROR E0744

src/test/compile-fail/issue-52443.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ fn main() {
88
//~| WARN denote infinite loops with
99
[(); { for _ in 0usize.. {}; 0}];
1010
//~^ ERROR calls in constants are limited to constant functions
11+
//~| ERROR calls in constants are limited to constant functions
1112
//~| ERROR `for` is not allowed in a `const`
1213
//~| ERROR references in constants may only refer to immutable values
1314
//~| ERROR evaluation of constant value failed

src/test/run-make/wasm-export-all-symbols/bar.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22

33
#[no_mangle]
44
pub extern fn foo() {}
5+
6+
#[no_mangle]
7+
pub static FOO: u64 = 42;

0 commit comments

Comments
 (0)