Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We meant to use a trait instead of lifetime here #88182

Merged
merged 1 commit into from
Aug 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
We meant to use a trait instead of lifetime here
spastorino committed Aug 20, 2021

Verified

This commit was signed with the committer’s verified signature. The key has expired.
jeff-mccoy Megamind
commit 49a31a2b3e0817b5ac8fbad01b621bf9015974d6
Original file line number Diff line number Diff line change
@@ -3,8 +3,7 @@
fn main() {}

trait Trait {}
type Underconstrained<T: Trait> = impl 'static;
//~^ ERROR: at least one trait must be specified
type Underconstrained<T: Trait> = impl Send;

// no `Trait` bound
fn underconstrain<T>(_: T) -> Underconstrained<T> {
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
error: at least one trait must be specified
--> $DIR/generic_underconstrained.rs:6:35
|
LL | type Underconstrained<T: Trait> = impl 'static;
| ^^^^^^^^^^^^

error[E0277]: the trait bound `T: Trait` is not satisfied
--> $DIR/generic_underconstrained.rs:10:31
--> $DIR/generic_underconstrained.rs:9:31
|
LL | fn underconstrain<T>(_: T) -> Underconstrained<T> {
| ^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T`
|
note: required by a bound in `Underconstrained`
--> $DIR/generic_underconstrained.rs:6:26
|
LL | type Underconstrained<T: Trait> = impl 'static;
LL | type Underconstrained<T: Trait> = impl Send;
| ^^^^^ required by this bound in `Underconstrained`
help: consider restricting type parameter `T`
|
LL | fn underconstrain<T: Trait>(_: T) -> Underconstrained<T> {
| +++++++

error: aborting due to 2 previous errors
error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
Original file line number Diff line number Diff line change
@@ -2,17 +2,15 @@

fn main() {}

type Underconstrained<T: std::fmt::Debug> = impl 'static;
//~^ ERROR: at least one trait must be specified
type Underconstrained<T: std::fmt::Debug> = impl Send;

// not a defining use, because it doesn't define *all* possible generics
fn underconstrained<U>(_: U) -> Underconstrained<U> {
//~^ ERROR `U` doesn't implement `Debug`
5u32
}

type Underconstrained2<T: std::fmt::Debug> = impl 'static;
//~^ ERROR: at least one trait must be specified
type Underconstrained2<T: std::fmt::Debug> = impl Send;

// not a defining use, because it doesn't define *all* possible generics
fn underconstrained2<U, V>(_: U, _: V) -> Underconstrained2<V> {
24 changes: 6 additions & 18 deletions src/test/ui/type-alias-impl-trait/generic_underconstrained2.stderr
Original file line number Diff line number Diff line change
@@ -1,47 +1,35 @@
error: at least one trait must be specified
--> $DIR/generic_underconstrained2.rs:5:45
|
LL | type Underconstrained<T: std::fmt::Debug> = impl 'static;
| ^^^^^^^^^^^^

error: at least one trait must be specified
--> $DIR/generic_underconstrained2.rs:14:46
|
LL | type Underconstrained2<T: std::fmt::Debug> = impl 'static;
| ^^^^^^^^^^^^

error[E0277]: `U` doesn't implement `Debug`
--> $DIR/generic_underconstrained2.rs:9:33
--> $DIR/generic_underconstrained2.rs:8:33
|
LL | fn underconstrained<U>(_: U) -> Underconstrained<U> {
| ^^^^^^^^^^^^^^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
note: required by a bound in `Underconstrained`
--> $DIR/generic_underconstrained2.rs:5:26
|
LL | type Underconstrained<T: std::fmt::Debug> = impl 'static;
LL | type Underconstrained<T: std::fmt::Debug> = impl Send;
| ^^^^^^^^^^^^^^^ required by this bound in `Underconstrained`
help: consider restricting type parameter `U`
|
LL | fn underconstrained<U: std::fmt::Debug>(_: U) -> Underconstrained<U> {
| +++++++++++++++++

error[E0277]: `V` doesn't implement `Debug`
--> $DIR/generic_underconstrained2.rs:18:43
--> $DIR/generic_underconstrained2.rs:16:43
|
LL | fn underconstrained2<U, V>(_: U, _: V) -> Underconstrained2<V> {
| ^^^^^^^^^^^^^^^^^^^^ `V` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
note: required by a bound in `Underconstrained2`
--> $DIR/generic_underconstrained2.rs:14:27
--> $DIR/generic_underconstrained2.rs:13:27
|
LL | type Underconstrained2<T: std::fmt::Debug> = impl 'static;
LL | type Underconstrained2<T: std::fmt::Debug> = impl Send;
| ^^^^^^^^^^^^^^^ required by this bound in `Underconstrained2`
help: consider restricting type parameter `V`
|
LL | fn underconstrained2<U, V: std::fmt::Debug>(_: U, _: V) -> Underconstrained2<V> {
| +++++++++++++++++

error: aborting due to 4 previous errors
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0277`.