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
This commit is contained in:
bors 2021-09-19 11:03:09 +00:00
commit 08a0307b32
61 changed files with 506 additions and 139 deletions

View File

@ -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,

View File

@ -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),

View File

@ -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))
}
}
}

View File

@ -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,
@ -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
}
}

View File

@ -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" {

View File

@ -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
}

View File

@ -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) {

View File

@ -1212,6 +1212,7 @@ symbols! {
simd_select_bitmask,
simd_shl,
simd_shr,
simd_shuffle,
simd_sub,
simd_trunc,
simd_xor,

View File

@ -1860,6 +1860,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
field,
expr_t,
expr,
None,
);
}
err.emit();
@ -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![
@ -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");

View File

@ -2,7 +2,7 @@
//! intrinsics that the compiler exposes.
use crate::errors::{
SimdShuffleMissingLength, UnrecognizedAtomicOperation, UnrecognizedIntrinsicFunction,
UnrecognizedAtomicOperation, UnrecognizedIntrinsicFunction,
WrongNumberOfGenericArgumentsToIntrinsic,
};
use crate::require_same_types;
@ -468,6 +468,7 @@ 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) => {
@ -475,7 +476,9 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
(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;
}
}

View File

@ -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(
@ -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 },

View File

@ -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);
@ -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,
);
}
}
}

View File

@ -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 {

View File

@ -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")]

View File

@ -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)
}
}

View File

@ -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")
/// }
/// }
///
@ -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")
/// }
/// }
///

View File

@ -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)]

View File

@ -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")]

View File

@ -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")]

View File

@ -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
//!
@ -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")]

View File

@ -1,4 +1,6 @@
//! Unix-specific extensions to primitives in the `std::fs` module.
//! Unix-specific extensions to primitives in the [`std::fs`] module.
//!
//! [`std::fs`]: crate::fs
#![stable(feature = "rust1", since = "1.0.0")]

View File

@ -4,8 +4,8 @@
//! exposes Unix-specific functions that would otherwise be inappropriate as
//! part of the core `std` library.
//!
//! It exposes more ways to deal with platform-specific strings (`OsStr`,
//! `OsString`), allows to set permissions more granularly, extract low-level
//! It exposes more ways to deal with platform-specific strings ([`OsStr`],
//! [`OsString`]), allows to set permissions more granularly, extract low-level
//! file descriptors from files and sockets, and has platform-specific helpers
//! for spawning processes.
//!
@ -24,6 +24,9 @@
//! Ok(())
//! }
//! ```
//!
//! [`OsStr`]: crate::ffi::OsStr
//! [`OsString`]: crate::ffi::OsString
#![stable(feature = "rust1", since = "1.0.0")]
#![doc(cfg(unix))]

View File

@ -1,4 +1,4 @@
//! Unix-specific networking functionality
//! Unix-specific networking functionality.
#![stable(feature = "unix_socket", since = "1.10.0")]

View File

@ -1,4 +1,6 @@
//! Unix-specific extensions to primitives in the `std::process` module.
//! Unix-specific extensions to primitives in the [`std::process`] module.
//!
//! [`std::process`]: crate::process
#![stable(feature = "rust1", since = "1.0.0")]

View File

@ -1,4 +1,6 @@
//! Unix-specific extensions to primitives in the `std::thread` module.
//! Unix-specific extensions to primitives in the [`std::thread`] module.
//!
//! [`std::thread`]: crate::thread
#![stable(feature = "thread_extensions", since = "1.9.0")]

View File

@ -1,4 +1,6 @@
//! WASI-specific extension to the primitives in the `std::ffi` module
//! WASI-specific extensions to primitives in the [`std::ffi`] module
//!
//! [`std::ffi`]: crate::ffi
#![stable(feature = "rust1", since = "1.0.0")]

View File

@ -1,4 +1,6 @@
//! WASI-specific extensions to primitives in the `std::fs` module.
//! WASI-specific extensions to primitives in the [`std::fs`] module.
//!
//! [`std::fs`]: crate::fs
#![deny(unsafe_op_in_unsafe_fn)]
#![unstable(feature = "wasi_ext", issue = "71213")]

View File

