From bbcacddef691464e5abe373f95849670298c63a7 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Thu, 6 Aug 2020 12:11:49 -0400 Subject: [PATCH 01/28] Don't call a function in function-arguments-naked.rs Fixes #75096 It's U.B. to use anything other than inline assmebling in a naked function. Fortunately, the `#break` directive works fine without anything in the function body. --- src/test/debuginfo/function-arguments-naked.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/test/debuginfo/function-arguments-naked.rs b/src/test/debuginfo/function-arguments-naked.rs index e88a99b322ed5..f8e6253448a3f 100644 --- a/src/test/debuginfo/function-arguments-naked.rs +++ b/src/test/debuginfo/function-arguments-naked.rs @@ -34,7 +34,5 @@ fn main() { #[naked] fn naked(x: usize, y: usize) { - zzz(); // #break + // #break } - -fn zzz() { () } From 0aee186723a3bb3290fd4348b92b3c1aad862fc9 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 7 Aug 2020 12:24:28 +0200 Subject: [PATCH 02/28] make MaybeUninit::as_(mut_)ptr const --- library/core/src/mem/maybe_uninit.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index cf721b01ce3c6..132b9db19ce08 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -405,9 +405,11 @@ impl MaybeUninit { /// (Notice that the rules around references to uninitialized data are not finalized yet, but /// until they are, it is advisable to avoid them.) #[stable(feature = "maybe_uninit", since = "1.36.0")] + #[rustc_const_unstable(feature="maybe_uninit_as_ptr", issue = "none")] #[inline(always)] - pub fn as_ptr(&self) -> *const T { - unsafe { &*self.value as *const T } + pub const fn as_ptr(&self) -> *const T { + // `MaybeUninit` and `ManuallyDrop` are both `repr(transparent)` so we can cast the pointer. + self as *const _ as *const T } /// Gets a mutable pointer to the contained value. Reading from this pointer or turning it @@ -442,9 +444,11 @@ impl MaybeUninit { /// (Notice that the rules around references to uninitialized data are not finalized yet, but /// until they are, it is advisable to avoid them.) #[stable(feature = "maybe_uninit", since = "1.36.0")] + #[rustc_const_unstable(feature="maybe_uninit_as_ptr", issue = "none")] #[inline(always)] - pub fn as_mut_ptr(&mut self) -> *mut T { - unsafe { &mut *self.value as *mut T } + pub const fn as_mut_ptr(&mut self) -> *mut T { + // `MaybeUninit` and `ManuallyDrop` are both `repr(transparent)` so we can cast the pointer. + self as *mut _ as *mut T } /// Extracts the value from the `MaybeUninit` container. This is a great way From ec5d78d35004846f1d0c344e968eaf0068a68357 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 7 Aug 2020 12:27:53 +0200 Subject: [PATCH 03/28] fix feature gate and tracking issue --- library/core/src/mem/maybe_uninit.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index 132b9db19ce08..027498d3911c8 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -405,7 +405,7 @@ impl MaybeUninit { /// (Notice that the rules around references to uninitialized data are not finalized yet, but /// until they are, it is advisable to avoid them.) #[stable(feature = "maybe_uninit", since = "1.36.0")] - #[rustc_const_unstable(feature="maybe_uninit_as_ptr", issue = "none")] + #[rustc_const_unstable(feature = "const_maybe_uninit_as_ptr", issue = "75251")] #[inline(always)] pub const fn as_ptr(&self) -> *const T { // `MaybeUninit` and `ManuallyDrop` are both `repr(transparent)` so we can cast the pointer. @@ -444,7 +444,7 @@ impl MaybeUninit { /// (Notice that the rules around references to uninitialized data are not finalized yet, but /// until they are, it is advisable to avoid them.) #[stable(feature = "maybe_uninit", since = "1.36.0")] - #[rustc_const_unstable(feature="maybe_uninit_as_ptr", issue = "none")] + #[rustc_const_unstable(feature = "const_maybe_uninit_as_ptr", issue = "75251")] #[inline(always)] pub const fn as_mut_ptr(&mut self) -> *mut T { // `MaybeUninit` and `ManuallyDrop` are both `repr(transparent)` so we can cast the pointer. From a5309349510190178c8a860732374026bc2be298 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 7 Aug 2020 13:44:02 +0200 Subject: [PATCH 04/28] clean up const-hacks in int endianess conversion functions --- library/core/src/num/mod.rs | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 95eae7e2a73a1..6893717627035 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -2346,17 +2346,12 @@ assert_eq!( #[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")] // SAFETY: const sound because integers are plain old datatypes so we can always // transmute them to arrays of bytes - #[allow_internal_unstable(const_fn_union)] + #[allow_internal_unstable(const_fn_transmute)] #[inline] pub const fn to_ne_bytes(self) -> [u8; mem::size_of::()] { - #[repr(C)] - union Bytes { - val: $SelfT, - bytes: [u8; mem::size_of::<$SelfT>()], - } // SAFETY: integers are plain old datatypes so we can always transmute them to // arrays of bytes - unsafe { Bytes { val: self }.bytes } + unsafe { mem::transmute(self) } } } @@ -2464,16 +2459,11 @@ fn read_ne_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), #[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")] // SAFETY: const sound because integers are plain old datatypes so we can always // transmute to them - #[allow_internal_unstable(const_fn_union)] + #[allow_internal_unstable(const_fn_transmute)] #[inline] pub const fn from_ne_bytes(bytes: [u8; mem::size_of::()]) -> Self { - #[repr(C)] - union Bytes { - val: $SelfT, - bytes: [u8; mem::size_of::<$SelfT>()], - } // SAFETY: integers are plain old datatypes so we can always transmute to them - unsafe { Bytes { bytes }.val } + unsafe { mem::transmute(bytes) } } } @@ -4368,17 +4358,12 @@ assert_eq!( #[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")] // SAFETY: const sound because integers are plain old datatypes so we can always // transmute them to arrays of bytes - #[allow_internal_unstable(const_fn_union)] + #[allow_internal_unstable(const_fn_transmute)] #[inline] pub const fn to_ne_bytes(self) -> [u8; mem::size_of::()] { - #[repr(C)] - union Bytes { - val: $SelfT, - bytes: [u8; mem::size_of::<$SelfT>()], - } // SAFETY: integers are plain old datatypes so we can always transmute them to // arrays of bytes - unsafe { Bytes { val: self }.bytes } + unsafe { mem::transmute(self) } } } @@ -4486,16 +4471,11 @@ fn read_ne_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), #[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")] // SAFETY: const sound because integers are plain old datatypes so we can always // transmute to them - #[allow_internal_unstable(const_fn_union)] + #[allow_internal_unstable(const_fn_transmute)] #[inline] pub const fn from_ne_bytes(bytes: [u8; mem::size_of::()]) -> Self { - #[repr(C)] - union Bytes { - val: $SelfT, - bytes: [u8; mem::size_of::<$SelfT>()], - } // SAFETY: integers are plain old datatypes so we can always transmute to them - unsafe { Bytes { bytes }.val } + unsafe { mem::transmute(bytes) } } } From 91dda2c24ef245939c4ef0248380aa05583e3e30 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Fri, 7 Aug 2020 09:46:47 -0400 Subject: [PATCH 05/28] Only test function-arguments-naked.rs on x86_64 We need to use inline assembly, which is inherently platform-specific. --- src/test/debuginfo/function-arguments-naked.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/debuginfo/function-arguments-naked.rs b/src/test/debuginfo/function-arguments-naked.rs index f8e6253448a3f..f6919d6f7f77d 100644 --- a/src/test/debuginfo/function-arguments-naked.rs +++ b/src/test/debuginfo/function-arguments-naked.rs @@ -3,6 +3,9 @@ // We have to ignore android because of this issue: // https://github.com/rust-lang/rust/issues/74847 // ignore-android +// +// We need to use inline assembly, so just use one platform +// only-x86_64 // compile-flags:-g @@ -24,6 +27,7 @@ // lldb-command:continue +#![feature(asm)] #![feature(naked_functions)] #![feature(omit_gdb_pretty_printer_section)] #![omit_gdb_pretty_printer_section] @@ -34,5 +38,5 @@ fn main() { #[naked] fn naked(x: usize, y: usize) { - // #break + unsafe { asm!("ret"); } // #break } From c34c77c764491460449a6bef06b2149c3ab82f2d Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Fri, 7 Aug 2020 09:51:50 -0400 Subject: [PATCH 06/28] Apply `extern "C"` calling convention Co-authored-by: Amanieu d'Antras --- src/test/debuginfo/function-arguments-naked.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/debuginfo/function-arguments-naked.rs b/src/test/debuginfo/function-arguments-naked.rs index f6919d6f7f77d..5f3a1eb44e4e5 100644 --- a/src/test/debuginfo/function-arguments-naked.rs +++ b/src/test/debuginfo/function-arguments-naked.rs @@ -37,6 +37,6 @@ fn main() { } #[naked] -fn naked(x: usize, y: usize) { +extern "C" fn naked(x: usize, y: usize) { unsafe { asm!("ret"); } // #break } From 7d4565bf02a94370a2dce4ab0cfb2c79d61270a1 Mon Sep 17 00:00:00 2001 From: Takayuki Nakata Date: Wed, 5 Aug 2020 23:44:28 +0900 Subject: [PATCH 07/28] Add missing backtick --- src/librustc_ast/ast.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_ast/ast.rs b/src/librustc_ast/ast.rs index 6543117774a68..fe609388af389 100644 --- a/src/librustc_ast/ast.rs +++ b/src/librustc_ast/ast.rs @@ -378,7 +378,7 @@ impl Default for Generics { #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct WhereClause { /// `true` if we ate a `where` token: this can happen - /// if we parsed no predicates (e.g. `struct Foo where {} + /// if we parsed no predicates (e.g. `struct Foo where {}`). /// This allows us to accurately pretty-print /// in `nt_to_tokenstream` pub has_where_token: bool, From 7e9a8483f486f73c5be14abfe48cf5298c7972f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 7 Aug 2020 11:52:02 -0700 Subject: [PATCH 08/28] Small cleanup * Add docstring to `Parser` field * Remove unnecessary `unwrap` * Remove unnecessary borrow * Fix indentation of some `teach`text output --- src/librustc_parse/parser/mod.rs | 2 ++ src/librustc_resolve/late.rs | 2 +- src/librustc_typeck/check/pat.rs | 36 ++++++++++++++++---------------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/librustc_parse/parser/mod.rs b/src/librustc_parse/parser/mod.rs index 2509a9792215d..1165b9740296a 100644 --- a/src/librustc_parse/parser/mod.rs +++ b/src/librustc_parse/parser/mod.rs @@ -104,6 +104,8 @@ pub struct Parser<'a> { /// error. pub(super) unclosed_delims: Vec, last_unexpected_token_span: Option, + /// Span pointing at the `:` for the last type ascription the parser has seen, and whether it + /// looked like it could have been a mistyped path or literal `Option:Some(42)`). pub last_type_ascription: Option<(Span, bool /* likely path typo */)>, /// If present, this `Parser` is not parsing Rust code but rather a macro call. subparser_name: Option<&'static str>, diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index 44ff420909541..461edaf32524d 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -226,7 +226,7 @@ impl<'a> PathSource<'a> { ValueNS => "method or associated constant", MacroNS => bug!("associated macro"), }, - PathSource::Expr(parent) => match &parent.as_ref().map(|p| &p.kind) { + PathSource::Expr(parent) => match parent.as_ref().map(|p| &p.kind) { // "function" here means "anything callable" rather than `DefKind::Fn`, // this is not precise but usually more helpful than just "value". Some(ExprKind::Call(call_expr, _)) => match &call_expr.kind { diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs index 9c7ea34bf51b6..f598ada900fee 100644 --- a/src/librustc_typeck/check/pat.rs +++ b/src/librustc_typeck/check/pat.rs @@ -1114,7 +1114,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { tcx.sess.struct_span_err(pat.span, "`..` cannot be used in union patterns").emit(); } } else if !etc && !unmentioned_fields.is_empty() { - unmentioned_err = Some(self.error_unmentioned_fields(pat.span, &unmentioned_fields)); + unmentioned_err = Some(self.error_unmentioned_fields(pat, &unmentioned_fields)); } match (inexistent_fields_err, unmentioned_err) { (Some(mut i), Some(mut u)) => { @@ -1237,13 +1237,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if tcx.sess.teach(&err.get_code().unwrap()) { err.note( "This error indicates that a struct pattern attempted to \ - extract a non-existent field from a struct. Struct fields \ - are identified by the name used before the colon : so struct \ - patterns should resemble the declaration of the struct type \ - being matched.\n\n\ - If you are using shorthand field patterns but want to refer \ - to the struct field by a different name, you should rename \ - it explicitly.", + extract a non-existent field from a struct. Struct fields \ + are identified by the name used before the colon : so struct \ + patterns should resemble the declaration of the struct type \ + being matched.\n\n\ + If you are using shorthand field patterns but want to refer \ + to the struct field by a different name, you should rename \ + it explicitly.", ); } err @@ -1299,7 +1299,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn error_unmentioned_fields( &self, - span: Span, + pat: &Pat<'_>, unmentioned_fields: &[Ident], ) -> DiagnosticBuilder<'tcx> { let field_names = if unmentioned_fields.len() == 1 { @@ -1312,23 +1312,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .join(", "); format!("fields {}", fields) }; - let mut diag = struct_span_err!( + let mut err = struct_span_err!( self.tcx.sess, - span, + pat.span, E0027, "pattern does not mention {}", field_names ); - diag.span_label(span, format!("missing {}", field_names)); - if self.tcx.sess.teach(&diag.get_code().unwrap()) { - diag.note( + err.span_label(pat.span, format!("missing {}", field_names)); + if self.tcx.sess.teach(&err.get_code().unwrap()) { + err.note( "This error indicates that a pattern for a struct fails to specify a \ - sub-pattern for every one of the struct's fields. Ensure that each field \ - from the struct's definition is mentioned in the pattern, or use `..` to \ - ignore unwanted fields.", + sub-pattern for every one of the struct's fields. Ensure that each field \ + from the struct's definition is mentioned in the pattern, or use `..` to \ + ignore unwanted fields.", ); } - diag + err } fn check_pat_box( From 3ef8c7257770ded9aadce5424c377acb4199209a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 1 Aug 2020 17:38:20 +0200 Subject: [PATCH 09/28] fix clippy::expect_fun_call: use unwrap_or_else to prevent panic message from always being evaluated --- src/librustdoc/docfs.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/docfs.rs b/src/librustdoc/docfs.rs index 4ce6bcbe2749e..d7f1b98945ac6 100644 --- a/src/librustdoc/docfs.rs +++ b/src/librustdoc/docfs.rs @@ -69,9 +69,9 @@ impl DocFS { let sender = self.errors.clone().expect("can't write after closing"); rayon::spawn(move || { fs::write(&path, contents).unwrap_or_else(|e| { - sender - .send(format!("\"{}\": {}", path.display(), e)) - .expect(&format!("failed to send error on \"{}\"", path.display())); + sender.send(format!("\"{}\": {}", path.display(), e)).unwrap_or_else(|_| { + panic!("failed to send error on \"{}\"", path.display()) + }) }); }); Ok(()) From 8bc1f9182234acb060ff284abd46c10ee7d968ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 1 Aug 2020 17:40:26 +0200 Subject: [PATCH 10/28] fix clippy::filter_next: use .find(..) instead of .filter(..).next() --- .../nice_region_error/named_anon_conflict.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/librustc_infer/infer/error_reporting/nice_region_error/named_anon_conflict.rs b/src/librustc_infer/infer/error_reporting/nice_region_error/named_anon_conflict.rs index 72deba990b0b5..89142edb2dc61 100644 --- a/src/librustc_infer/infer/error_reporting/nice_region_error/named_anon_conflict.rs +++ b/src/librustc_infer/infer/error_reporting/nice_region_error/named_anon_conflict.rs @@ -85,11 +85,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { debug!("try_report_named_anon_conflict: ret ty {:?}", ty); if sub == &ty::ReStatic - && v.0 - .into_iter() - .filter(|t| t.span.desugaring_kind().is_none()) - .next() - .is_some() + && v.0.into_iter().find(|t| t.span.desugaring_kind().is_none()).is_some() { // If the failure is due to a `'static` requirement coming from a `dyn` or // `impl` Trait that *isn't* caused by `async fn` desugaring, handle this case From fca81fa3cdfaf9c53e1793c70448f106b74b358f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 1 Aug 2020 17:45:08 +0200 Subject: [PATCH 11/28] fix clippy::iter_next_slice: use .get(0) instead of .iter().next() --- src/librustc_middle/traits/query.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_middle/traits/query.rs b/src/librustc_middle/traits/query.rs index 69696ac9e93c0..4b7663e9adec1 100644 --- a/src/librustc_middle/traits/query.rs +++ b/src/librustc_middle/traits/query.rs @@ -128,7 +128,7 @@ pub struct DropckOutlivesResult<'tcx> { impl<'tcx> DropckOutlivesResult<'tcx> { pub fn report_overflows(&self, tcx: TyCtxt<'tcx>, span: Span, ty: Ty<'tcx>) { - if let Some(overflow_ty) = self.overflows.iter().next() { + if let Some(overflow_ty) = self.overflows.get(0) { let mut err = struct_span_err!( tcx.sess, span, From fb975cd6fb0858fe285376792dcf40d324ebfad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 1 Aug 2020 17:46:59 +0200 Subject: [PATCH 12/28] fix clippy::map_identity: remove redundant .map(|x| x) call --- src/librustc_parse_format/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_parse_format/lib.rs b/src/librustc_parse_format/lib.rs index 7db62f3493ede..ebb3aa3866e43 100644 --- a/src/librustc_parse_format/lib.rs +++ b/src/librustc_parse_format/lib.rs @@ -820,7 +820,7 @@ fn find_skips_from_snippet( } let r_start = str_style.map(|r| r + 1).unwrap_or(0); - let r_end = str_style.map(|r| r).unwrap_or(0); + let r_end = str_style.unwrap_or(0); let s = &snippet[r_start + 1..snippet.len() - r_end - 1]; (find_skips(s, str_style.is_some()), true) } From 27bb68927d55c1d893634f3865ed5f5e651a14b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 1 Aug 2020 17:50:31 +0200 Subject: [PATCH 13/28] fix clippy::redundant_clone: remove redundant clones --- src/librustc_session/filesearch.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_session/filesearch.rs b/src/librustc_session/filesearch.rs index 504490d938cfa..8fe71b71caed1 100644 --- a/src/librustc_session/filesearch.rs +++ b/src/librustc_session/filesearch.rs @@ -98,7 +98,7 @@ impl<'a> FileSearch<'a> { p.push(RUST_LIB_DIR); p.push(&self.triple); p.push("bin"); - if self_contained { vec![p.clone(), p.join("self-contained")] } else { vec![p.clone()] } + if self_contained { vec![p.clone(), p.join("self-contained")] } else { vec![p] } } } From 09e29e7e43c4e947c276efa4b281db78e49dea4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 1 Aug 2020 17:52:20 +0200 Subject: [PATCH 14/28] fix clippy::redundant_pattern_matching: use .is_some() instead of if let Some(_) = .. --- .../error_reporting/nice_region_error/static_impl_trait.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/librustc_infer/infer/error_reporting/nice_region_error/static_impl_trait.rs b/src/librustc_infer/infer/error_reporting/nice_region_error/static_impl_trait.rs index 0125e0f48e885..7493b8b0a9f77 100644 --- a/src/librustc_infer/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/src/librustc_infer/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -257,7 +257,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { param.param_ty.to_string(), Applicability::MaybeIncorrect, ); - } else if let Some(_) = opaque + } else if opaque .bounds .iter() .filter_map(|arg| match arg { @@ -269,6 +269,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { _ => None, }) .next() + .is_some() { } else { err.span_suggestion_verbose( From f3ec5be849ff6d4afb675259073911c1ba21dd01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 1 Aug 2020 17:53:16 +0200 Subject: [PATCH 15/28] fix clippy::single_char_pattern: use char instead of string single-char pattern --- .../traits/error_reporting/suggestions.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs index 13f8c71a629a9..e29e740f13669 100644 --- a/src/librustc_trait_selection/traits/error_reporting/suggestions.rs +++ b/src/librustc_trait_selection/traits/error_reporting/suggestions.rs @@ -495,7 +495,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { if let Ok(src) = self.tcx.sess.source_map().span_to_snippet(span) { // Don't care about `&mut` because `DerefMut` is used less // often and user will not expect autoderef happens. - if src.starts_with("&") && !src.starts_with("&mut ") { + if src.starts_with('&') && !src.starts_with("&mut ") { let derefs = "*".repeat(steps); err.span_suggestion( span, From a1c22122da34c4ce7b7817724221b2aad815b076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 1 Aug 2020 17:57:51 +0200 Subject: [PATCH 16/28] fix clippy::unit_arg: make it explicit that Ok(()) is being returned --- src/librustdoc/docfs.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/docfs.rs b/src/librustdoc/docfs.rs index d7f1b98945ac6..8b52ce710a45f 100644 --- a/src/librustdoc/docfs.rs +++ b/src/librustdoc/docfs.rs @@ -74,9 +74,9 @@ impl DocFS { }) }); }); - Ok(()) } else { - Ok(try_err!(fs::write(&path, contents), path)) + try_err!(fs::write(&path, contents), path); } + Ok(()) } } From f6b18573531bf67717b9d87250350709af72afd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 1 Aug 2020 18:01:19 +0200 Subject: [PATCH 17/28] fix clippy::unnecessary_mut_passed: function arg is not required to be mutable --- src/librustc_metadata/rmeta/encoder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index acae44e6bf7c9..c91f81a13404a 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -162,7 +162,7 @@ impl<'a, 'tcx> SpecializedEncoder for EncodeContext<'a, 'tcx> { fn specialized_encode(&mut self, expn: &ExpnId) -> Result<(), Self::Error> { rustc_span::hygiene::raw_encode_expn_id( *expn, - &mut self.hygiene_ctxt, + &self.hygiene_ctxt, ExpnDataEncodeMode::Metadata, self, ) From eccc2fe50374f0270517ce1b1c9d051717c7659c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 1 Aug 2020 18:20:39 +0200 Subject: [PATCH 18/28] fix clippy::unneeded_wildcard_pattern: remove redundant wildcard pattern --- src/librustc_save_analysis/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index d854835a02475..31aa2c4035e68 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -702,7 +702,7 @@ impl<'tcx> SaveContext<'tcx> { Res::Def(HirDefKind::ConstParam, def_id) => { Some(Ref { kind: RefKind::Variable, span, ref_id: id_from_def_id(def_id) }) } - Res::Def(HirDefKind::Ctor(_, ..), def_id) => { + Res::Def(HirDefKind::Ctor(..), def_id) => { // This is a reference to a tuple struct or an enum variant where the def_id points // to an invisible constructor function. That is not a very useful // def, so adjust to point to the tuple struct or enum variant itself. From 057730c4b1ab3d56d3f650b37b2245870941cbe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 1 Aug 2020 19:20:44 +0200 Subject: [PATCH 19/28] fix clippy::len_zero: use is_empty() instead of comparing .len() to zero --- src/librustc_traits/chalk/db.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_traits/chalk/db.rs b/src/librustc_traits/chalk/db.rs index 715e5299a37bd..31b20e451915e 100644 --- a/src/librustc_traits/chalk/db.rs +++ b/src/librustc_traits/chalk/db.rs @@ -379,7 +379,7 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t ty::AdtKind::Struct | ty::AdtKind::Union => None, ty::AdtKind::Enum => { let constraint = self.tcx.adt_sized_constraint(adt_def.did); - if constraint.0.len() > 0 { unimplemented!() } else { Some(true) } + if !constraint.0.is_empty() { unimplemented!() } else { Some(true) } } }, _ => None, @@ -398,7 +398,7 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t ty::AdtKind::Struct | ty::AdtKind::Union => None, ty::AdtKind::Enum => { let constraint = self.tcx.adt_sized_constraint(adt_def.did); - if constraint.0.len() > 0 { unimplemented!() } else { Some(true) } + if !constraint.0.is_empty() { unimplemented!() } else { Some(true) } } }, _ => None, From 63c0d9ca51bb471189a0d5529c8ee5491fb4e102 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Fri, 7 Aug 2020 00:48:24 +0100 Subject: [PATCH 20/28] Display elided lifetime for non-reference type in doc --- src/librustdoc/clean/mod.rs | 27 ++++++++++++----------- src/librustdoc/clean/types.rs | 4 ++++ src/test/rustdoc/elided-lifetime.rs | 33 +++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 src/test/rustdoc/elided-lifetime.rs diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 2a090d6efa5fd..7b1dd5b11ed0e 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1395,10 +1395,13 @@ impl Clean for hir::Ty<'_> { _ => None, }); if let Some(lt) = lifetime.cloned() { - if !lt.is_elided() { - let lt_def_id = cx.tcx.hir().local_def_id(param.hir_id); - lt_substs.insert(lt_def_id.to_def_id(), lt.clean(cx)); - } + let lt_def_id = cx.tcx.hir().local_def_id(param.hir_id); + let cleaned = if !lt.is_elided() { + lt.clean(cx) + } else { + self::types::Lifetime::elided() + }; + lt_substs.insert(lt_def_id.to_def_id(), cleaned); } indices.lifetimes += 1; } @@ -1957,21 +1960,17 @@ impl Clean for hir::GenericArgs<'_> { output: if output != Type::Tuple(Vec::new()) { Some(output) } else { None }, } } else { - let elide_lifetimes = self.args.iter().all(|arg| match arg { - hir::GenericArg::Lifetime(lt) => lt.is_elided(), - _ => true, - }); GenericArgs::AngleBracketed { args: self .args .iter() - .filter_map(|arg| match arg { - hir::GenericArg::Lifetime(lt) if !elide_lifetimes => { - Some(GenericArg::Lifetime(lt.clean(cx))) + .map(|arg| match arg { + hir::GenericArg::Lifetime(lt) if !lt.is_elided() => { + GenericArg::Lifetime(lt.clean(cx)) } - hir::GenericArg::Lifetime(_) => None, - hir::GenericArg::Type(ty) => Some(GenericArg::Type(ty.clean(cx))), - hir::GenericArg::Const(ct) => Some(GenericArg::Const(ct.clean(cx))), + hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()), + hir::GenericArg::Type(ty) => GenericArg::Type(ty.clean(cx)), + hir::GenericArg::Const(ct) => GenericArg::Const(ct.clean(cx)), }) .collect(), bindings: self.bindings.clean(cx), diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 1bea41b658532..b261df4073dfc 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -749,6 +749,10 @@ impl Lifetime { pub fn statik() -> Lifetime { Lifetime("'static".to_string()) } + + pub fn elided() -> Lifetime { + Lifetime("'_".to_string()) + } } #[derive(Clone, Debug)] diff --git a/src/test/rustdoc/elided-lifetime.rs b/src/test/rustdoc/elided-lifetime.rs new file mode 100644 index 0000000000000..641866aaf3c5f --- /dev/null +++ b/src/test/rustdoc/elided-lifetime.rs @@ -0,0 +1,33 @@ +#![crate_name = "foo"] + +// rust-lang/rust#75225 +// +// Since Rust 2018 we encourage writing out <'_> explicitly to make it clear +// that borrowing is occuring. Make sure rustdoc is following the same idiom. + +pub struct Ref<'a>(&'a u32); +type ARef<'a> = Ref<'a>; + +// @has foo/fn.test1.html +// @matches - "Ref<'_>" +pub fn test1(a: &u32) -> Ref { + Ref(a) +} + +// @has foo/fn.test2.html +// @matches - "Ref<'_>" +pub fn test2(a: &u32) -> Ref<'_> { + Ref(a) +} + +// @has foo/fn.test3.html +// @matches - "Ref<'_>" +pub fn test3(a: &u32) -> ARef { + Ref(a) +} + +// @has foo/fn.test4.html +// @matches - "Ref<'_>" +pub fn test4(a: &u32) -> ARef<'_> { + Ref(a) +} From 505d157814ba4e7d3ee0d036832008c3221b3df4 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Fri, 7 Aug 2020 23:34:44 +0100 Subject: [PATCH 21/28] Display elided lifetime for external paths --- src/librustdoc/clean/utils.rs | 11 +++++++---- src/test/rustdoc/elided-lifetime.rs | 13 +++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 52c306688268f..adef4c83224ba 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -2,9 +2,9 @@ use crate::clean::auto_trait::AutoTraitFinder; use crate::clean::blanket_impl::BlanketImplFinder; use crate::clean::{ inline, Clean, Crate, Deprecation, ExternalCrate, FnDecl, FnRetTy, Generic, GenericArg, - GenericArgs, GenericBound, Generics, GetDefId, ImportSource, Item, ItemEnum, MacroKind, Path, - PathSegment, Primitive, PrimitiveType, ResolvedPath, Span, Stability, Type, TypeBinding, - TypeKind, Visibility, WherePredicate, + GenericArgs, GenericBound, Generics, GetDefId, ImportSource, Item, ItemEnum, Lifetime, + MacroKind, Path, PathSegment, Primitive, PrimitiveType, ResolvedPath, Span, Stability, Type, + TypeBinding, TypeKind, Visibility, WherePredicate, }; use crate::core::DocContext; @@ -121,7 +121,10 @@ pub fn external_generic_args( let args: Vec<_> = substs .iter() .filter_map(|kind| match kind.unpack() { - GenericArgKind::Lifetime(lt) => lt.clean(cx).map(GenericArg::Lifetime), + GenericArgKind::Lifetime(lt) => match lt { + ty::ReLateBound(_, ty::BrAnon(_)) => Some(GenericArg::Lifetime(Lifetime::elided())), + _ => lt.clean(cx).map(GenericArg::Lifetime), + }, GenericArgKind::Type(_) if skip_self => { skip_self = false; None diff --git a/src/test/rustdoc/elided-lifetime.rs b/src/test/rustdoc/elided-lifetime.rs index 641866aaf3c5f..6ba58380ed593 100644 --- a/src/test/rustdoc/elided-lifetime.rs +++ b/src/test/rustdoc/elided-lifetime.rs @@ -31,3 +31,16 @@ pub fn test3(a: &u32) -> ARef { pub fn test4(a: &u32) -> ARef<'_> { Ref(a) } + +// Ensure external paths also display elided lifetime +// @has foo/fn.test5.html +// @matches - "Iter<'_" +pub fn test5(a: &Option) -> std::option::Iter { + a.iter() +} + +// @has foo/fn.test6.html +// @matches - "Iter<'_" +pub fn test6(a: &Option) -> std::option::Iter<'_, u32> { + a.iter() +} From f95cfe573a66e98e3f5becc3f0aa346271992d17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Fri, 7 Aug 2020 23:45:19 +0200 Subject: [PATCH 22/28] fix clippy::redundant_closure: remove redundant closures and call functions directly --- src/librustc_traits/chalk/db.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_traits/chalk/db.rs b/src/librustc_traits/chalk/db.rs index 31b20e451915e..56f90ba3b9982 100644 --- a/src/librustc_traits/chalk/db.rs +++ b/src/librustc_traits/chalk/db.rs @@ -276,7 +276,7 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t parameters[0].assert_ty_ref(&self.interner).could_match(&self.interner, &lowered_ty) }); - let impls = matched_impls.map(|matched_impl| chalk_ir::ImplId(matched_impl)).collect(); + let impls = matched_impls.map(chalk_ir::ImplId).collect(); impls } @@ -440,7 +440,7 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t FnOnce => self.tcx.lang_items().fn_once_trait(), Unsize => self.tcx.lang_items().unsize_trait(), }; - def_id.map(|t| chalk_ir::TraitId(t)) + def_id.map(chalk_ir::TraitId) } fn is_object_safe(&self, trait_id: chalk_ir::TraitId>) -> bool { From ea9ccfa42c0cd439042c251fc97fa8f160c3e272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Fri, 7 Aug 2020 23:59:59 +0200 Subject: [PATCH 23/28] fix clippy::while_let_loop: use while let{} instead of loop { if ... break; } --- src/librustc_typeck/check/place_op.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/librustc_typeck/check/place_op.rs b/src/librustc_typeck/check/place_op.rs index 1246875092355..84f34c0039a0a 100644 --- a/src/librustc_typeck/check/place_op.rs +++ b/src/librustc_typeck/check/place_op.rs @@ -200,13 +200,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Gather up expressions we want to munge. let mut exprs = vec![expr]; - loop { - match exprs.last().unwrap().kind { - hir::ExprKind::Field(ref expr, _) - | hir::ExprKind::Index(ref expr, _) - | hir::ExprKind::Unary(hir::UnOp::UnDeref, ref expr) => exprs.push(&expr), - _ => break, - } + while let hir::ExprKind::Field(ref expr, _) + | hir::ExprKind::Index(ref expr, _) + | hir::ExprKind::Unary(hir::UnOp::UnDeref, ref expr) = exprs.last().unwrap().kind + { + exprs.push(&expr); } debug!("convert_place_derefs_to_mutable: exprs={:?}", exprs); From 4ba1a194635b3c3f412f8caa7106191ac04c4950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 8 Aug 2020 00:07:01 +0200 Subject: [PATCH 24/28] fix clippy::into_iter_on_ref: use .iter() instead of into_iter() on references. --- src/librustc_traits/chalk/db.rs | 4 ++-- src/librustc_ty/ty.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_traits/chalk/db.rs b/src/librustc_traits/chalk/db.rs index 56f90ba3b9982..5129b5c57590e 100644 --- a/src/librustc_traits/chalk/db.rs +++ b/src/librustc_traits/chalk/db.rs @@ -141,7 +141,7 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t let predicates = self.tcx.predicates_of(adt_def.did).predicates; let where_clauses: Vec<_> = predicates - .into_iter() + .iter() .map(|(wc, _)| wc.subst(self.tcx, bound_vars)) .filter_map(|wc| LowerInto::>>>::lower_into(wc, &self.interner)) .collect(); @@ -187,7 +187,7 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t let predicates = self.tcx.predicates_defined_on(def_id).predicates; let where_clauses: Vec<_> = predicates - .into_iter() + .iter() .map(|(wc, _)| wc.subst(self.tcx, &bound_vars)) .filter_map(|wc| LowerInto::>>>::lower_into(wc, &self.interner)).collect(); diff --git a/src/librustc_ty/ty.rs b/src/librustc_ty/ty.rs index dfb28b473ff26..b31f9f3c7b14f 100644 --- a/src/librustc_ty/ty.rs +++ b/src/librustc_ty/ty.rs @@ -443,7 +443,7 @@ fn opaque_type_projection_predicates( let bounds = tcx.predicates_of(def_id); let predicates = - util::elaborate_predicates(tcx, bounds.predicates.into_iter().map(|&(pred, _)| pred)); + util::elaborate_predicates(tcx, bounds.predicates.iter().map(|&(pred, _)| pred)); let filtered_predicates = predicates.filter_map(|obligation| { let pred = obligation.predicate; From 15dcda36e6df44bc396208c8aeccba8fca2957ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 8 Aug 2020 00:14:28 +0200 Subject: [PATCH 25/28] fix clippy::map_clone: use .cloned() instead of .map(|x| x.clone()) --- src/librustc_codegen_ssa/back/write.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs index b0fae566a5aef..ae3ec15fcd70a 100644 --- a/src/librustc_codegen_ssa/back/write.rs +++ b/src/librustc_codegen_ssa/back/write.rs @@ -490,7 +490,7 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir( let _timer = sess.timer("copy_all_cgu_workproducts_to_incr_comp_cache_dir"); for module in compiled_modules.modules.iter().filter(|m| m.kind == ModuleKind::Regular) { - let path = module.object.as_ref().map(|path| path.clone()); + let path = module.object.as_ref().cloned(); if let Some((id, product)) = copy_cgu_workproduct_to_incr_comp_cache_dir(sess, &module.name, &path) From ff692ab14fec0549c3c58029d056175782c6d9c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 8 Aug 2020 00:27:46 +0200 Subject: [PATCH 26/28] fix clippy::clone_on_copy: don't clone types that are copy --- src/librustc_infer/infer/glb.rs | 4 ++-- src/librustc_infer/infer/nll_relate/mod.rs | 2 +- src/librustc_infer/infer/sub.rs | 2 +- src/librustc_mir/transform/validate.rs | 2 +- src/librustc_trait_selection/autoderef.rs | 2 +- src/librustc_typeck/check/dropck.rs | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/librustc_infer/infer/glb.rs b/src/librustc_infer/infer/glb.rs index 8a0ab52f38306..ccba904df9e00 100644 --- a/src/librustc_infer/infer/glb.rs +++ b/src/librustc_infer/infer/glb.rs @@ -50,7 +50,7 @@ impl TypeRelation<'tcx> for Glb<'combine, 'infcx, 'tcx> { ty::Invariant => self.fields.equate(self.a_is_expected).relate(a, b), ty::Covariant => self.relate(a, b), // FIXME(#41044) -- not correct, need test - ty::Bivariant => Ok(a.clone()), + ty::Bivariant => Ok(a), ty::Contravariant => self.fields.lub(self.a_is_expected).relate(a, b), } } @@ -97,7 +97,7 @@ impl TypeRelation<'tcx> for Glb<'combine, 'infcx, 'tcx> { // very challenging, switch to invariance. This is obviously // overly conservative but works ok in practice. self.relate_with_variance(ty::Variance::Invariant, a, b)?; - Ok(a.clone()) + Ok(a) } } diff --git a/src/librustc_infer/infer/nll_relate/mod.rs b/src/librustc_infer/infer/nll_relate/mod.rs index cb1f1c08d88f8..3f5ed36035c1a 100644 --- a/src/librustc_infer/infer/nll_relate/mod.rs +++ b/src/librustc_infer/infer/nll_relate/mod.rs @@ -719,7 +719,7 @@ where self.a_scopes.pop().unwrap(); } - Ok(a.clone()) + Ok(a) } } diff --git a/src/librustc_infer/infer/sub.rs b/src/librustc_infer/infer/sub.rs index 4f860c77d6541..308f884f9a63f 100644 --- a/src/librustc_infer/infer/sub.rs +++ b/src/librustc_infer/infer/sub.rs @@ -68,7 +68,7 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> { match variance { ty::Invariant => self.fields.equate(self.a_is_expected).relate(a, b), ty::Covariant => self.relate(a, b), - ty::Bivariant => Ok(a.clone()), + ty::Bivariant => Ok(a), ty::Contravariant => self.with_expected_switched(|this| this.relate(b, a)), } } diff --git a/src/librustc_mir/transform/validate.rs b/src/librustc_mir/transform/validate.rs index b8a74f09409ca..9296e2ca7008f 100644 --- a/src/librustc_mir/transform/validate.rs +++ b/src/librustc_mir/transform/validate.rs @@ -115,7 +115,7 @@ pub fn equal_up_to_regions( T: Relate<'tcx>, { self.relate(a.skip_binder(), b.skip_binder())?; - Ok(a.clone()) + Ok(a) } } diff --git a/src/librustc_trait_selection/autoderef.rs b/src/librustc_trait_selection/autoderef.rs index cc971440feac5..02eefe5622384 100644 --- a/src/librustc_trait_selection/autoderef.rs +++ b/src/librustc_trait_selection/autoderef.rs @@ -187,7 +187,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> { } pub fn span(&self) -> Span { - self.span.clone() + self.span } pub fn reached_recursion_limit(&self) -> bool { diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index 88c47b38ccc40..9ef9164191675 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -368,6 +368,6 @@ impl TypeRelation<'tcx> for SimpleEqRelation<'tcx> { let anon_b = self.tcx.anonymize_late_bound_regions(&b); self.relate(anon_a.skip_binder(), anon_b.skip_binder())?; - Ok(a.clone()) + Ok(a) } } From a605e510561f70cdae4592fb30b320dc6a07f603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 8 Aug 2020 00:39:38 +0200 Subject: [PATCH 27/28] fix clippy::needless_return: remove unneeded return statements --- library/test/src/helpers/concurrency.rs | 4 ++-- src/librustc_codegen_llvm/debuginfo/metadata.rs | 4 ++-- src/librustc_infer/infer/region_constraints/leak_check.rs | 4 ++-- src/librustc_lint/types.rs | 2 +- src/librustc_mir/borrow_check/diagnostics/mod.rs | 2 +- src/librustc_mir/transform/simplify_try.rs | 2 +- src/librustc_span/hygiene.rs | 4 ++-- src/librustc_traits/chalk/db.rs | 2 +- src/librustc_typeck/mem_categorization.rs | 4 ++-- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/library/test/src/helpers/concurrency.rs b/library/test/src/helpers/concurrency.rs index 2fe87247e3acf..7ca27bf0dc15e 100644 --- a/library/test/src/helpers/concurrency.rs +++ b/library/test/src/helpers/concurrency.rs @@ -4,7 +4,7 @@ use std::env; #[allow(deprecated)] pub fn get_concurrency() -> usize { - return match env::var("RUST_TEST_THREADS") { + match env::var("RUST_TEST_THREADS") { Ok(s) => { let opt_n: Option = s.parse().ok(); match opt_n { @@ -13,7 +13,7 @@ pub fn get_concurrency() -> usize { } } Err(..) => num_cpus(), - }; + } } cfg_if::cfg_if! { diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs index 6ae7c7efaee62..9d6b15ec4af8c 100644 --- a/src/librustc_codegen_llvm/debuginfo/metadata.rs +++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs @@ -960,7 +960,7 @@ fn pointer_type_metadata( fn param_type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType { debug!("param_type_metadata: {:?}", t); let name = format!("{:?}", t); - return unsafe { + unsafe { llvm::LLVMRustDIBuilderCreateBasicType( DIB(cx), name.as_ptr().cast(), @@ -968,7 +968,7 @@ fn param_type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType { Size::ZERO.bits(), DW_ATE_unsigned, ) - }; + } } pub fn compile_unit_metadata( diff --git a/src/librustc_infer/infer/region_constraints/leak_check.rs b/src/librustc_infer/infer/region_constraints/leak_check.rs index 32e708bf52b32..2d4c1e5d050ba 100644 --- a/src/librustc_infer/infer/region_constraints/leak_check.rs +++ b/src/librustc_infer/infer/region_constraints/leak_check.rs @@ -288,9 +288,9 @@ impl<'me, 'tcx> LeakCheck<'me, 'tcx> { ) -> TypeError<'tcx> { debug!("error: placeholder={:?}, other_region={:?}", placeholder, other_region); if self.overly_polymorphic { - return TypeError::RegionsOverlyPolymorphic(placeholder.name, other_region); + TypeError::RegionsOverlyPolymorphic(placeholder.name, other_region) } else { - return TypeError::RegionsInsufficientlyPolymorphic(placeholder.name, other_region); + TypeError::RegionsInsufficientlyPolymorphic(placeholder.name, other_region) } } } diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index de750010ed1e6..d285449c69024 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -1074,7 +1074,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { } // If `ty` is a `repr(transparent)` newtype, and the non-zero-sized type is a generic // argument, which after substitution, is `()`, then this branch can be hit. - FfiResult::FfiUnsafe { ty, .. } if is_return_type && ty.is_unit() => return, + FfiResult::FfiUnsafe { ty, .. } if is_return_type && ty.is_unit() => {} FfiResult::FfiUnsafe { ty, reason, help } => { self.emit_ffi_unsafe_type_lint(ty, sp, &reason, help.as_deref()); } diff --git a/src/librustc_mir/borrow_check/diagnostics/mod.rs b/src/librustc_mir/borrow_check/diagnostics/mod.rs index d8f6abd92f6b8..ba74ffaa8d620 100644 --- a/src/librustc_mir/borrow_check/diagnostics/mod.rs +++ b/src/librustc_mir/borrow_check/diagnostics/mod.rs @@ -868,7 +868,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { } } } - return normal_ret; + normal_ret } /// Finds the span of arguments of a closure (within `maybe_closure_span`) diff --git a/src/librustc_mir/transform/simplify_try.rs b/src/librustc_mir/transform/simplify_try.rs index 97a01de867e1d..02896d7de357f 100644 --- a/src/librustc_mir/transform/simplify_try.rs +++ b/src/librustc_mir/transform/simplify_try.rs @@ -361,7 +361,7 @@ fn optimization_applies<'tcx>( } trace!("SUCCESS: optimization applies!"); - return true; + true } impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity { diff --git a/src/librustc_span/hygiene.rs b/src/librustc_span/hygiene.rs index a03ac4e1fdba1..fe5370b9644fc 100644 --- a/src/librustc_span/hygiene.rs +++ b/src/librustc_span/hygiene.rs @@ -1030,7 +1030,7 @@ pub fn decode_expn_id< drop(expns); expn_id }); - return Ok(expn_id); + Ok(expn_id) } // Decodes `SyntaxContext`, using the provided `HygieneDecodeContext` @@ -1103,7 +1103,7 @@ pub fn decode_syntax_context< assert_eq!(dummy.dollar_crate_name, kw::Invalid); }); - return Ok(new_ctxt); + Ok(new_ctxt) } pub fn num_syntax_ctxts() -> usize { diff --git a/src/librustc_traits/chalk/db.rs b/src/librustc_traits/chalk/db.rs index 5129b5c57590e..4c8be8eb61010 100644 --- a/src/librustc_traits/chalk/db.rs +++ b/src/librustc_traits/chalk/db.rs @@ -174,7 +174,7 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t phantom_data: adt_def.is_phantom_data(), }, }); - return struct_datum; + struct_datum } fn fn_def_datum( diff --git a/src/librustc_typeck/mem_categorization.rs b/src/librustc_typeck/mem_categorization.rs index afc7cb346eb42..8a6fe620af7a3 100644 --- a/src/librustc_typeck/mem_categorization.rs +++ b/src/librustc_typeck/mem_categorization.rs @@ -583,7 +583,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { self.tcx() .sess .delay_span_bug(span, "struct or tuple struct pattern not applied to an ADT"); - return Err(()); + Err(()) } } } @@ -596,7 +596,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { ty::Tuple(substs) => Ok(substs.len()), _ => { self.tcx().sess.delay_span_bug(span, "tuple pattern not applied to a tuple"); - return Err(()); + Err(()) } } } From 541fbbb6fab4afdeea48fdb9e94cee48991b3333 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sat, 8 Aug 2020 01:07:43 +0100 Subject: [PATCH 28/28] Cross-crate doc inlining test case for elided lifetime --- src/test/rustdoc/auxiliary/elided-lifetime.rs | 11 ++++++++ src/test/rustdoc/elided-lifetime.rs | 25 ++++++++----------- 2 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 src/test/rustdoc/auxiliary/elided-lifetime.rs diff --git a/src/test/rustdoc/auxiliary/elided-lifetime.rs b/src/test/rustdoc/auxiliary/elided-lifetime.rs new file mode 100644 index 0000000000000..4f2c93379d88e --- /dev/null +++ b/src/test/rustdoc/auxiliary/elided-lifetime.rs @@ -0,0 +1,11 @@ +#![crate_name = "bar"] + +pub struct Ref<'a>(&'a u32); + +pub fn test5(a: &u32) -> Ref { + Ref(a) +} + +pub fn test6(a: &u32) -> Ref<'_> { + Ref(a) +} diff --git a/src/test/rustdoc/elided-lifetime.rs b/src/test/rustdoc/elided-lifetime.rs index 6ba58380ed593..5a32554f972b7 100644 --- a/src/test/rustdoc/elided-lifetime.rs +++ b/src/test/rustdoc/elided-lifetime.rs @@ -1,10 +1,12 @@ -#![crate_name = "foo"] - +// aux-build:elided-lifetime.rs +// // rust-lang/rust#75225 // // Since Rust 2018 we encourage writing out <'_> explicitly to make it clear // that borrowing is occuring. Make sure rustdoc is following the same idiom. +#![crate_name = "foo"] + pub struct Ref<'a>(&'a u32); type ARef<'a> = Ref<'a>; @@ -32,15 +34,10 @@ pub fn test4(a: &u32) -> ARef<'_> { Ref(a) } -// Ensure external paths also display elided lifetime -// @has foo/fn.test5.html -// @matches - "Iter<'_" -pub fn test5(a: &Option) -> std::option::Iter { - a.iter() -} - -// @has foo/fn.test6.html -// @matches - "Iter<'_" -pub fn test6(a: &Option) -> std::option::Iter<'_, u32> { - a.iter() -} +// Ensure external paths in inlined docs also display elided lifetime +// @has foo/bar/fn.test5.html +// @matches - "Ref<'_>" +// @has foo/bar/fn.test6.html +// @matches - "Ref<'_>" +#[doc(inline)] +pub extern crate bar;