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

Add ?Sized bound to a supertrait listing in E0038 error documentation #65200

Merged
merged 3 commits into from
Oct 12, 2019

Conversation

KamilaBorowska
Copy link
Contributor

This example failed to compile because of implicit Sized bound for A parameter that wasn't required by Trait.

This example failed to compile because of implicit `Sized` bound
for `A` parameter that wasn't required by `Trait`.
@rust-highfive
Copy link
Collaborator

Some changes occurred in diagnostic error codes

cc @GuillaumeGomez

@rust-highfive
Copy link
Collaborator

r? @davidtwco

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 8, 2019
Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that this is an improvement, but my understanding of what this example is intended to demonstrate might be incorrect.

I think this example is intended to demonstrate a failing example for this case - this is what the previous cases do, so changing this to a passing example might be not desirable.

As I understand it, this example attempts to demonstrate why a trait is no longer object-safe when it uses Self in a supertrait listing:

When a trait Foo has a supertrait Super<Self> then that can make Foo non-object-safe even if Super<T> is object-safe. Suppose Super<T> contains a method returning T - and Super<T> is still object-safe if it does - then when used as a supertrait (Super<Self>), the subtrait would be not be object-safe as it would have a method returning a unknown type (this is the "Method references the Self type in its parameters or return type" case from above).

I think the error's example is better suited to explaining that if it remains as a failing example than as a passing example, as in this PR.

That said, the next paragraph might be slightly incorrect as it references a "trait Foo" even though the example names the trait "Trait", so if you want to modify this PR to correct that instead, then that would be appreciated.

@GuillaumeGomez
Copy link
Member

The first example is supposed to fail and is checked as such.

@KamilaBorowska
Copy link
Contributor Author

@davidtwco @GuillaumeGomez

Is this how the example is supposed to fail?

trait Super<A> {}

trait Trait: Super<Self> {}

Gives the following error:

error[E0277]: the size for values of type `Self` cannot be known at compilation time
 --> src/lib.rs:3:1
  |
3 | trait Trait: Super<Self> {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
  |
  = 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 adding a `where Self: std::marker::Sized` bound
note: required by `Super`
 --> src/lib.rs:1:1
  |
1 | trait Super<A> {}
  | ^^^^^^^^^^^^^^

Note that the error is not E0038, but rather E0277. The issue is that with trait Trait: Super<Self> {}, Self doesn't have Sized bound, which is required by A parameter in Super<A> (due to implicit Sized bound on generic parameters).

There are two ways to fix that, one is to put Sized bound on Trait, but that would essentially make this Self: Sized requirement (nothing special about that one), so I picked the other way of putting a T: ?Sized bound so that Self would be used as a type parameter in the supertrait listing.

@KamilaBorowska
Copy link
Contributor Author

KamilaBorowska commented Oct 8, 2019

But yeah, now that I'm checking there is something weird with the description, although I think it should be "trait Trait" instead of "trait Foo" (a rather small change).

@davidtwco
Copy link
Member

@davidtwco @GuillaumeGomez Is this how the example is supposed to fail?

I think it would probably be desirable for the example to error with the code that it is describing (that said, I don't maintain the error codes and the intent might just have been to have as simple an example as possible that explains the case).

Note that the error is not E0038, but rather E0277. The issue is that with trait Trait: Super<Self> {}, Self doesn't have Sized bound, which is required by A parameter in Super<A> (due to implicit Sized bound on generic parameters).

I think that this slightly modified version of the example is probably what we're after. It shows that Trait is not object-safe only because of the Super<Self> (it's otherwise empty).

@KamilaBorowska
Copy link
Contributor Author

Yeah, I can add main function, no problem :).

