From 4f9807a03728b5c695c14182bf104f296f357531 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 2 Sep 2018 18:50:39 +0200 Subject: [PATCH] [PATCH] Disable all trait object unsizing --- 0006-Disable-all-trait-object-unsizing.patch | 137 +++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 0006-Disable-all-trait-object-unsizing.patch diff --git a/0006-Disable-all-trait-object-unsizing.patch b/0006-Disable-all-trait-object-unsizing.patch new file mode 100644 index 000000000000..96226073ce3f --- /dev/null +++ b/0006-Disable-all-trait-object-unsizing.patch @@ -0,0 +1,137 @@ +From 307aba455c6ee3227d7c522c07761cda19dc716c Mon Sep 17 00:00:00 2001 +From: bjorn3 +Date: Wed, 29 Aug 2018 14:29:05 +0200 +Subject: [PATCH] Disable all trait object unsizing + +--- + src/libcore/alloc.rs | 2 +- + src/libcore/fmt/builders.rs | 13 ++++++++----- + src/libcore/fmt/mod.rs | 3 ++- + src/libcore/panic.rs | 5 +++-- + src/libcore/slice/mod.rs | 2 +- + 5 files changed, 15 insertions(+), 10 deletions(-) + +diff --git a/src/libcore/alloc.rs b/src/libcore/alloc.rs +index 35e4eea..28b6e2f 100644 +--- a/src/libcore/alloc.rs ++++ b/src/libcore/alloc.rs +@@ -144,7 +144,7 @@ impl Layout { + #[stable(feature = "alloc_layout", since = "1.28.0")] + #[inline] + pub fn for_value(t: &T) -> Self { +- let (size, align) = (mem::size_of_val(t), mem::align_of_val(t)); ++ let (size, align) = panic!(); //(mem::size_of_val(t), mem::align_of_val(t)); + // See rationale in `new` for why this us using an unsafe variant below + debug_assert!(Layout::from_size_align(size, align).is_ok()); + unsafe { +diff --git a/src/libcore/fmt/builders.rs b/src/libcore/fmt/builders.rs +index 3c5f934..1427ab3 100644 +--- a/src/libcore/fmt/builders.rs ++++ b/src/libcore/fmt/builders.rs +@@ -18,6 +18,7 @@ struct PadAdapter<'a> { + impl<'a> PadAdapter<'a> { + fn wrap<'b, 'c: 'a+'b>(fmt: &'c mut fmt::Formatter, slot: &'b mut Option) + -> fmt::Formatter<'b> { ++ /* + fmt.wrap_buf(move |buf| { + *slot = Some(PadAdapter { + buf, +@@ -25,6 +26,8 @@ impl<'a> PadAdapter<'a> { + }); + slot.as_mut().unwrap() + }) ++ */ ++ panic!(); + } + } + +@@ -107,7 +110,7 @@ pub fn debug_struct_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>, + impl<'a, 'b: 'a> DebugStruct<'a, 'b> { + /// Adds a new field to the generated struct output. + #[stable(feature = "debug_builders", since = "1.2.0")] +- pub fn field(&mut self, name: &str, value: &dyn fmt::Debug) -> &mut DebugStruct<'a, 'b> { ++ pub fn field(&mut self, name: &str, value: &impl fmt::Debug) -> &mut DebugStruct<'a, 'b> { + self.result = self.result.and_then(|_| { + let prefix = if self.has_fields { + "," +@@ -204,7 +207,7 @@ pub fn debug_tuple_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>, name: &str) -> D + impl<'a, 'b: 'a> DebugTuple<'a, 'b> { + /// Adds a new field to the generated tuple struct output. + #[stable(feature = "debug_builders", since = "1.2.0")] +- pub fn field(&mut self, value: &dyn fmt::Debug) -> &mut DebugTuple<'a, 'b> { ++ pub fn field(&mut self, value: &impl fmt::Debug) -> &mut DebugTuple<'a, 'b> { + self.result = self.result.and_then(|_| { + let (prefix, space) = if self.fields > 0 { + (",", " ") +@@ -258,7 +261,7 @@ struct DebugInner<'a, 'b: 'a> { + } + + impl<'a, 'b: 'a> DebugInner<'a, 'b> { +- fn entry(&mut self, entry: &dyn fmt::Debug) { ++ fn entry(&mut self, entry: &impl fmt::Debug) { + self.result = self.result.and_then(|_| { + if self.is_pretty() { + let mut slot = None; +@@ -340,7 +343,7 @@ pub fn debug_set_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugSet<'a, 'b + impl<'a, 'b: 'a> DebugSet<'a, 'b> { + /// Adds a new entry to the set output. + #[stable(feature = "debug_builders", since = "1.2.0")] +- pub fn entry(&mut self, entry: &dyn fmt::Debug) -> &mut DebugSet<'a, 'b> { ++ pub fn entry(&mut self, entry: &impl fmt::Debug) -> &mut DebugSet<'a, 'b> { + self.inner.entry(entry); + self + } +@@ -411,7 +414,7 @@ pub fn debug_list_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugList<'a, + impl<'a, 'b: 'a> DebugList<'a, 'b> { + /// Adds a new entry to the list output. + #[stable(feature = "debug_builders", since = "1.2.0")] +- pub fn entry(&mut self, entry: &dyn fmt::Debug) -> &mut DebugList<'a, 'b> { ++ pub fn entry(&mut self, entry: &impl fmt::Debug) -> &mut DebugList<'a, 'b> { + self.inner.entry(entry); + self + } +diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs +index 928f95e..ad33906 100644 +--- a/src/libcore/fmt/mod.rs ++++ b/src/libcore/fmt/mod.rs +@@ -224,7 +224,8 @@ pub trait Write { + } + } + +- write(&mut Adapter(self), args) ++ //write(&mut Adapter(self), args) ++ panic!() + } + } + +diff --git a/src/libcore/panic.rs b/src/libcore/panic.rs +index 17cac5a..27b7dde 100644 +--- a/src/libcore/panic.rs ++++ b/src/libcore/panic.rs +@@ -58,8 +58,9 @@ impl<'a> PanicInfo<'a> { + pub fn internal_constructor(message: Option<&'a fmt::Arguments<'a>>, + location: Location<'a>) + -> Self { +- struct NoPayload; +- PanicInfo { payload: &NoPayload, location, message } ++ //struct NoPayload; ++ //PanicInfo { payload: &NoPayload, location, message } ++ panic!(); + } + + #[doc(hidden)] +diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs +index 88fdd76..8537f0e 100644 +--- a/src/libcore/slice/mod.rs ++++ b/src/libcore/slice/mod.rs +@@ -4003,7 +4003,7 @@ impl SlicePartialEq for [A] + return true; + } + unsafe { +- let size = mem::size_of_val(self); ++ let size = panic!(); //mem::size_of_val(self); + memcmp(self.as_ptr() as *const u8, + other.as_ptr() as *const u8, size) == 0 + } +-- +2.11.0