-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
1 parent
25acbbd
commit 102997a
Showing
3 changed files
with
824 additions
and
1 deletion.
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
142 changes: 142 additions & 0 deletions
142
tests/ui/object-safety/reference-to-bare-trait-in-fn-inputs-and-outputs-issue-125139.rs
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,142 @@ | ||
//@ edition:2021 | ||
|
||
trait Trait {} | ||
|
||
struct IceCream; | ||
|
||
impl IceCream { | ||
fn foo(_: &Trait) {} | ||
//~^ ERROR: trait objects must include the `dyn` keyword | ||
|
||
fn bar(self, _: &'a Trait) {} | ||
//~^ ERROR: trait objects must include the `dyn` keyword | ||
//~| ERROR: use of undeclared lifetime name | ||
|
||
fn alice<'a>(&self, _: &Trait) {} | ||
//~^ ERROR: trait objects must include the `dyn` keyword | ||
|
||
fn bob<'a>(_: &'a Trait) {} | ||
//~^ ERROR: trait objects must include the `dyn` keyword | ||
|
||
fn cat() -> &Trait { | ||
//~^ ERROR: missing lifetime specifier | ||
//~| ERROR: trait objects must include the `dyn` keyword | ||
&Type | ||
} | ||
|
||
fn dog<'a>() -> &Trait { | ||
//~^ ERROR: missing lifetime specifier | ||
//~| ERROR: trait objects must include the `dyn` keyword | ||
&Type | ||
} | ||
|
||
fn kitten() -> &'a Trait { | ||
//~^ ERROR: use of undeclared lifetime name | ||
//~| ERROR: trait objects must include the `dyn` keyword | ||
&Type | ||
} | ||
|
||
fn puppy<'a>() -> &'a Trait { | ||
//~^ ERROR: trait objects must include the `dyn` keyword | ||
&Type | ||
} | ||
|
||
fn parrot() -> &mut Trait { | ||
//~^ ERROR: missing lifetime specifier | ||
//~| ERROR: cannot return a mutable reference to a bare trait | ||
&mut Type | ||
//~^ ERROR: cannot return reference to temporary value | ||
} | ||
} | ||
|
||
trait Sing { | ||
fn foo(_: &Trait); | ||
//~^ ERROR: trait objects must include the `dyn` keyword | ||
|
||
fn bar(_: &'a Trait); | ||
//~^ ERROR: trait objects must include the `dyn` keyword | ||
//~| ERROR: use of undeclared lifetime name | ||
|
||
fn alice<'a>(_: &Trait); | ||
//~^ ERROR: trait objects must include the `dyn` keyword | ||
|
||
fn bob<'a>(_: &'a Trait); | ||
//~^ ERROR: trait objects must include the `dyn` keyword | ||
|
||
fn cat() -> &Trait; | ||
//~^ ERROR: missing lifetime specifier | ||
//~| ERROR: trait objects must include the `dyn` keyword | ||
|
||
fn dog<'a>() -> &Trait { | ||
//~^ ERROR: missing lifetime specifier | ||
//~| ERROR: trait objects must include the `dyn` keyword | ||
&Type | ||
} | ||
|
||
fn kitten() -> &'a Trait { | ||
//~^ ERROR: use of undeclared lifetime name | ||
//~| ERROR: trait objects must include the `dyn` keyword | ||
&Type | ||
} | ||
|
||
fn puppy<'a>() -> &'a Trait { | ||
//~^ ERROR: trait objects must include the `dyn` keyword | ||
&Type | ||
} | ||
|
||
fn parrot() -> &mut Trait { | ||
//~^ ERROR: missing lifetime specifier | ||
//~| ERROR: cannot return a mutable reference to a bare trait | ||
&mut Type | ||
//~^ ERROR: cannot return reference to temporary value | ||
} | ||
} | ||
|
||
fn foo(_: &Trait) {} | ||
//~^ ERROR: trait objects must include the `dyn` keyword | ||
|
||
fn bar(_: &'a Trait) {} | ||
//~^ ERROR: trait objects must include the `dyn` keyword | ||
//~| ERROR: use of undeclared lifetime name | ||
|
||
fn alice<'a>(_: &Trait) {} | ||
//~^ ERROR: trait objects must include the `dyn` keyword | ||
|
||
fn bob<'a>(_: &'a Trait) {} | ||
//~^ ERROR: trait objects must include the `dyn` keyword | ||
|
||
struct Type; | ||
|
||
impl Trait for Type {} | ||
|
||
fn cat() -> &Trait { | ||
//~^ ERROR: missing lifetime specifier | ||
//~| ERROR: trait objects must include the `dyn` keyword | ||
&Type | ||
} | ||
|
||
fn dog<'a>() -> &Trait { | ||
//~^ ERROR: missing lifetime specifier | ||
//~| ERROR: trait objects must include the `dyn` keyword | ||
&Type | ||
} | ||
|
||
fn kitten() -> &'a Trait { | ||
//~^ ERROR: use of undeclared lifetime name | ||
//~| ERROR: trait objects must include the `dyn` keyword | ||
&Type | ||
} | ||
|
||
fn puppy<'a>() -> &'a Trait { | ||
//~^ ERROR: trait objects must include the `dyn` keyword | ||
&Type | ||
} | ||
|
||
fn parrot() -> &mut Trait { | ||
//~^ ERROR: missing lifetime specifier | ||
//~| ERROR: cannot return a mutable reference to a bare trait | ||
&mut Type | ||
//~^ ERROR: cannot return reference to temporary value | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.