|
1 | 1 | // Characters and their corresponding confusables were collected from
|
2 | 2 | // http://www.unicode.org/Public/security/10.0.0/confusables.txt
|
3 | 3 |
|
4 |
| -use syntax_pos::{Span, NO_EXPANSION}; |
| 4 | +use syntax_pos::{Span, Pos, NO_EXPANSION}; |
5 | 5 | use errors::{Applicability, DiagnosticBuilder};
|
6 | 6 | use super::StringReader;
|
7 | 7 |
|
@@ -333,14 +333,27 @@ crate fn check_for_substitution<'a>(reader: &StringReader<'a>,
|
333 | 333 | let span = Span::new(reader.pos, reader.next_pos, NO_EXPANSION);
|
334 | 334 | match ASCII_ARRAY.iter().find(|&&(c, _)| c == ascii_char) {
|
335 | 335 | Some(&(ascii_char, ascii_name)) => {
|
336 |
| - let msg = |
337 |
| - format!("Unicode character '{}' ({}) looks like '{}' ({}), but it is not", |
338 |
| - ch, u_name, ascii_char, ascii_name); |
339 |
| - err.span_suggestion( |
340 |
| - span, |
341 |
| - &msg, |
342 |
| - ascii_char.to_string(), |
343 |
| - Applicability::MaybeIncorrect); |
| 336 | + // special help suggestion for "directed" double quotes |
| 337 | + if let Some(s) = reader.peek_delimited('“', '”') { |
| 338 | + let msg = format!("Unicode characters '“' (Left Double Quotation Mark) and \ |
| 339 | + '”' (Right Double Quotation Mark) look like '{}' ({}), but are not", |
| 340 | + ascii_char, ascii_name); |
| 341 | + err.span_suggestion( |
| 342 | + Span::new(reader.pos, reader.next_pos + Pos::from_usize(s.len()) + |
| 343 | + Pos::from_usize('”'.len_utf8()), NO_EXPANSION), |
| 344 | + &msg, |
| 345 | + format!("\"{}\"", s), |
| 346 | + Applicability::MaybeIncorrect); |
| 347 | + } else { |
| 348 | + let msg = |
| 349 | + format!("Unicode character '{}' ({}) looks like '{}' ({}), but it is not", |
| 350 | + ch, u_name, ascii_char, ascii_name); |
| 351 | + err.span_suggestion( |
| 352 | + span, |
| 353 | + &msg, |
| 354 | + ascii_char.to_string(), |
| 355 | + Applicability::MaybeIncorrect); |
| 356 | + } |
344 | 357 | true
|
345 | 358 | },
|
346 | 359 | None => {
|
|
0 commit comments