Commit Graph

133 Commits

Author SHA1 Message Date
Tim Diekmann
56cbf2f22a Overhaul of the AllocRef trait to match allocator-wg's latest consens 2020-03-26 17:10:54 +01:00
Marti Raudsepp
1d004bddee Fix deprecated Error.description() usage in docs 2020-03-21 12:33:52 +02:00
Mazdak Farrokhzad
d21320cbd9
Rollup merge of #69792 - LenaWil:try_reserve_error/impl-error, r=sfackler
Implement Error for TryReserveError

I noticed that the Error trait wasn't implemented for TryReserveError. (#48043)

Not sure if the error messages and code style are 100% correct, it's my first time contributing to the Rust std.
2020-03-12 16:32:21 +01:00
Lena Wildervanck
88f8b88160 Remove deprecated description function of TryReserveError 2020-03-10 11:19:40 +01:00
Lena Wildervanck
b900de0f77 Implement Error for TryReserveError 2020-03-07 00:59:25 +01:00
Dylan Nugent
9afbf28ef6 Update deprecation version to 1.42 for Error::description
Error::description is deprecated as of version 1.42, as the commit was
not in the release for 1.41.
2020-03-05 21:55:36 -05:00
Lzu Tao
5f3f1a3606 inline impl From<String> for Box<dyn Error + Send + Sync> 2020-01-10 19:27:02 +00:00
David Tolnay
4646a88b7a
Deprecate Error::description for real
`description` has been documented as soft-deprecated since 1.27.0 (17
months ago). There is no longer any reason to call it or implement it.

This commit:

- adds #[rustc_deprecated(since = "1.41.0")] to Error::description;

- moves description (and cause, which is also deprecated) below the
  source and backtrace methods in the Error trait;

- reduces documentation of description and cause to take up much less
  vertical real estate in rustdocs, while preserving the example that
  shows how to render errors without needing to call description;

- removes the description function of all *currently unstable* Error
  impls in the standard library;

- marks #[allow(deprecated)] the description function of all *stable*
  Error impls in the standard library;

- replaces miscellaneous uses of description in example code and the
  compiler.
2019-12-24 22:39:49 -08:00
Mazdak Farrokhzad
75b27ef59c
Rollup merge of #67561 - euclio:remove-description, r=jonas-schievink
remove `description` from `Error` impls in docs

Since `description` is soft-deprecated, there's no need to show it implemented in these examples.
2019-12-24 04:40:00 +01:00
Andy Russell
24f3dcfdc7
remove description from Error impls in docs 2019-12-23 09:47:28 -06:00
Mark Rousskov
a06baa56b9 Format the world 2019-12-22 17:42:47 -05:00
Niko Matsakis
d286113024 Revert "Stabilize the never_type, written !."
This reverts commit 15c30ddd69.
2019-12-14 09:01:09 -05:00
Niko Matsakis
ca8154861e Revert "Redefine core::convert::Infallible as !."
This reverts commit 089229a193.
2019-12-14 09:00:49 -05:00
Brian Wignall
16fabd8efd Fix spelling typos 2019-11-26 22:19:54 -05:00
Mazdak Farrokhzad
089229a193 Redefine core::convert::Infallible as !. 2019-11-21 14:55:33 +01:00
Mazdak Farrokhzad
15c30ddd69 Stabilize the never_type, written !. 2019-11-21 14:55:32 +01:00
Harald Hoyer
de122e673a
std::error::Chain: remove Copy
remove Copy from Iterator as per comment
https://github.com/rust-lang/rust/issues/58520#issuecomment-553682166
2019-11-18 09:01:34 +01:00
Harald Hoyer
7b9d50d14d rename Error::iter_chain() and remove Error::iter_sources()
Rename
* Error::iter_chain() -> Error::chain()
* ErrorIter -> Chain

Removed
* Error::iter_sources()

according to
https://github.com/rust-lang/rust/issues/58520

Rationale:

   1. Such iterators are helpful. They should better be stabilized sooner
      than later.
   2. self should be included. It is easy to .skip(1) it.
      Not including self is harmful because it is harder to add self
      to the iterator than to remove it.
   3. The chosen name should be telling and reflect the fact that self is
      included. `.chain()` was chosen because the iterator iterates over
      the chain of errors that is somehow included in self.
   4. The resulting iterator is named `Chain` because the `error::Chain`
      is what we want to have.
2019-10-22 16:52:05 +02:00
BO41
37018e0f9b Fix typos in error.rs 2019-10-13 12:12:46 +02:00
Mazdak Farrokhzad
afc52916f6
Rollup merge of #64203 - alexreg:rush-pr-2, r=centril
A few cosmetic improvements to code & comments in liballoc and libcore

Factored out from hacking on rustc for work on the REPL.

r? @Centril
2019-09-14 16:42:22 +02:00
Alex Crichton
34662c6961 std: Add a backtrace module
This commit adds a `backtrace` module to the standard library, as
designed in [RFC 2504]. The `Backtrace` type is intentionally very
conservative, effectively only allowing capturing it and printing it.

Additionally this commit also adds a `backtrace` method to the `Error`
trait which defaults to returning `None`, as specified in [RFC 2504].
More information about the design here can be found in [RFC 2504] and in
the [tracking issue].

Implementation-wise this is all based on the `backtrace` crate and very
closely mirrors the `backtrace::Backtrace` type on crates.io. Otherwise
it's pretty standard in how it handles everything internally.

[RFC 2504]: https://github.com/rust-lang/rfcs/blob/master/text/2504-fix-error.md
[tracking issue]: https://github.com/rust-lang/rust/issues/53487

cc #53487
2019-09-09 08:20:34 -07:00
Alexander Regueiro
b0006dff10 A few cosmetic improvements to code & comments in liballoc and libcore 2019-09-06 16:02:25 +01:00
Vadim Petrochenkov
8eaf17bca2 Introduce built-in macros through libcore 2019-07-26 13:09:54 +03:00
s3bk
8951cb5c40 implement Error::source for Box<T: Error>
fixes https://github.com/rust-lang/rust/issues/61899
2019-06-17 11:24:09 +03:00
Pietro Albini
eebe62aaa1
Rollup merge of #60897 - seanmonstar:patch-4, r=sfackler
error: remove StringError from Debug output

Seeing `StringError("something something")` in debug output can cause
 someone to think there was an error dealing with `String`s, not that the
error type is just a string. So, remove that noise.

For example:

```
io error: Custom { kind: InvalidData, error: StringError("corrupt data") }
```

With this change:

```
io error: Custom { kind: InvalidData, error: "corrupt data" }
```
2019-05-31 13:33:51 +02:00
memoryruins
83660b6273 Update libstd doctests to use dyn 2019-05-29 00:57:42 -04:00
Mazdak Farrokhzad
a34dae3587
Rollup merge of #60511 - taiki-e:libstd-intra-doc, r=Dylan-DPC
Fix intra-doc link resolution failure on re-exporting libstd

