Skip to content

Commit 1d100ba

Browse files
committedAug 8, 2020
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
·
1.88.01.47.0
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

‎src/librustc_infer/infer/region_constraints/leak_check.rs

Lines changed: 2 additions & 2 deletions
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
}

‎src/librustc_infer/infer/sub.rs

Lines changed: 1 addition & 1 deletion
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
}

‎src/librustc_lint/types.rs

Lines changed: 1 addition & 1 deletion
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
}

‎src/librustc_metadata/rmeta/encoder.rs

Lines changed: 1 addition & 1 deletion
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
)

‎src/librustc_middle/traits/query.rs

Lines changed: 1 addition & 1 deletion
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,

‎src/librustc_mir/borrow_check/diagnostics/mod.rs

Lines changed: 1 addition & 1 deletion
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`)

‎src/librustc_mir/transform/simplify_try.rs

Lines changed: 1 addition & 1 deletion
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 {

‎src/librustc_mir/transform/validate.rs

Lines changed: 1 addition & 1 deletion
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

‎src/librustc_parse/parser/mod.rs

Lines changed: 2 additions & 0 deletions
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>,

‎src/librustc_parse_format/lib.rs

Lines changed: 1 addition & 1 deletion
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
}

‎src/librustc_resolve/late.rs

Lines changed: 1 addition & 1 deletion
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 {

‎src/librustc_save_analysis/lib.rs

Lines changed: 1 addition & 1 deletion
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.

‎src/librustc_session/filesearch.rs

Lines changed: 1 addition & 1 deletion
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

‎src/librustc_span/hygiene.rs

Lines changed: 2 additions & 2 deletions
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 {

‎src/librustc_trait_selection/autoderef.rs

Lines changed: 1 addition & 1 deletion
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 {

‎src/librustc_trait_selection/traits/error_reporting/suggestions.rs

Lines changed: 1 addition & 1 deletion
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,

‎src/librustc_traits/chalk/db.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
141141

142142
let predicates = self.tcx.predicates_of(adt_def.did).predicates;
143143
let where_clauses: Vec<_> = predicates
144-
.into_iter()
144+
.iter()
145145
.map(|(wc, _)| wc.subst(self.tcx, bound_vars))
146146
.filter_map(|wc| LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(wc, &self.interner))
147147
.collect();
@@ -174,7 +174,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
174174
phantom_data: adt_def.is_phantom_data(),
175175
},
176176
});
177-
return struct_datum;
177+
struct_datum
178178
}
179179

180180
fn fn_def_datum(
@@ -187,7 +187,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
187187

188188
let predicates = self.tcx.predicates_defined_on(def_id).predicates;
189189
let where_clauses: Vec<_> = predicates
190-
.into_iter()
190+
.iter()
191191
.map(|(wc, _)| wc.subst(self.tcx, &bound_vars))
192192
.filter_map(|wc| LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(wc, &self.interner)).collect();
193193

@@ -276,7 +276,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
276276
parameters[0].assert_ty_ref(&self.interner).could_match(&self.interner, &lowered_ty)
277277
});
278278

279-
let impls = matched_impls.map(|matched_impl| chalk_ir::ImplId(matched_impl)).collect();
279+
let impls = matched_impls.map(chalk_ir::ImplId).collect();
280280
impls
281281
}
282282

@@ -379,7 +379,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
379379
ty::AdtKind::Struct | ty::AdtKind::Union => None,
380380
ty::AdtKind::Enum => {
381381
let constraint = self.tcx.adt_sized_constraint(adt_def.did);
382-
if constraint.0.len() > 0 { unimplemented!() } else { Some(true) }
382+
if !constraint.0.is_empty() { unimplemented!() } else { Some(true) }
383383
}
384384
},
385385
_ => None,
@@ -398,7 +398,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
398398
ty::AdtKind::Struct | ty::AdtKind::Union => None,
399399
ty::AdtKind::Enum => {
400400
let constraint = self.tcx.adt_sized_constraint(adt_def.did);
401-
if constraint.0.len() > 0 { unimplemented!() } else { Some(true) }
401+
if !constraint.0.is_empty() { unimplemented!() } else { Some(true) }
402402
}
403403
},
404404
_ => None,
@@ -440,7 +440,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
440440
FnOnce => self.tcx.lang_items().fn_once_trait(),
441441
Unsize => self.tcx.lang_items().unsize_trait(),
442442
};
443-
def_id.map(|t| chalk_ir::TraitId(t))
443+
def_id.map(chalk_ir::TraitId)
444444
}
445445

446446
fn is_object_safe(&self, trait_id: chalk_ir::TraitId<RustInterner<'tcx>>) -> bool {

‎src/librustc_ty/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ fn opaque_type_projection_predicates(
443443

444444
let bounds = tcx.predicates_of(def_id);
445445
let predicates =
446-
util::elaborate_predicates(tcx, bounds.predicates.into_iter().map(|&(pred, _)| pred));
446+
util::elaborate_predicates(tcx, bounds.predicates.iter().map(|&(pred, _)| pred));
447447

448448
let filtered_predicates = predicates.filter_map(|obligation| {
449449
let pred = obligation.predicate;

‎src/librustc_typeck/check/dropck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,6 @@ impl TypeRelation<'tcx> for SimpleEqRelation<'tcx> {
368368
let anon_b = self.tcx.anonymize_late_bound_regions(&b);
369369
self.relate(anon_a.skip_binder(), anon_b.skip_binder())?;
370370

371-
Ok(a.clone())
371+
Ok(a)
372372
}
373373
}

‎src/librustc_typeck/check/pat.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11141114
tcx.sess.struct_span_err(pat.span, "`..` cannot be used in union patterns").emit();
11151115
}
11161116
} else if !etc && !unmentioned_fields.is_empty() {
1117-
unmentioned_err = Some(self.error_unmentioned_fields(pat.span, &unmentioned_fields));
1117+
unmentioned_err = Some(self.error_unmentioned_fields(pat, &unmentioned_fields));
11181118
}
11191119
match (inexistent_fields_err, unmentioned_err) {
11201120
(Some(mut i), Some(mut u)) => {
@@ -1237,13 +1237,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12371237
if tcx.sess.teach(&err.get_code().unwrap()) {
12381238
err.note(
12391239
"This error indicates that a struct pattern attempted to \
1240-
extract a non-existent field from a struct. Struct fields \
1241-
are identified by the name used before the colon : so struct \
1242-
patterns should resemble the declaration of the struct type \
1243-
being matched.\n\n\
1244-
If you are using shorthand field patterns but want to refer \
1245-
to the struct field by a different name, you should rename \
1246-
it explicitly.",
1240+
extract a non-existent field from a struct. Struct fields \
1241+
are identified by the name used before the colon : so struct \
1242+
patterns should resemble the declaration of the struct type \
1243+
being matched.\n\n\
1244+
If you are using shorthand field patterns but want to refer \
1245+
to the struct field by a different name, you should rename \
1246+
it explicitly.",
12471247
);
12481248
}
12491249
err
@@ -1299,7 +1299,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12991299

13001300
fn error_unmentioned_fields(
13011301
&self,
1302-
span: Span,
1302+
pat: &Pat<'_>,
13031303
unmentioned_fields: &[Ident],
13041304
) -> DiagnosticBuilder<'tcx> {
13051305
let field_names = if unmentioned_fields.len() == 1 {
@@ -1312,23 +1312,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13121312
.join(", ");
13131313
format!("fields {}", fields)
13141314
};
1315-
let mut diag = struct_span_err!(
1315+
let mut err = struct_span_err!(
13161316
self.tcx.sess,
1317-
span,
1317+
pat.span,
13181318
E0027,
13191319
"pattern does not mention {}",
13201320
field_names
13211321
);
1322-
diag.span_label(span, format!("missing {}", field_names));
1323-
if self.tcx.sess.teach(&diag.get_code().unwrap()) {
1324-
diag.note(
1322+
err.span_label(pat.span, format!("missing {}", field_names));
1323+
if self.tcx.sess.teach(&err.get_code().unwrap()) {
1324+
err.note(
13251325
"This error indicates that a pattern for a struct fails to specify a \
1326-
sub-pattern for every one of the struct's fields. Ensure that each field \
1327-
from the struct's definition is mentioned in the pattern, or use `..` to \
1328-
ignore unwanted fields.",
1326+
sub-pattern for every one of the struct's fields. Ensure that each field \
1327+
from the struct's definition is mentioned in the pattern, or use `..` to \
1328+
ignore unwanted fields.",
13291329
);
13301330
}
1331-
diag
1331+
err
13321332
}
13331333

13341334
fn check_pat_box(

‎src/librustc_typeck/check/place_op.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
200200
// Gather up expressions we want to munge.
201201
let mut exprs = vec![expr];
202202

203-
loop {
204-
match exprs.last().unwrap().kind {
205-
hir::ExprKind::Field(ref expr, _)
206-
| hir::ExprKind::Index(ref expr, _)
207-
| hir::ExprKind::Unary(hir::UnOp::UnDeref, ref expr) => exprs.push(&expr),
208-
_ => break,
209-
}
203+
while let hir::ExprKind::Field(ref expr, _)
204+
| hir::ExprKind::Index(ref expr, _)
205+
| hir::ExprKind::Unary(hir::UnOp::UnDeref, ref expr) = exprs.last().unwrap().kind
206+
{
207+
exprs.push(&expr);
210208
}
211209

212210
debug!("convert_place_derefs_to_mutable: exprs={:?}", exprs);

‎src/librustc_typeck/mem_categorization.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
583583
self.tcx()
584584
.sess
585585
.delay_span_bug(span, "struct or tuple struct pattern not applied to an ADT");
586-
return Err(());
586+
Err(())
587587
}
588588
}
589589
}
@@ -596,7 +596,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
596596
ty::Tuple(substs) => Ok(substs.len()),
597597
_ => {
598598
self.tcx().sess.delay_span_bug(span, "tuple pattern not applied to a tuple");
599-
return Err(());
599+
Err(())
600600
}
601601
}
602602
}

‎src/librustdoc/clean/mod.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,10 +1395,13 @@ impl Clean<Type> for hir::Ty<'_> {
13951395
_ => None,
13961396
});
13971397
if let Some(lt) = lifetime.cloned() {
1398-
if !lt.is_elided() {
1399-
let lt_def_id = cx.tcx.hir().local_def_id(param.hir_id);
1400-
lt_substs.insert(lt_def_id.to_def_id(), lt.clean(cx));
1401-
}
1398+
let lt_def_id = cx.tcx.hir().local_def_id(param.hir_id);
1399+
let cleaned = if !lt.is_elided() {
1400+
lt.clean(cx)
1401+
} else {
1402+
self::types::Lifetime::elided()
1403+
};
1404+
lt_substs.insert(lt_def_id.to_def_id(), cleaned);
14021405
}
14031406
indices.lifetimes += 1;
14041407
}
@@ -1957,21 +1960,17 @@ impl Clean<GenericArgs> for hir::GenericArgs<'_> {
19571960
output: if output != Type::Tuple(Vec::new()) { Some(output) } else { None },
19581961
}
19591962
} else {
1960-
let elide_lifetimes = self.args.iter().all(|arg| match arg {
1961-
hir::GenericArg::Lifetime(lt) => lt.is_elided(),
1962-
_ => true,
1963-
});
19641963
GenericArgs::AngleBracketed {
19651964
args: self
19661965
.args
19671966
.iter()
1968-
.filter_map(|arg| match arg {
1969-
hir::GenericArg::Lifetime(lt) if !elide_lifetimes => {
1970-
Some(GenericArg::Lifetime(lt.clean(cx)))
1967+
.map(|arg| match arg {
1968+
hir::GenericArg::Lifetime(lt) if !lt.is_elided() => {
1969+
GenericArg::Lifetime(lt.clean(cx))
19711970
}
1972-
hir::GenericArg::Lifetime(_) => None,
1973-
hir::GenericArg::Type(ty) => Some(GenericArg::Type(ty.clean(cx))),
1974-
hir::GenericArg::Const(ct) => Some(GenericArg::Const(ct.clean(cx))),
1971+
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
1972+
hir::GenericArg::Type(ty) => GenericArg::Type(ty.clean(cx)),
1973+
hir::GenericArg::Const(ct) => GenericArg::Const(ct.clean(cx)),
19751974
})
19761975
.collect(),
19771976
bindings: self.bindings.clean(cx),

‎src/librustdoc/clean/types.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,10 @@ impl Lifetime {
750750
pub fn statik() -> Lifetime {
751751
Lifetime("'static".to_string())
752752
}
753+
754+
pub fn elided() -> Lifetime {
755+
Lifetime("'_".to_string())
756+
}
753757
}
754758

755759
#[derive(Clone, Debug)]

‎src/librustdoc/clean/utils.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use crate::clean::auto_trait::AutoTraitFinder;
22
use crate::clean::blanket_impl::BlanketImplFinder;
33
use crate::clean::{
44
inline, Clean, Crate, Deprecation, ExternalCrate, FnDecl, FnRetTy, Generic, GenericArg,
5-
GenericArgs, GenericBound, Generics, GetDefId, ImportSource, Item, ItemEnum, MacroKind, Path,
6-
PathSegment, Primitive, PrimitiveType, ResolvedPath, Span, Stability, Type, TypeBinding,
7-
TypeKind, Visibility, WherePredicate,
5+
GenericArgs, GenericBound, Generics, GetDefId, ImportSource, Item, ItemEnum, Lifetime,
6+
MacroKind, Path, PathSegment, Primitive, PrimitiveType, ResolvedPath, Span, Stability, Type,
7+
TypeBinding, TypeKind, Visibility, WherePredicate,
88
};
99
use crate::core::DocContext;
1010

@@ -121,7 +121,10 @@ pub fn external_generic_args(
121121
let args: Vec<_> = substs
122122
.iter()
123123
.filter_map(|kind| match kind.unpack() {
124-
GenericArgKind::Lifetime(lt) => lt.clean(cx).map(GenericArg::Lifetime),
124+
GenericArgKind::Lifetime(lt) => match lt {
125+
ty::ReLateBound(_, ty::BrAnon(_)) => Some(GenericArg::Lifetime(Lifetime::elided())),
126+
_ => lt.clean(cx).map(GenericArg::Lifetime),
127+
},
125128
GenericArgKind::Type(_) if skip_self => {
126129
skip_self = false;
127130
None

‎src/librustdoc/docfs.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ impl DocFS {
6969
let sender = self.errors.clone().expect("can't write after closing");
7070
rayon::spawn(move || {
7171
fs::write(&path, contents).unwrap_or_else(|e| {
72-
sender
73-
.send(format!("\"{}\": {}", path.display(), e))
74-
.expect(&format!("failed to send error on \"{}\"", path.display()));
72+
sender.send(format!("\"{}\": {}", path.display(), e)).unwrap_or_else(|_| {
73+
panic!("failed to send error on \"{}\"", path.display())
74+
})
7575
});
7676
});
77-
Ok(())
7877
} else {
79-
Ok(try_err!(fs::write(&path, contents), path))
78+
try_err!(fs::write(&path, contents), path);
8079
}
80+
Ok(())
8181
}
8282
}

‎src/test/debuginfo/function-arguments-naked.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
// We have to ignore android because of this issue:
44
// https://github.com/rust-lang/rust/issues/74847
55
// ignore-android
6+
//
7+
// We need to use inline assembly, so just use one platform
8+
// only-x86_64
69

710
// compile-flags:-g
811

@@ -24,6 +27,7 @@
2427
// lldb-command:continue
2528

2629

30+
#![feature(asm)]
2731
#![feature(naked_functions)]
2832
#![feature(omit_gdb_pretty_printer_section)]
2933
#![omit_gdb_pretty_printer_section]
@@ -33,8 +37,6 @@ fn main() {
3337
}
3438

3539
#[naked]
36-
fn naked(x: usize, y: usize) {
37-
zzz(); // #break
40+
extern "C" fn naked(x: usize, y: usize) {
41+
unsafe { asm!("ret"); } // #break
3842
}
39-
40-
fn zzz() { () }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![crate_name = "bar"]
2+
3+
pub struct Ref<'a>(&'a u32);
4+
5+
pub fn test5(a: &u32) -> Ref {
6+
Ref(a)
7+
}
8+
9+
pub fn test6(a: &u32) -> Ref<'_> {
10+
Ref(a)
11+
}

‎src/test/rustdoc/elided-lifetime.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// aux-build:elided-lifetime.rs
2+
//
3+
// rust-lang/rust#75225
4+
//
5+
// Since Rust 2018 we encourage writing out <'_> explicitly to make it clear
6+
// that borrowing is occuring. Make sure rustdoc is following the same idiom.
7+
8+
#![crate_name = "foo"]
9+
10+
pub struct Ref<'a>(&'a u32);
11+
type ARef<'a> = Ref<'a>;
12+
13+
// @has foo/fn.test1.html
14+
// @matches - "Ref</a>&lt;'_&gt;"
15+
pub fn test1(a: &u32) -> Ref {
16+
Ref(a)
17+
}
18+
19+
// @has foo/fn.test2.html
20+
// @matches - "Ref</a>&lt;'_&gt;"
21+
pub fn test2(a: &u32) -> Ref<'_> {
22+
Ref(a)
23+
}
24+
25+
// @has foo/fn.test3.html
26+
// @matches - "Ref</a>&lt;'_&gt;"
27+
pub fn test3(a: &u32) -> ARef {
28+
Ref(a)
29+
}
30+
31+
// @has foo/fn.test4.html
32+
// @matches - "Ref</a>&lt;'_&gt;"
33+
pub fn test4(a: &u32) -> ARef<'_> {
34+
Ref(a)
35+
}
36+
37+
// Ensure external paths in inlined docs also display elided lifetime
38+
// @has foo/bar/fn.test5.html
39+
// @matches - "Ref</a>&lt;'_&gt;"
40+
// @has foo/bar/fn.test6.html
41+
// @matches - "Ref</a>&lt;'_&gt;"
42+
#[doc(inline)]
43+
pub extern crate bar;

0 commit comments

Comments
 (0)
Please sign in to comment.