@@ -259,8 +259,8 @@ trait Foo {
This is similar to the second sub-error, but subtler. It happens in situations
like the following:

```compile_fail
trait Super<A> {}
```compile_fail,E0038
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@GuillaumeGomez
Copy link
Member

Thanks!

@bors: r+ rollup

@bors
Copy link
Contributor

bors commented Oct 10, 2019

📌 Commit 3f9d834 has been approved by GuillaumeGomez

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 10, 2019
tmandry added a commit to tmandry/rust that referenced this pull request Oct 11, 2019
Add ?Sized bound to a supertrait listing in E0038 error documentation

This example failed to compile because of implicit `Sized` bound for `A` parameter that wasn't required by `Trait`.
tmandry added a commit to tmandry/rust that referenced this pull request Oct 11, 2019
Add ?Sized bound to a supertrait listing in E0038 error documentation

This example failed to compile because of implicit `Sized` bound for `A` parameter that wasn't required by `Trait`.
tmandry added a commit to tmandry/rust that referenced this pull request Oct 11, 2019
Rollup of 16 pull requests

Successful merges:

 - rust-lang#64337 (libstd: Fix typos in doc)
 - rust-lang#64986 (Function pointers as const generic arguments)
 - rust-lang#65048 (Added doc about behavior of extend on HashMap)
 - rust-lang#65191 (Add some regression tests)
 - rust-lang#65200 (Add ?Sized bound to a supertrait listing in E0038 error documentation)
 - rust-lang#65205 (Add long error explanation for E0568)
 - rust-lang#65240 (self-profiling: Add events for metadata loading (plus a small dep-tracking optimization))
 - rust-lang#65248 (Suggest `if let` on `let` refutable binding)
 - rust-lang#65252 (expand: Simplify expansion of derives)
 - rust-lang#65263 (Deduplicate is_{freeze,copy,sized}_raw)
 - rust-lang#65265 (Cleanup librustc mir err codes)
 - rust-lang#65266 (Mark Path::join as must_use)
 - rust-lang#65276 (Don't cc rust-lang/compiler for toolstate changes)
 - rust-lang#65277 (Query generator kind for error reporting)
 - rust-lang#65283 (stability: Do not use `buffer_lint` after lowering to HIR)
 - rust-lang#65289 (Fix suggested bound addition diagnostic)

Failed merges:

r? @ghost
Centril added a commit to Centril/rust that referenced this pull request Oct 11, 2019
Add ?Sized bound to a supertrait listing in E0038 error documentation

This example failed to compile because of implicit `Sized` bound for `A` parameter that wasn't required by `Trait`.
Centril added a commit to Centril/rust that referenced this pull request Oct 11, 2019
Rollup of 16 pull requests

Successful merges:

 - rust-lang#64337 (libstd: Fix typos in doc)
 - rust-lang#64986 (Function pointers as const generic arguments)
 - rust-lang#65048 (Added doc about behavior of extend on HashMap)
 - rust-lang#65191 (Add some regression tests)
 - rust-lang#65200 (Add ?Sized bound to a supertrait listing in E0038 error documentation)
 - rust-lang#65205 (Add long error explanation for E0568)
 - rust-lang#65240 (self-profiling: Add events for metadata loading (plus a small dep-tracking optimization))
 - rust-lang#65248 (Suggest `if let` on `let` refutable binding)
 - rust-lang#65252 (expand: Simplify expansion of derives)
 - rust-lang#65263 (Deduplicate is_{freeze,copy,sized}_raw)
 - rust-lang#65265 (Cleanup librustc mir err codes)
 - rust-lang#65266 (Mark Path::join as must_use)
 - rust-lang#65276 (Don't cc rust-lang/compiler for toolstate changes)
 - rust-lang#65277 (Query generator kind for error reporting)
 - rust-lang#65283 (stability: Do not use `buffer_lint` after lowering to HIR)
 - rust-lang#65289 (Fix suggested bound addition diagnostic)

Failed merges:

r? @ghost
bors added a commit that referenced this pull request Oct 11, 2019
Rollup of 11 pull requests

Successful merges:

 - #64337 (libstd: Fix typos in doc)
 - #65048 (Added doc about behavior of extend on HashMap)
 - #65191 (Add some regression tests)
 - #65200 (Add ?Sized bound to a supertrait listing in E0038 error documentation)
 - #65205 (Add long error explanation for E0568)
 - #65263 (Deduplicate is_{freeze,copy,sized}_raw)
 - #65266 (Mark Path::join as must_use)
 - #65276 (Don't cc rust-lang/compiler for toolstate changes)
 - #65277 (Query generator kind for error reporting)
 - #65283 (stability: Do not use `buffer_lint` after lowering to HIR)
 - #65299 (Rollup of 16 pull requests)

Failed merges:

r? @ghost
tmandry added a commit to tmandry/rust that referenced this pull request Oct 11, 2019
Add ?Sized bound to a supertrait listing in E0038 error documentation

This example failed to compile because of implicit `Sized` bound for `A` parameter that wasn't required by `Trait`.
bors added a commit that referenced this pull request Oct 12, 2019
Rollup of 15 pull requests

Successful merges:

 - #64337 (libstd: Fix typos in doc)
 - #64986 (Function pointers as const generic arguments)
 - #65048 (Added doc about behavior of extend on HashMap)
 - #65191 (Add some regression tests)
 - #65200 (Add ?Sized bound to a supertrait listing in E0038 error documentation)
 - #65205 (Add long error explanation for E0568)
 - #65220 (Update LLVM for Emscripten exception handling support)
 - #65263 (Deduplicate is_{freeze,copy,sized}_raw)
 - #65266 (Mark Path::join as must_use)
 - #65276 (Don't cc rust-lang/compiler for toolstate changes)
 - #65277 (Query generator kind for error reporting)
 - #65283 (stability: Do not use `buffer_lint` after lowering to HIR)
 - #65289 (Fix suggested bound addition diagnostic)
 - #65310 (deriving: avoid dummy Span on an artificial `type_ident` path)
 - #65321 (Remove painful test that is not pulling its weight)

Failed merges:

r? @ghost
@bors bors merged commit 3f9d834 into rust-lang:master Oct 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants