Skip to content

Commit

Permalink
Update Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
veera-sivarajan committed Jul 13, 2024
1 parent 25acbbd commit 102997a
Show file tree
Hide file tree
Showing 3 changed files with 824 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tests/ui/dyn-keyword/dyn-2021-edition-error.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ error[E0782]: trait objects must include the `dyn` keyword
LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) {
| ^^^^^^^^^
|
help: add `dyn` keyword before this trait
help: use a new generic type parameter, constrained by `SomeTrait`
|
LL | fn function<T: SomeTrait>(x: &T, y: Box<SomeTrait>) {
| ++++++++++++++ ~
help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
|
LL | fn function(x: &impl SomeTrait, y: Box<SomeTrait>) {
| ++++
help: alternatively, use a trait object to accept any type that implements `SomeTrait`, accessing its methods at runtime using dynamic dispatch
|
LL | fn function(x: &dyn SomeTrait, y: Box<SomeTrait>) {
| +++
Expand Down
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() {}
Loading

0 comments on commit 102997a

Please sign in to comment.