Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use and_then instead of unwrap_or_default.
  • Loading branch information
m-ou-se committed Aug 31, 2021
1 parent fc0fb38 commit 7c0479b
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions compiler/rustc_typeck/src/check/method/prelude2021.rs
Expand Up @@ -273,11 +273,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
method_name.name
));

let mut self_ty_name = self
.sess()
.source_map()
.span_to_snippet(self_ty_span.find_ancestor_inside(span).unwrap_or_default())
.unwrap_or_else(|_| self_ty.to_string());
let mut self_ty_name = self_ty_span
.find_ancestor_inside(span)
.and_then(|span| self.sess().source_map().span_to_snippet(span).ok())
.unwrap_or_else(|| self_ty.to_string());

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

let (expr_text, precise) = if let Ok(expr_text) = self
.sess()
.source_map()
.span_to_snippet(expr.span.find_ancestor_inside(outer).unwrap_or_default())
let (expr_text, precise) = if let Some(expr_text) = expr
.span
.find_ancestor_inside(outer)
.and_then(|span| self.sess().source_map().span_to_snippet(span).ok())
{
(expr_text, true)
} else {
Expand Down

0 comments on commit 7c0479b

Please sign in to comment.