Skip to content

Commit 1d100ba

Browse files
committed
Auto merge of #75276 - JohnTitor:rollup-rz4hs0w, r=JohnTitor
Rollup of 7 pull requests Successful merges: - #75224 (Don't call a function in function-arguments-naked.rs) - #75237 (Display elided lifetime for non-reference type in doc) - #75250 (make MaybeUninit::as_(mut_)ptr const) - #75253 (clean up const-hacks in int endianess conversion functions) - #75259 (Add missing backtick) - #75267 (Small cleanup) - #75270 (fix a couple of clippy findings) Failed merges: r? @ghost
2 parents f9c2177 + 21bfe52 commit 1d100ba

File tree

39 files changed

+170
-127
lines changed

39 files changed

+170
-127
lines changed

library/core/src/mem/maybe_uninit.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,11 @@ impl<T> MaybeUninit<T> {
405405
/// (Notice that the rules around references to uninitialized data are not finalized yet, but
406406
/// until they are, it is advisable to avoid them.)
407407
#[stable(feature = "maybe_uninit", since = "1.36.0")]
408+
#[rustc_const_unstable(feature = "const_maybe_uninit_as_ptr", issue = "75251")]
408409
#[inline(always)]
409-
pub fn as_ptr(&self) -> *const T {
410-
unsafe { &*self.value as *const T }
410+
pub const fn as_ptr(&self) -> *const T {
411+
// `MaybeUninit` and `ManuallyDrop` are both `repr(transparent)` so we can cast the pointer.
412+
self as *const _ as *const T
411413
}
412414

413415
/// Gets a mutable pointer to the contained value. Reading from this pointer or turning it
@@ -442,9 +444,11 @@ impl<T> MaybeUninit<T> {
442444
/// (Notice that the rules around references to uninitialized data are not finalized yet, but
443445
/// until they are, it is advisable to avoid them.)
444446
#[stable(feature = "maybe_uninit", since = "1.36.0")]
447+
#[rustc_const_unstable(feature = "const_maybe_uninit_as_ptr", issue = "75251")]
445448
#[inline(always)]
446-
pub fn as_mut_ptr(&mut self) -> *mut T {
447-
unsafe { &mut *self.value as *mut T }
449+
pub const fn as_mut_ptr(&mut self) -> *mut T {
450+
// `MaybeUninit` and `ManuallyDrop` are both `repr(transparent)` so we can cast the pointer.
451+
self as *mut _ as *mut T
448452
}
449453

450454
/// Extracts the value from the `MaybeUninit<T>` container. This is a great way

library/core/src/num/mod.rs

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,17 +2346,12 @@ assert_eq!(
23462346
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
23472347
// SAFETY: const sound because integers are plain old datatypes so we can always
23482348
// transmute them to arrays of bytes
2349-
#[allow_internal_unstable(const_fn_union)]
2349+
#[allow_internal_unstable(const_fn_transmute)]
23502350
#[inline]
23512351
pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
2352-
#[repr(C)]
2353-
union Bytes {
2354-
val: $SelfT,
2355-
bytes: [u8; mem::size_of::<$SelfT>()],
2356-
}
23572352
// SAFETY: integers are plain old datatypes so we can always transmute them to
23582353
// arrays of bytes
2359-
unsafe { Bytes { val: self }.bytes }
2354+
unsafe { mem::transmute(self) }
23602355
}
23612356
}
23622357

@@ -2464,16 +2459,11 @@ fn read_ne_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT),
24642459
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
24652460
// SAFETY: const sound because integers are plain old datatypes so we can always
24662461
// transmute to them
2467-
#[allow_internal_unstable(const_fn_union)]
2462+
#[allow_internal_unstable(const_fn_transmute)]
24682463
#[inline]
24692464
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
2470-
#[repr(C)]
2471-
union Bytes {
2472-
val: $SelfT,
2473-
bytes: [u8; mem::size_of::<$SelfT>()],
2474-
}
24752465
// SAFETY: integers are plain old datatypes so we can always transmute to them
2476-
unsafe { Bytes { bytes }.val }
2466+
unsafe { mem::transmute(bytes) }
24772467
}
24782468
}
24792469

@@ -4368,17 +4358,12 @@ assert_eq!(
43684358
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
43694359
// SAFETY: const sound because integers are plain old datatypes so we can always
43704360
// transmute them to arrays of bytes
4371-
#[allow_internal_unstable(const_fn_union)]
4361+
#[allow_internal_unstable(const_fn_transmute)]
43724362
#[inline]
43734363
pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
4374-
#[repr(C)]
4375-
union Bytes {
4376-
val: $SelfT,
4377-
bytes: [u8; mem::size_of::<$SelfT>()],
4378-
}
43794364
// SAFETY: integers are plain old datatypes so we can always transmute them to
43804365
// arrays of bytes
4381-
unsafe { Bytes { val: self }.bytes }
4366+
unsafe { mem::transmute(self) }
43824367
}
43834368
}
43844369

