|
1 | 1 | use crate::convert::{TryFrom, TryInto};
|
2 | 2 | use crate::intrinsics::assert_unsafe_precondition;
|
3 | 3 | use crate::num::NonZeroUsize;
|
4 |
| -use crate::{cmp, fmt, hash, mem, num, str}; |
| 4 | +use crate::{cmp, fmt, hash, mem, num}; |
5 | 5 |
|
6 | 6 | /// A type storing a `usize` which is a power of two, and thus
|
7 | 7 | /// represents a possible alignment in the rust abstract machine.
|
@@ -163,92 +163,6 @@ impl fmt::Debug for Alignment {
|
163 | 163 | }
|
164 | 164 | }
|
165 | 165 |
|
166 |
| -#[unstable(feature = "ptr_alignment_type", issue = "102070")] |
167 |
| -impl fmt::Display for Alignment { |
168 |
| - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
169 |
| - fmt::Display::fmt(&self.as_nonzero(), f) |
170 |
| - } |
171 |
| -} |
172 |
| - |
173 |
| -#[unstable(feature = "ptr_alignment_type", issue = "102070")] |
174 |
| -impl fmt::Binary for Alignment { |
175 |
| - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
176 |
| - fmt::Binary::fmt(&self.as_nonzero(), f) |
177 |
| - } |
178 |
| -} |
179 |
| - |
180 |
| -#[unstable(feature = "ptr_alignment_type", issue = "102070")] |
181 |
| -impl fmt::Octal for Alignment { |
182 |
| - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
183 |
| - fmt::Octal::fmt(&self.as_nonzero(), f) |
184 |
| - } |
185 |
| -} |
186 |
| - |
187 |
| -#[unstable(feature = "ptr_alignment_type", issue = "102070")] |
188 |
| -impl fmt::LowerHex for Alignment { |
189 |
| - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
190 |
| - fmt::LowerHex::fmt(&self.as_nonzero(), f) |
191 |
| - } |
192 |
| -} |
193 |
| - |
194 |
| -#[unstable(feature = "ptr_alignment_type", issue = "102070")] |
195 |
| -impl fmt::UpperHex for Alignment { |
196 |
| - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
197 |
| - fmt::UpperHex::fmt(&self.as_nonzero(), f) |
198 |
| - } |
199 |
| -} |
200 |
| - |
201 |
| -impl Alignment { |
202 |
| - // longest string: 1p-128 |
203 |
| - fn fmt_exp(self, buf: &mut [u8; 6], p: u8) -> &[u8] { |
204 |
| - buf[0] = b'1'; |
205 |
| - buf[1] = p; |
206 |
| - |
207 |
| - let mut shl = self.log2() as u8; |
208 |
| - if shl == 0 { |
209 |
| - buf[2] = b'0'; |
210 |
| - return &buf[..3]; |
211 |
| - } |
212 |
| - |
213 |
| - buf[2] = b'-'; |
214 |
| - if shl > 100 { |
215 |
| - buf[5] = b'0' + shl % 10; |
216 |
| - shl /= 10; |
217 |
| - buf[4] = b'0' + shl % 10; |
218 |
| - shl /= 10; |
219 |
| - buf[3] = b'0' + shl % 10; |
220 |
| - &buf[..6] |
221 |
| - } else if shl > 10 { |
222 |
| - buf[4] = b'0' + shl % 10; |
223 |
| - shl /= 10; |
224 |
| - buf[3] = b'0' + shl % 10; |
225 |
| - &buf[..5] |
226 |
| - } else { |
227 |
| - buf[3] = b'0' + shl % 10; |
228 |
| - &buf[..4] |
229 |
| - } |
230 |
| - } |
231 |
| -} |
232 |
| - |
233 |
| -#[unstable(feature = "ptr_alignment_type", issue = "102070")] |
234 |
| -impl fmt::LowerExp for Alignment { |
235 |
| - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
236 |
| - let mut buf = [0; 6]; |
237 |
| - |
238 |
| - // SAFETY: We generate an ASCII string, which is valid UTF-8. |
239 |
| - f.pad(unsafe { str::from_utf8_unchecked(self.fmt_exp(&mut buf, b'p')) }) |
240 |
| - } |
241 |
| -} |
242 |
| - |
243 |
| -#[unstable(feature = "ptr_alignment_type", issue = "102070")] |
244 |
| -impl fmt::UpperExp for Alignment { |
245 |
| - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
246 |
| - let mut buf = [0; 6]; |
247 |
| - // SAFETY: We generate an ASCII string, which is valid UTF-8. |
248 |
| - f.pad(unsafe { str::from_utf8_unchecked(self.fmt_exp(&mut buf, b'P')) }) |
249 |
| - } |
250 |
| -} |
251 |
| - |
252 | 166 | #[unstable(feature = "ptr_alignment_type", issue = "102070")]
|
253 | 167 | impl TryFrom<NonZeroUsize> for Alignment {
|
254 | 168 | type Error = num::TryFromIntError;
|
|
0 commit comments