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

Diff for: library/core/src/mem/maybe_uninit.rs

+8-4
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

Diff for: library/core/src/num/mod.rs

+8-28
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

Diff for: library/test/src/helpers/concurrency.rs

+2-2
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! {

Diff for: src/librustc_ast/ast.rs

+1-1
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,

Diff for: src/librustc_codegen_llvm/debuginfo/metadata.rs

+2-2
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(

Diff for: src/librustc_codegen_ssa/back/write.rs

+1-1
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)

Diff for: src/librustc_infer/infer/error_reporting/nice_region_error/named_anon_conflict.rs

+1-5
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

Diff for: src/librustc_infer/infer/error_reporting/nice_region_error/static_impl_trait.rs

+2-1
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(

Diff for: src/librustc_infer/infer/glb.rs

+2-2
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

Diff for: src/librustc_infer/infer/nll_relate/mod.rs

+1-1
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

Diff for: src/librustc_infer/infer/region_constraints/leak_check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ impl<'me, 'tcx> LeakCheck<'me, 'tcx> {
288288
) -> TypeError<'tcx> {
289289
debug!("error: placeholder={:?}, other_region={:?}", placeholder, other_region);
290290
if self.overly_polymorphic {
291-
return TypeError::RegionsOverlyPolymorphic(placeholder.name, other_region);
291+
TypeError::RegionsOverlyPolymorphic(placeholder.name, other_region)
292292
} else {
293-
return TypeError::RegionsInsufficientlyPolymorphic(placeholder.name, other_region);
293+
TypeError::RegionsInsufficientlyPolymorphic(placeholder.name, other_region)
294294
}
295295
}
296296
}

Diff for: src/librustc_infer/infer/sub.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
6868
match variance {
6969
ty::Invariant => self.fields.equate(self.a_is_expected).relate(a, b),
7070
ty::Covariant => self.relate(a, b),
71-
ty::Bivariant => Ok(a.clone()),
71+
ty::Bivariant => Ok(a),
7272
ty::Contravariant => self.with_expected_switched(|this| this.relate(b, a)),
7373
}
7474
}

Diff for: src/librustc_lint/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
10741074
}
10751075
// If `ty` is a `repr(transparent)` newtype, and the non-zero-sized type is a generic
10761076
// argument, which after substitution, is `()`, then this branch can be hit.
1077-
FfiResult::FfiUnsafe { ty, .. } if is_return_type && ty.is_unit() => return,
1077+
FfiResult::FfiUnsafe { ty, .. } if is_return_type && ty.is_unit() => {}
10781078
FfiResult::FfiUnsafe { ty, reason, help } => {
10791079
self.emit_ffi_unsafe_type_lint(ty, sp, &reason, help.as_deref());
10801080
}

