Skip to content

Commit 916fba5

Browse files
committed
Auto merge of #147807 - samueltardieu:rollup-r0jucvf, r=samueltardieu
Rollup of 6 pull requests Successful merges: - #144936 (CFI: Fix types that implement Fn, FnMut, or FnOnce) - #147468 (Implement fs api set_times and set_times_nofollow) - #147660 (rustdoc-search: stringdex 0.0.2) - #147735 (Micro-optimization in `FunctionCx::initialize_locals`) - #147764 (Undo CopyForDeref assertion in const qualif) - #147783 (bootstrap: migrate to object 0.37) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a41214f + fd7e47e commit 916fba5

File tree

23 files changed

+1001
-113
lines changed

23 files changed

+1001
-113
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5263,9 +5263,9 @@ dependencies = [
52635263

52645264
[[package]]
52655265
name = "stringdex"
5266-
version = "0.0.1-alpha10"
5266+
version = "0.0.2"
52675267
source = "registry+https://github.com/rust-lang/crates.io-index"
5268-
checksum = "0fa846a7d509d1828a4f90962dc09810e161abcada7fc6a921e92c168d0811d7"
5268+
checksum = "18b3bd4f10d15ef859c40291769f0d85209de6b0f1c30713ff9cdf45ac43ea36"
52695269
dependencies = [
52705270
"stacker",
52715271
]

compiler/rustc_codegen_ssa/src/mir/locals.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ impl<'tcx, V> Locals<'tcx, V> {
4040
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
4141
pub(super) fn initialize_locals(&mut self, values: Vec<LocalRef<'tcx, Bx::Value>>) {
4242
assert!(self.locals.values.is_empty());
43+
self.locals.values = IndexVec::from_raw(values);
4344
// FIXME(#115215): After #115025 get's merged this might not be necessary
44-
for (local, value) in values.into_iter().enumerate() {
45+
for (local, value) in self.locals.values.iter_enumerated() {
4546
match value {
4647
LocalRef::Place(_) | LocalRef::UnsizedPlace(_) | LocalRef::PendingOperand => (),
4748
LocalRef::Operand(op) => {
48-
let local = mir::Local::from_usize(local);
4949
let expected_ty = self.monomorphize(self.mir.local_decls[local].ty);
5050
if expected_ty != op.layout.ty {
5151
warn!(
@@ -56,7 +56,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
5656
}
5757
}
5858
}
59-
self.locals.values.push(value);
6059
}
6160
}
6261

compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ where
234234

235235
Rvalue::Discriminant(place) => in_place::<Q, _>(cx, in_local, place.as_ref()),
236236

237-
Rvalue::CopyForDeref(_) => bug!("`CopyForDeref` in runtime MIR"),
237+
Rvalue::CopyForDeref(place) => in_place::<Q, _>(cx, in_local, place.as_ref()),
238238

239239
Rvalue::Use(operand)
240240
| Rvalue::Repeat(operand, _)

compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use rustc_hir as hir;
1010
use rustc_hir::LangItem;
1111
use rustc_middle::bug;
1212
use rustc_middle::ty::{
13-
self, ExistentialPredicateStableCmpExt as _, Instance, InstanceKind, IntTy, List, TraitRef, Ty,
14-
TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, UintTy,
13+
self, ExistentialPredicateStableCmpExt as _, Instance, IntTy, List, TraitRef, Ty, TyCtxt,
14+
TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, UintTy,
1515
};
1616
use rustc_span::def_id::DefId;
1717
use rustc_span::{DUMMY_SP, sym};
@@ -458,6 +458,30 @@ pub(crate) fn transform_instance<'tcx>(
458458
instance
459459
}
460460

461+
fn default_or_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> Option<DefId> {
462+
match instance.def {
463+
ty::InstanceKind::Item(def_id) | ty::InstanceKind::FnPtrShim(def_id, _) => {
464+
tcx.opt_associated_item(def_id).map(|item| item.def_id)
465+
}
466+
_ => None,
467+
}
468+
}
469+
470+
/// Determines if an instance represents a trait method implementation and returns the necessary
471+
/// information for type erasure.
472+
///
473+
/// This function handles two main cases:
474+
///
475+
/// * **Implementation in an `impl` block**: When the instance represents a concrete implementation
476+
/// of a trait method in an `impl` block, it extracts the trait reference, method ID, and trait
477+
/// ID from the implementation. The method ID is obtained from the `trait_item_def_id` field of
478+
/// the associated item, which points to the original trait method definition.
479+
///
480+
/// * **Provided method in a `trait` block or synthetic `shim`**: When the instance represents a
481+
/// default implementation provided in the trait definition itself or a synthetic shim, it uses
482+
/// the instance's own `def_id` as the method ID and determines the trait ID from the associated
483+
/// item.
484+
///
461485
fn implemented_method<'tcx>(
462486
tcx: TyCtxt<'tcx>,
463487
instance: Instance<'tcx>,
@@ -473,11 +497,9 @@ fn implemented_method<'tcx>(
473497
trait_method = tcx.associated_item(method_id);
474498
trait_id = trait_ref.skip_binder().def_id;
475499
impl_id
476-
} else if let InstanceKind::Item(def_id) = instance.def
477-
&& let Some(trait_method_bound) = tcx.opt_associated_item(def_id)
478-
{
479-
// Provided method in a `trait` block
480-
trait_method = trait_method_bound;
500+
} else if let Some(trait_method_def_id) = default_or_shim(tcx, instance) {
501+
// Provided method in a `trait` block or a synthetic `shim`
502+
trait_method = tcx.associated_item(trait_method_def_id);
481503
method_id = instance.def_id();
482504
trait_id = tcx.trait_of_assoc(method_id)?;
483505
trait_ref = ty::EarlyBinder::bind(TraitRef::from_assoc(tcx, trait_id, instance.args));

library/std/src/fs.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,87 @@ pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result
387387
inner(path.as_ref(), contents.as_ref())
388388
}
389389

390+
/// Changes the timestamps of the file or directory at the specified path.
391+
///
392+
/// This function will attempt to set the access and modification times
393+
/// to the times specified. If the path refers to a symbolic link, this function
394+
/// will follow the link and change the timestamps of the target file.
395+
///
396+
/// # Platform-specific behavior
397+
///
398+
/// This function currently corresponds to the `utimensat` function on Unix platforms, the
399+
/// `setattrlist` function on Apple platforms, and the `SetFileTime` function on Windows.
400+
///
401+
/// # Errors
402+
///
403+
/// This function will return an error if the user lacks permission to change timestamps on the
404+
/// target file or symlink. It may also return an error if the OS does not support it.
405+
///
406+
/// # Examples
407+
///
408+
/// ```no_run
409+
/// #![feature(fs_set_times)]
410+
/// use std::fs::{self, FileTimes};
411+
/// use std::time::SystemTime;
412+
///
413+
/// fn main() -> std::io::Result<()> {
414+
/// let now = SystemTime::now();
415+
/// let times = FileTimes::new()
416+
/// .set_accessed(now)
417+
/// .set_modified(now);
418+
/// fs::set_times("foo.txt", times)?;
419+
/// Ok(())
420+
/// }
421+
/// ```
422+
#[unstable(feature = "fs_set_times", issue = "147455")]
423+
#[doc(alias = "utimens")]
424+
#[doc(alias = "utimes")]
425+
#[doc(alias = "utime")]
426+
pub fn set_times<P: AsRef<Path>>(path: P, times: FileTimes) -> io::Result<()> {
427+
fs_imp::set_times(path.as_ref(), times.0)
428+
}
429+
430+
/// Changes the timestamps of the file or symlink at the specified path.
431+
///
432+
/// This function will attempt to set the access and modification times
433+
/// to the times specified. Differ from `set_times`, if the path refers to a symbolic link,
434+
/// this function will change the timestamps of the symlink itself, not the target file.
435+
///
436+
/// # Platform-specific behavior
437+
///
438+
/// This function currently corresponds to the `utimensat` function with `AT_SYMLINK_NOFOLLOW` on
439+
/// Unix platforms, the `setattrlist` function with `FSOPT_NOFOLLOW` on Apple platforms, and the
440+
/// `SetFileTime` function on Windows.
441+
///
442+
/// # Errors
443+
///
444+
/// This function will return an error if the user lacks permission to change timestamps on the
445+
/// target file or symlink. It may also return an error if the OS does not support it.
446+
///
447+
/// # Examples
448+
///
449+
/// ```no_run
450+
/// #![feature(fs_set_times)]
451+
/// use std::fs::{self, FileTimes};
452+
/// use std::time::SystemTime;
453+
///
454+
/// fn main() -> std::io::Result<()> {
455+
/// let now = SystemTime::now();
456+
/// let times = FileTimes::new()
457+
/// .set_accessed(now)
458+
/// .set_modified(now);
459+
/// fs::set_times_nofollow("symlink.txt", times)?;
460+
/// Ok(())
461+
/// }
462+
/// ```
463+
#[unstable(feature = "fs_set_times", issue = "147455")]
464+
#[doc(alias = "utimensat")]
465+
#[doc(alias = "lutimens")]
466+
#[doc(alias = "lutimes")]
467+
pub fn set_times_nofollow<P: AsRef<Path>>(path: P, times: FileTimes) -> io::Result<()> {
468+
fs_imp::set_times_nofollow(path.as_ref(), times.0)
469+
}
470+
390471
#[stable(feature = "file_lock", since = "1.89.0")]
391472
impl error::Error for TryLockError {}
392473

0 commit comments

Comments
 (0)