From b032fac34e5be72aa02748eadd4e8d8917a7e758 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 6 Nov 2025 18:07:49 +0100 Subject: [PATCH 1/7] stabilize duration_from_nanos_u128 --- library/core/src/time.rs | 7 +++---- library/coretests/tests/lib.rs | 1 - src/tools/miri/src/lib.rs | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/library/core/src/time.rs b/library/core/src/time.rs index f721fcd6156cf..51a01545f5cf5 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -317,7 +317,6 @@ impl Duration { /// # Examples /// /// ``` - /// #![feature(duration_from_nanos_u128)] /// use std::time::Duration; /// /// let nanos = 10_u128.pow(24) + 321; @@ -326,12 +325,12 @@ impl Duration { /// assert_eq!(10_u64.pow(15), duration.as_secs()); /// assert_eq!(321, duration.subsec_nanos()); /// ``` - #[unstable(feature = "duration_from_nanos_u128", issue = "139201")] - // This is necessary because of const `try_from`, but can be removed if a trait-free impl is used instead - #[rustc_const_unstable(feature = "duration_from_nanos_u128", issue = "139201")] + #[stable(feature = "duration_from_nanos_u128", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "duration_from_nanos_u128", since = "CURRENT_RUSTC_VERSION")] #[must_use] #[inline] #[track_caller] + #[rustc_allow_const_fn_unstable(const_trait_impl, const_convert)] // for `u64::try_from` pub const fn from_nanos_u128(nanos: u128) -> Duration { const NANOS_PER_SEC: u128 = self::NANOS_PER_SEC as u128; let Ok(secs) = u64::try_from(nanos / NANOS_PER_SEC) else { diff --git a/library/coretests/tests/lib.rs b/library/coretests/tests/lib.rs index 80b62038c40ec..e190536abcf9f 100644 --- a/library/coretests/tests/lib.rs +++ b/library/coretests/tests/lib.rs @@ -42,7 +42,6 @@ #![feature(drop_guard)] #![feature(duration_constants)] #![feature(duration_constructors)] -#![feature(duration_from_nanos_u128)] #![feature(error_generic_member_access)] #![feature(exact_div)] #![feature(exact_size_is_empty)] diff --git a/src/tools/miri/src/lib.rs b/src/tools/miri/src/lib.rs index b756fbb901bc6..0b40c76e251f3 100644 --- a/src/tools/miri/src/lib.rs +++ b/src/tools/miri/src/lib.rs @@ -17,7 +17,7 @@ #![feature(derive_coerce_pointee)] #![feature(arbitrary_self_types)] #![feature(iter_advance_by)] -#![feature(duration_from_nanos_u128)] +#![cfg_attr(bootstrap, feature(duration_from_nanos_u128))] // Configure clippy and other lints #![allow( clippy::collapsible_else_if, From 112d833ea5c72f89078069ffc5d10da5b1adf2ca Mon Sep 17 00:00:00 2001 From: yukang Date: Fri, 7 Nov 2025 16:19:30 +0800 Subject: [PATCH 2/7] Fix ICE for repr simd on non struct --- compiler/rustc_hir_typeck/src/inline_asm.rs | 8 +++++ .../asm/invalid-repr-simd-on-enum-148634.rs | 16 ++++++++++ .../invalid-repr-simd-on-enum-148634.stderr | 30 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 tests/ui/asm/invalid-repr-simd-on-enum-148634.rs create mode 100644 tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr diff --git a/compiler/rustc_hir_typeck/src/inline_asm.rs b/compiler/rustc_hir_typeck/src/inline_asm.rs index c0cd23be6909d..d3dc27114dc4f 100644 --- a/compiler/rustc_hir_typeck/src/inline_asm.rs +++ b/compiler/rustc_hir_typeck/src/inline_asm.rs @@ -93,6 +93,14 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> { } } ty::Adt(adt, args) if adt.repr().simd() => { + if !adt.is_struct() { + self.fcx.dcx().span_delayed_bug( + span, + format!("repr(simd) should only be used on structs, got {}", adt.descr()), + ); + return Err(NonAsmTypeReason::Invalid(ty)); + } + let fields = &adt.non_enum_variant().fields; if fields.is_empty() { return Err(NonAsmTypeReason::EmptySIMDArray(ty)); diff --git a/tests/ui/asm/invalid-repr-simd-on-enum-148634.rs b/tests/ui/asm/invalid-repr-simd-on-enum-148634.rs new file mode 100644 index 0000000000000..2764a87da5904 --- /dev/null +++ b/tests/ui/asm/invalid-repr-simd-on-enum-148634.rs @@ -0,0 +1,16 @@ +#![feature(repr_simd)] + +use std::arch::asm; + +#[repr(simd)] +//~^ ERROR attribute should be applied to a struct +//~| ERROR unsupported representation for zero-variant enum +enum Es {} + +fn main() { + unsafe { + let mut x: Es; + asm!("{}", out(reg) x); + //~^ ERROR cannot use value of type `Es` for inline assembly + } +} diff --git a/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr b/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr new file mode 100644 index 0000000000000..2ddc472de00d5 --- /dev/null +++ b/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr @@ -0,0 +1,30 @@ +error[E0517]: attribute should be applied to a struct + --> $DIR/invalid-repr-simd-on-enum-148634.rs:5:8 + | +LL | #[repr(simd)] + | ^^^^ +... +LL | enum Es {} + | ---------- not a struct + +error[E0084]: unsupported representation for zero-variant enum + --> $DIR/invalid-repr-simd-on-enum-148634.rs:5:8 + | +LL | #[repr(simd)] + | ^^^^ +... +LL | enum Es {} + | ------- zero-variant enum + +error: cannot use value of type `Es` for inline assembly + --> $DIR/invalid-repr-simd-on-enum-148634.rs:13:29 + | +LL | asm!("{}", out(reg) x); + | ^ + | + = note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0084, E0517. +For more information about an error, try `rustc --explain E0084`. From 258a446c898dbcba98b95a0759e019aa366cb8b6 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 11 Nov 2025 11:07:01 +1100 Subject: [PATCH 3/7] Simplify `Resolver::resolve_macro_path`. There are only two call sites, and three of the arguments are identical at both call sites. This commit removes those arguments and renames the method accordingly. --- compiler/rustc_resolve/src/ident.rs | 5 +---- compiler/rustc_resolve/src/macros.rs | 16 +++++----------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index f3f0a74d03bc0..8ecae07dea67d 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -458,14 +458,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { let mut result = Err(Determinacy::Determined); for derive in parent_scope.derives { let parent_scope = &ParentScope { derives: &[], ..*parent_scope }; - match this.reborrow().resolve_macro_path( + match this.reborrow().resolve_derive_macro_path( derive, - MacroKind::Derive, parent_scope, - true, force, ignore_import, - None, ) { Ok((Some(ext), _)) => { if ext.helper_attrs.contains(&ident.name) { diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index 4a5894c9ffa86..d40752d21c1ef 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -395,14 +395,11 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> { for (i, resolution) in entry.resolutions.iter_mut().enumerate() { if resolution.exts.is_none() { resolution.exts = Some( - match self.cm().resolve_macro_path( + match self.cm().resolve_derive_macro_path( &resolution.path, - MacroKind::Derive, &parent_scope, - true, force, None, - None, ) { Ok((Some(ext), _)) => { if !ext.helper_attrs.is_empty() { @@ -706,26 +703,23 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { Ok((ext, res)) } - pub(crate) fn resolve_macro_path<'r>( + pub(crate) fn resolve_derive_macro_path<'r>( self: CmResolver<'r, 'ra, 'tcx>, path: &ast::Path, - kind: MacroKind, parent_scope: &ParentScope<'ra>, - trace: bool, force: bool, ignore_import: Option>, - suggestion_span: Option, ) -> Result<(Option>, Res), Determinacy> { self.resolve_macro_or_delegation_path( path, - kind, + MacroKind::Derive, parent_scope, - trace, + true, force, None, None, ignore_import, - suggestion_span, + None, ) } From 8ece93912c493990e5533eca4c3874db8ece9466 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 11 Nov 2025 11:13:50 +1100 Subject: [PATCH 4/7] Remove `trace` argument from `resolve_macro_or_delegation_path`. It's `true` at all call sites. --- compiler/rustc_resolve/src/macros.rs | 37 +++++++++++----------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index d40752d21c1ef..4fed69071e58f 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -561,7 +561,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { path, kind, parent_scope, - true, force, deleg_impl, invoc_in_mod_inert_attr.map(|def_id| (def_id, node_id)), @@ -714,7 +713,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { path, MacroKind::Derive, parent_scope, - true, force, None, None, @@ -728,7 +726,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { ast_path: &ast::Path, kind: MacroKind, parent_scope: &ParentScope<'ra>, - trace: bool, force: bool, deleg_impl: Option, invoc_in_mod_inert_attr: Option<(LocalDefId, NodeId)>, @@ -767,16 +764,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { PathResult::Module(..) => unreachable!(), }; - if trace { - self.multi_segment_macro_resolutions.borrow_mut(&self).push(( - path, - path_span, - kind, - *parent_scope, - res.ok(), - ns, - )); - } + self.multi_segment_macro_resolutions.borrow_mut(&self).push(( + path, + path_span, + kind, + *parent_scope, + res.ok(), + ns, + )); self.prohibit_imported_non_macro_attrs(None, res.ok(), path_span); res @@ -794,15 +789,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { return Err(Determinacy::Undetermined); } - if trace { - self.single_segment_macro_resolutions.borrow_mut(&self).push(( - path[0].ident, - kind, - *parent_scope, - binding.ok(), - suggestion_span, - )); - } + self.single_segment_macro_resolutions.borrow_mut(&self).push(( + path[0].ident, + kind, + *parent_scope, + binding.ok(), + suggestion_span, + )); let res = binding.map(|binding| binding.res()); self.prohibit_imported_non_macro_attrs(binding.ok(), res.ok(), path_span); From b728064935ac5a6a534ffc1f92ac8f83f134ac4b Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 13 Nov 2025 09:10:15 +1100 Subject: [PATCH 5/7] Add a helpful comment to `DeriveResolution::exts`. --- compiler/rustc_expand/src/base.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 810a5a21a055b..946f17943fe3d 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -1099,6 +1099,9 @@ pub struct Indeterminate; pub struct DeriveResolution { pub path: ast::Path, pub item: Annotatable, + // FIXME: currently this field is only used in `is_none`/`is_some` conditions. However, the + // `Arc` will be used if the FIXME in `MacroExpander::fully_expand_fragment` + // is completed. pub exts: Option>, pub is_const: bool, } From a40c3e5b4b63bd7edc9a9f0a3b24bfe9452c5869 Mon Sep 17 00:00:00 2001 From: Sinan Nalkaya Date: Thu, 13 Nov 2025 11:53:58 +0100 Subject: [PATCH 6/7] Disable rustdoc-test-builder test partially for SGX target. --- tests/run-make/rustdoc-test-builder/rmake.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/run-make/rustdoc-test-builder/rmake.rs b/tests/run-make/rustdoc-test-builder/rmake.rs index d10a3c92cae42..17d40c68fd922 100644 --- a/tests/run-make/rustdoc-test-builder/rmake.rs +++ b/tests/run-make/rustdoc-test-builder/rmake.rs @@ -25,7 +25,10 @@ fn main() { // Some targets (for example wasm) cannot execute doctests directly even with a runner, // so only exercise the success path when the target can run on the host. - if target().contains("wasm") || std::env::var_os("REMOTE_TEST_CLIENT").is_some() { + if target().contains("wasm") + || target().contains("sgx") + || std::env::var_os("REMOTE_TEST_CLIENT").is_some() + { return; } From df57c32e6dea49c3cf89f4411940ab19365a1e3f Mon Sep 17 00:00:00 2001 From: yukang Date: Thu, 13 Nov 2025 18:56:32 +0800 Subject: [PATCH 7/7] add Tainted for NonAsmTypeReason --- compiler/rustc_hir_typeck/src/inline_asm.rs | 10 +++++++--- tests/ui/asm/invalid-repr-simd-on-enum-148634.rs | 1 - tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr | 10 +--------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/inline_asm.rs b/compiler/rustc_hir_typeck/src/inline_asm.rs index d3dc27114dc4f..6460bd72c7973 100644 --- a/compiler/rustc_hir_typeck/src/inline_asm.rs +++ b/compiler/rustc_hir_typeck/src/inline_asm.rs @@ -7,7 +7,7 @@ use rustc_middle::bug; use rustc_middle::ty::{self, Article, FloatTy, IntTy, Ty, TyCtxt, TypeVisitableExt, UintTy}; use rustc_session::lint; use rustc_span::def_id::LocalDefId; -use rustc_span::{Span, Symbol, sym}; +use rustc_span::{ErrorGuaranteed, Span, Symbol, sym}; use rustc_target::asm::{ InlineAsmReg, InlineAsmRegClass, InlineAsmRegOrRegClass, InlineAsmType, ModifierInfo, }; @@ -27,6 +27,7 @@ enum NonAsmTypeReason<'tcx> { InvalidElement(DefId, Ty<'tcx>), NotSizedPtr(Ty<'tcx>), EmptySIMDArray(Ty<'tcx>), + Tainted(ErrorGuaranteed), } impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> { @@ -94,11 +95,11 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> { } ty::Adt(adt, args) if adt.repr().simd() => { if !adt.is_struct() { - self.fcx.dcx().span_delayed_bug( + let guar = self.fcx.dcx().span_delayed_bug( span, format!("repr(simd) should only be used on structs, got {}", adt.descr()), ); - return Err(NonAsmTypeReason::Invalid(ty)); + return Err(NonAsmTypeReason::Tainted(guar)); } let fields = &adt.non_enum_variant().fields; @@ -242,6 +243,9 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> { let msg = format!("use of empty SIMD vector `{ty}`"); self.fcx.dcx().struct_span_err(expr.span, msg).emit(); } + NonAsmTypeReason::Tainted(_error_guard) => { + // An error has already been reported. + } } return None; } diff --git a/tests/ui/asm/invalid-repr-simd-on-enum-148634.rs b/tests/ui/asm/invalid-repr-simd-on-enum-148634.rs index 2764a87da5904..dff63a289522d 100644 --- a/tests/ui/asm/invalid-repr-simd-on-enum-148634.rs +++ b/tests/ui/asm/invalid-repr-simd-on-enum-148634.rs @@ -11,6 +11,5 @@ fn main() { unsafe { let mut x: Es; asm!("{}", out(reg) x); - //~^ ERROR cannot use value of type `Es` for inline assembly } } diff --git a/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr b/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr index 2ddc472de00d5..e9b13fee7f93f 100644 --- a/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr +++ b/tests/ui/asm/invalid-repr-simd-on-enum-148634.stderr @@ -16,15 +16,7 @@ LL | #[repr(simd)] LL | enum Es {} | ------- zero-variant enum -error: cannot use value of type `Es` for inline assembly - --> $DIR/invalid-repr-simd-on-enum-148634.rs:13:29 - | -LL | asm!("{}", out(reg) x); - | ^ - | - = note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors Some errors have detailed explanations: E0084, E0517. For more information about an error, try `rustc --explain E0084`.