Rollup merge of #133843 - estebank:empty-semi-sugg, r=jieyouxu
Do not emit empty suggestion The `println!();` statement's span doesn't include the `;`, and the modified suggestions where trying to get the `;` by getting the differenece between the statement's and the expression's spans, which was an empty suggestion. Fix #133833, fix #133834.
This commit is contained in:
commit
ab16eeba5c
4 changed files with 89 additions and 1 deletions
|
@ -3394,7 +3394,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
let Some(ty) = self.node_ty_opt(tail_expr.hir_id) else {
|
||||
return;
|
||||
};
|
||||
if self.can_eq(self.param_env, expected_ty, ty) {
|
||||
if self.can_eq(self.param_env, expected_ty, ty)
|
||||
// FIXME: this happens with macro calls. Need to figure out why the stmt
|
||||
// `println!();` doesn't include the `;` in its `Span`. (#133845)
|
||||
// We filter these out to avoid ICEs with debug assertions on caused by
|
||||
// empty suggestions.
|
||||
&& stmt.span.hi() != tail_expr.span.hi()
|
||||
{
|
||||
err.span_suggestion_short(
|
||||
stmt.span.with_lo(tail_expr.span.hi()),
|
||||
"remove this semicolon",
|
||||
|
|
|
@ -3838,6 +3838,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
&& self.predicate_must_hold_modulo_regions(&Obligation::misc(
|
||||
tcx, expr.span, body_id, param_env, pred,
|
||||
))
|
||||
&& expr.span.hi() != rcvr.span.hi()
|
||||
{
|
||||
err.span_suggestion_verbose(
|
||||
expr.span.with_lo(rcvr.span.hi()),
|
||||
|
@ -4115,6 +4116,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
// the expected is a projection that we need to resolve.
|
||||
// && let Some(tail_ty) = typeck_results.expr_ty_opt(expr)
|
||||
&& expected_found.found.is_unit()
|
||||
// FIXME: this happens with macro calls. Need to figure out why the stmt
|
||||
// `println!();` doesn't include the `;` in its `Span`. (#133845)
|
||||
// We filter these out to avoid ICEs with debug assertions on caused by
|
||||
// empty suggestions.
|
||||
&& expr.span.hi() != stmt.span.hi()
|
||||
{
|
||||
err.span_suggestion_verbose(
|
||||
expr.span.shrink_to_hi().with_hi(stmt.span.hi()),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue