diff options
| author | bors <bors@rust-lang.org> | 2019-05-17 20:02:13 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-05-17 20:02:13 +0000 |
| commit | 73a3a90d25ddb3be3d0ad2238dbb55ae79e459dc (patch) | |
| tree | 010c00a2f10b722cee1ffd7349450594941fc825 /src/libstd/error.rs | |
| parent | 823a75d9ba34860b9a6712c7a9d35e86e0a88436 (diff) | |
| parent | f48f37b052bd2683ff89037001d794f5ffac9e5b (diff) | |
| download | rust-73a3a90d25ddb3be3d0ad2238dbb55ae79e459dc.tar.gz rust-73a3a90d25ddb3be3d0ad2238dbb55ae79e459dc.zip | |
Auto merge of #60920 - Manishearth:rollup-p4xp4gk, r=Manishearth
Rollup of 4 pull requests Successful merges: - #60791 (Update books) - #60891 (Allow claiming issues with triagebot) - #60901 (Handle more string addition cases with appropriate suggestions) - #60902 (Prevent Error::type_id overrides) Failed merges: r? @ghost
Diffstat (limited to 'src/libstd/error.rs')
| -rw-r--r-- | src/libstd/error.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 7cb830e751a..62282006a40 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -201,11 +201,19 @@ pub trait Error: Debug + Display { #[unstable(feature = "error_type_id", reason = "this is memory unsafe to override in user code", issue = "60784")] - fn type_id(&self) -> TypeId where Self: 'static { + fn type_id(&self, _: private::Internal) -> TypeId where Self: 'static { TypeId::of::<Self>() } } +mod private { + // This is a hack to prevent `type_id` from being overridden by `Error` + // implementations, since that can enable unsound downcasting. + #[unstable(feature = "error_type_id", issue = "60784")] + #[derive(Debug)] + pub struct Internal; +} + #[stable(feature = "rust1", since = "1.0.0")] impl<'a, E: Error + 'a> From<E> for Box<dyn Error + 'a> { /// Converts a type of [`Error`] into a box of dyn [`Error`]. @@ -575,7 +583,7 @@ impl dyn Error + 'static { let t = TypeId::of::<T>(); // Get TypeId of the type in the trait object - let boxed = self.type_id(); + let boxed = self.type_id(private::Internal); // Compare both TypeIds on equality t == boxed |
