diff options
| author | Léo Lanteri Thauvin <leseulartichaut@gmail.com> | 2021-08-16 17:29:49 +0200 |
|---|---|---|
| committer | Léo Lanteri Thauvin <leseulartichaut@gmail.com> | 2021-08-25 20:24:35 +0200 |
| commit | fde1b76b4b1d0d84f5691f4785906b31bb91f38d (patch) | |
| tree | 966691ff24d8ec26354d737e549bbfccaa658f3d /compiler/rustc_save_analysis/src | |
| parent | a992a11913b39a258158646bb1e03528c5aa5060 (diff) | |
| download | rust-fde1b76b4b1d0d84f5691f4785906b31bb91f38d.tar.gz rust-fde1b76b4b1d0d84f5691f4785906b31bb91f38d.zip | |
Use if-let guards in the codebase
Diffstat (limited to 'compiler/rustc_save_analysis/src')
| -rw-r--r-- | compiler/rustc_save_analysis/src/lib.rs | 89 |
1 files changed, 45 insertions, 44 deletions
diff --git a/compiler/rustc_save_analysis/src/lib.rs b/compiler/rustc_save_analysis/src/lib.rs index 0a8a88132e3..41d174cde0a 100644 --- a/compiler/rustc_save_analysis/src/lib.rs +++ b/compiler/rustc_save_analysis/src/lib.rs @@ -1,5 +1,7 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] +#![feature(if_let_guard)] #![feature(nll)] +#![cfg_attr(bootstrap, allow(incomplete_features))] // if_let_guard #![recursion_limit = "256"] mod dump_visitor; @@ -326,54 +328,53 @@ impl<'tcx> SaveContext<'tcx> { attributes: lower_attributes(attrs.to_vec(), self), })) } - hir::ItemKind::Impl(hir::Impl { ref of_trait, ref self_ty, ref items, .. }) => { - if let hir::TyKind::Path(hir::QPath::Resolved(_, ref path)) = self_ty.kind { - // Common case impl for a struct or something basic. - if generated_code(path.span) { - return None; - } - let sub_span = path.segments.last().unwrap().ident.span; - filter!(self.span_utils, sub_span); + hir::ItemKind::Impl(hir::Impl { ref of_trait, ref self_ty, ref items, .. }) + if let hir::TyKind::Path(hir::QPath::Resolved(_, ref path)) = self_ty.kind => + { + // Common case impl for a struct or something basic. + if generated_code(path.span) { + return None; + } + let sub_span = path.segments.last().unwrap().ident.span; + filter!(self.span_utils, sub_span); - let impl_id = self.next_impl_id(); - let span = self.span_from_span(sub_span); + let impl_id = self.next_impl_id(); + let span = self.span_from_span(sub_span); - let type_data = self.lookup_def_id(self_ty.hir_id); - type_data.map(|type_data| { - Data::RelationData( - Relation { - kind: RelationKind::Impl { id: impl_id }, - span: span.clone(), - from: id_from_def_id(type_data), - to: of_trait - .as_ref() - .and_then(|t| self.lookup_def_id(t.hir_ref_id)) - .map(id_from_def_id) - .unwrap_or_else(null_id), - }, - Impl { - id: impl_id, - kind: match *of_trait { - Some(_) => ImplKind::Direct, - None => ImplKind::Inherent, - }, - span, - value: String::new(), - parent: None, - children: items - .iter() - .map(|i| id_from_def_id(i.id.def_id.to_def_id())) - .collect(), - docs: String::new(), - sig: None, - attributes: vec![], + let type_data = self.lookup_def_id(self_ty.hir_id); + type_data.map(|type_data| { + Data::RelationData( + Relation { + kind: RelationKind::Impl { id: impl_id }, + span: span.clone(), + from: id_from_def_id(type_data), + to: of_trait + .as_ref() + .and_then(|t| self.lookup_def_id(t.hir_ref_id)) + .map(id_from_def_id) + .unwrap_or_else(null_id), + }, + Impl { + id: impl_id, + kind: match *of_trait { + Some(_) => ImplKind::Direct, + None => ImplKind::Inherent, }, - ) - }) - } else { - None - } + span, + value: String::new(), + parent: None, + children: items + .iter() + .map(|i| id_from_def_id(i.id.def_id.to_def_id())) + .collect(), + docs: String::new(), + sig: None, + attributes: vec![], + }, + ) + }) } + hir::ItemKind::Impl(_) => None, _ => { // FIXME bug!(); |
