Skip to content

Commit 1398572

Browse files
committed
Auto merge of #52680 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 7 pull requests Successful merges: - #52391 (Add unaligned volatile intrinsics) - #52402 (impl PartialEq+Eq for BuildHasherDefault) - #52645 (Allow declaring existential types inside blocks) - #52656 (Stablize Redox Unix Sockets) - #52658 (Prefer `Option::map`/etc over `match` wherever it improves clarity) - #52668 (clarify pointer offset function safety concerns) - #52677 (Release notes: add some missing 1.28 libs stabilization) Failed merges: r? @ghost
2 parents 46804ef + 1deaed9 commit 1398572

File tree

20 files changed

+191
-66
lines changed

20 files changed

+191
-66
lines changed

RELEASES.md

+22-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ Stabilized APIs
5252
---------------
5353
- [`Iterator::step_by`]
5454
- [`Path::ancestors`]
55+
- [`SystemTime::UNIX_EPOCH`]
56+
- [`alloc::GlobalAlloc`]
57+
- [`alloc::Layout`]
58+
- [`alloc::LayoutErr`]
59+
- [`alloc::System`]
60+
- [`alloc::alloc`]
61+
- [`alloc::alloc_zeroed`]
62+
- [`alloc::dealloc`]
63+
- [`alloc::realloc`]
64+
- [`alloc::handle_alloc_error`]
5565
- [`btree_map::Entry::or_default`]
5666
- [`fmt::Alignment`]
5767
- [`hash_map::Entry::or_default`]
@@ -122,6 +132,16 @@ Compatibility Notes
122132
[cargo/5584]: https://github.com/rust-lang/cargo/pull/5584/
123133
[`Iterator::step_by`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.step_by
124134
[`Path::ancestors`]: https://doc.rust-lang.org/std/path/struct.Path.html#method.ancestors
135+
[`SystemTime::UNIX_EPOCH`]: https://doc.rust-lang.org/std/time/struct.SystemTime.html#associatedconstant.UNIX_EPOCH
136+
[`alloc::GlobalAlloc`]: https://doc.rust-lang.org/std/alloc/trait.GlobalAlloc.html
137+
[`alloc::Layout`]: https://doc.rust-lang.org/std/alloc/struct.Layout.html
138+
[`alloc::LayoutErr`]: https://doc.rust-lang.org/std/alloc/struct.LayoutErr.html
139+
[`alloc::System`]: https://doc.rust-lang.org/std/alloc/struct.System.html
140+
[`alloc::alloc`]: https://doc.rust-lang.org/std/alloc/fn.alloc.html
141+
[`alloc::alloc_zeroed`]: https://doc.rust-lang.org/std/alloc/fn.alloc_zeroed.html
142+
[`alloc::dealloc`]: https://doc.rust-lang.org/std/alloc/fn.dealloc.html
143+
[`alloc::realloc`]: https://doc.rust-lang.org/std/alloc/fn.realloc.html
144+
[`alloc::handle_alloc_error`]: https://doc.rust-lang.org/std/alloc/fn.handle_alloc_error.html
125145
[`btree_map::Entry::or_default`]: https://doc.rust-lang.org/std/collections/btree_map/enum.Entry.html#method.or_default
126146
[`fmt::Alignment`]: https://doc.rust-lang.org/std/fmt/enum.Alignment.html
127147
[`hash_map::Entry::or_default`]: https://doc.rust-lang.org/std/collections/btree_map/enum.Entry.html#method.or_default
@@ -3162,7 +3182,7 @@ Stabilized APIs
31623182
* [`UnixDatagram::shutdown`](http://doc.rust-lang.org/std/os/unix/net/struct.UnixDatagram.html#method.shutdown)
31633183
* RawFd impls for `UnixDatagram`
31643184
* `{BTree,Hash}Map::values_mut`
3165-
* [`<[_]>::binary_search_by_key`](http://doc.rust-lang.org/beta/std/primitive.slice.html#method.binary_search_by_key)
3185+
* [`<[_]>::binary_search_by_key`](http://doc.rust-lang.org/std/primitive.slice.html#method.binary_search_by_key)
31663186

31673187
Libraries
31683188
---------
@@ -4080,7 +4100,7 @@ Compatibility Notes
40804100
[1.6bh]: https://github.com/rust-lang/rust/pull/29811
40814101
[1.6c]: https://github.com/rust-lang/cargo/pull/2192
40824102
[1.6cc]: https://github.com/rust-lang/cargo/pull/2131
4083-
[1.6co]: http://doc.rust-lang.org/beta/core/index.html
4103+
[1.6co]: http://doc.rust-lang.org/core/index.html
40844104
[1.6dv]: https://github.com/rust-lang/rust/pull/30000
40854105
[1.6f]: https://github.com/rust-lang/rust/pull/29129
40864106
[1.6m]: https://github.com/rust-lang/rust/pull/29828

src/libcore/hash/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,16 @@ impl<H> Default for BuildHasherDefault<H> {
542542
}
543543
}
544544

545+
#[stable(since = "1.29.0", feature = "build_hasher_eq")]
546+
impl<H> PartialEq for BuildHasherDefault<H> {
547+
fn eq(&self, _other: &BuildHasherDefault<H>) -> bool {
548+
true
549+
}
550+
}
551+
552+
#[stable(since = "1.29.0", feature = "build_hasher_eq")]
553+
impl<H> Eq for BuildHasherDefault<H> {}
554+
545555
//////////////////////////////////////////////////////////////////////////////
546556

547557
mod impls {

src/libcore/intrinsics.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,15 @@ extern "rust-intrinsic" {
10851085
/// [`std::ptr::write_volatile`](../../std/ptr/fn.write_volatile.html).
10861086
pub fn volatile_store<T>(dst: *mut T, val: T);
10871087

1088+
/// Perform a volatile load from the `src` pointer
1089+
/// The pointer is not required to be aligned.
1090+
#[cfg(not(stage0))]
1091+
pub fn unaligned_volatile_load<T>(src: *const T) -> T;
1092+
/// Perform a volatile store to the `dst` pointer.
1093+
/// The pointer is not required to be aligned.
1094+
#[cfg(not(stage0))]
1095+
pub fn unaligned_volatile_store<T>(dst: *mut T, val: T);
1096+
10881097
/// Returns the square root of an `f32`
10891098
pub fn sqrtf32(x: f32) -> f32;
10901099
/// Returns the square root of an `f64`

src/libcore/ptr.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ impl<T: ?Sized> *const T {
591591
/// Behavior:
592592
///
593593
/// * Both the starting and resulting pointer must be either in bounds or one
594-
/// byte past the end of an allocated object.
594+
/// byte past the end of *the same* allocated object.
595595
///
596596
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
597597
///
@@ -643,9 +643,15 @@ impl<T: ?Sized> *const T {
643643
///
644644
/// The resulting pointer does not need to be in bounds, but it is
645645
/// potentially hazardous to dereference (which requires `unsafe`).
646+
/// In particular, the resulting pointer may *not* be used to access a
647+
/// different allocated object than the one `self` points to. In other
648+
/// words, `x.wrapping_offset(y.wrapping_offset_from(x))` is
649+
/// *not* the same as `y`, and dereferencing it is undefined behavior
650+
/// unless `x` and `y` point into the same allocated object.
646651
///
647652
/// Always use `.offset(count)` instead when possible, because `offset`
648-
/// allows the compiler to optimize better.
653+
/// allows the compiler to optimize better. If you need to cross object
654+
/// boundaries, cast the pointer to an integer and do the arithmetic there.
649655
///
650656
/// # Examples
651657
///
@@ -1340,7 +1346,7 @@ impl<T: ?Sized> *mut T {
13401346
/// Behavior:
13411347
///
13421348
/// * Both the starting and resulting pointer must be either in bounds or one
1343-
/// byte past the end of an allocated object.
1349+
/// byte past the end of *the same* allocated object.
13441350
///
13451351
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
13461352
///
@@ -1391,9 +1397,15 @@ impl<T: ?Sized> *mut T {
13911397
///
13921398
/// The resulting pointer does not need to be in bounds, but it is
13931399
/// potentially hazardous to dereference (which requires `unsafe`).
1400+
/// In particular, the resulting pointer may *not* be used to access a
1401+
/// different allocated object than the one `self` points to. In other
1402+
/// words, `x.wrapping_offset(y.wrapping_offset_from(x))` is
1403+
/// *not* the same as `y`, and dereferencing it is undefined behavior
1404+
/// unless `x` and `y` point into the same allocated object.
13941405
///
13951406
/// Always use `.offset(count)` instead when possible, because `offset`
1396-
/// allows the compiler to optimize better.
1407+
/// allows the compiler to optimize better. If you need to cross object
1408+
/// boundaries, cast the pointer to an integer and do the arithmetic there.
13971409
///
13981410
/// # Examples
13991411
///

src/libcore/str/mod.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -696,13 +696,10 @@ impl<'a> Iterator for CharIndices<'a> {
696696
impl<'a> DoubleEndedIterator for CharIndices<'a> {
697697
#[inline]
698698
fn next_back(&mut self) -> Option<(usize, char)> {
699-
match self.iter.next_back() {
700-
None => None,
701-
Some(ch) => {
702-
let index = self.front_offset + self.iter.iter.len();
703-
Some((index, ch))
704-
}
705-
}
699+
self.iter.next_back().map(|ch| {
700+
let index = self.front_offset + self.iter.iter.len();
701+
(index, ch)
702+
})
706703
}
707704
}
708705

src/librustc/traits/on_unimplemented.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,10 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedDirective {
190190
for command in self.subcommands.iter().chain(Some(self)).rev() {
191191
if let Some(ref condition) = command.condition {
192192
if !attr::eval_condition(condition, &tcx.sess.parse_sess, &mut |c| {
193-
options.contains(&(c.name().as_str().to_string(),
194-
match c.value_str().map(|s| s.as_str().to_string()) {
195-
Some(s) => Some(s),
196-
None => None
197-
}))
193+
options.contains(&(
194+
c.name().as_str().to_string(),
195+
c.value_str().map(|s| s.as_str().to_string())
196+
))
198197
}) {
199198
debug!("evaluate: skipping {:?} due to condition", command);
200199
continue

src/librustc/ty/mod.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -2697,15 +2697,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
26972697
self.opt_associated_item(def_id)
26982698
};
26992699

2700-
match item {
2701-
Some(trait_item) => {
2702-
match trait_item.container {
2703-
TraitContainer(_) => None,
2704-
ImplContainer(def_id) => Some(def_id),
2705-
}
2700+
item.and_then(|trait_item|
2701+
match trait_item.container {
2702+
TraitContainer(_) => None,
2703+
ImplContainer(def_id) => Some(def_id),
27062704
}
2707-
None => None
2708-
}
2705+
)
27092706
}
27102707

27112708
/// Looks up the span of `impl_did` if the impl is local; otherwise returns `Err`

src/librustc_codegen_llvm/builder.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ bitflags! {
5454
pub struct MemFlags: u8 {
5555
const VOLATILE = 1 << 0;
5656
const NONTEMPORAL = 1 << 1;
57+
const UNALIGNED = 1 << 2;
5758
}
5859
}
5960

@@ -602,7 +603,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
602603
let ptr = self.check_store(val, ptr);
603604
unsafe {
604605
let store = llvm::LLVMBuildStore(self.llbuilder, val, ptr);
605-
llvm::LLVMSetAlignment(store, align.abi() as c_uint);
606+
let align = if flags.contains(MemFlags::UNALIGNED) {
607+
1
608+
} else {
609+
align.abi() as c_uint
610+
};
611+
llvm::LLVMSetAlignment(store, align);
606612
if flags.contains(MemFlags::VOLATILE) {
607613
llvm::LLVMSetVolatile(store, llvm::True);
608614
}

src/librustc_codegen_llvm/intrinsic.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,20 @@ pub fn codegen_intrinsic_call<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
234234
memset_intrinsic(bx, true, substs.type_at(0),
235235
args[0].immediate(), args[1].immediate(), args[2].immediate())
236236
}
237-
"volatile_load" => {
237+
"volatile_load" | "unaligned_volatile_load" => {
238238
let tp_ty = substs.type_at(0);
239239
let mut ptr = args[0].immediate();
240240
if let PassMode::Cast(ty) = fn_ty.ret.mode {
241241
ptr = bx.pointercast(ptr, ty.llvm_type(cx).ptr_to());
242242
}
243243
let load = bx.volatile_load(ptr);
244+
let align = if name == "unaligned_volatile_load" {
245+
1
246+
} else {
247+
cx.align_of(tp_ty).abi() as u32
248+
};
244249
unsafe {
245-
llvm::LLVMSetAlignment(load, cx.align_of(tp_ty).abi() as u32);
250+
llvm::LLVMSetAlignment(load, align);
246251
}
247252
to_immediate(bx, load, cx.layout_of(tp_ty))
248253
},
@@ -251,6 +256,11 @@ pub fn codegen_intrinsic_call<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
251256
args[1].val.volatile_store(bx, dst);
252257
return;
253258
},
259+
"unaligned_volatile_store" => {
260+
let dst = args[0].deref(bx.cx);
261+
args[1].val.unaligned_volatile_store(bx, dst);
262+
return;
263+
},
254264
"prefetch_read_data" | "prefetch_write_data" |
255265
"prefetch_read_instruction" | "prefetch_write_instruction" => {
256266
let expect = cx.get_intrinsic(&("llvm.prefetch"));

src/librustc_codegen_llvm/mir/operand.rs

+4
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ impl<'a, 'tcx> OperandValue {
276276
self.store_with_flags(bx, dest, MemFlags::VOLATILE);
277277
}
278278

279+
pub fn unaligned_volatile_store(self, bx: &Builder<'a, 'tcx>, dest: PlaceRef<'tcx>) {
280+
self.store_with_flags(bx, dest, MemFlags::VOLATILE | MemFlags::UNALIGNED);
281+
}
282+
279283
pub fn nontemporal_store(self, bx: &Builder<'a, 'tcx>, dest: PlaceRef<'tcx>) {
280284
self.store_with_flags(bx, dest, MemFlags::NONTEMPORAL);
281285
}

src/librustc_metadata/locator.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -824,17 +824,14 @@ impl<'a> Context<'a> {
824824
if rlib.is_none() && rmeta.is_none() && dylib.is_none() {
825825
return None;
826826
}
827-
match slot {
828-
Some((_, metadata)) => {
829-
Some(Library {
830-
dylib,
831-
rlib,
832-
rmeta,
833-
metadata,
834-
})
827+
slot.map(|(_, metadata)|
828+
Library {
829+
dylib,
830+
rlib,
831+
rmeta,
832+
metadata,
835833
}
836-
None => None,
837-
}
834+
)
838835
}
839836
}
840837

src/librustc_typeck/check/intrinsic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
270270
"roundf32" => (0, vec![ tcx.types.f32 ], tcx.types.f32),
271271
"roundf64" => (0, vec![ tcx.types.f64 ], tcx.types.f64),
272272

273-
"volatile_load" =>
273+
"volatile_load" | "unaligned_volatile_load" =>
274274
(1, vec![ tcx.mk_imm_ptr(param(0)) ], param(0)),
275-
"volatile_store" =>
275+
"volatile_store" | "unaligned_volatile_store" =>
276276
(1, vec![ tcx.mk_mut_ptr(param(0)), param(0) ], tcx.mk_nil()),
277277

278278
"ctpop" | "ctlz" | "ctlz_nonzero" | "cttz" | "cttz_nonzero" |

src/libstd/net/parser.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ impl<'a> Parser<'a> {
5353
F: FnOnce(&mut Parser) -> Option<T>,
5454
{
5555
self.read_atomically(move |p| {
56-
match cb(p) {
57-
Some(x) => if p.is_eof() {Some(x)} else {None},
58-
None => None,
59-
}
56+
cb(p).filter(|_| p.is_eof())
6057
})
6158
}
6259

src/libstd/path.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1065,10 +1065,7 @@ impl<'a> Iterator for Ancestors<'a> {
10651065

10661066
fn next(&mut self) -> Option<Self::Item> {
10671067
let next = self.next;
1068-
self.next = match next {
1069-
Some(path) => path.parent(),
1070-
None => None,
1071-
};
1068+
self.next = next.and_then(Path::parent);
10721069
next
10731070
}
10741071
}

0 commit comments

Comments
 (0)