@ -24,6 +24,9 @@
//! Ok(())
//! }
//! ```
//!
//! [`OsStr`]: crate::ffi::OsStr
//! [`OsString`]: crate::ffi::OsString
#![stable(feature = "rust1", since = "1.0.0")]
#![deny(unsafe_op_in_unsafe_fn)]

View File

@ -1,4 +1,4 @@
//! Windows-specific extensions to the primitives in the `std::ffi` module.
//! Windows-specific extensions to primitives in the [`std::ffi`] module.
//!
//! # Overview
//!
@ -49,6 +49,7 @@
//! [ill-formed-utf-16]: https://simonsapin.github.io/wtf-8/#ill-formed-utf-16
//! [`collect`]: crate::iter::Iterator::collect
//! [U+FFFD]: crate::char::REPLACEMENT_CHARACTER
//! [`std::ffi`]: crate::ffi
#![stable(feature = "rust1", since = "1.0.0")]

View File

@ -1,4 +1,6 @@
//! Windows-specific extensions for the primitives in the `std::fs` module.
//! Windows-specific extensions to primitives in the [`std::fs`] module.
//!
//! [`std::fs`]: crate::fs
#![stable(feature = "rust1", since = "1.0.0")]

View File

@ -5,6 +5,22 @@
//! the core `std` library. These extensions allow developers to use
//! `std` types and idioms with Windows in a way that the normal
//! platform-agnostic idioms would not normally support.
//!
//! # Examples
//!
//! ```no_run
//! use std::fs::File;
//! use std::os::windows::prelude::*;
//!
//! fn main() -> std::io::Result<()> {
//! let f = File::create("foo.txt")?;
//! let handle = f.as_raw_handle();
//!
//! // use handle with native windows bindings
//!
//! Ok(())
//! }
//! ```
#![stable(feature = "rust1", since = "1.0.0")]
#![doc(cfg(windows))]

View File

@ -1,4 +1,6 @@
//! Extensions to `std::process` for Windows.
//! Windows-specific extensions to primitives in the [`std::process`] module.
//!
//! [`std::process`]: crate::process
#![stable(feature = "process_extensions", since = "1.2.0")]

View File

@ -1,4 +1,6 @@
//! Extensions to `std::thread` for Windows.
//! Windows-specific extensions to primitives in the [`std::thread`] module.
//!
//! [`std::thread`]: crate::thread
#![stable(feature = "thread_extensions", since = "1.9.0")]

View File