Diff for: src/librustc_metadata/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl<'a, 'tcx> SpecializedEncoder<ExpnId> for EncodeContext<'a, 'tcx> {
162162
fn specialized_encode(&mut self, expn: &ExpnId) -> Result<(), Self::Error> {
163163
rustc_span::hygiene::raw_encode_expn_id(
164164
*expn,
165-
&mut self.hygiene_ctxt,
165+
&self.hygiene_ctxt,
166166
ExpnDataEncodeMode::Metadata,
167167
self,
168168
)

Diff for: src/librustc_middle/traits/query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub struct DropckOutlivesResult<'tcx> {
128128

129129
impl<'tcx> DropckOutlivesResult<'tcx> {
130130
pub fn report_overflows(&self, tcx: TyCtxt<'tcx>, span: Span, ty: Ty<'tcx>) {
131-
if let Some(overflow_ty) = self.overflows.iter().next() {
131+
if let Some(overflow_ty) = self.overflows.get(0) {
132132
let mut err = struct_span_err!(
133133
tcx.sess,
134134
span,

Diff for: src/librustc_mir/borrow_check/diagnostics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
868868
}
869869
}
870870
}
871-
return normal_ret;
871+
normal_ret
872872
}
873873

874874
/// Finds the span of arguments of a closure (within `maybe_closure_span`)

Diff for: src/librustc_mir/transform/simplify_try.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ fn optimization_applies<'tcx>(
361361
}
362362

363363
trace!("SUCCESS: optimization applies!");
364-
return true;
364+
true
365365
}
366366

367367
impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity {

Diff for: src/librustc_mir/transform/validate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub fn equal_up_to_regions(
115115
T: Relate<'tcx>,
116116
{
117117
self.relate(a.skip_binder(), b.skip_binder())?;
118-
Ok(a.clone())
118+
Ok(a)
119119
}
120120
}
121121

Diff for: src/librustc_parse/parser/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ pub struct Parser<'a> {
103103
/// error.
104104
pub(super) unclosed_delims: Vec<UnmatchedBrace>,
105105
last_unexpected_token_span: Option<Span>,
106+
/// Span pointing at the `:` for the last type ascription the parser has seen, and whether it
107+
/// looked like it could have been a mistyped path or literal `Option:Some(42)`).
106108
pub last_type_ascription: Option<(Span, bool /* likely path typo */)>,
107109
/// If present, this `Parser` is not parsing Rust code but rather a macro call.
108110
subparser_name: Option<&'static str>,

Diff for: src/librustc_parse_format/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ fn find_skips_from_snippet(
820820
}
821821

822822
let r_start = str_style.map(|r| r + 1).unwrap_or(0);
823-
let r_end = str_style.map(|r| r).unwrap_or(0);
823+
let r_end = str_style.unwrap_or(0);
824824
let s = &snippet[r_start + 1..snippet.len() - r_end - 1];
825825
(find_skips(s, str_style.is_some()), true)
826826
}

Diff for: src/librustc_resolve/late.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl<'a> PathSource<'a> {
226226
ValueNS => "method or associated constant",
227227
MacroNS => bug!("associated macro"),
228228
},
229-
PathSource::Expr(parent) => match &parent.as_ref().map(|p| &p.kind) {
229+
PathSource::Expr(parent) => match parent.as_ref().map(|p| &p.kind) {
230230
// "function" here means "anything callable" rather than `DefKind::Fn`,
231231
// this is not precise but usually more helpful than just "value".
232232
Some(ExprKind::Call(call_expr, _)) => match &call_expr.kind {

Diff for: src/librustc_save_analysis/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ impl<'tcx> SaveContext<'tcx> {
702702
Res::Def(HirDefKind::ConstParam, def_id) => {
703703
Some(Ref { kind: RefKind::Variable, span, ref_id: id_from_def_id(def_id) })
704704
}
705-
Res::Def(HirDefKind::Ctor(_, ..), def_id) => {
705+
Res::Def(HirDefKind::Ctor(..), def_id) => {
706706
// This is a reference to a tuple struct or an enum variant where the def_id points
707707
// to an invisible constructor function. That is not a very useful
708708
// def, so adjust to point to the tuple struct or enum variant itself.

Diff for: src/librustc_session/filesearch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'a> FileSearch<'a> {
9898
p.push(RUST_LIB_DIR);
9999
p.push(&self.triple);
100100
p.push("bin");
101-
if self_contained { vec![p.clone(), p.join("self-contained")] } else { vec![p.clone()] }
101+
if self_contained { vec![p.clone(), p.join("self-contained")] } else { vec![p] }
102102
}
103103
}
104104

Diff for: src/librustc_span/hygiene.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ pub fn decode_expn_id<
10301030
drop(expns);
10311031
expn_id
10321032
});
1033-
return Ok(expn_id);
1033+
Ok(expn_id)
10341034
}
10351035

10361036
// Decodes `SyntaxContext`, using the provided `HygieneDecodeContext`
@@ -1103,7 +1103,7 @@ pub fn decode_syntax_context<
11031103
assert_eq!(dummy.dollar_crate_name, kw::Invalid);
11041104
});
11051105

1106-
return Ok(new_ctxt);
1106+
Ok(new_ctxt)
11071107
}
11081108

11091109
pub fn num_syntax_ctxts() -> usize {

Diff for: src/librustc_trait_selection/autoderef.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
187187
}
188188

189189
pub fn span(&self) -> Span {
190-
self.span.clone()
190+
self.span
191191
}
192192

193193
pub fn reached_recursion_limit(&self) -> bool {

Diff for: src/librustc_trait_selection/traits/error_reporting/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
495495
if let Ok(src) = self.tcx.sess.source_map().span_to_snippet(span) {
496496
// Don't care about `&mut` because `DerefMut` is used less
497497
// often and user will not expect autoderef happens.
498-
if src.starts_with("&") && !src.starts_with("&mut ") {
498+
if src.starts_with('&') && !src.starts_with("&mut ") {
499499
let derefs = "*".repeat(steps);
500500
err.span_suggestion(
501501
span,

0 commit comments

Comments
 (0)