Skip to content

Commit 150322f

Browse files
committed
Auto merge of rust-lang#70518 - Dylan-DPC:rollup-n2gkh3a, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#69937 (ASCII methods on OsStr) - rust-lang#70235 (Validate git setup before accessing functionality) - rust-lang#70503 (rename Scalar::{ptr_null -> null_ptr} and add "machine_" prefix like elsewhere) - rust-lang#70508 (Miri: use more specialized Scalar::from_ constructors where appropriate) - rust-lang#70510 (fix TryEnterCriticalSection return type) Failed merges: r? @ghost
2 parents 7762131 + be8d896 commit 150322f

File tree

14 files changed

+298
-46
lines changed

14 files changed

+298
-46
lines changed

Diff for: src/bootstrap/format.rs

+43-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::Build;
44
use build_helper::{output, t};
55
use ignore::WalkBuilder;
66
use std::path::Path;
7-
use std::process::Command;
7+
use std::process::{Command, Stdio};
88

99
fn rustfmt(src: &Path, rustfmt: &Path, path: &Path, check: bool) {
1010
let mut cmd = Command::new(&rustfmt);
@@ -56,16 +56,48 @@ pub fn format(build: &Build, check: bool) {
5656
for ignore in rustfmt_config.ignore {
5757
ignore_fmt.add(&format!("!{}", ignore)).expect(&ignore);
5858
}
59-
let untracked_paths_output = output(
60-
Command::new("git").arg("status").arg("--porcelain").arg("--untracked-files=normal"),
61-
);
62-
let untracked_paths = untracked_paths_output
63-
.lines()
64-
.filter(|entry| entry.starts_with("??"))
65-
.map(|entry| entry.split(" ").nth(1).expect("every git status entry should list a path"));
66-
for untracked_path in untracked_paths {
67-
eprintln!("skip untracked path {} during rustfmt invocations", untracked_path);
68-
ignore_fmt.add(&format!("!{}", untracked_path)).expect(&untracked_path);
59+
let git_available = match Command::new("git")
60+
.arg("--version")
61+
.stdout(Stdio::null())
62+
.stderr(Stdio::null())
63+
.status()
64+
{
65+
Ok(status) => status.success(),
66+
Err(_) => false,
67+
};
68+
if git_available {
69+
let in_working_tree = match Command::new("git")
70+
.arg("rev-parse")
71+
.arg("--is-inside-work-tree")
72+
.stdout(Stdio::null())
73+
.stderr(Stdio::null())
74+
.status()
75+
{
76+
Ok(status) => status.success(),
77+
Err(_) => false,
78+
};
79+
if in_working_tree {
80+
let untracked_paths_output = output(
81+
Command::new("git")
82+
.arg("status")
83+
.arg("--porcelain")
84+
.arg("--untracked-files=normal"),
85+
);
86+
let untracked_paths = untracked_paths_output
87+
.lines()
88+
.filter(|entry| entry.starts_with("??"))
89+
.map(|entry| {
90+
entry.split(" ").nth(1).expect("every git status entry should list a path")
91+
});
92+
for untracked_path in untracked_paths {
93+
eprintln!("skip untracked path {} during rustfmt invocations", untracked_path);
94+
ignore_fmt.add(&format!("!{}", untracked_path)).expect(&untracked_path);
95+
}
96+
} else {
97+
eprintln!("Not in git tree. Skipping git-aware format checks");
98+
}
99+
} else {
100+
eprintln!("Could not find usable git. Skipping git-aware format checks");
69101
}
70102
let ignore_fmt = ignore_fmt.build().unwrap();
71103

Diff for: src/librustc/mir/interpret/pointer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ pub trait PointerArithmetic: layout::HasDataLayout {
4646
}
4747

4848
#[inline]
49-
fn usize_max(&self) -> u64 {
49+
fn machine_usize_max(&self) -> u64 {
5050
let max_usize_plus_1 = 1u128 << self.pointer_size().bits();
5151
u64::try_from(max_usize_plus_1 - 1).unwrap()
5252
}
5353

5454
#[inline]
55-
fn isize_max(&self) -> i64 {
55+
fn machine_isize_max(&self) -> i64 {
5656
let max_isize_plus_1 = 1u128 << (self.pointer_size().bits() - 1);
5757
i64::try_from(max_isize_plus_1 - 1).unwrap()
5858
}

Diff for: src/librustc/mir/interpret/value.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl<'tcx, Tag> Scalar<Tag> {
192192
}
193193

194194
#[inline]
195-
pub fn ptr_null(cx: &impl HasDataLayout) -> Self {
195+
pub fn null_ptr(cx: &impl HasDataLayout) -> Self {
196196
Scalar::Raw { data: 0, size: cx.data_layout().pointer_size.bytes() as u8 }
197197
}
198198

Diff for: src/librustc_mir/interpret/cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
208208

209209
Char => {
210210
// `u8` to `char` cast
211-
Ok(Scalar::from_uint(u8::try_from(v).unwrap(), Size::from_bytes(4)))
211+
Ok(Scalar::from_u32(u8::try_from(v).unwrap().into()))
212212
}
213213

214214
// Casts to bool are not permitted by rustc, no need to handle them here.

Diff for: src/librustc_mir/interpret/intrinsics.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
//! looking at their MIR. Intrinsics/functions supported here are shared by CTFE
33
//! and miri.
44
5+
use std::convert::TryFrom;
6+
57
use rustc::mir::{
68
self,
79
interpret::{ConstValue, GlobalId, InterpResult, Scalar},
@@ -220,7 +222,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
220222
sym::discriminant_value => {
221223
let place = self.deref_operand(args[0])?;
222224
let discr_val = self.read_discriminant(place.into())?.0;
223-
self.write_scalar(Scalar::from_uint(discr_val, dest.layout.size), dest)?;
225+
self.write_scalar(Scalar::from_u64(u64::try_from(discr_val).unwrap()), dest)?;
224226
}
225227
sym::unchecked_shl
226228
| sym::unchecked_shr
@@ -275,7 +277,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
275277
}
276278

277279
sym::ptr_offset_from => {
278-
let isize_layout = self.layout_of(self.tcx.types.isize)?;
279280
let a = self.read_immediate(args[0])?.to_scalar()?;
280281
let b = self.read_immediate(args[1])?.to_scalar()?;
281282

@@ -292,7 +293,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
292293
let a = a.to_machine_usize(self)?;
293294
let b = b.to_machine_usize(self)?;
294295
if a == b && a != 0 {
295-
self.write_scalar(Scalar::from_int(0, isize_layout.size), dest)?;
296+
self.write_scalar(Scalar::from_machine_isize(0, self), dest)?;
296297
true
297298
} else {
298299
false
@@ -312,6 +313,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
312313
);
313314
}
314315
let usize_layout = self.layout_of(self.tcx.types.usize)?;
316+
let isize_layout = self.layout_of(self.tcx.types.isize)?;
315317
let a_offset = ImmTy::from_uint(a.offset.bytes(), usize_layout);
316318
let b_offset = ImmTy::from_uint(b.offset.bytes(), usize_layout);
317319
let (val, _overflowed, _ty) =

Diff for: src/librustc_mir/interpret/operand.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ impl<Tag> From<Pointer<Tag>> for Immediate<Tag> {
5454

5555
impl<'tcx, Tag> Immediate<Tag> {
5656
pub fn new_slice(val: Scalar<Tag>, len: u64, cx: &impl HasDataLayout) -> Self {
57-
Immediate::ScalarPair(
58-
val.into(),
59-
Scalar::from_uint(len, cx.data_layout().pointer_size).into(),
60-
)
57+
Immediate::ScalarPair(val.into(), Scalar::from_machine_usize(len, cx).into())
6158
}
6259

6360
pub fn new_dyn_trait(val: Scalar<Tag>, vtable: Pointer<Tag>) -> Self {
@@ -621,7 +618,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
621618
let real_discr = if discr_val.layout.abi.is_signed() {
622619
// going from layout tag type to typeck discriminant type
623620
// requires first sign extending with the discriminant layout
624-
let sexted = sign_extend(bits_discr, discr_val.layout.size) as i128;
621+
let sexted = sign_extend(bits_discr, discr_val.layout.size);
625622
// and then zeroing with the typeck discriminant type
626623
let discr_ty = rval
627624
.layout
@@ -631,8 +628,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
631628
.repr
632629
.discr_type();
633630
let size = layout::Integer::from_attr(self, discr_ty).size();
634-
let truncatee = sexted as u128;
635-
truncate(truncatee, size)
631+
truncate(sexted, size)
636632
} else {
637633
bits_discr
638634
};

Diff for: src/librustc_mir/interpret/place.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<Tag> MemPlace<Tag> {
139139
/// Produces a Place that will error if attempted to be read from or written to
140140
#[inline(always)]
141141
fn null(cx: &impl HasDataLayout) -> Self {
142-
Self::from_scalar_ptr(Scalar::ptr_null(cx), Align::from_bytes(1).unwrap())
142+
Self::from_scalar_ptr(Scalar::null_ptr(cx), Align::from_bytes(1).unwrap())
143143
}
144144

145145
#[inline(always)]
@@ -180,7 +180,7 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> {
180180
#[inline]
181181
pub fn dangling(layout: TyLayout<'tcx>, cx: &impl HasDataLayout) -> Self {
182182
let align = layout.align.abi;
183-
let ptr = Scalar::from_uint(align.bytes(), cx.pointer_size());
183+
let ptr = Scalar::from_machine_usize(align.bytes(), cx);
184184
// `Poison` this to make sure that the pointer value `ptr` is never observable by the program.
185185
MPlaceTy { mplace: MemPlace { ptr, align, meta: MemPlaceMeta::Poison }, layout }
186186
}
@@ -504,7 +504,7 @@ where
504504
// implement this.
505505
ty::Array(inner, _) => (MemPlaceMeta::None, self.tcx.mk_array(inner, inner_len)),
506506
ty::Slice(..) => {
507-
let len = Scalar::from_uint(inner_len, self.pointer_size());
507+
let len = Scalar::from_machine_usize(inner_len, self);
508508
(MemPlaceMeta::Meta(len), base.layout.ty)
509509
}
510510
_ => bug!("cannot subslice non-array type: `{:?}`", base.layout.ty),
@@ -1044,7 +1044,7 @@ where
10441044
kind: MemoryKind<M::MemoryKind>,
10451045
) -> MPlaceTy<'tcx, M::PointerTag> {
10461046
let ptr = self.memory.allocate_bytes(str.as_bytes(), kind);
1047-
let meta = Scalar::from_uint(u128::try_from(str.len()).unwrap(), self.pointer_size());
1047+
let meta = Scalar::from_machine_usize(u64::try_from(str.len()).unwrap(), self);
10481048
let mplace = MemPlace {
10491049
ptr: ptr.into(),
10501050
align: Align::from_bytes(1).unwrap(),

Diff for: src/librustc_mir/interpret/step.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! The main entry point is the `step` method.
44
55
use rustc::mir;
6-
use rustc::mir::interpret::{InterpResult, PointerArithmetic, Scalar};
6+
use rustc::mir::interpret::{InterpResult, Scalar};
77
use rustc::ty::layout::LayoutOf;
88

99
use super::{InterpCx, Machine};
@@ -229,8 +229,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
229229
let src = self.eval_place(place)?;
230230
let mplace = self.force_allocation(src)?;
231231
let len = mplace.len(self)?;
232-
let size = self.pointer_size();
233-
self.write_scalar(Scalar::from_uint(len, size), dest)?;
232+
self.write_scalar(Scalar::from_machine_usize(len, self), dest)?;
234233
}
235234

236235
AddressOf(_, ref place) | Ref(_, _, ref place) => {
@@ -254,8 +253,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
254253
!layout.is_unsized(),
255254
"SizeOf nullary MIR operator called for unsized type"
256255
);
257-
let size = self.pointer_size();
258-
self.write_scalar(Scalar::from_uint(layout.size.bytes(), size), dest)?;
256+
self.write_scalar(Scalar::from_machine_usize(layout.size.bytes(), self), dest)?;
259257
}
260258

261259
Cast(kind, ref operand, _) => {

Diff for: src/libstd/ffi/os_str.rs

+141
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,147 @@ impl OsStr {
698698
fn bytes(&self) -> &[u8] {
699699
unsafe { &*(&self.inner as *const _ as *const [u8]) }
700700
}
701+
702+
/// Converts this string to its ASCII lower case equivalent in-place.
703+
///
704+
/// ASCII letters 'A' to 'Z' are mapped to 'a' to 'z',
705+
/// but non-ASCII letters are unchanged.
706+
///
707+
/// To return a new lowercased value without modifying the existing one, use
708+
/// [`to_ascii_lowercase`].
709+
///
710+
/// [`to_ascii_lowercase`]: #method.to_ascii_lowercase
711+
///
712+
/// # Examples
713+
///
714+
/// ```
715+
/// #![feature(osstring_ascii)]
716+
/// use std::ffi::OsString;
717+
///
718+
/// let mut s = OsString::from("GRÜßE, JÜRGEN ❤");
719+
///
720+
/// s.make_ascii_lowercase();
721+
///
722+
/// assert_eq!("grÜße, jÜrgen ❤", s);
723+
/// ```
724+
#[unstable(feature = "osstring_ascii", issue = "70516")]
725+
pub fn make_ascii_lowercase(&mut self) {
726+
self.inner.make_ascii_lowercase()
727+
}
728+
729+
/// Converts this string to its ASCII upper case equivalent in-place.
730+
///
731+
/// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z',
732+
/// but non-ASCII letters are unchanged.
733+
///
734+
/// To return a new uppercased value without modifying the existing one, use
735+
/// [`to_ascii_uppercase`].
736+
///
737+
/// [`to_ascii_uppercase`]: #method.to_ascii_uppercase
738+
///
739+
/// # Examples
740+
///
741+
/// ```
742+
/// #![feature(osstring_ascii)]
743+
/// use std::ffi::OsString;
744+
///
745+
/// let mut s = OsString::from("Grüße, Jürgen ❤");
746+
///
747+
/// s.make_ascii_uppercase();
748+
///
749+
/// assert_eq!("GRüßE, JüRGEN ❤", s);
750+
/// ```
751+
#[unstable(feature = "osstring_ascii", issue = "70516")]
752+
pub fn make_ascii_uppercase(&mut self) {
753+
self.inner.make_ascii_uppercase()
754+
}
755+
756+
/// Returns a copy of this string where each character is mapped to its
757+
/// ASCII lower case equivalent.
758+
///
759+
/// ASCII letters 'A' to 'Z' are mapped to 'a' to 'z',
760+
/// but non-ASCII letters are unchanged.
761+
///
762+
/// To lowercase the value in-place, use [`make_ascii_lowercase`].
763+
///
764+
/// [`make_ascii_lowercase`]: #method.make_ascii_lowercase
765+
///
766+
/// # Examples
767+
///
768+
/// ```
769+
/// #![feature(osstring_ascii)]
770+
/// use std::ffi::OsString;
771+
/// let s = OsString::from("Grüße, Jürgen ❤");
772+
///
773+
/// assert_eq!("grüße, jürgen ❤", s.to_ascii_lowercase());
774+
/// ```
775+
#[unstable(feature = "osstring_ascii", issue = "70516")]
776+
pub fn to_ascii_lowercase(&self) -> OsString {
777+
OsString::from_inner(self.inner.to_ascii_lowercase())
778+
}
779+
780+
/// Returns a copy of this string where each character is mapped to its
781+
/// ASCII upper case equivalent.
782+
///
783+
/// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z',
784+
/// but non-ASCII letters are unchanged.
785+
///
786+
/// To uppercase the value in-place, use [`make_ascii_uppercase`].
787+
///
788+
/// [`make_ascii_uppercase`]: #method.make_ascii_uppercase
789+
///
790+
/// # Examples
791+
///
792+
/// ```
793+
/// #![feature(osstring_ascii)]
794+
/// use std::ffi::OsString;
795+
/// let s = OsString::from("Grüße, Jürgen ❤");
796+
///
797+
/// assert_eq!("GRüßE, JüRGEN ❤", s.to_ascii_uppercase());
798+
/// ```
799+
#[unstable(feature = "osstring_ascii", issue = "70516")]
800+
pub fn to_ascii_uppercase(&self) -> OsString {
801+
OsString::from_inner(self.inner.to_ascii_uppercase())
802+
}
803+
804+
/// Checks if all characters in this string are within the ASCII range.
805+
///
806+
/// # Examples
807+
///
808+
/// ```
809+
/// #![feature(osstring_ascii)]
810+
/// use std::ffi::OsString;
811+
///
812+
/// let ascii = OsString::from("hello!\n");
813+
/// let non_ascii = OsString::from("Grüße, Jürgen ❤");
814+
///
815+
/// assert!(ascii.is_ascii());
816+
/// assert!(!non_ascii.is_ascii());
817+
/// ```
818+
#[unstable(feature = "osstring_ascii", issue = "70516")]
819+
pub fn is_ascii(&self) -> bool {
820+
self.inner.is_ascii()
821+
}
822+
823+
/// Checks that two strings are an ASCII case-insensitive match.
824+
///
825+
/// Same as `to_ascii_lowercase(a) == to_ascii_lowercase(b)`,
826+
/// but without allocating and copying temporaries.
827+
///
828+
/// # Examples
829+
///
830+
/// ```
831+
/// #![feature(osstring_ascii)]
832+
/// use std::ffi::OsString;
833+
///
834+
/// assert!(OsString::from("Ferris").eq_ignore_ascii_case("FERRIS"));
835+
/// assert!(OsString::from("Ferrös").eq_ignore_ascii_case("FERRöS"));
836+
/// assert!(!OsString::from("Ferrös").eq_ignore_ascii_case("FERRÖS"));
837+
/// ```
838+
#[unstable(feature = "osstring_ascii", issue = "70516")]
839+
pub fn eq_ignore_ascii_case<S: ?Sized + AsRef<OsStr>>(&self, other: &S) -> bool {
840+
self.inner.eq_ignore_ascii_case(&other.as_ref().inner)
841+
}
701842
}
702843

703844
#[stable(feature = "box_from_os_str", since = "1.17.0")]

Diff for: src/libstd/sys/windows/c.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ extern "system" {
778778
pub fn ioctlsocket(s: SOCKET, cmd: c_long, argp: *mut c_ulong) -> c_int;
779779
pub fn InitializeCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
780780
pub fn EnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
781-
pub fn TryEnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION) -> BOOLEAN;
781+
pub fn TryEnterCriticalSection(CriticalSection: *mut CRITICAL_SECTION) -> BOOL;
782782
pub fn LeaveCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
783783
pub fn DeleteCriticalSection(CriticalSection: *mut CRITICAL_SECTION);
784784

0 commit comments

Comments
 (0)