@ -37,35 +37,36 @@ pub mod inner {
// This could be a problem for programs that call instants at intervals greater
// than 68 years. Interstellar probes may want to ensure that actually_monotonic() is true.
let packed = (secs << 32) | nanos;
let old = mono.load(Relaxed);
if old == UNINITIALIZED || packed.wrapping_sub(old) < u64::MAX / 2 {
mono.store(packed, Relaxed);
raw
} else {
// Backslide occurred. We reconstruct monotonized time from the upper 32 bit of the
// passed in value and the 64bits loaded from the atomic
let seconds_lower = old >> 32;
let mut seconds_upper = secs & 0xffff_ffff_0000_0000;
if secs & 0xffff_ffff > seconds_lower {
// Backslide caused the lower 32bit of the seconds part to wrap.
// This must be the case because the seconds part is larger even though
// we are in the backslide branch, i.e. the seconds count should be smaller or equal.
//
// We assume that backslides are smaller than 2^32 seconds
// which means we need to add 1 to the upper half to restore it.
//
// Example:
// most recent observed time: 0xA1_0000_0000_0000_0000u128
// bits stored in AtomicU64: 0x0000_0000_0000_0000u64
// backslide by 1s
// caller time is 0xA0_ffff_ffff_0000_0000u128
// -> we can fix up the upper half time by adding 1 << 32
seconds_upper = seconds_upper.wrapping_add(0x1_0000_0000);
let updated = mono.fetch_update(Relaxed, Relaxed, |old| {
(old == UNINITIALIZED || packed.wrapping_sub(old) < u64::MAX / 2).then_some(packed)
});
match updated {
Ok(_) => raw,
Err(newer) => {
// Backslide occurred. We reconstruct monotonized time from the upper 32 bit of the
// passed in value and the 64bits loaded from the atomic
let seconds_lower = newer >> 32;
let mut seconds_upper = secs & 0xffff_ffff_0000_0000;
if secs & 0xffff_ffff > seconds_lower {
// Backslide caused the lower 32bit of the seconds part to wrap.
// This must be the case because the seconds part is larger even though
// we are in the backslide branch, i.e. the seconds count should be smaller or equal.
//
// We assume that backslides are smaller than 2^32 seconds
// which means we need to add 1 to the upper half to restore it.
//
// Example:
// most recent observed time: 0xA1_0000_0000_0000_0000u128
// bits stored in AtomicU64: 0x0000_0000_0000_0000u64
// backslide by 1s
// caller time is 0xA0_ffff_ffff_0000_0000u128
// -> we can fix up the upper half time by adding 1 << 32
seconds_upper = seconds_upper.wrapping_add(0x1_0000_0000);
}
let secs = seconds_upper | seconds_lower;
let nanos = newer as u32;
ZERO.checked_add_duration(&Duration::new(secs, nanos)).unwrap()
}
let secs = seconds_upper | seconds_lower;
let nanos = old as u32;
ZERO.checked_add_duration(&Duration::new(secs, nanos)).unwrap()
}
}
}

View File

@ -8,9 +8,9 @@
const fn test1<T: std::ops::Add>() {}
//[stock]~^ trait bounds
const fn test2(_x: &dyn Send) {}
//[stock]~^ trait bounds
//[stock]~^ trait objects in const fn are unstable
const fn test3() -> &'static dyn Send { loop {} }
//[stock]~^ trait bounds
//[stock]~^ trait objects in const fn are unstable
#[rustc_error]

View File

@ -7,7 +7,7 @@ LL | const fn test1<T: std::ops::Add>() {}
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
= help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
error[E0658]: trait objects in const fn are unstable
--> $DIR/const_fn_trait_bound.rs:10:16
|
LL | const fn test2(_x: &dyn Send) {}
@ -16,7 +16,7 @@ LL | const fn test2(_x: &dyn Send) {}
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
= help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
error[E0658]: trait objects in const fn are unstable
--> $DIR/const_fn_trait_bound.rs:12:21
|
LL | const fn test3() -> &'static dyn Send { loop {} }

View File

@ -130,16 +130,16 @@ const fn no_apit(_x: impl std::fmt::Debug) {}
//~^ ERROR trait bounds other than `Sized`
//~| ERROR destructor
const fn no_dyn_trait(_x: &dyn std::fmt::Debug) {}
//~^ ERROR trait bounds other than `Sized`
//~^ ERROR trait objects in const fn are unstable
const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
//~^ ERROR trait bounds other than `Sized`
//~^ ERROR trait objects in const fn are unstable
const fn no_unsafe() { unsafe {} }
const fn really_no_traits_i_mean_it() { (&() as &dyn std::fmt::Debug, ()).1 }
//~^ ERROR trait bounds other than `Sized`
//~| ERROR trait bounds other than `Sized`
//~| ERROR trait bounds other than `Sized`
//~^ ERROR trait objects in const fn are unstable
//~| ERROR trait objects in const fn are unstable
//~| ERROR trait objects in const fn are unstable
const fn no_fn_ptrs(_x: fn()) {}
//~^ ERROR function pointer

View File

@ -279,7 +279,7 @@ LL | const fn no_apit(_x: impl std::fmt::Debug) {}
| |
| constant functions cannot evaluate destructors
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
error[E0658]: trait objects in const fn are unstable
--> $DIR/min_const_fn.rs:132:23
|
LL | const fn no_dyn_trait(_x: &dyn std::fmt::Debug) {}
@ -288,7 +288,7 @@ LL | const fn no_dyn_trait(_x: &dyn std::fmt::Debug) {}
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
= help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
error[E0658]: trait objects in const fn are unstable
--> $DIR/min_const_fn.rs:134:32
|
LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
@ -297,7 +297,7 @@ LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
= help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
error[E0658]: trait objects in const fn are unstable
--> $DIR/min_const_fn.rs:139:41
|
LL | const fn really_no_traits_i_mean_it() { (&() as &dyn std::fmt::Debug, ()).1 }
@ -308,7 +308,7 @@ LL | const fn really_no_traits_i_mean_it() { (&() as &dyn std::fmt::Debug, ()).1
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
= help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
error[E0658]: trait objects in const fn are unstable
--> $DIR/min_const_fn.rs:139:42
|
LL | const fn really_no_traits_i_mean_it() { (&() as &dyn std::fmt::Debug, ()).1 }
@ -319,7 +319,7 @@ LL | const fn really_no_traits_i_mean_it() { (&() as &dyn std::fmt::Debug, ()).1
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
= help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
error[E0658]: trait objects in const fn are unstable
--> $DIR/min_const_fn.rs:139:42
|
LL | const fn really_no_traits_i_mean_it() { (&() as &dyn std::fmt::Debug, ()).1 }

View File

@ -7,9 +7,9 @@ struct Hide(HasDyn);
const fn no_inner_dyn_trait(_x: Hide) {}
const fn no_inner_dyn_trait2(x: Hide) {
x.0.field;
//~^ ERROR trait bounds other than `Sized`
//~^ ERROR trait objects in const fn are unstable
}
const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasDyn { field: &0 }) }
//~^ ERROR trait bounds other than `Sized`
//~^ ERROR trait objects in const fn are unstable
fn main() {}

View File

@ -1,4 +1,4 @@
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
error[E0658]: trait objects in const fn are unstable
--> $DIR/min_const_fn_dyn.rs:9:5
|
LL | const fn no_inner_dyn_trait2(x: Hide) {
@ -9,7 +9,7 @@ LL | x.0.field;
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
= help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
error[E0658]: trait objects in const fn are unstable
--> $DIR/min_const_fn_dyn.rs:12:66
|
LL | const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasDyn { field: &0 }) }

