Skip to content

Commit 7c0479b

Browse files
committed
Use and_then instead of unwrap_or_default.
1 parent fc0fb38 commit 7c0479b

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

compiler/rustc_typeck/src/check/method/prelude2021.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
273273
method_name.name
274274
));
275275

276-
let mut self_ty_name = self
277-
.sess()
278-
.source_map()
279-
.span_to_snippet(self_ty_span.find_ancestor_inside(span).unwrap_or_default())
280-
.unwrap_or_else(|_| self_ty.to_string());
276+
let mut self_ty_name = self_ty_span
277+
.find_ancestor_inside(span)
278+
.and_then(|span| self.sess().source_map().span_to_snippet(span).ok())
279+
.unwrap_or_else(|| self_ty.to_string());
281280

282281
// Get the number of generics the self type has (if an Adt) unless we can determine that
283282
// the user has written the self type with generics already which we (naively) do by looking
@@ -385,10 +384,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
385384
Some(probe::AutorefOrPtrAdjustment::ToConstPtr) | None => "",
386385
};
387386

388-
let (expr_text, precise) = if let Ok(expr_text) = self
389-
.sess()
390-
.source_map()
391-
.span_to_snippet(expr.span.find_ancestor_inside(outer).unwrap_or_default())
387+
let (expr_text, precise) = if let Some(expr_text) = expr
388+
.span
389+
.find_ancestor_inside(outer)
390+
.and_then(|span| self.sess().source_map().span_to_snippet(span).ok())
392391
{
393392
(expr_text, true)
394393
} else {

0 commit comments

Comments
 (0)