about summary refs log tree commit diff
path: root/src/test/ui/traits
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2020-05-28 10:35:48 -0700
committerEsteban Küber <esteban@kuber.com.ar>2020-05-28 10:36:21 -0700
commit1bd69702de07858ad9c7ae7ed89c3c99aea64550 (patch)
tree833948c489ef166c2ae76b5c2f8dafde455d4e81 /src/test/ui/traits
parentf213acf4db81a33308ab2d53b5927108d63a2d7f (diff)
downloadrust-1bd69702de07858ad9c7ae7ed89c3c99aea64550.tar.gz
rust-1bd69702de07858ad9c7ae7ed89c3c99aea64550.zip
Account for `Self` as a type param
Diffstat (limited to 'src/test/ui/traits')
-rw-r--r--src/test/ui/traits/self-without-lifetime-constraint.rs53
-rw-r--r--src/test/ui/traits/self-without-lifetime-constraint.stderr19
2 files changed, 72 insertions, 0 deletions
diff --git a/src/test/ui/traits/self-without-lifetime-constraint.rs b/src/test/ui/traits/self-without-lifetime-constraint.rs
new file mode 100644
index 00000000000..99013d32ab8
--- /dev/null
+++ b/src/test/ui/traits/self-without-lifetime-constraint.rs
@@ -0,0 +1,53 @@
+use std::error::Error;
+use std::fmt;
+
+#[derive(Copy, Clone, Debug, PartialEq)]
+pub enum ValueRef<'a> {
+    Null,
+    Integer(i64),
+    Real(f64),
+    Text(&'a [u8]),
+    Blob(&'a [u8]),
+}
+
+impl<'a> ValueRef<'a> {
+    pub fn as_str(&self) -> FromSqlResult<&'a str, &'a &'a str> {
+        match *self {
+            ValueRef::Text(t) => {
+                std::str::from_utf8(t).map_err(|_| FromSqlError::InvalidType).map(|x| (x, &x))
+            }
+            _ => Err(FromSqlError::InvalidType),
+        }
+    }
+}
+
+#[derive(Debug)]
+#[non_exhaustive]
+pub enum FromSqlError {
+    InvalidType
+}
+
+impl fmt::Display for FromSqlError {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        write!(f, "InvalidType")
+    }
+}
+
+impl Error for FromSqlError {}
+
+pub type FromSqlResult<T, K> = Result<(T, K), FromSqlError>;
+
+pub trait FromSql: Sized {
+    fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self, &Self>;
+}
+
+impl FromSql for &str {
+    fn column_result(value: ValueRef<'_>) -> FromSqlResult<&str, &&str> {
+    //~^ ERROR `impl` item signature doesn't match `trait` item signature
+        value.as_str()
+    }
+}
+
+pub fn main() {
+    println!("{}", "Hello World");
+}
diff --git a/src/test/ui/traits/self-without-lifetime-constraint.stderr b/src/test/ui/traits/self-without-lifetime-constraint.stderr
new file mode 100644
index 00000000000..6c7abe753e2
--- /dev/null
+++ b/src/test/ui/traits/self-without-lifetime-constraint.stderr
@@ -0,0 +1,19 @@
+error: `impl` item signature doesn't match `trait` item signature
+  --> $DIR/self-without-lifetime-constraint.rs:45:5
+   |
+LL |     fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self, &Self>;
+   |     -------------------------------------------------------------------- expected `fn(ValueRef<'_>) -> std::result::Result<(&str, &&str), FromSqlError>`
+...
+LL |     fn column_result(value: ValueRef<'_>) -> FromSqlResult<&str, &&str> {
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(ValueRef<'_>) -> std::result::Result<(&str, &&str), FromSqlError>`
+   |
+   = note: expected `fn(ValueRef<'_>) -> std::result::Result<(&str, &&str), _>`
+              found `fn(ValueRef<'_>) -> std::result::Result<(&str, &&str), _>`
+help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
+  --> $DIR/self-without-lifetime-constraint.rs:41:60
+   |
+LL |     fn column_result(value: ValueRef<'_>) -> FromSqlResult<Self, &Self>;
+   |                                                            ^^^^ consider borrowing this type parameter in the trait
+
+error: aborting due to previous error
+