Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Lookahead for closing curly quote when encountering opening curly quote #58436

Closed

Description

@estebank

When encountering curly quotes, the compiler now points at the opening one suggesting changing it for a regular straight quote. It should also look ahead looking for a closing curly quote char and suggest changing that one too, because when fixing only the first one, the parser will interpret this as an unclosed string.

fn main() {
    println!(“”);
}
error: unknown start of token: \u{201c}
 --> src/main.rs:2:14
  |
2 |     println!(“”);
  |              ^
help: Unicode character '“' (Left Double Quotation Mark) looks like '"' (Quotation Mark), but it is not
  |
2 |     println!("”);
  |              ^

After applying suggestion:

error: unterminated double quote string
 --> src/main.rs:2:14
  |
2 |       println!("”);
  |  ______________^
3 | | }
  | |_^

Ideally

error: unknown start of token: \u{201c}
 --> src/main.rs:2:14
  |
2 |     println!(“”);
  |              ^-
help: Unicode character '“' (Left Double Quotation Mark) and '”' (Right Double Quotation Mark) look like '"' (Quotation Mark), but it are not
  |
2 |     println!("");
  |              ^^

Activity

  1. added
    C-enhancement
    A-suggestion-diagnostics
    on Feb 13, 2019
  2. pmccarter commented on Feb 13, 2019

    @pmccarter
    Contributor

    I could maybe do this with some mentoring, if not too difficult or trivial...

  3. estebank commented on Feb 13, 2019

    @estebank
    ContributorAuthor

    @pmccarter this method is the one that supplies the error:

    crate fn check_for_substitution<'a>(reader: &StringReader<'a>,
    ch: char,
    err: &mut DiagnosticBuilder<'a>) -> bool {
    UNICODE_ARRAY
    .iter()
    .find(|&&(c, _, _)| c == ch)
    .map(|&(_, u_name, ascii_char)| {
    let span = Span::new(reader.pos, reader.next_pos, NO_EXPANSION);
    match ASCII_ARRAY.iter().find(|&&(c, _)| c == ascii_char) {
    Some(&(ascii_char, ascii_name)) => {
    let msg =
    format!("Unicode character '{}' ({}) looks like '{}' ({}), but it is not",
    ch, u_name, ascii_char, ascii_name);
    err.span_suggestion(
    span,
    &msg,
    ascii_char.to_string(),
    Applicability::MaybeIncorrect);
    true
    },
    None => {
    let msg = format!("substitution character not found for '{}'", ch);
    reader.sess.span_diagnostic.span_bug_no_panic(span, &msg);
    false
    }
    }
    }).unwrap_or(false)
    }

    It gets called from the lexer:

    unicode_chars::check_for_substitution(self, c, &mut err);

    It should be possible to special case the “ char to continue advancing, using self.nextch() I think, until finding a ”, and if found, add that to the diagnostic.

    The Forge has info on setting up the repo and building your own rustc. The workflow is usually running ./x.py test src/test/ui --stage 1 --bless and modifying/creating test files in src/test/ui.

  4. added 4 commits that reference this issue on Feb 23, 2019
    ff11324
    cb48a98
    d6c330d
    18dd2d2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-suggestion-diagnosticsC-enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions