Skip to content

Commit 9a79a27

Browse files
committed
Auto merge of #148903 - GuillaumeGomez:rollup-hxsp81c, r=GuillaumeGomez
Rollup of 4 pull requests Successful merges: - #148587 (stabilize duration_from_nanos_u128) - #148638 (Fix ICE for repr simd on non struct) - #148808 (Some resolve cleanups) - #148901 (Disable rustdoc-test-builder test partially for SGX target.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d682af8 + 138cd58 commit 9a79a27

File tree

10 files changed

+81
-44
lines changed

10 files changed

+81
-44
lines changed

compiler/rustc_expand/src/base.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,9 @@ pub struct Indeterminate;
10991099
pub struct DeriveResolution {
11001100
pub path: ast::Path,
11011101
pub item: Annotatable,
1102+
// FIXME: currently this field is only used in `is_none`/`is_some` conditions. However, the
1103+
// `Arc<SyntaxExtension>` will be used if the FIXME in `MacroExpander::fully_expand_fragment`
1104+
// is completed.
11021105
pub exts: Option<Arc<SyntaxExtension>>,
11031106
pub is_const: bool,
11041107
}

compiler/rustc_hir_typeck/src/inline_asm.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::bug;
77
use rustc_middle::ty::{self, Article, FloatTy, IntTy, Ty, TyCtxt, TypeVisitableExt, UintTy};
88
use rustc_session::lint;
99
use rustc_span::def_id::LocalDefId;
10-
use rustc_span::{Span, Symbol, sym};
10+
use rustc_span::{ErrorGuaranteed, Span, Symbol, sym};
1111
use rustc_target::asm::{
1212
InlineAsmReg, InlineAsmRegClass, InlineAsmRegOrRegClass, InlineAsmType, ModifierInfo,
1313
};
@@ -27,6 +27,7 @@ enum NonAsmTypeReason<'tcx> {
2727
InvalidElement(DefId, Ty<'tcx>),
2828
NotSizedPtr(Ty<'tcx>),
2929
EmptySIMDArray(Ty<'tcx>),
30+
Tainted(ErrorGuaranteed),
3031
}
3132

3233
impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
@@ -93,6 +94,14 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
9394
}
9495
}
9596
ty::Adt(adt, args) if adt.repr().simd() => {
97+
if !adt.is_struct() {
98+
let guar = self.fcx.dcx().span_delayed_bug(
99+
span,
100+
format!("repr(simd) should only be used on structs, got {}", adt.descr()),
101+
);
102+
return Err(NonAsmTypeReason::Tainted(guar));
103+
}
104+
96105
let fields = &adt.non_enum_variant().fields;
97106
if fields.is_empty() {
98107
return Err(NonAsmTypeReason::EmptySIMDArray(ty));
@@ -234,6 +243,9 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
234243
let msg = format!("use of empty SIMD vector `{ty}`");
235244
self.fcx.dcx().struct_span_err(expr.span, msg).emit();
236245
}
246+
NonAsmTypeReason::Tainted(_error_guard) => {
247+
// An error has already been reported.
248+
}
237249
}
238250
return None;
239251
}

