about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-03-17 10:43:38 +0000
committerbors <bors@rust-lang.org>2025-03-17 10:43:38 +0000
commit9c67cecd12d79f1bbc00a74f70e7ef9fff086a5a (patch)
treed43ca065385a4b4d3d8f1b70ba5737dbefa2a46d /tests
parent9bad8ac498985707f29b0bdc0293cc0457a3ab38 (diff)
parent87b87b1966fef82e15a9f9619ee46f5e843cf4c2 (diff)
downloadrust-9c67cecd12d79f1bbc00a74f70e7ef9fff086a5a.tar.gz
rust-9c67cecd12d79f1bbc00a74f70e7ef9fff086a5a.zip
Auto merge of #138595 - jhpratt:rollup-09pvfzu, r=jhpratt
Rollup of 9 pull requests

Successful merges:

 - #136355 (Add `*_value` methods to proc_macro lib)
 - #137621 (Add std support to cygwin target)
 - #137793 (Stablize anonymous pipe)
 - #138341 (std: Mention clone-on-write mutation in Arc<T>)
 - #138517 (Improve upvar analysis for deref of child capture)
 - #138584 (Update Rust Foundation links in Readme)
 - #138586 (Document `#![register_tool]`)
 - #138590 (Flatten and simplify some control flow 🫓)
 - #138592 (update change entry for #137147)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/async-await/async-closures/imm-deref-lending.rs46
