summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-12-05 19:03:15 +0100
committerGitHub <noreply@github.com>2019-12-05 19:03:15 +0100
commit8e6cf861e5e1b558b6a03dd0eaabc15b37570063 (patch)
treee445f9e8705333bba11b133a94b1c077c89536db
parentRollup merge of #67005 - andrewbanchich:master, r=joshtriplett (diff)
parentAccount for raw idents in module file finding (diff)
downloadrust-8e6cf861e5e1b558b6a03dd0eaabc15b37570063.tar.gz
rust-8e6cf861e5e1b558b6a03dd0eaabc15b37570063.tar.bz2
rust-8e6cf861e5e1b558b6a03dd0eaabc15b37570063.tar.xz
Rollup merge of #67010 - estebank:raw-idents, r=Centril
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/librustc_parse/parser/module.rs4
-rw-r--r--src/libsyntax_pos/symbol.rs6
-rw-r--r--src/test/ui/issues/issue-65634-raw-ident-suggestion.rs22
-rw-r--r--src/test/ui/issues/issue-65634-raw-ident-suggestion.stderr22
-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/suggestions/raw-name-use-suggestion.rs2
-rw-r--r--src/test/ui/suggestions/raw-name-use-suggestion.stderr2
9 files changed, 61 insertions, 8 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/librustc_parse/parser/module.rs b/src/librustc_parse/parser/module.rs
index 59d7c2b..807defc 100644
--- a/src/librustc_parse/parser/module.rs
+++ b/src/librustc_parse/parser/module.rs
@@ -212,13 +212,13 @@ impl<'a> Parser<'a> {
212 // `./<id>.rs` and `./<id>/mod.rs`. 212 // `./<id>.rs` and `./<id>/mod.rs`.
213 let relative_prefix_string; 213 let relative_prefix_string;
214 let relative_prefix = if let Some(ident) = relative { 214 let relative_prefix = if let Some(ident) = relative {
215 relative_prefix_string = format!("{}{}", ident, path::MAIN_SEPARATOR); 215 relative_prefix_string = format!("{}{}", ident.name, path::MAIN_SEPARATOR);
216 &relative_prefix_string 216 &relative_prefix_string
217 } else { 217 } else {
218 "" 218 ""
219 }; 219 };
220 220
221 let mod_name = id.to_string(); 221 let mod_name = id.name.to_string();
222 let default_path_str = format!("{}{}.rs", relative_prefix, mod_name); 222 let default_path_str = format!("{}{}.rs", relative_prefix, mod_name);
223 let secondary_path_str = format!("{}{}{}mod.rs", 223 let secondary_path_str = format!("{}{}{}mod.rs",
224 relative_prefix, mod_name, path::MAIN_SEPARATOR); 224 relative_prefix, mod_name, path::MAIN_SEPARATOR);
diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs
index 2af6671..c68e03b 100644
--- a/src/libsyntax_pos/symbol.rs
+++ b/src/libsyntax_pos/symbol.rs
@@ -869,12 +869,18 @@ impl Hash for Ident {
869 869
870impl fmt::Debug for Ident { 870impl fmt::Debug for Ident {
871 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 871 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
872 if self.is_raw_guess() {
873 write!(f, "r#")?;
874 }
872 write!(f, "{}{:?}", self.name, self.span.ctxt()) 875 write!(f, "{}{:?}", self.name, self.span.ctxt())
873 } 876 }
874} 877}
875 878
876impl fmt::Display for Ident { 879impl fmt::Display for Ident {
877 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 880 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
881 if self.is_raw_guess() {
882 write!(f, "r#")?;
883 }
878 fmt::Display::fmt(&self.name, f) 884 fmt::Display::fmt(&self.name, f)
879 } 885 }
880} 886}
diff --git a/src/test/ui/issues/issue-65634-raw-ident-suggestion.rs b/src/test/ui/issues/issue-65634-raw-ident-suggestion.rs
new file mode 100644
index 0000000..b928510
--- /dev/null
+++ b/src/test/ui/issues/issue-65634-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/issues/issue-65634-raw-ident-suggestion.stderr b/src/test/ui/issues/issue-65634-raw-ident-suggestion.stderr
new file mode 100644
index 0000000..c7bb653
--- /dev/null
+++ b/src/test/ui/issues/issue-65634-raw-ident-suggestion.stderr
@@ -0,0 +1,22 @@
1error[E0034]: multiple applicable items in scope
2 --> $DIR/issue-65634-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/issue-65634-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/issue-65634-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/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/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();