Skip to content

Commit

Permalink
Auto merge of #89089 - JohnTitor:rollup-6s6mccx, r=JohnTitor
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Sep 19, 2021
2 parents 7a3d1a5 + 4877ad3 commit 08a0307
Show file tree
Hide file tree
Showing 61 changed files with 506 additions and 139 deletions.
25 changes: 21 additions & 4 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,12 +918,29 @@ fn generic_simd_intrinsic(
}

if let Some(stripped) = name_str.strip_prefix("simd_shuffle") {
let n: u64 = stripped.parse().unwrap_or_else(|_| {
span_bug!(span, "bad `simd_shuffle` instruction only caught in codegen?")
});
// If this intrinsic is the older "simd_shuffleN" form, simply parse the integer.
// If there is no suffix, use the index array length.
let n: u64 = if stripped.is_empty() {
// Make sure this is actually an array, since typeck only checks the length-suffixed
// version of this intrinsic.
match args[2].layout.ty.kind() {
ty::Array(ty, len) if matches!(ty.kind(), ty::Uint(ty::UintTy::U32)) => {
len.try_eval_usize(bx.cx.tcx, ty::ParamEnv::reveal_all()).unwrap_or_else(|| {
span_bug!(span, "could not evaluate shuffle index array length")
})
}
_ => return_error!(
"simd_shuffle index must be an array of `u32`, got `{}`",
args[2].layout.ty
),
}
} else {
stripped.parse().unwrap_or_else(|_| {
span_bug!(span, "bad `simd_shuffle` instruction only caught in codegen?")
})
};

require_simd!(ret_ty, "return");

let (out_len, out_ty) = ret_ty.simd_size_and_type(bx.tcx());
require!(
out_len == n,
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
if i == 2 && intrinsic.as_str().starts_with("simd_shuffle") {
if let mir::Operand::Constant(constant) = arg {
let c = self.eval_mir_constant(constant);
let (llval, ty) =
self.simd_shuffle_indices(&bx, constant.span, constant.ty(), c);
let (llval, ty) = self.simd_shuffle_indices(
&bx,
constant.span,
self.monomorphize(constant.ty()),
c,
);
return OperandRef {
val: Immediate(llval),
layout: bx.layout_of(ty),
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/transform/check_consts/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,11 @@ impl Checker<'mir, 'tcx> {
match pred.skip_binder() {
ty::ExistentialPredicate::AutoTrait(_)
| ty::ExistentialPredicate::Projection(_) => {
self.check_op(ops::ty::TraitBound(kind))
self.check_op(ops::ty::DynTrait(kind))
}
ty::ExistentialPredicate::Trait(trait_ref) => {
if Some(trait_ref.def_id) != self.tcx.lang_items().sized_trait() {
self.check_op(ops::ty::TraitBound(kind))
self.check_op(ops::ty::DynTrait(kind))
}
}
}
Expand Down
45 changes: 42 additions & 3 deletions compiler/rustc_const_eval/src/transform/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ pub mod ty {
}

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

match ccx.fn_sig() {
Some(fn_sig) if !fn_sig.span.contains(span) => {
builder.span_label(fn_sig.span, "function declared as const here");
err.span_label(fn_sig.span, "function declared as const here");
}
_ => {}
}

builder
err
}
}

#[derive(Debug)]
pub struct DynTrait(pub mir::LocalKind);
impl NonConstOp for DynTrait {
fn importance(&self) -> DiagnosticImportance {
match self.0 {
mir::LocalKind::Var | mir::LocalKind::Temp => DiagnosticImportance::Secondary,
mir::LocalKind::ReturnPointer | mir::LocalKind::Arg => {
DiagnosticImportance::Primary
}
}
}

fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
if ccx.const_kind() != hir::ConstContext::ConstFn {
Status::Allowed
} else {
Status::Unstable(sym::const_fn_trait_bound)
}
}

fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
let mut err = feature_err(
&ccx.tcx.sess.parse_sess,
sym::const_fn_trait_bound,
span,
"trait objects in const fn are unstable",
);

match ccx.fn_sig() {
Some(fn_sig) if !fn_sig.span.contains(span) => {
err.span_label(fn_sig.span, "function declared as const here");
}
_ => {}
}

err
}
}

Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_error_codes/src/error_codes/E0439.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#### Note: this error code is no longer emitted by the compiler.

The length of the platform-intrinsic function `simd_shuffle` wasn't specified.

Erroneous code example:

```compile_fail,E0439
```ignore (no longer emitted)
#![feature(platform_intrinsics)]
extern "platform-intrinsic" {
Expand Down
15 changes: 9 additions & 6 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1386,14 +1386,17 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
// `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` lint if needed.
// See #78991 for an investigation of treating macros in this position
// as statements, rather than expressions, during parsing.
if let StmtKind::Expr(expr) = &stmt.kind {
if matches!(**expr, ast::Expr { kind: ast::ExprKind::MacCall(..), .. }) {
let res = match &stmt.kind {
StmtKind::Expr(expr)
if matches!(**expr, ast::Expr { kind: ast::ExprKind::MacCall(..), .. }) =>
{
self.cx.current_expansion.is_trailing_mac = true;
// Don't use `assign_id` for this statement - it may get removed
// entirely due to a `#[cfg]` on the contained expression
noop_flat_map_stmt(stmt, self)
}
}

let res = assign_id!(self, &mut stmt.id, || noop_flat_map_stmt(stmt, self));

_ => assign_id!(self, &mut stmt.id, || noop_flat_map_stmt(stmt, self)),
};
self.cx.current_expansion.is_trailing_mac = false;
res
}
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_resolve/src/late/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1652,7 +1652,11 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body<'_>) {
}

fn expression_label(ex: &hir::Expr<'_>) -> Option<Ident> {
if let hir::ExprKind::Loop(_, Some(label), ..) = ex.kind { Some(label.ident) } else { None }
match ex.kind {
hir::ExprKind::Loop(_, Some(label), ..) => Some(label.ident),
hir::ExprKind::Block(_, Some(label)) => Some(label.ident),
_ => None,
}
}

fn check_if_label_shadows_lifetime(tcx: TyCtxt<'_>, mut scope: ScopeRef<'_>, label: Ident) {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,7 @@ symbols! {
simd_select_bitmask,
simd_shl,
simd_shr,
simd_shuffle,
simd_sub,
simd_trunc,
simd_xor,
Expand Down
16 changes: 13 additions & 3 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1860,6 +1860,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
field,
expr_t,
expr,
None,
);
}
err.emit();
Expand All @@ -1886,9 +1887,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};
let expr_snippet =
self.tcx.sess.source_map().span_to_snippet(expr.span).unwrap_or(String::new());
if expr_is_call && expr_snippet.starts_with("(") && expr_snippet.ends_with(")") {
let after_open = expr.span.lo() + rustc_span::BytePos(1);
let before_close = expr.span.hi() - rustc_span::BytePos(1);
let is_wrapped = expr_snippet.starts_with("(") && expr_snippet.ends_with(")");
let after_open = expr.span.lo() + rustc_span::BytePos(1);
let before_close = expr.span.hi() - rustc_span::BytePos(1);

if expr_is_call && is_wrapped {
err.multipart_suggestion(
"remove wrapping parentheses to call the method",
vec![
Expand All @@ -1898,12 +1901,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Applicability::MachineApplicable,
);
} else if !self.expr_in_place(expr.hir_id) {
// Suggest call parentheses inside the wrapping parentheses
let span = if is_wrapped {
expr.span.with_lo(after_open).with_hi(before_close)
} else {
expr.span
};
self.suggest_method_call(
&mut err,
"use parentheses to call the method",
field,
expr_t,
expr,
Some(span),
);
} else {
err.help("methods are immutable and cannot be assigned to");
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_typeck/src/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! intrinsics that the compiler exposes.

use crate::errors::{
SimdShuffleMissingLength, UnrecognizedAtomicOperation, UnrecognizedIntrinsicFunction,
UnrecognizedAtomicOperation, UnrecognizedIntrinsicFunction,
WrongNumberOfGenericArgumentsToIntrinsic,
};
use crate::require_same_types;
Expand Down Expand Up @@ -468,14 +468,17 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
| sym::simd_reduce_max
| sym::simd_reduce_min_nanless
| sym::simd_reduce_max_nanless => (2, vec![param(0)], param(1)),
sym::simd_shuffle => (3, vec![param(0), param(0), param(1)], param(2)),
name if name.as_str().starts_with("simd_shuffle") => {
match name.as_str()["simd_shuffle".len()..].parse() {
Ok(n) => {
let params = vec![param(0), param(0), tcx.mk_array(tcx.types.u32, n)];
(2, params, param(1))
}
Err(_) => {
tcx.sess.emit_err(SimdShuffleMissingLength { span: it.span, name });
let msg =
format!("unrecognized platform-specific intrinsic function: `{}`", name);
tcx.sess.struct_span_err(it.span, &msg).emit();
return;
}
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_typeck/src/check/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
method_name: Ident,
self_ty: Ty<'tcx>,
call_expr: &hir::Expr<'_>,
span: Option<Span>,
) {
let params = self
.probe_for_name(
Expand All @@ -159,7 +160,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.unwrap_or(0);

// Account for `foo.bar<T>`;
let sugg_span = call_expr.span.shrink_to_hi();
let sugg_span = span.unwrap_or_else(|| call_expr.span).shrink_to_hi();
let (suggestion, applicability) = (
format!("({})", (0..params).map(|_| "_").collect::<Vec<_>>().join(", ")),
if params > 0 { Applicability::HasPlaceholders } else { Applicability::MaybeIncorrect },
Expand Down
15 changes: 14 additions & 1 deletion compiler/rustc_typeck/src/check/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
plural
),
);
if plural == "" {

if unmentioned_fields.len() == 1 {
let input =
unmentioned_fields.iter().map(|(_, field)| field.name).collect::<Vec<_>>();
let suggested_name = find_best_match_for_name(&input, ident.name, None);
Expand All @@ -1473,6 +1474,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// We don't want to throw `E0027` in case we have thrown `E0026` for them.
unmentioned_fields.retain(|&(_, x)| x.name != suggested_name);
}
} else if inexistent_fields.len() == 1 {
let unmentioned_field = unmentioned_fields[0].1.name;
err.span_suggestion_short(
ident.span,
&format!(
"`{}` has a field named `{}`",
tcx.def_path_str(variant.def_id),
unmentioned_field
),
unmentioned_field.to_string(),
Applicability::MaybeIncorrect,
);
}
}
}
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_typeck/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,6 @@ pub struct AssocTypeBindingNotAllowed {
pub span: Span,
}

#[derive(SessionDiagnostic)]
#[error = "E0439"]
pub struct SimdShuffleMissingLength {
#[message = "invalid `simd_shuffle`, needs length: `{name}`"]
pub span: Span,
pub name: Symbol,
}

#[derive(SessionDiagnostic)]
#[error = "E0436"]
pub struct FunctionalRecordUpdateOnNonStruct {
Expand Down
8 changes: 7 additions & 1 deletion library/alloc/src/collections/vec_deque/into_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ pub struct IntoIter<
T,
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
> {
pub(crate) inner: VecDeque<T, A>,
inner: VecDeque<T, A>,
}

impl<T, A: Allocator> IntoIter<T, A> {
pub(super) fn new(inner: VecDeque<T, A>) -> Self {
IntoIter { inner }
}
}

#[stable(feature = "collection_debug", since = "1.17.0")]
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2827,7 +2827,7 @@ impl<T, A: Allocator> IntoIterator for VecDeque<T, A> {
/// Consumes the `VecDeque` into a front-to-back iterator yielding elements by
/// value.
fn into_iter(self) -> IntoIter<T, A> {
IntoIter { inner: self }
IntoIter::new(self)
}
}

Expand Down
4 changes: 2 additions & 2 deletions library/std/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl<'a, E: Error + 'a> From<E> for Box<dyn Error + 'a> {
///
/// impl fmt::Display for AnError {
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
/// write!(f , "An error")
/// write!(f, "An error")
/// }
/// }
///
Expand Down Expand Up @@ -215,7 +215,7 @@ impl<'a, E: Error + Send + Sync + 'a> From<E> for Box<dyn Error + Send + Sync +
///
/// impl fmt::Display for AnError {
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
/// write!(f , "An error")
/// write!(f, "An error")
/// }
/// }
///
Expand Down
1 change: 1 addition & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
#![feature(atomic_mut_ptr)]
#![feature(auto_traits)]
#![feature(bench_black_box)]
#![feature(bool_to_option)]
#![feature(box_syntax)]
#![feature(c_unwind)]
#![feature(c_variadic)]
Expand Down
4 changes: 3 additions & 1 deletion library/std/src/os/linux/fs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//! Linux-specific extensions to primitives in the `std::fs` module.
//! Linux-specific extensions to primitives in the [`std::fs`] module.
//!
//! [`std::fs`]: crate::fs

#![stable(feature = "metadata_ext", since = "1.1.0")]

Expand Down
4 changes: 3 additions & 1 deletion library/std/src/os/linux/process.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//! Linux-specific extensions to primitives in the `std::process` module.
//! Linux-specific extensions to primitives in the [`std::process`] module.
//!
//! [`std::process`]: crate::process

#![unstable(feature = "linux_pidfd", issue = "82971")]

Expand Down
4 changes: 3 additions & 1 deletion library/std/src/os/unix/ffi/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Unix-specific extension to the primitives in the `std::ffi` module.
//! Unix-specific extensions to primitives in the [`std::ffi`] module.
//!
//! # Examples
//!
Expand Down Expand Up @@ -31,6 +31,8 @@
//! let bytes = os_str.as_bytes();
//! assert_eq!(bytes, b"foo");
//! ```
//!
//! [`std::ffi`]: crate::ffi

#![stable(feature = "rust1", since = "1.0.0")]

Expand Down
Loading

0 comments on commit 08a0307

Please sign in to comment.