diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index 7c84530abbee2..c2260a4590975 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -986,16 +986,6 @@ impl<'a> MethodDef<'a> { f(cx, span, &substructure) } - fn get_ret_ty( - &self, - cx: &ExtCtxt<'_>, - trait_: &TraitDef<'_>, - generics: &Generics, - type_ident: Ident, - ) -> Box { - self.ret_ty.to_ty(cx, trait_.span, type_ident, generics) - } - fn is_static(&self) -> bool { !self.explicit_self } @@ -1068,10 +1058,14 @@ impl<'a> MethodDef<'a> { self_arg.into_iter().chain(nonself_args).collect() }; - let ret_type = self.get_ret_ty(cx, trait_, generics, type_ident); + let ret_type = if let Ty::Unit = &self.ret_ty { + ast::FnRetTy::Default(span) + } else { + ast::FnRetTy::Ty(self.ret_ty.to_ty(cx, span, type_ident, generics)) + }; let method_ident = Ident::new(self.name, span); - let fn_decl = cx.fn_decl(args, ast::FnRetTy::Ty(ret_type)); + let fn_decl = cx.fn_decl(args, ret_type); let body_block = body.into_block(cx, span); let trait_lo_sp = span.shrink_to_lo(); diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index 9379faf1156fc..ca4805a93e017 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -1397,12 +1397,12 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn call( &mut self, llty: &'ll Type, - fn_call_attrs: Option<&CodegenFnAttrs>, + caller_attrs: Option<&CodegenFnAttrs>, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, llfn: &'ll Value, args: &[&'ll Value], funclet: Option<&Funclet<'ll>>, - instance: Option>, + callee_instance: Option>, ) -> &'ll Value { debug!("call {:?} with args ({:?})", llfn, args); @@ -1414,10 +1414,10 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } // Emit CFI pointer type membership test - self.cfi_type_test(fn_call_attrs, fn_abi, instance, llfn); + self.cfi_type_test(caller_attrs, fn_abi, callee_instance, llfn); // Emit KCFI operand bundle - let kcfi_bundle = self.kcfi_operand_bundle(fn_call_attrs, fn_abi, instance, llfn); + let kcfi_bundle = self.kcfi_operand_bundle(caller_attrs, fn_abi, callee_instance, llfn); if let Some(kcfi_bundle) = kcfi_bundle.as_ref().map(|b| b.as_ref()) { bundles.push(kcfi_bundle); } @@ -1435,17 +1435,17 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { ) }; - if let Some(instance) = instance { + if let Some(callee_instance) = callee_instance { // Attributes on the function definition being called - let fn_defn_attrs = self.cx.tcx.codegen_fn_attrs(instance.def_id()); - if let Some(fn_call_attrs) = fn_call_attrs + let callee_attrs = self.cx.tcx.codegen_fn_attrs(callee_instance.def_id()); + if let Some(caller_attrs) = caller_attrs // If there is an inline attribute and a target feature that matches // we will add the attribute to the callsite otherwise we'll omit // this and not add the attribute to prevent soundness issues. - && let Some(inlining_rule) = attributes::inline_attr(&self.cx, self.cx.tcx, instance) + && let Some(inlining_rule) = attributes::inline_attr(&self.cx, self.cx.tcx, callee_instance) && self.cx.tcx.is_target_feature_call_safe( - &fn_defn_attrs.target_features, - &fn_call_attrs.target_features.iter().cloned().chain( + &callee_attrs.target_features, + &caller_attrs.target_features.iter().cloned().chain( self.cx.tcx.sess.target_features.iter().map(|feat| TargetFeature { name: *feat, kind: TargetFeatureKind::Implied, @@ -1470,14 +1470,15 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn tail_call( &mut self, llty: Self::Type, - fn_attrs: Option<&CodegenFnAttrs>, + caller_attrs: Option<&CodegenFnAttrs>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, llfn: Self::Value, args: &[Self::Value], funclet: Option<&Self::Funclet>, - instance: Option>, + callee_instance: Option>, ) { - let call = self.call(llty, fn_attrs, Some(fn_abi), llfn, args, funclet, instance); + let call = + self.call(llty, caller_attrs, Some(fn_abi), llfn, args, funclet, callee_instance); llvm::LLVMSetTailCallKind(call, llvm::TailCallKind::MustTail); match &fn_abi.ret.mode { diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index d22546dee5654..35de8b5e1486b 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -199,12 +199,12 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> { // do an invoke, otherwise do a call. let fn_ty = bx.fn_decl_backend_type(fn_abi); - let fn_attrs = if bx.tcx().def_kind(fx.instance.def_id()).has_codegen_attrs() { + let caller_attrs = if bx.tcx().def_kind(fx.instance.def_id()).has_codegen_attrs() { Some(bx.tcx().codegen_instance_attrs(fx.instance.def)) } else { None }; - let fn_attrs = fn_attrs.as_deref(); + let caller_attrs = caller_attrs.as_deref(); if !fn_abi.can_unwind { unwind = mir::UnwindAction::Unreachable; @@ -233,7 +233,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> { }; if kind == CallKind::Tail { - bx.tail_call(fn_ty, fn_attrs, fn_abi, fn_ptr, llargs, self.funclet(fx), instance); + bx.tail_call(fn_ty, caller_attrs, fn_abi, fn_ptr, llargs, self.funclet(fx), instance); return MergingSucc::False; } @@ -245,7 +245,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> { }; let invokeret = bx.invoke( fn_ty, - fn_attrs, + caller_attrs, Some(fn_abi), fn_ptr, llargs, @@ -268,8 +268,15 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> { } MergingSucc::False } else { - let llret = - bx.call(fn_ty, fn_attrs, Some(fn_abi), fn_ptr, llargs, self.funclet(fx), instance); + let llret = bx.call( + fn_ty, + caller_attrs, + Some(fn_abi), + fn_ptr, + llargs, + self.funclet(fx), + instance, + ); if fx.mir[self.bb].is_cleanup { bx.apply_attrs_to_cleanup_callsite(llret); } diff --git a/compiler/rustc_codegen_ssa/src/traits/builder.rs b/compiler/rustc_codegen_ssa/src/traits/builder.rs index ba36188f05d15..3486bd140eceb 100644 --- a/compiler/rustc_codegen_ssa/src/traits/builder.rs +++ b/compiler/rustc_codegen_ssa/src/traits/builder.rs @@ -600,10 +600,13 @@ pub trait BuilderMethods<'a, 'tcx>: /// /// ## Arguments /// - /// The `fn_attrs`, `fn_abi`, and `instance` arguments are Options because they are advisory. - /// They relate to optional codegen enhancements like LLVM CFI, and do not affect ABI per se. - /// Any ABI-related transformations should be handled by different, earlier stages of codegen. - /// For instance, in the caller of `BuilderMethods::call`. + /// `caller_attrs` are the attributes of the surrounding caller; they have nothing to do with + /// the callee. + /// + /// The `caller_attrs`, `fn_abi`, and `callee_instance` arguments are Options because they are + /// advisory. They relate to optional codegen enhancements like LLVM CFI, and do not affect ABI + /// per se. Any ABI-related transformations should be handled by different, earlier stages of + /// codegen. For instance, in the caller of `BuilderMethods::call`. /// /// This means that a codegen backend which disregards `fn_attrs`, `fn_abi`, and `instance` /// should still do correct codegen, and code should not be miscompiled if they are omitted. @@ -620,23 +623,23 @@ pub trait BuilderMethods<'a, 'tcx>: fn call( &mut self, llty: Self::Type, - fn_attrs: Option<&CodegenFnAttrs>, + caller_attrs: Option<&CodegenFnAttrs>, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, fn_val: Self::Value, args: &[Self::Value], funclet: Option<&Self::Funclet>, - instance: Option>, + callee_instance: Option>, ) -> Self::Value; fn tail_call( &mut self, llty: Self::Type, - fn_attrs: Option<&CodegenFnAttrs>, + caller_attrs: Option<&CodegenFnAttrs>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, llfn: Self::Value, args: &[Self::Value], funclet: Option<&Self::Funclet>, - instance: Option>, + callee_instance: Option>, ); fn zext(&mut self, val: Self::Value, dest_ty: Self::Type) -> Self::Value; diff --git a/compiler/rustc_const_eval/src/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/check_consts/qualifs.rs index 02615e3bbc18c..fe3891d0dd7e0 100644 --- a/compiler/rustc_const_eval/src/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/check_consts/qualifs.rs @@ -343,17 +343,18 @@ where // Check the qualifs of the value of `const` items. let uneval = match constant.const_ { - Const::Ty(_, ct) - if matches!( - ct.kind(), - ty::ConstKind::Param(_) | ty::ConstKind::Error(_) | ty::ConstKind::Value(_) - ) => - { - None - } - Const::Ty(_, c) => { - bug!("expected ConstKind::Param or ConstKind::Value here, found {:?}", c) - } + Const::Ty(_, ct) => match ct.kind() { + ty::ConstKind::Param(_) | ty::ConstKind::Error(_) => None, + // Unevaluated consts in MIR bodies don't have associated MIR (e.g. `#[type_const]`). + ty::ConstKind::Unevaluated(_) => None, + // FIXME(mgca): Investigate whether using `None` for `ConstKind::Value` is overly + // strict, and if instead we should be doing some kind of value-based analysis. + ty::ConstKind::Value(_) => None, + _ => bug!( + "expected ConstKind::Param, ConstKind::Value, ConstKind::Unevaluated, or ConstKind::Error here, found {:?}", + ct + ), + }, Const::Unevaluated(uv, _) => Some(uv), Const::Val(..) => None, }; @@ -364,10 +365,8 @@ where // check performed after the promotion. Verify that with an assertion. assert!(promoted.is_none() || Q::ALLOW_PROMOTED); - // Don't peak inside trait associated constants, also `#[type_const] const` items - // don't have bodies so there's nothing to look at - if promoted.is_none() && cx.tcx.trait_of_assoc(def).is_none() && !cx.tcx.is_type_const(def) - { + // Don't peak inside trait associated constants. + if promoted.is_none() && cx.tcx.trait_of_assoc(def).is_none() { let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def); if !Q::in_qualifs(&qualifs) { diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index e07c1cc7dbd81..85877d73519a5 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -41,8 +41,11 @@ // have to worry about it being moved to a different module in std during stabilization. // FIXME(#151359): Remove this when `feature(assert_matches)` is stable in stage0. // (This doesn't necessarily need to be fixed during the beta bump itself.) +#[cfg(bootstrap)] pub use std::assert_matches::{assert_matches, debug_assert_matches}; use std::fmt; +#[cfg(not(bootstrap))] +pub use std::{assert_matches, debug_assert_matches}; pub use atomic_ref::AtomicRef; pub use ena::{snapshot_vec, undo_log, unify}; diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp index 599f79d011989..f68f4e71520b3 100644 --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp @@ -527,6 +527,12 @@ LLVMRustCreateAttrNoValue(LLVMContextRef C, LLVMRustAttributeKind RustAttr) { *unwrap(C), CaptureInfo(CaptureComponents::Address | CaptureComponents::ReadProvenance))); } +#endif +#if LLVM_VERSION_GE(23, 0) + if (RustAttr == LLVMRustAttributeKind::DeadOnReturn) { + return wrap(Attribute::getWithDeadOnReturnInfo(*unwrap(C), + llvm::DeadOnReturnInfo())); + } #endif return wrap(Attribute::get(*unwrap(C), fromRust(RustAttr))); } diff --git a/compiler/rustc_middle/src/ty/consts/valtree.rs b/compiler/rustc_middle/src/ty/consts/valtree.rs index 5a5bf7d38ea46..e3fc9bfee49c4 100644 --- a/compiler/rustc_middle/src/ty/consts/valtree.rs +++ b/compiler/rustc_middle/src/ty/consts/valtree.rs @@ -147,7 +147,12 @@ impl<'tcx> Value<'tcx> { _ => return None, } - Some(tcx.arena.alloc_from_iter(self.to_branch().into_iter().map(|ct| ct.to_leaf().to_u8()))) + // We create an iterator that yields `Option` + let iterator = self.to_branch().into_iter().map(|ct| Some(ct.try_to_leaf()?.to_u8())); + // If there is `None` in the iterator, then the array is not a valid array of u8s and we return `None` + let bytes: Vec = iterator.collect::>>()?; + + Some(tcx.arena.alloc_from_iter(bytes)) } /// Converts to a `ValTreeKind::Leaf` value, `panic`'ing diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index fd0a5ca309a4c..de13c4f836a5f 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1911,14 +1911,16 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { return Ok(()); } }, - (ty::ValTreeKind::Branch(_), ty::Array(t, _)) if t == u8_type => { - let bytes = cv.try_to_raw_bytes(self.tcx()).unwrap_or_else(|| { - bug!("expected to convert valtree to raw bytes for type {:?}", t) - }); + // If it is a branch with an array, and this array can be printed as raw bytes, then dump its bytes + (ty::ValTreeKind::Branch(_), ty::Array(t, _)) + if t == u8_type + && let Some(bytes) = cv.try_to_raw_bytes(self.tcx()) => + { write!(self, "*")?; self.pretty_print_byte_str(bytes)?; return Ok(()); } + // Otherwise, print the array separated by commas (or if it's a tuple) (ty::ValTreeKind::Branch(fields), ty::Array(..) | ty::Tuple(..)) => { let fields_iter = fields.iter().copied(); diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index ce17046969184..81d46e3b5b0d4 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -1563,11 +1563,22 @@ impl<'v> RootCollector<'_, 'v> { // If we're collecting items eagerly, then recurse into all constants. // Otherwise the value is only collected when explicitly mentioned in other items. if self.strategy == MonoItemCollectionStrategy::Eager { - if !self.tcx.generics_of(id.owner_id).own_requires_monomorphization() - && let Ok(val) = self.tcx.const_eval_poly(id.owner_id.to_def_id()) - { - collect_const_value(self.tcx, val, self.output); + let def_id = id.owner_id.to_def_id(); + // Type Consts don't have bodies to evaluate + // nor do they make sense as a static. + if self.tcx.is_type_const(def_id) { + // FIXME(mgca): Is this actually what we want? We may want to + // normalize to a ValTree then convert to a const allocation and + // collect that? + return; + } + if self.tcx.generics_of(id.owner_id).own_requires_monomorphization() { + return; } + let Ok(val) = self.tcx.const_eval_poly(def_id) else { + return; + }; + collect_const_value(self.tcx, val, self.output); } } DefKind::Impl { of_trait: true } => { diff --git a/library/alloc/src/collections/btree/map/tests.rs b/library/alloc/src/collections/btree/map/tests.rs index a61a2da172d1e..938e867b85812 100644 --- a/library/alloc/src/collections/btree/map/tests.rs +++ b/library/alloc/src/collections/btree/map/tests.rs @@ -1,4 +1,4 @@ -use core::assert_matches::assert_matches; +use core::assert_matches; use std::iter; use std::ops::Bound::{Excluded, Included, Unbounded}; use std::panic::{AssertUnwindSafe, catch_unwind}; diff --git a/library/alloctests/tests/c_str2.rs b/library/alloctests/tests/c_str2.rs index fe7686bd1c592..8ecab03b5ceb3 100644 --- a/library/alloctests/tests/c_str2.rs +++ b/library/alloctests/tests/c_str2.rs @@ -1,7 +1,7 @@ use alloc::ffi::CString; use alloc::rc::Rc; use alloc::sync::Arc; -use core::assert_matches::assert_matches; +use core::assert_matches; use core::ffi::{CStr, FromBytesUntilNulError, c_char}; #[allow(deprecated)] use core::hash::SipHasher13 as DefaultHasher; diff --git a/library/alloctests/tests/str.rs b/library/alloctests/tests/str.rs index fbb3b01fd67f9..fcc4aaaa1dcd1 100644 --- a/library/alloctests/tests/str.rs +++ b/library/alloctests/tests/str.rs @@ -1,6 +1,6 @@ #![allow(invalid_from_utf8)] -use std::assert_matches::assert_matches; +use std::assert_matches; use std::borrow::Cow; use std::cmp::Ordering::{Equal, Greater, Less}; use std::str::{from_utf8, from_utf8_unchecked}; diff --git a/library/alloctests/tests/string.rs b/library/alloctests/tests/string.rs index 71557f284f475..08eb1855a4824 100644 --- a/library/alloctests/tests/string.rs +++ b/library/alloctests/tests/string.rs @@ -1,10 +1,9 @@ -use std::assert_matches::assert_matches; use std::borrow::Cow; use std::cell::Cell; use std::collections::TryReserveErrorKind::*; use std::ops::Bound::*; use std::ops::{Bound, RangeBounds}; -use std::{panic, str}; +use std::{assert_matches, panic, str}; pub trait IntoCow<'a, B: ?Sized> where diff --git a/library/alloctests/tests/vec.rs b/library/alloctests/tests/vec.rs index c8f9504ae14e8..5ab305f7a5048 100644 --- a/library/alloctests/tests/vec.rs +++ b/library/alloctests/tests/vec.rs @@ -3,12 +3,10 @@ use core::num::NonZero; use core::ptr::NonNull; use core::{assert_eq, assert_ne}; use std::alloc::System; -use std::assert_matches::assert_matches; use std::borrow::Cow; use std::cell::Cell; use std::collections::TryReserveErrorKind::*; use std::fmt::Debug; -use std::hint; use std::iter::InPlaceIterable; use std::mem::swap; use std::ops::Bound::*; @@ -16,6 +14,7 @@ use std::panic::{AssertUnwindSafe, catch_unwind}; use std::rc::Rc; use std::sync::atomic::{AtomicU32, Ordering}; use std::vec::{Drain, IntoIter, PeekMut}; +use std::{assert_matches, hint}; use crate::testing::macros::struct_with_counted_drop; diff --git a/library/alloctests/tests/vec_deque.rs b/library/alloctests/tests/vec_deque.rs index e9f860f8df9bd..e06d18250a51a 100644 --- a/library/alloctests/tests/vec_deque.rs +++ b/library/alloctests/tests/vec_deque.rs @@ -1,6 +1,6 @@ use core::cell::Cell; use core::num::NonZero; -use std::assert_matches::assert_matches; +use std::assert_matches; use std::collections::TryReserveErrorKind::*; use std::collections::VecDeque; use std::collections::vec_deque::Drain; diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index 64bdb8e85e03d..051dda731881f 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -54,7 +54,7 @@ )] use crate::ffi::va_list::{VaArgSafe, VaList}; -use crate::marker::{ConstParamTy, Destruct, DiscriminantKind, PointeeSized, Tuple}; +use crate::marker::{ConstParamTy, DiscriminantKind, PointeeSized, Tuple}; use crate::{mem, ptr}; mod bounds; @@ -483,11 +483,14 @@ pub const fn unlikely(b: bool) -> bool { #[rustc_nounwind] #[miri::intrinsic_fallback_is_spec] #[inline] -pub const fn select_unpredictable(b: bool, true_val: T, false_val: T) -> T -where - T: [const] Destruct, -{ - if b { true_val } else { false_val } +pub const fn select_unpredictable(b: bool, true_val: T, false_val: T) -> T { + if b { + forget(false_val); + true_val + } else { + forget(true_val); + false_val + } } /// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited: diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index dfc9a7b5dbc32..c4d16ba633b81 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -223,11 +223,7 @@ use prelude::rust_2024::*; mod macros; #[unstable(feature = "assert_matches", issue = "82775")] -/// Unstable module containing the unstable `assert_matches` macro. -pub mod assert_matches { - #[unstable(feature = "assert_matches", issue = "82775")] - pub use crate::macros::{assert_matches, debug_assert_matches}; -} +pub use crate::macros::{assert_matches, debug_assert_matches}; #[unstable(feature = "derive_from", issue = "144889")] /// Unstable module containing the unstable `From` derive macro. diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index a437a4795481c..3176f3c067092 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -124,6 +124,8 @@ macro_rules! assert_ne { }; } +// FIXME add back debug_assert_matches doc link after bootstrap. + /// Asserts that an expression matches the provided pattern. /// /// This macro is generally preferable to `assert!(matches!(value, pattern))`, because it can print @@ -135,11 +137,9 @@ macro_rules! assert_ne { /// otherwise this macro will panic. /// /// Assertions are always checked in both debug and release builds, and cannot -/// be disabled. See [`debug_assert_matches!`] for assertions that are disabled in +/// be disabled. See `debug_assert_matches!` for assertions that are disabled in /// release builds by default. /// -/// [`debug_assert_matches!`]: crate::assert_matches::debug_assert_matches -/// /// On panic, this macro will print the value of the expression with its debug representation. /// /// Like [`assert!`], this macro has a second form, where a custom panic message can be provided. @@ -149,7 +149,7 @@ macro_rules! assert_ne { /// ``` /// #![feature(assert_matches)] /// -/// use std::assert_matches::assert_matches; +/// use std::assert_matches; /// /// let a = Some(345); /// let b = Some(56); @@ -382,7 +382,7 @@ macro_rules! debug_assert_ne { /// ``` /// #![feature(assert_matches)] /// -/// use std::assert_matches::debug_assert_matches; +/// use std::debug_assert_matches; /// /// let a = Some(345); /// let b = Some(56); @@ -404,7 +404,7 @@ macro_rules! debug_assert_ne { #[rustc_macro_transparency = "semiopaque"] pub macro debug_assert_matches($($arg:tt)*) { if $crate::cfg!(debug_assertions) { - $crate::assert_matches::assert_matches!($($arg)*); + $crate::assert_matches!($($arg)*); } } diff --git a/library/core/src/num/f16.rs b/library/core/src/num/f16.rs index bcf0f3fc45c29..344f58da277b8 100644 --- a/library/core/src/num/f16.rs +++ b/library/core/src/num/f16.rs @@ -132,6 +132,7 @@ pub mod consts { pub const LN_10: f16 = 2.30258509299404568401799145468436421_f16; } +#[doc(test(attr(feature(cfg_target_has_reliable_f16_f128), allow(internal_features))))] impl f16 { // FIXME(f16_f128): almost all methods in this `impl` are missing examples and a const // implementation. Add these once we can run code on all platforms and have f16/f128 in CTFE. @@ -272,7 +273,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let nan = f16::NAN; /// let f = 7.0_f16; @@ -294,7 +295,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let f = 7.0f16; /// let inf = f16::INFINITY; @@ -319,7 +320,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let f = 7.0f16; /// let inf: f16 = f16::INFINITY; @@ -347,7 +348,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let min = f16::MIN_POSITIVE; // 6.1035e-5 /// let max = f16::MAX; @@ -376,7 +377,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let min = f16::MIN_POSITIVE; // 6.1035e-5 /// let max = f16::MAX; @@ -407,7 +408,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// use std::num::FpCategory; /// @@ -443,8 +444,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # // FIXME(f16_f128): LLVM crashes on s390x, llvm/llvm-project#50374 - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let f = 7.0_f16; /// let g = -7.0_f16; @@ -472,8 +472,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # // FIXME(f16_f128): LLVM crashes on s390x, llvm/llvm-project#50374 - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let f = 7.0_f16; /// let g = -7.0_f16; @@ -507,8 +506,7 @@ impl f16 { /// /// ```rust /// #![feature(f16)] - /// # // FIXME(f16_f128): ABI issues on MSVC - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// // f16::EPSILON is the difference between 1.0 and the next number up. /// assert_eq!(1.0f16.next_up(), 1.0 + f16::EPSILON); @@ -562,8 +560,7 @@ impl f16 { /// /// ```rust /// #![feature(f16)] - /// # // FIXME(f16_f128): ABI issues on MSVC - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let x = 1.0f16; /// // Clamp value into range [0, 1). @@ -606,8 +603,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # // FIXME(f16_f128): extendhfsf2, truncsfhf2, __gnu_h2f_ieee, __gnu_f2h_ieee missing for many platforms - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let x = 2.0_f16; /// let abs_difference = (x.recip() - (1.0 / x)).abs(); @@ -633,8 +629,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # // FIXME(f16_f128): extendhfsf2, truncsfhf2, __gnu_h2f_ieee, __gnu_f2h_ieee missing for many platforms - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let angle = std::f16::consts::PI; /// @@ -663,8 +658,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # // FIXME(f16_f128): extendhfsf2, truncsfhf2, __gnu_h2f_ieee, __gnu_f2h_ieee missing for many platforms - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let angle = 180.0f16; /// @@ -697,7 +691,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(target_arch = "aarch64")] { // FIXME(f16_F128): rust-lang/rust#123885 + /// # #[cfg(target_has_reliable_f16)] { /// /// let x = 1.0f16; /// let y = 2.0f16; @@ -728,7 +722,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(target_arch = "aarch64")] { // FIXME(f16_F128): rust-lang/rust#123885 + /// # #[cfg(target_has_reliable_f16)] { /// /// let x = 1.0f16; /// let y = 2.0f16; @@ -760,7 +754,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// #![feature(float_minimum_maximum)] - /// # #[cfg(target_arch = "aarch64")] { // FIXME(f16_F128): rust-lang/rust#123885 + /// # #[cfg(target_has_reliable_f16)] { /// /// let x = 1.0f16; /// let y = 2.0f16; @@ -792,7 +786,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// #![feature(float_minimum_maximum)] - /// # #[cfg(target_arch = "aarch64")] { // FIXME(f16_F128): rust-lang/rust#123885 + /// # #[cfg(target_has_reliable_f16)] { /// /// let x = 1.0f16; /// let y = 2.0f16; @@ -818,7 +812,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(target_arch = "aarch64")] { // FIXME(f16_F128): rust-lang/rust#123885 + /// # #[cfg(target_has_reliable_f16)] { /// /// assert_eq!(1f16.midpoint(4.0), 2.5); /// assert_eq!((-5.5f16).midpoint(8.0), 1.25); @@ -848,7 +842,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let value = 4.6_f16; /// let rounded = unsafe { value.to_int_unchecked::() }; @@ -891,7 +885,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// # // FIXME(f16_f128): enable this once const casting works /// # // assert_ne!((1f16).to_bits(), 1f16 as u128); // to_bits() is not casting! @@ -939,7 +933,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let v = f16::from_bits(0x4a40); /// assert_eq!(v, 12.5); @@ -965,8 +959,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # // FIXME(f16_f128): LLVM crashes on s390x, llvm/llvm-project#50374 - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let bytes = 12.5f16.to_be_bytes(); /// assert_eq!(bytes, [0x4a, 0x40]); @@ -989,8 +982,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # // FIXME(f16_f128): LLVM crashes on s390x, llvm/llvm-project#50374 - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let bytes = 12.5f16.to_le_bytes(); /// assert_eq!(bytes, [0x40, 0x4a]); @@ -1019,8 +1011,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # // FIXME(f16_f128): LLVM crashes on s390x, llvm/llvm-project#50374 - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let bytes = 12.5f16.to_ne_bytes(); /// assert_eq!( @@ -1049,7 +1040,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let value = f16::from_be_bytes([0x4a, 0x40]); /// assert_eq!(value, 12.5); @@ -1071,7 +1062,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let value = f16::from_le_bytes([0x40, 0x4a]); /// assert_eq!(value, 12.5); @@ -1100,7 +1091,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let value = f16::from_ne_bytes(if cfg!(target_endian = "big") { /// [0x4a, 0x40] @@ -1150,8 +1141,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # // FIXME(f16_f128): extendhfsf2, truncsfhf2, __gnu_h2f_ieee, __gnu_f2h_ieee missing for many platforms - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// struct GoodBoy { /// name: &'static str, @@ -1234,7 +1224,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// assert!((-3.0f16).clamp(-2.0, 1.0) == -2.0); /// assert!((0.0f16).clamp(-2.0, 1.0) == 0.0); @@ -1285,7 +1275,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// #![feature(clamp_magnitude)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// assert_eq!(5.0f16.clamp_magnitude(3.0), 3.0); /// assert_eq!((-5.0f16).clamp_magnitude(3.0), -3.0); /// assert_eq!(2.0f16.clamp_magnitude(3.0), 2.0); @@ -1309,7 +1299,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16_math)] { /// /// let x = 3.5_f16; /// let y = -3.5_f16; @@ -1325,8 +1315,7 @@ impl f16 { #[rustc_const_unstable(feature = "f16", issue = "116909")] #[must_use = "method returns a new number and does not mutate the original value"] pub const fn abs(self) -> Self { - // FIXME(f16_f128): replace with `intrinsics::fabsf16` when available - Self::from_bits(self.to_bits() & !(1 << 15)) + intrinsics::fabsf16(self) } /// Returns a number that represents the sign of `self`. @@ -1339,7 +1328,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let f = 3.5_f16; /// @@ -1375,7 +1364,7 @@ impl f16 { /// /// ``` /// #![feature(f16)] - /// # #[cfg(all(target_arch = "x86_64", target_os = "linux"))] { + /// # #[cfg(target_has_reliable_f16_math)] { /// /// let f = 3.5_f16; /// @@ -1465,7 +1454,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let f = 3.7_f16; /// let g = 3.0_f16; @@ -1494,7 +1483,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let f = 3.01_f16; /// let g = 4.0_f16; @@ -1523,7 +1512,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let f = 3.3_f16; /// let g = -3.3_f16; @@ -1557,7 +1546,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let f = 3.3_f16; /// let g = -3.3_f16; @@ -1589,7 +1578,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let f = 3.7_f16; /// let g = 3.0_f16; @@ -1619,7 +1608,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let x = 3.6_f16; /// let y = -3.6_f16; @@ -1658,7 +1647,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let m = 10.0_f16; /// let x = 4.0_f16; @@ -1703,7 +1692,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let a: f16 = 7.0; /// let b = 4.0; @@ -1747,7 +1736,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let a: f16 = 7.0; /// let b = 4.0; @@ -1790,7 +1779,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let x = 2.0_f16; /// let abs_difference = (x.powi(2) - (x * x)).abs(); @@ -1823,7 +1812,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let positive = 4.0_f16; /// let negative = -4.0_f16; @@ -1858,7 +1847,7 @@ impl f16 { /// ``` /// #![feature(f16)] /// # #[cfg(not(miri))] - /// # #[cfg(target_has_reliable_f16_math)] { + /// # #[cfg(target_has_reliable_f16)] { /// /// let x = 8.0f16; /// diff --git a/library/core/src/option.rs b/library/core/src/option.rs index ed31d4efaa754..eb4f978b7c19d 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -2103,10 +2103,7 @@ impl Option<&T> { where T: Clone, { - match self { - Some(t) => Some(t.clone()), - None => None, - } + self.map(T::clone) } } @@ -2154,10 +2151,7 @@ impl Option<&mut T> { where T: Clone, { - match self { - Some(t) => Some(t.clone()), - None => None, - } + self.as_deref().map(T::clone) } } diff --git a/library/std/src/collections/hash/map/tests.rs b/library/std/src/collections/hash/map/tests.rs index cc1a9900bec97..fd7d81b2855f3 100644 --- a/library/std/src/collections/hash/map/tests.rs +++ b/library/std/src/collections/hash/map/tests.rs @@ -3,7 +3,7 @@ use realstd::collections::TryReserveErrorKind::*; use super::Entry::{Occupied, Vacant}; use super::HashMap; -use crate::assert_matches::assert_matches; +use crate::assert_matches; use crate::cell::RefCell; use crate::hash::{BuildHasher, BuildHasherDefault, DefaultHasher, RandomState}; use crate::test_helpers::test_rng; diff --git a/library/std/src/fs/tests.rs b/library/std/src/fs/tests.rs index 6a86705f2fadb..6d0b261dcadcf 100644 --- a/library/std/src/fs/tests.rs +++ b/library/std/src/fs/tests.rs @@ -2,7 +2,6 @@ use rand::RngCore; #[cfg(not(miri))] use super::Dir; -use crate::assert_matches::assert_matches; use crate::fs::{self, File, FileTimes, OpenOptions, TryLockError}; #[cfg(not(miri))] use crate::io; @@ -21,7 +20,7 @@ use crate::path::Path; use crate::sync::Arc; use crate::test_helpers::{TempDir, tmpdir}; use crate::time::{Duration, Instant, SystemTime}; -use crate::{env, str, thread}; +use crate::{assert_matches, env, str, thread}; macro_rules! check { ($e:expr) => { diff --git a/library/std/src/io/error/tests.rs b/library/std/src/io/error/tests.rs index eef44c6ac3b6a..a8eef06381dae 100644 --- a/library/std/src/io/error/tests.rs +++ b/library/std/src/io/error/tests.rs @@ -1,7 +1,6 @@ use super::{Custom, Error, ErrorData, ErrorKind, Repr, SimpleMessage, const_error}; -use crate::assert_matches::assert_matches; use crate::sys::io::{decode_error_kind, error_string}; -use crate::{error, fmt}; +use crate::{assert_matches, error, fmt}; #[test] fn test_size() { diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 03451214ccb5c..44db1bf22bc83 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -711,9 +711,9 @@ pub use core::todo; // Re-export built-in macros defined through core. #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] pub use core::{ - assert, assert_matches, cfg, column, compile_error, concat, const_format_args, env, file, - format_args, format_args_nl, include, include_bytes, include_str, line, log_syntax, - module_path, option_env, stringify, trace_macros, + assert, cfg, column, compile_error, concat, const_format_args, env, file, format_args, + format_args_nl, include, include_bytes, include_str, line, log_syntax, module_path, option_env, + stringify, trace_macros, }; // Re-export macros defined in core. #[stable(feature = "rust1", since = "1.0.0")] @@ -722,6 +722,8 @@ pub use core::{ assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, r#try, unimplemented, unreachable, write, writeln, }; +#[unstable(feature = "assert_matches", issue = "82775")] +pub use core::{assert_matches, debug_assert_matches}; // Re-export unstable derive macro defined through core. #[unstable(feature = "derive_from", issue = "144889")] diff --git a/library/std/src/sys/pal/unix/linux/pidfd/tests.rs b/library/std/src/sys/pal/unix/linux/pidfd/tests.rs index 0330f28e647d3..4cc2368c25a22 100644 --- a/library/std/src/sys/pal/unix/linux/pidfd/tests.rs +++ b/library/std/src/sys/pal/unix/linux/pidfd/tests.rs @@ -1,5 +1,5 @@ use super::PidFd as InternalPidFd; -use crate::assert_matches::assert_matches; +use crate::assert_matches; use crate::os::fd::AsRawFd; use crate::os::linux::process::{ChildExt, CommandExt as _}; use crate::os::unix::process::{CommandExt as _, ExitStatusExt}; diff --git a/library/std/src/sys/process/unix/unix.rs b/library/std/src/sys/process/unix/unix.rs index 460d5ec0f0747..62d6e0581e6c8 100644 --- a/library/std/src/sys/process/unix/unix.rs +++ b/library/std/src/sys/process/unix/unix.rs @@ -524,7 +524,7 @@ impl Command { return Ok(None); } } - core::assert_matches::debug_assert_matches!(support, SPAWN | NO); + core::debug_assert_matches!(support, SPAWN | NO); } } _ => { diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 0f75a332ad6bc..9dc4b1ec4e9a2 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -1,4 +1,7 @@ -use std::assert_matches::debug_assert_matches; +#[cfg(bootstrap)] +pub use std::assert_matches::debug_assert_matches; +#[cfg(not(bootstrap))] +pub use std::debug_assert_matches; use std::fmt::{self, Display, Write as _}; use std::sync::LazyLock as Lazy; use std::{ascii, mem}; diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index eee13ff2b0dc0..f38a21bd1ff36 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -1390,10 +1390,6 @@ impl clean::FnDecl { pub(crate) fn visibility_print_with_space(item: &clean::Item, cx: &Context<'_>) -> impl Display { fmt::from_fn(move |f| { - if item.is_doc_hidden() { - f.write_str("#[doc(hidden)] ")?; - } - let Some(vis) = item.visibility(cx.tcx()) else { return Ok(()); }; diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 0637f1cb6c82a..86e8167dc3cda 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1075,6 +1075,7 @@ fn assoc_type( cx: &Context<'_>, ) -> impl fmt::Display { fmt::from_fn(move |w| { + render_attributes_in_code(w, it, &" ".repeat(indent), cx)?; write!( w, "{indent}{vis}type {name}{generics}", @@ -2931,6 +2932,21 @@ fn render_attributes_in_code( prefix: &str, cx: &Context<'_>, ) -> fmt::Result { + render_attributes_in_code_with_options(w, item, prefix, cx, true, "") +} + +pub(super) fn render_attributes_in_code_with_options( + w: &mut impl fmt::Write, + item: &clean::Item, + prefix: &str, + cx: &Context<'_>, + render_doc_hidden: bool, + open_tag: &str, +) -> fmt::Result { + w.write_str(open_tag)?; + if render_doc_hidden && item.is_doc_hidden() { + render_code_attribute(prefix, "#[doc(hidden)]", w)?; + } for attr in &item.attrs.other_attrs { let hir::Attribute::Parsed(kind) = attr else { continue }; let attr = match kind { diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 55e36c462f967..5363755a0da7a 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -344,15 +344,38 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i } for (_, myitem) in ¬_stripped_items[&type_] { + let visibility_and_hidden = |item: &clean::Item| match item.visibility(tcx) { + Some(ty::Visibility::Restricted(_)) => { + if item.is_doc_hidden() { + // Don't separate with a space when there are two of them + " ðŸ”’👻 " + } else { + " ðŸ”’ " + } + } + _ if item.is_doc_hidden() => " ðŸ‘» ", + _ => "", + }; + match myitem.kind { clean::ExternCrateItem { ref src } => { use crate::html::format::print_anchor; + let visibility_and_hidden = visibility_and_hidden(myitem); + // Module listings use the hidden marker, so skip doc(hidden) here. + super::render_attributes_in_code_with_options( + w, + myitem, + "", + cx, + false, + "
", + )?; match *src { Some(src) => { write!( w, - "
{}extern crate {} as {};", + "{}extern crate {} as {};", visibility_print_with_space(myitem, cx), print_anchor(myitem.item_id.expect_def_id(), src, cx), EscapeBodyTextWithWbr(myitem.name.unwrap().as_str()) @@ -361,7 +384,7 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i None => { write!( w, - "
{}extern crate {};", + "{}extern crate {};", visibility_print_with_space(myitem, cx), print_anchor( myitem.item_id.expect_def_id(), @@ -371,7 +394,7 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i )?; } } - write!(w, "
")? + write!(w, "{visibility_and_hidden}")? } clean::ImportItem(ref import) => { let (stab_tags, deprecation) = match import.source.did { @@ -386,6 +409,7 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i } None => (String::new(), item.is_deprecated(tcx)), }; + let visibility_and_hidden = visibility_and_hidden(myitem); let id = match import.kind { clean::ImportKind::Simple(s) => { format!(" id=\"{}\"", cx.derive_id(format!("reexport.{s}"))) @@ -397,13 +421,13 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i "", deprecation_attr = deprecation_class_attr(deprecation) )?; - render_attributes_in_code(w, myitem, "", cx)?; write!( w, - "{vis}{imp}{stab_tags}\ + "{vis}{imp}{visibility_and_hidden}{stab_tags}\ ", vis = visibility_print_with_space(myitem, cx), imp = print_import(import, cx), + visibility_and_hidden = visibility_and_hidden, )?; } _ => { @@ -421,20 +445,7 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i } _ => "", }; - let visibility_and_hidden = match myitem.visibility(tcx) { - Some(ty::Visibility::Restricted(_)) => { - if myitem.is_doc_hidden() { - // Don't separate with a space when there are two of them - " ðŸ”’👻 " - } else { - " ðŸ”’ " - } - } - _ if myitem.is_doc_hidden() => { - " ðŸ‘» " - } - _ => "", - }; + let visibility_and_hidden = visibility_and_hidden(myitem); let docs = MarkdownSummaryLine(&myitem.doc_value(), &myitem.links(cx)) .into_string(); @@ -1868,7 +1879,6 @@ fn item_variants( fn item_macro(cx: &Context<'_>, it: &clean::Item, t: &clean::Macro) -> impl fmt::Display { fmt::from_fn(|w| { wrap_item(w, |w| { - // FIXME: Also print `#[doc(hidden)]` for `macro_rules!` if it `is_doc_hidden`. render_attributes_in_code(w, it, "", cx)?; if !t.macro_rules { write!(w, "{}", visibility_print_with_space(it, cx))?; diff --git a/src/tools/clippy/clippy_utils/src/ty/mod.rs b/src/tools/clippy/clippy_utils/src/ty/mod.rs index c1be4acc70683..dc5f7dc01dbb9 100644 --- a/src/tools/clippy/clippy_utils/src/ty/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ty/mod.rs @@ -29,7 +29,10 @@ use rustc_span::{DUMMY_SP, Span, Symbol, sym}; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt; use rustc_trait_selection::traits::{Obligation, ObligationCause}; +#[cfg(bootstrap)] use std::assert_matches::debug_assert_matches; +#[cfg(not(bootstrap))] +use std::debug_assert_matches; use std::collections::hash_map::Entry; use std::{iter, mem}; diff --git a/src/tools/miri/tests/pass/intrinsics/select-unpredictable-drop.rs b/src/tools/miri/tests/pass/intrinsics/select-unpredictable-drop.rs new file mode 100644 index 0000000000000..ecf9f4b92058b --- /dev/null +++ b/src/tools/miri/tests/pass/intrinsics/select-unpredictable-drop.rs @@ -0,0 +1,19 @@ +//! Check that `select_unpredictable` properly forgets the value it does not select. +#![feature(core_intrinsics)] +use std::cell::Cell; +use std::intrinsics::select_unpredictable; + +fn main() { + let (true_val, false_val) = (Cell::new(false), Cell::new(false)); + _ = select_unpredictable(true, TraceDrop(&true_val), TraceDrop(&false_val)); + assert!(true_val.get()); + assert!(!false_val.get()); +} + +struct TraceDrop<'a>(&'a Cell); + +impl<'a> Drop for TraceDrop<'a> { + fn drop(&mut self) { + self.0.set(true); + } +} diff --git a/tests/codegen-llvm/addr-of-mutate.rs b/tests/codegen-llvm/addr-of-mutate.rs index d59d85af62a91..d1939391b25de 100644 --- a/tests/codegen-llvm/addr-of-mutate.rs +++ b/tests/codegen-llvm/addr-of-mutate.rs @@ -5,7 +5,7 @@ // Test for the absence of `readonly` on the argument when it is mutated via `&raw const`. // See . -// CHECK: i8 @foo(ptr{{( dead_on_return)?}} noalias noundef align 1{{( captures\(address\))?}} dereferenceable(128) %x) +// CHECK: i8 @foo(ptr{{( dead_on_return)?}} noalias noundef align 1{{( captures\(address\))?}}{{( dead_on_return)?}} dereferenceable(128) %x) #[no_mangle] pub fn foo(x: [u8; 128]) -> u8 { let ptr = core::ptr::addr_of!(x).cast_mut(); @@ -15,7 +15,7 @@ pub fn foo(x: [u8; 128]) -> u8 { x[0] } -// CHECK: i1 @second(ptr{{( dead_on_return)?}} noalias noundef align {{[0-9]+}}{{( captures\(address\))?}} dereferenceable({{[0-9]+}}) %a_ptr_and_b) +// CHECK: i1 @second(ptr{{( dead_on_return)?}} noalias noundef align {{[0-9]+}}{{( captures\(address\))?}}{{( dead_on_return)?}} dereferenceable({{[0-9]+}}) %a_ptr_and_b) #[no_mangle] pub unsafe fn second(a_ptr_and_b: (*mut (i32, bool), (i64, bool))) -> bool { let b_bool_ptr = core::ptr::addr_of!(a_ptr_and_b.1.1).cast_mut(); @@ -24,7 +24,7 @@ pub unsafe fn second(a_ptr_and_b: (*mut (i32, bool), (i64, bool))) -> bool { } // If going through a deref (and there are no other mutating accesses), then `readonly` is fine. -// CHECK: i1 @third(ptr{{( dead_on_return)?}} noalias noundef readonly align {{[0-9]+}}{{( captures\(none\))?}} dereferenceable({{[0-9]+}}) %a_ptr_and_b) +// CHECK: i1 @third(ptr{{( dead_on_return)?}} noalias noundef readonly align {{[0-9]+}}{{( captures\(none\))?}}{{( dead_on_return)?}} dereferenceable({{[0-9]+}}) %a_ptr_and_b) #[no_mangle] pub unsafe fn third(a_ptr_and_b: (*mut (i32, bool), (i64, bool))) -> bool { let b_bool_ptr = core::ptr::addr_of!((*a_ptr_and_b.0).1).cast_mut(); diff --git a/tests/codegen-llvm/function-arguments.rs b/tests/codegen-llvm/function-arguments.rs index 4d557470504e0..b5febca3b87b5 100644 --- a/tests/codegen-llvm/function-arguments.rs +++ b/tests/codegen-llvm/function-arguments.rs @@ -134,7 +134,7 @@ pub fn mutable_notunpin_borrow(_: &mut NotUnpin) {} #[no_mangle] pub fn notunpin_borrow(_: &NotUnpin) {} -// CHECK: @indirect_struct(ptr{{( dead_on_return)?}} noalias noundef readonly align 4{{( captures\(none\))?}} dereferenceable(32) %_1) +// CHECK: @indirect_struct(ptr{{( dead_on_return)?}} noalias noundef readonly align 4{{( captures\(none\))?}}{{( dead_on_return)?}} dereferenceable(32) %_1) #[no_mangle] pub fn indirect_struct(_: S) {} diff --git a/tests/codegen-llvm/loongarch-abi/loongarch64-lp64d-abi.rs b/tests/codegen-llvm/loongarch-abi/loongarch64-lp64d-abi.rs index 546007ab0f2cf..4c61224ac6d8f 100644 --- a/tests/codegen-llvm/loongarch-abi/loongarch64-lp64d-abi.rs +++ b/tests/codegen-llvm/loongarch-abi/loongarch64-lp64d-abi.rs @@ -256,7 +256,7 @@ pub struct IntDoubleInt { c: i32, } -// CHECK: define void @f_int_double_int_s_arg(ptr{{( dead_on_return)?}} noalias noundef align 8{{( captures\(address\))?}} dereferenceable(24) %a) +// CHECK: define void @f_int_double_int_s_arg(ptr{{( dead_on_return)?}} noalias noundef align 8{{( captures\(address\))?}}{{( dead_on_return)?}} dereferenceable(24) %a) #[no_mangle] pub extern "C" fn f_int_double_int_s_arg(a: IntDoubleInt) {} diff --git a/tests/rustdoc-html/display-hidden-items.rs b/tests/rustdoc-html/display-hidden-items.rs index 8b0854d1ade81..6b548e3945600 100644 --- a/tests/rustdoc-html/display-hidden-items.rs +++ b/tests/rustdoc-html/display-hidden-items.rs @@ -5,25 +5,32 @@ #![crate_name = "foo"] //@ has 'foo/index.html' -//@ has - '//dt/span[@title="Hidden item"]' '👻' -//@ has - '//*[@id="reexport.hidden_reexport"]/code' '#[doc(hidden)] pub use hidden::inside_hidden as hidden_reexport;' +//@ matches - '//dt[code]' 'pub extern crate .*hidden_core;.*👻' +//@ has - '//dt/code' 'pub extern crate core as hidden_core;' +#[doc(hidden)] +pub extern crate core as hidden_core; + +//@ has - '//*[@id="reexport.hidden_reexport"]/span[@title="Hidden item"]' '👻' +//@ has - '//*[@id="reexport.hidden_reexport"]/code' 'pub use hidden::inside_hidden as hidden_reexport;' #[doc(hidden)] pub use hidden::inside_hidden as hidden_reexport; //@ has - '//dt/a[@class="trait"]' 'TraitHidden' //@ has 'foo/trait.TraitHidden.html' -//@ has - '//code' '#[doc(hidden)] pub trait TraitHidden' +//@ has 'foo/trait.TraitHidden.html' '//*[@class="rust item-decl"]//*[@class="code-attribute"]' '#[doc(hidden)]' +//@ has 'foo/trait.TraitHidden.html' '//*[@class="rust item-decl"]/code' 'pub trait TraitHidden' #[doc(hidden)] pub trait TraitHidden {} //@ has 'foo/index.html' '//dt/a[@class="trait"]' 'Trait' pub trait Trait { //@ has 'foo/trait.Trait.html' - //@ has - '//*[@id="associatedconstant.BAR"]/*[@class="code-header"]' '#[doc(hidden)] const BAR: u32 = 0' + //@ has - '//*[@id="associatedconstant.BAR"]/*[@class="code-header"]/*[@class="code-attribute"]' '#[doc(hidden)]' #[doc(hidden)] const BAR: u32 = 0; + //@ has - '//*[@id="method.foo"]/*[@class="code-header"]/*[@class="code-attribute"]' '#[doc(hidden)]' //@ has - '//*[@id="method.foo"]/*[@class="code-header"]' 'fn foo()' #[doc(hidden)] fn foo() {} @@ -44,15 +51,16 @@ impl Struct { } impl Trait for Struct { - //@ has - '//*[@id="associatedconstant.BAR"]/*[@class="code-header"]' '#[doc(hidden)] const BAR: u32 = 0' - //@ has - '//*[@id="method.foo"]/*[@class="code-header"]' '#[doc(hidden)] fn foo()' + //@ has - '//*[@id="associatedconstant.BAR"]/*[@class="code-header"]/*[@class="code-attribute"]' '#[doc(hidden)]' + //@ has - '//*[@id="method.foo"]/*[@class="code-header"]/*[@class="code-attribute"]' '#[doc(hidden)]' } //@ has - '//*[@id="impl-TraitHidden-for-Struct"]/*[@class="code-header"]' 'impl TraitHidden for Struct' impl TraitHidden for Struct {} //@ has 'foo/index.html' '//dt/a[@class="enum"]' 'HiddenEnum' //@ has 'foo/enum.HiddenEnum.html' -//@ has - '//code' '#[doc(hidden)] pub enum HiddenEnum' +//@ has 'foo/enum.HiddenEnum.html' '//*[@class="rust item-decl"]//*[@class="code-attribute"]' '#[doc(hidden)]' +//@ has 'foo/enum.HiddenEnum.html' '//*[@class="rust item-decl"]/code' 'pub enum HiddenEnum' #[doc(hidden)] pub enum HiddenEnum { A, @@ -60,6 +68,7 @@ pub enum HiddenEnum { //@ has 'foo/index.html' '//dt/a[@class="enum"]' 'Enum' pub enum Enum { + //@ has 'foo/enum.Enum.html' '//*[@id="variant.A"]/*[@class="code-header"]/*[@class="code-attribute"]' '#[doc(hidden)]' //@ has 'foo/enum.Enum.html' '//*[@id="variant.A"]/*[@class="code-header"]' 'A' #[doc(hidden)] A, diff --git a/tests/ui-fulldeps/rustc_public/check_abi.rs b/tests/ui-fulldeps/rustc_public/check_abi.rs index b3519a2c60eda..256e267b7d303 100644 --- a/tests/ui-fulldeps/rustc_public/check_abi.rs +++ b/tests/ui-fulldeps/rustc_public/check_abi.rs @@ -25,7 +25,7 @@ use rustc_public::mir::mono::Instance; use rustc_public::target::MachineInfo; use rustc_public::ty::{AdtDef, RigidTy, Ty, TyKind}; use rustc_public::{CrateDef, CrateItem, CrateItems, ItemKind}; -use std::assert_matches::assert_matches; +use std::assert_matches; use std::collections::HashSet; use std::convert::TryFrom; use std::io::Write; diff --git a/tests/ui-fulldeps/rustc_public/check_allocation.rs b/tests/ui-fulldeps/rustc_public/check_allocation.rs index 3a0a2382be728..783f562d57908 100644 --- a/tests/ui-fulldeps/rustc_public/check_allocation.rs +++ b/tests/ui-fulldeps/rustc_public/check_allocation.rs @@ -20,7 +20,7 @@ extern crate rustc_interface; extern crate rustc_public; use std::ascii::Char; -use std::assert_matches::assert_matches; +use std::assert_matches; use std::cmp::{max, min}; use std::collections::HashMap; use std::ffi::CStr; diff --git a/tests/ui-fulldeps/rustc_public/check_defs.rs b/tests/ui-fulldeps/rustc_public/check_defs.rs index e6f9fb9972b0f..0d472e156b40f 100644 --- a/tests/ui-fulldeps/rustc_public/check_defs.rs +++ b/tests/ui-fulldeps/rustc_public/check_defs.rs @@ -19,7 +19,7 @@ use mir::{TerminatorKind::*, mono::Instance}; use rustc_public::mir::mono::InstanceKind; use rustc_public::ty::{RigidTy, Ty, TyKind, UintTy}; use rustc_public::*; -use std::assert_matches::assert_matches; +use std::assert_matches; use std::io::Write; use std::ops::ControlFlow; diff --git a/tests/ui-fulldeps/rustc_public/check_foreign.rs b/tests/ui-fulldeps/rustc_public/check_foreign.rs index bd34fb5cf8a88..ea6d6585e51ec 100644 --- a/tests/ui-fulldeps/rustc_public/check_foreign.rs +++ b/tests/ui-fulldeps/rustc_public/check_foreign.rs @@ -20,7 +20,7 @@ use rustc_public::{ ty::{Abi, ForeignItemKind}, *, }; -use std::assert_matches::assert_matches; +use std::assert_matches; use std::io::Write; use std::ops::ControlFlow; diff --git a/tests/ui-fulldeps/rustc_public/check_intrinsics.rs b/tests/ui-fulldeps/rustc_public/check_intrinsics.rs index f722f0bbd7180..e3538a39f3371 100644 --- a/tests/ui-fulldeps/rustc_public/check_intrinsics.rs +++ b/tests/ui-fulldeps/rustc_public/check_intrinsics.rs @@ -24,7 +24,7 @@ use rustc_public::mir::mono::{Instance, InstanceKind}; use rustc_public::mir::visit::{Location, MirVisitor}; use rustc_public::mir::{LocalDecl, Terminator, TerminatorKind}; use rustc_public::ty::{FnDef, GenericArgs, RigidTy, TyKind}; -use std::assert_matches::assert_matches; +use std::assert_matches; use std::convert::TryFrom; use std::io::Write; use std::ops::ControlFlow; diff --git a/tests/ui-fulldeps/rustc_public/crate-info.rs b/tests/ui-fulldeps/rustc_public/crate-info.rs index 06cbbfcd69ec7..9bf865c54eeef 100644 --- a/tests/ui-fulldeps/rustc_public/crate-info.rs +++ b/tests/ui-fulldeps/rustc_public/crate-info.rs @@ -22,7 +22,7 @@ use rustc_public::ItemKind; use rustc_public::crate_def::CrateDef; use rustc_public::mir::mono::Instance; use rustc_public::ty::{RigidTy, TyKind}; -use std::assert_matches::assert_matches; +use std::assert_matches; use std::io::Write; use std::ops::ControlFlow; diff --git a/tests/ui-fulldeps/rustc_public/projections.rs b/tests/ui-fulldeps/rustc_public/projections.rs index c1cdb5374d460..53baace827a02 100644 --- a/tests/ui-fulldeps/rustc_public/projections.rs +++ b/tests/ui-fulldeps/rustc_public/projections.rs @@ -21,7 +21,7 @@ use rustc_public::ItemKind; use rustc_public::crate_def::CrateDef; use rustc_public::mir::{ProjectionElem, Rvalue, StatementKind}; use rustc_public::ty::{RigidTy, TyKind, UintTy}; -use std::assert_matches::assert_matches; +use std::assert_matches; use std::io::Write; use std::ops::ControlFlow; diff --git a/tests/ui/const-generics/mgca/type_const-incemental-compile.rs b/tests/ui/const-generics/mgca/type_const-incemental-compile.rs new file mode 100644 index 0000000000000..60e6968363db3 --- /dev/null +++ b/tests/ui/const-generics/mgca/type_const-incemental-compile.rs @@ -0,0 +1,11 @@ +//@ check-pass +//@compile-flags: -Clink-dead-code=true +// link-dead-code tries to eagerly monomorphize and collect items +// This lead to collector.rs to try and evaluate a type_const +// which will fail since they do not have bodies. +#![expect(incomplete_features)] +#![feature(min_generic_const_args)] + +#[type_const] +const TYPE_CONST: usize = 0; +fn main() {} diff --git a/tests/ui/const-generics/mgca/type_const-pub.rs b/tests/ui/const-generics/mgca/type_const-pub.rs index fc5b1ce36a14b..f443562394df3 100644 --- a/tests/ui/const-generics/mgca/type_const-pub.rs +++ b/tests/ui/const-generics/mgca/type_const-pub.rs @@ -7,4 +7,6 @@ #[type_const] pub const TYPE_CONST : usize = 1; -fn main() {} +fn main() { + print!("{}", TYPE_CONST) +} diff --git a/tests/ui/const-generics/mgca/wrong_type_const_arr_diag.rs b/tests/ui/const-generics/mgca/wrong_type_const_arr_diag.rs new file mode 100644 index 0000000000000..8a2117096a4a8 --- /dev/null +++ b/tests/ui/const-generics/mgca/wrong_type_const_arr_diag.rs @@ -0,0 +1,13 @@ +// This test causes ERROR: mismatched types [E0308] +// and makes rustc to print array from const arguments +#![feature(min_generic_const_args, adt_const_params)] +#![allow(incomplete_features)] + +struct TakesArr; + +fn foo() { + let _: TakesArr<{ [N] }> = TakesArr::<{ [1] }>; + //~^ ERROR: mismatched types [E0308] +} + +fn main() {} diff --git a/tests/ui/const-generics/mgca/wrong_type_const_arr_diag.stderr b/tests/ui/const-generics/mgca/wrong_type_const_arr_diag.stderr new file mode 100644 index 0000000000000..a2e212b28ec6f --- /dev/null +++ b/tests/ui/const-generics/mgca/wrong_type_const_arr_diag.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/wrong_type_const_arr_diag.rs:9:32 + | +LL | let _: TakesArr<{ [N] }> = TakesArr::<{ [1] }>; + | ----------------- ^^^^^^^^^^^^^^^^^^^ expected `[N]`, found `*b"\x01"` + | | + | expected due to this + | + = note: expected struct `TakesArr<[N]>` + found struct `TakesArr<*b"\x01">` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/const-generics/mgca/wrong_type_const_arr_diag_trait.rs b/tests/ui/const-generics/mgca/wrong_type_const_arr_diag_trait.rs new file mode 100644 index 0000000000000..d290619a04ff6 --- /dev/null +++ b/tests/ui/const-generics/mgca/wrong_type_const_arr_diag_trait.rs @@ -0,0 +1,21 @@ +// This test causes ERROR: mismatched types [E0308] +// and makes rustc to print array from const arguments +#![feature(min_generic_const_args, adt_const_params, trivial_bounds)] +#![allow(incomplete_features)] + +trait Trait { + #[type_const] + const ASSOC: u8; +} + +struct TakesArr; + +fn foo() +where + u8: Trait +{ + let _: TakesArr<{ [::ASSOC] }> = TakesArr::<{ [1] }>; + //~^ ERROR: mismatched types [E0308] +} + +fn main() {} diff --git a/tests/ui/const-generics/mgca/wrong_type_const_arr_diag_trait.stderr b/tests/ui/const-generics/mgca/wrong_type_const_arr_diag_trait.stderr new file mode 100644 index 0000000000000..66de4a4d6a864 --- /dev/null +++ b/tests/ui/const-generics/mgca/wrong_type_const_arr_diag_trait.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/wrong_type_const_arr_diag_trait.rs:17:51 + | +LL | let _: TakesArr<{ [::ASSOC] }> = TakesArr::<{ [1] }>; + | ------------------------------------ ^^^^^^^^^^^^^^^^^^^ expected `[::ASSOC]`, found `*b"\x01"` + | | + | expected due to this + | + = note: expected struct `TakesArr<[::ASSOC]>` + found struct `TakesArr<*b"\x01">` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/coroutine/uninhabited-field.rs b/tests/ui/coroutine/uninhabited-field.rs index d6ada07ce0cbc..bc1f8d7733716 100644 --- a/tests/ui/coroutine/uninhabited-field.rs +++ b/tests/ui/coroutine/uninhabited-field.rs @@ -5,7 +5,7 @@ #![feature(coroutine_trait)] #![feature(coroutines, stmt_expr_attributes)] #![feature(never_type)] -use std::assert_matches::assert_matches; +use std::assert_matches; use std::ops::Coroutine; use std::ops::CoroutineState; use std::pin::Pin; diff --git a/tests/ui/deriving/deriving-all-codegen.stdout b/tests/ui/deriving/deriving-all-codegen.stdout index b778eab605961..2a05d77f8f6da 100644 --- a/tests/ui/deriving/deriving-all-codegen.stdout +++ b/tests/ui/deriving/deriving-all-codegen.stdout @@ -51,7 +51,7 @@ impl ::core::default::Default for Empty { #[automatically_derived] impl ::core::hash::Hash for Empty { #[inline] - fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {} + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {} } #[automatically_derived] impl ::core::marker::StructuralPartialEq for Empty { } @@ -65,7 +65,7 @@ impl ::core::cmp::Eq for Empty { #[inline] #[doc(hidden)] #[coverage(off)] - fn assert_receiver_is_total_eq(&self) -> () {} + fn assert_receiver_is_total_eq(&self) {} } #[automatically_derived] impl ::core::cmp::PartialOrd for Empty { @@ -123,7 +123,7 @@ impl ::core::default::Default for Point { #[automatically_derived] impl ::core::hash::Hash for Point { #[inline] - fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) { ::core::hash::Hash::hash(&self.x, state); ::core::hash::Hash::hash(&self.y, state) } @@ -142,7 +142,7 @@ impl ::core::cmp::Eq for Point { #[inline] #[doc(hidden)] #[coverage(off)] - fn assert_receiver_is_total_eq(&self) -> () { + fn assert_receiver_is_total_eq(&self) { let _: ::core::cmp::AssertParamIsEq; } } @@ -211,7 +211,7 @@ impl ::core::default::Default for PackedPoint { #[automatically_derived] impl ::core::hash::Hash for PackedPoint { #[inline] - fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) { ::core::hash::Hash::hash(&{ self.x }, state); ::core::hash::Hash::hash(&{ self.y }, state) } @@ -230,7 +230,7 @@ impl ::core::cmp::Eq for PackedPoint { #[inline] #[doc(hidden)] #[coverage(off)] - fn assert_receiver_is_total_eq(&self) -> () { + fn assert_receiver_is_total_eq(&self) { let _: ::core::cmp::AssertParamIsEq; } } @@ -297,7 +297,7 @@ impl ::core::convert::From for TupleSingleField { #[automatically_derived] impl ::core::hash::Hash for TupleSingleField { #[inline] - fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) { ::core::hash::Hash::hash(&self.0, state) } } @@ -313,7 +313,7 @@ impl ::core::cmp::Eq for TupleSingleField { #[inline] #[doc(hidden)] #[coverage(off)] - fn assert_receiver_is_total_eq(&self) -> () { + fn assert_receiver_is_total_eq(&self) { let _: ::core::cmp::AssertParamIsEq; } } @@ -372,7 +372,7 @@ impl ::core::convert::From for SingleField { #[automatically_derived] impl ::core::hash::Hash for SingleField { #[inline] - fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) { ::core::hash::Hash::hash(&self.foo, state) } } @@ -388,7 +388,7 @@ impl ::core::cmp::Eq for SingleField { #[inline] #[doc(hidden)] #[coverage(off)] - fn assert_receiver_is_total_eq(&self) -> () { + fn assert_receiver_is_total_eq(&self) { let _: ::core::cmp::AssertParamIsEq; } } @@ -465,7 +465,7 @@ impl ::core::default::Default for Big { #[automatically_derived] impl ::core::hash::Hash for Big { #[inline] - fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) { ::core::hash::Hash::hash(&self.b1, state); ::core::hash::Hash::hash(&self.b2, state); ::core::hash::Hash::hash(&self.b3, state); @@ -493,7 +493,7 @@ impl ::core::cmp::Eq for Big { #[inline] #[doc(hidden)] #[coverage(off)] - fn assert_receiver_is_total_eq(&self) -> () { + fn assert_receiver_is_total_eq(&self) { let _: ::core::cmp::AssertParamIsEq; } } @@ -741,7 +741,7 @@ impl ::core::convert::From<[u32]> for Unsized { #[automatically_derived] impl ::core::hash::Hash for Unsized { #[inline] - fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) { ::core::hash::Hash::hash(&self.0, state) } } @@ -757,7 +757,7 @@ impl ::core::cmp::Eq for Unsized { #[inline] #[doc(hidden)] #[coverage(off)] - fn assert_receiver_is_total_eq(&self) -> () { + fn assert_receiver_is_total_eq(&self) { let _: ::core::cmp::AssertParamIsEq<[u32]>; } } @@ -829,7 +829,7 @@ impl impl ::core::hash::Hash for Generic where T::A: ::core::hash::Hash { #[inline] - fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) { ::core::hash::Hash::hash(&self.t, state); ::core::hash::Hash::hash(&self.ta, state); ::core::hash::Hash::hash(&self.u, state) @@ -852,7 +852,7 @@ impl ::core::cmp::Eq for #[inline] #[doc(hidden)] #[coverage(off)] - fn assert_receiver_is_total_eq(&self) -> () { + fn assert_receiver_is_total_eq(&self) { let _: ::core::cmp::AssertParamIsEq; let _: ::core::cmp::AssertParamIsEq; let _: ::core::cmp::AssertParamIsEq; @@ -946,7 +946,7 @@ impl where T::A: ::core::hash::Hash + ::core::marker::Copy { #[inline] - fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) { ::core::hash::Hash::hash(&{ self.0 }, state); ::core::hash::Hash::hash(&{ self.1 }, state); ::core::hash::Hash::hash(&{ self.2 }, state) @@ -974,7 +974,7 @@ impl () { + fn assert_receiver_is_total_eq(&self) { let _: ::core::cmp::AssertParamIsEq; let _: ::core::cmp::AssertParamIsEq; let _: ::core::cmp::AssertParamIsEq; @@ -1043,7 +1043,7 @@ impl ::core::fmt::Debug for Enum0 { #[automatically_derived] impl ::core::hash::Hash for Enum0 { #[inline] - fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) { match *self {} } } @@ -1059,7 +1059,7 @@ impl ::core::cmp::Eq for Enum0 { #[inline] #[doc(hidden)] #[coverage(off)] - fn assert_receiver_is_total_eq(&self) -> () {} + fn assert_receiver_is_total_eq(&self) {} } #[automatically_derived] impl ::core::cmp::PartialOrd for Enum0 { @@ -1105,7 +1105,7 @@ impl ::core::fmt::Debug for Enum1 { #[automatically_derived] impl ::core::hash::Hash for Enum1 { #[inline] - fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) { match self { Enum1::Single { x: __self_0 } => ::core::hash::Hash::hash(__self_0, state), @@ -1129,7 +1129,7 @@ impl ::core::cmp::Eq for Enum1 { #[inline] #[doc(hidden)] #[coverage(off)] - fn assert_receiver_is_total_eq(&self) -> () { + fn assert_receiver_is_total_eq(&self) { let _: ::core::cmp::AssertParamIsEq; } } @@ -1181,7 +1181,7 @@ impl ::core::default::Default for Fieldless1 { #[automatically_derived] impl ::core::hash::Hash for Fieldless1 { #[inline] - fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {} + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {} } #[automatically_derived] impl ::core::marker::StructuralPartialEq for Fieldless1 { } @@ -1195,7 +1195,7 @@ impl ::core::cmp::Eq for Fieldless1 { #[inline] #[doc(hidden)] #[coverage(off)] - fn assert_receiver_is_total_eq(&self) -> () {} + fn assert_receiver_is_total_eq(&self) {} } #[automatically_derived] impl ::core::cmp::PartialOrd for Fieldless1 { @@ -1251,7 +1251,7 @@ impl ::core::default::Default for Fieldless { #[automatically_derived] impl ::core::hash::Hash for Fieldless { #[inline] - fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) { let __self_discr = ::core::intrinsics::discriminant_value(self); ::core::hash::Hash::hash(&__self_discr, state) } @@ -1272,7 +1272,7 @@ impl ::core::cmp::Eq for Fieldless { #[inline] #[doc(hidden)] #[coverage(off)] - fn assert_receiver_is_total_eq(&self) -> () {} + fn assert_receiver_is_total_eq(&self) {} } #[automatically_derived] impl ::core::cmp::PartialOrd for Fieldless { @@ -1345,7 +1345,7 @@ impl ::core::default::Default for Mixed { #[automatically_derived] impl ::core::hash::Hash for Mixed { #[inline] - fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) { let __self_discr = ::core::intrinsics::discriminant_value(self); ::core::hash::Hash::hash(&__self_discr, state); match self { @@ -1382,7 +1382,7 @@ impl ::core::cmp::Eq for Mixed { #[inline] #[doc(hidden)] #[coverage(off)] - fn assert_receiver_is_total_eq(&self) -> () { + fn assert_receiver_is_total_eq(&self) { let _: ::core::cmp::AssertParamIsEq; let _: ::core::cmp::AssertParamIsEq>; let _: ::core::cmp::AssertParamIsEq>; @@ -1545,7 +1545,7 @@ impl ::core::fmt::Debug for Fielded { #[automatically_derived] impl ::core::hash::Hash for Fielded { #[inline] - fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) { let __self_discr = ::core::intrinsics::discriminant_value(self); ::core::hash::Hash::hash(&__self_discr, state); match self { @@ -1580,7 +1580,7 @@ impl ::core::cmp::Eq for Fielded { #[inline] #[doc(hidden)] #[coverage(off)] - fn assert_receiver_is_total_eq(&self) -> () { + fn assert_receiver_is_total_eq(&self) { let _: ::core::cmp::AssertParamIsEq; let _: ::core::cmp::AssertParamIsEq; let _: ::core::cmp::AssertParamIsEq>; @@ -1666,7 +1666,7 @@ impl ::core::fmt::Debug for impl ::core::hash::Hash for EnumGeneric { #[inline] - fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { + fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) { let __self_discr = ::core::intrinsics::discriminant_value(self); ::core::hash::Hash::hash(&__self_discr, state); match self { @@ -1702,7 +1702,7 @@ impl ::core::cmp::Eq for #[inline] #[doc(hidden)] #[coverage(off)] - fn assert_receiver_is_total_eq(&self) -> () { + fn assert_receiver_is_total_eq(&self) { let _: ::core::cmp::AssertParamIsEq; let _: ::core::cmp::AssertParamIsEq; } diff --git a/tests/ui/macros/assert-matches-macro-msg.rs b/tests/ui/macros/assert-matches-macro-msg.rs index 956bc9cf0f49b..8f4cd254f56b7 100644 --- a/tests/ui/macros/assert-matches-macro-msg.rs +++ b/tests/ui/macros/assert-matches-macro-msg.rs @@ -6,7 +6,7 @@ #![feature(assert_matches)] -use std::assert_matches::assert_matches; +use std::assert_matches; fn main() { assert_matches!(1 + 1, 3, "1 + 1 definitely should be 3"); diff --git a/tests/ui/stats/macro-stats.stderr b/tests/ui/stats/macro-stats.stderr index 11a6bfdfcd292..a48940460f91e 100644 --- a/tests/ui/stats/macro-stats.stderr +++ b/tests/ui/stats/macro-stats.stderr @@ -4,11 +4,11 @@ macro-stats Macro Name Uses Lines Avg Lines B macro-stats ----------------------------------------------------------------------------------- macro-stats #[derive(Clone)] 8 67 8.4 1_879 234.9 macro-stats #[derive(PartialOrd)] 1 17 17.0 675 675.0 -macro-stats #[derive(Hash)] 2 17 8.5 577 288.5 +macro-stats #[derive(Hash)] 2 17 8.5 565 282.5 macro-stats q! 1 26 26.0 519 519.0 macro-stats #[derive(Ord)] 1 15 15.0 503 503.0 macro-stats #[derive(Default)] 2 16 8.0 403 201.5 -macro-stats #[derive(Eq)] 1 11 11.0 325 325.0 +macro-stats #[derive(Eq)] 1 11 11.0 319 319.0 macro-stats #[derive(Debug)] 1 8 8.0 277 277.0 macro-stats #[derive(PartialEq)] 1 9 9.0 267 267.0 macro-stats #[derive(Copy)] 1 2 2.0 61 61.0 diff --git a/tests/ui/stdlib-unit-tests/matches2021.rs b/tests/ui/stdlib-unit-tests/matches2021.rs index 78c8be7321362..c3276cd883471 100644 --- a/tests/ui/stdlib-unit-tests/matches2021.rs +++ b/tests/ui/stdlib-unit-tests/matches2021.rs @@ -5,7 +5,7 @@ #![feature(assert_matches)] -use std::assert_matches::assert_matches; +use std::assert_matches; fn main() { assert!(matches!((), ()));