Skip to content

Commit

Permalink
Auto merge of #137284 - matthiaskrgr:rollup-deuhk46, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 9 pull requests

Successful merges:

 - #127793 (Added project-specific Zed IDE settings)
 - #134995 (Stabilize const_slice_flatten)
 - #136301 (Improve instant docs)
 - #136347 (Add a bullet point to `std::fs::copy`)
 - #136794 (Stabilize file_lock)
 - #137094 (x86_win64 ABI: do not use xmm0 with softfloat ABI)
 - #137227 (docs(dev): Update the feature-gate instructions)
 - #137232 (Don't mention `FromResidual` on bad `?`)
 - #137251 (coverage: Get hole spans from nested items without fully visiting them)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Feb 19, 2025
2 parents ed49386 + 3fc6dfd commit f280acf
Show file tree
Hide file tree
Showing 21 changed files with 330 additions and 125 deletions.
51 changes: 26 additions & 25 deletions compiler/rustc_mir_transform/src/coverage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,35 +346,37 @@ fn extract_hole_spans_from_hir<'tcx>(
body_span: Span, // Usually `hir_body.value.span`, but not always
hir_body: &hir::Body<'tcx>,
) -> Vec<Span> {
struct HolesVisitor<'hir, F> {
tcx: TyCtxt<'hir>,
visit_hole_span: F,
struct HolesVisitor<'tcx> {
tcx: TyCtxt<'tcx>,
body_span: Span,
hole_spans: Vec<Span>,
}

impl<'hir, F: FnMut(Span)> Visitor<'hir> for HolesVisitor<'hir, F> {
/// - We need `NestedFilter::INTRA = true` so that `visit_item` will be called.
/// - Bodies of nested items don't actually get visited, because of the
/// `visit_item` override.
/// - For nested bodies that are not part of an item, we do want to visit any
/// items contained within them.
type NestedFilter = nested_filter::All;
impl<'tcx> Visitor<'tcx> for HolesVisitor<'tcx> {
/// We have special handling for nested items, but we still want to
/// traverse into nested bodies of things that are not considered items,
/// such as "anon consts" (e.g. array lengths).
type NestedFilter = nested_filter::OnlyBodies;

fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
fn maybe_tcx(&mut self) -> TyCtxt<'tcx> {
self.tcx
}

fn visit_item(&mut self, item: &'hir hir::Item<'hir>) {
(self.visit_hole_span)(item.span);
/// We override `visit_nested_item` instead of `visit_item` because we
/// only need the item's span, not the item itself.
fn visit_nested_item(&mut self, id: hir::ItemId) -> Self::Result {
let span = self.tcx.def_span(id.owner_id.def_id);
self.visit_hole_span(span);
// Having visited this item, we don't care about its children,
// so don't call `walk_item`.
}

// We override `visit_expr` instead of the more specific expression
// visitors, so that we have direct access to the expression span.
fn visit_expr(&mut self, expr: &'hir hir::Expr<'hir>) {
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
match expr.kind {
hir::ExprKind::Closure(_) | hir::ExprKind::ConstBlock(_) => {
(self.visit_hole_span)(expr.span);
self.visit_hole_span(expr.span);
// Having visited this expression, we don't care about its
// children, so don't call `walk_expr`.
}
Expand All @@ -384,18 +386,17 @@ fn extract_hole_spans_from_hir<'tcx>(
}
}
}

let mut hole_spans = vec![];
let mut visitor = HolesVisitor {
tcx,
visit_hole_span: |hole_span| {
impl HolesVisitor<'_> {
fn visit_hole_span(&mut self, hole_span: Span) {
// Discard any holes that aren't directly visible within the body span.
if body_span.contains(hole_span) && body_span.eq_ctxt(hole_span) {
hole_spans.push(hole_span);
if self.body_span.contains(hole_span) && self.body_span.eq_ctxt(hole_span) {
self.hole_spans.push(hole_span);
}
},
};
}
}

let mut visitor = HolesVisitor { tcx, body_span, hole_spans: vec![] };

visitor.visit_body(hir_body);
hole_spans
visitor.hole_spans
}
16 changes: 10 additions & 6 deletions compiler/rustc_target/src/callconv/x86_win64.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use rustc_abi::{BackendRepr, Float, Integer, Primitive, RegKind, Size};

use crate::callconv::{ArgAbi, FnAbi, Reg};
use crate::spec::HasTargetSpec;
use crate::spec::{HasTargetSpec, RustcAbi};

// Win64 ABI: https://docs.microsoft.com/en-us/cpp/build/parameter-passing

pub(crate) fn compute_abi_info<Ty>(_cx: &impl HasTargetSpec, fn_abi: &mut FnAbi<'_, Ty>) {
pub(crate) fn compute_abi_info<Ty>(cx: &impl HasTargetSpec, fn_abi: &mut FnAbi<'_, Ty>) {
let fixup = |a: &mut ArgAbi<'_, Ty>, is_ret: bool| {
match a.layout.backend_repr {
BackendRepr::Uninhabited | BackendRepr::Memory { sized: false } => {}
Expand All @@ -24,10 +24,14 @@ pub(crate) fn compute_abi_info<Ty>(_cx: &impl HasTargetSpec, fn_abi: &mut FnAbi<
}
BackendRepr::Scalar(scalar) => {
if is_ret && matches!(scalar.primitive(), Primitive::Int(Integer::I128, _)) {
// `i128` is returned in xmm0 by Clang and GCC
// FIXME(#134288): This may change for the `-msvc` targets in the future.
let reg = Reg { kind: RegKind::Vector, size: Size::from_bits(128) };
a.cast_to(reg);
if cx.target_spec().rustc_abi == Some(RustcAbi::X86Softfloat) {
// Use the native `i128` LLVM type for the softfloat ABI -- in other words, adjust nothing.
} else {
// `i128` is returned in xmm0 by Clang and GCC
// FIXME(#134288): This may change for the `-msvc` targets in the future.
let reg = Reg { kind: RegKind::Vector, size: Size::from_bits(128) };
a.cast_to(reg);
}
} else if a.layout.size.bytes() > 8
&& !matches!(scalar.primitive(), Primitive::Float(Float::F128))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3289,6 +3289,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
let mut parent_trait_pred =
self.resolve_vars_if_possible(data.derived.parent_trait_pred);
let parent_def_id = parent_trait_pred.def_id();
if tcx.is_diagnostic_item(sym::FromResidual, parent_def_id)
&& !tcx.features().enabled(sym::try_trait_v2)
{
// If `#![feature(try_trait_v2)]` is not enabled, then there's no point on
// talking about `FromResidual<Result<A, B>>`, as the end user has nothing they
// can do about it. As far as they are concerned, `?` is compiler magic.
return;
}
let self_ty_str =
tcx.short_string(parent_trait_pred.skip_binder().self_ty(), err.long_ty_path());
let trait_name = parent_trait_pred.print_modifiers_and_trait_path().to_string();
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4796,7 +4796,7 @@ impl<T, const N: usize> [[T; N]] {
/// assert!(empty_slice_of_arrays.as_flattened().is_empty());
/// ```
#[stable(feature = "slice_flatten", since = "1.80.0")]
#[rustc_const_unstable(feature = "const_slice_flatten", issue = "95629")]
#[rustc_const_stable(feature = "const_slice_flatten", since = "CURRENT_RUSTC_VERSION")]
pub const fn as_flattened(&self) -> &[T] {
let len = if T::IS_ZST {
self.len().checked_mul(N).expect("slice len overflow")
Expand Down Expand Up @@ -4833,7 +4833,7 @@ impl<T, const N: usize> [[T; N]] {
/// assert_eq!(array, [[6, 7, 8], [9, 10, 11], [12, 13, 14]]);
/// ```
#[stable(feature = "slice_flatten", since = "1.80.0")]
#[rustc_const_unstable(feature = "const_slice_flatten", issue = "95629")]
#[rustc_const_stable(feature = "const_slice_flatten", since = "CURRENT_RUSTC_VERSION")]
pub const fn as_flattened_mut(&mut self) -> &mut [T] {
let len = if T::IS_ZST {
self.len().checked_mul(N).expect("slice len overflow")
Expand Down
16 changes: 6 additions & 10 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,6 @@ impl File {
/// # Examples
///
/// ```no_run
/// #![feature(file_lock)]
/// use std::fs::File;
///
/// fn main() -> std::io::Result<()> {
Expand All @@ -673,7 +672,7 @@ impl File {
/// Ok(())
/// }
/// ```
#[unstable(feature = "file_lock", issue = "130994")]
#[stable(feature = "file_lock", since = "CURRENT_RUSTC_VERSION")]
pub fn lock(&self) -> io::Result<()> {
self.inner.lock()
}
Expand Down Expand Up @@ -717,7 +716,6 @@ impl File {
/// # Examples
///
/// ```no_run
/// #![feature(file_lock)]
/// use std::fs::File;
///
/// fn main() -> std::io::Result<()> {
Expand All @@ -726,7 +724,7 @@ impl File {
/// Ok(())
/// }
/// ```
#[unstable(feature = "file_lock", issue = "130994")]
#[stable(feature = "file_lock", since = "CURRENT_RUSTC_VERSION")]
pub fn lock_shared(&self) -> io::Result<()> {
self.inner.lock_shared()
}
Expand Down Expand Up @@ -775,7 +773,6 @@ impl File {
/// # Examples
///
/// ```no_run
/// #![feature(file_lock)]
/// use std::fs::File;
///
/// fn main() -> std::io::Result<()> {
Expand All @@ -784,7 +781,7 @@ impl File {
/// Ok(())
/// }
/// ```
#[unstable(feature = "file_lock", issue = "130994")]
#[stable(feature = "file_lock", since = "CURRENT_RUSTC_VERSION")]
pub fn try_lock(&self) -> io::Result<bool> {
self.inner.try_lock()
}
Expand Down Expand Up @@ -832,7 +829,6 @@ impl File {
/// # Examples
///
/// ```no_run
/// #![feature(file_lock)]
/// use std::fs::File;
///
/// fn main() -> std::io::Result<()> {
Expand All @@ -841,7 +837,7 @@ impl File {
/// Ok(())
/// }
/// ```
#[unstable(feature = "file_lock", issue = "130994")]
#[stable(feature = "file_lock", since = "CURRENT_RUSTC_VERSION")]
pub fn try_lock_shared(&self) -> io::Result<bool> {
self.inner.try_lock_shared()
}
Expand Down Expand Up @@ -869,7 +865,6 @@ impl File {
/// # Examples
///
/// ```no_run
/// #![feature(file_lock)]
/// use std::fs::File;
///
/// fn main() -> std::io::Result<()> {
Expand All @@ -879,7 +874,7 @@ impl File {
/// Ok(())
/// }
/// ```
#[unstable(feature = "file_lock", issue = "130994")]
#[stable(feature = "file_lock", since = "CURRENT_RUSTC_VERSION")]
pub fn unlock(&self) -> io::Result<()> {
self.inner.unlock()
}
Expand Down Expand Up @@ -2531,6 +2526,7 @@ pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()>
/// * `from` does not exist.
/// * The current process does not have the permission rights to read
/// `from` or write `to`.
/// * The parent directory of `to` doesn't exist.
///
/// # Examples
///
Expand Down
10 changes: 8 additions & 2 deletions library/std/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,17 @@ use crate::sys_common::{FromInner, IntoInner};
/// use std::time::{Instant, Duration};
///
/// let now = Instant::now();
/// let max_seconds = u64::MAX / 1_000_000_000;
/// let duration = Duration::new(max_seconds, 0);
/// let days_per_10_millennia = 365_2425;
/// let solar_seconds_per_day = 60 * 60 * 24;
/// let millenium_in_solar_seconds = 31_556_952_000;
/// assert_eq!(millenium_in_solar_seconds, days_per_10_millennia * solar_seconds_per_day / 10);
///
/// let duration = Duration::new(millenium_in_solar_seconds, 0);
/// println!("{:?}", now + duration);
/// ```
///
/// For cross-platform code, you can comfortably use durations of up to around one hundred years.
///
/// # Underlying System calls
///
/// The following system calls are [currently] being used by `now()` to find out
Expand Down
Loading

0 comments on commit f280acf

Please sign in to comment.