Skip to content

Commit a268e92

Browse files
committed
Auto merge of #146014 - matthiaskrgr:rollup-t39vmhf, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #144964 (std: clarify `OpenOptions` error for create without write access) - #145242 (std: use a TAIT to define `SplitPaths` on UNIX) - #145467 (Stabilize `strict_provenance_atomic_ptr` feature) - #145990 (`AutoDeref::final_ty` is already resolved) - #145991 (std: haiku: fix `B_FIND_PATH_IMAGE_PATH`) - #146000 (Improve librustdoc error when a file creation/modification failed) r? `@ghost` `@rustbot` modify labels: rollup
2 parents fe55364 + 2f674fd commit a268e92

File tree

17 files changed

+110
-78
lines changed

17 files changed

+110
-78
lines changed

compiler/rustc_hir_analysis/src/autoderef.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,10 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
202202
Some((normalized_ty, ocx.into_pending_obligations()))
203203
}
204204

205-
/// Returns the final type we ended up with, which may be an inference
206-
/// variable (we will resolve it first, if we want).
207-
pub fn final_ty(&self, resolve: bool) -> Ty<'tcx> {
208-
if resolve {
209-
self.infcx.resolve_vars_if_possible(self.state.cur_ty)
210-
} else {
211-
self.state.cur_ty
212-
}
205+
/// Returns the final type we ended up with, which may be an unresolved
206+
/// inference variable.
207+
pub fn final_ty(&self) -> Ty<'tcx> {
208+
self.state.cur_ty
213209
}
214210

