summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-12-03 19:01:42 -0800
committerEsteban Küber <esteban@kuber.com.ar>2019-12-03 19:01:42 -0800
commitf6b435d923e5979cd3579427901d2140a932dfc0 (patch)
tree01dcd96d45f6bd4822ca60fc07ea2399571d1ccf
parentAuto merge of #66997 - Centril:rollup-uraqpgu, r=Centril (diff)
downloadrust-f6b435d923e5979cd3579427901d2140a932dfc0.tar.gz
rust-f6b435d923e5979cd3579427901d2140a932dfc0.tar.bz2
rust-f6b435d923e5979cd3579427901d2140a932dfc0.tar.xz
Accurately portray raw identifiers in error messages
When refering to or suggesting raw identifiers, refer to them with `r#`. Fix #65634.
-rw-r--r--src/librustc/ty/print/pretty.rs3
-rw-r--r--src/libsyntax_pos/symbol.rs6
-rw-r--r--src/test/ui/parser/raw/raw-literal-keywords.rs4
-rw-r--r--src/test/ui/parser/raw/raw-literal-keywords.stderr4
-rw-r--r--src/test/ui/raw-ident-suggestion.rs22
-rw-r--r--src/test/ui/raw-ident-suggestion.stderr22
-rw-r--r--src/test/ui/suggestions/raw-name-use-suggestion.rs2
-rw-r--r--src/test/ui/suggestions/raw-name-use-suggestion.stderr2
8 files changed, 59 insertions, 6 deletions
diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs
index fff2f06..745f7d0 100644
--- a/src/librustc/ty/print/pretty.rs
+++ b/src/librustc/ty/print/pretty.rs
@@ -1282,6 +1282,9 @@ impl<F: fmt::Write> Printer<'tcx> for FmtPrinter<'_, 'tcx, F> {
1282 if !self.empty_path { 1282 if !self.empty_path {
1283 write!(self, "::")?; 1283 write!(self, "::")?;
1284 } 1284 }
1285 if ast::Ident::from_str(&name).is_raw_guess() {
1286 write!(self, "r#")?;
1287 }
1285 write!(self, "{}", name)?; 1288 write!(self, "{}", name)?;
1286 1289
1287 // FIXME(eddyb) this will print e.g. `{{closure}}#3`, but it 1290 // FIXME(eddyb) this will print e.g. `{{closure}}#3`, but it
diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs
index 88a3251..73df24a 100644
--- a/src/libsyntax_pos/symbol.rs
+++ b/src/libsyntax_pos/symbol.rs
@@ -840,12 +840,18 @@ impl Hash for Ident {
840 840
841impl fmt::Debug for Ident { 841impl fmt::Debug for Ident {
842 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 842 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
843 if self.is_raw_guess() {
844 write!(f, "r#")?;
845 }
843 write!(f, "{}{:?}", self.name, self.span.ctxt()) 846 write!(f, "{}{:?}", self.name, self.span.ctxt())
844 } 847 }
845} 848}
846 849
847impl fmt::Display for Ident { 850impl fmt::Display for Ident {
848 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 851 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
852 if self.is_raw_guess() {
853 write!(f, "r#")?;
854 }
849 fmt::Display::fmt(&self.name, f) 855 fmt::Display::fmt(&self.name, f)
850 } 856 }
851} 857}
diff --git a/src/test/ui/parser/raw/raw-literal-keywords.rs b/src/test/ui/parser/raw/raw-literal-keywords.rs
index bf9cbcd..a986980 100644
--- a/src/test/ui/parser/raw/raw-literal-keywords.rs
+++ b/src/test/ui/parser/raw/raw-literal-keywords.rs
@@ -11,11 +11,11 @@ fn test_union() {
11} 11}
12 12
13fn test_if_2() { 13fn test_if_2() {
14 let _ = r#if; //~ ERROR cannot find value `if` in this scope 14 let _ = r#if; //~ ERROR cannot find value `r#if` in this scope
15} 15}
16 16
17fn test_struct_2() { 17fn test_struct_2() {
18 let _ = r#struct; //~ ERROR cannot find value `struct` in this scope 18 let _ = r#struct; //~ ERROR cannot find value `r#struct` in this scope
19} 19}
20 20
21fn test_union_2() { 21fn test_union_2() {
diff --git a/src/test/ui/parser/raw/raw-literal-keywords.stderr b/src/test/ui/parser/raw/raw-literal-keywords.stderr
index fd8eda3..f7b6c89 100644
--- a/src/test/ui/parser/raw/raw-literal-keywords.stderr
+++ b/src/test/ui/parser/raw/raw-literal-keywords.stderr
@@ -16,13 +16,13 @@ error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found
16LL | r#union Test; 16LL | r#union Test;
17 | ^^^^ expected one of 8 possible tokens 17 | ^^^^ expected one of 8 possible tokens
18 18
19error[E0425]: cannot find value `if` in this scope 19error[E0425]: cannot find value `r#if` in this scope
20 --> $DIR/raw-literal-keywords.rs:14:13 20 --> $DIR/raw-literal-keywords.rs:14:13
21 | 21 |
22LL | let _ = r#if; 22LL | let _ = r#if;
23 | ^^^^ not found in this scope 23 | ^^^^ not found in this scope
24 24
25error[E0425]: cannot find value `struct` in this scope 25error[E0425]: cannot find value `r#struct` in this scope
26 --> $DIR/raw-literal-keywords.rs:18:13 26 --> $DIR/raw-literal-keywords.rs:18:13
27 | 27 |
28LL | let _ = r#struct; 28LL | let _ = r#struct;
diff --git a/src/test/ui/raw-ident-suggestion.rs b/src/test/ui/raw-ident-suggestion.rs
new file mode 100644
index 0000000..b928510
--- /dev/null
+++ b/src/test/ui/raw-ident-suggestion.rs
@@ -0,0 +1,22 @@
1#![allow(non_camel_case_types)]
2
3trait r#async {
4 fn r#struct(&self) {
5 println!("async");
6 }
7}
8
9trait r#await {
10 fn r#struct(&self) {
11 println!("await");
12 }
13}
14
15struct r#fn {}
16
17impl r#async for r#fn {}
18impl r#await for r#fn {}
19
20fn main() {
21 r#fn {}.r#struct(); //~ ERROR multiple applicable items in scope
22}
diff --git a/src/test/ui/raw-ident-suggestion.stderr b/src/test/ui/raw-ident-suggestion.stderr
new file mode 100644
index 0000000..fddd942
--- /dev/null
+++ b/src/test/ui/raw-ident-suggestion.stderr
@@ -0,0 +1,22 @@
1error[E0034]: multiple applicable items in scope
2 --> $DIR/raw-ident-suggestion.rs:21:13
3 |
4LL | r#fn {}.r#struct();
5 | ^^^^^^^^ multiple `r#struct` found
6 |
7note: candidate #1 is defined in an impl of the trait `async` for the type `r#fn`
8 --> $DIR/raw-ident-suggestion.rs:4:5
9 |
10LL | fn r#struct(&self) {
11 | ^^^^^^^^^^^^^^^^^^
12 = help: to disambiguate the method call, write `async::r#struct(r#fn {})` instead
13note: candidate #2 is defined in an impl of the trait `await` for the type `r#fn`
14 --> $DIR/raw-ident-suggestion.rs:10:5
15 |
16LL | fn r#struct(&self) {
17 | ^^^^^^^^^^^^^^^^^^
18 = help: to disambiguate the method call, write `await::r#struct(r#fn {})` instead
19
20error: aborting due to previous error
21
22For more information about this error, try `rustc --explain E0034`.
diff --git a/src/test/ui/suggestions/raw-name-use-suggestion.rs b/src/test/ui/suggestions/raw-name-use-suggestion.rs
index 6c01383..0a8073c 100644
--- a/src/test/ui/suggestions/raw-name-use-suggestion.rs
+++ b/src/test/ui/suggestions/raw-name-use-suggestion.rs
@@ -5,5 +5,5 @@ mod foo {
5 5
6fn main() { 6fn main() {
7 foo::let(); //~ ERROR expected identifier, found keyword `let` 7 foo::let(); //~ ERROR expected identifier, found keyword `let`
8 r#break(); //~ ERROR cannot find function `break` in this scope 8 r#break(); //~ ERROR cannot find function `r#break` in this scope
9} 9}
diff --git a/src/test/ui/suggestions/raw-name-use-suggestion.stderr b/src/test/ui/suggestions/raw-name-use-suggestion.stderr
index 58eb87c..62b7631 100644
--- a/src/test/ui/suggestions/raw-name-use-suggestion.stderr
+++ b/src/test/ui/suggestions/raw-name-use-suggestion.stderr
@@ -20,7 +20,7 @@ help: you can escape reserved keywords to use them as identifiers
20LL | foo::r#let(); 20LL | foo::r#let();
21 | ^^^^^ 21 | ^^^^^
22 22
23error[E0425]: cannot find function `break` in this scope 23error[E0425]: cannot find function `r#break` in this scope
24 --> $DIR/raw-name-use-suggestion.rs:8:5 24 --> $DIR/raw-name-use-suggestion.rs:8:5
25 | 25 |
26LL | r#break(); 26LL | r#break();