Currently, re-exporting libstd items as below will [occur a lot of failures](https://gist.github.com/taiki-e/e33e0e8631ef47f65a74a3b69f456366).
```rust
pub use std::*;
```

Until the underlying issue (#56922) fixed, we can fix that so they don't propagate to downstream crates.

Related: https://github.com/rust-lang/rust/pull/56941 (That PR fixed failures that occur when re-exporting from libcore to libstd.)

r? @QuietMisdreavus
2019-05-20 23:02:59 +02:00
Steven Fackler
686a611b9e
Update src/libstd/error.rs
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-05-16 20:18:29 -07:00
Steven Fackler
e836a4cd79 Prevent Error::type_id overrides
type_id now takes an argument that can't be named outside of the
std::error module, which prevents any implementations from overriding
it. It's a pretty grody solution, and there's no way we can stabilize
the method with this API, but it avoids the soudness issue!

Closes #60784
2019-05-16 19:48:13 -07:00
Sean McArthur
d2d89b10de error: remove StringError from Debug output
Seeing `StringError("something something")` in debug output can cause
 someone to think there was an error dealing with `String`s, not that the
error type is just a string. So, remove that noise.
2019-05-16 17:37:43 -07:00
Alex Crichton
c47e2ef8d4 Destabilize the Error::type_id function
This commit destabilizes the `Error::type_id` function in the standard library.
This does so by effectively reverting #58048, restoring the `#[unstable]`
attribute. The security mailing list has recently been notified of a
vulnerability relating to the stabilization of this function. First stabilized
in Rust 1.34.0, a stable function here allows users to implement a custom
return value for this function:

    struct MyType;

    impl Error for MyType {
	fn type_id(&self) -> TypeId {
	    // Enable safe casting to `String` by accident.
	    TypeId::of::<String>()
	}
    }

This, when combined with the `Error::downcast` family of functions, allows
safely casting a type to any other type, clearly a memory safety issue! A
security announcement will be shortly posted to the security mailing list as
well as the Rust Blog, and when those links are available they'll be filled in
for this PR as well.

This commit simply destabilizes the `Error::type_id` which, although breaking
for users since Rust 1.34.0, is hoped to have little impact and has been deemed
sufficient to mitigate this issue for the stable channel. The long-term fate of
the `Error::type_id` API will be discussed at #60784.
2019-05-13 08:18:37 -07:00
Taiki Endo
ccb9dac5ed Fix intra-doc link resolution failure on re-exporting libstd 2019-05-04 23:48:57 +09:00
Mazdak Farrokhzad
34454451a1
Rollup merge of #59587 - XAMPPRocky:master, r=Centril
Remove #[doc(hidden)] from Error::type_id

Nominating this for beta so that `Error::type_id` has documentation in time for release.

cc @rust-lang/release @rust-lang/docs
2019-03-31 19:19:56 +02:00
Aaron Power
c056a79f35 Remove #[doc(hidden)] from Error::type_id 2019-03-31 16:54:05 +02:00
Mazdak Farrokhzad
379c380a60 libstd: deny(elided_lifetimes_in_paths) 2019-03-31 12:56:51 +02:00
Scott McMurray
df4ea90b39 Use lifetime contravariance to elide more lifetimes in core+alloc+std 2019-03-09 19:10:28 -08:00
Taiki Endo
93b6d9e086 libstd => 2018 2019-02-28 04:06:15 +09:00
bors
00aae71f50 Auto merge of #58302 - SimonSapin:tryfrom, r=alexcrichton
Stabilize TryFrom and TryInto with a convert::Infallible empty enum

This is the plan proposed in https://github.com/rust-lang/rust/issues/33417#issuecomment-423073898
2019-02-25 20:24:10 +00:00
Steven Fackler
3ba6177515 Fix tracking issue for error iterators 2019-02-16 12:16:18 -08:00
Simon Sapin
c80a8f51dc Stabilize TryFrom and TryInto 2019-02-13 18:00:18 +01:00
Mazdak Farrokhzad
5aa260a4b5
Rollup merge of #58289 - haraldh:master, r=sfackler
impl iter() for dyn Error

Examples:

```rust
let next_error_type_a = err
    .iter()
    .filter_map(Error::downcast_ref::<ErrorTypeA>)
    .next();
```

```rust
let source_root_error = err.iter().last();
```

Credit for the ErrorIter goes to reddit user /u/tdiekmann (Tim Diekmann)
https://www.reddit.com/r/rust/comments/aj3lpg/is_an_iterator_impl_over_errorsource_possible/
2019-02-13 04:37:05 +01:00
Alexander Regueiro
99ed06eb88 libs: doc comments 2019-02-10 23:57:25 +00:00
Harald Hoyer
f06af1ff17
impl iter_sources() and iter_chain() for dyn Error
Examples:

```rust
let next_error_type_a = err
    .iter_chain()
    .filter_map(Error::downcast_ref::<ErrorTypeA>)
    .next();
```

```rust
let source_root_error = err.iter_chain().last();
```

Credit for the ErrorIter goes to Tim Diekmann
https://www.reddit.com/r/rust/comments/aj3lpg/is_an_iterator_impl_over_errorsource_possible/
2019-02-09 16:04:25 +01:00
Simon Sapin
cc1e05f0ca Stabilize std::error::Error::type_id
This should have been part of https://github.com/rust-lang/rust/pull/57834

FCP: https://github.com/rust-lang/rust/issues/27745#issuecomment-373906749
2019-02-01 11:29:02 +01:00
Czipperz
564a24c772 Change std::error::Error trait documentation to talk about source instead of cause 2019-01-08 17:45:54 -05:00
Mark Rousskov
2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
Alex Crichton
cf47a19305 Bump to 1.33.0
* Update bootstrap compiler
* Update version to 1.33.0
* Remove some `#[cfg(stage0)]` annotations

Actually updating the version number is blocked on updating Cargo
2018-12-12 08:09:26 -08:00
Alexander Regueiro
ee89c088b0 Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
Pietro Albini
1dbc8b0d4b
Rollup merge of #53523 - phungleson:fix-impl-from-for-std-error, r=GuillaumeGomez
Add doc for impl From for Std Error

As part of issue #51430 (cc @skade).

I am not sure if it is going to a correct direction so put up here so that people can comment.
2018-10-04 12:20:05 +02:00
Son
30f2e96ab1 Remove main() in examples 2018-10-03 08:21:51 +10:00