Skip to content

Commit 193c725

Browse files
committed
small improvements
1 parent 3e33c84 commit 193c725

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

clippy_lints/src/new_vs_default.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_hir_and_then;
2-
use clippy_utils::source::{indent_of, reindent_multiline, snippet, snippet_with_applicability, trim_span};
2+
use clippy_utils::source::{
3+
indent_of, reindent_multiline, snippet, snippet_opt, snippet_with_applicability, trim_span,
4+
};
35
use clippy_utils::sugg::DiagExt;
46
use clippy_utils::ty::is_unit_struct;
57
use clippy_utils::{is_default_equivalent_call, return_ty};
@@ -182,8 +184,7 @@ impl<'tcx> LateLintPass<'tcx> for NewVsDefault {
182184
// Check if a Default implementation exists for the Self type, regardless of
183185
// generics
184186
let default_type = if let Some(ref impling_types) = self.impling_types
185-
&& let self_def = cx.tcx.type_of(item.owner_id).instantiate_identity().skip_norm_wip()
186-
&& let Some(self_def) = self_def.ty_adt_def()
187+
&& let Some(self_def) = self_ty.ty_adt_def()
187188
&& let Some(self_local_did) = self_def.did().as_local()
188189
{
189190
impling_types
@@ -251,12 +252,12 @@ impl<'tcx> LateLintPass<'tcx> for NewVsDefault {
251252

252253
let additional_where_preds =
253254
snippet_with_applicability(cx, impl_item.generics.where_clause_span, "", &mut app);
254-
let ident = indent_of(cx, generics.where_clause_span).unwrap_or(0);
255+
let indent = indent_of(cx, generics.where_clause_span).unwrap_or(0);
255256
// Remove the leading `where ` keyword
256257
let additional_where_preds =
257258
additional_where_preds.trim_start_matches("where").trim_start();
258259
where_clause_sugg.push('\n');
259-
where_clause_sugg.extend(std::iter::repeat_n(' ', ident));
260+
where_clause_sugg.extend(std::iter::repeat_n(' ', indent));
260261
where_clause_sugg.push_str(additional_where_preds);
261262
}
262263
format!("\n{where_clause_sugg}\n")
@@ -268,8 +269,7 @@ impl<'tcx> LateLintPass<'tcx> for NewVsDefault {
268269
} else {
269270
String::new()
270271
};
271-
let self_ty_fmt = self_ty.to_string();
272-
let self_type_snip = snippet_with_applicability(cx, impl_self_ty.span, &self_ty_fmt, &mut app);
272+
let self_type_snip = snippet_opt(cx, impl_self_ty.span).unwrap_or_else(|| self_ty.to_string());
273273
span_lint_hir_and_then(
274274
cx,
275275
NEW_WITHOUT_DEFAULT,
@@ -324,8 +324,8 @@ fn block_span_unless_only_default(cx: &LateContext<'_>, block: &hir::Block<'_>)
324324
// Block only has a trailing expression, e.g. `Self::default()`
325325
return None;
326326
}
327-
if let [hir::Stmt { kind, .. }] = block.stmts
328-
&& let StmtKind::Expr(expr) | StmtKind::Semi(expr) = kind
327+
if let [stmt] = block.stmts
328+
&& let StmtKind::Expr(expr) | StmtKind::Semi(expr) = stmt.kind
329329
&& let ExprKind::Ret(Some(ret_expr)) = expr.kind
330330
&& expr_calls_default(cx, ret_expr)
331331
{

0 commit comments

Comments
 (0)