View File

@ -1,8 +0,0 @@
#![feature(platform_intrinsics)]
extern "platform-intrinsic" {
fn simd_shuffle<A,B>(a: A, b: A, c: [u32; 8]) -> B; //~ ERROR E0439
}
fn main () {
}

View File

@ -1,9 +0,0 @@
error[E0439]: invalid `simd_shuffle`, needs length: `simd_shuffle`
--> $DIR/E0439.rs:4:5
|
LL | fn simd_shuffle<A,B>(a: A, b: A, c: [u32; 8]) -> B;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0439`.

View File

@ -2,7 +2,10 @@ error[E0026]: struct `SimpleStruct` does not have a field named `state`
--> $DIR/issue-51102.rs:13:17
|
LL | state: 0,
| ^^^^^ struct `SimpleStruct` does not have this field
| ^^^^^
| |
| struct `SimpleStruct` does not have this field
| help: `SimpleStruct` has a field named `no_state_here`
error[E0025]: field `no_state_here` bound multiple times in the pattern
--> $DIR/issue-51102.rs:24:17

View File

@ -1,7 +1,7 @@
// check-pass
#![feature(label_break_value)]
// Issue #21633: reject duplicate loop labels in function bodies.
// Issue #21633: reject duplicate loop labels and block labels in function bodies.
//
// This is testing the generalization (to the whole function body)
// discussed here:
@ -26,6 +26,8 @@ pub fn foo() {
{ 'lt: loop { break; } }
{ 'lt: while let Some(_) = None::<i32> { break; } }
//~^ WARN label name `'lt` shadows a label name that is already in scope
{ 'bl: {} }
{ 'bl: {} } //~ WARN label name `'bl` shadows a label name that is already in scope
}

View File

@ -62,5 +62,13 @@ LL | { 'lt: loop { break; } }
LL | { 'lt: while let Some(_) = None::<i32> { break; } }
| ^^^ label `'lt` already in scope
warning: 8 warnings emitted
warning: label name `'bl` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels-2.rs:30:7
|
LL | { 'bl: {} }
| --- first declared here
LL | { 'bl: {} }
| ^^^ label `'bl` already in scope
warning: 9 warnings emitted

View File

@ -1,8 +1,7 @@
// check-pass
#![feature(label_break_value)]
// Issue #21633: reject duplicate loop labels in function bodies.
// This is testing the exact cases that are in the issue description.
// Issue #21633: reject duplicate loop labels and block labels in function bodies.
#[allow(unused_labels)]
fn foo() {
@ -24,6 +23,8 @@ fn foo() {
'lt: loop { break; }
'lt: while let Some(_) = None::<i32> { break; }
//~^ WARN label name `'lt` shadows a label name that is already in scope
'bl: {}
'bl: {} //~ WARN label name `'bl` shadows a label name that is already in scope
}
// Note however that it is okay for the same label to be reused in
@ -33,6 +34,8 @@ struct S;
impl S {
fn m1(&self) { 'okay: loop { break 'okay; } }
fn m2(&self) { 'okay: loop { break 'okay; } }
fn m3(&self) { 'okay: { break 'okay; } }
fn m4(&self) { 'okay: { break 'okay; } }
}
@ -40,5 +43,7 @@ pub fn main() {
let s = S;
s.m1();
s.m2();
s.m3();
s.m4();
foo();
}

View File

@ -1,5 +1,5 @@
warning: label name `'fl` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels.rs:10:5
--> $DIR/loops-reject-duplicate-labels.rs:9:5
|
LL | 'fl: for _ in 0..10 { break; }
| --- first declared here
@ -7,7 +7,7 @@ LL | 'fl: loop { break; }
| ^^^ label `'fl` already in scope
warning: label name `'lf` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels.rs:13:5
--> $DIR/loops-reject-duplicate-labels.rs:12:5
|
LL | 'lf: loop { break; }
| --- first declared here
@ -15,7 +15,7 @@ LL | 'lf: for _ in 0..10 { break; }
| ^^^ label `'lf` already in scope
warning: label name `'wl` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels.rs:15:5
--> $DIR/loops-reject-duplicate-labels.rs:14:5
|
LL | 'wl: while 2 > 1 { break; }
| --- first declared here
@ -23,7 +23,7 @@ LL | 'wl: loop { break; }
| ^^^ label `'wl` already in scope
warning: label name `'lw` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels.rs:17:5
--> $DIR/loops-reject-duplicate-labels.rs:16:5
|
LL | 'lw: loop { break; }
| --- first declared here
@ -31,7 +31,7 @@ LL | 'lw: while 2 > 1 { break; }
| ^^^ label `'lw` already in scope
warning: label name `'fw` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels.rs:19:5
--> $DIR/loops-reject-duplicate-labels.rs:18:5
|
LL | 'fw: for _ in 0..10 { break; }
| --- first declared here
@ -39,7 +39,7 @@ LL | 'fw: while 2 > 1 { break; }
| ^^^ label `'fw` already in scope
warning: label name `'wf` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels.rs:21:5
--> $DIR/loops-reject-duplicate-labels.rs:20:5
|
LL | 'wf: while 2 > 1 { break; }
| --- first declared here
@ -47,7 +47,7 @@ LL | 'wf: for _ in 0..10 { break; }
| ^^^ label `'wf` already in scope
warning: label name `'tl` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels.rs:23:5
--> $DIR/loops-reject-duplicate-labels.rs:22:5
|
LL | 'tl: while let Some(_) = None::<i32> { break; }
| --- first declared here
@ -55,12 +55,20 @@ LL | 'tl: loop { break; }
| ^^^ label `'tl` already in scope
warning: label name `'lt` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels.rs:25:5
--> $DIR/loops-reject-duplicate-labels.rs:24:5
|
LL | 'lt: loop { break; }
| --- first declared here
LL | 'lt: while let Some(_) = None::<i32> { break; }
| ^^^ label `'lt` already in scope
warning: 8 warnings emitted
warning: label name `'bl` shadows a label name that is already in scope
--> $DIR/loops-reject-duplicate-labels.rs:27:5
|
LL | 'bl: {}
| --- first declared here
LL | 'bl: {}
| ^^^ label `'bl` already in scope
warning: 9 warnings emitted

View File

@ -1,10 +1,10 @@
// check-pass
#![feature(label_break_value)]
#![allow(dead_code, unused_variables)]
// Issue #21633: reject duplicate loop labels in function bodies.
// Issue #21633: reject duplicate loop labels and block labels in function bodies.
//
// Test rejection of lifetimes in *expressions* that shadow loop labels.
// Test rejection of lifetimes in *expressions* that shadow labels.
fn foo() {
// Reusing lifetime `'a` in function item is okay.
@ -23,8 +23,13 @@ fn foo() {
assert_eq!((*b)(&z), z);
break 'a;
}
}
'b: {
let b = Box::new(|x: &()| ()) as Box<dyn for <'b> Fn(&'b ())>;
//~^ WARN lifetime name `'b` shadows a label name that is already in scope
break 'b;
}
}
pub fn main() {
foo();

View File

@ -6,5 +6,13 @@ LL | 'a: loop {
LL | let b = Box::new(|x: &i8| *x) as Box<dyn for <'a> Fn(&'a i8) -> i8>;
| ^^ label `'a` already in scope
warning: 1 warning emitted
warning: lifetime name `'b` shadows a label name that is already in scope
--> $DIR/loops-reject-lifetime-shadowing-label.rs:28:55
|
LL | 'b: {
| -- first declared here
LL | let b = Box::new(|x: &()| ()) as Box<dyn for <'b> Fn(&'b ())>;
| ^^ label `'b` already in scope
warning: 2 warnings emitted

View File

@ -0,0 +1,16 @@
// check-pass
//
// Ensures that we properly lint
// a removed 'expression' resulting from a macro
// in trailing expression position
macro_rules! expand_it {
() => {
#[cfg(FALSE)] 25; //~ WARN trailing semicolon in macro
//~| WARN this was previously
}
}
fn main() {
expand_it!()
}

View File

@ -0,0 +1,18 @@
warning: trailing semicolon in macro used in expression position
--> $DIR/lint-trailing-macro-call.rs:9:25
|
LL | #[cfg(FALSE)] 25;
| ^
...
LL | expand_it!()
| ------------ in this macro invocation
|
= note: `#[warn(semicolon_in_expressions_from_macros)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #79813 <https://github.com/rust-lang/rust/issues/79813>
= note: macro invocations at the end of a block are treated as expressions
= note: to ignore the value produced by the macro, add a semicolon after the invocation of `expand_it`
= note: this warning originates in the macro `expand_it` (in Nightly builds, run with -Z macro-backtrace for more info)
warning: 1 warning emitted

View File

@ -16,7 +16,10 @@ error[E0026]: struct `S` does not have a field named `0x1`
--> $DIR/numeric-fields.rs:7:17
|
LL | S{0: a, 0x1: b, ..} => {}
| ^^^ struct `S` does not have this field
| ^^^
| |
| struct `S` does not have this field
| help: `S` has a field named `1`
error: aborting due to 2 previous errors

View File

@ -0,0 +1,33 @@
// build-fail
// Test that the simd_shuffle intrinsic produces ok-ish error
// messages when misused.
#![feature(repr_simd, platform_intrinsics)]
#[repr(simd)]
#[derive(Copy, Clone)]
pub struct Simd<T, const N: usize>([T; N]);
extern "platform-intrinsic" {
fn simd_shuffle<T, I, U>(a: T, b: T, i: I) -> U;
}
fn main() {
const I: [u32; 2] = [0; 2];
const I2: [f32; 2] = [0.; 2];
let v = Simd::<u32, 4>([0; 4]);
unsafe {
let _: Simd<u32, 2> = simd_shuffle(v, v, I);
let _: Simd<u32, 4> = simd_shuffle(v, v, I);
//~^ ERROR invalid monomorphization of `simd_shuffle` intrinsic
let _: Simd<f32, 2> = simd_shuffle(v, v, I);
//~^ ERROR invalid monomorphization of `simd_shuffle` intrinsic
let _: Simd<u32, 2> = simd_shuffle(v, v, I2);
//~^ ERROR invalid monomorphization of `simd_shuffle` intrinsic
}
}

View File

@ -0,0 +1,21 @@
error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected return type of length 2, found `Simd<u32, 4_usize>` with length 4
--> $DIR/simd-intrinsic-generic-shuffle.rs:24:31
|
LL | let _: Simd<u32, 4> = simd_shuffle(v, v, I);
| ^^^^^^^^^^^^^^^^^^^^^
error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: expected return element type `u32` (element of input `Simd<u32, 4_usize>`), found `Simd<f32, 2_usize>` with element type `f32`
--> $DIR/simd-intrinsic-generic-shuffle.rs:27:31
|
LL | let _: Simd<f32, 2> = simd_shuffle(v, v, I);
| ^^^^^^^^^^^^^^^^^^^^^
error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: simd_shuffle index must be an array of `u32`, got `[f32; 2]`
--> $DIR/simd-intrinsic-generic-shuffle.rs:30:31
|
LL | let _: Simd<u32, 2> = simd_shuffle(v, v, I2);
| ^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0511`.

View File

@ -0,0 +1,40 @@
//run-pass
#![feature(repr_simd, platform_intrinsics)]
extern "platform-intrinsic" {
fn simd_shuffle<T, I, U>(a: T, b: T, i: I) -> U;
}
#[derive(Copy, Clone)]
#[repr(simd)]
struct Simd<T, const N: usize>([T; N]);
trait Shuffle<const N: usize> {
const I: [u32; N];
unsafe fn shuffle<T, const M: usize>(&self, a: Simd<T, M>, b: Simd<T, M>) -> Simd<T, N> {
simd_shuffle(a, b, Self::I)
}
}
fn main() {
struct I1;
impl Shuffle<4> for I1 {
const I: [u32; 4] = [0, 2, 4, 6];
}
struct I2;
impl Shuffle<2> for I2 {
const I: [u32; 2] = [1, 5];
}
let a = Simd::<u8, 4>([0, 1, 2, 3]);
let b = Simd::<u8, 4>([4, 5, 6, 7]);
unsafe {
let x: Simd<u8, 4> = I1.shuffle(a, b);
assert_eq!(x.0, [0, 2, 4, 6]);
let y: Simd<u8, 2> = I2.shuffle(a, b);
assert_eq!(y.0, [1, 5]);
}
}

View File

@ -188,4 +188,14 @@ fn main() {
48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33,
32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17,
16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1));
extern "platform-intrinsic" {
fn simd_shuffle<T, I, U>(a: T, b: T, i: I) -> U;
}
let v = u8x2(0, 0);
const I: [u32; 2] = [4, 4];
unsafe {
let _: u8x2 = simd_shuffle(v, v, I);
//~^ ERROR invalid monomorphization of `simd_shuffle` intrinsic
}
}

