-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggest
?Sized
when applicable for ADTs
Fix #71790.
- Loading branch information
Showing
4 changed files
with
166 additions
and
34 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
17 changes: 17 additions & 0 deletions
17
src/test/ui/suggestions/adt-param-with-implicit-sized-bound.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,17 @@ | ||
trait Trait { | ||
fn func1() -> Struct1<Self>; //~ ERROR E0277 | ||
fn func2<'a>() -> Struct2<'a, Self>; //~ ERROR E0277 | ||
fn func3() -> Struct3<Self>; //~ ERROR E0277 | ||
} | ||
|
||
struct Struct1<T>{ | ||
_t: std::marker::PhantomData<*const T>, | ||
} | ||
struct Struct2<'a, T>{ | ||
_t: &'a T, | ||
} | ||
struct Struct3<T>{ | ||
_t: T, | ||
} | ||
|
||
fn main() {} |
59 changes: 59 additions & 0 deletions
59
src/test/ui/suggestions/adt-param-with-implicit-sized-bound.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,59 @@ | ||
error[E0277]: the size for values of type `Self` cannot be known at compilation time | ||
--> $DIR/adt-param-with-implicit-sized-bound.rs:2:19 | ||
| | ||
LL | fn func1() -> Struct1<Self>; | ||
| ^^^^^^^^^^^^^ doesn't have a size known at compile-time | ||
... | ||
LL | struct Struct1<T>{ | ||
| - required by this bound in `Struct1` | ||
| | ||
= help: the trait `std::marker::Sized` is not implemented for `Self` | ||
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait> | ||
help: consider further restricting `Self` | ||
| | ||
LL | fn func1() -> Struct1<Self> where Self: std::marker::Sized; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
help: consider relaxing the implicit `Sized` restriction | ||
| | ||
LL | struct Struct1<T: ?Sized>{ | ||
| ^^^^^^^^ | ||
|
||
error[E0277]: the size for values of type `Self` cannot be known at compilation time | ||
--> $DIR/adt-param-with-implicit-sized-bound.rs:3:23 | ||
| | ||
LL | fn func2<'a>() -> Struct2<'a, Self>; | ||
| ^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | ||
... | ||
LL | struct Struct2<'a, T>{ | ||
| - required by this bound in `Struct2` | ||
| | ||
= help: the trait `std::marker::Sized` is not implemented for `Self` | ||
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait> | ||
help: consider further restricting `Self` | ||
| | ||
LL | fn func2<'a>() -> Struct2<'a, Self> where Self: std::marker::Sized; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
help: consider relaxing the implicit `Sized` restriction | ||
| | ||
LL | struct Struct2<'a, T: ?Sized>{ | ||
| ^^^^^^^^ | ||
|
||
error[E0277]: the size for values of type `Self` cannot be known at compilation time | ||
--> $DIR/adt-param-with-implicit-sized-bound.rs:4:19 | ||
| | ||
LL | fn func3() -> Struct3<Self>; | ||
| ^^^^^^^^^^^^^ doesn't have a size known at compile-time | ||
... | ||
LL | struct Struct3<T>{ | ||
| - required by this bound in `Struct3` | ||
| | ||
= help: the trait `std::marker::Sized` is not implemented for `Self` | ||
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait> | ||
help: consider further restricting `Self` | ||
| | ||
LL | fn func3() -> Struct3<Self> where Self: std::marker::Sized; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |