TypeError::Sorts(ref exp_found) => {
// if they are both "path types", there's a chance of ambiguity
// due to different versions of the same crate
- match (&exp_found.expected.sty, &exp_found.found.sty) {
- (&ty::Adt(exp_adt, _), &ty::Adt(found_adt, _)) => {
- report_path_match(err, exp_adt.did, found_adt.did);
- }
- _ => (),
+ if let (&ty::Adt(exp_adt, _), &ty::Adt(found_adt, _))
+ = (&exp_found.expected.sty, &exp_found.found.sty)
+ {
+ report_path_match(err, exp_adt.did, found_adt.did);
}
}
TypeError::Traits(ref exp_found) => {
&RegionKind::ReFree(ref free_region)) = (&sub_origin, sup_region) {
let hir = &self.tcx.hir;
if let Some(node_id) = hir.as_local_node_id(free_region.scope) {
- match hir.get(node_id) {
- Node::Expr(Expr {
- node: Closure(_, _, _, closure_span, None),
- ..
- }) => {
- let sup_sp = sup_origin.span();
- let origin_sp = origin.span();
- let mut err = self.tcx.sess.struct_span_err(
- sup_sp,
- "borrowed data cannot be stored outside of its closure");
- err.span_label(sup_sp, "cannot be stored outside of its closure");
- if origin_sp == sup_sp || origin_sp.contains(sup_sp) {
+ if let Node::Expr(Expr {
+ node: Closure(_, _, _, closure_span, None),
+ ..
+ }) = hir.get(node_id) {
+ let sup_sp = sup_origin.span();
+ let origin_sp = origin.span();
+ let mut err = self.tcx.sess.struct_span_err(
+ sup_sp,
+ "borrowed data cannot be stored outside of its closure");
+ err.span_label(sup_sp, "cannot be stored outside of its closure");
+ if origin_sp == sup_sp || origin_sp.contains(sup_sp) {
// // sup_sp == origin.span():
//
// let mut x = None;
// ------------ ... because it cannot outlive this closure
// f = Some(x);
// ^ cannot be stored outside of its closure
- err.span_label(*external_span,
- "borrowed data cannot be stored into here...");
- err.span_label(*closure_span,
- "...because it cannot outlive this closure");
- } else {
+ err.span_label(*external_span,
+ "borrowed data cannot be stored into here...");
+ err.span_label(*closure_span,
+ "...because it cannot outlive this closure");
+ } else {
// FIXME: the wording for this case could be much improved
//
// let mut lines_to_use: Vec<&CrateId> = Vec::new();
// ...so that variable is valid at time of its declaration
// lines_to_use.push(installed_id);
// ^^^^^^^^^^^^ cannot be stored outside of its closure
- err.span_label(origin_sp,
- "cannot infer an appropriate lifetime...");
- err.span_label(*external_span,
- "...so that variable is valid at time of its \
- declaration");
- err.span_label(*closure_span,
- "borrowed data cannot outlive this closure");
- }
- err.emit();
- return Some(ErrorReported);
+ err.span_label(origin_sp,
+ "cannot infer an appropriate lifetime...");
+ err.span_label(*external_span,
+ "...so that variable is valid at time of its \
+ declaration");
+ err.span_label(*closure_span,
+ "borrowed data cannot outlive this closure");
}
- _ => {}
+ err.emit();
+ return Some(ErrorReported);
}
}
}
/// Print the error message for lifetime errors when the return type is a static impl Trait.
pub(super) fn try_report_static_impl_trait(&self) -> Option<ErrorReported> {
if let Some(ref error) = self.error {
- match error.clone() {
- RegionResolutionError::SubSupConflict(
+ if let RegionResolutionError::SubSupConflict(
var_origin,
sub_origin,
sub_r,
sup_origin,
sup_r,
- ) => {
- let anon_reg_sup = self.tcx.is_suitable_region(sup_r)?;
- if sub_r == &RegionKind::ReStatic &&
- self.tcx.return_type_impl_trait(anon_reg_sup.def_id).is_some()
- {
- let sp = var_origin.span();
- let return_sp = sub_origin.span();
- let mut err = self.tcx.sess.struct_span_err(
- sp,
- "cannot infer an appropriate lifetime",
+ ) = error.clone()
+ {
+ let anon_reg_sup = self.tcx.is_suitable_region(sup_r)?;
+ if sub_r == &RegionKind::ReStatic &&
+ self.tcx.return_type_impl_trait(anon_reg_sup.def_id).is_some()
+ {
+ let sp = var_origin.span();
+ let return_sp = sub_origin.span();
+ let mut err = self.tcx.sess.struct_span_err(
+ sp,
+ "cannot infer an appropriate lifetime",
+ );
+ err.span_label(
+ return_sp,
+ "this return type evaluates to the `'static` lifetime...",
+ );
+ err.span_label(
+ sup_origin.span(),
+ "...but this borrow...",
+ );
+
+ let (lifetime, lt_sp_opt) = self.tcx.msg_span_from_free_region(sup_r);
+ if let Some(lifetime_sp) = lt_sp_opt {
+ err.span_note(
+ lifetime_sp,
+ &format!("...can't outlive {}", lifetime),
);
- err.span_label(
+ }
+
+ let lifetime_name = match sup_r {
+ RegionKind::ReFree(FreeRegion {
+ bound_region: BoundRegion::BrNamed(_, ref name), ..
+ }) => name.to_string(),
+ _ => "'_".to_owned(),
+ };
+ if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(return_sp) {
+ err.span_suggestion_with_applicability(
return_sp,
- "this return type evaluates to the `'static` lifetime...",
+ &format!(
+ "you can add a constraint to the return type to make it last \
+ less than `'static` and match {}",
+ lifetime,
+ ),
+ format!("{} + {}", snippet, lifetime_name),
+ Applicability::Unspecified,
);
- err.span_label(
- sup_origin.span(),
- "...but this borrow...",
- );
-
- let (lifetime, lt_sp_opt) = self.tcx.msg_span_from_free_region(sup_r);
- if let Some(lifetime_sp) = lt_sp_opt {
- err.span_note(
- lifetime_sp,
- &format!("...can't outlive {}", lifetime),
- );
- }
-
- let lifetime_name = match sup_r {
- RegionKind::ReFree(FreeRegion {
- bound_region: BoundRegion::BrNamed(_, ref name), ..
- }) => name.to_string(),
- _ => "'_".to_owned(),
- };
- if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(return_sp) {
- err.span_suggestion_with_applicability(
- return_sp,
- &format!(
- "you can add a constraint to the return type to make it last \
- less than `'static` and match {}",
- lifetime,
- ),
- format!("{} + {}", snippet, lifetime_name),
- Applicability::Unspecified,
- );
- }
- err.emit();
- return Some(ErrorReported);
}
+ err.emit();
+ return Some(ErrorReported);
}
- _ => {}
}
}
None
decl: &hir::FnDecl,
) -> Option<Span> {
let ret_ty = self.tcx.type_of(scope_def_id);
- match ret_ty.sty {
- ty::FnDef(_, _) => {
- let sig = ret_ty.fn_sig(self.tcx);
- let late_bound_regions = self.tcx
- .collect_referenced_late_bound_regions(&sig.output());
- if late_bound_regions.iter().any(|r| *r == br) {
- return Some(decl.output.span());
- }
+ if let ty::FnDef(_, _) = ret_ty.sty {
+ let sig = ret_ty.fn_sig(self.tcx);
+ let late_bound_regions = self.tcx
+ .collect_referenced_late_bound_regions(&sig.output());
+ if late_bound_regions.iter().any(|r| *r == br) {
+ return Some(decl.output.span());
}
- _ => {}
}
None
}
}
};
- match dump_region_data_to(region_rels, ®ion_data.constraints, &output_path) {
- Ok(()) => {}
- Err(e) => {
- let msg = format!("io error dumping region constraints: {}", e);
- tcx.sess.err(&msg)
- }
+ if let Err(e) = dump_region_data_to(region_rels, ®ion_data.constraints, &output_path) {
+ let msg = format!("io error dumping region constraints: {}", e);
+ tcx.sess.err(&msg)
}
}
debug!("RegionConstraintCollector: add_verify({:?})", verify);
// skip no-op cases known to be satisfied
- match verify.bound {
- VerifyBound::AllBounds(ref bs) if bs.len() == 0 => {
+ if let VerifyBound::AllBounds(ref bs) = verify.bound {
+ if bs.len() == 0 {
return;
}
- _ => {}
}
let index = self.data.verifys.len();
pub fn rollback_to(&mut self, s: Snapshot<'tcx>) {
debug!("rollback_to{:?}", {
for action in self.values.actions_since_snapshot(&s.snapshot) {
- match *action {
- sv::UndoLog::NewElem(index) => {
- debug!("inference variable _#{}t popped", index)
- }
- _ => { }
+ if let sv::UndoLog::NewElem(index) = *action {
+ debug!("inference variable _#{}t popped", index)
}
}
});