]> git.lizzy.rs Git - rust.git/commitdiff
make some let-if-bindings more idiomatic (clippy::useless_let_if_seq)
authorMatthias Krüger <matthias.krueger@famsik.de>
Sat, 21 Mar 2020 13:44:17 +0000 (14:44 +0100)
committerMatthias Krüger <matthias.krueger@famsik.de>
Sat, 21 Mar 2020 19:45:18 +0000 (20:45 +0100)
src/librustc/ty/layout.rs
src/librustc_mir/borrow_check/diagnostics/move_errors.rs
src/librustc_mir_build/build/mod.rs
src/librustc_resolve/build_reduced_graph.rs

index 6d28796b34847231c42291b6de331f6f9f41c268..d66fcd3a20db92017521bde7569f5340244cd8dc 100644 (file)
@@ -381,12 +381,8 @@ fn univariant_uninterned(
         // Field 5 would be the first element, so memory_index is i:
         // Note: if we didn't optimize, it's already right.
 
-        let memory_index;
-        if optimize {
-            memory_index = invert_mapping(&inverse_memory_index);
-        } else {
-            memory_index = inverse_memory_index;
-        }
+        let memory_index =
+            if optimize { invert_mapping(&inverse_memory_index) } else { inverse_memory_index };
 
         let size = min_size.align_to(align.abi);
         let mut abi = Abi::Aggregate { sized };
@@ -944,33 +940,33 @@ fn layout_raw_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx LayoutDetails, Layou
                             let offset = st[i].fields.offset(field_index) + niche.offset;
                             let size = st[i].size;
 
-                            let mut abi = match st[i].abi {
-                                Abi::Scalar(_) => Abi::Scalar(niche_scalar.clone()),
-                                Abi::ScalarPair(ref first, ref second) => {
-                                    // We need to use scalar_unit to reset the
-                                    // valid range to the maximal one for that
-                                    // primitive, because only the niche is
-                                    // guaranteed to be initialised, not the
-                                    // other primitive.
-                                    if offset.bytes() == 0 {
-                                        Abi::ScalarPair(
-                                            niche_scalar.clone(),
-                                            scalar_unit(second.value),
-                                        )
-                                    } else {
-                                        Abi::ScalarPair(
-                                            scalar_unit(first.value),
-                                            niche_scalar.clone(),
-                                        )
+                            let abi = if st.iter().all(|v| v.abi.is_uninhabited()) {
+                                Abi::Uninhabited
+                            } else {
+                                match st[i].abi {
+                                    Abi::Scalar(_) => Abi::Scalar(niche_scalar.clone()),
+                                    Abi::ScalarPair(ref first, ref second) => {
+                                        // We need to use scalar_unit to reset the
+                                        // valid range to the maximal one for that
+                                        // primitive, because only the niche is
+                                        // guaranteed to be initialised, not the
+                                        // other primitive.
+                                        if offset.bytes() == 0 {
+                                            Abi::ScalarPair(
+                                                niche_scalar.clone(),
+                                                scalar_unit(second.value),
+                                            )
+                                        } else {
+                                            Abi::ScalarPair(
+                                                scalar_unit(first.value),
+                                                niche_scalar.clone(),
+                                            )
+                                        }
                                     }
+                                    _ => Abi::Aggregate { sized: true },
                                 }
-                                _ => Abi::Aggregate { sized: true },
                             };
 
-                            if st.iter().all(|v| v.abi.is_uninhabited()) {
-                                abi = Abi::Uninhabited;
-                            }
-
                             let largest_niche =
                                 Niche::from_scalar(dl, offset, niche_scalar.clone());
 
index 9451fee499d36df2efe292fd7029192a3777b093..7b65a5a10986ab22f7591ee5e9ebacbabfda1ac3 100644 (file)
@@ -490,17 +490,13 @@ fn add_move_error_suggestions(&self, err: &mut DiagnosticBuilder<'a>, binds_to:
                 {
                     if pat_snippet.starts_with('&') {
                         let pat_snippet = pat_snippet[1..].trim_start();
-                        let suggestion;
-                        let to_remove;
-                        if pat_snippet.starts_with("mut")
+                        let (suggestion, to_remove) = if pat_snippet.starts_with("mut")
                             && pat_snippet["mut".len()..].starts_with(rustc_lexer::is_whitespace)
                         {
-                            suggestion = pat_snippet["mut".len()..].trim_start();
-                            to_remove = "&mut";
+                            (pat_snippet["mut".len()..].trim_start(), "&mut")
                         } else {
-                            suggestion = pat_snippet;
-                            to_remove = "&";
-                        }
+                            (pat_snippet, "&")
+                        };
                         suggestions.push((pat_span, to_remove, suggestion.to_owned()));
                     }
                 }
index c21834bfde84b744bf674f3ede722cc84c259ff0..d66650329313b907e2fd390073a91c364d942ebf 100644 (file)
@@ -637,11 +637,12 @@ fn construct_fn<'a, 'tcx, A>(
     );
     assert_eq!(block, builder.return_block());
 
-    let mut spread_arg = None;
-    if abi == Abi::RustCall {
+    let spread_arg = if abi == Abi::RustCall {
         // RustCall pseudo-ABI untuples the last argument.
-        spread_arg = Some(Local::new(arguments.len()));
-    }
+        Some(Local::new(arguments.len()))
+    } else {
+        None
+    };
     debug!("fn_id {:?} has attrs {:?}", fn_def_id, tcx.get_attrs(fn_def_id));
 
     let mut body = builder.finish();
index ce3b1233a74737d94df369fd6caa8ab9c5bad79a..77d6e4560ab9374960233e5dc814a713cfa92476 100644 (file)
@@ -750,14 +750,16 @@ fn build_reduced_graph_for_item(&mut self, item: &'b Item) {
                 // If this is a tuple or unit struct, define a name
                 // in the value namespace as well.
                 if let Some(ctor_node_id) = vdata.ctor_id() {
-                    let mut ctor_vis = vis;
                     // If the structure is marked as non_exhaustive then lower the visibility
                     // to within the crate.
-                    if vis == ty::Visibility::Public
+                    let mut ctor_vis = if vis == ty::Visibility::Public
                         && attr::contains_name(&item.attrs, sym::non_exhaustive)
                     {
-                        ctor_vis = ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX));
-                    }
+                        ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX))
+                    } else {
+                        vis
+                    };
+
                     for field in vdata.fields() {
                         // NOTE: The field may be an expansion placeholder, but expansion sets
                         // correct visibilities for unnamed field placeholders specifically, so the
@@ -1166,7 +1168,7 @@ fn $visit(&mut self, node: &'b $ty) {
                 visit::$walk(self, node);
             }
         }
-    }
+    };
 }
 
 impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {