Skip to content

Handle fully enclosed multiline spans gracefully in emitter #61017

Open
@estebank

Description

@estebank

Currently the solution to overlapping multiline spans is correct, but doesn't handle spans that are completely enclosed by others in any way, simply using span ordering and growing towards the left as needed. The following is a representative example of the problem:

error[E0308]: if and else have incompatible types
    --> src/libsyntax/parse/parser.rs:2640:33
     |
2636 |                                 let (span, msg) = if self.token == token::Token::Eof && self.is_subparser {
     |    _______________________________________________-
2637 |   |                                 (self.sess.source_map().next_point(self.span),
     |  _|_________________________________-
2638 | | |                                  "expected expression, found end of macro arguments")
     | |_|_____________________________________________________________________________________- expected because of this
2639 |   |                             } else {
2640 | / |                                 (self.span, format!(
2641 | | |                                     "expected expression, found {}",
2642 | | |                                     self.this_token_descr(),
2643 | | |                                 ))
     | |_|__________________________________^ expected &str, found struct `std::string::String`
2644 |   |                             };
     |   |_____________________________- if and else have incompatible types
     |
     = note: expected type `(syntax_pos::span_encoding::Span, &str)`
                found type `(syntax_pos::span_encoding::Span, std::string::String)`

Ideally, the emitter should handle this case by identifying that there are overlapping spans that are fully enclosed and special case the output to make it easier to read:

error[E0308]: if and else have incompatible types
    --> src/libsyntax/parse/parser.rs:2640:33
     |
2636 |                                let (span, msg) = if self.token == token::Token::Eof && self.is_subparser {
     |  ________________________________________________-
2637 | | /                                (self.sess.source_map().next_point(self.span),
2638 | | |                                 "expected expression, found end of macro arguments")
     | | |____________________________________________________________________________________- expected because of this
2639 | |                              } else {
2640 | | /                                (self.span, format!(
2641 | | |                                    "expected expression, found {}",
2642 | | |                                    self.this_token_descr(),
2643 | | |                                ))
     | | |_________________________________^ expected &str, found struct `std::string::String`
2644 | |                              };
     | |______________________________- if and else have incompatible types
     |
     = note: expected type `(syntax_pos::span_encoding::Span, &str)`
                found type `(syntax_pos::span_encoding::Span, std::string::String)`

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions