about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev@gmail.com>2021-01-27 04:43:20 +0900
committerGitHub <noreply@github.com>2021-01-27 04:43:20 +0900
commit644df2fd23450c8c859c1bce10c51087a3c254f8 (patch)
treed727010809ebdcb6c5afd3d139794d7897ec7a70 /src
parent8299105821327f2a316d0ffa925e55e770b65ad2 (diff)
parent088c89d9ffe47fb6d1b51c8edfd8ad652ee2a7f7 (diff)
downloadrust-644df2fd23450c8c859c1bce10c51087a3c254f8.tar.gz
rust-644df2fd23450c8c859c1bce10c51087a3c254f8.zip
Rollup merge of #81195 - estebank:suggest-bound-on-trait-with-params, r=oli-obk
Account for generics when suggesting bound

Fix #81175.
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/bound-suggestions.fixed27
-rw-r--r--src/test/ui/bound-suggestions.rs27
-rw-r--r--src/test/ui/bound-suggestions.stderr82
3 files changed, 133 insertions, 3 deletions
diff --git a/src/test/ui/bound-suggestions.fixed b/src/test/ui/bound-suggestions.fixed
index a3fe67a9595..be61b7dda25 100644
--- a/src/test/ui/bound-suggestions.fixed
+++ b/src/test/ui/bound-suggestions.fixed
@@ -40,4 +40,29 @@ fn test_many_bounds_where<X>(x: X) where X: Sized, X: Sized, X: Debug {
     //~^ ERROR doesn't implement
 }
 
-pub fn main() { }
+trait Foo<T>: Sized {
+    const SIZE: usize = core::mem::size_of::<Self>();
+    //~^ ERROR the size for values of type `Self` cannot be known at compilation time
+}
+
+trait Bar: std::fmt::Display + Sized {
+    const SIZE: usize = core::mem::size_of::<Self>();
+    //~^ ERROR the size for values of type `Self` cannot be known at compilation time
+}
+
+trait Baz: Sized where Self: std::fmt::Display {
+    const SIZE: usize = core::mem::size_of::<Self>();
+    //~^ ERROR the size for values of type `Self` cannot be known at compilation time
+}
+
+trait Qux<T>: Sized where Self: std::fmt::Display {
+    const SIZE: usize = core::mem::size_of::<Self>();
+    //~^ ERROR the size for values of type `Self` cannot be known at compilation time
+}
+
+trait Bat<T>: std::fmt::Display + Sized {
+    const SIZE: usize = core::mem::size_of::<Self>();
+    //~^ ERROR the size for values of type `Self` cannot be known at compilation time
+}
+
+fn main() { }
diff --git a/src/test/ui/bound-suggestions.rs b/src/test/ui/bound-suggestions.rs
index de6133d7f59..86f708d42f5 100644
--- a/src/test/ui/bound-suggestions.rs
+++ b/src/test/ui/bound-suggestions.rs
@@ -40,4 +40,29 @@ fn test_many_bounds_where<X>(x: X) where X: Sized, X: Sized {
     //~^ ERROR doesn't implement
 }
 
-pub fn main() { }
+trait Foo<T> {
+    const SIZE: usize = core::mem::size_of::<Self>();
+    //~^ ERROR the size for values of type `Self` cannot be known at compilation time
+}
+
+trait Bar: std::fmt::Display {
+    const SIZE: usize = core::mem::size_of::<Self>();
+    //~^ ERROR the size for values of type `Self` cannot be known at compilation time
+}
+
+trait Baz where Self: std::fmt::Display {
+    const SIZE: usize = core::mem::size_of::<Self>();
+    //~^ ERROR the size for values of type `Self` cannot be known at compilation time
+}
+
+trait Qux<T> where Self: std::fmt::Display {
+    const SIZE: usize = core::mem::size_of::<Self>();
+    //~^ ERROR the size for values of type `Self` cannot be known at compilation time
+}
+
+trait Bat<T>: std::fmt::Display {
+    const SIZE: usize = core::mem::size_of::<Self>();
+    //~^ ERROR the size for values of type `Self` cannot be known at compilation time
+}
+
+fn main() { }
diff --git a/src/test/ui/bound-suggestions.stderr b/src/test/ui/bound-suggestions.stderr
index 010f95d8ad6..12e67e90265 100644
--- a/src/test/ui/bound-suggestions.stderr
+++ b/src/test/ui/bound-suggestions.stderr
@@ -76,6 +76,86 @@ help: consider further restricting type parameter `X`
 LL | fn test_many_bounds_where<X>(x: X) where X: Sized, X: Sized, X: Debug {
    |                                                            ^^^^^^^^^^
 
-error: aborting due to 6 previous errors
+error[E0277]: the size for values of type `Self` cannot be known at compilation time
+  --> $DIR/bound-suggestions.rs:44:46
+   |
+LL |     const SIZE: usize = core::mem::size_of::<Self>();
+   |                                              ^^^^ doesn't have a size known at compile-time
+   | 
+  ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL
+   |
+LL | pub const fn size_of<T>() -> usize {
+   |                      - required by this bound in `std::mem::size_of`
+   |
+help: consider further restricting `Self`
+   |
+LL | trait Foo<T>: Sized {
+   |             ^^^^^^^
+
+error[E0277]: the size for values of type `Self` cannot be known at compilation time
+  --> $DIR/bound-suggestions.rs:49:46
+   |
+LL |     const SIZE: usize = core::mem::size_of::<Self>();
+   |                                              ^^^^ doesn't have a size known at compile-time
+   | 
+  ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL
+   |
+LL | pub const fn size_of<T>() -> usize {
+   |                      - required by this bound in `std::mem::size_of`
+   |
+help: consider further restricting `Self`
+   |
+LL | trait Bar: std::fmt::Display + Sized {
+   |                              ^^^^^^^
+
+error[E0277]: the size for values of type `Self` cannot be known at compilation time
+  --> $DIR/bound-suggestions.rs:54:46
+   |
+LL |     const SIZE: usize = core::mem::size_of::<Self>();
+   |                                              ^^^^ doesn't have a size known at compile-time
+   | 
+  ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL
+   |
+LL | pub const fn size_of<T>() -> usize {
+   |                      - required by this bound in `std::mem::size_of`
+   |
+help: consider further restricting `Self`
+   |
+LL | trait Baz: Sized where Self: std::fmt::Display {
+   |          ^^^^^^^
+
+error[E0277]: the size for values of type `Self` cannot be known at compilation time
+  --> $DIR/bound-suggestions.rs:59:46
+   |
+LL |     const SIZE: usize = core::mem::size_of::<Self>();
+   |                                              ^^^^ doesn't have a size known at compile-time
+   | 
+  ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL
+   |
+LL | pub const fn size_of<T>() -> usize {
+   |                      - required by this bound in `std::mem::size_of`
+   |
+help: consider further restricting `Self`
+   |
+LL | trait Qux<T>: Sized where Self: std::fmt::Display {
+   |             ^^^^^^^
+
+error[E0277]: the size for values of type `Self` cannot be known at compilation time
+  --> $DIR/bound-suggestions.rs:64:46
+   |
+LL |     const SIZE: usize = core::mem::size_of::<Self>();
+   |                                              ^^^^ doesn't have a size known at compile-time
+   | 
+  ::: $SRC_DIR/core/src/mem/mod.rs:LL:COL
+   |
+LL | pub const fn size_of<T>() -> usize {
+   |                      - required by this bound in `std::mem::size_of`
+   |
+help: consider further restricting `Self`
+   |
+LL | trait Bat<T>: std::fmt::Display + Sized {
+   |                                 ^^^^^^^
+
+error: aborting due to 11 previous errors
 
 For more information about this error, try `rustc --explain E0277`.