let (sp, suggestion) = receiver
.and_then(|s| tcx.sess.source_map().span_to_snippet(s).ok())
.filter(|snippet| !snippet.is_empty())
- .map(|snippet| (expr_span, format!("drop({})", snippet)))
+ .map(|snippet| (expr_span, format!("drop({snippet})")))
.unwrap_or_else(|| (span, "drop".to_string()));
err.span_suggestion(
enum CallStep<'tcx> {
Builtin(Ty<'tcx>),
- DeferredClosure(ty::FnSig<'tcx>),
+ DeferredClosure(DefId, ty::FnSig<'tcx>),
/// E.g., enum variant constructors.
Overloaded(MethodCallee<'tcx>),
}
self.confirm_builtin_call(call_expr, callee_expr, callee_ty, arg_exprs, expected)
}
- Some(CallStep::DeferredClosure(fn_sig)) => {
- self.confirm_deferred_closure_call(call_expr, arg_exprs, expected, fn_sig)
+ Some(CallStep::DeferredClosure(def_id, fn_sig)) => {
+ self.confirm_deferred_closure_call(call_expr, arg_exprs, expected, def_id, fn_sig)
}
Some(CallStep::Overloaded(method_callee)) => {
closure_substs: substs,
},
);
- return Some(CallStep::DeferredClosure(closure_sig));
+ return Some(CallStep::DeferredClosure(def_id, closure_sig));
}
}
hir::ExprKind::Tup(exp),
hir::ExprKind::Call(_, args),
) = (parent_node, &callee_expr.kind, &call_expr.kind)
+ && args.len() == exp.len()
{
- if args.len() == exp.len() {
- let start = callee_expr.span.shrink_to_hi();
- err.span_suggestion(
- start,
- "consider separating array elements with a comma",
- ",".to_string(),
- Applicability::MaybeIncorrect,
- );
- return true;
- }
+ let start = callee_expr.span.shrink_to_hi();
+ err.span_suggestion(
+ start,
+ "consider separating array elements with a comma",
+ ",".to_string(),
+ Applicability::MaybeIncorrect,
+ );
+ return true;
}
false
}
) -> Ty<'tcx> {
let (fn_sig, def_id) = match *callee_ty.kind() {
ty::FnDef(def_id, subst) => {
- let fn_sig = self.tcx.fn_sig(def_id).subst(self.tcx, subst);
+ let fn_sig = self.tcx.bound_fn_sig(def_id).subst(self.tcx, subst);
// Unit testing: function items annotated with
// `#[rustc_evaluate_where_clauses]` trigger special output
ref t => {
let mut unit_variant = None;
let mut removal_span = call_expr.span;
- if let ty::Adt(adt_def, ..) = t {
- if adt_def.is_enum() {
- if let hir::ExprKind::Call(expr, _) = call_expr.kind {
- removal_span =
- expr.span.shrink_to_hi().to(call_expr.span.shrink_to_hi());
- unit_variant =
- self.tcx.sess.source_map().span_to_snippet(expr.span).ok();
- }
- }
+ if let ty::Adt(adt_def, ..) = t
+ && adt_def.is_enum()
+ && let hir::ExprKind::Call(expr, _) = call_expr.kind
+ {
+ removal_span =
+ expr.span.shrink_to_hi().to(call_expr.span.shrink_to_hi());
+ unit_variant =
+ self.tcx.sess.source_map().span_to_snippet(expr.span).ok();
}
let callee_ty = self.resolve_vars_if_possible(callee_ty);
E0618,
"expected function, found {}",
match unit_variant {
- Some(ref path) => format!("enum variant `{}`", path),
- None => format!("`{}`", callee_ty),
+ Some(ref path) => format!("enum variant `{path}`"),
+ None => format!("`{callee_ty}`"),
}
);
err.span_suggestion_verbose(
removal_span,
&format!(
- "`{}` is a unit variant, you need to write it without the parentheses",
- path
+ "`{path}` is a unit variant, you need to write it without the parentheses",
),
String::new(),
Applicability::MachineApplicable,
if let Some(span) = self.tcx.hir().res_span(def) {
let callee_ty = callee_ty.to_string();
let label = match (unit_variant, inner_callee_path) {
- (Some(path), _) => Some(format!("`{}` defined here", path)),
+ (Some(path), _) => Some(format!("`{path}` defined here")),
(_, Some(hir::QPath::Resolved(_, path))) => self
.tcx
.sess
.source_map()
.span_to_snippet(path.span)
.ok()
- .map(|p| format!("`{}` defined here returns `{}`", p, callee_ty)),
+ .map(|p| format!("`{p}` defined here returns `{callee_ty}`")),
_ => {
match def {
// Emit a different diagnostic for local variables, as they are not
self.tcx.def_path_str(def_id),
))
}
- _ => Some(format!("`{}` defined here", callee_ty)),
+ _ => Some(format!("`{callee_ty}` defined here")),
}
}
};
call_expr: &'tcx hir::Expr<'tcx>,
arg_exprs: &'tcx [hir::Expr<'tcx>],
expected: Expectation<'tcx>,
+ closure_def_id: DefId,
fn_sig: ty::FnSig<'tcx>,
) -> Ty<'tcx> {
// `fn_sig` is the *signature* of the closure being called. We
arg_exprs,
fn_sig.c_variadic,
TupleArgumentsFlag::TupleArguments,
- None,
+ Some(closure_def_id),
);
fn_sig.output()