about summary refs log tree commit diff
path: root/src/test/ui/str
diff options
context:
space:
mode:
authorDavid Wood <david@davidtw.co>2018-08-08 14:50:16 +0200
committerDavid Wood <david@davidtw.co>2018-08-14 11:12:09 +0200
commit3fc7ab237314a4ce85e612b4ce590c27f1425291 (patch)
treec775f852e05e1272032cb053ee347315c973c7b5 /src/test/ui/str
parent3e0a4079884eab5b54489c92f7428cda2797ea5c (diff)
Merged migrated compile-fail tests and ui tests. Fixes #46841.
Diffstat (limited to 'src/test/ui/str')
-rw-r--r--src/test/ui/str/str-array-assignment.rs21
-rw-r--r--src/test/ui/str/str-array-assignment.stderr49
-rw-r--r--src/test/ui/str/str-as-char.fixed16
-rw-r--r--src/test/ui/str/str-as-char.rs16
-rw-r--r--src/test/ui/str/str-as-char.stderr12
-rw-r--r--src/test/ui/str/str-concat-on-double-ref.rs17
-rw-r--r--src/test/ui/str/str-concat-on-double-ref.stderr11
-rw-r--r--src/test/ui/str/str-idx.rs14
-rw-r--r--src/test/ui/str/str-idx.stderr11
-rw-r--r--src/test/ui/str/str-lit-type-mismatch.rs16
-rw-r--r--src/test/ui/str/str-lit-type-mismatch.stderr39
-rw-r--r--src/test/ui/str/str-mut-idx.rs21
-rw-r--r--src/test/ui/str/str-mut-idx.stderr35
13 files changed, 278 insertions, 0 deletions
diff --git a/src/test/ui/str/str-array-assignment.rs b/src/test/ui/str/str-array-assignment.rs
new file mode 100644
index 00000000000..9d6cf5fe598
--- /dev/null
+++ b/src/test/ui/str/str-array-assignment.rs
@@ -0,0 +1,21 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+  let s = "abc";
+  let t = if true { s[..2] } else { s };
+  //~^ ERROR if and else have incompatible types
+  let u: &str = if true { s[..2] } else { s };
+  //~^ ERROR mismatched types
+  let v = s[..2];
+  //~^ ERROR the size for values of type
+  let w: &str = s[..2];
+  //~^ ERROR mismatched types
+}
diff --git a/src/test/ui/str/str-array-assignment.stderr b/src/test/ui/str/str-array-assignment.stderr
new file mode 100644
index 00000000000..59521bd2e2f
--- /dev/null
+++ b/src/test/ui/str/str-array-assignment.stderr
@@ -0,0 +1,49 @@
+error[E0308]: if and else have incompatible types
+  --> $DIR/str-array-assignment.rs:13:11
+   |
+LL |   let t = if true { s[..2] } else { s };
+   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected str, found &str
+   |
+   = note: expected type `str`
+              found type `&str`
+
+error[E0308]: mismatched types
+  --> $DIR/str-array-assignment.rs:15:27
+   |
+LL |   let u: &str = if true { s[..2] } else { s };
+   |                           ^^^^^^
+   |                           |
+   |                           expected &str, found str
+   |                           help: consider borrowing here: `&s[..2]`
+   |
+   = note: expected type `&str`
+              found type `str`
+
+error[E0277]: the size for values of type `str` cannot be known at compilation time
+  --> $DIR/str-array-assignment.rs:17:7
+   |
+LL |   let v = s[..2];
+   |       ^   ------ help: consider borrowing here: `&s[..2]`
+   |       |
+   |       doesn't have a size known at compile-time
+   |
+   = help: the trait `std::marker::Sized` is not implemented for `str`
+   = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
+   = note: all local variables must have a statically known size
+
+error[E0308]: mismatched types
+  --> $DIR/str-array-assignment.rs:19:17
+   |
+LL |   let w: &str = s[..2];
+   |                 ^^^^^^
+   |                 |
+   |                 expected &str, found str
+   |                 help: consider borrowing here: `&s[..2]`
+   |
+   = note: expected type `&str`
+              found type `str`
+
+error: aborting due to 4 previous errors
+
+Some errors occurred: E0277, E0308.
+For more information about an error, try `rustc --explain E0277`.
diff --git a/src/test/ui/str/str-as-char.fixed b/src/test/ui/str/str-as-char.fixed
new file mode 100644
index 00000000000..c0dad38e436
--- /dev/null
+++ b/src/test/ui/str/str-as-char.fixed
@@ -0,0 +1,16 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// run-rustfix
+
+fn main() {
+    println!("●●");
+    //~^ ERROR character literal may only contain one codepoint
+}
diff --git a/src/test/ui/str/str-as-char.rs b/src/test/ui/str/str-as-char.rs
new file mode 100644
index 00000000000..b5a5df0af7f
--- /dev/null
+++ b/src/test/ui/str/str-as-char.rs
@@ -0,0 +1,16 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// run-rustfix
+
+fn main() {
+    println!('●●');
+    //~^ ERROR character literal may only contain one codepoint
+}
diff --git a/src/test/ui/str/str-as-char.stderr b/src/test/ui/str/str-as-char.stderr
new file mode 100644
index 00000000000..60eb182adf1
--- /dev/null
+++ b/src/test/ui/str/str-as-char.stderr
@@ -0,0 +1,12 @@
+error: character literal may only contain one codepoint
+  --> $DIR/str-as-char.rs:14:14
+   |
+LL |     println!('●●');
+   |              ^^^^
+help: if you meant to write a `str` literal, use double quotes
+   |
+LL |     println!("●●");
+   |              ^^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/str/str-concat-on-double-ref.rs b/src/test/ui/str/str-concat-on-double-ref.rs
new file mode 100644
index 00000000000..292dcbf8ef7
--- /dev/null
+++ b/src/test/ui/str/str-concat-on-double-ref.rs
@@ -0,0 +1,17 @@
+// Copyright 2012-2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+    let a: &String = &"1".to_owned();
+    let b: &str = &"2";
+    let c = a + b;
+    //~^ ERROR binary operation `+` cannot be applied to type `&std::string::String`
+    println!("{:?}", c);
+}
diff --git a/src/test/ui/str/str-concat-on-double-ref.stderr b/src/test/ui/str/str-concat-on-double-ref.stderr
new file mode 100644
index 00000000000..d42c859598f
--- /dev/null
+++ b/src/test/ui/str/str-concat-on-double-ref.stderr
@@ -0,0 +1,11 @@
+error[E0369]: binary operation `+` cannot be applied to type `&std::string::String`
+  --> $DIR/str-concat-on-double-ref.rs:14:13
+   |
+LL |     let c = a + b;
+   |             ^^^^^
+   |
+   = note: an implementation of `std::ops::Add` might be missing for `&std::string::String`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0369`.
diff --git a/src/test/ui/str/str-idx.rs b/src/test/ui/str/str-idx.rs
new file mode 100644
index 00000000000..b5f1ffb977e
--- /dev/null
+++ b/src/test/ui/str/str-idx.rs
@@ -0,0 +1,14 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub fn main() {
+    let s: &str = "hello";
+    let c: u8 = s[4]; //~ ERROR the type `str` cannot be indexed by `{integer}`
+}
diff --git a/src/test/ui/str/str-idx.stderr b/src/test/ui/str/str-idx.stderr
new file mode 100644
index 00000000000..496187c92f1
--- /dev/null
+++ b/src/test/ui/str/str-idx.stderr
@@ -0,0 +1,11 @@
+error[E0277]: the type `str` cannot be indexed by `{integer}`
+  --> $DIR/str-idx.rs:13:17
+   |
+LL |     let c: u8 = s[4]; //~ ERROR the type `str` cannot be indexed by `{integer}`
+   |                 ^^^^ `str` cannot be indexed by `{integer}`
+   |
+   = help: the trait `std::ops::Index<{integer}>` is not implemented for `str`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/str/str-lit-type-mismatch.rs b/src/test/ui/str/str-lit-type-mismatch.rs
new file mode 100644
index 00000000000..4a062f78a32
--- /dev/null
+++ b/src/test/ui/str/str-lit-type-mismatch.rs
@@ -0,0 +1,16 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+
+fn main() {
+    let x: &[u8] = "foo"; //~ ERROR mismatched types
+    let y: &[u8; 4] = "baaa"; //~ ERROR mismatched types
+    let z: &str = b"foo"; //~ ERROR mismatched types
+}
diff --git a/src/test/ui/str/str-lit-type-mismatch.stderr b/src/test/ui/str/str-lit-type-mismatch.stderr
new file mode 100644
index 00000000000..de18851636d
--- /dev/null
+++ b/src/test/ui/str/str-lit-type-mismatch.stderr
@@ -0,0 +1,39 @@
+error[E0308]: mismatched types
+  --> $DIR/str-lit-type-mismatch.rs:13:20
+   |
+LL |     let x: &[u8] = "foo"; //~ ERROR mismatched types
+   |                    ^^^^^
+   |                    |
+   |                    expected slice, found str
+   |                    help: consider adding a leading `b`: `b"foo"`
+   |
+   = note: expected type `&[u8]`
+              found type `&'static str`
+
+error[E0308]: mismatched types
+  --> $DIR/str-lit-type-mismatch.rs:14:23
+   |
+LL |     let y: &[u8; 4] = "baaa"; //~ ERROR mismatched types
+   |                       ^^^^^^
+   |                       |
+   |                       expected array of 4 elements, found str
+   |                       help: consider adding a leading `b`: `b"baaa"`
+   |
+   = note: expected type `&[u8; 4]`
+              found type `&'static str`
+
+error[E0308]: mismatched types
+  --> $DIR/str-lit-type-mismatch.rs:15:19
+   |
+LL |     let z: &str = b"foo"; //~ ERROR mismatched types
+   |                   ^^^^^^
+   |                   |
+   |                   expected str, found array of 3 elements
+   |                   help: consider removing the leading `b`: `"foo"`
+   |
+   = note: expected type `&str`
+              found type `&'static [u8; 3]`
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/str/str-mut-idx.rs b/src/test/ui/str/str-mut-idx.rs
new file mode 100644
index 00000000000..136bfaefa71
--- /dev/null
+++ b/src/test/ui/str/str-mut-idx.rs
@@ -0,0 +1,21 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn bot<T>() -> T { loop {} }
+
+fn mutate(s: &mut str) {
+    s[1..2] = bot();
+    //~^ ERROR the size for values of type
+    //~| ERROR the size for values of type
+    s[1usize] = bot();
+    //~^ ERROR the type `str` cannot be mutably indexed by `usize`
+}
+
+pub fn main() {}
diff --git a/src/test/ui/str/str-mut-idx.stderr b/src/test/ui/str/str-mut-idx.stderr
new file mode 100644
index 00000000000..df21ea2b274
--- /dev/null
+++ b/src/test/ui/str/str-mut-idx.stderr
@@ -0,0 +1,35 @@
+error[E0277]: the size for values of type `str` cannot be known at compilation time
+  --> $DIR/str-mut-idx.rs:14:15
+   |
+LL |     s[1..2] = bot();
+   |               ^^^ doesn't have a size known at compile-time
+   |
+   = help: the trait `std::marker::Sized` is not implemented for `str`
+   = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
+note: required by `bot`
+  --> $DIR/str-mut-idx.rs:11:1
+   |
+LL | fn bot<T>() -> T { loop {} }
+   | ^^^^^^^^^^^^^^^^
+
+error[E0277]: the size for values of type `str` cannot be known at compilation time
+  --> $DIR/str-mut-idx.rs:14:5
+   |
+LL |     s[1..2] = bot();
+   |     ^^^^^^^ doesn't have a size known at compile-time
+   |
+   = help: the trait `std::marker::Sized` is not implemented for `str`
+   = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
+   = note: the left-hand-side of an assignment must have a statically known size
+
+error[E0277]: the type `str` cannot be mutably indexed by `usize`
+  --> $DIR/str-mut-idx.rs:17:5
+   |
+LL |     s[1usize] = bot();
+   |     ^^^^^^^^^ `str` cannot be mutably indexed by `usize`
+   |
+   = help: the trait `std::ops::IndexMut<usize>` is not implemented for `str`
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0277`.