View File

@ -71,6 +71,12 @@ LL | | 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1));
|
= note: this error originates in the macro `test_shuffle_lanes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 6 previous errors
error[E0511]: invalid monomorphization of `simd_shuffle` intrinsic: shuffle index #0 is out of bounds (limit 4)
--> $DIR/shuffle-not-out-of-bounds.rs:198:23
|
LL | let _: u8x2 = simd_shuffle(v, v, I);
| ^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 7 previous errors
For more information about this error, try `rustc --explain E0511`.

View File

@ -0,0 +1,24 @@
//run-pass
#![feature(repr_simd, platform_intrinsics)]
extern "platform-intrinsic" {
fn simd_shuffle<T, I, U>(a: T, b: T, i: I) -> U;
}
#[derive(Copy, Clone)]
#[repr(simd)]
struct Simd<T, const N: usize>([T; N]);
fn main() {
const I1: [u32; 4] = [0, 2, 4, 6];
const I2: [u32; 2] = [1, 5];
let a = Simd::<u8, 4>([0, 1, 2, 3]);
let b = Simd::<u8, 4>([4, 5, 6, 7]);
unsafe {
let x: Simd<u8, 4> = simd_shuffle(a, b, I1);
assert_eq!(x.0, [0, 2, 4, 6]);
let y: Simd<u8, 2> = simd_shuffle(a, b, I2);
assert_eq!(y.0, [1, 5]);
}
}

View File

@ -0,0 +1,9 @@
// run-rustfix
fn main() {
let a = Some(42);
println!(
"The value is {}.",
(a.unwrap()) //~ERROR [E0615]
);
}

View File

@ -0,0 +1,9 @@
// run-rustfix
fn main() {
let a = Some(42);
println!(
"The value is {}.",
(a.unwrap) //~ERROR [E0615]
);
}

View File

@ -0,0 +1,14 @@
error[E0615]: attempted to take value of method `unwrap` on type `Option<{integer}>`
--> $DIR/issue-89044-wrapped-expr-method.rs:7:12
|
LL | (a.unwrap)
| ^^^^^^ method, not a field
|
help: use parentheses to call the method
|
LL | (a.unwrap())
| ++
error: aborting due to previous error
For more information about this error, try `rustc --explain E0615`.