about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-01-04 19:56:13 +0000
committerbors <bors@rust-lang.org>2022-01-04 19:56:13 +0000
commit7d6f948173ccb18822bab13d548c65632db5f0aa (patch)
tree0c6d6e241b150691b700e05281607dfd6f649d22 /src
parent2b681ac06b1a6b7ea39525e59363ffee0d1a68e5 (diff)
parent76c02711a5e30c71c3f4ff8bf0314578cf8b3256 (diff)
Auto merge of #92556 - matthiaskrgr:rollup-s9vopuj, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #91754 (Modifications to `std::io::Stdin` on Windows so that there is no longer a 4-byte buffer minimum in read().)
 - #91884 (Constify `Box<T, A>` methods)
 - #92107 (Actually set IMAGE_SCN_LNK_REMOVE for .rmeta)
 - #92456 (Make the documentation of builtin macro attributes accessible)
 - #92507 (Suggest single quotes when char expected, str provided)
 - #92525 (intra-doc: Make `Receiver::into_iter` into a clickable link)
 - #92532 (revert #92254 "Bump gsgdt to 0.1.3")

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/inference/char-as-str-multi.rs6
-rw-r--r--src/test/ui/inference/char-as-str-multi.stderr11
-rw-r--r--src/test/ui/inference/char-as-str-single.fixed11
-rw-r--r--src/test/ui/inference/char-as-str-single.rs11
-rw-r--r--src/test/ui/inference/char-as-str-single.stderr29
-rw-r--r--src/test/ui/inference/str-as-char.fixed8
-rw-r--r--src/test/ui/inference/str-as-char.rs8
-rw-r--r--src/test/ui/inference/str-as-char.stderr16
-rw-r--r--src/test/ui/issues/issue-23589.stderr5
9 files changed, 105 insertions, 0 deletions
diff --git a/src/test/ui/inference/char-as-str-multi.rs b/src/test/ui/inference/char-as-str-multi.rs
new file mode 100644
index 00000000000..21bbc6f20b2
--- /dev/null
+++ b/src/test/ui/inference/char-as-str-multi.rs
@@ -0,0 +1,6 @@
+// When a MULTI-character string literal is used where a char should be,
+// DO NOT suggest changing to single quotes.
+
+fn main() {
+    let _: char = "foo"; //~ ERROR mismatched types
+}
diff --git a/src/test/ui/inference/char-as-str-multi.stderr b/src/test/ui/inference/char-as-str-multi.stderr
new file mode 100644
index 00000000000..c3ba17a5579
--- /dev/null
+++ b/src/test/ui/inference/char-as-str-multi.stderr
@@ -0,0 +1,11 @@
+error[E0308]: mismatched types
+  --> $DIR/char-as-str-multi.rs:5:19
+   |
+LL |     let _: char = "foo";
+   |            ----   ^^^^^ expected `char`, found `&str`
+   |            |
+   |            expected due to this
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/inference/char-as-str-single.fixed b/src/test/ui/inference/char-as-str-single.fixed
new file mode 100644
index 00000000000..e401492a830
--- /dev/null
+++ b/src/test/ui/inference/char-as-str-single.fixed
@@ -0,0 +1,11 @@
+// When a SINGLE-character string literal is used where a char should be,
+// suggest changing to single quotes.
+
+// Testing both single-byte and multi-byte characters, as we should handle both.
+
+// run-rustfix
+
+fn main() {
+    let _: char = 'a'; //~ ERROR mismatched types
+    let _: char = '人'; //~ ERROR mismatched types
+}
diff --git a/src/test/ui/inference/char-as-str-single.rs b/src/test/ui/inference/char-as-str-single.rs
new file mode 100644
index 00000000000..4f23cea5354
--- /dev/null
+++ b/src/test/ui/inference/char-as-str-single.rs
@@ -0,0 +1,11 @@
+// When a SINGLE-character string literal is used where a char should be,
+// suggest changing to single quotes.
+
+// Testing both single-byte and multi-byte characters, as we should handle both.
+
+// run-rustfix
+
+fn main() {
+    let _: char = "a"; //~ ERROR mismatched types
+    let _: char = "人"; //~ ERROR mismatched types
+}
diff --git a/src/test/ui/inference/char-as-str-single.stderr b/src/test/ui/inference/char-as-str-single.stderr
new file mode 100644
index 00000000000..29075c15414
--- /dev/null
+++ b/src/test/ui/inference/char-as-str-single.stderr
@@ -0,0 +1,29 @@
+error[E0308]: mismatched types
+  --> $DIR/char-as-str-single.rs:9:19
+   |
+LL |     let _: char = "a";
+   |            ----   ^^^ expected `char`, found `&str`
+   |            |
+   |            expected due to this
+   |
+help: if you meant to write a `char` literal, use single quotes
+   |
+LL |     let _: char = 'a';
+   |                   ~~~
+
+error[E0308]: mismatched types
+  --> $DIR/char-as-str-single.rs:10:19
+   |
+LL |     let _: char = "人";
+   |            ----   ^^^^ expected `char`, found `&str`
+   |            |
+   |            expected due to this
+   |
+help: if you meant to write a `char` literal, use single quotes
+   |
+LL |     let _: char = '人';
+   |                   ~~~~
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/inference/str-as-char.fixed b/src/test/ui/inference/str-as-char.fixed
new file mode 100644
index 00000000000..09f3dec5a17
--- /dev/null
+++ b/src/test/ui/inference/str-as-char.fixed
@@ -0,0 +1,8 @@
+// When a char literal is used where a str should be,
+// suggest changing to double quotes.
+
+// run-rustfix
+
+fn main() {
+    let _: &str = "a"; //~ ERROR mismatched types
+}
diff --git a/src/test/ui/inference/str-as-char.rs b/src/test/ui/inference/str-as-char.rs
new file mode 100644
index 00000000000..7092a612442
--- /dev/null
+++ b/src/test/ui/inference/str-as-char.rs
@@ -0,0 +1,8 @@
+// When a char literal is used where a str should be,
+// suggest changing to double quotes.
+
+// run-rustfix
+
+fn main() {
+    let _: &str = 'a'; //~ ERROR mismatched types
+}
diff --git a/src/test/ui/inference/str-as-char.stderr b/src/test/ui/inference/str-as-char.stderr
new file mode 100644
index 00000000000..ebbe7c80f77
--- /dev/null
+++ b/src/test/ui/inference/str-as-char.stderr
@@ -0,0 +1,16 @@
+error[E0308]: mismatched types
+  --> $DIR/str-as-char.rs:7:19
+   |
+LL |     let _: &str = 'a';
+   |            ----   ^^^ expected `&str`, found `char`
+   |            |
+   |            expected due to this
+   |
+help: if you meant to write a `str` literal, use double quotes
+   |
+LL |     let _: &str = "a";
+   |                   ~~~
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/issues/issue-23589.stderr b/src/test/ui/issues/issue-23589.stderr
index d126e1bf0b5..e065e17c280 100644
--- a/src/test/ui/issues/issue-23589.stderr
+++ b/src/test/ui/issues/issue-23589.stderr
@@ -12,6 +12,11 @@ error[E0308]: mismatched types
    |
 LL |     let v: Vec(&str) = vec!['1', '2'];
    |                             ^^^ expected `&str`, found `char`
+   |
+help: if you meant to write a `str` literal, use double quotes
+   |
+LL |     let v: Vec(&str) = vec!["1", '2'];
+   |                             ~~~
 
 error: aborting due to 2 previous errors