forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/ui/traits/self-without-lifetime-constraint.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|