From 97ae79ac9d8090dcbf0242865cda171d00ea116a Mon Sep 17 00:00:00 2001 From: bohan Date: Mon, 16 Jan 2023 15:09:05 +0800 Subject: add raw identifier for keyword in suggestion --- compiler/rustc_middle/src/ty/print/pretty.rs | 2 +- ...e-65634-raw-ident-suggestion.edition2015.stderr | 28 ++++++++++++++++++++++ ...e-65634-raw-ident-suggestion.edition2018.stderr | 28 ++++++++++++++++++++++ .../ui/issues/issue-65634-raw-ident-suggestion.rs | 3 +++ .../issues/issue-65634-raw-ident-suggestion.stderr | 28 ---------------------- 5 files changed, 60 insertions(+), 29 deletions(-) create mode 100644 tests/ui/issues/issue-65634-raw-ident-suggestion.edition2015.stderr create mode 100644 tests/ui/issues/issue-65634-raw-ident-suggestion.edition2018.stderr delete mode 100644 tests/ui/issues/issue-65634-raw-ident-suggestion.stderr diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 5576e53e6a7..ae7c20fff0c 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -393,7 +393,7 @@ pub trait PrettyPrinter<'tcx>: match self.tcx().trimmed_def_paths(()).get(&def_id) { None => Ok((self, false)), Some(symbol) => { - self.write_str(symbol.as_str())?; + write!(self, "{}", Ident::with_dummy_span(*symbol))?; Ok((self, true)) } } diff --git a/tests/ui/issues/issue-65634-raw-ident-suggestion.edition2015.stderr b/tests/ui/issues/issue-65634-raw-ident-suggestion.edition2015.stderr new file mode 100644 index 00000000000..d0cb16995af --- /dev/null +++ b/tests/ui/issues/issue-65634-raw-ident-suggestion.edition2015.stderr @@ -0,0 +1,28 @@ +error[E0034]: multiple applicable items in scope + --> $DIR/issue-65634-raw-ident-suggestion.rs:24:13 + | +LL | r#fn {}.r#struct(); + | ^^^^^^^^ multiple `r#struct` found + | +note: candidate #1 is defined in an impl of the trait `async` for the type `r#fn` + --> $DIR/issue-65634-raw-ident-suggestion.rs:7:5 + | +LL | fn r#struct(&self) { + | ^^^^^^^^^^^^^^^^^^ +note: candidate #2 is defined in an impl of the trait `await` for the type `r#fn` + --> $DIR/issue-65634-raw-ident-suggestion.rs:13:5 + | +LL | fn r#struct(&self) { + | ^^^^^^^^^^^^^^^^^^ +help: disambiguate the associated function for candidate #1 + | +LL | async::r#struct(&r#fn {}); + | ~~~~~~~~~~~~~~~~~~~~~~~~~ +help: disambiguate the associated function for candidate #2 + | +LL | await::r#struct(&r#fn {}); + | ~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0034`. diff --git a/tests/ui/issues/issue-65634-raw-ident-suggestion.edition2018.stderr b/tests/ui/issues/issue-65634-raw-ident-suggestion.edition2018.stderr new file mode 100644 index 00000000000..a75c1c41363 --- /dev/null +++ b/tests/ui/issues/issue-65634-raw-ident-suggestion.edition2018.stderr @@ -0,0 +1,28 @@ +error[E0034]: multiple applicable items in scope + --> $DIR/issue-65634-raw-ident-suggestion.rs:24:13 + | +LL | r#fn {}.r#struct(); + | ^^^^^^^^ multiple `r#struct` found + | +note: candidate #1 is defined in an impl of the trait `r#async` for the type `r#fn` + --> $DIR/issue-65634-raw-ident-suggestion.rs:7:5 + | +LL | fn r#struct(&self) { + | ^^^^^^^^^^^^^^^^^^ +note: candidate #2 is defined in an impl of the trait `r#await` for the type `r#fn` + --> $DIR/issue-65634-raw-ident-suggestion.rs:13:5 + | +LL | fn r#struct(&self) { + | ^^^^^^^^^^^^^^^^^^ +help: disambiguate the associated function for candidate #1 + | +LL | r#async::r#struct(&r#fn {}); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +help: disambiguate the associated function for candidate #2 + | +LL | r#await::r#struct(&r#fn {}); + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0034`. diff --git a/tests/ui/issues/issue-65634-raw-ident-suggestion.rs b/tests/ui/issues/issue-65634-raw-ident-suggestion.rs index b928510258b..03dd0340c9d 100644 --- a/tests/ui/issues/issue-65634-raw-ident-suggestion.rs +++ b/tests/ui/issues/issue-65634-raw-ident-suggestion.rs @@ -1,3 +1,6 @@ +// revisions: edition2015 edition2018 +//[edition2018]edition:2018 + #![allow(non_camel_case_types)] trait r#async { diff --git a/tests/ui/issues/issue-65634-raw-ident-suggestion.stderr b/tests/ui/issues/issue-65634-raw-ident-suggestion.stderr deleted file mode 100644 index 68ccf5cab5b..00000000000 --- a/tests/ui/issues/issue-65634-raw-ident-suggestion.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error[E0034]: multiple applicable items in scope - --> $DIR/issue-65634-raw-ident-suggestion.rs:21:13 - | -LL | r#fn {}.r#struct(); - | ^^^^^^^^ multiple `r#struct` found - | -note: candidate #1 is defined in an impl of the trait `async` for the type `fn` - --> $DIR/issue-65634-raw-ident-suggestion.rs:4:5 - | -LL | fn r#struct(&self) { - | ^^^^^^^^^^^^^^^^^^ -note: candidate #2 is defined in an impl of the trait `await` for the type `fn` - --> $DIR/issue-65634-raw-ident-suggestion.rs:10:5 - | -LL | fn r#struct(&self) { - | ^^^^^^^^^^^^^^^^^^ -help: disambiguate the associated function for candidate #1 - | -LL | async::r#struct(&r#fn {}); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ -help: disambiguate the associated function for candidate #2 - | -LL | await::r#struct(&r#fn {}); - | ~~~~~~~~~~~~~~~~~~~~~~~~~ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0034`. -- cgit 1.4.1-3-g733a5