mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Rollup merge of #151172 - estebank:default-field-values, r=dianne
Use default field values in a few more cases Makes the use expressions significantly shorter.
This commit is contained in:
@@ -2309,12 +2309,12 @@ struct ExprFinder<'hir> {
|
||||
tcx: TyCtxt<'hir>,
|
||||
issue_span: Span,
|
||||
expr_span: Span,
|
||||
body_expr: Option<&'hir hir::Expr<'hir>>,
|
||||
loop_bind: Option<&'hir Ident>,
|
||||
loop_span: Option<Span>,
|
||||
head_span: Option<Span>,
|
||||
pat_span: Option<Span>,
|
||||
head: Option<&'hir hir::Expr<'hir>>,
|
||||
body_expr: Option<&'hir hir::Expr<'hir>> = None,
|
||||
loop_bind: Option<&'hir Ident> = None,
|
||||
loop_span: Option<Span> = None,
|
||||
head_span: Option<Span> = None,
|
||||
pat_span: Option<Span> = None,
|
||||
head: Option<&'hir hir::Expr<'hir>> = None,
|
||||
}
|
||||
impl<'hir> Visitor<'hir> for ExprFinder<'hir> {
|
||||
fn visit_expr(&mut self, ex: &'hir hir::Expr<'hir>) {
|
||||
@@ -2380,17 +2380,7 @@ fn visit_expr(&mut self, ex: &'hir hir::Expr<'hir>) {
|
||||
hir::intravisit::walk_expr(self, ex);
|
||||
}
|
||||
}
|
||||
let mut finder = ExprFinder {
|
||||
tcx,
|
||||
expr_span: span,
|
||||
issue_span,
|
||||
loop_bind: None,
|
||||
body_expr: None,
|
||||
head_span: None,
|
||||
loop_span: None,
|
||||
pat_span: None,
|
||||
head: None,
|
||||
};
|
||||
let mut finder = ExprFinder { tcx, expr_span: span, issue_span, .. };
|
||||
finder.visit_expr(tcx.hir_body(body_id).value);
|
||||
|
||||
if let Some(body_expr) = finder.body_expr
|
||||
@@ -2625,13 +2615,13 @@ fn suggest_binding_for_closure_capture_self(
|
||||
|
||||
struct ExpressionFinder<'tcx> {
|
||||
capture_span: Span,
|
||||
closure_change_spans: Vec<Span>,
|
||||
closure_arg_span: Option<Span>,
|
||||
in_closure: bool,
|
||||
suggest_arg: String,
|
||||
closure_change_spans: Vec<Span> = vec![],
|
||||
closure_arg_span: Option<Span> = None,
|
||||
in_closure: bool = false,
|
||||
suggest_arg: String = String::new(),
|
||||
tcx: TyCtxt<'tcx>,
|
||||
closure_local_id: Option<hir::HirId>,
|
||||
closure_call_changes: Vec<(Span, String)>,
|
||||
closure_local_id: Option<hir::HirId> = None,
|
||||
closure_call_changes: Vec<(Span, String)> = vec![],
|
||||
}
|
||||
impl<'hir> Visitor<'hir> for ExpressionFinder<'hir> {
|
||||
fn visit_expr(&mut self, e: &'hir hir::Expr<'hir>) {
|
||||
@@ -2712,16 +2702,8 @@ fn visit_stmt(&mut self, s: &'hir hir::Stmt<'hir>) {
|
||||
}) = self.infcx.tcx.hir_node(self.mir_hir_id())
|
||||
&& let hir::Node::Expr(expr) = self.infcx.tcx.hir_node(body_id.hir_id)
|
||||
{
|
||||
let mut finder = ExpressionFinder {
|
||||
capture_span: *capture_kind_span,
|
||||
closure_change_spans: vec![],
|
||||
closure_arg_span: None,
|
||||
in_closure: false,
|
||||
suggest_arg: String::new(),
|
||||
closure_local_id: None,
|
||||
closure_call_changes: vec![],
|
||||
tcx: self.infcx.tcx,
|
||||
};
|
||||
let mut finder =
|
||||
ExpressionFinder { capture_span: *capture_kind_span, tcx: self.infcx.tcx, .. };
|
||||
finder.visit_expr(expr);
|
||||
|
||||
if finder.closure_change_spans.is_empty() || finder.closure_call_changes.is_empty() {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#![allow(internal_features)]
|
||||
#![feature(assert_matches)]
|
||||
#![feature(box_patterns)]
|
||||
#![feature(default_field_values)]
|
||||
#![feature(file_buffered)]
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(negative_impls)]
|
||||
|
||||
@@ -51,12 +51,12 @@ pub(super) fn diagnostic_hir_wf_check<'tcx>(
|
||||
struct HirWfCheck<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
predicate: ty::Predicate<'tcx>,
|
||||
cause: Option<ObligationCause<'tcx>>,
|
||||
cause_depth: usize,
|
||||
cause: Option<ObligationCause<'tcx>> = None,
|
||||
cause_depth: usize = 0,
|
||||
icx: ItemCtxt<'tcx>,
|
||||
def_id: LocalDefId,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
depth: usize,
|
||||
depth: usize = 0,
|
||||
}
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for HirWfCheck<'tcx> {
|
||||
@@ -124,16 +124,8 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx, AmbigArg>) {
|
||||
}
|
||||
}
|
||||
|
||||
let mut visitor = HirWfCheck {
|
||||
tcx,
|
||||
predicate,
|
||||
cause: None,
|
||||
cause_depth: 0,
|
||||
icx,
|
||||
def_id,
|
||||
param_env: tcx.param_env(def_id.to_def_id()),
|
||||
depth: 0,
|
||||
};
|
||||
let param_env = tcx.param_env(def_id.to_def_id());
|
||||
let mut visitor = HirWfCheck { tcx, predicate, icx, def_id, param_env, .. };
|
||||
|
||||
// Get the starting `hir::Ty` using our `WellFormedLoc`.
|
||||
// We will walk 'into' this type to try to find
|
||||
|
||||
@@ -57,6 +57,7 @@
|
||||
|
||||
// tidy-alphabetical-start
|
||||
#![feature(assert_matches)]
|
||||
#![feature(default_field_values)]
|
||||
#![feature(gen_blocks)]
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(iter_intersperse)]
|
||||
|
||||
Reference in New Issue
Block a user