compiler/rustc_resolve/src/ident.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,14 +458,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
458458
let mut result = Err(Determinacy::Determined);
459459
for derive in parent_scope.derives {
460460
let parent_scope = &ParentScope { derives: &[], ..*parent_scope };
461-
match this.reborrow().resolve_macro_path(
461+
match this.reborrow().resolve_derive_macro_path(
462462
derive,
463-
MacroKind::Derive,
464463
parent_scope,
465-
true,
466464
force,
467465
ignore_import,
468-
None,
469466
) {
470467
Ok((Some(ext), _)) => {
471468
if ext.helper_attrs.contains(&ident.name) {

compiler/rustc_resolve/src/macros.rs

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -396,14 +396,11 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
396396
for (i, resolution) in entry.resolutions.iter_mut().enumerate() {
397397
if resolution.exts.is_none() {
398398
resolution.exts = Some(
399-
match self.cm().resolve_macro_path(
399+
match self.cm().resolve_derive_macro_path(
400400
&resolution.path,
401-
MacroKind::Derive,
402401
&parent_scope,
403-
true,
404402
force,
405403
None,
406-
None,
407404
) {
408405
Ok((Some(ext), _)) => {
409406
if !ext.helper_attrs.is_empty() {
@@ -571,7 +568,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
571568
path,
572569
kind,
573570
parent_scope,
574-
true,
575571
force,
576572
deleg_impl,
577573
invoc_in_mod_inert_attr.map(|def_id| (def_id, node_id)),
@@ -713,26 +709,22 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
713709
Ok((ext, res))
714710
}
715711

716-
pub(crate) fn resolve_macro_path<'r>(
712+
pub(crate) fn resolve_derive_macro_path<'r>(
717713
self: CmResolver<'r, 'ra, 'tcx>,
718714
path: &ast::Path,
719-
kind: MacroKind,
720715
parent_scope: &ParentScope<'ra>,
721-
trace: bool,
722716
force: bool,
723717
ignore_import: Option<Import<'ra>>,
724-
suggestion_span: Option<Span>,
725718
) -> Result<(Option<Arc<SyntaxExtension>>, Res), Determinacy> {
726719
self.resolve_macro_or_delegation_path(
727720
path,
728-
kind,
721+
MacroKind::Derive,
729722
parent_scope,
730-
trace,
731723
force,
732724
None,
733725
None,
734726
ignore_import,
735-
suggestion_span,
727+
None,
736728
)
737729
}
738730

@@ -741,7 +733,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
741733
ast_path: &ast::Path,
742734
kind: MacroKind,
743735
parent_scope: &ParentScope<'ra>,
744-
trace: bool,
745736
force: bool,
746737
deleg_impl: Option<LocalDefId>,
747738
invoc_in_mod_inert_attr: Option<(LocalDefId, NodeId)>,
@@ -780,16 +771,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
780771
PathResult::Module(..) => unreachable!(),
781772
};
782773

783-
if trace {
784-
self.multi_segment_macro_resolutions.borrow_mut(&self).push((
785-
path,
786-
path_span,
787-
kind,
788-
*parent_scope,
789-
res.ok(),
790-
ns,
791-
));
792-
}
774+
self.multi_segment_macro_resolutions.borrow_mut(&self).push((
775+
path,
776+
path_span,
777+
kind,
778+
*parent_scope,
779+
res.ok(),
780+
ns,
781+
));
793782

794783
self.prohibit_imported_non_macro_attrs(None, res.ok(), path_span);
795784
res
@@ -807,15 +796,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
807796
return Err(Determinacy::Undetermined);
808797
}
809798

810-
if trace {
811-
self.single_segment_macro_resolutions.borrow_mut(&self).push((
812-
path[0].ident,
813-
kind,
814-
*parent_scope,
815-
binding.ok(),
816-
suggestion_span,
817-
));
818-
}
799+
self.single_segment_macro_resolutions.borrow_mut(&self).push((
800+
path[0].ident,
801+
kind,
802+
*parent_scope,
803+
binding.ok(),
804+
suggestion_span,
805+
));
819806

820807
let res = binding.map(|binding| binding.res());
821808
self.prohibit_imported_non_macro_attrs(binding.ok(), res.ok(), path_span);

library/core/src/time.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ impl Duration {
317317
/// # Examples
318318
///
319319
/// ```
320-
/// #![feature(duration_from_nanos_u128)]
321320
/// use std::time::Duration;
322321
///
323322
/// let nanos = 10_u128.pow(24) + 321;
@@ -326,12 +325,12 @@ impl Duration {
326325
/// assert_eq!(10_u64.pow(15), duration.as_secs());
327326
/// assert_eq!(321, duration.subsec_nanos());
328327
/// ```
329-
#[unstable(feature = "duration_from_nanos_u128", issue = "139201")]
330-
// This is necessary because of const `try_from`, but can be removed if a trait-free impl is used instead
331-
#[rustc_const_unstable(feature = "duration_from_nanos_u128", issue = "139201")]
328+
#[stable(feature = "duration_from_nanos_u128", since = "CURRENT_RUSTC_VERSION")]
329+
#[rustc_const_stable(feature = "duration_from_nanos_u128", since = "CURRENT_RUSTC_VERSION")]
332330
#[must_use]
333331
#[inline]
334332
#[track_caller]
333+
#[rustc_allow_const_fn_unstable(const_trait_impl, const_convert)] // for `u64::try_from`
335334
pub const fn from_nanos_u128(nanos: u128) -> Duration {
336335
const NANOS_PER_SEC: u128 = self::NANOS_PER_SEC as u128;
337336
let Ok(secs) = u64::try_from(nanos / NANOS_PER_SEC) else {

library/coretests/tests/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#![feature(drop_guard)]
4343
#![feature(duration_constants)]
4444
#![feature(duration_constructors)]
45-
#![feature(duration_from_nanos_u128)]
4645
#![feature(error_generic_member_access)]
4746
#![feature(exact_div)]
4847
#![feature(exact_size_is_empty)]

src/tools/miri/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#![feature(derive_coerce_pointee)]
1818
#![feature(arbitrary_self_types)]
1919
#![feature(iter_advance_by)]
20-
#![feature(duration_from_nanos_u128)]
20+
#![cfg_attr(bootstrap, feature(duration_from_nanos_u128))]
2121
// Configure clippy and other lints
2222
#![allow(
2323
clippy::collapsible_else_if,

tests/run-make/rustdoc-test-builder/rmake.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ fn main() {
2525

2626
// Some targets (for example wasm) cannot execute doctests directly even with a runner,
2727
// so only exercise the success path when the target can run on the host.
28-
if target().contains("wasm") || std::env::var_os("REMOTE_TEST_CLIENT").is_some() {
28+
if target().contains("wasm")
29+
|| target().contains("sgx")
30+
|| std::env::var_os("REMOTE_TEST_CLIENT").is_some()
31+
{
2932
return;
3033
}
3134

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![feature(repr_simd)]
2+
3+
use std::arch::asm;
4+
5+
#[repr(simd)]
6+
//~^ ERROR attribute should be applied to a struct
7+
//~| ERROR unsupported representation for zero-variant enum
8+
enum Es {}
9+
10+
fn main() {
11+
unsafe {
12+
let mut x: Es;
13+
asm!("{}", out(reg) x);
14+
}
15+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0517]: attribute should be applied to a struct
2+
--> $DIR/invalid-repr-simd-on-enum-148634.rs:5:8
3+
|
4+
LL | #[repr(simd)]
5+
| ^^^^
6+
...
7+
LL | enum Es {}
8+
| ---------- not a struct
9+
10+
error[E0084]: unsupported representation for zero-variant enum
11+
--> $DIR/invalid-repr-simd-on-enum-148634.rs:5:8
12+
|
13+
LL | #[repr(simd)]
14+
| ^^^^
15+
...
16+
LL | enum Es {}
17+
| ------- zero-variant enum
18+
19+
error: aborting due to 2 previous errors
20+
21+
Some errors have detailed explanations: E0084, E0517.
22+
For more information about an error, try `rustc --explain E0084`.

0 commit comments

Comments
 (0)