@@ -4486,16 +4471,11 @@ fn read_ne_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT),
44864471
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
44874472
// SAFETY: const sound because integers are plain old datatypes so we can always
44884473
// transmute to them
4489-
#[allow_internal_unstable(const_fn_union)]
4474+
#[allow_internal_unstable(const_fn_transmute)]
44904475
#[inline]
44914476
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
4492-
#[repr(C)]
4493-
union Bytes {
4494-
val: $SelfT,
4495-
bytes: [u8; mem::size_of::<$SelfT>()],
4496-
}
44974477
// SAFETY: integers are plain old datatypes so we can always transmute to them
4498-
unsafe { Bytes { bytes }.val }
4478+
unsafe { mem::transmute(bytes) }
44994479
}
45004480
}
45014481

library/test/src/helpers/concurrency.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::env;
44

55
#[allow(deprecated)]
66
pub fn get_concurrency() -> usize {
7-
return match env::var("RUST_TEST_THREADS") {
7+
match env::var("RUST_TEST_THREADS") {
88
Ok(s) => {
99
let opt_n: Option<usize> = s.parse().ok();
1010
match opt_n {
@@ -13,7 +13,7 @@ pub fn get_concurrency() -> usize {
1313
}
1414
}
1515
Err(..) => num_cpus(),
16-
};
16+
}
1717
}
1818

1919
cfg_if::cfg_if! {

src/librustc_ast/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ impl Default for Generics {
378378
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
379379
pub struct WhereClause {
380380
/// `true` if we ate a `where` token: this can happen
381-
/// if we parsed no predicates (e.g. `struct Foo where {}
381+
/// if we parsed no predicates (e.g. `struct Foo where {}`).
382382
/// This allows us to accurately pretty-print
383383
/// in `nt_to_tokenstream`
384384
pub has_where_token: bool,

src/librustc_codegen_llvm/debuginfo/metadata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -960,15 +960,15 @@ fn pointer_type_metadata(
960960
fn param_type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType {
961961
debug!("param_type_metadata: {:?}", t);
962962
let name = format!("{:?}", t);
963-
return unsafe {
963+
unsafe {
964964
llvm::LLVMRustDIBuilderCreateBasicType(
965965
DIB(cx),
966966
name.as_ptr().cast(),
967967
name.len(),
968968
Size::ZERO.bits(),
969969
DW_ATE_unsigned,
970970
)
971-
};
971+
}
972972
}
973973

974974
pub fn compile_unit_metadata(

src/librustc_codegen_ssa/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
490490
let _timer = sess.timer("copy_all_cgu_workproducts_to_incr_comp_cache_dir");
491491

492492
for module in compiled_modules.modules.iter().filter(|m| m.kind == ModuleKind::Regular) {
493-
let path = module.object.as_ref().map(|path| path.clone());
493+
let path = module.object.as_ref().cloned();
494494

495495
if let Some((id, product)) =
496496
copy_cgu_workproduct_to_incr_comp_cache_dir(sess, &module.name, &path)

src/librustc_infer/infer/error_reporting/nice_region_error/named_anon_conflict.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
8585

8686
debug!("try_report_named_anon_conflict: ret ty {:?}", ty);
8787
if sub == &ty::ReStatic
88-
&& v.0
89-
.into_iter()
90-
.filter(|t| t.span.desugaring_kind().is_none())
91-
.next()
92-
.is_some()
88+
&& v.0.into_iter().find(|t| t.span.desugaring_kind().is_none()).is_some()
9389
{
9490
// If the failure is due to a `'static` requirement coming from a `dyn` or
9591
// `impl` Trait that *isn't* caused by `async fn` desugaring, handle this case

src/librustc_infer/infer/error_reporting/nice_region_error/static_impl_trait.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
257257
param.param_ty.to_string(),
258258
Applicability::MaybeIncorrect,
259259
);
260-
} else if let Some(_) = opaque
260+
} else if opaque
261261
.bounds
262262
.iter()
263263
.filter_map(|arg| match arg {
@@ -269,6 +269,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
269269
_ => None,
270270
})
271271
.next()
272+
.is_some()
272273
{
273274
} else {
274275
err.span_suggestion_verbose(

src/librustc_infer/infer/glb.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl TypeRelation<'tcx> for Glb<'combine, 'infcx, 'tcx> {
5050
ty::Invariant => self.fields.equate(self.a_is_expected).relate(a, b),
5151
ty::Covariant => self.relate(a, b),
5252
// FIXME(#41044) -- not correct, need test
53-
ty::Bivariant => Ok(a.clone()),
53+
ty::Bivariant => Ok(a),
5454
ty::Contravariant => self.fields.lub(self.a_is_expected).relate(a, b),
5555
}
5656
}
@@ -97,7 +97,7 @@ impl TypeRelation<'tcx> for Glb<'combine, 'infcx, 'tcx> {
9797
// very challenging, switch to invariance. This is obviously
9898
// overly conservative but works ok in practice.
9999
self.relate_with_variance(ty::Variance::Invariant, a, b)?;
100-
Ok(a.clone())
100+
Ok(a)
101101
}
102102
}
103103

src/librustc_infer/infer/nll_relate/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ where
719719
self.a_scopes.pop().unwrap();
720720
}
721721

722-
Ok(a.clone())
722+
Ok(a)
723723
}
724724
}
725725

0 commit comments

Comments
 (0)