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

Conversation

@kornelski
Copy link
Contributor

kornelski commented Nov 29, 2017

Rendered

Thread on internals

@nagisa

This comment has been minimized.

Copy link
Contributor

nagisa commented 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.

This comment has been minimized.

@durka

durka Nov 29, 2017

Contributor

Why not also formally deprecate the method?

This comment has been minimized.

@kornelski

kornelski Nov 29, 2017

Author Contributor
  • 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.

This comment has been minimized.

@joshtriplett

joshtriplett Nov 30, 2017

Member

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.

This comment has been minimized.

@U007D

U007D Dec 1, 2017

+1 for eventual formal deprecation

@jnicholls

This comment has been minimized.

Copy link

jnicholls commented Nov 30, 2017

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

@aturon

This comment has been minimized.

Copy link
Member

aturon commented Feb 14, 2018

@withoutboats can you shepherd this RFC?

@withoutboats

This comment has been minimized.

Copy link
Contributor

withoutboats commented Feb 14, 2018

Why not deprecate it also?

@Centril

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

sfackler commented Feb 14, 2018

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

@Centril

This comment has been minimized.

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.

This comment has been minimized.

@Mark-Simulacrum

Mark-Simulacrum Apr 20, 2018

Member

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.

This comment has been minimized.

@kornelski

kornelski Apr 20, 2018

Author Contributor

Simon's current PR just returns ""

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

@U007D

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor Author

kornelski commented Apr 21, 2018

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

@repax

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor Author

kornelski commented Apr 21, 2018

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

This comment has been minimized.

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

Auto merge of #50163 - kornelski:error, r=Kimundi
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

This comment has been minimized.

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.

This comment has been minimized.

@U007D

U007D Apr 30, 2018

...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

U007D approved these changes Apr 30, 2018

@U007D

U007D approved these changes Apr 30, 2018

@U007D

This comment has been minimized.

Copy link

U007D commented Apr 30, 2018

I have no power... :)

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

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented May 3, 2018

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
You can’t perform that action at this time.