215211
pub fn step_count(&self) -> usize {

compiler/rustc_hir_typeck/src/autoderef.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
4242

4343
let mut obligations = PredicateObligations::new();
4444
let targets =
45-
steps.iter().skip(1).map(|&(ty, _)| ty).chain(iter::once(autoderef.final_ty(false)));
45+
steps.iter().skip(1).map(|&(ty, _)| ty).chain(iter::once(autoderef.final_ty()));
4646
let steps: Vec<_> = steps
4747
.iter()
4848
.map(|&(source, kind)| {

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8686
result = self.try_overloaded_call_step(call_expr, callee_expr, arg_exprs, &autoderef);
8787
}
8888

89-
match autoderef.final_ty(false).kind() {
89+
match autoderef.final_ty().kind() {
9090
ty::FnDef(def_id, _) => {
9191
let abi = self.tcx.fn_sig(def_id).skip_binder().skip_binder().abi;
9292
self.check_call_abi(abi, call_expr.span);
@@ -200,8 +200,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
200200
arg_exprs: &'tcx [hir::Expr<'tcx>],
201201
autoderef: &Autoderef<'a, 'tcx>,
202202
) -> Option<CallStep<'tcx>> {
203-
let adjusted_ty =
204-
self.structurally_resolve_type(autoderef.span(), autoderef.final_ty(false));
203+
let adjusted_ty = self.structurally_resolve_type(autoderef.span(), autoderef.final_ty());
205204

206205
// If the callee is a function pointer or a closure, then we're all set.
207206
match *adjusted_ty.kind() {

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2918,7 +2918,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29182918
// Emits an error if we deref an infer variable, like calling `.field` on a base type
29192919
// of `&_`. We can also use this to suppress unnecessary "missing field" errors that
29202920
// will follow ambiguity errors.
2921-
let final_ty = self.structurally_resolve_type(autoderef.span(), autoderef.final_ty(false));
2921+
let final_ty = self.structurally_resolve_type(autoderef.span(), autoderef.final_ty());
29222922
if let ty::Error(_) = final_ty.kind() {
29232923
return final_ty;
29242924
}

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ pub(crate) fn method_autoderef_steps<'tcx>(
629629
.collect();
630630
(steps, autoderef_via_deref.reached_recursion_limit())
631631
};
632-
let final_ty = autoderef_via_deref.final_ty(true);
632+
let final_ty = autoderef_via_deref.final_ty();
633633
let opt_bad_ty = match final_ty.kind() {
634634
ty::Infer(ty::TyVar(_)) | ty::Error(_) => Some(MethodAutoderefBadTy {
635635
reached_raw_pointer,

compiler/rustc_hir_typeck/src/place_op.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
109109
index_ty: Ty<'tcx>,
110110
index_expr: &hir::Expr<'_>,
111111
) -> Option<(/*index type*/ Ty<'tcx>, /*element type*/ Ty<'tcx>)> {
112-
let adjusted_ty =
113-
self.structurally_resolve_type(autoderef.span(), autoderef.final_ty(false));
112+
let adjusted_ty = self.structurally_resolve_type(autoderef.span(), autoderef.final_ty());
114113
debug!(
115114
"try_index_step(expr={:?}, base_expr={:?}, adjusted_ty={:?}, \
116115
index_ty={:?})",

library/core/src/sync/atomic.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,7 +2199,6 @@ impl<T> AtomicPtr<T> {
21992199
/// # Examples
22002200
///
22012201
/// ```
2202-
/// #![feature(strict_provenance_atomic_ptr)]
22032202
/// use core::sync::atomic::{AtomicPtr, Ordering};
22042203
///
22052204
/// let atom = AtomicPtr::<i64>::new(core::ptr::null_mut());
@@ -2209,7 +2208,7 @@ impl<T> AtomicPtr<T> {
22092208
/// ```
22102209
#[inline]
22112210
#[cfg(target_has_atomic = "ptr")]
2212-
#[unstable(feature = "strict_provenance_atomic_ptr", issue = "99108")]
2211+
#[stable(feature = "strict_provenance_atomic_ptr", since = "CURRENT_RUSTC_VERSION")]
22132212
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
22142213
pub fn fetch_ptr_add(&self, val: usize, order: Ordering) -> *mut T {
22152214
self.fetch_byte_add(val.wrapping_mul(size_of::<T>()), order)
@@ -2240,7 +2239,6 @@ impl<T> AtomicPtr<T> {
22402239
/// # Examples
22412240
///
22422241
/// ```
2243-
/// #![feature(strict_provenance_atomic_ptr)]
22442242
/// use core::sync::atomic::{AtomicPtr, Ordering};
22452243
///
22462244
/// let array = [1i32, 2i32];
@@ -2254,7 +2252,7 @@ impl<T> AtomicPtr<T> {
22542252
/// ```
22552253
#[inline]
22562254
#[cfg(target_has_atomic = "ptr")]
2257-
#[unstable(feature = "strict_provenance_atomic_ptr", issue = "99108")]
2255+
#[stable(feature = "strict_provenance_atomic_ptr", since = "CURRENT_RUSTC_VERSION")]
22582256
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
22592257
pub fn fetch_ptr_sub(&self, val: usize, order: Ordering) -> *mut T {
22602258
self.fetch_byte_sub(val.wrapping_mul(size_of::<T>()), order)
@@ -2279,7 +2277,6 @@ impl<T> AtomicPtr<T> {
22792277
/// # Examples
22802278
///
22812279
/// ```
2282-
/// #![feature(strict_provenance_atomic_ptr)]
22832280
/// use core::sync::atomic::{AtomicPtr, Ordering};
22842281
///
22852282
/// let atom = AtomicPtr::<i64>::new(core::ptr::null_mut());
@@ -2289,7 +2286,7 @@ impl<T> AtomicPtr<T> {
22892286
/// ```
22902287
#[inline]
22912288
#[cfg(target_has_atomic = "ptr")]
2292-
#[unstable(feature = "strict_provenance_atomic_ptr", issue = "99108")]
2289+
#[stable(feature = "strict_provenance_atomic_ptr", since = "CURRENT_RUSTC_VERSION")]
22932290
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
22942291
pub fn fetch_byte_add(&self, val: usize, order: Ordering) -> *mut T {
22952292
// SAFETY: data races are prevented by atomic intrinsics.
@@ -2315,7 +2312,6 @@ impl<T> AtomicPtr<T> {
23152312
/// # Examples
23162313
///
23172314
/// ```
2318-
/// #![feature(strict_provenance_atomic_ptr)]
23192315
/// use core::sync::atomic::{AtomicPtr, Ordering};
23202316
///
23212317
/// let mut arr = [0i64, 1];
@@ -2325,7 +2321,7 @@ impl<T> AtomicPtr<T> {
23252321
/// ```
23262322
#[inline]
23272323
#[cfg(target_has_atomic = "ptr")]
2328-
#[unstable(feature = "strict_provenance_atomic_ptr", issue = "99108")]
2324+
#[stable(feature = "strict_provenance_atomic_ptr", since = "CURRENT_RUSTC_VERSION")]
23292325
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
23302326
pub fn fetch_byte_sub(&self, val: usize, order: Ordering) -> *mut T {
23312327
// SAFETY: data races are prevented by atomic intrinsics.
@@ -2361,7 +2357,6 @@ impl<T> AtomicPtr<T> {
23612357
/// # Examples
23622358
///
23632359
/// ```
2364-
/// #![feature(strict_provenance_atomic_ptr)]
23652360
/// use core::sync::atomic::{AtomicPtr, Ordering};
23662361
///
23672362
/// let pointer = &mut 3i64 as *mut i64;
@@ -2376,7 +2371,7 @@ impl<T> AtomicPtr<T> {
23762371
/// ```
23772372
#[inline]
23782373
#[cfg(target_has_atomic = "ptr")]
2379-
#[unstable(feature = "strict_provenance_atomic_ptr", issue = "99108")]
2374+
#[stable(feature = "strict_provenance_atomic_ptr", since = "CURRENT_RUSTC_VERSION")]
23802375
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
23812376
pub fn fetch_or(&self, val: usize, order: Ordering) -> *mut T {
23822377
// SAFETY: data races are prevented by atomic intrinsics.
@@ -2412,7 +2407,6 @@ impl<T> AtomicPtr<T> {
24122407
/// # Examples
24132408
///
24142409
/// ```
2415-
/// #![feature(strict_provenance_atomic_ptr)]
24162410
/// use core::sync::atomic::{AtomicPtr, Ordering};
24172411
///
24182412
/// let pointer = &mut 3i64 as *mut i64;
@@ -2426,7 +2420,7 @@ impl<T> AtomicPtr<T> {
24262420
/// ```
24272421
#[inline]
24282422
#[cfg(target_has_atomic = "ptr")]
2429-
#[unstable(feature = "strict_provenance_atomic_ptr", issue = "99108")]
2423+
#[stable(feature = "strict_provenance_atomic_ptr", since = "CURRENT_RUSTC_VERSION")]
24302424
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
24312425
pub fn fetch_and(&self, val: usize, order: Ordering) -> *mut T {
24322426
// SAFETY: data races are prevented by atomic intrinsics.
@@ -2462,7 +2456,6 @@ impl<T> AtomicPtr<T> {
24622456
/// # Examples
24632457
///
24642458
/// ```
2465-
/// #![feature(strict_provenance_atomic_ptr)]
24662459
/// use core::sync::atomic::{AtomicPtr, Ordering};
24672460
///
24682461
/// let pointer = &mut 3i64 as *mut i64;
@@ -2474,7 +2467,7 @@ impl<T> AtomicPtr<T> {
24742467
/// ```
24752468
#[inline]
24762469
#[cfg(target_has_atomic = "ptr")]
2477-
#[unstable(feature = "strict_provenance_atomic_ptr", issue = "99108")]
2470+
#[stable(feature = "strict_provenance_atomic_ptr", since = "CURRENT_RUSTC_VERSION")]
24782471
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
24792472
pub fn fetch_xor(&self, val: usize, order: Ordering) -> *mut T {
24802473
// SAFETY: data races are prevented by atomic intrinsics.

library/coretests/tests/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
#![feature(std_internals)]
9696
#![feature(step_trait)]
9797
#![feature(str_internals)]
98-
#![feature(strict_provenance_atomic_ptr)]
9998
#![feature(strict_provenance_lints)]
10099
#![feature(test)]
101100
#![feature(trusted_len)]

library/std/src/fs.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,10 @@ impl OpenOptions {
16141614
/// See also [`std::fs::write()`][self::write] for a simple function to
16151615
/// create a file with some given data.
16161616
///
1617+
/// # Errors
1618+
///
1619+
/// If `.create(true)` is set without `.write(true)` or `.append(true)`,
1620+
/// calling [`open`](Self::open) will fail with [`InvalidInput`](io::ErrorKind::InvalidInput) error.
16171621
/// # Examples
16181622
///
16191623
/// ```no_run
@@ -1685,7 +1689,8 @@ impl OpenOptions {
16851689
/// * [`AlreadyExists`]: `create_new` was specified and the file already
16861690
/// exists.
16871691
/// * [`InvalidInput`]: Invalid combinations of open options (truncate
1688-
/// without write access, no access mode set, etc.).
1692+
/// without write access, create without write or append access,
1693+
/// no access mode set, etc.).
16891694
///
16901695
/// The following errors don't match any existing [`io::ErrorKind`] at the moment:
16911696
/// * One of the directory components of the specified file path

library/std/src/fs/tests.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,12 +1265,7 @@ fn open_flavors() {
12651265
let mut ra = OO::new();
12661266
ra.read(true).append(true);
12671267

1268-
#[cfg(windows)]
1269-
let invalid_options = 87; // ERROR_INVALID_PARAMETER
1270-
#[cfg(all(unix, not(target_os = "vxworks")))]
1271-
let invalid_options = "Invalid argument";
1272-
#[cfg(target_os = "vxworks")]
1273-
let invalid_options = "invalid argument";
1268+
let invalid_options = "creating or truncating a file requires write or append access";
12741269

12751270
// Test various combinations of creation modes and access modes.
12761271
//
@@ -2084,3 +2079,34 @@ fn test_rename_junction() {
20842079
// Junction links are always absolute so we just check the file name is correct.
20852080
assert_eq!(fs::read_link(&dest).unwrap().file_name(), Some(not_exist.as_os_str()));
20862081
}
2082+
2083+
#[test]
2084+
fn test_open_options_invalid_combinations() {
2085+
use crate::fs::OpenOptions as OO;
2086+
2087+
let test_cases: &[(fn() -> OO, &str)] = &[
2088+
(|| OO::new().create(true).read(true).clone(), "create without write"),
2089+
(|| OO::new().create_new(true).read(true).clone(), "create_new without write"),
2090+
(|| OO::new().truncate(true).read(true).clone(), "truncate without write"),
2091+
(|| OO::new().truncate(true).append(true).clone(), "truncate with append"),
2092+
];
2093+
2094+
for (make_opts, desc) in test_cases {
2095+
let opts = make_opts();
2096+
let result = opts.open("nonexistent.txt");
2097+
assert!(result.is_err(), "{desc} should fail");
2098+
let err = result.unwrap_err();
2099+
assert_eq!(err.kind(), ErrorKind::InvalidInput, "{desc} - wrong error kind");
2100+
assert_eq!(
2101+
err.to_string(),
2102+
"creating or truncating a file requires write or append access",
2103+
"{desc} - wrong error message"
2104+
);
2105+
}
2106+
2107+
let result = OO::new().open("nonexistent.txt");
2108+
assert!(result.is_err(), "no access mode should fail");
2109+
let err = result.unwrap_err();
2110+
assert_eq!(err.kind(), ErrorKind::InvalidInput);
2111+
assert_eq!(err.to_string(), "must specify at least one of read, write, or append access");
2112+
}

0 commit comments

Comments
 (0)