-rw-r--r--tests/ui/async-await/async-closures/imm-deref-not-lending.rs49
-rw-r--r--tests/ui/async-await/async-closures/imm-deref-not-lending.stderr14
-rw-r--r--tests/ui/feature-gates/literal-escaper.rs3
-rw-r--r--tests/ui/feature-gates/literal-escaper.stderr13
-rw-r--r--tests/ui/proc-macro/auxiliary/api/literal.rs53
-rw-r--r--tests/ui/proc-macro/auxiliary/api/proc_macro_api_tests.rs1
-rw-r--r--tests/ui/tool-attributes/crate-attr.rs5
-rw-r--r--tests/ui/tool-attributes/multiple-registered.rs7
-rw-r--r--tests/ui/tool-attributes/nested-disallowed.rs4
-rw-r--r--tests/ui/tool-attributes/nested-disallowed.stderr8
11 files changed, 202 insertions, 1 deletions
diff --git a/tests/ui/async-await/async-closures/imm-deref-lending.rs b/tests/ui/async-await/async-closures/imm-deref-lending.rs
new file mode 100644
index 00000000000..59f8d434d9c
--- /dev/null
+++ b/tests/ui/async-await/async-closures/imm-deref-lending.rs
@@ -0,0 +1,46 @@
+//@ edition: 2021
+//@ check-pass
+
+#![feature(impl_trait_in_bindings)]
+
+struct FooS {
+    precise: i32,
+}
+
+fn ref_inside_mut(f: &mut &FooS) {
+    let x: impl AsyncFn() = async move || {
+        let y = &f.precise;
+    };
+}
+
+fn mut_inside_ref(f: &&mut FooS) {
+    let x: impl AsyncFn() = async move || {
+        let y = &f.precise;
+    };
+}
+
+fn mut_ref_inside_mut(f: &mut &mut FooS) {
+    let x: impl AsyncFn() = async move || {
+        let y = &f.precise;
+    };
+}
+
+fn ref_inside_box(f: Box<&FooS>) {
+    let x: impl AsyncFn() = async move || {
+        let y = &f.precise;
+    };
+}
+
+fn box_inside_ref(f: &Box<FooS>) {
+    let x: impl AsyncFn() = async move || {
+        let y = &f.precise;
+    };
+}
+
+fn box_inside_box(f: Box<Box<FooS>>) {
+    let x: impl AsyncFn() = async move || {
+        let y = &f.precise;
+    };
+}
+
+fn main() {}
diff --git a/tests/ui/async-await/async-closures/imm-deref-not-lending.rs b/tests/ui/async-await/async-closures/imm-deref-not-lending.rs
new file mode 100644
index 00000000000..bd1197cc636
--- /dev/null
+++ b/tests/ui/async-await/async-closures/imm-deref-not-lending.rs
@@ -0,0 +1,49 @@
+//@ edition: 2021
+
+#![feature(impl_trait_in_bindings)]
+
+struct FooS {
+    precise: i32,
+}
+
+fn ref_inside_mut(f: &mut &FooS) {
+    let x: impl Fn() -> _ = async move || {
+        let y = &f.precise;
+    };
+}
+
+fn mut_inside_ref(f: &&mut FooS) {
+    let x: impl Fn() -> _ = async move || {
+        let y = &f.precise;
+    };
+}
+
+// Expected to fail, no immutable reference here.
+fn mut_ref_inside_mut(f: &mut &mut FooS) {
+    let x: impl Fn() -> _ = async move || {
+        //~^ ERROR async closure does not implement `Fn`
+        let y = &f.precise;
+    };
+}
+
+fn ref_inside_box(f: Box<&FooS>) {
+    let x: impl Fn() -> _ = async move || {
+        let y = &f.precise;
+    };
+}
+
+fn box_inside_ref(f: &Box<FooS>) {
+    let x: impl Fn() -> _ = async move || {
+        let y = &f.precise;
+    };
+}
+
+// Expected to fail, no immutable reference here.
+fn box_inside_box(f: Box<Box<FooS>>) {
+    let x: impl Fn() -> _ = async move || {
+        //~^ ERROR async closure does not implement `Fn`
+        let y = &f.precise;
+    };
+}
+
+fn main() {}
diff --git a/tests/ui/async-await/async-closures/imm-deref-not-lending.stderr b/tests/ui/async-await/async-closures/imm-deref-not-lending.stderr
new file mode 100644
index 00000000000..cd3ff55e458
--- /dev/null
+++ b/tests/ui/async-await/async-closures/imm-deref-not-lending.stderr
@@ -0,0 +1,14 @@
+error: async closure does not implement `Fn` because it captures state from its environment
+  --> $DIR/imm-deref-not-lending.rs:23:29
+   |
+LL |     let x: impl Fn() -> _ = async move || {
+   |                             ^^^^^^^^^^^^^
+
+error: async closure does not implement `Fn` because it captures state from its environment
+  --> $DIR/imm-deref-not-lending.rs:43:29
+   |
+LL |     let x: impl Fn() -> _ = async move || {
+   |                             ^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
diff --git a/tests/ui/feature-gates/literal-escaper.rs b/tests/ui/feature-gates/literal-escaper.rs
new file mode 100644
index 00000000000..7c145fca7de
--- /dev/null
+++ b/tests/ui/feature-gates/literal-escaper.rs
@@ -0,0 +1,3 @@
+#![crate_type = "lib"]
+
+extern crate literal_escaper; //~ ERROR
diff --git a/tests/ui/feature-gates/literal-escaper.stderr b/tests/ui/feature-gates/literal-escaper.stderr
new file mode 100644
index 00000000000..edddb6504f5
--- /dev/null
+++ b/tests/ui/feature-gates/literal-escaper.stderr
@@ -0,0 +1,13 @@
+error[E0658]: use of unstable library feature `rustc_private`: this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
+  --> $DIR/literal-escaper.rs:3:1
+   |
+LL | extern crate literal_escaper;
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
+   = help: add `#![feature(rustc_private)]` to the crate attributes to enable
+   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/proc-macro/auxiliary/api/literal.rs b/tests/ui/proc-macro/auxiliary/api/literal.rs
index 7109340bb64..941de1521ad 100644
--- a/tests/ui/proc-macro/auxiliary/api/literal.rs
+++ b/tests/ui/proc-macro/auxiliary/api/literal.rs
@@ -1,10 +1,11 @@
 // ignore-tidy-linelength
 
-use proc_macro::Literal;
+use proc_macro::{ConversionErrorKind, Literal};
 
 pub fn test() {
     test_display_literal();
     test_parse_literal();
+    test_str_value_methods();
 }
 
 fn test_display_literal() {
@@ -81,3 +82,53 @@ fn test_parse_literal() {
     assert!("- 10".parse::<Literal>().is_err());
     assert!("-'x'".parse::<Literal>().is_err());
 }
+
+fn test_str_value_methods() {
+    // Testing `str_value`
+    let lit = "\"\n\"".parse::<Literal>().unwrap();
+    assert_eq!(lit.str_value(), Ok("\n".to_string()));
+
+    let lit = "r#\"\n\"#".parse::<Literal>().unwrap();
+    assert_eq!(lit.str_value(), Ok("\n".to_string()));
+
+    let lit = "1".parse::<Literal>().unwrap();
+    assert_eq!(lit.str_value(), Err(ConversionErrorKind::InvalidLiteralKind));
+
+    let lit = "b\"\n\"".parse::<Literal>().unwrap();
+    assert_eq!(lit.str_value(), Err(ConversionErrorKind::InvalidLiteralKind));
+
+    let lit = "c\"\n\"".parse::<Literal>().unwrap();
+    assert_eq!(lit.str_value(), Err(ConversionErrorKind::InvalidLiteralKind));
+
+    // Testing `cstr_value`
+    let lit = "\"\n\"".parse::<Literal>().unwrap();
+    assert_eq!(lit.cstr_value(), Err(ConversionErrorKind::InvalidLiteralKind));
+
+    let lit = "r#\"\n\"#".parse::<Literal>().unwrap();
+    assert_eq!(lit.cstr_value(), Err(ConversionErrorKind::InvalidLiteralKind));
+
+    let lit = "1".parse::<Literal>().unwrap();
+    assert_eq!(lit.cstr_value(), Err(ConversionErrorKind::InvalidLiteralKind));
+
+    let lit = "b\"\n\"".parse::<Literal>().unwrap();
+    assert_eq!(lit.cstr_value(), Err(ConversionErrorKind::InvalidLiteralKind));
+
+    let lit = "c\"\n\"".parse::<Literal>().unwrap();
+    assert_eq!(lit.cstr_value(), Ok(vec![b'\n', 0]));
+
+    // Testing `byte_str_value`
+    let lit = "\"\n\"".parse::<Literal>().unwrap();
+    assert_eq!(lit.byte_str_value(), Err(ConversionErrorKind::InvalidLiteralKind));
+
+    let lit = "r#\"\n\"#".parse::<Literal>().unwrap();
+    assert_eq!(lit.byte_str_value(), Err(ConversionErrorKind::InvalidLiteralKind));
+
+    let lit = "1".parse::<Literal>().unwrap();
+    assert_eq!(lit.byte_str_value(), Err(ConversionErrorKind::InvalidLiteralKind));
+
+    let lit = "b\"\n\"".parse::<Literal>().unwrap();
+    assert_eq!(lit.byte_str_value(), Ok(vec![b'\n']));
+
+    let lit = "c\"\n\"".parse::<Literal>().unwrap();
+    assert_eq!(lit.byte_str_value(), Err(ConversionErrorKind::InvalidLiteralKind));
+}
diff --git a/tests/ui/proc-macro/auxiliary/api/proc_macro_api_tests.rs b/tests/ui/proc-macro/auxiliary/api/proc_macro_api_tests.rs
index abd667d8ce1..390d46852cd 100644
--- a/tests/ui/proc-macro/auxiliary/api/proc_macro_api_tests.rs
+++ b/tests/ui/proc-macro/auxiliary/api/proc_macro_api_tests.rs
@@ -1,6 +1,7 @@
 //@ edition: 2021
 
 #![feature(proc_macro_span)]
+#![feature(proc_macro_value)]
 #![deny(dead_code)] // catch if a test function is never called
 
 extern crate proc_macro;
diff --git a/tests/ui/tool-attributes/crate-attr.rs b/tests/ui/tool-attributes/crate-attr.rs
new file mode 100644
index 00000000000..c6d7974945f
--- /dev/null
+++ b/tests/ui/tool-attributes/crate-attr.rs
@@ -0,0 +1,5 @@
+//@ check-pass
+//@ compile-flags: -Z crate-attr=feature(register_tool) -Z crate-attr=register_tool(foo)
+
+#[allow(foo::bar)]
+fn main() {}
diff --git a/tests/ui/tool-attributes/multiple-registered.rs b/tests/ui/tool-attributes/multiple-registered.rs
new file mode 100644
index 00000000000..4d54c2dcb08
--- /dev/null
+++ b/tests/ui/tool-attributes/multiple-registered.rs
@@ -0,0 +1,7 @@
+//@ check-pass
+
+#![feature(register_tool)]
+#![register_tool(foo, bar, baz)]
+
+#[allow(foo::a, bar::b, baz::c)]
+fn main() {}
diff --git a/tests/ui/tool-attributes/nested-disallowed.rs b/tests/ui/tool-attributes/nested-disallowed.rs
new file mode 100644
index 00000000000..8e780427761
--- /dev/null
+++ b/tests/ui/tool-attributes/nested-disallowed.rs
@@ -0,0 +1,4 @@
+#![feature(register_tool)]
+#![register_tool(foo::bar)] //~ ERROR only accepts identifiers
+
+fn main() {}
diff --git a/tests/ui/tool-attributes/nested-disallowed.stderr b/tests/ui/tool-attributes/nested-disallowed.stderr
new file mode 100644
index 00000000000..1af73fc2f19
--- /dev/null
+++ b/tests/ui/tool-attributes/nested-disallowed.stderr
@@ -0,0 +1,8 @@
+error: `register_tool` only accepts identifiers
+  --> $DIR/nested-disallowed.rs:2:18
+   |
+LL | #![register_tool(foo::bar)]
+   |                  ^^^^^^^^ not an identifier
+
+error: aborting due to 1 previous error
+