about summary refs log tree commit diff
path: root/tests/ui/const-generics
diff options
context:
space:
mode:
authorOneirical <manchot@videotron.ca>2025-07-13 16:39:45 -0400
committerOneirical <manchot@videotron.ca>2025-08-10 11:54:15 -0400
commitaa543963c68061d9ca46037071d66a028626ff3f (patch)
tree2d6e7de7e1b2fe2176d81f48a456a05ef1b06dff /tests/ui/const-generics
parentf8e355c230c6eb7b78ffce6a92fd81f78c890524 (diff)
downloadrust-aa543963c68061d9ca46037071d66a028626ff3f.tar.gz
rust-aa543963c68061d9ca46037071d66a028626ff3f.zip
Rehome tests/ui/issues/ tests [4/?]
Diffstat (limited to 'tests/ui/const-generics')
-rw-r--r--tests/ui/const-generics/try-from-with-const-genericsrs-98299.rs21
-rw-r--r--tests/ui/const-generics/try-from-with-const-genericsrs-98299.stderr61
2 files changed, 82 insertions, 0 deletions
diff --git a/tests/ui/const-generics/try-from-with-const-genericsrs-98299.rs b/tests/ui/const-generics/try-from-with-const-genericsrs-98299.rs
new file mode 100644
index 00000000000..49c88856bc9
--- /dev/null
+++ b/tests/ui/const-generics/try-from-with-const-genericsrs-98299.rs
@@ -0,0 +1,21 @@
+// https://github.com/rust-lang/rust/issues/98299
+use std::convert::TryFrom;
+
+pub fn test_usage(p: ()) {
+    SmallCString::try_from(p).map(|cstr| cstr);
+    //~^ ERROR: type annotations needed
+    //~| ERROR: type annotations needed
+    //~| ERROR: type annotations needed
+}
+
+pub struct SmallCString<const N: usize> {}
+
+impl<const N: usize> TryFrom<()> for SmallCString<N> {
+    type Error = ();
+
+    fn try_from(path: ()) -> Result<Self, Self::Error> {
+        unimplemented!();
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/const-generics/try-from-with-const-genericsrs-98299.stderr b/tests/ui/const-generics/try-from-with-const-genericsrs-98299.stderr
new file mode 100644
index 00000000000..1557b83b00e
--- /dev/null
+++ b/tests/ui/const-generics/try-from-with-const-genericsrs-98299.stderr
@@ -0,0 +1,61 @@
+error[E0284]: type annotations needed for `SmallCString<_>`
+  --> $DIR/try-from-with-const-genericsrs-98299.rs:5:36
+   |
+LL |     SmallCString::try_from(p).map(|cstr| cstr);
+   |     ------------                   ^^^^
+   |     |
+   |     type must be known at this point
+   |
+note: required by a const generic parameter in `SmallCString`
+  --> $DIR/try-from-with-const-genericsrs-98299.rs:11:25
+   |
+LL | pub struct SmallCString<const N: usize> {}
+   |                         ^^^^^^^^^^^^^^ required by this const generic parameter in `SmallCString`
+help: consider giving this closure parameter an explicit type, where the value of const parameter `N` is specified
+   |
+LL |     SmallCString::try_from(p).map(|cstr: SmallCString<N>| cstr);
+   |                                        +++++++++++++++++
+
+error[E0284]: type annotations needed for `SmallCString<_>`
+  --> $DIR/try-from-with-const-genericsrs-98299.rs:5:36
+   |
+LL |     SmallCString::try_from(p).map(|cstr| cstr);
+   |     ------------                   ^^^^
+   |     |
+   |     type must be known at this point
+   |
+note: required for `SmallCString<_>` to implement `TryFrom<()>`
+  --> $DIR/try-from-with-const-genericsrs-98299.rs:13:22
+   |
+LL | impl<const N: usize> TryFrom<()> for SmallCString<N> {
+   |      --------------  ^^^^^^^^^^^     ^^^^^^^^^^^^^^^
+   |      |
+   |      unsatisfied trait bound introduced here
+help: consider giving this closure parameter an explicit type, where the value of const parameter `N` is specified
+   |
+LL |     SmallCString::try_from(p).map(|cstr: SmallCString<N>| cstr);
+   |                                        +++++++++++++++++
+
+error[E0284]: type annotations needed for `SmallCString<_>`
+  --> $DIR/try-from-with-const-genericsrs-98299.rs:5:36
+   |
+LL |     SmallCString::try_from(p).map(|cstr| cstr);
+   |     -------------------------      ^^^^
+   |     |
+   |     type must be known at this point
+   |
+note: required for `SmallCString<_>` to implement `TryFrom<()>`
+  --> $DIR/try-from-with-const-genericsrs-98299.rs:13:22
+   |
+LL | impl<const N: usize> TryFrom<()> for SmallCString<N> {
+   |      --------------  ^^^^^^^^^^^     ^^^^^^^^^^^^^^^
+   |      |
+   |      unsatisfied trait bound introduced here
+help: consider giving this closure parameter an explicit type, where the value of const parameter `N` is specified
+   |
+LL |     SmallCString::try_from(p).map(|cstr: SmallCString<N>| cstr);
+   |                                        +++++++++++++++++
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0284`.