| author | bors <bors@rust-lang.org> 2024-05-15 12:43:34 UTC |
| committer | bors <bors@rust-lang.org> 2024-05-15 12:43:34 UTC |
| log | ade234d5743795423db6cc7cd52541390a088eab |
| tree | 162aa1667fea17a9ea7200db43923c1d1c16de34 |
| parent | 3cb0030fe9de01eeacb7c03eeef0c51420798cfb |
| parent | 8d38f2fb11d3536639d1aa0d641e60e1f7dfe64e |
Rollup of 6 pull requests
Successful merges:
- #124307 (Optimize character escaping.)
- #124975 (Use an helper to move the files)
- #125027 (Migrate `run-make/c-link-to-rust-staticlib` to `rmake`)
- #125038 (Invert comparison in `uN::checked_sub`)
- #125104 (Migrate `run-make/no-cdylib-as-rdylib` to `rmake`)
- #125137 (MIR operators: clarify Shl/Shr handling of negative offsets)
r? `@ghost`
`@rustbot` modify labels: rollup15 files changed, 190 insertions(+), 125 deletions(-)
compiler/rustc_middle/src/mir/syntax.rs+6-2| ... | ... | @@ -1480,13 +1480,17 @@ pub enum BinOp { |
| 1480 | 1480 | BitOr, |
| 1481 | 1481 | /// The `<<` operator (shift left) |
| 1482 | 1482 | /// |
| 1483 | /// The offset is truncated to the size of the first operand and made unsigned before shifting. | |
| 1483 | /// The offset is (uniquely) determined as follows: | |
| 1484 | /// - it is "equal modulo LHS::BITS" to the RHS | |
| 1485 | /// - it is in the range `0..LHS::BITS` | |
| 1484 | 1486 | Shl, |
| 1485 | 1487 | /// Like `Shl`, but is UB if the RHS >= LHS::BITS or RHS < 0 |
| 1486 | 1488 | ShlUnchecked, |
| 1487 | 1489 | /// The `>>` operator (shift right) |
| 1488 | 1490 | /// |
| 1489 | /// The offset is truncated to the size of the first operand and made unsigned before shifting. | |
| 1491 | /// The offset is (uniquely) determined as follows: | |
| 1492 | /// - it is "equal modulo LHS::BITS" to the RHS | |
| 1493 | /// - it is in the range `0..LHS::BITS` | |
| 1490 | 1494 | /// |
| 1491 | 1495 | /// This is an arithmetic shift if the LHS is signed |
| 1492 | 1496 | /// and a logical shift if the LHS is unsigned. |
library/core/src/ascii.rs+9-5| ... | ... | @@ -91,17 +91,21 @@ pub struct EscapeDefault(escape::EscapeIterInner<4>); |
| 91 | 91 | /// ``` |
| 92 | 92 | #[stable(feature = "rust1", since = "1.0.0")] |
| 93 | 93 | pub fn escape_default(c: u8) -> EscapeDefault { |
| 94 | let mut data = [Char::Null; 4]; | |
| 95 | let range = escape::escape_ascii_into(&mut data, c); | |
| 96 | EscapeDefault(escape::EscapeIterInner::new(data, range)) | |
| 94 | EscapeDefault::new(c) | |
| 97 | 95 | } |
| 98 | 96 | |
| 99 | 97 | impl EscapeDefault { |
| 98 | #[inline] | |
| 99 | pub(crate) const fn new(c: u8) -> Self { | |
| 100 | Self(escape::EscapeIterInner::ascii(c)) | |
| 101 | } | |
| 102 | ||
| 103 | #[inline] | |
| 100 | 104 | pub(crate) fn empty() -> Self { |
| 101 | let data = [Char::Null; 4]; | |
| 102 | EscapeDefault(escape::EscapeIterInner::new(data, 0..0)) | |
| 105 | Self(escape::EscapeIterInner::empty()) | |
| 103 | 106 | } |
| 104 | 107 | |
| 108 | #[inline] | |
| 105 | 109 | pub(crate) fn as_str(&self) -> &str { |
| 106 | 110 | self.0.as_str() |
| 107 | 111 | } |
library/core/src/char/methods.rs+4-4| ... | ... | @@ -449,10 +449,10 @@ impl char { |
| 449 | 449 | '\"' if args.escape_double_quote => EscapeDebug::backslash(ascii::Char::QuotationMark), |
| 450 | 450 | '\'' if args.escape_single_quote => EscapeDebug::backslash(ascii::Char::Apostrophe), |
| 451 | 451 | _ if args.escape_grapheme_extended && self.is_grapheme_extended() => { |
| 452 | EscapeDebug::from_unicode(self.escape_unicode()) | |
| 452 | EscapeDebug::unicode(self) | |
| 453 | 453 | } |
| 454 | 454 | _ if is_printable(self) => EscapeDebug::printable(self), |
| 455 | _ => EscapeDebug::from_unicode(self.escape_unicode()), | |
| 455 | _ => EscapeDebug::unicode(self), | |
| 456 | 456 | } |
| 457 | 457 | } |
| 458 | 458 | |
| ... | ... | @@ -555,9 +555,9 @@ impl char { |
| 555 | 555 | '\t' => EscapeDefault::backslash(ascii::Char::SmallT), |
| 556 | 556 | '\r' => EscapeDefault::backslash(ascii::Char::SmallR), |
| 557 | 557 | '\n' => EscapeDefault::backslash(ascii::Char::SmallN), |
| 558 | '\\' | '\'' | '"' => EscapeDefault::backslash(self.as_ascii().unwrap()), | |
| 558 | '\\' | '\'' | '\"' => EscapeDefault::backslash(self.as_ascii().unwrap()), | |
| 559 | 559 | '\x20'..='\x7e' => EscapeDefault::printable(self.as_ascii().unwrap()), |
| 560 | _ => EscapeDefault::from_unicode(self.escape_unicode()), | |
| 560 | _ => EscapeDefault::unicode(self), | |
| 561 | 561 | } |
| 562 | 562 | } |
| 563 | 563 |
library/core/src/char/mod.rs+23-21| ... | ... | @@ -152,10 +152,9 @@ pub const fn from_digit(num: u32, radix: u32) -> Option<char> { |
| 152 | 152 | pub struct EscapeUnicode(escape::EscapeIterInner<10>); |
| 153 | 153 | |
| 154 | 154 | impl EscapeUnicode { |
| 155 | fn new(chr: char) -> Self { | |
| 156 | let mut data = [ascii::Char::Null; 10]; | |
| 157 | let range = escape::escape_unicode_into(&mut data, chr); | |
| 158 | Self(escape::EscapeIterInner::new(data, range)) | |
| 155 | #[inline] | |
| 156 | const fn new(c: char) -> Self { | |
| 157 | Self(escape::EscapeIterInner::unicode(c)) | |
| 159 | 158 | } |
| 160 | 159 | } |
| 161 | 160 | |
| ... | ... | @@ -219,18 +218,19 @@ impl fmt::Display for EscapeUnicode { |
| 219 | 218 | pub struct EscapeDefault(escape::EscapeIterInner<10>); |
| 220 | 219 | |
| 221 | 220 | impl EscapeDefault { |
| 222 | fn printable(chr: ascii::Char) -> Self { | |
| 223 | let data = [chr]; | |
| 224 | Self(escape::EscapeIterInner::from_array(data)) | |
| 221 | #[inline] | |
| 222 | const fn printable(c: ascii::Char) -> Self { | |
| 223 | Self(escape::EscapeIterInner::ascii(c.to_u8())) | |
| 225 | 224 | } |
| 226 | 225 | |
| 227 | fn backslash(chr: ascii::Char) -> Self { | |
| 228 | let data = [ascii::Char::ReverseSolidus, chr]; | |
| 229 | Self(escape::EscapeIterInner::from_array(data)) | |
| 226 | #[inline] | |
| 227 | const fn backslash(c: ascii::Char) -> Self { | |
| 228 | Self(escape::EscapeIterInner::backslash(c)) | |
| 230 | 229 | } |
| 231 | 230 | |
| 232 | fn from_unicode(esc: EscapeUnicode) -> Self { | |
| 233 | Self(esc.0) | |
| 231 | #[inline] | |
| 232 | const fn unicode(c: char) -> Self { | |
| 233 | Self(escape::EscapeIterInner::unicode(c)) | |
| 234 | 234 | } |
| 235 | 235 | } |
| 236 | 236 | |
| ... | ... | @@ -304,23 +304,24 @@ enum EscapeDebugInner { |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | impl EscapeDebug { |
| 307 | fn printable(chr: char) -> Self { | |
| 307 | #[inline] | |
| 308 | const fn printable(chr: char) -> Self { | |
| 308 | 309 | Self(EscapeDebugInner::Char(chr)) |
| 309 | 310 | } |
| 310 | 311 | |
| 311 | fn backslash(chr: ascii::Char) -> Self { | |
| 312 | let data = [ascii::Char::ReverseSolidus, chr]; | |
| 313 | let iter = escape::EscapeIterInner::from_array(data); | |
| 314 | Self(EscapeDebugInner::Bytes(iter)) | |
| 312 | #[inline] | |
| 313 | const fn backslash(c: ascii::Char) -> Self { | |
| 314 | Self(EscapeDebugInner::Bytes(escape::EscapeIterInner::backslash(c))) | |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | fn from_unicode(esc: EscapeUnicode) -> Self { | |
| 318 | Self(EscapeDebugInner::Bytes(esc.0)) | |
| 317 | #[inline] | |
| 318 | const fn unicode(c: char) -> Self { | |
| 319 | Self(EscapeDebugInner::Bytes(escape::EscapeIterInner::unicode(c))) | |
| 319 | 320 | } |
| 320 | 321 | |
| 322 | #[inline] | |
| 321 | 323 | fn clear(&mut self) { |
| 322 | let bytes = escape::EscapeIterInner::from_array([]); | |
| 323 | self.0 = EscapeDebugInner::Bytes(bytes); | |
| 324 | self.0 = EscapeDebugInner::Bytes(escape::EscapeIterInner::empty()); | |
| 324 | 325 | } |
| 325 | 326 | } |
| 326 | 327 | |
| ... | ... | @@ -339,6 +340,7 @@ impl Iterator for EscapeDebug { |
| 339 | 340 | } |
| 340 | 341 | } |
| 341 | 342 | |
| 343 | #[inline] | |
| 342 | 344 | fn size_hint(&self) -> (usize, Option<usize>) { |
| 343 | 345 | let n = self.len(); |
| 344 | 346 | (n, Some(n)) |
library/core/src/escape.rs+90-49| ... | ... | @@ -6,56 +6,79 @@ use crate::ops::Range; |
| 6 | 6 | |
| 7 | 7 | const HEX_DIGITS: [ascii::Char; 16] = *b"0123456789abcdef".as_ascii().unwrap(); |
| 8 | 8 | |
| 9 | /// Escapes a byte into provided buffer; returns length of escaped | |
| 10 | /// representation. | |
| 11 | pub(crate) fn escape_ascii_into(output: &mut [ascii::Char; 4], byte: u8) -> Range<u8> { | |
| 12 | #[inline] | |
| 13 | fn backslash(a: ascii::Char) -> ([ascii::Char; 4], u8) { | |
| 14 | ([ascii::Char::ReverseSolidus, a, ascii::Char::Null, ascii::Char::Null], 2) | |
| 15 | } | |
| 9 | #[inline] | |
| 10 | const fn backslash<const N: usize>(a: ascii::Char) -> ([ascii::Char; N], Range<u8>) { | |
| 11 | const { assert!(N >= 2) }; | |
| 12 | ||
| 13 | let mut output = [ascii::Char::Null; N]; | |
| 14 | ||
| 15 | output[0] = ascii::Char::ReverseSolidus; | |
| 16 | output[1] = a; | |
| 17 | ||
| 18 | (output, 0..2) | |
| 19 | } | |
| 16 | 20 | |
| 17 | let (data, len) = match byte { | |
| 21 | /// Escapes an ASCII character. | |
| 22 | /// | |
| 23 | /// Returns a buffer and the length of the escaped representation. | |
| 24 | const fn escape_ascii<const N: usize>(byte: u8) -> ([ascii::Char; N], Range<u8>) { | |
| 25 | const { assert!(N >= 4) }; | |
| 26 | ||
| 27 | match byte { | |
| 18 | 28 | b'\t' => backslash(ascii::Char::SmallT), |
| 19 | 29 | b'\r' => backslash(ascii::Char::SmallR), |
| 20 | 30 | b'\n' => backslash(ascii::Char::SmallN), |
| 21 | 31 | b'\\' => backslash(ascii::Char::ReverseSolidus), |
| 22 | 32 | b'\'' => backslash(ascii::Char::Apostrophe), |
| 23 | 33 | b'\"' => backslash(ascii::Char::QuotationMark), |
| 24 | _ => { | |
| 25 | if let Some(a) = byte.as_ascii() | |
| 34 | byte => { | |
| 35 | let mut output = [ascii::Char::Null; N]; | |
| 36 | ||
| 37 | if let Some(c) = byte.as_ascii() | |
| 26 | 38 | && !byte.is_ascii_control() |
| 27 | 39 | { |
| 28 | ([a, ascii::Char::Null, ascii::Char::Null, ascii::Char::Null], 1) | |
| 40 | output[0] = c; | |
| 41 | (output, 0..1) | |
| 29 | 42 | } else { |
| 30 | let hi = HEX_DIGITS[usize::from(byte >> 4)]; | |
| 31 | let lo = HEX_DIGITS[usize::from(byte & 0xf)]; | |
| 32 | ([ascii::Char::ReverseSolidus, ascii::Char::SmallX, hi, lo], 4) | |
| 43 | let hi = HEX_DIGITS[(byte >> 4) as usize]; | |
| 44 | let lo = HEX_DIGITS[(byte & 0xf) as usize]; | |
| 45 | ||
| 46 | output[0] = ascii::Char::ReverseSolidus; | |
| 47 | output[1] = ascii::Char::SmallX; | |
| 48 | output[2] = hi; | |
| 49 | output[3] = lo; | |
| 50 | ||
| 51 | (output, 0..4) | |
| 33 | 52 | } |
| 34 | 53 | } |
| 35 | }; | |
| 36 | *output = data; | |
| 37 | 0..len | |
| 54 | } | |
| 38 | 55 | } |
| 39 | 56 | |
| 40 | /// Escapes a character into provided buffer using `\u{NNNN}` representation. | |
| 41 | pub(crate) fn escape_unicode_into(output: &mut [ascii::Char; 10], ch: char) -> Range<u8> { | |
| 57 | /// Escapes a character `\u{NNNN}` representation. | |
| 58 | /// | |
| 59 | /// Returns a buffer and the length of the escaped representation. | |
| 60 | const fn escape_unicode<const N: usize>(c: char) -> ([ascii::Char; N], Range<u8>) { | |
| 61 | const { assert!(N >= 10 && N < u8::MAX as usize) }; | |
| 62 | ||
| 63 | let c = u32::from(c); | |
| 64 | ||
| 65 | // OR-ing `1` ensures that for `c == 0` the code computes that | |
| 66 | // one digit should be printed. | |
| 67 | let start = (c | 1).leading_zeros() as usize / 4 - 2; | |
| 68 | ||
| 69 | let mut output = [ascii::Char::Null; N]; | |
| 70 | output[3] = HEX_DIGITS[((c >> 20) & 15) as usize]; | |
| 71 | output[4] = HEX_DIGITS[((c >> 16) & 15) as usize]; | |
| 72 | output[5] = HEX_DIGITS[((c >> 12) & 15) as usize]; | |
| 73 | output[6] = HEX_DIGITS[((c >> 8) & 15) as usize]; | |
| 74 | output[7] = HEX_DIGITS[((c >> 4) & 15) as usize]; | |
| 75 | output[8] = HEX_DIGITS[((c >> 0) & 15) as usize]; | |
| 42 | 76 | output[9] = ascii::Char::RightCurlyBracket; |
| 77 | output[start + 0] = ascii::Char::ReverseSolidus; | |
| 78 | output[start + 1] = ascii::Char::SmallU; | |
| 79 | output[start + 2] = ascii::Char::LeftCurlyBracket; | |
| 43 | 80 | |
| 44 | let ch = ch as u32; | |
| 45 | output[3] = HEX_DIGITS[((ch >> 20) & 15) as usize]; | |
| 46 | output[4] = HEX_DIGITS[((ch >> 16) & 15) as usize]; | |
| 47 | output[5] = HEX_DIGITS[((ch >> 12) & 15) as usize]; | |
| 48 | output[6] = HEX_DIGITS[((ch >> 8) & 15) as usize]; | |
| 49 | output[7] = HEX_DIGITS[((ch >> 4) & 15) as usize]; | |
| 50 | output[8] = HEX_DIGITS[((ch >> 0) & 15) as usize]; | |
| 51 | ||
| 52 | // or-ing 1 ensures that for ch==0 the code computes that one digit should | |
| 53 | // be printed. | |
| 54 | let start = (ch | 1).leading_zeros() as usize / 4 - 2; | |
| 55 | const UNICODE_ESCAPE_PREFIX: &[ascii::Char; 3] = b"\\u{".as_ascii().unwrap(); | |
| 56 | output[start..][..3].copy_from_slice(UNICODE_ESCAPE_PREFIX); | |
| 57 | ||
| 58 | (start as u8)..10 | |
| 81 | (output, (start as u8)..(N as u8)) | |
| 59 | 82 | } |
| 60 | 83 | |
| 61 | 84 | /// An iterator over an fixed-size array. |
| ... | ... | @@ -65,45 +88,63 @@ pub(crate) fn escape_unicode_into(output: &mut [ascii::Char; 10], ch: char) -> R |
| 65 | 88 | #[derive(Clone, Debug)] |
| 66 | 89 | pub(crate) struct EscapeIterInner<const N: usize> { |
| 67 | 90 | // The element type ensures this is always ASCII, and thus also valid UTF-8. |
| 68 | pub(crate) data: [ascii::Char; N], | |
| 91 | data: [ascii::Char; N], | |
| 69 | 92 | |
| 70 | // Invariant: alive.start <= alive.end <= N. | |
| 71 | pub(crate) alive: Range<u8>, | |
| 93 | // Invariant: `alive.start <= alive.end <= N` | |
| 94 | alive: Range<u8>, | |
| 72 | 95 | } |
| 73 | 96 | |
| 74 | 97 | impl<const N: usize> EscapeIterInner<N> { |
| 75 | pub fn new(data: [ascii::Char; N], alive: Range<u8>) -> Self { | |
| 76 | const { assert!(N < 256) }; | |
| 77 | debug_assert!(alive.start <= alive.end && usize::from(alive.end) <= N, "{alive:?}"); | |
| 78 | Self { data, alive } | |
| 98 | pub const fn backslash(c: ascii::Char) -> Self { | |
| 99 | let (data, range) = backslash(c); | |
| 100 | Self { data, alive: range } | |
| 101 | } | |
| 102 | ||
| 103 | pub const fn ascii(c: u8) -> Self { | |
| 104 | let (data, range) = escape_ascii(c); | |
| 105 | Self { data, alive: range } | |
| 79 | 106 | } |
| 80 | 107 | |
| 81 | pub fn from_array<const M: usize>(array: [ascii::Char; M]) -> Self { | |
| 82 | const { assert!(M <= N) }; | |
| 108 | pub const fn unicode(c: char) -> Self { | |
| 109 | let (data, range) = escape_unicode(c); | |
| 110 | Self { data, alive: range } | |
| 111 | } | |
| 83 | 112 | |
| 84 | let mut data = [ascii::Char::Null; N]; | |
| 85 | data[..M].copy_from_slice(&array); | |
| 86 | Self::new(data, 0..M as u8) | |
| 113 | #[inline] | |
| 114 | pub const fn empty() -> Self { | |
| 115 | Self { data: [ascii::Char::Null; N], alive: 0..0 } | |
| 87 | 116 | } |
| 88 | 117 | |
| 118 | #[inline] | |
| 89 | 119 | pub fn as_ascii(&self) -> &[ascii::Char] { |
| 90 | &self.data[usize::from(self.alive.start)..usize::from(self.alive.end)] | |
| 120 | // SAFETY: `self.alive` is guaranteed to be a valid range for indexing `self.data`. | |
| 121 | unsafe { | |
| 122 | self.data.get_unchecked(usize::from(self.alive.start)..usize::from(self.alive.end)) | |
| 123 | } | |
| 91 | 124 | } |
| 92 | 125 | |
| 126 | #[inline] | |
| 93 | 127 | pub fn as_str(&self) -> &str { |
| 94 | 128 | self.as_ascii().as_str() |
| 95 | 129 | } |
| 96 | 130 | |
| 131 | #[inline] | |
| 97 | 132 | pub fn len(&self) -> usize { |
| 98 | 133 | usize::from(self.alive.end - self.alive.start) |
| 99 | 134 | } |
| 100 | 135 | |
| 101 | 136 | pub fn next(&mut self) -> Option<u8> { |
| 102 | self.alive.next().map(|i| self.data[usize::from(i)].to_u8()) | |
| 137 | let i = self.alive.next()?; | |
| 138 | ||
| 139 | // SAFETY: `i` is guaranteed to be a valid index for `self.data`. | |
| 140 | unsafe { Some(self.data.get_unchecked(usize::from(i)).to_u8()) } | |
| 103 | 141 | } |
| 104 | 142 | |
| 105 | 143 | pub fn next_back(&mut self) -> Option<u8> { |
| 106 | self.alive.next_back().map(|i| self.data[usize::from(i)].to_u8()) | |
| 144 | let i = self.alive.next_back()?; | |
| 145 | ||
| 146 | // SAFETY: `i` is guaranteed to be a valid index for `self.data`. | |
| 147 | unsafe { Some(self.data.get_unchecked(usize::from(i)).to_u8()) } | |
| 107 | 148 | } |
| 108 | 149 | |
| 109 | 150 | pub fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> { |
library/core/src/num/uint_macros.rs+3-3| ... | ... | @@ -584,11 +584,11 @@ macro_rules! uint_impl { |
| 584 | 584 | // Thus, rather than using `overflowing_sub` that produces a wrapping |
| 585 | 585 | // subtraction, check it ourself so we can use an unchecked one. |
| 586 | 586 | |
| 587 | if self >= rhs { | |
| 587 | if self < rhs { | |
| 588 | None | |
| 589 | } else { | |
| 588 | 590 | // SAFETY: just checked this can't overflow |
| 589 | 591 | Some(unsafe { intrinsics::unchecked_sub(self, rhs) }) |
| 590 | } else { | |
| 591 | None | |
| 592 | 592 | } |
| 593 | 593 | } |
| 594 | 594 |
src/bootstrap/src/core/build_steps/dist.rs+4-2| ... | ... | @@ -26,7 +26,9 @@ use crate::core::build_steps::tool::{self, Tool}; |
| 26 | 26 | use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step}; |
| 27 | 27 | use crate::core::config::TargetSelection; |
| 28 | 28 | use crate::utils::channel::{self, Info}; |
| 29 | use crate::utils::helpers::{exe, is_dylib, output, t, target_supports_cranelift_backend, timeit}; | |
| 29 | use crate::utils::helpers::{ | |
| 30 | exe, is_dylib, move_file, output, t, target_supports_cranelift_backend, timeit, | |
| 31 | }; | |
| 30 | 32 | use crate::utils::tarball::{GeneratedTarball, OverlayKind, Tarball}; |
| 31 | 33 | use crate::{Compiler, DependencyType, Mode, LLVM_TOOLS}; |
| 32 | 34 | |
| ... | ... | @@ -2024,7 +2026,7 @@ impl Step for Extended { |
| 2024 | 2026 | builder.run(&mut cmd); |
| 2025 | 2027 | |
| 2026 | 2028 | if !builder.config.dry_run() { |
| 2027 | t!(fs::rename(exe.join(&filename), distdir(builder).join(&filename))); | |
| 2029 | t!(move_file(exe.join(&filename), distdir(builder).join(&filename))); | |
| 2028 | 2030 | } |
| 2029 | 2031 | } |
| 2030 | 2032 | } |
src/bootstrap/src/core/download.rs+3-3| ... | ... | @@ -12,7 +12,7 @@ use build_helper::ci::CiEnv; |
| 12 | 12 | use build_helper::stage0_parser::VersionMetadata; |
| 13 | 13 | use xz2::bufread::XzDecoder; |
| 14 | 14 | |
| 15 | use crate::utils::helpers::{check_run, exe, program_out_of_date}; | |
| 15 | use crate::utils::helpers::{check_run, exe, move_file, program_out_of_date}; | |
| 16 | 16 | use crate::{core::build_steps::llvm::detect_llvm_sha, utils::helpers::hex_encode}; |
| 17 | 17 | use crate::{t, Config}; |
| 18 | 18 | |
| ... | ... | @@ -209,7 +209,7 @@ impl Config { |
| 209 | 209 | None => panic!("no protocol in {url}"), |
| 210 | 210 | } |
| 211 | 211 | t!( |
| 212 | std::fs::rename(&tempfile, dest_path), | |
| 212 | move_file(&tempfile, dest_path), | |
| 213 | 213 | format!("failed to rename {tempfile:?} to {dest_path:?}") |
| 214 | 214 | ); |
| 215 | 215 | } |
| ... | ... | @@ -313,7 +313,7 @@ impl Config { |
| 313 | 313 | if src_path.is_dir() && dst_path.exists() { |
| 314 | 314 | continue; |
| 315 | 315 | } |
| 316 | t!(fs::rename(src_path, dst_path)); | |
| 316 | t!(move_file(src_path, dst_path)); | |
| 317 | 317 | } |
| 318 | 318 | let dst_dir = dst.join(directory_prefix); |
| 319 | 319 | if dst_dir.exists() { |
src/bootstrap/src/utils/helpers.rs+15| ... | ... | @@ -150,6 +150,21 @@ pub fn symlink_dir(config: &Config, original: &Path, link: &Path) -> io::Result< |
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | /// Rename a file if from and to are in the same filesystem or | |
| 154 | /// copy and remove the file otherwise | |
| 155 | pub fn move_file<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()> { | |
| 156 | match fs::rename(&from, &to) { | |
| 157 | // FIXME: Once `ErrorKind::CrossesDevices` is stabilized use | |
| 158 | // if e.kind() == io::ErrorKind::CrossesDevices { | |
| 159 | #[cfg(unix)] | |
| 160 | Err(e) if e.raw_os_error() == Some(libc::EXDEV) => { | |
| 161 | std::fs::copy(&from, &to)?; | |
| 162 | std::fs::remove_file(&from) | |
| 163 | } | |
| 164 | r => r, | |
| 165 | } | |
| 166 | } | |
| 167 | ||
| 153 | 168 | pub fn forcing_clang_based_tests() -> bool { |
| 154 | 169 | if let Some(var) = env::var_os("RUSTBUILD_FORCE_CLANG_BASED_TESTS") { |
| 155 | 170 | match &var.to_string_lossy().to_lowercase()[..] { |
src/bootstrap/src/utils/tarball.rs+2-2| ... | ... | @@ -13,7 +13,7 @@ use std::{ |
| 13 | 13 | use crate::core::builder::Builder; |
| 14 | 14 | use crate::core::{build_steps::dist::distdir, builder::Kind}; |
| 15 | 15 | use crate::utils::channel; |
| 16 | use crate::utils::helpers::t; | |
| 16 | use crate::utils::helpers::{move_file, t}; | |
| 17 | 17 | |
| 18 | 18 | #[derive(Copy, Clone)] |
| 19 | 19 | pub(crate) enum OverlayKind { |
| ... | ... | @@ -284,7 +284,7 @@ impl<'a> Tarball<'a> { |
| 284 | 284 | // name, not "image". We rename the image directory just before passing |
| 285 | 285 | // into rust-installer. |
| 286 | 286 | let dest = self.temp_dir.join(self.package_name()); |
| 287 | t!(std::fs::rename(&self.image_dir, &dest)); | |
| 287 | t!(move_file(&self.image_dir, &dest)); | |
| 288 | 288 | |
| 289 | 289 | self.run(|this, cmd| { |
| 290 | 290 | let distdir = distdir(this.builder); |
src/tools/tidy/src/allowed_run_make_makefiles.txt-2| ... | ... | @@ -8,7 +8,6 @@ run-make/branch-protection-check-IBT/Makefile |
| 8 | 8 | run-make/c-dynamic-dylib/Makefile |
| 9 | 9 | run-make/c-dynamic-rlib/Makefile |
| 10 | 10 | run-make/c-link-to-rust-dylib/Makefile |
| 11 | run-make/c-link-to-rust-staticlib/Makefile | |
| 12 | 11 | run-make/c-static-dylib/Makefile |
| 13 | 12 | run-make/c-static-rlib/Makefile |
| 14 | 13 | run-make/c-unwind-abi-catch-lib-panic/Makefile |
| ... | ... | @@ -179,7 +178,6 @@ run-make/native-link-modifier-whole-archive/Makefile |
| 179 | 178 | run-make/no-alloc-shim/Makefile |
| 180 | 179 | run-make/no-builtins-attribute/Makefile |
| 181 | 180 | run-make/no-builtins-lto/Makefile |
| 182 | run-make/no-cdylib-as-rdylib/Makefile | |
| 183 | 181 | run-make/no-duplicate-libs/Makefile |
| 184 | 182 | run-make/no-intermediate-extras/Makefile |
| 185 | 183 | run-make/obey-crate-type-flag/Makefile |
tests/run-make/c-link-to-rust-staticlib/Makefile deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | # This test checks that C linking with Rust does not encounter any errors, with static libraries. | |
| 2 | # See https://github.com/rust-lang/rust/issues/10434 | |
| 3 | ||
| 4 | # ignore-cross-compile | |
| 5 | include ../tools.mk | |
| 6 | ||
| 7 | # ignore-freebsd | |
| 8 | # FIXME | |
| 9 | ||
| 10 | all: | |
| 11 | 	$(RUSTC) foo.rs | |
| 12 | 	$(CC) bar.c $(call STATICLIB,foo) $(call OUT_EXE,bar) \ | |
| 13 | 		$(EXTRACFLAGS) $(EXTRACXXFLAGS) | |
| 14 | 	$(call RUN,bar) | |
| 15 | 	rm $(call STATICLIB,foo) | |
| 16 | 	$(call RUN,bar) |
tests/run-make/c-link-to-rust-staticlib/rmake.rs created+15| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | // This test checks that C linking with Rust does not encounter any errors, with a static library. | |
| 2 | // See https://github.com/rust-lang/rust/issues/10434 | |
| 3 | ||
| 4 | //@ ignore-cross-compile | |
| 5 | ||
| 6 | use run_make_support::{cc, extra_c_flags, run, rustc, static_lib}; | |
| 7 | use std::fs; | |
| 8 | ||
| 9 | fn main() { | |
| 10 | rustc().input("foo.rs").run(); | |
| 11 | cc().input("bar.c").input(static_lib("foo")).out_exe("bar").args(&extra_c_flags()).run(); | |
| 12 | run("bar"); | |
| 13 | fs::remove_file(static_lib("foo")); | |
| 14 | run("bar"); | |
| 15 | } |
tests/run-make/no-cdylib-as-rdylib/Makefile deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | # ignore-cross-compile | |
| 2 | include ../tools.mk | |
| 3 | ||
| 4 | # Test that rustc will not attempt to link against a cdylib as if | |
| 5 | # it is a rust dylib when an rlib for the same crate is available. | |
| 6 | # Previously rustc didn't actually check if any further formats of | |
| 7 | # a crate which has been loaded are of the same version and if | |
| 8 | # they are actually valid. This caused a cdylib to be interpreted | |
| 9 | # as rust dylib as soon as the corresponding rlib was loaded. As | |
| 10 | # cdylibs don't export any rust symbols, linking would fail if | |
| 11 | # rustc decides to link against the cdylib rather than the rlib. | |
| 12 | ||
| 13 | all: | |
| 14 | 	$(RUSTC) bar.rs --crate-type=rlib --crate-type=cdylib | |
| 15 | 	$(RUSTC) foo.rs -C prefer-dynamic | |
| 16 | 	$(call RUN,foo) |
tests/run-make/no-cdylib-as-rdylib/rmake.rs created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | // This test produces an rlib and a cdylib from bar.rs. | |
| 2 | // Then, foo.rs attempts to link to the bar library. | |
| 3 | // If the test passes, that means rustc favored the rlib and ignored the cdylib. | |
| 4 | // If the test fails, that is because the cdylib was picked, which does not export | |
| 5 | // any Rust symbols. | |
| 6 | // See https://github.com/rust-lang/rust/pull/113695 | |
| 7 | ||
| 8 | //@ ignore-cross-compile | |
| 9 | ||
| 10 | use run_make_support::{run, rustc}; | |
| 11 | ||
| 12 | fn main() { | |
| 13 | rustc().input("bar.rs").crate_type("rlib").crate_type("cdylib").run(); | |
| 14 | rustc().input("foo.rs").arg("-Cprefer-dynamic").run(); | |
| 15 | run("foo"); | |
| 16 | } |