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

Bury Error::description() #2230

Merged
merged 4 commits into from
May 3, 2018
Merged

Bury Error::description() #2230

merged 4 commits into from
May 3, 2018

Conversation

kornelski
Copy link
Contributor

@kornelski kornelski commented Nov 29, 2017

@nagisa
Copy link
Member

nagisa commented Nov 29, 2017

cf. rust-lang/rust#44842

@dtolnay dtolnay added the T-libs-api Relevant to the library API team, which will review and decide on the RFC. label Nov 29, 2017
# Drawbacks
[drawbacks]: #drawbacks

When users start omitting bespoke `description()` implementations, code that still uses this method will get machine-generated rather than human-written descriptions, so success of this change depends also on steering authors away from using this method as well.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not also formally deprecate the method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • It could create too many warnings. Perhaps it would be OK to do it after a while?
  • Some projects may still like using a static string for description. I'm concerned about saving time users who don't want to use it, but don't want to get in the way of users who still want it.

Copy link
Member

Choose a reason for hiding this comment

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

I would like to see the method formally deprecated at some point, but I agree that we should give it several releases before doing so, and make sure it has minimal impact on the ecosystem.

Copy link

Choose a reason for hiding this comment

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

+1 for eventual formal deprecation

@jnicholls
Copy link

Totally agree on making this method optional/transparent/forgotten/deprecated/dismissed/booted/chopped/kicked/etc.

@aturon
Copy link
Member

aturon commented Feb 14, 2018

@withoutboats can you shepherd this RFC?

@withoutboats
Copy link
Contributor

Why not deprecate it also?

@Centril
Copy link
Contributor

Centril commented Feb 14, 2018

@withoutboats It might be just me... but .description() seems like a cheap way to describe error enums with unit-only-variants... There's always Debug, but a &str is cheaper..

To make .description() a bit more useful you could perhaps make it derivable?

@sfackler
Copy link
Member

@Centril can you point to some code that uses description in that way?

@Centril
Copy link
Contributor

Centril commented Feb 14, 2018

@sfackler Not really; If you have such a unit-variant enum, then I guess you can use an inherent method instead - the bound isn't important wrt. .description() here, and neither as a trait object.

# Reference-level explanation
[reference-level-explanation]: #reference-level-explanation

The description method can have default implementation returning `core::intrinsics::type_name::<Self>()`. This preserves basic functionality of this method for backwards compatibility.
Copy link
Member

Choose a reason for hiding this comment

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

Are we comfortable somewhat stabilizing type_name? This makes it at least somewhat easy to (abuse) this to get it's functionality on stable for non-error types in at least binaries where the impl of Error doesn't matter too much from an exposed API perspective.

Either way, we should explicitly state that this method's default return value is not stable and should not be relied on from version to version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simon's current PR just returns ""

kornelski added a commit to kornelski/book that referenced this pull request Apr 20, 2018
@U007D
Copy link

U007D commented Apr 20, 2018

Overall, I like this. Although I'm not sure why we'd steer people away from implementing .description() in documentation and not officially deprecate it. The rationale given:

... this RFC does not propose formal deprecation at this time to avoid unnecessary warnings during the transition.

would seem to apply any time any feature is deprecated, no? The above-mentioned warning would also serve to reinforce the updated documentation, essentially ensuring discovery.

Overall, things are currently a bit messier than I think we'd all like around errors and error handling--moving as swiftly as we can (but not recklessly) seems to me to be a good way to realizing the full potential of Rust's error handling--to that end, I'd (also) support official deprecation of .description().

Procedural question: Should I review with "change requested", or just leave this feedback as it is?

@repax
Copy link

repax commented Apr 20, 2018

I would like description() to be deprecated, or at least just return "". I think it's undesirable to expose identifier names (which are just source-code level entities).

The identifier name of a type should not have any consequence on its public output/effect - especially not by default.

@kornelski
Copy link
Contributor Author

kornelski commented Apr 21, 2018

What should the default message be? Type name is out. Empty string is out.

@repax
Copy link

repax commented Apr 21, 2018

Is is out of the question to have different outputs depending on whether dbg_print is enabled? If enabled, a more detailed description could be provided by the compiler, and if not a minimal default would be used. The developer can always add his/her own implementation, if necessary.

The default output for both the dbg_print and the non-dbg_print case could simply be left unspecified. That should be compatible with the current situation.

@kornelski
Copy link
Contributor Author

I'm thinking about making the message push authors towards switching to Display instead, so "description is deprecated" or "use Display instead" or "https://rust-lang.org/how-to-fix-descriptions"

@U007D
Copy link

U007D commented Apr 21, 2018

Hmm.. this is tricky! :)

".description() is deprecated--see https://rust-lang.org/how-to-fix-description" (along with explanatory content at that address) seems to be a reasonable default message to me, given the excellent points made by @repax and @Mark-Simulacrum. (Suggest singular 'description' in URL)

bors added a commit to rust-lang/rust that referenced this pull request Apr 30, 2018
Bury Error::description()

Second attempt of #49536 rust-lang/rfcs#2230

The exact wording of the default implementation is still up in the air, but I think it's a detail that can be amended later.
@kornelski
Copy link
Contributor Author

kornelski commented Apr 30, 2018

the implementation is merged!

done

# Drawbacks
[drawbacks]: #drawbacks

When users start omitting bespoke `description()` implementations, code that still uses this method will start getting empty strings instead of human-written description. If this becomes a problem, the `description()` method can also be formally deprecated (with the `#[deprecated]` attribute). However, there's no urgency to remove existing implementations of `description()`, so this RFC does not propose formal deprecation at this time to avoid unnecessary warnings during the transition.
Copy link

@U007D U007D Apr 30, 2018

Choose a reason for hiding this comment

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

...code that still uses this method will start getting empty strings instead of human-written description

No longer--the implementation merged into master now returns "description() is deprecated; use Display" as a default message.

Suggest: s/empty strings/.description() deprecated message

@U007D
Copy link

U007D commented Apr 30, 2018

I have no power... :)

@alexcrichton alexcrichton merged commit 01434ea into rust-lang:master May 3, 2018
@alexcrichton
Copy link
Member

It turns out that the implementation for this RFC has already merged! In light of that I'm going to go ahead and merge the RFC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-error-handling Proposals relating to error handling. A-traits-libstd Standard library trait related proposals & ideas T-libs-api Relevant to the library API team, which will review and decide on the RFC.
Projects
None yet
Development

Successfully merging this pull request may close these issues.