diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 4045f08c053ed..c861b17c00c6f 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -126,7 +126,7 @@ struct LoweringContext<'a, 'hir> { is_in_dyn_type: bool, current_hir_id_owner: hir::OwnerId, - owner: &'a PerOwnerResolverData, + owner: &'a PerOwnerResolverData<'hir>, item_local_id_counter: hir::ItemLocalId, trait_map: ItemLocalMap<&'hir [TraitCandidate<'hir>]>, @@ -288,11 +288,6 @@ impl<'tcx> ResolverAstLowering<'tcx> { .map(|fn_indexes| fn_indexes.iter().map(|(num, _)| *num).collect()) } - /// Obtains per-namespace resolutions for `use` statement with the given `NodeId`. - fn get_import_res(&self, id: NodeId) -> PerNS>> { - self.import_res_map.get(&id).copied().unwrap_or_default() - } - /// Obtain the list of lifetimes parameters to add to an item. /// /// Extra lifetime parameters should only be added in places that can appear @@ -810,8 +805,8 @@ impl<'hir> LoweringContext<'_, 'hir> { self.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id))); } - if let Some(traits) = self.resolver.trait_map.get(&ast_node_id) { - self.trait_map.insert(hir_id.local_id, &traits[..]); + if let Some(traits) = self.owner.trait_map.get(&ast_node_id) { + self.trait_map.insert(hir_id.local_id, *traits); } // Check whether the same `NodeId` is lowered more than once. @@ -856,8 +851,8 @@ impl<'hir> LoweringContext<'_, 'hir> { } fn lower_import_res(&mut self, id: NodeId, span: Span) -> PerNS> { - let per_ns = self.resolver.get_import_res(id); - let per_ns = per_ns.map(|res| res.map(|res| self.lower_res(res))); + debug_assert_eq!(id, self.owner.id); + let per_ns = self.owner.import_res.map(|res| res.map(|res| self.lower_res(res))); if per_ns.is_empty() { // Propagate the error to all namespaces, just to be sure. self.dcx().span_delayed_bug(span, "no resolution for an import"); diff --git a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs index 14d3eebf8fa1a..1ff3d6c13d0aa 100644 --- a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs @@ -8,6 +8,7 @@ use crate::attributes::AttributeSafety; use crate::session_diagnostics::{ EmptyExportName, NakedFunctionIncompatibleAttribute, NullOnExport, NullOnObjcClass, NullOnObjcSelector, ObjcClassExpectedStringLiteral, ObjcSelectorExpectedStringLiteral, + SanitizeInvalidStatic, }; use crate::target_checking::Policy::AllowSilent; @@ -566,8 +567,18 @@ pub(crate) struct SanitizeParser; impl SingleAttributeParser for SanitizeParser { const PATH: &[Symbol] = &[sym::sanitize]; - // FIXME: still checked in check_attrs.rs - const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS); + const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[ + Allow(Target::Fn), + Allow(Target::Closure), + Allow(Target::Method(MethodKind::Inherent)), + Allow(Target::Method(MethodKind::Trait { body: true })), + Allow(Target::Method(MethodKind::TraitImpl)), + Allow(Target::Impl { of_trait: false }), + Allow(Target::Impl { of_trait: true }), + Allow(Target::Mod), + Allow(Target::Crate), + Allow(Target::Static), + ]); const TEMPLATE: AttributeTemplate = template!(List: &[ r#"address = "on|off""#, r#"kernel_address = "on|off""#, @@ -668,6 +679,18 @@ impl SingleAttributeParser for SanitizeParser { } } + // The sanitizer attribute is only allowed on statics, if only address bits are set + let all_set_except_address = + (on_set | off_set) & !(SanitizerSet::ADDRESS | SanitizerSet::KERNELADDRESS); + if cx.target == Target::Static + && let Some(set) = all_set_except_address.iter().next() + { + cx.emit_err(SanitizeInvalidStatic { + span: cx.attr_span, + field: set.as_str().expect("Since this `SanitizerSet` is returned from an iterator, exactly one field is set") + }); + } + Some(AttributeKind::Sanitize { on_set, off_set, rtsan, span: cx.attr_span }) } } diff --git a/compiler/rustc_attr_parsing/src/session_diagnostics.rs b/compiler/rustc_attr_parsing/src/session_diagnostics.rs index 1d4d8d8123633..b4afdfd7ce409 100644 --- a/compiler/rustc_attr_parsing/src/session_diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/session_diagnostics.rs @@ -1023,3 +1023,12 @@ pub(crate) enum InvalidMachoSectionReason { #[note("section name `{$section}` is longer than 16 bytes")] SectionTooLong { section: String }, } + +#[derive(Diagnostic)] +#[diag("`#[sanitize({$field} = ...)]` attribute cannot be used on statics")] +#[help("`#[sanitize]` can be used on statics if only the address is sanitized")] +pub(crate) struct SanitizeInvalidStatic { + #[primary_span] + pub span: Span, + pub field: &'static str, +} diff --git a/compiler/rustc_attr_parsing/src/target_checking.rs b/compiler/rustc_attr_parsing/src/target_checking.rs index 6d1b06cc7dfcb..483a3d6a1329b 100644 --- a/compiler/rustc_attr_parsing/src/target_checking.rs +++ b/compiler/rustc_attr_parsing/src/target_checking.rs @@ -361,6 +361,13 @@ pub(crate) fn allowed_targets_applied( Target::Method(MethodKind::Trait { body: true }), Target::Method(MethodKind::TraitImpl), ]; + const FUNCTION_WITH_BODY_LIKE: &[Target] = &[ + Target::Fn, + Target::Closure, + Target::Method(MethodKind::Inherent), + Target::Method(MethodKind::Trait { body: true }), + Target::Method(MethodKind::TraitImpl), + ]; const METHOD_LIKE: &[Target] = &[ Target::Method(MethodKind::Inherent), Target::Method(MethodKind::Trait { body: false }), @@ -379,6 +386,13 @@ pub(crate) fn allowed_targets_applied( target, &mut added_fake_targets, ); + filter_targets( + &mut allowed_targets, + FUNCTION_WITH_BODY_LIKE, + "functions with a body", + target, + &mut added_fake_targets, + ); filter_targets(&mut allowed_targets, METHOD_LIKE, "methods", target, &mut added_fake_targets); filter_targets(&mut allowed_targets, IMPL_LIKE, "impl blocks", target, &mut added_fake_targets); filter_targets(&mut allowed_targets, ADT_LIKE, "data types", target, &mut added_fake_targets); diff --git a/compiler/rustc_builtin_macros/src/format_foreign/shell/tests.rs b/compiler/rustc_builtin_macros/src/format_foreign/shell/tests.rs index 145e3e529b0dc..a828f3bae9b77 100644 --- a/compiler/rustc_builtin_macros/src/format_foreign/shell/tests.rs +++ b/compiler/rustc_builtin_macros/src/format_foreign/shell/tests.rs @@ -22,7 +22,7 @@ fn test_escape() { fn test_parse() { macro_rules! assert_pns_eq_sub { ($in_:expr, $kind:ident($arg:expr, $pos:expr)) => { - assert_eq!(pns(concat!($in_, "!")), Some((S::$kind($arg.into(), $pos), "!"))) + assert_eq!(pns(concat!($in_, "!")), Some((S::$kind($arg, $pos), "!"))) }; } diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index 7dc6d292a94af..9dcab40e19db9 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -165,25 +165,30 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { } /// Test if it is valid for a MIR assignment to assign `src`-typed place to `dest`-typed value. -/// This test should be symmetric, as it is primarily about layout compatibility. pub(super) fn mir_assign_valid_types<'tcx>( tcx: TyCtxt<'tcx>, typing_env: TypingEnv<'tcx>, src: TyAndLayout<'tcx>, dest: TyAndLayout<'tcx>, ) -> bool { - // Type-changing assignments can happen when subtyping is used. While - // all normal lifetimes are erased, higher-ranked types with their - // late-bound lifetimes are still around and can lead to type - // differences. + // We *could* check `Invariant` here since all subtyping must be explicit post-borrowck. + // However, this check is also used by the interpreter to figure out if a transmute can be + // turned into a regular assignment (which has a more efficient codepath), so we want the check + // to consider as many assignments as possible to be valid. Therefore we are happy to accept + // one-way subtyping. if util::relate_types(tcx, typing_env, Variance::Covariant, src.ty, dest.ty) { - // Make sure the layout is equal, too -- just to be safe. Miri really - // needs layout equality. For performance reason we skip this check when - // the types are equal. Equal types *can* have different layouts when - // enum downcast is involved (as enum variants carry the type of the - // enum), but those should never occur in assignments. + // Make sure the layout is equal, too -- just to be safe. Miri really needs layout equality. + // For performance reason we skip this check when the types are equal. Equal types *can* + // have different layouts when enum downcast is involved (as enum variants carry the type of + // the enum), but those should never occur in assignments. if cfg!(debug_assertions) || src.ty != dest.ty { - assert_eq!(src.layout, dest.layout); + assert_eq!( + src.layout, + dest.layout, + "{src} is a subtype of {dest} but they have different layout", + src = src.ty, + dest = dest.ty, + ); } true } else { diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs index b1e3fd735399d..b865cafa38647 100644 --- a/compiler/rustc_const_eval/src/interpret/step.rs +++ b/compiler/rustc_const_eval/src/interpret/step.rs @@ -190,8 +190,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { } UnaryOp(un_op, ref operand) => { - // The operand always has the same type as the result. - let val = self.read_immediate(&self.eval_operand(operand, Some(dest.layout))?)?; + let layout = util::unop_homogeneous(un_op).then_some(dest.layout); + let val = self.read_immediate(&self.eval_operand(operand, layout)?)?; let result = self.unary_op(un_op, &val)?; assert_eq!(result.layout, dest.layout, "layout mismatch for result of {un_op:?}"); self.write_immediate(*result, &dest)?; diff --git a/compiler/rustc_const_eval/src/util/mod.rs b/compiler/rustc_const_eval/src/util/mod.rs index 39992123882a9..c63d7748087c9 100644 --- a/compiler/rustc_const_eval/src/util/mod.rs +++ b/compiler/rustc_const_eval/src/util/mod.rs @@ -38,3 +38,13 @@ pub fn binop_right_homogeneous(op: mir::BinOp) -> bool { Offset | Shl | ShlUnchecked | Shr | ShrUnchecked => false, } } + +/// Classify whether an operator is "homogeneous", i.e., the operand has the +/// same type as the result. +#[inline] +pub fn unop_homogeneous(op: mir::UnOp) -> bool { + match op { + mir::UnOp::Not | mir::UnOp::Neg => true, + mir::UnOp::PtrMetadata => false, + } +} diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index d275d5a28b88a..e473db48b04c2 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -717,7 +717,8 @@ impl IntoDiagArg for Namespace { } /// Just a helper ‒ separate structure for each namespace. -#[derive(Copy, Clone, Default, Debug, StableHash)] +#[derive(Copy, Clone, Debug, StableHash)] +#[derive_const(Default)] pub struct PerNS { pub value_ns: T, pub type_ns: T, diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index bc159ee8a004c..98763ff742f25 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -286,7 +286,7 @@ impl<'tcx> InferCtxt<'tcx> { (GenericArgKind::Lifetime(v_o), GenericArgKind::Lifetime(v_r)) => { if v_o != v_r { output_query_region_constraints.constraints.push(( - ty::RegionEqPredicate(v_o.into(), v_r).into(), + ty::RegionEqPredicate(v_o, v_r).into(), constraint_category, ty::VisibleForLeakCheck::Yes, )); diff --git a/compiler/rustc_middle/src/mir/interpret/queries.rs b/compiler/rustc_middle/src/mir/interpret/queries.rs index 6bd1bbe3af20c..80275b58b96dd 100644 --- a/compiler/rustc_middle/src/mir/interpret/queries.rs +++ b/compiler/rustc_middle/src/mir/interpret/queries.rs @@ -107,13 +107,12 @@ impl<'tcx> TyCtxt<'tcx> { Ok(Some(instance)) => GlobalId { instance, promoted: None }, // For errors during resolution, we deliberately do not point at the usage site of the constant, // since for these errors the place the constant is used shouldn't matter. - Ok(None) => return Err(ErrorHandled::TooGeneric(DUMMY_SP).into()), + Ok(None) => return Err(ErrorHandled::TooGeneric(DUMMY_SP)), Err(err) => { return Err(ErrorHandled::Reported( ReportedErrorInfo::non_const_eval_error(err), DUMMY_SP, - ) - .into()); + )); } }; diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 068d190e9b333..1793a8b6b0627 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -27,9 +27,9 @@ pub use intrinsic::IntrinsicDef; use rustc_abi::{ Align, FieldIdx, Integer, IntegerType, ReprFlags, ReprOptions, ScalableElt, VariantIdx, }; -use rustc_ast as ast; use rustc_ast::expand::typetree::{FncTree, Kind, Type, TypeTree}; use rustc_ast::node_id::NodeMap; +use rustc_ast::{self as ast}; pub use rustc_ast_ir::{Movability, Mutability, try_visit}; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::intern::Interned; @@ -204,7 +204,7 @@ pub struct ResolverGlobalCtxt { } #[derive(Debug)] -pub struct PerOwnerResolverData { +pub struct PerOwnerResolverData<'tcx> { pub node_id_to_def_id: NodeMap = Default::default(), /// Whether lifetime elision was successful. pub lifetime_elision_allowed: bool = false, @@ -214,14 +214,19 @@ pub struct PerOwnerResolverData { /// Resolutions for lifetimes. pub lifetimes_res_map: NodeMap = Default::default(), + pub trait_map: NodeMap<&'tcx [hir::TraitCandidate<'tcx>]> = Default::default(), + + /// Resolution for import nodes, which have multiple resolutions in different namespaces. + pub import_res: hir::def::PerNS>> = Default::default(), + /// The id of the owner pub id: ast::NodeId, /// The `DefId` of the owner, can't be found in `node_id_to_def_id`. pub def_id: LocalDefId, } -impl PerOwnerResolverData { - pub fn new(id: ast::NodeId, def_id: LocalDefId) -> PerOwnerResolverData { +impl<'tcx> PerOwnerResolverData<'tcx> { + pub fn new(id: ast::NodeId, def_id: LocalDefId) -> PerOwnerResolverData<'tcx> { PerOwnerResolverData { id, def_id, .. } } @@ -242,16 +247,12 @@ impl PerOwnerResolverData { pub struct ResolverAstLowering<'tcx> { /// Resolutions for nodes that have a single resolution. pub partial_res_map: NodeMap, - /// Resolutions for import nodes, which have multiple resolutions in different namespaces. - pub import_res_map: NodeMap>>>, /// Lifetime parameters that lowering will have to introduce. pub extra_lifetime_params_map: NodeMap>, pub next_node_id: ast::NodeId, - pub owners: NodeMap, - - pub trait_map: NodeMap<&'tcx [hir::TraitCandidate<'tcx>]>, + pub owners: NodeMap>, /// Lints that were emitted by the resolver and early lints. pub lint_buffer: Steal, @@ -1098,7 +1099,7 @@ impl<'tcx> TypingEnv<'tcx> { def_id: impl IntoQueryKey, ) -> TypingEnv<'tcx> { let def_id = def_id.into_query_key(); - Self::new(tcx.param_env(def_id), TypingMode::non_body_analysis().into()) + Self::new(tcx.param_env(def_id), TypingMode::non_body_analysis()) } pub fn post_analysis(tcx: TyCtxt<'tcx>, def_id: impl IntoQueryKey) -> TypingEnv<'tcx> { diff --git a/compiler/rustc_mir_build/src/builder/expr/into.rs b/compiler/rustc_mir_build/src/builder/expr/into.rs index c9aae29cabc53..a6c3d5f9fb9a7 100644 --- a/compiler/rustc_mir_build/src/builder/expr/into.rs +++ b/compiler/rustc_mir_build/src/builder/expr/into.rs @@ -914,7 +914,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block, source_info, destination, - Rvalue::Reborrow(target, mutability, place.into()), + Rvalue::Reborrow(target, mutability, place), ); block.unit() } diff --git a/compiler/rustc_mir_transform/src/check_null.rs b/compiler/rustc_mir_transform/src/check_null.rs index c73b4d7db243f..b589e2fff1569 100644 --- a/compiler/rustc_mir_transform/src/check_null.rs +++ b/compiler/rustc_mir_transform/src/check_null.rs @@ -79,7 +79,7 @@ fn insert_null_check<'tcx>( source_info, StatementKind::Assign(Box::new((pointee_should_be_checked, rvalue))), )); - Operand::Copy(pointee_should_be_checked.into()) + Operand::Copy(pointee_should_be_checked) } }; diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs index 381bcca6b97c9..66e6b69f18ebb 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs @@ -389,7 +389,7 @@ where impl_def_id, impl_args, impl_trait_ref, - target_container_def_id.into(), + target_container_def_id, )?; if !cx.check_args_compatible(target_item_def_id.into(), target_args) { diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index d698a7ed4127a..1b162151adfb1 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -18,7 +18,7 @@ use rustc_feature::BUILTIN_ATTRIBUTE_MAP; use rustc_hir::attrs::diagnostic::Directive; use rustc_hir::attrs::{ AttributeKind, DocAttribute, DocInline, EiiDecl, EiiImpl, EiiImplResolution, InlineAttr, - ReprAttr, SanitizerSet, + ReprAttr, }; use rustc_hir::def::DefKind; use rustc_hir::def_id::LocalModDefId; @@ -227,9 +227,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } &AttributeKind::FfiPure(attr_span) => self.check_ffi_pure(attr_span, attrs), AttributeKind::MayDangle(attr_span) => self.check_may_dangle(hir_id, *attr_span), - &AttributeKind::Sanitize { on_set, off_set, rtsan: _, span: attr_span } => { - self.check_sanitize(attr_span, on_set | off_set, span, target); - } AttributeKind::Link(_, attr_span) => self.check_link(hir_id, *attr_span, target), AttributeKind::MacroExport { span, .. } => { self.check_macro_export(hir_id, *span, target) @@ -401,6 +398,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { AttributeKind::RustcThenThisWouldNeed(..) => (), AttributeKind::RustcTrivialFieldReads => (), AttributeKind::RustcUnsafeSpecializationMarker => (), + AttributeKind::Sanitize { .. } => {} AttributeKind::ShouldPanic { .. } => (), AttributeKind::Stability { .. } => (), AttributeKind::TestRunner(..) => (), @@ -627,52 +625,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } } - /// Checks that the `#[sanitize(..)]` attribute is applied to a - /// function/closure/method, or to an impl block or module. - fn check_sanitize( - &self, - attr_span: Span, - set: SanitizerSet, - target_span: Span, - target: Target, - ) { - let mut not_fn_impl_mod = None; - let mut no_body = None; - - match target { - Target::Fn - | Target::Closure - | Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) - | Target::Impl { .. } - | Target::Mod => return, - Target::Static - // if we mask out the address bits, i.e. *only* address was set, - // we allow it - if set & !(SanitizerSet::ADDRESS | SanitizerSet::KERNELADDRESS) - == SanitizerSet::empty() => - { - return; - } - - // These are "functions", but they aren't allowed because they don't - // have a body, so the usual explanation would be confusing. - Target::Method(MethodKind::Trait { body: false }) | Target::ForeignFn => { - no_body = Some(target_span); - } - - _ => { - not_fn_impl_mod = Some(target_span); - } - } - - self.dcx().emit_err(errors::SanitizeAttributeNotAllowed { - attr_span, - not_fn_impl_mod, - no_body, - help: (), - }); - } - /// Checks if `#[naked]` is applied to a function definition. fn check_naked(&self, hir_id: HirId, target: Target) { match target { diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 97dd413e16cf6..f8b8d2210347c 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -1049,19 +1049,6 @@ pub(crate) struct UnnecessaryPartialStableFeature { #[note("see issue #55436 for more information")] pub(crate) struct IneffectiveUnstableImpl; -#[derive(Diagnostic)] -#[diag("sanitize attribute not allowed here")] -pub(crate) struct SanitizeAttributeNotAllowed { - #[primary_span] - pub attr_span: Span, - #[label("not a function, impl block, or module")] - pub not_fn_impl_mod: Option, - #[label("function has no body")] - pub no_body: Option, - #[help("sanitize attribute can be applied to a function (with body), impl block, or module")] - pub help: (), -} - // FIXME(jdonszelmann): move back to rustc_attr #[derive(Diagnostic)] #[diag( diff --git a/compiler/rustc_query_impl/src/execution.rs b/compiler/rustc_query_impl/src/execution.rs index 2f48583f0beed..a237e7610a392 100644 --- a/compiler/rustc_query_impl/src/execution.rs +++ b/compiler/rustc_query_impl/src/execution.rs @@ -14,7 +14,7 @@ use rustc_middle::query::{ use rustc_middle::ty::TyCtxt; use rustc_middle::verify_ich::incremental_verify_ich; use rustc_span::{DUMMY_SP, Span}; -use tracing::warn; +use tracing::debug; use crate::dep_graph::{DepNode, DepNodeIndex}; use crate::handle_cycle_error; @@ -100,7 +100,12 @@ fn collect_active_query_jobs_inner<'tcx, C>( for shard in query.state.active.try_lock_shards() { match shard { Some(shard) => collect_shard_jobs(&shard), - None => warn!("Failed to collect active jobs for query `{}`!", query.name), + // This collection is best-effort (it is only used to print the query + // stack on panic), so a contended shard is expected and fine to skip. + // Emitting this at `warn!` would leak nondeterministically into the + // panic output under the parallel front-end, where another thread may + // still hold a shard lock, so keep it at `debug!`. + None => debug!("Failed to collect active jobs for query `{}`!", query.name), } } } diff --git a/compiler/rustc_resolve/src/check_unused.rs b/compiler/rustc_resolve/src/check_unused.rs index dc17aaae643ba..5c25e2cec2272 100644 --- a/compiler/rustc_resolve/src/check_unused.rs +++ b/compiler/rustc_resolve/src/check_unused.rs @@ -134,12 +134,10 @@ impl<'a, 'ra, 'tcx> UnusedImportCheckVisitor<'a, 'ra, 'tcx> { match item.kind { ast::UseTreeKind::Simple(Some(ident)) => { if ident.name == kw::Underscore - && !self.r.import_res_map.get(&id).is_some_and(|per_ns| { - matches!( - per_ns.type_ns, - Some(Res::Def(DefKind::Trait | DefKind::TraitAlias, _)) - ) - }) + && !matches!( + self.r.owners[&id].import_res.type_ns, + Some(Res::Def(DefKind::Trait | DefKind::TraitAlias, _)) + ) { self.unused_import(self.base_id).add(id); } diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index c95799758cd59..46cc163ca8ed2 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -1642,7 +1642,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { // purposes it's good enough to just favor one over the other. self.per_ns(|this, ns| { if let Some(binding) = bindings[ns].get().decl().map(|b| b.import_source()) { - this.import_res_map.entry(import_id).or_default()[ns] = Some(binding.res()); + this.owners.get_mut(&import_id).unwrap().import_res[ns] = Some(binding.res()); } }); diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 58899ffd53ab9..9e2cfa57e5809 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -5388,7 +5388,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { ident.span, Some((ident.name, ValueNS)), ); - self.r.trait_map.insert(node_id, traits); + self.r.current_owner.trait_map.insert(node_id, traits); } fn resolve_and_cache_rustdoc_path(&mut self, path_str: &str, ns: Namespace) -> Option { diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 7987c590f31fd..9af55565d30b7 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -1364,8 +1364,6 @@ pub struct Resolver<'ra, 'tcx> { /// Resolutions for nodes that have a single resolution. partial_res_map: NodeMap = Default::default(), - /// Resolutions for import nodes, which have multiple resolutions in different namespaces. - import_res_map: NodeMap>> = Default::default(), /// An import will be inserted into this map if it has been used. import_use_map: FxHashMap, Used> = default::fx_hash_map(), /// Lifetime parameters that lowering will have to introduce. @@ -1375,7 +1373,6 @@ pub struct Resolver<'ra, 'tcx> { extern_crate_map: UnordMap = Default::default(), module_children: LocalDefIdMap> = Default::default(), ambig_module_children: LocalDefIdMap> = Default::default(), - trait_map: NodeMap<&'tcx [TraitCandidate<'tcx>]> = Default::default(), /// A map from nodes to anonymous modules. /// Anonymous modules are pseudo-modules that are implicitly created around items @@ -1490,10 +1487,10 @@ pub struct Resolver<'ra, 'tcx> { next_node_id: NodeId = CRATE_NODE_ID, /// Preserves per owner data once the owner is finished resolving. - owners: NodeMap, + owners: NodeMap>, /// An entry of `owners` that gets taken out and reinserted whenever an owner is handled. - current_owner: PerOwnerResolverData, + current_owner: PerOwnerResolverData<'tcx>, disambiguators: LocalDefIdMap, @@ -1997,11 +1994,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { }; let ast_lowering = ty::ResolverAstLowering { partial_res_map: self.partial_res_map, - import_res_map: self.import_res_map, extra_lifetime_params_map: self.extra_lifetime_params_map, next_node_id: self.next_node_id, owners: self.owners, - trait_map: self.trait_map, lint_buffer: Steal::new(self.lint_buffer), delegation_infos: self.delegation_infos, disambiguators, @@ -2658,7 +2653,7 @@ fn with_owner<'ra, 'tcx, R: AsMut>, T>( fn with_owner_tables<'ra, 'tcx, R: AsMut>, T>( this: &mut R, owner: NodeId, - tables: PerOwnerResolverData, + tables: PerOwnerResolverData<'tcx>, work: impl FnOnce(&mut R) -> T, ) -> T { debug_assert!(!this.as_mut().owners.contains_key(&owner)); diff --git a/compiler/rustc_target/src/spec/json.rs b/compiler/rustc_target/src/spec/json.rs index c8a22205a5f3c..7156c3b08b918 100644 --- a/compiler/rustc_target/src/spec/json.rs +++ b/compiler/rustc_target/src/spec/json.rs @@ -252,7 +252,7 @@ impl ToJson for Target { }; ($attr:ident, $json_name:expr) => {{ let name = $json_name; - d.insert(name.into(), target.$attr.to_json()); + d.insert(name.to_string(), target.$attr.to_json()); }}; } @@ -262,7 +262,7 @@ impl ToJson for Target { let name = $json_name; #[allow(rustc::bad_opt_access)] if default.$attr != target.$attr { - d.insert(name.into(), target.$attr.to_json()); + d.insert(name.to_string(), target.$attr.to_json()); } }}; (link_args - $attr:ident, $json_name:expr) => {{ @@ -447,7 +447,6 @@ impl schemars::JsonSchema for EndianWrapper { "type": "string", "enum": ["big", "little"] }) - .into() } } @@ -473,7 +472,6 @@ impl schemars::JsonSchema for ExternAbiWrapper { "type": "string", "enum": all, }) - .into() } } diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index ea6abe5491262..9d9ec04d8c625 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -522,7 +522,6 @@ impl schemars::JsonSchema for LinkerFlavorCli { "type": "string", "enum": all }) - .into() } } @@ -587,7 +586,6 @@ impl schemars::JsonSchema for LinkSelfContainedDefault { "type": "string", "enum": ["false", "true", "wasm", "musl", "mingw"] }) - .into() } } @@ -733,7 +731,6 @@ impl schemars::JsonSchema for LinkSelfContainedComponents { "type": "string", "enum": all, }) - .into() } } @@ -912,7 +909,6 @@ impl schemars::JsonSchema for SmallDataThresholdSupport { "type": "string", "pattern": r#"^none|default-for-arch|llvm-module-flag=.+|llvm-arg=.+$"#, }) - .into() } } @@ -992,6 +988,8 @@ crate::target_spec_enum! { pub enum RustcAbi { /// On x86-32 only: make use of SSE and SSE2 for ABI purposes. X86Sse2 = "x86-sse2", + /// On PowerPC only: build for SPE. + PowerPcSpe = "powerpc-spe", /// On x86-32/64, aarch64, and S390x: do not use any FPU or SIMD registers for the ABI. Softfloat = "softfloat", "x86-softfloat", } @@ -1288,7 +1286,6 @@ impl schemars::JsonSchema for SanitizerSet { "type": "string", "enum": all, }) - .into() } } @@ -3427,13 +3424,15 @@ impl Target { "`llvm_abiname` is unused on PowerPC" ); check!(self.llvm_floatabi.is_none(), "`llvm_floatabi` is unused on PowerPC"); - check!(self.rustc_abi.is_none(), "`rustc_abi` is unused on PowerPC"); - // FIXME: Check that `target_abi` matches the actually configured ABI (with or - // without SPE). check_matches!( + (&self.rustc_abi, &self.cfg_abi), + (Some(RustcAbi::PowerPcSpe), CfgAbi::Spe) + | (None, CfgAbi::Unspecified | CfgAbi::Other(_)), + "invalid PowerPC Rust-specific ABI and `cfg(target_abi)` combination:\n\ + Rust-specific ABI: {:?}\n\ + cfg(target_abi): {}", + self.rustc_abi, self.cfg_abi, - CfgAbi::Spe | CfgAbi::Unspecified | CfgAbi::Other(_), - "invalid `target_abi` for PowerPC" ); } Arch::PowerPC64 => { diff --git a/compiler/rustc_target/src/spec/targets/powerpc_unknown_linux_gnuspe.rs b/compiler/rustc_target/src/spec/targets/powerpc_unknown_linux_gnuspe.rs index cafb7037c0544..d2d374d608595 100644 --- a/compiler/rustc_target/src/spec/targets/powerpc_unknown_linux_gnuspe.rs +++ b/compiler/rustc_target/src/spec/targets/powerpc_unknown_linux_gnuspe.rs @@ -1,8 +1,8 @@ use rustc_abi::Endian; use crate::spec::{ - Arch, Cc, CfgAbi, LinkerFlavor, Lld, StackProbeType, Target, TargetMetadata, TargetOptions, - base, + Arch, Cc, CfgAbi, LinkerFlavor, Lld, RustcAbi, StackProbeType, Target, TargetMetadata, + TargetOptions, base, }; pub(crate) fn target() -> Target { @@ -24,6 +24,7 @@ pub(crate) fn target() -> Target { arch: Arch::PowerPC, options: TargetOptions { cfg_abi: CfgAbi::Spe, + rustc_abi: Some(RustcAbi::PowerPcSpe), endian: Endian::Big, features: "+secure-plt,+msync,+spe".into(), mcount: "_mcount".into(), diff --git a/compiler/rustc_target/src/spec/targets/powerpc_unknown_linux_muslspe.rs b/compiler/rustc_target/src/spec/targets/powerpc_unknown_linux_muslspe.rs index c9427adf8dce5..e7b6593a7dc54 100644 --- a/compiler/rustc_target/src/spec/targets/powerpc_unknown_linux_muslspe.rs +++ b/compiler/rustc_target/src/spec/targets/powerpc_unknown_linux_muslspe.rs @@ -1,8 +1,8 @@ use rustc_abi::Endian; use crate::spec::{ - Arch, Cc, CfgAbi, LinkerFlavor, Lld, StackProbeType, Target, TargetMetadata, TargetOptions, - base, + Arch, Cc, CfgAbi, LinkerFlavor, Lld, RustcAbi, StackProbeType, Target, TargetMetadata, + TargetOptions, base, }; pub(crate) fn target() -> Target { @@ -24,6 +24,7 @@ pub(crate) fn target() -> Target { arch: Arch::PowerPC, options: TargetOptions { cfg_abi: CfgAbi::Spe, + rustc_abi: Some(RustcAbi::PowerPcSpe), endian: Endian::Big, features: "+msync,+spe".into(), mcount: "_mcount".into(), diff --git a/compiler/rustc_target/src/spec/targets/powerpc_wrs_vxworks_spe.rs b/compiler/rustc_target/src/spec/targets/powerpc_wrs_vxworks_spe.rs index 0a9760d6d1bd7..8be9ed4c2aceb 100644 --- a/compiler/rustc_target/src/spec/targets/powerpc_wrs_vxworks_spe.rs +++ b/compiler/rustc_target/src/spec/targets/powerpc_wrs_vxworks_spe.rs @@ -1,8 +1,8 @@ use rustc_abi::Endian; use crate::spec::{ - Arch, Cc, CfgAbi, LinkerFlavor, Lld, StackProbeType, Target, TargetMetadata, TargetOptions, - base, + Arch, Cc, CfgAbi, LinkerFlavor, Lld, RustcAbi, StackProbeType, Target, TargetMetadata, + TargetOptions, base, }; pub(crate) fn target() -> Target { @@ -24,6 +24,7 @@ pub(crate) fn target() -> Target { arch: Arch::PowerPC, options: TargetOptions { cfg_abi: CfgAbi::Spe, + rustc_abi: Some(RustcAbi::PowerPcSpe), endian: Endian::Big, // feature msync would disable instruction 'fsync' which is not supported by fsl_p1p2 features: "+secure-plt,+msync,+spe".into(), diff --git a/compiler/rustc_target/src/target_features.rs b/compiler/rustc_target/src/target_features.rs index 85697b1414f05..358374f11d747 100644 --- a/compiler/rustc_target/src/target_features.rs +++ b/compiler/rustc_target/src/target_features.rs @@ -573,8 +573,15 @@ const HEXAGON_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ ]; static POWERPC_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ + // If you are thinking of adding "efpu2" here, please double-check that it really does not + // affect the ABI. // tidy-alphabetical-start ("altivec", Unstable(sym::powerpc_target_feature), &[]), + ( + "hard-float", + Forbidden { reason: "unsupported ABI-configuration feature", hard_error: false }, + &[], + ), ("msync", Unstable(sym::powerpc_target_feature), &[]), ("partword-atomics", Unstable(sym::powerpc_target_feature), &[]), ("power8-altivec", Unstable(sym::powerpc_target_feature), &["altivec"]), @@ -584,6 +591,7 @@ static POWERPC_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ ("power9-vector", Unstable(sym::powerpc_target_feature), &["power8-vector", "power9-altivec"]), ("power10-vector", Unstable(sym::powerpc_target_feature), &["power9-vector"]), ("quadword-atomics", Unstable(sym::powerpc_target_feature), &[]), + ("spe", Forbidden { reason: "unsupported ABI-configuration feature", hard_error: false }, &[]), ("vsx", Unstable(sym::powerpc_target_feature), &["altivec"]), // tidy-alphabetical-end ]; @@ -1139,12 +1147,12 @@ impl Target { /// the first list contains target features that must be enabled for ABI reasons, /// and the second list contains target feature that must be disabled for ABI reasons. /// - /// These features are automatically appended to whatever the target spec sets as default - /// features for the target. + /// These features are checked against the target features reported by LLVM based on + /// `-Ctarget-cpu` and `-Ctarget-features`. Constraint violations result in a warning. /// - /// All features enabled/disabled via `-Ctarget-features` and `#[target_features]` are checked - /// against this. We also check any implied features, based on the information above. If LLVM - /// implicitly enables more implied features than we do, that could bypass this check! + /// We also check features enabled via `#[target_features]` (and here, constraint violations + /// emit a hard error), including features enabled indirectly via implications -- but if LLVM + /// considers more features to be implied than we do, that could bypass this check! pub fn abi_required_features(&self) -> FeatureConstraints { const NOTHING: FeatureConstraints = FeatureConstraints { required: &[], incompatible: &[] }; // Some architectures don't have a clean explicit ABI designation; instead, the ABI is @@ -1175,6 +1183,7 @@ impl Target { // LLVM handles the rest. FeatureConstraints { required: &["soft-float"], incompatible: &[] } } + _ => unreachable!(), } } Arch::X86_64 => { @@ -1195,7 +1204,7 @@ impl Target { // LLVM handles the rest. FeatureConstraints { required: &["soft-float"], incompatible: &[] } } - Some(r) => panic!("invalid Rust ABI for x86_64: {r:?}"), + _ => unreachable!(), } } Arch::Arm => { @@ -1232,7 +1241,7 @@ impl Target { // `FeatureConstraints` uses Rust feature names, hence only "neon" shows up. FeatureConstraints { required: &["neon"], incompatible: &[] } } - Some(r) => panic!("invalid Rust ABI for aarch64: {r:?}"), + _ => unreachable!(), } } Arch::RiscV32 | Arch::RiscV64 => { @@ -1309,11 +1318,33 @@ impl Target { // llvm will switch to soft-float ABI just based on this feature. FeatureConstraints { required: &["soft-float"], incompatible: &["vector"] } } - Some(r) => { - panic!("invalid Rust ABI for s390x: {r:?}"); + _ => unreachable!(), + } + } + Arch::PowerPC => { + // The main ABI-relevant target features are "hard-float" and "spe". We use our own + // ABI indicator here. + match self.rustc_abi { + None => { + // Default hardfloat ABI. + FeatureConstraints { required: &["hard-float"], incompatible: &["spe"] } } + Some(RustcAbi::PowerPcSpe) => { + // "efpu2" (which disables some register use in LLVM) *should* be okay + // because SPE uses soft-float ABI's parameter passing rules and passes + // floats via GPRs. + // + FeatureConstraints { required: &["hard-float", "spe"], incompatible: &[] } + } + _ => unreachable!(), } } + Arch::PowerPC64 => { + // There's no SPE for PowerPC64, and we currently don't support any soft-float + // targets. (If we ever add one, we need to match on `RustcAbi::Softfloat` similar + // to other targets above.) + FeatureConstraints { required: &["hard-float"], incompatible: &["spe"] } + } Arch::Avr => { // We only support one ABI on AVR at the moment. // SRAM is minimum requirement for C/C++ in both avr-gcc and Clang, diff --git a/compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs b/compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs index 8ea17c776ea31..1ba0bb5f776ba 100644 --- a/compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs +++ b/compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs @@ -561,12 +561,12 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> { // and therefore is treated as rigid. if let Some(ty::PredicateKind::AliasRelate(lhs, rhs, _)) = pred.kind().no_bound_vars() { goal.infcx().visit_proof_tree_at_depth( - goal.goal().with(tcx, ty::ClauseKind::WellFormed(lhs.into())), + goal.goal().with(tcx, ty::ClauseKind::WellFormed(lhs)), goal.depth() + 1, self, )?; goal.infcx().visit_proof_tree_at_depth( - goal.goal().with(tcx, ty::ClauseKind::WellFormed(rhs.into())), + goal.goal().with(tcx, ty::ClauseKind::WellFormed(rhs)), goal.depth() + 1, self, )?; diff --git a/compiler/rustc_trait_selection/src/solve/normalize.rs b/compiler/rustc_trait_selection/src/solve/normalize.rs index 7c21dc161a1ec..97b460fe347d8 100644 --- a/compiler/rustc_trait_selection/src/solve/normalize.rs +++ b/compiler/rustc_trait_selection/src/solve/normalize.rs @@ -48,8 +48,8 @@ where let delegate = <&SolverDelegate<'tcx>>::from(infcx); let infer_term = delegate.next_term_var_of_kind(alias_term, at.cause.span); let predicate = ty::PredicateKind::AliasRelate( - alias_term.into(), - infer_term.into(), + alias_term, + infer_term, ty::AliasRelationDirection::Equate, ); let goal = Goal::new(infcx.tcx, at.param_env, predicate); @@ -92,8 +92,8 @@ impl<'me, 'tcx> ReplaceAliasWithInfer<'me, 'tcx> { self.at.cause.clone(), self.at.param_env, ty::PredicateKind::AliasRelate( - alias_term.into(), - infer_term.into(), + alias_term, + infer_term, ty::AliasRelationDirection::Equate, ), ); diff --git a/compiler/rustc_trait_selection/src/traits/normalize.rs b/compiler/rustc_trait_selection/src/traits/normalize.rs index ef69d0fe06c15..eff034e0c8d3f 100644 --- a/compiler/rustc_trait_selection/src/traits/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/normalize.rs @@ -295,7 +295,7 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> { let recursion_limit = self.cx().recursion_limit(); if !recursion_limit.value_within_limit(self.depth) { self.selcx.infcx.err_ctxt().report_overflow_error( - OverflowCause::DeeplyNormalize(free.into()), + OverflowCause::DeeplyNormalize(free), self.cause.span, false, |diag| { diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 9be10dfeb250e..f9efe28fa52e9 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -275,10 +275,13 @@ pub fn normalize_projection_term<'a, 'b, 'tcx>( // and a deferred predicate to resolve this when more type // information is available. - selcx - .infcx - .projection_term_to_infer(param_env, alias_term, cause, depth + 1, obligations) - .into() + selcx.infcx.projection_term_to_infer( + param_env, + alias_term, + cause, + depth + 1, + obligations, + ) }) } diff --git a/library/core/src/convert/num.rs b/library/core/src/convert/num.rs index 2e968e8ccc324..7179512e126ed 100644 --- a/library/core/src/convert/num.rs +++ b/library/core/src/convert/num.rs @@ -1,17 +1,9 @@ use crate::num::{IntErrorKind, TryFromIntError}; -mod private { - /// This trait being unreachable from outside the crate - /// prevents other implementations of the `FloatToInt` trait, - /// which allows potentially adding more trait methods after the trait is `#[stable]`. - #[unstable(feature = "convert_float_to_int", issue = "67057")] - pub trait Sealed {} -} - /// Supporting trait for inherent methods of `f32` and `f64` such as `to_int_unchecked`. /// Typically doesn’t need to be used directly. #[unstable(feature = "convert_float_to_int", issue = "67057")] -pub trait FloatToInt: private::Sealed + Sized { +pub impl(self) trait FloatToInt: Sized { #[unstable(feature = "convert_float_to_int", issue = "67057")] #[doc(hidden)] unsafe fn to_int_unchecked(self) -> Int; @@ -19,8 +11,6 @@ pub trait FloatToInt: private::Sealed + Sized { macro_rules! impl_float_to_int { ($Float:ty => $($Int:ty),+) => { - #[unstable(feature = "convert_float_to_int", issue = "67057")] - impl private::Sealed for $Float {} $( #[unstable(feature = "convert_float_to_int", issue = "67057")] impl FloatToInt<$Int> for $Float { diff --git a/library/core/src/ffi/va_list.rs b/library/core/src/ffi/va_list.rs index d5b83a23abe80..55d3cd22354e5 100644 --- a/library/core/src/ffi/va_list.rs +++ b/library/core/src/ffi/va_list.rs @@ -279,26 +279,6 @@ const impl<'f> Drop for VaList<'f> { } } -mod sealed { - pub trait Sealed {} - - impl Sealed for i16 {} - impl Sealed for i32 {} - impl Sealed for i64 {} - impl Sealed for isize {} - - impl Sealed for u16 {} - impl Sealed for u32 {} - impl Sealed for u64 {} - impl Sealed for usize {} - - impl Sealed for f32 {} - impl Sealed for f64 {} - - impl Sealed for *mut T {} - impl Sealed for *const T {} -} - /// Types that are valid to read using [`VaList::next_arg`]. /// /// This trait is implemented for primitive types that have a variable argument application-binary @@ -333,7 +313,7 @@ mod sealed { // types with an alignment larger than 8, or with a non-scalar layout. Inline assembly can be used // to accept unsupported types in the meantime. #[lang = "va_arg_safe"] -pub unsafe trait VaArgSafe: Copy + sealed::Sealed {} +pub impl(self) unsafe trait VaArgSafe: Copy {} crate::cfg_select! { any(target_arch = "avr", target_arch = "msp430") => { diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 1cdf52de8cad8..6bc184f80497a 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -111,7 +111,6 @@ #![feature(offset_of_enum)] #![feature(panic_internals)] #![feature(pattern_type_macro)] -#![feature(sealed)] #![feature(ub_checks)] // tidy-alphabetical-end // @@ -142,6 +141,7 @@ #![feature(freeze_impls)] #![feature(fundamental)] #![feature(funnel_shifts)] +#![feature(impl_restriction)] #![feature(intra_doc_pointers)] #![feature(intrinsics)] #![feature(lang_items)] @@ -219,14 +219,6 @@ pub mod from { pub use crate::macros::builtin::From; } -mod sealed { - /// This trait being unreachable from outside the crate - /// prevents outside implementations of our extension traits. - /// This allows adding more trait methods in the future. - #[unstable(feature = "sealed", issue = "none")] - pub trait Sealed {} -} - // We don't export this through #[macro_export] for now, to avoid breakage. #[unstable(feature = "autodiff", issue = "124509")] #[doc = include_str!("../../core/src/autodiff.md")] diff --git a/library/core/src/marker/variance.rs b/library/core/src/marker/variance.rs index 5fc62a5ad7ac2..31e30a16d45a3 100644 --- a/library/core/src/marker/variance.rs +++ b/library/core/src/marker/variance.rs @@ -30,7 +30,7 @@ macro_rules! phantom_type { } } - impl self::sealed::Sealed for $name where T: ?Sized { + impl self::private_items::PrivateItems for $name where T: ?Sized { const VALUE: Self = Self::new(); } impl Variance for $name where T: ?Sized {} @@ -114,7 +114,7 @@ macro_rules! phantom_lifetime { } } - impl self::sealed::Sealed for $name<'_> { + impl self::private_items::PrivateItems for $name<'_> { const VALUE: Self = Self::new(); } impl Variance for $name<'_> {} @@ -233,14 +233,14 @@ phantom_type! { pub struct PhantomInvariant(PhantomData T>); } -mod sealed { - pub trait Sealed { +mod private_items { + pub trait PrivateItems { const VALUE: Self; } } /// A marker trait for phantom variance types. -pub trait Variance: sealed::Sealed + Default {} +pub trait Variance: private_items::PrivateItems + Default {} /// Construct a variance marker; equivalent to [`Default::default`]. /// diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index ed4624f7c9494..ed91c1e6a4ff1 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -1848,12 +1848,3 @@ macro_rules! from_str_int_impl { from_str_int_impl! { signed isize i8 i16 i32 i64 i128 } from_str_int_impl! { unsigned usize u8 u16 u32 u64 u128 } - -macro_rules! impl_sealed { - ($($t:ty)*) => {$( - /// Allows extension traits within `core`. - #[unstable(feature = "sealed", issue = "none")] - impl crate::sealed::Sealed for $t {} - )*} -} -impl_sealed! { isize i8 i16 i32 i64 i128 usize u8 u16 u32 u64 u128 } diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index de2d10aebdff9..fdff6ceba6a4a 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -31,30 +31,14 @@ use crate::{fmt, intrinsics, ptr, ub_checks}; reason = "implementation detail which may disappear or be replaced at any time", issue = "none" )] -pub unsafe trait ZeroablePrimitive: Sized + Copy + private::Sealed { +pub impl(self) unsafe trait ZeroablePrimitive: Sized + Copy { /// A type like `Self` but with a niche that includes zero. type NonZeroInner: Sized + Copy; } macro_rules! impl_zeroable_primitive { ($($NonZeroInner:ident ( $primitive:ty )),+ $(,)?) => { - mod private { - #[unstable( - feature = "nonzero_internals", - reason = "implementation detail which may disappear or be replaced at any time", - issue = "none" - )] - pub trait Sealed {} - } - $( - #[unstable( - feature = "nonzero_internals", - reason = "implementation detail which may disappear or be replaced at any time", - issue = "none" - )] - impl private::Sealed for $primitive {} - #[unstable( feature = "nonzero_internals", reason = "implementation detail which may disappear or be replaced at any time", diff --git a/library/core/src/num/traits.rs b/library/core/src/num/traits.rs index 08012ebf1adb4..2a5818e9f8d4f 100644 --- a/library/core/src/num/traits.rs +++ b/library/core/src/num/traits.rs @@ -4,7 +4,7 @@ /// Trait for types that this type can be truncated to #[unstable(feature = "num_internals", reason = "internal implementation detail", issue = "none")] #[rustc_const_unstable(feature = "integer_widen_truncate", issue = "154330")] -pub const trait TruncateTarget: crate::sealed::Sealed { +pub impl(self) const trait TruncateTarget { #[doc(hidden)] fn internal_truncate(self) -> Target; @@ -18,7 +18,7 @@ pub const trait TruncateTarget: crate::sealed::Sealed { /// Trait for types that this type can be widened to #[unstable(feature = "num_internals", reason = "internal implementation detail", issue = "none")] #[rustc_const_unstable(feature = "integer_widen_truncate", issue = "154330")] -pub const trait WidenTarget: crate::sealed::Sealed { +pub impl(self) const trait WidenTarget { #[doc(hidden)] fn internal_widen(self) -> Target; } diff --git a/library/core/src/panic.rs b/library/core/src/panic.rs index cf07504466808..939d3df26ba24 100644 --- a/library/core/src/panic.rs +++ b/library/core/src/panic.rs @@ -1,4 +1,4 @@ -//! Panic support in the standard library. +//! Panic support in core. #![stable(feature = "core_panic_info", since = "1.41.0")] diff --git a/library/core/src/slice/index.rs b/library/core/src/slice/index.rs index 56eeb63bca45d..914db4bd75c0b 100644 --- a/library/core/src/slice/index.rs +++ b/library/core/src/slice/index.rs @@ -102,46 +102,6 @@ const unsafe fn get_offset_len_mut_noubcheck( crate::intrinsics::aggregate_raw_ptr(ptr, len) } -mod private_slice_index { - use super::{ops, range}; - - #[stable(feature = "slice_get_slice", since = "1.28.0")] - pub trait Sealed {} - - #[stable(feature = "slice_get_slice", since = "1.28.0")] - impl Sealed for usize {} - #[stable(feature = "slice_get_slice", since = "1.28.0")] - impl Sealed for ops::Range {} - #[stable(feature = "slice_get_slice", since = "1.28.0")] - impl Sealed for ops::RangeTo {} - #[stable(feature = "slice_get_slice", since = "1.28.0")] - impl Sealed for ops::RangeFrom {} - #[stable(feature = "slice_get_slice", since = "1.28.0")] - impl Sealed for ops::RangeFull {} - #[stable(feature = "slice_get_slice", since = "1.28.0")] - impl Sealed for ops::RangeInclusive {} - #[stable(feature = "slice_get_slice", since = "1.28.0")] - impl Sealed for ops::RangeToInclusive {} - #[stable(feature = "slice_index_with_ops_bound_pair", since = "1.53.0")] - impl Sealed for (ops::Bound, ops::Bound) {} - - #[stable(feature = "new_range_api", since = "1.96.0")] - impl Sealed for range::Range {} - #[stable(feature = "new_range_inclusive_api", since = "1.95.0")] - impl Sealed for range::RangeInclusive {} - #[stable(feature = "new_range_to_inclusive_api", since = "1.96.0")] - impl Sealed for range::RangeToInclusive {} - #[stable(feature = "new_range_from_api", since = "1.96.0")] - impl Sealed for range::RangeFrom {} - - impl Sealed for ops::IndexRange {} - - #[unstable(feature = "sliceindex_wrappers", issue = "146179")] - impl Sealed for crate::index::Last {} - #[unstable(feature = "sliceindex_wrappers", issue = "146179")] - impl Sealed for crate::index::Clamp where T: Sealed {} -} - /// A helper trait used for indexing operations. /// /// Implementations of this trait have to promise that if the argument @@ -160,7 +120,7 @@ mod private_slice_index { label = "slice indices are of type `usize` or ranges of `usize`" )] #[rustc_const_unstable(feature = "const_index", issue = "143775")] -pub const unsafe trait SliceIndex: private_slice_index::Sealed { +pub impl(crate) const unsafe trait SliceIndex { /// The output type returned by methods. #[stable(feature = "slice_get_slice", since = "1.28.0")] type Output: ?Sized; diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 5601716b73044..e09b1a1d5fb88 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -5740,24 +5740,6 @@ impl fmt::Display for GetDisjointMutError { } } -mod private_get_disjoint_mut_index { - use super::{Range, RangeInclusive, range}; - - #[unstable(feature = "get_disjoint_mut_helpers", issue = "none")] - pub trait Sealed {} - - #[unstable(feature = "get_disjoint_mut_helpers", issue = "none")] - impl Sealed for usize {} - #[unstable(feature = "get_disjoint_mut_helpers", issue = "none")] - impl Sealed for Range {} - #[unstable(feature = "get_disjoint_mut_helpers", issue = "none")] - impl Sealed for RangeInclusive {} - #[unstable(feature = "get_disjoint_mut_helpers", issue = "none")] - impl Sealed for range::Range {} - #[unstable(feature = "get_disjoint_mut_helpers", issue = "none")] - impl Sealed for range::RangeInclusive {} -} - /// A helper trait for `<[T]>::get_disjoint_mut()`. /// /// # Safety @@ -5765,9 +5747,7 @@ mod private_get_disjoint_mut_index { /// If `is_in_bounds()` returns `true` and `is_overlapping()` returns `false`, /// it must be safe to index the slice with the indices. #[unstable(feature = "get_disjoint_mut_helpers", issue = "none")] -pub unsafe trait GetDisjointMutIndex: - Clone + private_get_disjoint_mut_index::Sealed -{ +pub impl(self) unsafe trait GetDisjointMutIndex: Clone { /// Returns `true` if `self` is in bounds for `len` slice elements. #[unstable(feature = "get_disjoint_mut_helpers", issue = "none")] fn is_in_bounds(&self, len: usize) -> bool; diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index 4f2faa7e5fbd6..ec96099560915 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -257,8 +257,6 @@ use crate::{fmt, intrinsics}; )] #[expect(missing_debug_implementations)] mod private { - pub(super) trait Sealed {} - #[cfg(target_has_atomic_load_store = "8")] #[repr(C, align(1))] pub struct Align1(T); @@ -291,8 +289,7 @@ mod private { reason = "implementation detail which may disappear or be replaced at any time", issue = "none" )] -#[expect(private_bounds)] -pub unsafe trait AtomicPrimitive: Sized + Copy + private::Sealed { +pub impl(self) unsafe trait AtomicPrimitive: Sized + Copy { /// Temporary implementation detail. type Storage: Sized; } @@ -300,8 +297,6 @@ pub unsafe trait AtomicPrimitive: Sized + Copy + private::Sealed { macro impl_atomic_primitive( [$($T:ident)?] $Primitive:ty as $Storage:ident<$Operand:ty>, size($size:literal) ) { - impl $(<$T>)? private::Sealed for $Primitive {} - #[unstable( feature = "atomic_internals", reason = "implementation detail which may disappear or be replaced at any time", diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index 4e74479faa2cc..73fb3f54097fa 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -94,10 +94,6 @@ pub struct OsString { inner: Buf, } -/// Allows extension traits within `std`. -#[unstable(feature = "sealed", issue = "none")] -impl crate::sealed::Sealed for OsString {} - /// Borrowed reference to an OS string (see [`OsString`]). /// /// This type represents a borrowed reference to a string in the operating system's preferred @@ -120,10 +116,6 @@ pub struct OsStr { inner: Slice, } -/// Allows extension traits within `std`. -#[unstable(feature = "sealed", issue = "none")] -impl crate::sealed::Sealed for OsStr {} - impl OsString { /// Constructs a new empty `OsString`. /// diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 3f0db7a6b7435..3fa014dc1aedf 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -44,7 +44,6 @@ mod tests; use crate::ffi::OsString; use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write}; use crate::path::{Path, PathBuf}; -use crate::sealed::Sealed; use crate::sys::{AsInner, AsInnerMut, FromInner, IntoInner, fs as fs_imp}; use crate::time::SystemTime; use crate::{error, fmt}; @@ -2215,10 +2214,6 @@ impl AsInnerMut for FileTimes { } } -// For implementing OS extension traits in `std::os` -#[stable(feature = "file_set_times", since = "1.75.0")] -impl Sealed for FileTimes {} - impl Permissions { /// Returns `true` if these permissions describe a readonly (unwritable) file. /// diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index 5498ccd11b26b..cc25aeea9acd6 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -1195,7 +1195,7 @@ pub(crate) fn attempt_print_to_stderr(args: fmt::Arguments<'_>) { /// Trait to determine if a descriptor/handle refers to a terminal/tty. #[stable(feature = "is_terminal", since = "1.70.0")] -pub trait IsTerminal: crate::sealed::Sealed { +pub impl(crate) trait IsTerminal { /// Returns `true` if the descriptor/handle refers to a terminal/tty. /// /// On platforms where Rust does not know how to detect a terminal yet, this will return @@ -1250,9 +1250,6 @@ pub trait IsTerminal: crate::sealed::Sealed { macro_rules! impl_is_terminal { ($($t:ty),*$(,)?) => {$( - #[unstable(feature = "sealed", issue = "none")] - impl crate::sealed::Sealed for $t {} - #[stable(feature = "is_terminal", since = "1.70.0")] impl IsTerminal for $t { #[inline] diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index addbb407083c7..09d81f11e0a45 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -291,6 +291,7 @@ #![feature(f128)] #![feature(ffi_const)] #![feature(gpu_offload)] +#![feature(impl_restriction)] #![feature(intra_doc_pointers)] #![feature(lang_items)] #![feature(link_cfg)] @@ -792,6 +793,8 @@ include!("keyword_docs.rs"); #[unstable(feature = "restricted_std", issue = "none")] mod __restricted_std_workaround {} +// FIXME(jhpratt) This is currently only used by portable SIMD. Once rust-lang/portable-simd#529 is +// merged, this should be able to be removed. mod sealed { /// This trait being unreachable from outside the crate /// prevents outside implementations of our extension traits. diff --git a/library/std/src/os/darwin/fs.rs b/library/std/src/os/darwin/fs.rs index af98e069b41a3..fc2869d6b13f6 100644 --- a/library/std/src/os/darwin/fs.rs +++ b/library/std/src/os/darwin/fs.rs @@ -4,7 +4,6 @@ #![stable(feature = "metadata_ext", since = "1.1.0")] use crate::fs::{self, Metadata}; -use crate::sealed::Sealed; use crate::sys::{AsInner, AsInnerMut, IntoInner}; use crate::time::SystemTime; @@ -157,7 +156,7 @@ impl MetadataExt for Metadata { /// OS-specific extensions to [`fs::FileTimes`]. #[stable(feature = "file_set_times", since = "1.75.0")] -pub trait FileTimesExt: Sealed { +pub impl(self) trait FileTimesExt { /// Set the creation time of a file. #[stable(feature = "file_set_times", since = "1.75.0")] fn set_created(self, t: SystemTime) -> Self; diff --git a/library/std/src/os/fd/owned.rs b/library/std/src/os/fd/owned.rs index 8a39fe073bf95..703113783f198 100644 --- a/library/std/src/os/fd/owned.rs +++ b/library/std/src/os/fd/owned.rs @@ -237,9 +237,6 @@ impl fmt::Debug for OwnedFd { macro_rules! impl_is_terminal { ($($t:ty),*$(,)?) => {$( - #[unstable(feature = "sealed", issue = "none")] - impl crate::sealed::Sealed for $t {} - #[stable(feature = "is_terminal", since = "1.70.0")] impl io::IsTerminal for $t { #[inline] @@ -358,7 +355,7 @@ impl From for OwnedFd { /// Takes ownership of a [`TcpStream`](crate::net::TcpStream)'s socket file descriptor. #[inline] fn from(tcp_stream: crate::net::TcpStream) -> OwnedFd { - tcp_stream.into_inner().into_socket().into_inner().into_inner().into() + tcp_stream.into_inner().into_socket().into_inner().into_inner() } } @@ -388,7 +385,7 @@ impl From for OwnedFd { /// Takes ownership of a [`TcpListener`](crate::net::TcpListener)'s socket file descriptor. #[inline] fn from(tcp_listener: crate::net::TcpListener) -> OwnedFd { - tcp_listener.into_inner().into_socket().into_inner().into_inner().into() + tcp_listener.into_inner().into_socket().into_inner().into_inner() } } @@ -418,7 +415,7 @@ impl From for OwnedFd { /// Takes ownership of a [`UdpSocket`](crate::net::UdpSocket)'s file descriptor. #[inline] fn from(udp_socket: crate::net::UdpSocket) -> OwnedFd { - udp_socket.into_inner().into_socket().into_inner().into_inner().into() + udp_socket.into_inner().into_socket().into_inner().into_inner() } } diff --git a/library/std/src/os/freebsd/net.rs b/library/std/src/os/freebsd/net.rs index f759b91921b55..68f39ab349a72 100644 --- a/library/std/src/os/freebsd/net.rs +++ b/library/std/src/os/freebsd/net.rs @@ -5,7 +5,6 @@ use crate::ffi::CStr; use crate::io; use crate::os::unix::net; -use crate::sealed::Sealed; use crate::sys::AsInner; /// FreeBSD-specific functionality for `AF_UNIX` sockets [`UnixDatagram`] @@ -14,7 +13,7 @@ use crate::sys::AsInner; /// [`UnixDatagram`]: net::UnixDatagram /// [`UnixStream`]: net::UnixStream #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] -pub trait UnixSocketExt: Sealed { +pub impl(self) trait UnixSocketExt { /// Query the current setting of socket option `LOCAL_CREDS_PERSISTENT`. #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] fn local_creds_persistent(&self) -> io::Result; diff --git a/library/std/src/os/illumos/net.rs b/library/std/src/os/illumos/net.rs index c21c887edbdf9..65512348033cb 100644 --- a/library/std/src/os/illumos/net.rs +++ b/library/std/src/os/illumos/net.rs @@ -4,7 +4,6 @@ use crate::io; use crate::os::unix::net; -use crate::sealed::Sealed; use crate::sys::AsInner; /// illumos-specific functionality for `AF_UNIX` sockets [`UnixDatagram`] @@ -13,7 +12,7 @@ use crate::sys::AsInner; /// [`UnixDatagram`]: net::UnixDatagram /// [`UnixStream`]: net::UnixStream #[unstable(feature = "unix_socket_exclbind", issue = "123481")] -pub trait UnixSocketExt: Sealed { +pub impl(self) trait UnixSocketExt { /// Enables exclusive binding on the socket. /// /// If true and if the socket had been set with `SO_REUSEADDR`, diff --git a/library/std/src/os/linux/process.rs b/library/std/src/os/linux/process.rs index 60851db831bf9..77b468f49ebbf 100644 --- a/library/std/src/os/linux/process.rs +++ b/library/std/src/os/linux/process.rs @@ -7,7 +7,6 @@ use crate::io::Result; use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; use crate::process::{self, ExitStatus}; -use crate::sealed::Sealed; use crate::sys::{AsInner, AsInnerMut, FromInner, IntoInner}; #[cfg(not(doc))] use crate::sys::{fd::FileDesc, linux::pidfd::PidFd as InnerPidFd}; @@ -147,7 +146,7 @@ impl From for OwnedFd { /// Os-specific extensions for [`Child`] /// /// [`Child`]: process::Child -pub trait ChildExt: Sealed { +pub impl(crate) trait ChildExt { /// Obtains a reference to the [`PidFd`] created for this [`Child`], if available. /// /// A pidfd will only be available if its creation was requested with @@ -186,7 +185,7 @@ pub trait ChildExt: Sealed { /// Os-specific extensions for [`Command`] /// /// [`Command`]: process::Command -pub trait CommandExt: Sealed { +pub impl(self) trait CommandExt { /// Sets whether a [`PidFd`](struct@PidFd) should be created for the [`Child`] /// spawned by this [`Command`]. /// By default, no pidfd will be created. diff --git a/library/std/src/os/motor/ffi.rs b/library/std/src/os/motor/ffi.rs index e65a7736d3fa0..36531d4b57356 100644 --- a/library/std/src/os/motor/ffi.rs +++ b/library/std/src/os/motor/ffi.rs @@ -2,14 +2,13 @@ #![unstable(feature = "motor_ext", issue = "147456")] use crate::ffi::{OsStr, OsString}; -use crate::sealed::Sealed; use crate::sys::{AsInner, IntoInner}; /// Motor OS–specific extensions to [`OsString`]. /// /// This trait is sealed: it cannot be implemented outside the standard library. /// This is so that future additional methods are not breaking changes. -pub trait OsStringExt: Sealed { +pub impl(self) trait OsStringExt { /// Yields the underlying UTF-8 string of this [`OsString`]. /// /// OS strings on Motor OS are guaranteed to be UTF-8, so are just strings. @@ -27,7 +26,7 @@ impl OsStringExt for OsString { /// /// This trait is sealed: it cannot be implemented outside the standard library. /// This is so that future additional methods are not breaking changes. -pub trait OsStrExt: Sealed { +pub impl(self) trait OsStrExt { /// Gets the underlying UTF-8 string view of the [`OsStr`] slice. /// /// OS strings on Motor OS are guaranteed to be UTF-8, so are just strings. diff --git a/library/std/src/os/motor/process.rs b/library/std/src/os/motor/process.rs index 09f38a4721bbc..43c8ff5a42987 100644 --- a/library/std/src/os/motor/process.rs +++ b/library/std/src/os/motor/process.rs @@ -1,9 +1,8 @@ #![unstable(feature = "motor_ext", issue = "147456")] -use crate::sealed::Sealed; use crate::sys::AsInner; -pub trait ChildExt: Sealed { +pub impl(self) trait ChildExt { /// Extracts the main thread raw handle, without taking ownership fn sys_handle(&self) -> u64; } diff --git a/library/std/src/os/net/linux_ext/addr.rs b/library/std/src/os/net/linux_ext/addr.rs index 41009c0e28457..ea7e436d11129 100644 --- a/library/std/src/os/net/linux_ext/addr.rs +++ b/library/std/src/os/net/linux_ext/addr.rs @@ -1,11 +1,10 @@ //! Linux and Android-specific extensions to socket addresses. use crate::os::unix::net::SocketAddr; -use crate::sealed::Sealed; /// Platform-specific extensions to [`SocketAddr`]. #[stable(feature = "unix_socket_abstract", since = "1.70.0")] -pub trait SocketAddrExt: Sealed { +pub impl(in crate::os) trait SocketAddrExt { /// Creates a Unix socket address in the abstract namespace. /// /// The abstract namespace is a Linux-specific extension that allows Unix diff --git a/library/std/src/os/net/linux_ext/socket.rs b/library/std/src/os/net/linux_ext/socket.rs index ecc2758961e1d..b7bee94128534 100644 --- a/library/std/src/os/net/linux_ext/socket.rs +++ b/library/std/src/os/net/linux_ext/socket.rs @@ -2,7 +2,6 @@ use crate::io; use crate::os::unix::net; -use crate::sealed::Sealed; use crate::sys::AsInner; /// Linux-specific functionality for `AF_UNIX` sockets [`UnixDatagram`] @@ -11,7 +10,7 @@ use crate::sys::AsInner; /// [`UnixDatagram`]: net::UnixDatagram /// [`UnixStream`]: net::UnixStream #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] -pub trait UnixSocketExt: Sealed { +pub impl(self) trait UnixSocketExt { /// Query the current setting of socket option `SO_PASSCRED`. #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] fn passcred(&self) -> io::Result; diff --git a/library/std/src/os/net/linux_ext/tcp.rs b/library/std/src/os/net/linux_ext/tcp.rs index c97063dd16505..dd3a5ad7342b7 100644 --- a/library/std/src/os/net/linux_ext/tcp.rs +++ b/library/std/src/os/net/linux_ext/tcp.rs @@ -2,7 +2,6 @@ //! //! [`std::net`]: crate::net -use crate::sealed::Sealed; use crate::sys::AsInner; #[cfg(target_os = "linux")] use crate::time::Duration; @@ -12,7 +11,7 @@ use crate::{io, net}; /// /// [`TcpStream`]: net::TcpStream #[stable(feature = "tcp_quickack", since = "1.89.0")] -pub trait TcpStreamExt: Sealed { +pub impl(self) trait TcpStreamExt { /// Enable or disable `TCP_QUICKACK`. /// /// This flag causes Linux to eagerly send ACKs rather than delaying them. @@ -109,9 +108,6 @@ pub trait TcpStreamExt: Sealed { fn deferaccept(&self) -> io::Result; } -#[stable(feature = "tcp_quickack", since = "1.89.0")] -impl Sealed for net::TcpStream {} - #[stable(feature = "tcp_quickack", since = "1.89.0")] impl TcpStreamExt for net::TcpStream { fn set_quickack(&self, quickack: bool) -> io::Result<()> { diff --git a/library/std/src/os/netbsd/net.rs b/library/std/src/os/netbsd/net.rs index 9174fee2f9962..a77302ddbc675 100644 --- a/library/std/src/os/netbsd/net.rs +++ b/library/std/src/os/netbsd/net.rs @@ -5,7 +5,6 @@ use crate::ffi::CStr; use crate::io; use crate::os::unix::net; -use crate::sealed::Sealed; use crate::sys::AsInner; /// NetBSD-specific functionality for `AF_UNIX` sockets [`UnixDatagram`] @@ -14,7 +13,7 @@ use crate::sys::AsInner; /// [`UnixDatagram`]: net::UnixDatagram /// [`UnixStream`]: net::UnixStream #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] -pub trait UnixSocketExt: Sealed { +pub impl(self) trait UnixSocketExt { /// Query the current setting of socket option `LOCAL_CREDS`. #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] fn local_creds(&self) -> io::Result; diff --git a/library/std/src/os/solaris/net.rs b/library/std/src/os/solaris/net.rs index cea65f6ee7019..6376a0fe1024b 100644 --- a/library/std/src/os/solaris/net.rs +++ b/library/std/src/os/solaris/net.rs @@ -4,7 +4,6 @@ use crate::io; use crate::os::unix::net; -use crate::sealed::Sealed; use crate::sys::AsInner; /// solaris-specific functionality for `AF_UNIX` sockets [`UnixDatagram`] @@ -13,7 +12,7 @@ use crate::sys::AsInner; /// [`UnixDatagram`]: net::UnixDatagram /// [`UnixStream`]: net::UnixStream #[unstable(feature = "unix_socket_exclbind", issue = "123481")] -pub trait UnixSocketExt: Sealed { +pub impl(self) trait UnixSocketExt { /// Enables exclusive binding on the socket. /// /// If true and if the socket had been set with `SO_REUSEADDR`, diff --git a/library/std/src/os/solid/io.rs b/library/std/src/os/solid/io.rs index ac112e739170d..808e0b874ebbf 100644 --- a/library/std/src/os/solid/io.rs +++ b/library/std/src/os/solid/io.rs @@ -180,9 +180,6 @@ impl fmt::Debug for OwnedFd { macro_rules! impl_is_terminal { ($($t:ty),*$(,)?) => {$( - #[unstable(feature = "sealed", issue = "none")] - impl crate::sealed::Sealed for $t {} - #[stable(feature = "is_terminal", since = "1.70.0")] impl io::IsTerminal for $t { #[inline] diff --git a/library/std/src/os/unix/ffi/os_str.rs b/library/std/src/os/unix/ffi/os_str.rs index da47112f7cb47..8779224768420 100644 --- a/library/std/src/os/unix/ffi/os_str.rs +++ b/library/std/src/os/unix/ffi/os_str.rs @@ -1,6 +1,5 @@ use crate::ffi::{OsStr, OsString}; use crate::mem; -use crate::sealed::Sealed; use crate::sys::os_str::Buf; use crate::sys::{AsInner, FromInner, IntoInner}; @@ -12,7 +11,7 @@ use crate::sys::{AsInner, FromInner, IntoInner}; /// This trait is sealed: it cannot be implemented outside the standard library. /// This is so that future additional methods are not breaking changes. #[stable(feature = "rust1", since = "1.0.0")] -pub trait OsStringExt: Sealed { +pub impl(self) trait OsStringExt { /// Creates an [`OsString`] from a byte vector. /// /// See the module documentation for an example. @@ -43,7 +42,7 @@ impl OsStringExt for OsString { /// This trait is sealed: it cannot be implemented outside the standard library. /// This is so that future additional methods are not breaking changes. #[stable(feature = "rust1", since = "1.0.0")] -pub trait OsStrExt: Sealed { +pub impl(self) trait OsStrExt { #[stable(feature = "rust1", since = "1.0.0")] /// Creates an [`OsStr`] from a byte slice. /// diff --git a/library/std/src/os/unix/fs.rs b/library/std/src/os/unix/fs.rs index 219b340b92469..8a15dda63d573 100644 --- a/library/std/src/os/unix/fs.rs +++ b/library/std/src/os/unix/fs.rs @@ -14,7 +14,6 @@ use crate::fs::{self, OpenOptions, Permissions}; use crate::io::BorrowedCursor; use crate::os::unix::io::{AsFd, AsRawFd}; use crate::path::Path; -use crate::sealed::Sealed; use crate::sys::{AsInner, AsInnerMut, FromInner}; use crate::{io, sys}; @@ -1011,7 +1010,7 @@ impl DirEntryExt for fs::DirEntry { /// Sealed Unix-specific extension methods for [`fs::DirEntry`]. #[unstable(feature = "dir_entry_ext2", issue = "85573")] -pub trait DirEntryExt2: Sealed { +pub impl(self) trait DirEntryExt2 { /// Returns a reference to the underlying `OsStr` of this entry's filename. /// /// # Examples @@ -1035,10 +1034,6 @@ pub trait DirEntryExt2: Sealed { fn file_name_ref(&self) -> &OsStr; } -/// Allows extension traits within `std`. -#[unstable(feature = "sealed", issue = "none")] -impl Sealed for fs::DirEntry {} - #[unstable(feature = "dir_entry_ext2", issue = "85573")] impl DirEntryExt2 for fs::DirEntry { fn file_name_ref(&self) -> &OsStr { diff --git a/library/std/src/os/unix/io/mod.rs b/library/std/src/os/unix/io/mod.rs index 18b0f70c06877..0385e5513ea08 100644 --- a/library/std/src/os/unix/io/mod.rs +++ b/library/std/src/os/unix/io/mod.rs @@ -103,7 +103,7 @@ use crate::sys::cvt; mod tests; #[unstable(feature = "stdio_swap", issue = "150667")] -pub trait StdioExt: crate::sealed::Sealed { +pub impl(self) trait StdioExt { /// Redirects the stdio file descriptor to point to the file description underpinning `fd`. /// /// Rust std::io write buffers (if any) are flushed, but other runtimes diff --git a/library/std/src/os/unix/net/addr.rs b/library/std/src/os/unix/net/addr.rs index 0748f6984a825..304f2f23828de 100644 --- a/library/std/src/os/unix/net/addr.rs +++ b/library/std/src/os/unix/net/addr.rs @@ -4,7 +4,6 @@ use crate::ffi::OsStr; use crate::os::net::linux_ext; use crate::os::unix::ffi::OsStrExt; use crate::path::Path; -use crate::sealed::Sealed; use crate::sys::cvt; use crate::{fmt, io, mem, ptr}; @@ -253,9 +252,6 @@ impl SocketAddr { } } -#[stable(feature = "unix_socket_abstract", since = "1.70.0")] -impl Sealed for SocketAddr {} - #[doc(cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin")))] #[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))] #[stable(feature = "unix_socket_abstract", since = "1.70.0")] diff --git a/library/std/src/os/unix/net/datagram.rs b/library/std/src/os/unix/net/datagram.rs index beda370006f73..6876446c25c5d 100644 --- a/library/std/src/os/unix/net/datagram.rs +++ b/library/std/src/os/unix/net/datagram.rs @@ -21,7 +21,6 @@ use crate::io::{IoSlice, IoSliceMut}; use crate::net::Shutdown; use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; use crate::path::Path; -use crate::sealed::Sealed; use crate::sys::net::Socket; use crate::sys::{AsInner, FromInner, IntoInner, cvt}; use crate::time::Duration; @@ -60,10 +59,6 @@ const MSG_NOSIGNAL: core::ffi::c_int = 0x0; #[stable(feature = "unix_socket", since = "1.10.0")] pub struct UnixDatagram(Socket); -/// Allows extension traits within `std`. -#[unstable(feature = "sealed", issue = "none")] -impl Sealed for UnixDatagram {} - #[stable(feature = "unix_socket", since = "1.10.0")] impl fmt::Debug for UnixDatagram { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/library/std/src/os/unix/net/stream.rs b/library/std/src/os/unix/net/stream.rs index 30124d96951eb..aa31258b5ceec 100644 --- a/library/std/src/os/unix/net/stream.rs +++ b/library/std/src/os/unix/net/stream.rs @@ -35,7 +35,6 @@ use crate::io::{self, IoSlice, IoSliceMut}; use crate::net::Shutdown; use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; use crate::path::Path; -use crate::sealed::Sealed; use crate::sys::net::Socket; use crate::sys::{AsInner, FromInner, cvt}; use crate::time::Duration; @@ -73,10 +72,6 @@ use crate::time::Duration; #[stable(feature = "unix_socket", since = "1.10.0")] pub struct UnixStream(pub(super) Socket); -/// Allows extension traits within `std`. -#[unstable(feature = "sealed", issue = "none")] -impl Sealed for UnixStream {} - #[stable(feature = "unix_socket", since = "1.10.0")] impl fmt::Debug for UnixStream { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/library/std/src/os/unix/process.rs b/library/std/src/os/unix/process.rs index 71896d73670fd..c64859d1872eb 100644 --- a/library/std/src/os/unix/process.rs +++ b/library/std/src/os/unix/process.rs @@ -7,7 +7,6 @@ use crate::ffi::OsStr; use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}; use crate::path::Path; -use crate::sealed::Sealed; use crate::sys::process::ChildPipe; use crate::sys::{AsInner, AsInnerMut, FromInner, IntoInner}; use crate::{io, process, sys}; @@ -35,7 +34,7 @@ cfg_select! { /// This trait is sealed: it cannot be implemented outside the standard library. /// This is so that future additional methods are not breaking changes. #[stable(feature = "rust1", since = "1.0.0")] -pub trait CommandExt: Sealed { +pub impl(self) trait CommandExt { /// Sets the child process's user ID. This translates to a /// `setuid` call in the child process. Failure in the `setuid` /// call will cause the spawn to fail. @@ -291,7 +290,7 @@ impl CommandExt for process::Command { /// This trait is sealed: it cannot be implemented outside the standard library. /// This is so that future additional methods are not breaking changes. #[stable(feature = "rust1", since = "1.0.0")] -pub trait ExitStatusExt: Sealed { +pub impl(self) trait ExitStatusExt { /// Creates a new `ExitStatus` or `ExitStatusError` from the raw underlying integer status /// value from `wait` /// @@ -393,7 +392,7 @@ impl ExitStatusExt for process::ExitStatusError { } #[unstable(feature = "unix_send_signal", issue = "141975")] -pub trait ChildExt: Sealed { +pub impl(self) trait ChildExt { /// Sends a signal to a child process. /// /// # Errors diff --git a/library/std/src/os/windows/ffi.rs b/library/std/src/os/windows/ffi.rs index fa115385c5d4e..9d5af1b169e6a 100644 --- a/library/std/src/os/windows/ffi.rs +++ b/library/std/src/os/windows/ffi.rs @@ -58,7 +58,6 @@ use alloc::wtf8::Wtf8Buf; use crate::ffi::{OsStr, OsString}; use crate::fmt; use crate::iter::FusedIterator; -use crate::sealed::Sealed; use crate::sys::os_str::Buf; use crate::sys::{AsInner, FromInner}; @@ -67,7 +66,7 @@ use crate::sys::{AsInner, FromInner}; /// This trait is sealed: it cannot be implemented outside the standard library. /// This is so that future additional methods are not breaking changes. #[stable(feature = "rust1", since = "1.0.0")] -pub trait OsStringExt: Sealed { +pub impl(self) trait OsStringExt { /// Creates an `OsString` from a potentially ill-formed UTF-16 slice of /// 16-bit code units. /// @@ -101,7 +100,7 @@ impl OsStringExt for OsString { /// This trait is sealed: it cannot be implemented outside the standard library. /// This is so that future additional methods are not breaking changes. #[stable(feature = "rust1", since = "1.0.0")] -pub trait OsStrExt: Sealed { +pub impl(self) trait OsStrExt { /// Re-encodes an `OsStr` as a wide character sequence, i.e., potentially /// ill-formed UTF-16. /// diff --git a/library/std/src/os/windows/fs.rs b/library/std/src/os/windows/fs.rs index 54d5cafe15ec6..23797f4bcc40f 100644 --- a/library/std/src/os/windows/fs.rs +++ b/library/std/src/os/windows/fs.rs @@ -7,7 +7,6 @@ use crate::fs::{self, Metadata, OpenOptions, Permissions}; use crate::io::BorrowedCursor; use crate::path::Path; -use crate::sealed::Sealed; use crate::sys::{AsInner, AsInnerMut, FromInner, IntoInner}; use crate::time::SystemTime; use crate::{io, sys}; @@ -338,7 +337,7 @@ impl OpenOptionsExt for OpenOptions { } #[unstable(feature = "windows_freeze_file_times", issue = "149715")] -pub trait OpenOptionsExt2: Sealed { +pub impl(self) trait OpenOptionsExt2 { /// If set to `true`, prevent the "last access time" of the file from being changed. /// /// Default to `false`. @@ -352,9 +351,6 @@ pub trait OpenOptionsExt2: Sealed { fn freeze_last_write_time(&mut self, freeze: bool) -> &mut Self; } -#[unstable(feature = "sealed", issue = "none")] -impl Sealed for OpenOptions {} - #[unstable(feature = "windows_freeze_file_times", issue = "149715")] impl OpenOptionsExt2 for OpenOptions { fn freeze_last_access_time(&mut self, freeze: bool) -> &mut Self { @@ -398,7 +394,7 @@ impl OpenOptionsExt2 for OpenOptions { /// assert_eq!(permissions.file_attributes(), new_file_attr); /// ``` #[unstable(feature = "windows_permissions_ext", issue = "152956")] -pub trait PermissionsExt: Sealed { +pub impl(self) trait PermissionsExt { /// Returns the file attribute bits. #[unstable(feature = "windows_permissions_ext", issue = "152956")] fn file_attributes(&self) -> u32; @@ -412,9 +408,6 @@ pub trait PermissionsExt: Sealed { fn from_file_attributes(mask: u32) -> Self; } -#[unstable(feature = "windows_permissions_ext", issue = "152956")] -impl Sealed for fs::Permissions {} - #[unstable(feature = "windows_permissions_ext", issue = "152956")] impl PermissionsExt for fs::Permissions { fn file_attributes(&self) -> u32 { @@ -656,7 +649,7 @@ impl MetadataExt for Metadata { /// /// On Windows, a symbolic link knows whether it is a file or directory. #[stable(feature = "windows_file_type_ext", since = "1.64.0")] -pub trait FileTypeExt: Sealed { +pub impl(self) trait FileTypeExt { /// Returns `true` if this file type is a symbolic link that is also a directory. #[stable(feature = "windows_file_type_ext", since = "1.64.0")] fn is_symlink_dir(&self) -> bool; @@ -665,9 +658,6 @@ pub trait FileTypeExt: Sealed { fn is_symlink_file(&self) -> bool; } -#[stable(feature = "windows_file_type_ext", since = "1.64.0")] -impl Sealed for fs::FileType {} - #[stable(feature = "windows_file_type_ext", since = "1.64.0")] impl FileTypeExt for fs::FileType { fn is_symlink_dir(&self) -> bool { @@ -680,7 +670,7 @@ impl FileTypeExt for fs::FileType { /// Windows-specific extensions to [`fs::FileTimes`]. #[stable(feature = "file_set_times", since = "1.75.0")] -pub trait FileTimesExt: Sealed { +pub impl(self) trait FileTimesExt { /// Set the creation time of a file. #[stable(feature = "file_set_times", since = "1.75.0")] fn set_created(self, t: SystemTime) -> Self; diff --git a/library/std/src/os/windows/io/handle.rs b/library/std/src/os/windows/io/handle.rs index 13c0752b560b9..e58f94253bdf7 100644 --- a/library/std/src/os/windows/io/handle.rs +++ b/library/std/src/os/windows/io/handle.rs @@ -405,9 +405,6 @@ impl fmt::Debug for OwnedHandle { macro_rules! impl_is_terminal { ($($t:ty),*$(,)?) => {$( - #[unstable(feature = "sealed", issue = "none")] - impl crate::sealed::Sealed for $t {} - #[stable(feature = "is_terminal", since = "1.70.0")] impl io::IsTerminal for $t { #[inline] diff --git a/library/std/src/os/windows/process.rs b/library/std/src/os/windows/process.rs index ff3ae8145e0f6..65f63db7850b5 100644 --- a/library/std/src/os/windows/process.rs +++ b/library/std/src/os/windows/process.rs @@ -9,7 +9,6 @@ use crate::mem::MaybeUninit; use crate::os::windows::io::{ AsHandle, AsRawHandle, BorrowedHandle, FromRawHandle, IntoRawHandle, OwnedHandle, RawHandle, }; -use crate::sealed::Sealed; use crate::sys::{AsInner, AsInnerMut, FromInner, IntoInner}; use crate::{io, marker, process, ptr, sys}; @@ -153,7 +152,7 @@ impl From for process::ChildStderr { /// This trait is sealed: it cannot be implemented outside the standard library. /// This is so that future additional methods are not breaking changes. #[stable(feature = "exit_status_from", since = "1.12.0")] -pub trait ExitStatusExt: Sealed { +pub impl(self) trait ExitStatusExt { /// Creates a new `ExitStatus` from the raw underlying `u32` return value of /// a process. #[stable(feature = "exit_status_from", since = "1.12.0")] @@ -172,7 +171,7 @@ impl ExitStatusExt for process::ExitStatus { /// This trait is sealed: it cannot be implemented outside the standard library. /// This is so that future additional methods are not breaking changes. #[stable(feature = "windows_process_extensions", since = "1.16.0")] -pub trait CommandExt: Sealed { +pub impl(self) trait CommandExt { /// Sets the [process creation flags][1] to be passed to `CreateProcess`. /// /// These will always be ORed with `CREATE_UNICODE_ENVIRONMENT`. @@ -443,7 +442,7 @@ impl CommandExt for process::Command { } #[unstable(feature = "windows_process_extensions_main_thread_handle", issue = "96723")] -pub trait ChildExt: Sealed { +pub impl(self) trait ChildExt { /// Extracts the main thread raw handle, without taking ownership #[unstable(feature = "windows_process_extensions_main_thread_handle", issue = "96723")] fn main_thread_handle(&self) -> BorrowedHandle<'_>; @@ -461,7 +460,7 @@ impl ChildExt for process::Child { /// This trait is sealed: it cannot be implemented outside the standard library. /// This is so that future additional methods are not breaking changes. #[unstable(feature = "windows_process_exit_code_from", issue = "111688")] -pub trait ExitCodeExt: Sealed { +pub impl(self) trait ExitCodeExt { /// Creates a new `ExitCode` from the raw underlying `u32` return value of /// a process. /// diff --git a/library/std/src/process.rs b/library/std/src/process.rs index 0b8db439a6370..feead5b135d25 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -256,10 +256,6 @@ pub struct Child { pub stderr: Option, } -/// Allows extension traits within `std`. -#[unstable(feature = "sealed", issue = "none")] -impl crate::sealed::Sealed for Child {} - impl AsInner for Child { #[inline] fn as_inner(&self) -> &imp::Process { @@ -597,10 +593,6 @@ pub struct Command { inner: imp::Command, } -/// Allows extension traits within `std`. -#[unstable(feature = "sealed", issue = "none")] -impl crate::sealed::Sealed for Command {} - impl Command { /// Constructs a new `Command` for launching the program at /// path `program`, with the following default configuration: @@ -1893,10 +1885,6 @@ impl Default for ExitStatus { } } -/// Allows extension traits within `std`. -#[unstable(feature = "sealed", issue = "none")] -impl crate::sealed::Sealed for ExitStatus {} - impl ExitStatus { /// Was termination successful? Returns a `Result`. /// @@ -1999,10 +1987,6 @@ impl fmt::Display for ExitStatus { } } -/// Allows extension traits within `std`. -#[unstable(feature = "sealed", issue = "none")] -impl crate::sealed::Sealed for ExitStatusError {} - /// Describes the result of a process after it has failed /// /// Produced by the [`.exit_ok`](ExitStatus::exit_ok) method on [`ExitStatus`]. @@ -2171,10 +2155,6 @@ impl crate::error::Error for ExitStatusError {} #[stable(feature = "process_exitcode", since = "1.61.0")] pub struct ExitCode(imp::ExitCode); -/// Allows extension traits within `std`. -#[unstable(feature = "sealed", issue = "none")] -impl crate::sealed::Sealed for ExitCode {} - #[stable(feature = "process_exitcode", since = "1.61.0")] impl ExitCode { /// The canonical `ExitCode` for successful termination on this platform. diff --git a/library/std/src/sys/process/unix/unix.rs b/library/std/src/sys/process/unix/unix.rs index d476072a6449f..05eab410bf271 100644 --- a/library/std/src/sys/process/unix/unix.rs +++ b/library/std/src/sys/process/unix/unix.rs @@ -318,7 +318,7 @@ impl Command { // An alternative would be to require CAP_SETGID (in // addition to CAP_SETUID) for setting the UID. if e.raw_os_error() != Some(libc::EPERM) { - return Err(e.into()); + return Err(e); } } } diff --git a/library/std/src/sys/stdio/motor.rs b/library/std/src/sys/stdio/motor.rs index 2b1bc15285f9c..acc30b134d828 100644 --- a/library/std/src/sys/stdio/motor.rs +++ b/library/std/src/sys/stdio/motor.rs @@ -28,8 +28,6 @@ impl Stderr { } } -impl crate::sealed::Sealed for Stdin {} - impl crate::io::IsTerminal for Stdin { fn is_terminal(&self) -> bool { moto_rt::fs::is_terminal(moto_rt::FD_STDIN) diff --git a/src/librustdoc/build.rs b/src/librustdoc/build.rs index 94bb0e30fcdbc..3b887f7d022ec 100644 --- a/src/librustdoc/build.rs +++ b/src/librustdoc/build.rs @@ -55,12 +55,9 @@ fn main() { let minified_path = std::path::PathBuf::from(format!("{out_dir}/{path}.min")); if path.ends_with(".js") || path.ends_with(".css") { let minified: String = if path.ends_with(".css") { - minifier::css::minify(str::from_utf8(&data_bytes).unwrap()) - .unwrap() - .to_string() - .into() + minifier::css::minify(str::from_utf8(&data_bytes).unwrap()).unwrap().to_string() } else { - minifier::js::minify(str::from_utf8(&data_bytes).unwrap()).to_string().into() + minifier::js::minify(str::from_utf8(&data_bytes).unwrap()).to_string() }; std::fs::write(&minified_path, minified.as_bytes()).expect("write to out_dir"); } else { diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index dffdcbb7ef0cf..fe7e12cf1dc80 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -202,7 +202,7 @@ fn clean_param_env<'tcx>( .collect(); let mut generics = clean::Generics { params, where_predicates }; - simplify::sized_bounds(cx, &mut generics); + simplify::sizedness_bounds(cx, &mut generics); generics.where_predicates = simplify::where_clauses(cx.tcx, generics.where_predicates); generics } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 42845124eda50..7442ec99d90eb 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -988,7 +988,7 @@ fn clean_ty_generics_inner<'tcx>( where_predicates.into_iter().flat_map(|p| clean_predicate(*p, cx)).collect(); let mut generics = Generics { params, where_predicates }; - simplify::sized_bounds(cx, &mut generics); + simplify::sizedness_bounds(cx, &mut generics); generics.where_predicates = simplify::where_clauses(cx.tcx, generics.where_predicates); generics } diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index d529f2300e0c6..a5b5660589f29 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -13,7 +13,7 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::thin_vec::ThinVec; -use rustc_data_structures::unord::UnordSet; +use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_middle::ty::{TyCtxt, Unnormalized}; @@ -121,50 +121,72 @@ fn trait_is_same_or_supertrait(tcx: TyCtxt<'_>, child: DefId, trait_: DefId) -> .any(|did| trait_is_same_or_supertrait(tcx, did, trait_)) } -pub(crate) fn sized_bounds(cx: &mut DocContext<'_>, generics: &mut clean::Generics) { - let mut sized_params = UnordSet::new(); +/// Reconstruct all sizedness bounds on non-`Self` type parameters as they appear in the surface +/// language given generics that were cleaned from the middle::ty IR. +/// +/// For example, assuming `T` is a type parameter of the owner of `generics`, +/// `T: Sized` gets dropped and `T: MetaSized` gets rewritten to `T: ?Sized`. +pub(crate) fn sizedness_bounds(cx: &mut DocContext<'_>, generics: &mut clean::Generics) { + #[derive(PartialEq, Eq, PartialOrd, Ord)] + enum Sizedness { + PointeeSized, + MetaSized, + Sized, + } + + let mut type_params: FxIndexMap<_, _> = generics + .params + .iter() + .filter(|param| matches!(param.kind, clean::GenericParamDefKind::Type { .. })) + .map(|param| (param.name, Sizedness::PointeeSized)) + .collect(); - // In the surface language, all type parameters except `Self` have an - // implicit `Sized` bound unless removed with `?Sized`. - // However, in the list of where-predicates below, `Sized` appears like a - // normal bound: It's either present (the type is sized) or - // absent (the type might be unsized) but never *maybe* (i.e. `?Sized`). - // - // This is unsuitable for rendering. - // Thus, as a first step remove all `Sized` bounds that should be implicit. - // - // Note that associated types also have an implicit `Sized` bound but we - // don't actually know the set of associated types right here so that - // should be handled when cleaning associated types. generics.where_predicates.retain(|pred| { let WP::BoundPredicate { ty: clean::Generic(param), bounds, .. } = pred else { return true; }; - if bounds.iter().any(|b| b.is_sized_bound(cx.tcx)) { - sized_params.insert(*param); - false - } else if bounds.iter().any(|b| b.is_meta_sized_bound(cx.tcx)) { - // FIXME(sized-hierarchy): Always skip `MetaSized` bounds so that only `?Sized` - // is shown and none of the new sizedness traits leak into documentation. - false - } else { - true + // We require the caller to pass generics that were cleaned from the middle::ty IR. + // We know that that cleaning process never generates more than one bound per predicate. + let [bound] = &*bounds else { unreachable!() }; + + let clean::GenericBound::TraitBound(trait_ref, hir::TraitBoundModifiers::NONE) = bound + else { + return true; + }; + + // This transformation is only valid on type parameters defined on the closest item. + // If the parameter was defined by the parent item we know that the sizedness bound + // *has* to be user-written in which case we have to preserve it as is. + let Some(param_sizedness) = type_params.get_mut(param) else { return true }; + + let sizedness = match cx.tcx.as_lang_item(trait_ref.trait_.def_id()) { + Some(hir::LangItem::Sized) => Sizedness::Sized, + Some(hir::LangItem::MetaSized) => Sizedness::MetaSized, + _ => return true, + }; + + if sizedness > *param_sizedness { + *param_sizedness = sizedness; } + + false }); - // As a final step, go through the type parameters again and insert a - // `?Sized` bound for each one we didn't find to be `Sized`. - for param in &generics.params { - if let clean::GenericParamDefKind::Type { .. } = param.kind - && !sized_params.contains(¶m.name) - { - generics.where_predicates.push(WP::BoundPredicate { - ty: clean::Type::Generic(param.name), - bounds: vec![clean::GenericBound::maybe_sized(cx)], - bound_params: Vec::new(), - }) - } + for (param, sizedness) in type_params { + generics.where_predicates.push(WP::BoundPredicate { + ty: clean::Type::Generic(param), + bounds: vec![match sizedness { + // FIXME(sized-hierarchy, #157247): Actually render `MetaSized` as `MetaSized` and + // `PointeeSized` as `PointeeSized` instead of `?Sized` if the crate enables + // `sized_hierarchy` and doesn't set `#![doc(dont_leak…)]`. + Sizedness::MetaSized | Sizedness::PointeeSized => { + clean::GenericBound::maybe_sized(cx) + } + Sizedness::Sized => continue, + }], + bound_params: Vec::new(), + }); } } diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 2f992c622c496..9c757cf857925 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1201,11 +1201,8 @@ impl GenericBound { } fn is_bounded_by_lang_item(&self, tcx: TyCtxt<'_>, lang_item: LangItem) -> bool { - if let GenericBound::TraitBound( - PolyTrait { ref trait_, .. }, - rustc_hir::TraitBoundModifiers::NONE, - ) = *self - && tcx.is_lang_item(trait_.def_id(), lang_item) + if let GenericBound::TraitBound(poly_trait_ref, rustc_hir::TraitBoundModifiers::NONE) = self + && tcx.is_lang_item(poly_trait_ref.trait_.def_id(), lang_item) { return true; } @@ -1213,8 +1210,8 @@ impl GenericBound { } pub(crate) fn get_trait_path(&self) -> Option { - if let GenericBound::TraitBound(PolyTrait { ref trait_, .. }, _) = *self { - Some(trait_.clone()) + if let GenericBound::TraitBound(poly_trait_ref, _) = self { + Some(poly_trait_ref.trait_.clone()) } else { None } diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index f0a812b97d04f..da34deeefb197 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -731,7 +731,8 @@ ul.block, .block li, .block ul { } .block ul a { - padding-left: 1rem; + /* extend click target to far edge of screen (mile wide bar) */ + padding-left: calc(1rem + var(--sidebar-elems-left-padding)); } .sidebar-elems a, @@ -740,7 +741,7 @@ ul.block, .block li, .block ul { padding: 0.25rem; /* 4px */ margin-right: 0.25rem; /* extend click target to far edge of screen (mile wide bar) */ - border-left: solid var(--sidebar-elems-left-padding) transparent; + padding-left: calc(0.25rem + var(--sidebar-elems-left-padding)); margin-left: calc(-0.25rem - var(--sidebar-elems-left-padding)); background-clip: border-box; } @@ -861,7 +862,7 @@ ul.block, .block li, .block ul { | └─────┘ */ margin-top: -16px; - border-top: solid 16px transparent; + padding-top: 16px; box-sizing: content-box; position: relative; background-clip: border-box; @@ -870,8 +871,6 @@ ul.block, .block li, .block ul { .sidebar-crate h2 a { display: block; - /* extend click target to far edge of screen (mile wide bar) */ - border-left: solid var(--sidebar-elems-left-padding) transparent; background-clip: border-box; margin: 0 calc(-24px + 0.25rem) 0 calc(-0.2rem - var(--sidebar-elems-left-padding)); /* Align the sidebar crate link with the search bar, which have different @@ -888,7 +887,8 @@ ul.block, .block li, .block ul { x = ( 16px - 0.57rem ) / 2 */ padding: calc( ( 16px - 0.57rem ) / 2 ) 0.25rem; - padding-left: 0.2rem; + /* extend click target to far edge of screen (mile wide bar) */ + padding-left: calc(0.2rem + var(--sidebar-elems-left-padding)); } .sidebar-crate h2 .version { diff --git a/tests/rustdoc-gui/huge-logo.goml b/tests/rustdoc-gui/huge-logo.goml index 6ad6948ef2ab1..7bffbc16596c3 100644 --- a/tests/rustdoc-gui/huge-logo.goml +++ b/tests/rustdoc-gui/huge-logo.goml @@ -7,4 +7,4 @@ set-window-size: (1280, 1024) assert-property: (".sidebar-crate .logo-container", {"offsetWidth": "96", "offsetHeight": 48}) // offsetWidth = width of sidebar, offsetHeight = height + top padding assert-property: (".sidebar-crate .logo-container img", {"offsetWidth": "48", "offsetHeight": 64}) -assert-css: (".sidebar-crate .logo-container img", {"border-top-width": "16px", "margin-top": "-16px"}) +assert-css: (".sidebar-crate .logo-container img", {"padding-top": "16px", "margin-top": "-16px"}) diff --git a/tests/rustdoc-html/inline_cross/auxiliary/ext-sized-bounds.rs b/tests/rustdoc-html/inline_cross/auxiliary/ext-sized-bounds.rs new file mode 100644 index 0000000000000..c3a8305e12288 --- /dev/null +++ b/tests/rustdoc-html/inline_cross/auxiliary/ext-sized-bounds.rs @@ -0,0 +1,18 @@ +pub fn sized_param() {} + +pub fn relaxed_sized_on_param() {} + +pub trait SizedOnParentParam { + fn func() where T: Sized; +} + +pub trait SizedSelf: Sized {} + +pub trait SizedOnParentSelf { + fn func(self) -> Self + where + Self: Sized + { + self + } +} diff --git a/tests/rustdoc-html/inline_cross/auxiliary/issue-24183.rs b/tests/rustdoc-html/inline_cross/auxiliary/issue-24183.rs deleted file mode 100644 index e7a13acc6f864..0000000000000 --- a/tests/rustdoc-html/inline_cross/auxiliary/issue-24183.rs +++ /dev/null @@ -1,14 +0,0 @@ -#![crate_type = "lib"] - -pub trait U/*: ?Sized */ { - fn modified(self) -> Self - where - Self: Sized - { - self - } - - fn touch(&self)/* where Self: ?Sized */{} -} - -pub trait S: Sized {} diff --git a/tests/rustdoc-html/inline_cross/self-sized-bounds-24183.method_no_where_self_sized.html b/tests/rustdoc-html/inline_cross/self-sized-bounds-24183.method_no_where_self_sized.html deleted file mode 100644 index f3c1c045202b0..0000000000000 --- a/tests/rustdoc-html/inline_cross/self-sized-bounds-24183.method_no_where_self_sized.html +++ /dev/null @@ -1 +0,0 @@ -

fn touch(&self)

\ No newline at end of file diff --git a/tests/rustdoc-html/inline_cross/self-sized-bounds-24183.rs b/tests/rustdoc-html/inline_cross/self-sized-bounds-24183.rs deleted file mode 100644 index 909005532f505..0000000000000 --- a/tests/rustdoc-html/inline_cross/self-sized-bounds-24183.rs +++ /dev/null @@ -1,19 +0,0 @@ -// https://github.com/rust-lang/rust/issues/24183 -#![crate_type = "lib"] -#![crate_name = "usr"] - -//@ aux-crate:issue_24183=issue-24183.rs -//@ edition: 2021 - -//@ has usr/trait.U.html -//@ has - '//*[@class="rust item-decl"]' "pub trait U {" -//@ has - '//*[@id="method.modified"]' \ -// "fn modified(self) -> Self\ -// where \ -// Self: Sized" -//@ snapshot method_no_where_self_sized - '//*[@id="method.touch"]/*[@class="code-header"]' -pub use issue_24183::U; - -//@ has usr/trait.S.html -//@ has - '//*[@class="rust item-decl"]' 'pub trait S: Sized {' -pub use issue_24183::S; diff --git a/tests/rustdoc-html/inline_cross/sized-bounds.rs b/tests/rustdoc-html/inline_cross/sized-bounds.rs new file mode 100644 index 0000000000000..ac980897b7e66 --- /dev/null +++ b/tests/rustdoc-html/inline_cross/sized-bounds.rs @@ -0,0 +1,57 @@ +// Check that we properly reconstruct sized bounds from the middle::ty IR to the surface syntax. + +#![crate_name = "it"] +//@ aux-build: ext-sized-bounds.rs +extern crate ext_sized_bounds as ext; + +// Ensure that we translate [] to ``. +// Non-`Self` type params are implicitly `Sized`, so we can hide it. +// +//@ has it/fn.sized_param.html +//@ has - '//pre[@class="rust item-decl"]' "fn sized_param()" +//@ !has - '//pre[@class="rust item-decl"]' "T: Sized" +pub use ext::sized_param; + +// Ensure that we translate [] to `T: ?Sized`. +// On stable, the user must've opted out of the implicit `Sized` bound using relaxed bound `?Sized` +// which will implicitly add the `MetaSized` bound (which is unstable in the surface language). +// +//@ has it/fn.relaxed_sized_on_param.html +//@ has - '//pre[@class="rust item-decl"]' "fn relaxed_sized_on_param()where T: ?Sized" +pub use ext::relaxed_sized_on_param; + +// Ensure that we don't drop the `T: Sized` bound on `func`. Previously, we didn't check if `T` +// actually belongs to the closest item and thought that it was an implicit bound which it isn't. +// issue: +// +//@ has it/trait.SizedOnParentParam.html +//@ has - '//*[@class="rust item-decl"]' \ +// "trait SizedOnParentParam\ +// where \ +// T: ?Sized" +//@ has - '//*[@id="tymethod.func"]' \ +// "fn func()\ +// where \ +// T: Sized" +pub use ext::SizedOnParentParam; + +// Ensure that we don't drop the `Self: Sized` bound on traits. +// Traits are *not* implicitly bounded by `Sized`. They're only implicitly bounded by `MetaSized`. +// +//@ has it/trait.SizedSelf.html +//@ has - '//*[@class="rust item-decl"]' 'trait SizedSelf: Sized {' +pub use ext::SizedSelf; + +// Ensure that we don't drop the `Self: Sized` bound. +// First of all, `Self` type params of traits are not implicitly bounded by `Self`. +// Second of all, `Self` appears in a bound on an assoc item but `Self` belongs to the parent item, +// the trait meaning it's definitely user-written and not implicit. +// issue: +// +//@ has it/trait.SizedOnParentSelf.html +//@ has - '//*[@class="rust item-decl"]' "trait SizedOnParentSelf {" +//@ has - '//*[@id="method.func"]' \ +// "fn func(self) -> Self\ +// where \ +// Self: Sized" +pub use ext::SizedOnParentSelf; diff --git a/tests/ui/asm/naked-invalid-attr.stderr b/tests/ui/asm/naked-invalid-attr.stderr index 9962cbafc37f6..70c7168a8c960 100644 --- a/tests/ui/asm/naked-invalid-attr.stderr +++ b/tests/ui/asm/naked-invalid-attr.stderr @@ -18,7 +18,7 @@ error: `#[naked]` attribute cannot be used on foreign functions LL | #[unsafe(naked)] | ^^^^^^^^^^^^^^^^ | - = help: `#[naked]` can be applied to functions and methods + = help: `#[naked]` can only be applied to functions with a body error: `#[naked]` attribute cannot be used on structs --> $DIR/naked-invalid-attr.rs:14:1 @@ -42,7 +42,7 @@ error: `#[naked]` attribute cannot be used on required trait methods LL | #[unsafe(naked)] | ^^^^^^^^^^^^^^^^ | - = help: `#[naked]` can be applied to functions, inherent methods, provided trait methods, and trait methods in impl blocks + = help: `#[naked]` can only be applied to functions with a body error: `#[naked]` attribute cannot be used on closures --> $DIR/naked-invalid-attr.rs:52:5 diff --git a/tests/ui/attributes/attr-on-mac-call.rs b/tests/ui/attributes/attr-on-mac-call.rs index 67eca68c0dd29..182e9935de25f 100644 --- a/tests/ui/attributes/attr-on-mac-call.rs +++ b/tests/ui/attributes/attr-on-mac-call.rs @@ -1,6 +1,7 @@ -//@ check-pass +//@ check-fail // Regression test for https://github.com/rust-lang/rust/issues/145779 #![warn(unused_attributes)] +#![feature(sanitize)] fn main() { #[export_name = "x"] @@ -72,6 +73,8 @@ fn main() { #[link_name = "x"] //~^ WARN attribute cannot be used on macro calls //~| WARN previously accepted + #[sanitize(address = "off")] + //~^ ERROR attribute cannot be used on macro calls unreachable!(); #[repr()] diff --git a/tests/ui/attributes/attr-on-mac-call.stderr b/tests/ui/attributes/attr-on-mac-call.stderr index 26e3cd870e132..cafa43b6f0a1a 100644 --- a/tests/ui/attributes/attr-on-mac-call.stderr +++ b/tests/ui/attributes/attr-on-mac-call.stderr @@ -1,5 +1,13 @@ +error: `#[sanitize]` attribute cannot be used on macro calls + --> $DIR/attr-on-mac-call.rs:76:5 + | +LL | #[sanitize(address = "off")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: `#[sanitize]` can be applied to crates, functions, impl blocks, modules, and statics + warning: `#[export_name]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:6:5 + --> $DIR/attr-on-mac-call.rs:7:5 | LL | #[export_name = "x"] | ^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +21,7 @@ LL | #![warn(unused_attributes)] | ^^^^^^^^^^^^^^^^^ warning: `#[naked]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:9:5 + --> $DIR/attr-on-mac-call.rs:10:5 | LL | #[unsafe(naked)] | ^^^^^^^^^^^^^^^^ @@ -22,7 +30,7 @@ LL | #[unsafe(naked)] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[track_caller]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:12:5 + --> $DIR/attr-on-mac-call.rs:13:5 | LL | #[track_caller] | ^^^^^^^^^^^^^^^ @@ -31,7 +39,7 @@ LL | #[track_caller] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[used]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:15:5 + --> $DIR/attr-on-mac-call.rs:16:5 | LL | #[used] | ^^^^^^^ @@ -40,7 +48,7 @@ LL | #[used] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[target_feature]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:18:5 + --> $DIR/attr-on-mac-call.rs:19:5 | LL | #[target_feature(enable = "x")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -49,7 +57,7 @@ LL | #[target_feature(enable = "x")] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[deprecated]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:21:5 + --> $DIR/attr-on-mac-call.rs:22:5 | LL | #[deprecated] | ^^^^^^^^^^^^^ @@ -58,7 +66,7 @@ LL | #[deprecated] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[inline]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:24:5 + --> $DIR/attr-on-mac-call.rs:25:5 | LL | #[inline] | ^^^^^^^^^ @@ -67,7 +75,7 @@ LL | #[inline] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[link_name]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:27:5 + --> $DIR/attr-on-mac-call.rs:28:5 | LL | #[link_name = "x"] | ^^^^^^^^^^^^^^^^^^ @@ -76,7 +84,7 @@ LL | #[link_name = "x"] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[link_section]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:30:5 + --> $DIR/attr-on-mac-call.rs:31:5 | LL | #[link_section = "__TEXT,__text"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +93,7 @@ LL | #[link_section = "__TEXT,__text"] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[link_ordinal]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:33:5 + --> $DIR/attr-on-mac-call.rs:34:5 | LL | #[link_ordinal(42)] | ^^^^^^^^^^^^^^^^^^^ @@ -94,7 +102,7 @@ LL | #[link_ordinal(42)] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[non_exhaustive]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:36:5 + --> $DIR/attr-on-mac-call.rs:37:5 | LL | #[non_exhaustive] | ^^^^^^^^^^^^^^^^^ @@ -103,7 +111,7 @@ LL | #[non_exhaustive] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[proc_macro]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:39:5 + --> $DIR/attr-on-mac-call.rs:40:5 | LL | #[proc_macro] | ^^^^^^^^^^^^^ @@ -112,7 +120,7 @@ LL | #[proc_macro] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[cold]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:42:5 + --> $DIR/attr-on-mac-call.rs:43:5 | LL | #[cold] | ^^^^^^^ @@ -121,7 +129,7 @@ LL | #[cold] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[no_mangle]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:45:5 + --> $DIR/attr-on-mac-call.rs:46:5 | LL | #[no_mangle] | ^^^^^^^^^^^^ @@ -130,7 +138,7 @@ LL | #[no_mangle] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[deprecated]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:48:5 + --> $DIR/attr-on-mac-call.rs:49:5 | LL | #[deprecated] | ^^^^^^^^^^^^^ @@ -139,7 +147,7 @@ LL | #[deprecated] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[automatically_derived]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:51:5 + --> $DIR/attr-on-mac-call.rs:52:5 | LL | #[automatically_derived] | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -148,7 +156,7 @@ LL | #[automatically_derived] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[macro_use]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:54:5 + --> $DIR/attr-on-mac-call.rs:55:5 | LL | #[macro_use] | ^^^^^^^^^^^^ @@ -157,7 +165,7 @@ LL | #[macro_use] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[must_use]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:57:5 + --> $DIR/attr-on-mac-call.rs:58:5 | LL | #[must_use] | ^^^^^^^^^^^ @@ -166,7 +174,7 @@ LL | #[must_use] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[no_implicit_prelude]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:60:5 + --> $DIR/attr-on-mac-call.rs:61:5 | LL | #[no_implicit_prelude] | ^^^^^^^^^^^^^^^^^^^^^^ @@ -175,7 +183,7 @@ LL | #[no_implicit_prelude] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[path]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:63:5 + --> $DIR/attr-on-mac-call.rs:64:5 | LL | #[path = ""] | ^^^^^^^^^^^^ @@ -184,7 +192,7 @@ LL | #[path = ""] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[ignore]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:66:5 + --> $DIR/attr-on-mac-call.rs:67:5 | LL | #[ignore] | ^^^^^^^^^ @@ -193,7 +201,7 @@ LL | #[ignore] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[should_panic]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:69:5 + --> $DIR/attr-on-mac-call.rs:70:5 | LL | #[should_panic] | ^^^^^^^^^^^^^^^ @@ -202,7 +210,7 @@ LL | #[should_panic] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[link_name]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:72:5 + --> $DIR/attr-on-mac-call.rs:73:5 | LL | #[link_name = "x"] | ^^^^^^^^^^^^^^^^^^ @@ -211,7 +219,7 @@ LL | #[link_name = "x"] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[repr()]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:77:5 + --> $DIR/attr-on-mac-call.rs:80:5 | LL | #[repr()] | ^^^^^^^^^ @@ -220,7 +228,7 @@ LL | #[repr()] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: unused attribute - --> $DIR/attr-on-mac-call.rs:77:5 + --> $DIR/attr-on-mac-call.rs:80:5 | LL | #[repr()] | ^^^^^^^^^ help: remove this attribute @@ -228,7 +236,7 @@ LL | #[repr()] = note: using `repr` with an empty list has no effect warning: `#[repr(u8)]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:82:5 + --> $DIR/attr-on-mac-call.rs:85:5 | LL | #[repr(u8)] | ^^^^^^^^^^^ @@ -237,7 +245,7 @@ LL | #[repr(u8)] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[repr(align(...))]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:86:5 + --> $DIR/attr-on-mac-call.rs:89:5 | LL | #[repr(align(8))] | ^^^^^^^^^^^^^^^^^ @@ -246,7 +254,7 @@ LL | #[repr(align(8))] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[repr(packed)]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:90:5 + --> $DIR/attr-on-mac-call.rs:93:5 | LL | #[repr(packed)] | ^^^^^^^^^^^^^^^ @@ -255,7 +263,7 @@ LL | #[repr(packed)] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[repr(C)]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:94:5 + --> $DIR/attr-on-mac-call.rs:97:5 | LL | #[repr(C)] | ^^^^^^^^^^ @@ -264,7 +272,7 @@ LL | #[repr(C)] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[repr(Rust)]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:98:5 + --> $DIR/attr-on-mac-call.rs:101:5 | LL | #[repr(Rust)] | ^^^^^^^^^^^^^ @@ -273,7 +281,7 @@ LL | #[repr(Rust)] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[repr(simd)]` attribute cannot be used on macro calls - --> $DIR/attr-on-mac-call.rs:102:5 + --> $DIR/attr-on-mac-call.rs:105:5 | LL | #[repr(simd)] | ^^^^^^^^^^^^^ @@ -281,5 +289,5 @@ LL | #[repr(simd)] = help: `#[repr(simd)]` can only be applied to structs = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! -warning: 31 warnings emitted +error: aborting due to 1 previous error; 31 warnings emitted diff --git a/tests/ui/attributes/codegen_attr_on_required_trait_method.stderr b/tests/ui/attributes/codegen_attr_on_required_trait_method.stderr index 8d0ded5427ad8..7f0b0f0327e4e 100644 --- a/tests/ui/attributes/codegen_attr_on_required_trait_method.stderr +++ b/tests/ui/attributes/codegen_attr_on_required_trait_method.stderr @@ -4,7 +4,7 @@ error: `#[cold]` attribute cannot be used on required trait methods LL | #[cold] | ^^^^^^^ | - = help: `#[cold]` can be applied to closures, foreign functions, functions, inherent methods, provided trait methods, and trait methods in impl blocks + = help: `#[cold]` can be applied to foreign functions and functions with a body = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! note: the lint level is defined here --> $DIR/codegen_attr_on_required_trait_method.rs:1:9 @@ -18,7 +18,7 @@ error: `#[link_section]` attribute cannot be used on required trait methods LL | #[link_section = "__TEXT,__text"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: `#[link_section]` can be applied to functions, inherent methods, provided trait methods, statics, and trait methods in impl blocks + = help: `#[link_section]` can be applied to functions with a body and statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! error: `#[linkage]` attribute cannot be used on required trait methods @@ -27,7 +27,7 @@ error: `#[linkage]` attribute cannot be used on required trait methods LL | #[linkage = "common"] | ^^^^^^^^^^^^^^^^^^^^^ | - = help: `#[linkage]` can be applied to foreign functions, foreign statics, functions, inherent methods, provided trait methods, statics, and trait methods in impl blocks + = help: `#[linkage]` can be applied to foreign functions, foreign statics, functions with a body, and statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! error: aborting due to 3 previous errors diff --git a/tests/ui/coverage-attr/allowed-positions.stderr b/tests/ui/coverage-attr/allowed-positions.stderr index 09d6bac497d21..ae7e1d2fea980 100644 --- a/tests/ui/coverage-attr/allowed-positions.stderr +++ b/tests/ui/coverage-attr/allowed-positions.stderr @@ -46,7 +46,7 @@ error: `#[coverage]` attribute cannot be used on required trait methods LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ | - = help: `#[coverage]` can be applied to closures, crates, functions, impl blocks, inherent methods, modules, provided trait methods, and trait methods in impl blocks + = help: `#[coverage]` can be applied to crates, functions with a body, impl blocks, and modules error: `#[coverage]` attribute cannot be used on required trait methods --> $DIR/allowed-positions.rs:31:5 @@ -54,7 +54,7 @@ error: `#[coverage]` attribute cannot be used on required trait methods LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ | - = help: `#[coverage]` can be applied to closures, crates, functions, impl blocks, inherent methods, modules, provided trait methods, and trait methods in impl blocks + = help: `#[coverage]` can be applied to crates, functions with a body, impl blocks, and modules error: `#[coverage]` attribute cannot be used on associated types --> $DIR/allowed-positions.rs:39:5 @@ -110,7 +110,7 @@ error: `#[coverage]` attribute cannot be used on foreign functions LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ | - = help: `#[coverage]` can be applied to closures, crates, functions, impl blocks, methods, and modules + = help: `#[coverage]` can be applied to crates, functions with a body, impl blocks, and modules error: `#[coverage]` attribute cannot be used on statements --> $DIR/allowed-positions.rs:88:5 diff --git a/tests/ui/derives/coercepointee/auxiliary/another-proc-macro.rs b/tests/ui/derives/coercepointee/auxiliary/another-proc-macro.rs index 47f3c5b9c4b05..1f0e710ea24ec 100644 --- a/tests/ui/derives/coercepointee/auxiliary/another-proc-macro.rs +++ b/tests/ui/derives/coercepointee/auxiliary/another-proc-macro.rs @@ -11,7 +11,6 @@ pub fn derive(_input: TokenStream) -> TokenStream { const ANOTHER_MACRO_DERIVED: () = (); }; } - .into() } #[proc_macro_attribute] @@ -24,7 +23,6 @@ pub fn pointee( const POINTEE_MACRO_ATTR_DERIVED: () = (); }; } - .into() } #[proc_macro_attribute] @@ -37,5 +35,4 @@ pub fn default( const DEFAULT_MACRO_ATTR_DERIVED: () = (); }; } - .into() } diff --git a/tests/ui/extern/extern-no-mangle.stderr b/tests/ui/extern/extern-no-mangle.stderr index 62518fa8d0d97..15ed08123dab7 100644 --- a/tests/ui/extern/extern-no-mangle.stderr +++ b/tests/ui/extern/extern-no-mangle.stderr @@ -18,7 +18,7 @@ warning: `#[no_mangle]` attribute cannot be used on foreign functions LL | #[no_mangle] | ^^^^^^^^^^^^ | - = help: `#[no_mangle]` can be applied to functions, methods, and statics + = help: `#[no_mangle]` can be applied to functions with a body and statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[no_mangle]` attribute cannot be used on statements diff --git a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr index 7d252af4f94fe..da8c9095a8163 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr +++ b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr @@ -206,7 +206,7 @@ error: `#[export_name]` attribute cannot be used on required trait methods LL | #[export_name = "2200"] fn foo(); | ^^^^^^^^^^^^^^^^^^^^^^^ | - = help: `#[export_name]` can be applied to functions, inherent methods, provided trait methods, statics, and trait methods in impl blocks + = help: `#[export_name]` can be applied to functions with a body and statics error: `#[repr(C)]` attribute cannot be used on modules --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:121:1 diff --git a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr index 816969df09dfb..14d1ed6c8173b 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr +++ b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr @@ -447,7 +447,7 @@ warning: `#[no_mangle]` attribute cannot be used on required trait methods LL | #[no_mangle] fn foo(); | ^^^^^^^^^^^^ | - = help: `#[no_mangle]` can be applied to functions, inherent methods, statics, and trait methods in impl blocks + = help: `#[no_mangle]` can be applied to functions with a body and statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[no_mangle]` attribute cannot be used on provided trait methods @@ -859,7 +859,7 @@ warning: `#[link_section]` attribute cannot be used on required trait methods LL | #[link_section = ",1800"] | ^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: `#[link_section]` can be applied to functions, inherent methods, provided trait methods, statics, and trait methods in impl blocks + = help: `#[link_section]` can be applied to functions with a body and statics = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: `#[link]` attribute cannot be used on modules diff --git a/tests/ui/force-inlining/invalid.stderr b/tests/ui/force-inlining/invalid.stderr index ce4f1d77ad2d2..3b9975e19a1b1 100644 --- a/tests/ui/force-inlining/invalid.stderr +++ b/tests/ui/force-inlining/invalid.stderr @@ -134,7 +134,7 @@ error: `#[rustc_force_inline]` attribute cannot be used on foreign functions LL | #[rustc_force_inline] | ^^^^^^^^^^^^^^^^^^^^^ | - = help: `#[rustc_force_inline]` can be applied to functions and inherent methods + = help: `#[rustc_force_inline]` can only be applied to functions with a body error: `#[rustc_force_inline]` attribute cannot be used on type aliases --> $DIR/invalid.rs:66:1 diff --git a/tests/ui/lint/warn-unused-inline-on-fn-prototypes.stderr b/tests/ui/lint/warn-unused-inline-on-fn-prototypes.stderr index 9b625172a7590..d3cad7c0c4775 100644 --- a/tests/ui/lint/warn-unused-inline-on-fn-prototypes.stderr +++ b/tests/ui/lint/warn-unused-inline-on-fn-prototypes.stderr @@ -4,7 +4,7 @@ error: `#[inline]` attribute cannot be used on required trait methods LL | #[inline] | ^^^^^^^^^ | - = help: `#[inline]` can be applied to closures, functions, inherent methods, provided trait methods, and trait methods in impl blocks + = help: `#[inline]` can only be applied to functions with a body = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! note: the lint level is defined here --> $DIR/warn-unused-inline-on-fn-prototypes.rs:1:9 @@ -18,7 +18,7 @@ error: `#[inline]` attribute cannot be used on foreign functions LL | #[inline] | ^^^^^^^^^ | - = help: `#[inline]` can be applied to closures, functions, and methods + = help: `#[inline]` can only be applied to functions with a body = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! error: aborting due to 2 previous errors diff --git a/tests/ui/privacy/sealed-traits/auxiliary/private-trait-non-local-aux.rs b/tests/ui/privacy/sealed-traits/auxiliary/private-trait-non-local-aux.rs new file mode 100644 index 0000000000000..1a0b98dc5164c --- /dev/null +++ b/tests/ui/privacy/sealed-traits/auxiliary/private-trait-non-local-aux.rs @@ -0,0 +1,5 @@ +pub mod a { + mod b { + pub trait Sealed {} + } +} diff --git a/tests/ui/privacy/sealed-traits/private-trait-non-local.rs b/tests/ui/privacy/sealed-traits/private-trait-non-local.rs index 426f21cc7de2d..80d0b75d3da36 100644 --- a/tests/ui/privacy/sealed-traits/private-trait-non-local.rs +++ b/tests/ui/privacy/sealed-traits/private-trait-non-local.rs @@ -1,4 +1,6 @@ -extern crate core; -use core::slice::index::private_slice_index::Sealed; //~ ERROR module `index` is private -fn main() { -} +//@ aux-build: private-trait-non-local-aux.rs + +extern crate private_trait_non_local_aux as aux; +use aux::a::b::Sealed; //~ ERROR module `b` is private + +fn main() {} diff --git a/tests/ui/privacy/sealed-traits/private-trait-non-local.stderr b/tests/ui/privacy/sealed-traits/private-trait-non-local.stderr index e6b76322f9641..4f8cbacf02bed 100644 --- a/tests/ui/privacy/sealed-traits/private-trait-non-local.stderr +++ b/tests/ui/privacy/sealed-traits/private-trait-non-local.stderr @@ -1,11 +1,16 @@ -error[E0603]: module `index` is private - --> $DIR/private-trait-non-local.rs:2:18 +error[E0603]: module `b` is private + --> $DIR/private-trait-non-local.rs:4:13 | -LL | use core::slice::index::private_slice_index::Sealed; - | ^^^^^ private module ------ trait `Sealed` is not publicly re-exported +LL | use aux::a::b::Sealed; + | ^ ------ trait `Sealed` is not publicly re-exported + | | + | private module | -note: the module `index` is defined here - --> $SRC_DIR/core/src/slice/mod.rs:LL:COL +note: the module `b` is defined here + --> $DIR/auxiliary/private-trait-non-local-aux.rs:2:5 + | +LL | mod b { + | ^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/process/process-panic-after-fork.rs b/tests/ui/process/process-panic-after-fork.rs index 4632d3b61f7bf..f3b56721419cd 100644 --- a/tests/ui/process/process-panic-after-fork.rs +++ b/tests/ui/process/process-panic-after-fork.rs @@ -142,7 +142,7 @@ fn main() { let mut status: c_int = 0; let got = unsafe { libc::waitpid(child, &mut status, 0) }; assert_eq!(got, child); - let status = ExitStatus::from_raw(status.into()); + let status = ExitStatus::from_raw(status); status } diff --git a/tests/ui/resolve/proc_macro_generated_packed.rs b/tests/ui/resolve/proc_macro_generated_packed.rs index e35f50911663c..a8175895af04b 100644 --- a/tests/ui/resolve/proc_macro_generated_packed.rs +++ b/tests/ui/resolve/proc_macro_generated_packed.rs @@ -1,6 +1,6 @@ //! This test ICEs because the `repr(packed)` attribute //! was generated by a proc macro, so `#[derive]` didn't see it. -//@ ignore-parallel-frontend failed to collect active jobs + //@proc-macro: proc_macro_generate_packed.rs //@known-bug: #120873 //@ failure-status: 101 diff --git a/tests/ui/sanitize-attr/valid-sanitize.rs b/tests/ui/sanitize-attr/valid-sanitize.rs index ebe76fcba0442..56167a0070e97 100644 --- a/tests/ui/sanitize-attr/valid-sanitize.rs +++ b/tests/ui/sanitize-attr/valid-sanitize.rs @@ -12,27 +12,27 @@ mod submod {} #[sanitize(address = "off")] static FOO: u32 = 0; -#[sanitize(thread = "off")] //~ ERROR sanitize attribute not allowed here +#[sanitize(thread = "off")] //~ ERROR attribute cannot be used on static BAR: u32 = 0; -#[sanitize(address = "off")] //~ ERROR sanitize attribute not allowed here +#[sanitize(address = "off")] //~ ERROR attribute cannot be used on type MyTypeAlias = (); -#[sanitize(address = "off")] //~ ERROR sanitize attribute not allowed here +#[sanitize(address = "off")] //~ ERROR attribute cannot be used on trait MyTrait { - #[sanitize(address = "off")] //~ ERROR sanitize attribute not allowed here + #[sanitize(address = "off")] //~ ERROR attribute cannot be used on const TRAIT_ASSOC_CONST: u32; - #[sanitize(address = "off")] //~ ERROR sanitize attribute not allowed here + #[sanitize(address = "off")] //~ ERROR attribute cannot be used on type TraitAssocType; - #[sanitize(address = "off")] //~ ERROR sanitize attribute not allowed here + #[sanitize(address = "off")] //~ ERROR attribute cannot be used on fn trait_method(&self); #[sanitize(address = "off", thread = "on")] fn trait_method_with_default(&self) {} - #[sanitize(address = "off")] //~ ERROR sanitize attribute not allowed here + #[sanitize(address = "off")] //~ ERROR attribute cannot be used on fn trait_assoc_fn(); } @@ -40,7 +40,7 @@ trait MyTrait { impl MyTrait for () { const TRAIT_ASSOC_CONST: u32 = 0; - #[sanitize(address = "off")] //~ ERROR sanitize attribute not allowed here + #[sanitize(address = "off")] //~ ERROR attribute cannot be used on type TraitAssocType = Self; #[sanitize(address = "off", thread = "on")] @@ -57,14 +57,14 @@ trait HasAssocType { } impl HasAssocType for () { - #[sanitize(address = "off")] //~ ERROR sanitize attribute not allowed here + #[sanitize(address = "off")] //~ ERROR attribute cannot be used on type T = impl Copy; fn constrain_assoc_type() -> Self::T {} } -#[sanitize(address = "off")] //~ ERROR sanitize attribute not allowed here +#[sanitize(address = "off")] //~ ERROR attribute cannot be used on struct MyStruct { - #[sanitize(address = "off")] //~ ERROR sanitize attribute not allowed here + #[sanitize(address = "off")] //~ ERROR attribute cannot be used on field: u32, } @@ -77,25 +77,25 @@ impl MyStruct { } extern "C" { - #[sanitize(address = "off", thread = "on")] //~ ERROR sanitize attribute not allowed here + #[sanitize(address = "off", thread = "on")] //~ ERROR attribute cannot be used on static X: u32; - #[sanitize(address = "off", thread = "on")] //~ ERROR sanitize attribute not allowed here + #[sanitize(address = "off", thread = "on")] //~ ERROR attribute cannot be used on type T; - #[sanitize(address = "off", thread = "on")] //~ ERROR sanitize attribute not allowed here + #[sanitize(address = "off", thread = "on")] //~ ERROR attribute cannot be used on fn foreign_fn(); } #[sanitize(address = "off", thread = "on")] fn main() { - #[sanitize(address = "off", thread = "on")] //~ ERROR sanitize attribute not allowed here + #[sanitize(address = "off", thread = "on")] //~ ERROR attribute cannot be used on let _ = (); // Currently not allowed on let statements, even if they bind to a closure. // It might be nice to support this as a special case someday, but trying // to define the precise boundaries of that special case might be tricky. - #[sanitize(address = "off")] //~ ERROR sanitize attribute not allowed here + #[sanitize(address = "off")] //~ ERROR attribute cannot be used on let _let_closure = || (); // In situations where attributes can already be applied to expressions, @@ -106,10 +106,10 @@ fn main() { }; match () { - #[sanitize(address = "off")] //~ ERROR sanitize attribute not allowed here + #[sanitize(address = "off")] //~ ERROR attribute cannot be used on () => (), } - #[sanitize(address = "off")] //~ ERROR sanitize attribute not allowed here + #[sanitize(address = "off")] //~ ERROR attribute cannot be used on return (); } diff --git a/tests/ui/sanitize-attr/valid-sanitize.stderr b/tests/ui/sanitize-attr/valid-sanitize.stderr index ff9fe63eaf558..e1d6c0e187fdc 100644 --- a/tests/ui/sanitize-attr/valid-sanitize.stderr +++ b/tests/ui/sanitize-attr/valid-sanitize.stderr @@ -1,190 +1,146 @@ -error: sanitize attribute not allowed here +error: `#[sanitize(thread = ...)]` attribute cannot be used on statics --> $DIR/valid-sanitize.rs:15:1 | LL | #[sanitize(thread = "off")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | static BAR: u32 = 0; - | -------------------- not a function, impl block, or module | - = help: sanitize attribute can be applied to a function (with body), impl block, or module + = help: `#[sanitize]` can be used on statics if only the address is sanitized -error: sanitize attribute not allowed here +error: `#[sanitize]` attribute cannot be used on type aliases --> $DIR/valid-sanitize.rs:18:1 | LL | #[sanitize(address = "off")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | type MyTypeAlias = (); - | ---------------------- not a function, impl block, or module | - = help: sanitize attribute can be applied to a function (with body), impl block, or module + = help: `#[sanitize]` can be applied to crates, functions, impl blocks, modules, and statics -error: sanitize attribute not allowed here +error: `#[sanitize]` attribute cannot be used on traits --> $DIR/valid-sanitize.rs:21:1 | -LL | #[sanitize(address = "off")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | / trait MyTrait { -LL | | #[sanitize(address = "off")] -LL | | const TRAIT_ASSOC_CONST: u32; -... | -LL | | fn trait_assoc_fn(); -LL | | } - | |_- not a function, impl block, or module - | - = help: sanitize attribute can be applied to a function (with body), impl block, or module - -error: sanitize attribute not allowed here - --> $DIR/valid-sanitize.rs:65:1 - | -LL | #[sanitize(address = "off")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | / struct MyStruct { -LL | | #[sanitize(address = "off")] -LL | | field: u32, -LL | | } - | |_- not a function, impl block, or module - | - = help: sanitize attribute can be applied to a function (with body), impl block, or module - -error: sanitize attribute not allowed here - --> $DIR/valid-sanitize.rs:67:5 - | -LL | #[sanitize(address = "off")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | field: u32, - | ---------- not a function, impl block, or module - | - = help: sanitize attribute can be applied to a function (with body), impl block, or module - -error: sanitize attribute not allowed here - --> $DIR/valid-sanitize.rs:92:5 - | -LL | #[sanitize(address = "off", thread = "on")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | let _ = (); - | ----------- not a function, impl block, or module +LL | #[sanitize(address = "off")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: sanitize attribute can be applied to a function (with body), impl block, or module + = help: `#[sanitize]` can be applied to crates, functions, impl blocks, modules, and statics -error: sanitize attribute not allowed here - --> $DIR/valid-sanitize.rs:98:5 +error: `#[sanitize]` attribute cannot be used on associated consts + --> $DIR/valid-sanitize.rs:23:5 | LL | #[sanitize(address = "off")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | let _let_closure = || (); - | ------------------------- not a function, impl block, or module - | - = help: sanitize attribute can be applied to a function (with body), impl block, or module - -error: sanitize attribute not allowed here - --> $DIR/valid-sanitize.rs:109:9 - | -LL | #[sanitize(address = "off")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | () => (), - | -------- not a function, impl block, or module | - = help: sanitize attribute can be applied to a function (with body), impl block, or module + = help: `#[sanitize]` can be applied to crates, functions, impl blocks, modules, and statics -error: sanitize attribute not allowed here - --> $DIR/valid-sanitize.rs:113:5 +error: `#[sanitize]` attribute cannot be used on associated types + --> $DIR/valid-sanitize.rs:26:5 | LL | #[sanitize(address = "off")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | return (); - | --------- not a function, impl block, or module | - = help: sanitize attribute can be applied to a function (with body), impl block, or module + = help: `#[sanitize]` can be applied to crates, functions, impl blocks, modules, and statics -error: sanitize attribute not allowed here - --> $DIR/valid-sanitize.rs:23:5 +error: `#[sanitize]` attribute cannot be used on required trait methods + --> $DIR/valid-sanitize.rs:29:5 | LL | #[sanitize(address = "off")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | const TRAIT_ASSOC_CONST: u32; - | ----------------------------- not a function, impl block, or module | - = help: sanitize attribute can be applied to a function (with body), impl block, or module + = help: `#[sanitize]` can be applied to crates, functions with a body, impl blocks, modules, and statics -error: sanitize attribute not allowed here - --> $DIR/valid-sanitize.rs:26:5 +error: `#[sanitize]` attribute cannot be used on required trait methods + --> $DIR/valid-sanitize.rs:35:5 | LL | #[sanitize(address = "off")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | type TraitAssocType; - | -------------------- not a function, impl block, or module | - = help: sanitize attribute can be applied to a function (with body), impl block, or module + = help: `#[sanitize]` can be applied to crates, functions with a body, impl blocks, modules, and statics -error: sanitize attribute not allowed here - --> $DIR/valid-sanitize.rs:29:5 +error: `#[sanitize]` attribute cannot be used on associated types + --> $DIR/valid-sanitize.rs:43:5 | LL | #[sanitize(address = "off")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | fn trait_method(&self); - | ----------------------- function has no body | - = help: sanitize attribute can be applied to a function (with body), impl block, or module + = help: `#[sanitize]` can be applied to crates, functions, impl blocks, modules, and statics -error: sanitize attribute not allowed here - --> $DIR/valid-sanitize.rs:35:5 +error: `#[sanitize]` attribute cannot be used on associated types + --> $DIR/valid-sanitize.rs:60:5 | LL | #[sanitize(address = "off")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | fn trait_assoc_fn(); - | -------------------- function has no body | - = help: sanitize attribute can be applied to a function (with body), impl block, or module + = help: `#[sanitize]` can be applied to crates, functions, impl blocks, modules, and statics -error: sanitize attribute not allowed here - --> $DIR/valid-sanitize.rs:43:5 +error: `#[sanitize]` attribute cannot be used on structs + --> $DIR/valid-sanitize.rs:65:1 | -LL | #[sanitize(address = "off")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | type TraitAssocType = Self; - | --------------------------- not a function, impl block, or module +LL | #[sanitize(address = "off")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = help: sanitize attribute can be applied to a function (with body), impl block, or module + = help: `#[sanitize]` can be applied to crates, functions, impl blocks, modules, and statics -error: sanitize attribute not allowed here - --> $DIR/valid-sanitize.rs:60:5 +error: `#[sanitize]` attribute cannot be used on struct fields + --> $DIR/valid-sanitize.rs:67:5 | LL | #[sanitize(address = "off")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | type T = impl Copy; - | ------------------- not a function, impl block, or module | - = help: sanitize attribute can be applied to a function (with body), impl block, or module + = help: `#[sanitize]` can be applied to crates, functions, impl blocks, modules, and statics -error: sanitize attribute not allowed here +error: `#[sanitize]` attribute cannot be used on foreign statics --> $DIR/valid-sanitize.rs:80:5 | LL | #[sanitize(address = "off", thread = "on")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | static X: u32; - | -------------- not a function, impl block, or module | - = help: sanitize attribute can be applied to a function (with body), impl block, or module + = help: `#[sanitize]` can be applied to crates, functions, impl blocks, modules, and statics -error: sanitize attribute not allowed here +error: `#[sanitize]` attribute cannot be used on foreign types --> $DIR/valid-sanitize.rs:83:5 | LL | #[sanitize(address = "off", thread = "on")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | type T; - | ------- not a function, impl block, or module | - = help: sanitize attribute can be applied to a function (with body), impl block, or module + = help: `#[sanitize]` can be applied to crates, functions, impl blocks, modules, and statics -error: sanitize attribute not allowed here +error: `#[sanitize]` attribute cannot be used on foreign functions --> $DIR/valid-sanitize.rs:86:5 | LL | #[sanitize(address = "off", thread = "on")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -LL | fn foreign_fn(); - | ---------------- function has no body | - = help: sanitize attribute can be applied to a function (with body), impl block, or module + = help: `#[sanitize]` can be applied to crates, functions with a body, impl blocks, modules, and statics + +error: `#[sanitize]` attribute cannot be used on statements + --> $DIR/valid-sanitize.rs:92:5 + | +LL | #[sanitize(address = "off", thread = "on")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: `#[sanitize]` can be applied to crates, functions, impl blocks, modules, and statics + +error: `#[sanitize]` attribute cannot be used on statements + --> $DIR/valid-sanitize.rs:98:5 + | +LL | #[sanitize(address = "off")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: `#[sanitize]` can be applied to crates, functions, impl blocks, modules, and statics + +error: `#[sanitize]` attribute cannot be used on match arms + --> $DIR/valid-sanitize.rs:109:9 + | +LL | #[sanitize(address = "off")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: `#[sanitize]` can be applied to crates, functions, impl blocks, modules, and statics + +error: `#[sanitize]` attribute cannot be used on expressions + --> $DIR/valid-sanitize.rs:113:5 + | +LL | #[sanitize(address = "off")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: `#[sanitize]` can be applied to crates, functions, impl blocks, modules, and statics error: aborting due to 18 previous errors diff --git a/triagebot.toml b/triagebot.toml index 1a29876d02e70..36ea68ca69bdc 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -1497,6 +1497,7 @@ libs = [ "@joboet", "@nia-e", "@LawnGnome", + "@clarfonthey", ] infra-ci = [ "@Mark-Simulacrum",