remove unwrap

This commit is contained in:
yukang 2023-06-10 10:34:19 +08:00
parent e3071eaa60
commit f54e75730b

View File

@ -756,16 +756,19 @@ pub fn maybe_suggest_struct_literal(
// we expect to suggest `(foo::Bar { ... })` instead of `foo::(Bar { ... })` // we expect to suggest `(foo::Bar { ... })` instead of `foo::(Bar { ... })`
let sm = self.sess.source_map(); let sm = self.sess.source_map();
let before = maybe_struct_name.span.shrink_to_lo(); let before = maybe_struct_name.span.shrink_to_lo();
let extend_before = sm.span_extend_prev_while(before, |t| { if let Ok(extend_before) = sm.span_extend_prev_while(before, |t| {
t.is_alphanumeric() || t == ':' || t == '_' t.is_alphanumeric() || t == ':' || t == '_'
}); }) {
Err(self.sess.create_err(StructLiteralNeedingParens { Err(self.sess.create_err(StructLiteralNeedingParens {
span: maybe_struct_name.span.to(expr.span), span: maybe_struct_name.span.to(expr.span),
sugg: StructLiteralNeedingParensSugg { sugg: StructLiteralNeedingParensSugg {
before: extend_before.unwrap().shrink_to_lo(), before: extend_before.shrink_to_lo(),
after: expr.span.shrink_to_hi(), after: expr.span.shrink_to_hi(),
}, },
})) }))
} else {
return None;
}
} else { } else {
self.sess.emit_err(StructLiteralBodyWithoutPath { self.sess.emit_err(StructLiteralBodyWithoutPath {
span: expr.span, span: expr.span,