about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/generic-associated-types/gat-bounds-not-checked-with-right-substitutions.rs29
-rw-r--r--tests/ui/generic-associated-types/gat-bounds-not-checked-with-right-substitutions.stderr11
-rw-r--r--tests/ui/parser/issue-113342.rs9
-rw-r--r--tests/ui/parser/issue-113342.stderr11
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/basic.rs4
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/basic.stderr25
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/edition-2015-2018-lexing.rs24
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/gate.rs6
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/gate.stderr35
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.rsbin565 -> 760 bytes
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.stderrbin674 -> 4477 bytes
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.rs4
-rw-r--r--tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.stderr38
13 files changed, 180 insertions, 16 deletions
diff --git a/tests/ui/generic-associated-types/gat-bounds-not-checked-with-right-substitutions.rs b/tests/ui/generic-associated-types/gat-bounds-not-checked-with-right-substitutions.rs
new file mode 100644
index 00000000000..05d205266b4
--- /dev/null
+++ b/tests/ui/generic-associated-types/gat-bounds-not-checked-with-right-substitutions.rs
@@ -0,0 +1,29 @@
+// This test checks that we correctly reject the following unsound code.
+
+trait Lengthen<T> {
+    fn lengthen(self) -> T;
+}
+
+impl<'a> Lengthen<&'a str> for &'a str {
+    fn lengthen(self) -> &'a str { self }
+}
+
+trait Gat {
+    type Gat<'a>: for<'b> Lengthen<Self::Gat<'b>>;
+
+    fn lengthen(s: Self::Gat<'_>) -> Self::Gat<'static> {
+        s.lengthen()
+    }
+}
+
+impl Gat for () {
+    type Gat<'a> = &'a str; //~ ERROR: implementation of `Lengthen` is not general enough
+}
+
+fn main() {
+    let s = "hello, garbage".to_string();
+    let borrow: &'static str = <() as Gat>::lengthen(&s);
+    drop(s);
+
+    println!("{borrow}");
+}
diff --git a/tests/ui/generic-associated-types/gat-bounds-not-checked-with-right-substitutions.stderr b/tests/ui/generic-associated-types/gat-bounds-not-checked-with-right-substitutions.stderr
new file mode 100644
index 00000000000..7ea7a7b2de7
--- /dev/null
+++ b/tests/ui/generic-associated-types/gat-bounds-not-checked-with-right-substitutions.stderr
@@ -0,0 +1,11 @@
+error: implementation of `Lengthen` is not general enough
+  --> $DIR/gat-bounds-not-checked-with-right-substitutions.rs:20:20
+   |
+LL |     type Gat<'a> = &'a str;
+   |                    ^^^^^^^ implementation of `Lengthen` is not general enough
+   |
+   = note: `Lengthen<&'0 str>` would have to be implemented for the type `&'a str`, for any lifetime `'0`...
+   = note: ...but `Lengthen<&'1 str>` is actually implemented for the type `&'1 str`, for some specific lifetime `'1`
+
+error: aborting due to previous error
+
diff --git a/tests/ui/parser/issue-113342.rs b/tests/ui/parser/issue-113342.rs
new file mode 100644
index 00000000000..18b502736f7
--- /dev/null
+++ b/tests/ui/parser/issue-113342.rs
@@ -0,0 +1,9 @@
+#[link(name = "my_c_library")]
+extern "C" {
+    fn my_c_function(x: i32) -> bool;
+}
+
+#[no_mangle]
+extern "C" pub fn id(x: i32) -> i32 { x } //~ ERROR expected `fn`, found keyword `pub`
+
+fn main() {}
diff --git a/tests/ui/parser/issue-113342.stderr b/tests/ui/parser/issue-113342.stderr
new file mode 100644
index 00000000000..a0c5e665ff8
--- /dev/null
+++ b/tests/ui/parser/issue-113342.stderr
@@ -0,0 +1,11 @@
+error: expected `fn`, found keyword `pub`
+  --> $DIR/issue-113342.rs:7:12
+   |
+LL | extern "C" pub fn id(x: i32) -> i32 { x }
+   | -----------^^^
+   | |          |
+   | |          expected `fn`
+   | help: visibility `pub` must come before `extern "C"`: `pub extern "C"`
+
+error: aborting due to previous error
+
diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/basic.rs b/tests/ui/rfcs/rfc-3348-c-string-literals/basic.rs
index e4b07ab8108..3fc5fd481ea 100644
--- a/tests/ui/rfcs/rfc-3348-c-string-literals/basic.rs
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/basic.rs
@@ -1,4 +1,6 @@
-// run-pass
+// FIXME(c_str_literals): This should be `run-pass`
+// known-bug: #113333
+// edition: 2021
 
 #![feature(c_str_literals)]
 
diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/basic.stderr b/tests/ui/rfcs/rfc-3348-c-string-literals/basic.stderr
new file mode 100644
index 00000000000..571c319d8c5
--- /dev/null
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/basic.stderr
@@ -0,0 +1,25 @@
+error: prefix `c` is unknown
+  --> $DIR/basic.rs:8:27
+   |
+LL |     assert_eq!(b"test\0", c"test".to_bytes_with_nul());
+   |                           ^ unknown prefix
+   |
+   = note: prefixed identifiers and literals are reserved since Rust 2021
+help: consider inserting whitespace here
+   |
+LL |     assert_eq!(b"test\0", c "test".to_bytes_with_nul());
+   |                            +
+
+error: no rules expected the token `"test"`
+  --> $DIR/basic.rs:8:28
+   |
+LL |     assert_eq!(b"test\0", c"test".to_bytes_with_nul());
+   |                            -^^^^^
+   |                            |
+   |                            no rules expected this token in macro call
+   |                            help: missing comma here
+   |
+   = note: while trying to match sequence start
+
+error: aborting due to 2 previous errors
+
diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/edition-2015-2018-lexing.rs b/tests/ui/rfcs/rfc-3348-c-string-literals/edition-2015-2018-lexing.rs
new file mode 100644
index 00000000000..2a4cd600426
--- /dev/null
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/edition-2015-2018-lexing.rs
@@ -0,0 +1,24 @@
+// Regression test for issue #113235.
+
+// check-pass
+// revisions: edition2015 edition2018
+//[edition2015] edition: 2015
+//[edition2018] edition: 2018
+
+// Make sure that in pre-2021 editions we continue to parse the snippet
+// `c"hello"` as an identifier followed by a (normal) string literal and
+// allow the code below to compile.
+// Prefixes including `c` as used by C string literals are only reserved
+// in edition 2021 and onward.
+//
+// Consider checking out rust-2021/reserved-prefixes-migration.rs as well.
+
+macro_rules! parse {
+    (c $e:expr) => {
+        $e
+    };
+}
+
+fn main() {
+    let _: &'static str = parse!(c"hello");
+}
diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/gate.rs b/tests/ui/rfcs/rfc-3348-c-string-literals/gate.rs
index b27da26ed23..ddd6d9a25da 100644
--- a/tests/ui/rfcs/rfc-3348-c-string-literals/gate.rs
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/gate.rs
@@ -1,4 +1,6 @@
 // gate-test-c_str_literals
+// known-bug: #113333
+// edition: 2021
 
 macro_rules! m {
     ($t:tt) => {}
@@ -6,8 +8,8 @@ macro_rules! m {
 
 fn main() {
     c"foo";
-    //~^ ERROR: `c".."` literals are experimental
+    // FIXME(c_str_literals): This should be ``c".."` literals are experimental`
 
     m!(c"test");
-    //~^ ERROR: `c".."` literals are experimental
+    // FIXME(c_str_literals): This should be ``c".."` literals are experimental`
 }
diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/gate.stderr b/tests/ui/rfcs/rfc-3348-c-string-literals/gate.stderr
index bc0c537aada..8de36ca4a6e 100644
--- a/tests/ui/rfcs/rfc-3348-c-string-literals/gate.stderr
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/gate.stderr
@@ -1,21 +1,32 @@
-error[E0658]: `c".."` literals are experimental
-  --> $DIR/gate.rs:8:5
+error: prefix `c` is unknown
+  --> $DIR/gate.rs:10:5
    |
 LL |     c"foo";
-   |     ^^^^^^
+   |     ^ unknown prefix
    |
-   = note: see issue #105723 <https://github.com/rust-lang/rust/issues/105723> for more information
-   = help: add `#![feature(c_str_literals)]` to the crate attributes to enable
+   = note: prefixed identifiers and literals are reserved since Rust 2021
+help: consider inserting whitespace here
+   |
+LL |     c "foo";
+   |      +
 
-error[E0658]: `c".."` literals are experimental
-  --> $DIR/gate.rs:11:8
+error: prefix `c` is unknown
+  --> $DIR/gate.rs:13:8
    |
 LL |     m!(c"test");
-   |        ^^^^^^^
+   |        ^ unknown prefix
+   |
+   = note: prefixed identifiers and literals are reserved since Rust 2021
+help: consider inserting whitespace here
    |
-   = note: see issue #105723 <https://github.com/rust-lang/rust/issues/105723> for more information
-   = help: add `#![feature(c_str_literals)]` to the crate attributes to enable
+LL |     m!(c "test");
+   |         +
+
+error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `"foo"`
+  --> $DIR/gate.rs:10:6
+   |
+LL |     c"foo";
+   |      ^^^^^ expected one of 8 possible tokens
 
-error: aborting due to 2 previous errors
+error: aborting due to 3 previous errors
 
-For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.rs b/tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.rs
index 7bc6097f124..96945f125da 100644
--- a/tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.rs
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.rs
Binary files differdiff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.stderr b/tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.stderr
index ff9006f6f97..2226c7aa6a9 100644
--- a/tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.stderr
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.stderr
Binary files differdiff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.rs b/tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.rs
index 82e8e2090d7..066505c23df 100644
--- a/tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.rs
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.rs
@@ -1,4 +1,6 @@
-// run-pass
+// FIXME(c_str_literals): This should be `run-pass`
+// known-bug: #113333
+// edition: 2021
 
 #![feature(c_str_literals)]
 
diff --git a/tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.stderr b/tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.stderr
new file mode 100644
index 00000000000..47361fb61d2
--- /dev/null
+++ b/tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.stderr
@@ -0,0 +1,38 @@
+error: prefix `c` is unknown
+  --> $DIR/non-ascii.rs:9:9
+   |
+LL |         c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
+   |         ^ unknown prefix
+   |
+   = note: prefixed identifiers and literals are reserved since Rust 2021
+help: consider inserting whitespace here
+   |
+LL |         c "\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
+   |          +
+
+error: out of range hex escape
+  --> $DIR/non-ascii.rs:9:11
+   |
+LL |         c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
+   |           ^^^^ must be a character in the range [\x00-\x7f]
+
+error: out of range hex escape
+  --> $DIR/non-ascii.rs:9:15
+   |
+LL |         c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
+   |               ^^^^ must be a character in the range [\x00-\x7f]
+
+error: no rules expected the token `"\xEF\x80🦀\u{1F980}"`
+  --> $DIR/non-ascii.rs:9:10
+   |
+LL |         c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
+   |          -^^^^^^^^^^^^^^^^^^^^
+   |          |
+   |          no rules expected this token in macro call
+   |          help: missing comma here
+   |
+note: while trying to match `,`
+  --> $SRC_DIR/core/src/macros/mod.rs:LL:COL
+
+error: aborting due to 4 previous errors
+