Skip to content

Commit 08a0307

Browse files
committed
Auto merge of #89089 - JohnTitor:rollup-6s6mccx, r=JohnTitor
Rollup of 10 pull requests Successful merges: - #87960 (Suggest replacing an inexisting field for an unmentioned field) - #88855 (Allow simd_shuffle to accept vectors of any length) - #88966 (Check for shadowing issues involving block labels) - #88996 (Fix linting when trailing macro expands to a trailing semi) - #89017 (fix potential race in AtomicU64 time monotonizer) - #89021 (Add a separate error for `dyn Trait` in `const fn`) - #89051 (Add intra-doc links and small changes to `std::os` to be more consistent) - #89053 (refactor: VecDeques IntoIter fields to private) - #89055 (Suggest better place to add call parentheses for method expressions wrapped in parentheses) - #89081 (Fix a typo) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7a3d1a5 + 4877ad3 commit 08a0307

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+506
-139
lines changed

Diff for: compiler/rustc_codegen_llvm/src/intrinsic.rs

+21-4
Original file line numberDiff line numberDiff line change
@@ -918,12 +918,29 @@ fn generic_simd_intrinsic(
918918
}
919919

920920
if let Some(stripped) = name_str.strip_prefix("simd_shuffle") {
921-
let n: u64 = stripped.parse().unwrap_or_else(|_| {
922-
span_bug!(span, "bad `simd_shuffle` instruction only caught in codegen?")
923-
});
921+
// If this intrinsic is the older "simd_shuffleN" form, simply parse the integer.
922+
// If there is no suffix, use the index array length.
923+
let n: u64 = if stripped.is_empty() {
924+
// Make sure this is actually an array, since typeck only checks the length-suffixed
925+
// version of this intrinsic.
926+
match args[2].layout.ty.kind() {
927+
ty::Array(ty, len) if matches!(ty.kind(), ty::Uint(ty::UintTy::U32)) => {
928+
len.try_eval_usize(bx.cx.tcx, ty::ParamEnv::reveal_all()).unwrap_or_else(|| {
929+
span_bug!(span, "could not evaluate shuffle index array length")
930+
})
931+
}
932+
_ => return_error!(
933+
"simd_shuffle index must be an array of `u32`, got `{}`",
934+
args[2].layout.ty
935+
),
936+
}
937+
} else {
938+
stripped.parse().unwrap_or_else(|_| {
939+
span_bug!(span, "bad `simd_shuffle` instruction only caught in codegen?")
940+
})
941+
};
924942

925943
require_simd!(ret_ty, "return");
926-
927944
let (out_len, out_ty) = ret_ty.simd_size_and_type(bx.tcx());
928945
require!(
929946
out_len == n,

Diff for: compiler/rustc_codegen_ssa/src/mir/block.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
665665
if i == 2 && intrinsic.as_str().starts_with("simd_shuffle") {
666666
if let mir::Operand::Constant(constant) = arg {
667667
let c = self.eval_mir_constant(constant);
668-
let (llval, ty) =
669-
self.simd_shuffle_indices(&bx, constant.span, constant.ty(), c);
668+
let (llval, ty) = self.simd_shuffle_indices(
669+
&bx,
670+
constant.span,
671+
self.monomorphize(constant.ty()),
672+
c,
673+
);
670674
return OperandRef {
671675
val: Immediate(llval),
672676
layout: bx.layout_of(ty),

Diff for: compiler/rustc_const_eval/src/transform/check_consts/check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,11 @@ impl Checker<'mir, 'tcx> {
384384
match pred.skip_binder() {
385385
ty::ExistentialPredicate::AutoTrait(_)
386386
| ty::ExistentialPredicate::Projection(_) => {
387-
self.check_op(ops::ty::TraitBound(kind))
387+
self.check_op(ops::ty::DynTrait(kind))
388388
}
389389
ty::ExistentialPredicate::Trait(trait_ref) => {
390390
if Some(trait_ref.def_id) != self.tcx.lang_items().sized_trait() {
391-
self.check_op(ops::ty::TraitBound(kind))
391+
self.check_op(ops::ty::DynTrait(kind))
392392
}
393393
}
394394
}

Diff for: compiler/rustc_const_eval/src/transform/check_consts/ops.rs

+42-3
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ pub mod ty {
599599
}
600600

601601
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
602-
let mut builder = feature_err(
602+
let mut err = feature_err(
603603
&ccx.tcx.sess.parse_sess,
604604
sym::const_fn_trait_bound,
605605
span,
@@ -608,12 +608,51 @@ pub mod ty {
608608

609609
match ccx.fn_sig() {
610610
Some(fn_sig) if !fn_sig.span.contains(span) => {
611-
builder.span_label(fn_sig.span, "function declared as const here");
611+
err.span_label(fn_sig.span, "function declared as const here");
612612
}
613613
_ => {}
614614
}
615615

616-
builder
616+
err
617+
}
618+
}
619+
620+
#[derive(Debug)]
621+
pub struct DynTrait(pub mir::LocalKind);
622+
impl NonConstOp for DynTrait {
623+
fn importance(&self) -> DiagnosticImportance {
624+
match self.0 {
625+
mir::LocalKind::Var | mir::LocalKind::Temp => DiagnosticImportance::Secondary,
626+
mir::LocalKind::ReturnPointer | mir::LocalKind::Arg => {
627+
DiagnosticImportance::Primary
628+
}
629+
}
630+
}
631+
632+
fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
633+
if ccx.const_kind() != hir::ConstContext::ConstFn {
634+
Status::Allowed
635+
} else {
636+
Status::Unstable(sym::const_fn_trait_bound)
637+
}
638+
}
639+
640+
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
641+
let mut err = feature_err(
642+
&ccx.tcx.sess.parse_sess,
643+
sym::const_fn_trait_bound,
644+
span,
645+
"trait objects in const fn are unstable",
646+
);
647+
648+
match ccx.fn_sig() {
649+
Some(fn_sig) if !fn_sig.span.contains(span) => {
650+
err.span_label(fn_sig.span, "function declared as const here");
651+
}
652+
_ => {}
653+
}
654+
655+
err
617656
}
618657
}
619658

Diff for: compiler/rustc_error_codes/src/error_codes/E0439.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
#### Note: this error code is no longer emitted by the compiler.
2+
13
The length of the platform-intrinsic function `simd_shuffle` wasn't specified.
24

35
Erroneous code example:
46

5-
```compile_fail,E0439
7+
```ignore (no longer emitted)
68
#![feature(platform_intrinsics)]
79
810
extern "platform-intrinsic" {

Diff for: compiler/rustc_expand/src/expand.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1386,14 +1386,17 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
13861386
// `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` lint if needed.
13871387
// See #78991 for an investigation of treating macros in this position
13881388
// as statements, rather than expressions, during parsing.
1389-
if let StmtKind::Expr(expr) = &stmt.kind {
1390-
if matches!(**expr, ast::Expr { kind: ast::ExprKind::MacCall(..), .. }) {
1389+
let res = match &stmt.kind {
1390+
StmtKind::Expr(expr)
1391+
if matches!(**expr, ast::Expr { kind: ast::ExprKind::MacCall(..), .. }) =>
1392+
{
13911393
self.cx.current_expansion.is_trailing_mac = true;
1394+
// Don't use `assign_id` for this statement - it may get removed
1395+
// entirely due to a `#[cfg]` on the contained expression
1396+
noop_flat_map_stmt(stmt, self)
13921397
}
1393-
}
1394-
1395-
let res = assign_id!(self, &mut stmt.id, || noop_flat_map_stmt(stmt, self));
1396-
1398+
_ => assign_id!(self, &mut stmt.id, || noop_flat_map_stmt(stmt, self)),
1399+
};
13971400
self.cx.current_expansion.is_trailing_mac = false;
13981401
res
13991402
}

Diff for: compiler/rustc_resolve/src/late/lifetimes.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1652,7 +1652,11 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body<'_>) {
16521652
}
16531653

16541654
fn expression_label(ex: &hir::Expr<'_>) -> Option<Ident> {
1655-
if let hir::ExprKind::Loop(_, Some(label), ..) = ex.kind { Some(label.ident) } else { None }
1655+
match ex.kind {
1656+
hir::ExprKind::Loop(_, Some(label), ..) => Some(label.ident),
1657+
hir::ExprKind::Block(_, Some(label)) => Some(label.ident),
1658+
_ => None,
1659+
}
16561660
}
16571661

16581662
fn check_if_label_shadows_lifetime(tcx: TyCtxt<'_>, mut scope: ScopeRef<'_>, label: Ident) {

Diff for: compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,7 @@ symbols! {
12121212
simd_select_bitmask,
12131213
simd_shl,
12141214
simd_shr,
1215+
simd_shuffle,
12151216
simd_sub,
12161217
simd_trunc,
12171218
simd_xor,

Diff for: compiler/rustc_typeck/src/check/expr.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18601860
field,
18611861
expr_t,
18621862
expr,
1863+
None,
18631864
);
18641865
}
18651866
err.emit();
@@ -1886,9 +1887,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18861887
};
18871888
let expr_snippet =
18881889
self.tcx.sess.source_map().span_to_snippet(expr.span).unwrap_or(String::new());
1889-
if expr_is_call && expr_snippet.starts_with("(") && expr_snippet.ends_with(")") {
1890-
let after_open = expr.span.lo() + rustc_span::BytePos(1);
1891-
let before_close = expr.span.hi() - rustc_span::BytePos(1);
1890+
let is_wrapped = expr_snippet.starts_with("(") && expr_snippet.ends_with(")");
1891+
let after_open = expr.span.lo() + rustc_span::BytePos(1);
1892+
let before_close = expr.span.hi() - rustc_span::BytePos(1);
1893+
1894+
if expr_is_call && is_wrapped {
18921895
err.multipart_suggestion(
18931896
"remove wrapping parentheses to call the method",
18941897
vec![
@@ -1898,12 +1901,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18981901
Applicability::MachineApplicable,
18991902
);
19001903
} else if !self.expr_in_place(expr.hir_id) {
1904+
// Suggest call parentheses inside the wrapping parentheses
1905+
let span = if is_wrapped {
1906+
expr.span.with_lo(after_open).with_hi(before_close)
1907+
} else {
1908+
expr.span
1909+
};
19011910
self.suggest_method_call(
19021911
&mut err,
19031912
"use parentheses to call the method",
19041913
field,
19051914
expr_t,
19061915
expr,
1916+
Some(span),
19071917
);
19081918
} else {
19091919
err.help("methods are immutable and cannot be assigned to");

Diff for: compiler/rustc_typeck/src/check/intrinsic.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! intrinsics that the compiler exposes.
33
44
use crate::errors::{
5-
SimdShuffleMissingLength, UnrecognizedAtomicOperation, UnrecognizedIntrinsicFunction,
5+
UnrecognizedAtomicOperation, UnrecognizedIntrinsicFunction,
66
WrongNumberOfGenericArgumentsToIntrinsic,
77
};
88
use crate::require_same_types;
@@ -468,14 +468,17 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
468468
| sym::simd_reduce_max
469469
| sym::simd_reduce_min_nanless
470470
| sym::simd_reduce_max_nanless => (2, vec![param(0)], param(1)),
471+
sym::simd_shuffle => (3, vec![param(0), param(0), param(1)], param(2)),
471472
name if name.as_str().starts_with("simd_shuffle") => {
472473
match name.as_str()["simd_shuffle".len()..].parse() {
473474
Ok(n) => {
474475
let params = vec![param(0), param(0), tcx.mk_array(tcx.types.u32, n)];
475476
(2, params, param(1))
476477
}
477478
Err(_) => {
478-
tcx.sess.emit_err(SimdShuffleMissingLength { span: it.span, name });
479+
let msg =
480+
format!("unrecognized platform-specific intrinsic function: `{}`", name);
481+
tcx.sess.struct_span_err(it.span, &msg).emit();
479482
return;
480483
}
481484
}

Diff for: compiler/rustc_typeck/src/check/method/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
141141
method_name: Ident,
142142
self_ty: Ty<'tcx>,
143143
call_expr: &hir::Expr<'_>,
144+
span: Option<Span>,
144145
) {
145146
let params = self
146147
.probe_for_name(
@@ -159,7 +160,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
159160
.unwrap_or(0);
160161

161162
// Account for `foo.bar<T>`;
162-
let sugg_span = call_expr.span.shrink_to_hi();
163+
let sugg_span = span.unwrap_or_else(|| call_expr.span).shrink_to_hi();
163164
let (suggestion, applicability) = (
164165
format!("({})", (0..params).map(|_| "_").collect::<Vec<_>>().join(", ")),
165166
if params > 0 { Applicability::HasPlaceholders } else { Applicability::MaybeIncorrect },

Diff for: compiler/rustc_typeck/src/check/pat.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14521452
plural
14531453
),
14541454
);
1455-
if plural == "" {
1455+
1456+
if unmentioned_fields.len() == 1 {
14561457
let input =
14571458
unmentioned_fields.iter().map(|(_, field)| field.name).collect::<Vec<_>>();
14581459
let suggested_name = find_best_match_for_name(&input, ident.name, None);
@@ -1473,6 +1474,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14731474
// We don't want to throw `E0027` in case we have thrown `E0026` for them.
14741475
unmentioned_fields.retain(|&(_, x)| x.name != suggested_name);
14751476
}
1477+
} else if inexistent_fields.len() == 1 {
1478+
let unmentioned_field = unmentioned_fields[0].1.name;
1479+
err.span_suggestion_short(
1480+
ident.span,
1481+
&format!(
1482+
"`{}` has a field named `{}`",
1483+
tcx.def_path_str(variant.def_id),
1484+
unmentioned_field
1485+
),
1486+
unmentioned_field.to_string(),
1487+
Applicability::MaybeIncorrect,
1488+
);
14761489
}
14771490
}
14781491
}

Diff for: compiler/rustc_typeck/src/errors.rs

-8
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,6 @@ pub struct AssocTypeBindingNotAllowed {
121121
pub span: Span,
122122
}
123123

124-
#[derive(SessionDiagnostic)]
125-
#[error = "E0439"]
126-
pub struct SimdShuffleMissingLength {
127-
#[message = "invalid `simd_shuffle`, needs length: `{name}`"]
128-
pub span: Span,
129-
pub name: Symbol,
130-
}
131-
132124
#[derive(SessionDiagnostic)]
133125
#[error = "E0436"]
134126
pub struct FunctionalRecordUpdateOnNonStruct {

Diff for: library/alloc/src/collections/vec_deque/into_iter.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ pub struct IntoIter<
1717
T,
1818
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
1919
> {
20-
pub(crate) inner: VecDeque<T, A>,
20+
inner: VecDeque<T, A>,
21+
}
22+
23+
impl<T, A: Allocator> IntoIter<T, A> {
24+
pub(super) fn new(inner: VecDeque<T, A>) -> Self {
25+
IntoIter { inner }
26+
}
2127
}
2228

2329
#[stable(feature = "collection_debug", since = "1.17.0")]

Diff for: library/alloc/src/collections/vec_deque/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2827,7 +2827,7 @@ impl<T, A: Allocator> IntoIterator for VecDeque<T, A> {
28272827
/// Consumes the `VecDeque` into a front-to-back iterator yielding elements by
28282828
/// value.
28292829
fn into_iter(self) -> IntoIter<T, A> {
2830-
IntoIter { inner: self }
2830+
IntoIter::new(self)
28312831
}
28322832
}
28332833

Diff for: library/std/src/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl<'a, E: Error + 'a> From<E> for Box<dyn Error + 'a> {
182182
///
183183
/// impl fmt::Display for AnError {
184184
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
185-
/// write!(f , "An error")
185+
/// write!(f, "An error")
186186
/// }
187187
/// }
188188
///
@@ -215,7 +215,7 @@ impl<'a, E: Error + Send + Sync + 'a> From<E> for Box<dyn Error + Send + Sync +
215215
///
216216
/// impl fmt::Display for AnError {
217217
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
218-
/// write!(f , "An error")
218+
/// write!(f, "An error")
219219
/// }
220220
/// }
221221
///

Diff for: library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@
234234
#![feature(atomic_mut_ptr)]
235235
#![feature(auto_traits)]
236236
#![feature(bench_black_box)]
237+
#![feature(bool_to_option)]
237238
#![feature(box_syntax)]
238239
#![feature(c_unwind)]
239240
#![feature(c_variadic)]

Diff for: library/std/src/os/linux/fs.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
//! Linux-specific extensions to primitives in the `std::fs` module.
1+
//! Linux-specific extensions to primitives in the [`std::fs`] module.
2+
//!
3+
//! [`std::fs`]: crate::fs
24
35
#![stable(feature = "metadata_ext", since = "1.1.0")]
46

Diff for: library/std/src/os/linux/process.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
//! Linux-specific extensions to primitives in the `std::process` module.
1+
//! Linux-specific extensions to primitives in the [`std::process`] module.
2+
//!
3+
//! [`std::process`]: crate::process
24
35
#![unstable(feature = "linux_pidfd", issue = "82971")]
46

Diff for: library/std/src/os/unix/ffi/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Unix-specific extension to the primitives in the `std::ffi` module.
1+
//! Unix-specific extensions to primitives in the [`std::ffi`] module.
22
//!
33
//! # Examples
44
//!
@@ -31,6 +31,8 @@
3131
//! let bytes = os_str.as_bytes();
3232
//! assert_eq!(bytes, b"foo");
3333
//! ```
34+
//!
35+
//! [`std::ffi`]: crate::ffi
3436
3537
#![stable(feature = "rust1", since = "1.0.0")]
3638

0 commit comments

Comments
 (0)