Skip to content

Add error explanation for E0038 #26163

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

Closed
wants to merge 1 commit into from
Closed

Add error explanation for E0038 #26163

wants to merge 1 commit into from

Conversation

jashank
Copy link
Contributor

@jashank jashank commented Jun 10, 2015

I'd like to have added examples for each case but the overall error explanation started getting uncomfortably long. Instead, I've lifted and rewritten notes from src/librustc/middle/traits/object_safety.rs to be (somewhat) clearer.

Personally, I feel this should become five separate error codes for each ObjectSafetyViolation case, also counting MethodViolationCodes.

cc #24407

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@@ -284,6 +284,30 @@ This error indicates that an attempt was made to divide by zero (or take the
remainder of a zero divisor) in a static or constant expression.
"##,

E0038: r##"
This trait is not object safe, but the coercion of an implementation to a trait
Copy link
Contributor

Choose a reason for hiding this comment

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

This is perhaps a nitpick, but technically there are two ways to get a trait object value: casting and coercion. Instead of saying "coercion", it might be better to be vague here, something like "It is not allowed to create a trait object value for a trait that is not object safe"

@nham
Copy link
Contributor

nham commented Jun 10, 2015

Do you think it'd be useful to link to RFC 255 here? That RFC is a bit technical, but it does discuss the object safety rules in detail.

@jashank
Copy link
Contributor Author

jashank commented Jun 10, 2015

@nham, Thanks for that; I've added both suggestions. While yes, RFC 255 is a bit technical, it is (with my 'user' hat on) reasonably clear to understand, and there is a precedent for pointing to an RFC for more details.

@alexcrichton
Copy link
Member

@bors: r+ 7578947982b656053ced7891068bd8a6a3a66058

Thanks!

@bors
Copy link
Collaborator

bors commented Jun 11, 2015

⌛ Testing commit 7578947 with merge 4133fde...

@bors
Copy link
Collaborator

bors commented Jun 11, 2015

💔 Test failed - auto-mac-64-opt

@nikomatsakis
Copy link
Contributor

(Just made a few minor suggestions for improvement; the current text is also good. And the link to the RFC mitigates some of my concerns about details, I guess.)

@jashank
Copy link
Contributor Author

jashank commented Jun 12, 2015

@nikomatsakis: I think what I was trying to say there was how Self: Sized could become a bound of the trait, but wound up with a weird, and unclear wording. I agree that it's easier to grasp if the rationale is more apparent. How about

  • the trait does not have Self: Sized as a bound, to enforce the abstraction of an unknown underlying implementation with potentially arbitrary size

as an explanation (inspired by huonw's description of Sized)?

(Also, do I prefer Self: Sized or Self : Sized?)

With regards to the rationale for (e.g.) restricting generic type parameters to create the vtable, duplicates detail from The Book, or RFC 255, and IMHO is a bit beyond the scope of --explain.

@jashank
Copy link
Contributor Author

jashank commented Jun 12, 2015

Additionally, the build failure on auto-mac-64-opt---

rustc: x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib/librustc
<syntax macros>:2:1: 2:51 error: description for error code E0038 contains a line longer than 80 characters
<syntax macros>:2 __register_diagnostic ! { $ code , $ description } ) ; ( $ code : tt ) => (
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
make: *** [x86_64-apple-darwin/stage0/lib/rustlib/x86_64-apple-darwin/lib/stamp.rustc] Error 101

---appears to be entirely because of the RFC URL. Any suggestions about how to make that be a non-issue?

(edit: see rust-lang/prev.rust-lang.org#147)

@michaelsproul
Copy link
Contributor

@jashank: I'll tweak the lint so that it allows URLs to go over the 80 character line limit.

bors added a commit that referenced this pull request Jun 15, 2015
The plugin that enforces error explanation line-length is a bit restrictive, particularly when attempting to use URLs in explanations (cf #26163).

Jashank will still have to do some mucking around with `#[cfg(not(stage0))]` attributes or else wait until a snapshot with this commit lands.
@nikomatsakis
Copy link
Contributor

@jashank sounds good to me!

@bors
Copy link
Collaborator

bors commented Jun 29, 2015

☔ The latest upstream changes (presumably #26649) made this pull request unmergeable. Please resolve the merge conflicts.

@jashank
Copy link
Contributor Author

jashank commented Jun 29, 2015

... do I have any regrets after rebasing and updating this?

(Also, still blocked by the as-yet-unlanded-in-a-snapshot #26290.)

@@ -1089,6 +1116,8 @@ register_diagnostics! {
E0017,
E0022,
E0038,
Copy link
Member

Choose a reason for hiding this comment

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

I comment here again: this line should be removed.

@jashank
Copy link
Contributor Author

jashank commented Jul 3, 2015

Ooops, sorry about that, @GuillaumeGomez. Rebasing again.

As for the Markdown, all of -, *, and + should be valid. I cannot find any precedent for which to use in the explanations. Grepping the tree for doc comments suggests that - is most commonly used, but * is also used. (FWIW, I prefer -.)

@GuillaumeGomez
Copy link
Member

I use *, but if doc says * is fine, then just ignore my comment. ;-)

@GuillaumeGomez
Copy link
Member

cc @Manishearth

@bors
Copy link
Collaborator

bors commented Jul 4, 2015

☔ The latest upstream changes (presumably #26770) made this pull request unmergeable. Please resolve the merge conflicts.

@jashank
Copy link
Contributor Author

jashank commented Jul 5, 2015

Rebasing, and hopefully I haven't completely screwed up this time.

(I wonder if 26290 has landed yet, which would make this safe to merge.)

@GuillaumeGomez
Copy link
Member

You just have to squash now I guess.

@michaelsproul
Copy link
Contributor

There's no new snapshot but there is a workaround - you can register a single error with register_diagnostic!; combine with cfg conditional compilation and voila!

// Some error that the stage0 compiler doesn't like (E0038 for now)
#[cfg(stage0)]
register_diagnostic! { E0038 }
#[cfg(not(stage0))]
register_diagnostic! { E0038, r##"
Blah blah blah
"##
}

@michaelsproul
Copy link
Contributor

In terms of bootstrapping, this is fine, as it only excludes the error from the stage1 compiler.

I'd like to have added examples for each case but the overall error
explanation started getting uncomfortably long.  Instead, I've lifted
and rewritten notes from src/librustc/middle/traits/object_safety.rs to
be (somewhat) clearer.

Various suggestions for the wording came from @nham and @nikomatsakis.

cc #24407
@jashank
Copy link
Contributor Author

jashank commented Jul 5, 2015

I'm happy to wait for a new snapshot to land, because this isn't exactly a big change, and this is one less thing for the next snapshot wrangler to fix. (Also, apparently, there's a new snapshot coming Real Soon Now.)

Squashing this down to one commit, then Waiting for Snapshot.

@Manishearth
Copy link
Member

I wrote a more comprehensive version of this: #26963

Sorry for taking your PR over, let me know if there's something from here I should pick up :)

@jashank
Copy link
Contributor Author

jashank commented Jul 15, 2015

Nope, I don't see anything that hasn't been covered.

Closing in favour of #26963.

@jashank jashank closed this Jul 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants