From 965c86a646e4524ad9017b0842fe7a90d754e31d Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 26 Jun 2025 02:01:38 +0000 Subject: [PATCH 1/6] Remove support for dyn* --- compiler/rustc_ast/src/ast.rs | 6 +- compiler/rustc_ast_passes/src/feature_gate.rs | 1 - compiler/rustc_ast_pretty/src/pprust/state.rs | 1 - compiler/rustc_borrowck/src/type_check/mod.rs | 38 +------ .../rustc_codegen_cranelift/src/abi/mod.rs | 45 -------- compiler/rustc_codegen_cranelift/src/base.rs | 8 -- .../rustc_codegen_cranelift/src/unsize.rs | 33 ------ .../src/value_and_place.rs | 37 ------- .../rustc_codegen_cranelift/src/vtable.rs | 40 +++---- compiler/rustc_codegen_ssa/src/base.rs | 22 ---- compiler/rustc_codegen_ssa/src/mir/block.rs | 71 ------------ compiler/rustc_codegen_ssa/src/mir/rvalue.rs | 6 - .../src/check_consts/check.rs | 8 -- .../rustc_const_eval/src/interpret/call.rs | 53 +++------ .../rustc_const_eval/src/interpret/cast.rs | 14 --- .../rustc_const_eval/src/interpret/stack.rs | 3 +- .../rustc_const_eval/src/interpret/traits.rs | 22 +--- .../src/interpret/validity.rs | 3 - .../rustc_const_eval/src/interpret/visitor.rs | 21 ---- compiler/rustc_feature/src/removed.rs | 3 + compiler/rustc_feature/src/unstable.rs | 2 - compiler/rustc_hir/src/hir.rs | 2 +- compiler/rustc_hir/src/hir/tests.rs | 1 - .../src/hir_ty_lowering/mod.rs | 1 - compiler/rustc_hir_pretty/src/lib.rs | 1 - compiler/rustc_hir_typeck/src/cast.rs | 9 -- compiler/rustc_hir_typeck/src/coercion.rs | 68 ------------ compiler/rustc_middle/src/ty/adjustment.rs | 3 - compiler/rustc_middle/src/ty/layout.rs | 15 --- compiler/rustc_middle/src/ty/print/pretty.rs | 1 - compiler/rustc_middle/src/ty/sty.rs | 10 +- .../src/mentioned_items.rs | 3 +- compiler/rustc_mir_transform/src/validate.rs | 3 - compiler/rustc_monomorphize/src/collector.rs | 19 +--- .../src/solve/assembly/structural_traits.rs | 1 - .../src/solve/normalizes_to/mod.rs | 3 +- compiler/rustc_parse/src/parser/ty.rs | 10 +- .../src/cfi/typeid/itanium_cxx_abi/encode.rs | 1 - .../rustc_smir/src/rustc_internal/internal.rs | 1 - .../rustc_smir/src/rustc_smir/convert/mir.rs | 2 - .../rustc_smir/src/rustc_smir/convert/ty.rs | 2 - .../rustc_smir/src/stable_mir/mir/body.rs | 2 - compiler/rustc_smir/src/stable_mir/ty.rs | 1 - compiler/rustc_symbol_mangling/src/v0.rs | 2 - .../error_reporting/infer/note_and_explain.rs | 20 ---- .../src/traits/select/mod.rs | 1 - compiler/rustc_ty_utils/src/layout.rs | 8 -- compiler/rustc_ty_utils/src/ty.rs | 6 +- compiler/rustc_type_ir/src/inherent.rs | 3 +- compiler/rustc_type_ir/src/ty_kind.rs | 11 +- .../clippy_utils/src/qualify_min_const_fn.rs | 4 - src/tools/miri/src/helpers.rs | 4 - src/tools/miri/tests/pass/dyn-star.rs | 103 ------------------ src/tools/rustfmt/src/types.rs | 6 - src/tools/rustfmt/tests/target/issue_5542.rs | 10 -- src/tools/tidy/src/issues.txt | 1 - tests/codegen/function-arguments.rs | 9 -- tests/crashes/116979.rs | 14 --- tests/crashes/119694.rs | 18 --- tests/ui/SUMMARY.md | 4 - tests/ui/dyn-star/align.normal.stderr | 20 ---- tests/ui/dyn-star/align.over_aligned.stderr | 20 ---- tests/ui/dyn-star/align.rs | 16 --- tests/ui/dyn-star/async-block-dyn-star.rs | 9 -- tests/ui/dyn-star/async-block-dyn-star.stderr | 20 ---- .../ui/dyn-star/auxiliary/dyn-star-foreign.rs | 9 -- tests/ui/dyn-star/box.rs | 20 ---- tests/ui/dyn-star/cell.rs | 34 ------ ...ize-at-cast-polymorphic-bad.current.stderr | 18 --- ...k-size-at-cast-polymorphic-bad.next.stderr | 18 --- .../check-size-at-cast-polymorphic-bad.rs | 19 ---- .../check-size-at-cast-polymorphic.rs | 16 --- tests/ui/dyn-star/check-size-at-cast.rs | 10 -- tests/ui/dyn-star/check-size-at-cast.stderr | 11 -- tests/ui/dyn-star/const-and-static.rs | 10 -- tests/ui/dyn-star/const-and-static.stderr | 11 -- tests/ui/dyn-star/const.rs | 14 --- tests/ui/dyn-star/dispatch-on-pin-mut.rs | 36 ------ .../dyn-star/dispatch-on-pin-mut.run.stdout | 1 - tests/ui/dyn-star/dispatch-on-pin-mut.stderr | 11 -- .../dyn-star/dont-unsize-coerce-dyn-star.rs | 27 ----- .../dont-unsize-coerce-dyn-star.run.stdout | 2 - .../dont-unsize-coerce-dyn-star.stderr | 11 -- tests/ui/dyn-star/drop.rs | 28 ----- tests/ui/dyn-star/drop.run.stdout | 1 - tests/ui/dyn-star/dyn-async-trait.rs | 36 ------ tests/ui/dyn-star/dyn-pointer-like.rs | 23 ---- tests/ui/dyn-star/dyn-pointer-like.stderr | 39 ------- tests/ui/dyn-star/dyn-star-to-dyn.rs | 17 --- tests/ui/dyn-star/dyn-star-to-dyn.stderr | 11 -- tests/ui/dyn-star/dyn-to-rigid.rs | 11 -- tests/ui/dyn-star/dyn-to-rigid.stderr | 9 -- tests/ui/dyn-star/enum-cast.rs | 23 ---- tests/ui/dyn-star/error.rs | 13 --- tests/ui/dyn-star/error.stderr | 15 --- tests/ui/dyn-star/feature-gate-dyn_star.rs | 9 -- .../ui/dyn-star/feature-gate-dyn_star.stderr | 13 --- tests/ui/dyn-star/float-as-dyn-star.rs | 16 --- tests/ui/dyn-star/float-as-dyn-star.stderr | 23 ---- tests/ui/dyn-star/gated-span.rs | 8 -- tests/ui/dyn-star/gated-span.stderr | 13 --- tests/ui/dyn-star/illegal.rs | 16 --- tests/ui/dyn-star/illegal.stderr | 27 ----- tests/ui/dyn-star/issue-102430.rs | 32 ------ tests/ui/dyn-star/make-dyn-star.rs | 18 --- tests/ui/dyn-star/method.rs | 27 ----- .../ui/dyn-star/no-explicit-dyn-star-cast.rs | 13 --- .../dyn-star/no-explicit-dyn-star-cast.stderr | 30 ----- tests/ui/dyn-star/no-explicit-dyn-star.rs | 8 -- tests/ui/dyn-star/no-explicit-dyn-star.stderr | 9 -- tests/ui/dyn-star/no-implicit-dyn-star.rs | 8 -- tests/ui/dyn-star/no-implicit-dyn-star.stderr | 20 ---- .../ui/dyn-star/no-unsize-coerce-dyn-trait.rs | 13 --- .../no-unsize-coerce-dyn-trait.stderr | 14 --- .../param-env-region-infer.current.stderr | 9 -- tests/ui/dyn-star/param-env-region-infer.rs | 24 ---- tests/ui/dyn-star/pointer-like-impl-rules.rs | 82 -------------- .../dyn-star/pointer-like-impl-rules.stderr | 85 --------------- tests/ui/dyn-star/return.rs | 10 -- tests/ui/dyn-star/return.stderr | 11 -- tests/ui/dyn-star/syntax.rs | 11 -- tests/ui/dyn-star/thin.next.stderr | 11 -- tests/ui/dyn-star/thin.old.stderr | 11 -- tests/ui/dyn-star/thin.rs | 16 --- tests/ui/dyn-star/union.rs | 16 --- tests/ui/dyn-star/union.stderr | 20 ---- tests/ui/dyn-star/unsize-into-ref-dyn-star.rs | 9 -- .../dyn-star/unsize-into-ref-dyn-star.stderr | 9 -- tests/ui/dyn-star/upcast.rs | 32 ------ tests/ui/dyn-star/upcast.stderr | 28 ----- tests/ui/parser/trait-object-delimiters.rs | 2 +- .../ui/parser/trait-object-delimiters.stderr | 4 +- tests/ui/sized-hierarchy/impls.rs | 7 +- tests/ui/sized-hierarchy/impls.stderr | 66 +++++------ .../wrap-dyn-in-suggestion-issue-120223.rs | 8 -- ...wrap-dyn-in-suggestion-issue-120223.stderr | 33 +----- tests/ui/traits/dyn-star-drop-principal.rs | 12 -- .../ui/traits/dyn-star-drop-principal.stderr | 11 -- .../traits/trait-upcasting/dyn-to-dyn-star.rs | 19 ---- tests/ui/unpretty/exhaustive.expanded.stdout | 2 - tests/ui/unpretty/exhaustive.hir.stderr | 40 +++---- tests/ui/unpretty/exhaustive.hir.stdout | 2 - tests/ui/unpretty/exhaustive.rs | 2 - 143 files changed, 114 insertions(+), 2204 deletions(-) delete mode 100644 src/tools/miri/tests/pass/dyn-star.rs delete mode 100644 src/tools/rustfmt/tests/target/issue_5542.rs delete mode 100644 tests/crashes/116979.rs delete mode 100644 tests/crashes/119694.rs delete mode 100644 tests/ui/dyn-star/align.normal.stderr delete mode 100644 tests/ui/dyn-star/align.over_aligned.stderr delete mode 100644 tests/ui/dyn-star/align.rs delete mode 100644 tests/ui/dyn-star/async-block-dyn-star.rs delete mode 100644 tests/ui/dyn-star/async-block-dyn-star.stderr delete mode 100644 tests/ui/dyn-star/auxiliary/dyn-star-foreign.rs delete mode 100644 tests/ui/dyn-star/box.rs delete mode 100644 tests/ui/dyn-star/cell.rs delete mode 100644 tests/ui/dyn-star/check-size-at-cast-polymorphic-bad.current.stderr delete mode 100644 tests/ui/dyn-star/check-size-at-cast-polymorphic-bad.next.stderr delete mode 100644 tests/ui/dyn-star/check-size-at-cast-polymorphic-bad.rs delete mode 100644 tests/ui/dyn-star/check-size-at-cast-polymorphic.rs delete mode 100644 tests/ui/dyn-star/check-size-at-cast.rs delete mode 100644 tests/ui/dyn-star/check-size-at-cast.stderr delete mode 100644 tests/ui/dyn-star/const-and-static.rs delete mode 100644 tests/ui/dyn-star/const-and-static.stderr delete mode 100644 tests/ui/dyn-star/const.rs delete mode 100644 tests/ui/dyn-star/dispatch-on-pin-mut.rs delete mode 100644 tests/ui/dyn-star/dispatch-on-pin-mut.run.stdout delete mode 100644 tests/ui/dyn-star/dispatch-on-pin-mut.stderr delete mode 100644 tests/ui/dyn-star/dont-unsize-coerce-dyn-star.rs delete mode 100644 tests/ui/dyn-star/dont-unsize-coerce-dyn-star.run.stdout delete mode 100644 tests/ui/dyn-star/dont-unsize-coerce-dyn-star.stderr delete mode 100644 tests/ui/dyn-star/drop.rs delete mode 100644 tests/ui/dyn-star/drop.run.stdout delete mode 100644 tests/ui/dyn-star/dyn-async-trait.rs delete mode 100644 tests/ui/dyn-star/dyn-pointer-like.rs delete mode 100644 tests/ui/dyn-star/dyn-pointer-like.stderr delete mode 100644 tests/ui/dyn-star/dyn-star-to-dyn.rs delete mode 100644 tests/ui/dyn-star/dyn-star-to-dyn.stderr delete mode 100644 tests/ui/dyn-star/dyn-to-rigid.rs delete mode 100644 tests/ui/dyn-star/dyn-to-rigid.stderr delete mode 100644 tests/ui/dyn-star/enum-cast.rs delete mode 100644 tests/ui/dyn-star/error.rs delete mode 100644 tests/ui/dyn-star/error.stderr delete mode 100644 tests/ui/dyn-star/feature-gate-dyn_star.rs delete mode 100644 tests/ui/dyn-star/feature-gate-dyn_star.stderr delete mode 100644 tests/ui/dyn-star/float-as-dyn-star.rs delete mode 100644 tests/ui/dyn-star/float-as-dyn-star.stderr delete mode 100644 tests/ui/dyn-star/gated-span.rs delete mode 100644 tests/ui/dyn-star/gated-span.stderr delete mode 100644 tests/ui/dyn-star/illegal.rs delete mode 100644 tests/ui/dyn-star/illegal.stderr delete mode 100644 tests/ui/dyn-star/issue-102430.rs delete mode 100644 tests/ui/dyn-star/make-dyn-star.rs delete mode 100644 tests/ui/dyn-star/method.rs delete mode 100644 tests/ui/dyn-star/no-explicit-dyn-star-cast.rs delete mode 100644 tests/ui/dyn-star/no-explicit-dyn-star-cast.stderr delete mode 100644 tests/ui/dyn-star/no-explicit-dyn-star.rs delete mode 100644 tests/ui/dyn-star/no-explicit-dyn-star.stderr delete mode 100644 tests/ui/dyn-star/no-implicit-dyn-star.rs delete mode 100644 tests/ui/dyn-star/no-implicit-dyn-star.stderr delete mode 100644 tests/ui/dyn-star/no-unsize-coerce-dyn-trait.rs delete mode 100644 tests/ui/dyn-star/no-unsize-coerce-dyn-trait.stderr delete mode 100644 tests/ui/dyn-star/param-env-region-infer.current.stderr delete mode 100644 tests/ui/dyn-star/param-env-region-infer.rs delete mode 100644 tests/ui/dyn-star/pointer-like-impl-rules.rs delete mode 100644 tests/ui/dyn-star/pointer-like-impl-rules.stderr delete mode 100644 tests/ui/dyn-star/return.rs delete mode 100644 tests/ui/dyn-star/return.stderr delete mode 100644 tests/ui/dyn-star/syntax.rs delete mode 100644 tests/ui/dyn-star/thin.next.stderr delete mode 100644 tests/ui/dyn-star/thin.old.stderr delete mode 100644 tests/ui/dyn-star/thin.rs delete mode 100644 tests/ui/dyn-star/union.rs delete mode 100644 tests/ui/dyn-star/union.stderr delete mode 100644 tests/ui/dyn-star/unsize-into-ref-dyn-star.rs delete mode 100644 tests/ui/dyn-star/unsize-into-ref-dyn-star.stderr delete mode 100644 tests/ui/dyn-star/upcast.rs delete mode 100644 tests/ui/dyn-star/upcast.stderr delete mode 100644 tests/ui/traits/dyn-star-drop-principal.rs delete mode 100644 tests/ui/traits/dyn-star-drop-principal.stderr delete mode 100644 tests/ui/traits/trait-upcasting/dyn-to-dyn-star.rs diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index ab8dac1602666..62af9163cf3c2 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2577,8 +2577,7 @@ pub enum TyPatKind { pub enum TraitObjectSyntax { // SAFETY: When adding new variants make sure to update the `Tag` impl. Dyn = 0, - DynStar = 1, - None = 2, + None = 1, } /// SAFETY: `TraitObjectSyntax` only has 3 data-less variants which means @@ -2594,8 +2593,7 @@ unsafe impl Tag for TraitObjectSyntax { unsafe fn from_usize(tag: usize) -> Self { match tag { 0 => TraitObjectSyntax::Dyn, - 1 => TraitObjectSyntax::DynStar, - 2 => TraitObjectSyntax::None, + 1 => TraitObjectSyntax::None, _ => unreachable!(), } } diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 1ec56868f378f..c7f41fc3cb122 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -505,7 +505,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) { ); gate_all!(associated_const_equality, "associated const equality is incomplete"); gate_all!(yeet_expr, "`do yeet` expression is experimental"); - gate_all!(dyn_star, "`dyn*` trait objects are experimental"); gate_all!(const_closures, "const closures are experimental"); gate_all!(builtin_syntax, "`builtin #` syntax is unstable"); gate_all!(ergonomic_clones, "ergonomic clones are experimental"); diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 3d738fa31f2b3..9802ac90c9a65 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -1303,7 +1303,6 @@ impl<'a> State<'a> { ast::TyKind::TraitObject(bounds, syntax) => { match syntax { ast::TraitObjectSyntax::Dyn => self.word_nbsp("dyn"), - ast::TraitObjectSyntax::DynStar => self.word_nbsp("dyn*"), ast::TraitObjectSyntax::None => {} } self.print_type_bounds(bounds); diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 9b6dcfd17c62e..836b1441c1859 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -25,9 +25,9 @@ use rustc_middle::traits::query::NoSolution; use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::cast::CastTy; use rustc_middle::ty::{ - self, Binder, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, CoroutineArgsExt, - Dynamic, GenericArgsRef, OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt, - TypeVisitableExt, UserArgs, UserTypeAnnotationIndex, fold_regions, + self, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, CoroutineArgsExt, + GenericArgsRef, OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt, TypeVisitableExt, + UserArgs, UserTypeAnnotationIndex, fold_regions, }; use rustc_middle::{bug, span_bug}; use rustc_mir_dataflow::move_paths::MoveData; @@ -1233,38 +1233,6 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { ); } - CastKind::PointerCoercion(PointerCoercion::DynStar, coercion_source) => { - // get the constraints from the target type (`dyn* Clone`) - // - // apply them to prove that the source type `Foo` implements `Clone` etc - let (existential_predicates, region) = match ty.kind() { - Dynamic(predicates, region, ty::DynStar) => (predicates, region), - _ => panic!("Invalid dyn* cast_ty"), - }; - - let self_ty = op.ty(self.body, tcx); - - let is_implicit_coercion = coercion_source == CoercionSource::Implicit; - self.prove_predicates( - existential_predicates - .iter() - .map(|predicate| predicate.with_self_ty(tcx, self_ty)), - location.to_locations(), - ConstraintCategory::Cast { is_implicit_coercion, unsize_to: None }, - ); - - let outlives_predicate = tcx.mk_predicate(Binder::dummy( - ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives( - ty::OutlivesPredicate(self_ty, *region), - )), - )); - self.prove_predicate( - outlives_predicate, - location.to_locations(), - ConstraintCategory::Cast { is_implicit_coercion, unsize_to: None }, - ); - } - CastKind::PointerCoercion( PointerCoercion::MutToConstPointer, coercion_source, diff --git a/compiler/rustc_codegen_cranelift/src/abi/mod.rs b/compiler/rustc_codegen_cranelift/src/abi/mod.rs index 4c6fd90781543..8965e4a944d48 100644 --- a/compiler/rustc_codegen_cranelift/src/abi/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/abi/mod.rs @@ -753,51 +753,6 @@ pub(crate) fn codegen_drop<'tcx>( fx.bcx.ins().call_indirect(sig, drop_fn, &[ptr]); fx.bcx.ins().jump(ret_block, &[]); } - ty::Dynamic(_, _, ty::DynStar) => { - // IN THIS ARM, WE HAVE: - // ty = *mut (dyn* Trait) - // which is: *mut exists (T, Vtable) - // - // args = [ * ] - // | - // v - // ( Data, Vtable ) - // | - // v - // /-------\ - // | ... | - // \-------/ - // - // - // WE CAN CONVERT THIS INTO THE ABOVE LOGIC BY DOING - // - // data = &(*args[0]).0 // gives a pointer to Data above (really the same pointer) - // vtable = (*args[0]).1 // loads the vtable out - // (data, vtable) // an equivalent Rust `*mut dyn Trait` - // - // SO THEN WE CAN USE THE ABOVE CODE. - let (data, vtable) = drop_place.to_cvalue(fx).dyn_star_force_data_on_stack(fx); - let drop_fn = crate::vtable::drop_fn_of_obj(fx, vtable); - - let is_null = fx.bcx.ins().icmp_imm(IntCC::Equal, drop_fn, 0); - let target_block = fx.get_block(target); - let continued = fx.bcx.create_block(); - fx.bcx.ins().brif(is_null, target_block, &[], continued, &[]); - fx.bcx.switch_to_block(continued); - - let virtual_drop = Instance { - def: ty::InstanceKind::Virtual(drop_instance.def_id(), 0), - args: drop_instance.args, - }; - let fn_abi = FullyMonomorphizedLayoutCx(fx.tcx) - .fn_abi_of_instance(virtual_drop, ty::List::empty()); - - let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi); - let sig = fx.bcx.import_signature(sig); - fx.bcx.ins().call_indirect(sig, drop_fn, &[data]); - // FIXME implement cleanup on exceptions - fx.bcx.ins().jump(ret_block, &[]); - } _ => { assert!(!matches!(drop_instance.def, InstanceKind::Virtual(_, _))); diff --git a/compiler/rustc_codegen_cranelift/src/base.rs b/compiler/rustc_codegen_cranelift/src/base.rs index 0b641ba64b7a4..1464e053e78e2 100644 --- a/compiler/rustc_codegen_cranelift/src/base.rs +++ b/compiler/rustc_codegen_cranelift/src/base.rs @@ -778,14 +778,6 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt: let operand = codegen_operand(fx, operand); crate::unsize::coerce_unsized_into(fx, operand, lval); } - Rvalue::Cast( - CastKind::PointerCoercion(PointerCoercion::DynStar, _), - ref operand, - _, - ) => { - let operand = codegen_operand(fx, operand); - crate::unsize::coerce_dyn_star(fx, operand, lval); - } Rvalue::Cast(CastKind::Transmute, ref operand, _to_ty) => { let operand = codegen_operand(fx, operand); lval.write_cvalue_transmute(fx, operand); diff --git a/compiler/rustc_codegen_cranelift/src/unsize.rs b/compiler/rustc_codegen_cranelift/src/unsize.rs index df60b05c4636c..2aee0b2e97424 100644 --- a/compiler/rustc_codegen_cranelift/src/unsize.rs +++ b/compiler/rustc_codegen_cranelift/src/unsize.rs @@ -112,21 +112,6 @@ fn unsize_ptr<'tcx>( } } -/// Coerces `src` to `dst_ty` which is guaranteed to be a `dyn*` type. -pub(crate) fn cast_to_dyn_star<'tcx>( - fx: &mut FunctionCx<'_, '_, 'tcx>, - src: Value, - src_ty_and_layout: TyAndLayout<'tcx>, - dst_ty: Ty<'tcx>, - old_info: Option, -) -> (Value, Value) { - assert!( - matches!(dst_ty.kind(), ty::Dynamic(_, _, ty::DynStar)), - "destination type must be a dyn*" - ); - (src, unsized_info(fx, src_ty_and_layout.ty, dst_ty, old_info)) -} - /// Coerce `src`, which is a reference to a value of type `src_ty`, /// to a value of type `dst_ty` and store the result in `dst` pub(crate) fn coerce_unsized_into<'tcx>( @@ -174,24 +159,6 @@ pub(crate) fn coerce_unsized_into<'tcx>( } } -pub(crate) fn coerce_dyn_star<'tcx>( - fx: &mut FunctionCx<'_, '_, 'tcx>, - src: CValue<'tcx>, - dst: CPlace<'tcx>, -) { - let (data, extra) = if let ty::Dynamic(_, _, ty::DynStar) = src.layout().ty.kind() { - let (data, vtable) = src.load_scalar_pair(fx); - (data, Some(vtable)) - } else { - let data = src.load_scalar(fx); - (data, None) - }; - - let (data, vtable) = cast_to_dyn_star(fx, data, src.layout(), dst.layout().ty, extra); - - dst.write_cvalue(fx, CValue::by_val_pair(data, vtable, dst.layout())); -} - // Adapted from https://github.com/rust-lang/rust/blob/2a663555ddf36f6b041445894a8c175cd1bc718c/src/librustc_codegen_ssa/glue.rs pub(crate) fn size_and_align_of<'tcx>( diff --git a/compiler/rustc_codegen_cranelift/src/value_and_place.rs b/compiler/rustc_codegen_cranelift/src/value_and_place.rs index cbfb215a892a4..9d73f200afe2b 100644 --- a/compiler/rustc_codegen_cranelift/src/value_and_place.rs +++ b/compiler/rustc_codegen_cranelift/src/value_and_place.rs @@ -121,43 +121,6 @@ impl<'tcx> CValue<'tcx> { } } - // FIXME remove - /// Forces the data value of a dyn* value to the stack and returns a pointer to it as well as the - /// vtable pointer. - pub(crate) fn dyn_star_force_data_on_stack( - self, - fx: &mut FunctionCx<'_, '_, 'tcx>, - ) -> (Value, Value) { - assert!(self.1.ty.is_dyn_star()); - - match self.0 { - CValueInner::ByRef(ptr, None) => { - let (a_scalar, b_scalar) = match self.1.backend_repr { - BackendRepr::ScalarPair(a, b) => (a, b), - _ => unreachable!("dyn_star_force_data_on_stack({:?})", self), - }; - let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar); - let clif_ty2 = scalar_to_clif_type(fx.tcx, b_scalar); - let mut flags = MemFlags::new(); - flags.set_notrap(); - let vtable = ptr.offset(fx, b_offset).load(fx, clif_ty2, flags); - (ptr.get_addr(fx), vtable) - } - CValueInner::ByValPair(data, vtable) => { - let data_ptr = fx.create_stack_slot( - u32::try_from(fx.target_config.pointer_type().bytes()).unwrap(), - u32::try_from(fx.target_config.pointer_type().bytes()).unwrap(), - ); - data_ptr.store(fx, data, MemFlags::trusted()); - - (data_ptr.get_addr(fx), vtable) - } - CValueInner::ByRef(_, Some(_)) | CValueInner::ByVal(_) => { - unreachable!("dyn_star_force_data_on_stack({:?})", self) - } - } - } - pub(crate) fn try_to_ptr(self) -> Option<(Pointer, Option)> { match self.0 { CValueInner::ByRef(ptr, meta) => Some((ptr, meta)), diff --git a/compiler/rustc_codegen_cranelift/src/vtable.rs b/compiler/rustc_codegen_cranelift/src/vtable.rs index 1fae56949bc05..423cc8d225be1 100644 --- a/compiler/rustc_codegen_cranelift/src/vtable.rs +++ b/compiler/rustc_codegen_cranelift/src/vtable.rs @@ -46,34 +46,22 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>( mut arg: CValue<'tcx>, idx: usize, ) -> (Pointer, Value) { - let (ptr, vtable) = 'block: { - if let BackendRepr::Scalar(_) = arg.layout().backend_repr { - while !arg.layout().ty.is_raw_ptr() && !arg.layout().ty.is_ref() { - let (idx, _) = arg - .layout() - .non_1zst_field(fx) - .expect("not exactly one non-1-ZST field in a `DispatchFromDyn` type"); - arg = arg.value_field(fx, idx); - } - } - - if let ty::Ref(_, ty, _) = arg.layout().ty.kind() { - if ty.is_dyn_star() { - let inner_layout = fx.layout_of(arg.layout().ty.builtin_deref(true).unwrap()); - let dyn_star = CPlace::for_ptr(Pointer::new(arg.load_scalar(fx)), inner_layout); - let ptr = dyn_star.place_field(fx, FieldIdx::ZERO).to_ptr(); - let vtable = dyn_star.place_field(fx, FieldIdx::ONE).to_cvalue(fx).load_scalar(fx); - break 'block (ptr, vtable); - } + if let BackendRepr::Scalar(_) = arg.layout().backend_repr { + while !arg.layout().ty.is_raw_ptr() && !arg.layout().ty.is_ref() { + let (idx, _) = arg + .layout() + .non_1zst_field(fx) + .expect("not exactly one non-1-ZST field in a `DispatchFromDyn` type"); + arg = arg.value_field(fx, idx); } + } - if let BackendRepr::ScalarPair(_, _) = arg.layout().backend_repr { - let (ptr, vtable) = arg.load_scalar_pair(fx); - (Pointer::new(ptr), vtable) - } else { - let (ptr, vtable) = arg.try_to_ptr().unwrap(); - (ptr, vtable.unwrap()) - } + let (ptr, vtable) = if let BackendRepr::ScalarPair(_, _) = arg.layout().backend_repr { + let (ptr, vtable) = arg.load_scalar_pair(fx); + (Pointer::new(ptr), vtable) + } else { + let (ptr, vtable) = arg.try_to_ptr().unwrap(); + (ptr, vtable.unwrap()) }; let usize_size = fx.layout_of(fx.tcx.types.usize).size.bytes(); diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index cc90271cd0c6f..6509bbce32409 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -262,28 +262,6 @@ pub(crate) fn unsize_ptr<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( } } -/// Coerces `src` to `dst_ty` which is guaranteed to be a `dyn*` type. -pub(crate) fn cast_to_dyn_star<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( - bx: &mut Bx, - src: Bx::Value, - src_ty_and_layout: TyAndLayout<'tcx>, - dst_ty: Ty<'tcx>, - old_info: Option, -) -> (Bx::Value, Bx::Value) { - debug!("cast_to_dyn_star: {:?} => {:?}", src_ty_and_layout.ty, dst_ty); - assert!( - matches!(dst_ty.kind(), ty::Dynamic(_, _, ty::DynStar)), - "destination type must be a dyn*" - ); - let src = match bx.cx().type_kind(bx.cx().backend_type(src_ty_and_layout)) { - TypeKind::Pointer => src, - TypeKind::Integer => bx.inttoptr(src, bx.type_ptr()), - // FIXME(dyn-star): We probably have to do a bitcast first, then inttoptr. - kind => bug!("unexpected TypeKind for left-hand side of `dyn*` cast: {kind:?}"), - }; - (src, unsized_info(bx, src_ty_and_layout.ty, dst_ty, old_info)) -} - /// Coerces `src`, which is a reference to a value of type `src_ty`, /// to a value of type `dst_ty`, and stores the result in `dst`. pub(crate) fn coerce_unsized_into<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 3df97429e0931..6df8923588a09 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -628,50 +628,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { virtual_drop, ) } - ty::Dynamic(_, _, ty::DynStar) => { - // IN THIS ARM, WE HAVE: - // ty = *mut (dyn* Trait) - // which is: *mut exists (T, Vtable) - // - // args = [ * ] - // | - // v - // ( Data, Vtable ) - // | - // v - // /-------\ - // | ... | - // \-------/ - // - // - // WE CAN CONVERT THIS INTO THE ABOVE LOGIC BY DOING - // - // data = &(*args[0]).0 // gives a pointer to Data above (really the same pointer) - // vtable = (*args[0]).1 // loads the vtable out - // (data, vtable) // an equivalent Rust `*mut dyn Trait` - // - // SO THEN WE CAN USE THE ABOVE CODE. - let virtual_drop = Instance { - def: ty::InstanceKind::Virtual(drop_fn.def_id(), 0), // idx 0: the drop function - args: drop_fn.args, - }; - debug!("ty = {:?}", ty); - debug!("drop_fn = {:?}", drop_fn); - debug!("args = {:?}", args); - let fn_abi = bx.fn_abi_of_instance(virtual_drop, ty::List::empty()); - let meta_ptr = place.project_field(bx, 1); - let meta = bx.load_operand(meta_ptr); - // Truncate vtable off of args list - args = &args[..1]; - debug!("args' = {:?}", args); - ( - true, - meth::VirtualIndex::from_index(ty::COMMON_VTABLE_ENTRIES_DROPINPLACE) - .get_optional_fn(bx, meta.immediate(), ty, fn_abi), - fn_abi, - virtual_drop, - ) - } _ => ( false, bx.get_fn_addr(drop_fn), @@ -1102,33 +1058,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { llargs.push(data_ptr); continue; } - Immediate(_) => { - // See comment above explaining why we peel these newtypes - while !op.layout.ty.is_raw_ptr() && !op.layout.ty.is_ref() { - let (idx, _) = op.layout.non_1zst_field(bx).expect( - "not exactly one non-1-ZST field in a `DispatchFromDyn` type", - ); - op = op.extract_field(self, bx, idx.as_usize()); - } - - // Make sure that we've actually unwrapped the rcvr down - // to a pointer or ref to `dyn* Trait`. - if !op.layout.ty.builtin_deref(true).unwrap().is_dyn_star() { - span_bug!(fn_span, "can't codegen a virtual call on {:#?}", op); - } - let place = op.deref(bx.cx()); - let data_place = place.project_field(bx, 0); - let meta_place = place.project_field(bx, 1); - let meta = bx.load_operand(meta_place); - llfn = Some(meth::VirtualIndex::from_index(idx).get_fn( - bx, - meta.immediate(), - op.layout.ty, - fn_abi, - )); - llargs.push(data_place.val.llval); - continue; - } _ => { span_bug!(fn_span, "can't codegen a virtual call on {:#?}", op); } diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index db5ac6a514fb4..7ef04213d3207 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -468,12 +468,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { bug!("unexpected non-pair operand"); } } - mir::CastKind::PointerCoercion(PointerCoercion::DynStar, _) => { - let (lldata, llextra) = operand.val.pointer_parts(); - let (lldata, llextra) = - base::cast_to_dyn_star(bx, lldata, operand.layout, cast.ty, llextra); - OperandValue::Pair(lldata, llextra) - } | mir::CastKind::IntToInt | mir::CastKind::FloatToInt | mir::CastKind::FloatToFloat diff --git a/compiler/rustc_const_eval/src/check_consts/check.rs b/compiler/rustc_const_eval/src/check_consts/check.rs index 576b174369d46..0558be1ed7675 100644 --- a/compiler/rustc_const_eval/src/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/check_consts/check.rs @@ -642,14 +642,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { // These are all okay; they only change the type, not the data. } - Rvalue::Cast( - CastKind::PointerCoercion(PointerCoercion::Unsize | PointerCoercion::DynStar, _), - _, - _, - ) => { - // Unsizing and `dyn*` coercions are implemented for CTFE. - } - Rvalue::Cast(CastKind::PointerExposeProvenance, _, _) => { self.check_op(ops::RawPtrToIntCast); } diff --git a/compiler/rustc_const_eval/src/interpret/call.rs b/compiler/rustc_const_eval/src/interpret/call.rs index 37677f9e0483a..6cd2ee8c8adad 100644 --- a/compiler/rustc_const_eval/src/interpret/call.rs +++ b/compiler/rustc_const_eval/src/interpret/call.rs @@ -643,13 +643,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { break self.ref_to_mplace(&val)?; } ty::Dynamic(.., ty::Dyn) => break receiver.assert_mem_place(), // no immediate unsized values - ty::Dynamic(.., ty::DynStar) => { - // Not clear how to handle this, so far we assume the receiver is always a pointer. - span_bug!( - self.cur_span(), - "by-value calls on a `dyn*`... are those a thing?" - ); - } _ => { // Not there yet, search for the only non-ZST field. // (The rules for `DispatchFromDyn` ensure there's exactly one such field.) @@ -662,39 +655,23 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { }; // Obtain the underlying trait we are working on, and the adjusted receiver argument. - let (trait_, dyn_ty, adjusted_recv) = if let ty::Dynamic(data, _, ty::DynStar) = - receiver_place.layout.ty.kind() - { - let recv = self.unpack_dyn_star(&receiver_place, data)?; - - (data.principal(), recv.layout.ty, recv.ptr()) - } else { - // Doesn't have to be a `dyn Trait`, but the unsized tail must be `dyn Trait`. - // (For that reason we also cannot use `unpack_dyn_trait`.) - let receiver_tail = - self.tcx.struct_tail_for_codegen(receiver_place.layout.ty, self.typing_env); - let ty::Dynamic(receiver_trait, _, ty::Dyn) = receiver_tail.kind() else { - span_bug!( - self.cur_span(), - "dynamic call on non-`dyn` type {}", - receiver_tail - ) - }; - assert!(receiver_place.layout.is_unsized()); - - // Get the required information from the vtable. - let vptr = receiver_place.meta().unwrap_meta().to_pointer(self)?; - let dyn_ty = self.get_ptr_vtable_ty(vptr, Some(receiver_trait))?; - - // It might be surprising that we use a pointer as the receiver even if this - // is a by-val case; this works because by-val passing of an unsized `dyn - // Trait` to a function is actually desugared to a pointer. - (receiver_trait.principal(), dyn_ty, receiver_place.ptr()) + // Doesn't have to be a `dyn Trait`, but the unsized tail must be `dyn Trait`. + // (For that reason we also cannot use `unpack_dyn_trait`.) + let receiver_tail = + self.tcx.struct_tail_for_codegen(receiver_place.layout.ty, self.typing_env); + let ty::Dynamic(receiver_trait, _, ty::Dyn) = receiver_tail.kind() else { + span_bug!(self.cur_span(), "dynamic call on non-`dyn` type {}", receiver_tail) }; + assert!(receiver_place.layout.is_unsized()); + + // Get the required information from the vtable. + let vptr = receiver_place.meta().unwrap_meta().to_pointer(self)?; + let dyn_ty = self.get_ptr_vtable_ty(vptr, Some(receiver_trait))?; + let adjusted_recv = receiver_place.ptr(); // Now determine the actual method to call. Usually we use the easy way of just // looking up the method at index `idx`. - let vtable_entries = self.vtable_entries(trait_, dyn_ty); + let vtable_entries = self.vtable_entries(receiver_trait.principal(), dyn_ty); let Some(ty::VtblEntry::Method(fn_inst)) = vtable_entries.get(idx).copied() else { // FIXME(fee1-dead) these could be variants of the UB info enum instead of this throw_ub_custom!(fluent::const_eval_dyn_call_not_a_method); @@ -830,10 +807,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { // Dropping a trait object. Need to find actual drop fn. self.unpack_dyn_trait(&place, data)? } - ty::Dynamic(data, _, ty::DynStar) => { - // Dropping a `dyn*`. Need to find actual drop fn. - self.unpack_dyn_star(&place, data)? - } _ => { debug_assert_eq!( instance, diff --git a/compiler/rustc_const_eval/src/interpret/cast.rs b/compiler/rustc_const_eval/src/interpret/cast.rs index 9e15f4572d7b9..dc21a71794a7a 100644 --- a/compiler/rustc_const_eval/src/interpret/cast.rs +++ b/compiler/rustc_const_eval/src/interpret/cast.rs @@ -126,20 +126,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { } } - CastKind::PointerCoercion(PointerCoercion::DynStar, _) => { - if let ty::Dynamic(data, _, ty::DynStar) = cast_ty.kind() { - // Initial cast from sized to dyn trait - let vtable = self.get_vtable_ptr(src.layout.ty, data)?; - let vtable = Scalar::from_maybe_pointer(vtable, self); - let data = self.read_immediate(src)?.to_scalar(); - let _assert_pointer_like = data.to_pointer(self)?; - let val = Immediate::ScalarPair(data, vtable); - self.write_immediate(val, dest)?; - } else { - bug!() - } - } - CastKind::Transmute => { assert!(src.layout.is_sized()); assert!(dest.layout.is_sized()); diff --git a/compiler/rustc_const_eval/src/interpret/stack.rs b/compiler/rustc_const_eval/src/interpret/stack.rs index 2a2d1bb27547e..67691df807b6f 100644 --- a/compiler/rustc_const_eval/src/interpret/stack.rs +++ b/compiler/rustc_const_eval/src/interpret/stack.rs @@ -499,8 +499,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { | ty::Closure(..) | ty::CoroutineClosure(..) | ty::Never - | ty::Error(_) - | ty::Dynamic(_, _, ty::DynStar) => true, + | ty::Error(_) => true, ty::Str | ty::Slice(_) | ty::Dynamic(_, _, ty::Dyn) | ty::Foreign(..) => false, diff --git a/compiler/rustc_const_eval/src/interpret/traits.rs b/compiler/rustc_const_eval/src/interpret/traits.rs index 7249ef23bf627..38272a7cee946 100644 --- a/compiler/rustc_const_eval/src/interpret/traits.rs +++ b/compiler/rustc_const_eval/src/interpret/traits.rs @@ -1,4 +1,4 @@ -use rustc_abi::{Align, FieldIdx, Size}; +use rustc_abi::{Align, Size}; use rustc_middle::mir::interpret::{InterpResult, Pointer}; use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, ExistentialPredicateStableCmpExt, Ty, TyCtxt, VtblEntry}; @@ -126,24 +126,4 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { )?; interp_ok(mplace) } - - /// Turn a `dyn* Trait` type into an value with the actual dynamic type. - pub(super) fn unpack_dyn_star>( - &self, - val: &P, - expected_trait: &'tcx ty::List>, - ) -> InterpResult<'tcx, P> { - assert!( - matches!(val.layout().ty.kind(), ty::Dynamic(_, _, ty::DynStar)), - "`unpack_dyn_star` only makes sense on `dyn*` types" - ); - let data = self.project_field(val, FieldIdx::ZERO)?; - let vtable = self.project_field(val, FieldIdx::ONE)?; - let vtable = self.read_pointer(&vtable.to_op(self)?)?; - let ty = self.get_ptr_vtable_ty(vtable, Some(expected_trait))?; - // `data` is already the right thing but has the wrong type. So we transmute it. - let layout = self.layout_of(ty)?; - let data = data.transmute(layout, self)?; - interp_ok(data) - } } diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index 7d76d925ef23e..06af7eeeea051 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -357,9 +357,6 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> { // arrays/slices ty::Array(..) | ty::Slice(..) => PathElem::ArrayElem(field), - // dyn* vtables - ty::Dynamic(_, _, ty::DynKind::DynStar) if field == 1 => PathElem::Vtable, - // dyn traits ty::Dynamic(..) => { assert_eq!(field, 0); diff --git a/compiler/rustc_const_eval/src/interpret/visitor.rs b/compiler/rustc_const_eval/src/interpret/visitor.rs index 5aea91233bda9..a27b664613159 100644 --- a/compiler/rustc_const_eval/src/interpret/visitor.rs +++ b/compiler/rustc_const_eval/src/interpret/visitor.rs @@ -6,7 +6,6 @@ use std::num::NonZero; use rustc_abi::{FieldIdx, FieldsShape, VariantIdx, Variants}; use rustc_index::IndexVec; use rustc_middle::mir::interpret::InterpResult; -use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, Ty}; use tracing::trace; @@ -102,26 +101,6 @@ pub trait ValueVisitor<'tcx, M: Machine<'tcx>>: Sized { // recurse with the inner type return self.visit_field(v, 0, &inner_mplace.into()); } - ty::Dynamic(data, _, ty::DynStar) => { - // DynStar types. Very different from a dyn type (but strangely part of the - // same variant in `TyKind`): These are pairs where the 2nd component is the - // vtable, and the first component is the data (which must be ptr-sized). - - // First make sure the vtable can be read at its type. - // The type of this vtable is fake, it claims to be a reference to some actual memory but that isn't true. - // So we transmute it to a raw pointer. - let raw_ptr_ty = Ty::new_mut_ptr(*self.ecx().tcx, self.ecx().tcx.types.unit); - let raw_ptr_ty = self.ecx().layout_of(raw_ptr_ty)?; - let vtable_field = self - .ecx() - .project_field(v, FieldIdx::ONE)? - .transmute(raw_ptr_ty, self.ecx())?; - self.visit_field(v, 1, &vtable_field)?; - - // Then unpack the first field, and continue. - let data = self.ecx().unpack_dyn_star(v, data)?; - return self.visit_field(v, 0, &data); - } // Slices do not need special handling here: they have `Array` field // placement with length 0, so we enter the `Array` case below which // indirectly uses the metadata to determine the actual length. diff --git a/compiler/rustc_feature/src/removed.rs b/compiler/rustc_feature/src/removed.rs index c54b831e24448..3757d4c0843c6 100644 --- a/compiler/rustc_feature/src/removed.rs +++ b/compiler/rustc_feature/src/removed.rs @@ -122,6 +122,9 @@ declare_features! ( /// [^1]: Formerly known as "object safe". (removed, dyn_compatible_for_dispatch, "1.87.0", Some(43561), Some("removed, not used heavily and represented additional complexity in dyn compatibility"), 136522), + /// Allows `dyn* Trait` objects. + (removed, dyn_star, "1.65.0", Some(102425), + Some("removed as it was no longer necessary for AFIDT (async fn in dyn trait) support")), /// Uses generic effect parameters for ~const bounds (removed, effects, "1.84.0", Some(102090), Some("removed, redundant with `#![feature(const_trait_impl)]`"), 132479), diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index d9d5334615a3b..923653bd1345a 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -481,8 +481,6 @@ declare_features! ( (unstable, doc_cfg_hide, "1.57.0", Some(43781)), /// Allows `#[doc(masked)]`. (unstable, doc_masked, "1.21.0", Some(44027)), - /// Allows `dyn* Trait` objects. - (incomplete, dyn_star, "1.65.0", Some(102425)), /// Allows the .use postfix syntax `x.use` and use closures `use |x| { ... }` (incomplete, ergonomic_clones, "1.87.0", Some(132290)), /// Allows exhaustive pattern matching on types that contain uninhabited types. diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 679904c7cfe4e..30d2a2818f930 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -956,7 +956,7 @@ impl<'hir> Generics<'hir> { && let Some(ret_ty) = segment.args().paren_sugar_output() && let ret_ty = ret_ty.peel_refs() && let TyKind::TraitObject(_, tagged_ptr) = ret_ty.kind - && let TraitObjectSyntax::Dyn | TraitObjectSyntax::DynStar = tagged_ptr.tag() + && let TraitObjectSyntax::Dyn = tagged_ptr.tag() && ret_ty.span.can_be_used_for_suggestions() { Some(ret_ty.span) diff --git a/compiler/rustc_hir/src/hir/tests.rs b/compiler/rustc_hir/src/hir/tests.rs index 1fd793bc1616f..4f9609fd360d7 100644 --- a/compiler/rustc_hir/src/hir/tests.rs +++ b/compiler/rustc_hir/src/hir/tests.rs @@ -45,7 +45,6 @@ define_tests! { #[test] fn trait_object_roundtrips() { trait_object_roundtrips_impl(TraitObjectSyntax::Dyn); - trait_object_roundtrips_impl(TraitObjectSyntax::DynStar); trait_object_roundtrips_impl(TraitObjectSyntax::None); } diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index baf3b9b5bc9e0..1d7b56eef67c0 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -2433,7 +2433,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { } else { let repr = match repr { TraitObjectSyntax::Dyn | TraitObjectSyntax::None => ty::Dyn, - TraitObjectSyntax::DynStar => ty::DynStar, }; self.lower_trait_object_ty(hir_ty.span, hir_ty.hir_id, bounds, lifetime, repr) } diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index ff87d3dec6e96..e6ffed753b5b6 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -420,7 +420,6 @@ impl<'a> State<'a> { let syntax = lifetime.tag(); match syntax { ast::TraitObjectSyntax::Dyn => self.word_nbsp("dyn"), - ast::TraitObjectSyntax::DynStar => self.word_nbsp("dyn*"), ast::TraitObjectSyntax::None => {} } let mut first = true; diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index 6f8abc1e67d29..3eeb0eac023a9 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -143,7 +143,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | ty::Coroutine(..) | ty::Adt(..) | ty::Never - | ty::Dynamic(_, _, ty::DynStar) | ty::Error(_) => { let guar = self .dcx() @@ -734,14 +733,6 @@ impl<'a, 'tcx> CastCheck<'tcx> { use rustc_middle::ty::cast::CastTy::*; use rustc_middle::ty::cast::IntTy::*; - if self.cast_ty.is_dyn_star() { - // This coercion will fail if the feature is not enabled, OR - // if the coercion is (currently) illegal (e.g. `dyn* Foo + Send` - // to `dyn* Foo`). Report "casting is invalid" rather than - // "non-primitive cast". - return Err(CastError::IllegalCast); - } - let (t_from, t_cast) = match (CastTy::from_ty(self.expr_ty), CastTy::from_ty(self.cast_ty)) { (Some(t_from), Some(t_cast)) => (t_from, t_cast), diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 24092c01125fc..cc4ffc214b6fa 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -232,9 +232,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { ty::Ref(r_b, _, mutbl_b) => { return self.coerce_borrowed_pointer(a, b, r_b, mutbl_b); } - ty::Dynamic(predicates, region, ty::DynStar) if self.tcx.features().dyn_star() => { - return self.coerce_dyn_star(a, b, predicates, region); - } ty::Adt(pin, _) if self.tcx.features().pin_ergonomics() && self.tcx.is_lang_item(pin.did(), hir::LangItem::Pin) => @@ -711,71 +708,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { Ok(coercion) } - fn coerce_dyn_star( - &self, - a: Ty<'tcx>, - b: Ty<'tcx>, - predicates: &'tcx ty::List>, - b_region: ty::Region<'tcx>, - ) -> CoerceResult<'tcx> { - if !self.tcx.features().dyn_star() { - return Err(TypeError::Mismatch); - } - - // FIXME(dyn_star): We should probably allow things like casting from - // `dyn* Foo + Send` to `dyn* Foo`. - if let ty::Dynamic(a_data, _, ty::DynStar) = a.kind() - && let ty::Dynamic(b_data, _, ty::DynStar) = b.kind() - && a_data.principal_def_id() == b_data.principal_def_id() - { - return self.unify(a, b); - } - - // Check the obligations of the cast -- for example, when casting - // `usize` to `dyn* Clone + 'static`: - let obligations = predicates - .iter() - .map(|predicate| { - // For each existential predicate (e.g., `?Self: Clone`) instantiate - // the type of the expression (e.g., `usize` in our example above) - // and then require that the resulting predicate (e.g., `usize: Clone`) - // holds (it does). - let predicate = predicate.with_self_ty(self.tcx, a); - Obligation::new(self.tcx, self.cause.clone(), self.param_env, predicate) - }) - .chain([ - // Enforce the region bound (e.g., `usize: 'static`, in our example). - Obligation::new( - self.tcx, - self.cause.clone(), - self.param_env, - ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives( - ty::OutlivesPredicate(a, b_region), - ))), - ), - // Enforce that the type is `usize`/pointer-sized. - Obligation::new( - self.tcx, - self.cause.clone(), - self.param_env, - ty::TraitRef::new( - self.tcx, - self.tcx.require_lang_item(hir::LangItem::PointerLike, self.cause.span), - [a], - ), - ), - ]) - .collect(); - - Ok(InferOk { - value: ( - vec![Adjustment { kind: Adjust::Pointer(PointerCoercion::DynStar), target: b }], - b, - ), - obligations, - }) - } - /// Applies reborrowing for `Pin` /// /// We currently only support reborrowing `Pin<&mut T>` as `Pin<&mut T>`. This is accomplished diff --git a/compiler/rustc_middle/src/ty/adjustment.rs b/compiler/rustc_middle/src/ty/adjustment.rs index 3bacdfe5ac880..74573455f531a 100644 --- a/compiler/rustc_middle/src/ty/adjustment.rs +++ b/compiler/rustc_middle/src/ty/adjustment.rs @@ -36,9 +36,6 @@ pub enum PointerCoercion { /// type. Codegen backends and miri figure out what has to be done /// based on the precise source/target type at hand. Unsize, - - /// Go from a pointer-like type to a `dyn*` object. - DynStar, } /// Represents coercing a value to a different type of value. diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 5cb943b0d8c66..43f5648fbd27e 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -946,21 +946,6 @@ where } } - ty::Dynamic(_, _, ty::DynStar) => { - if i == 0 { - TyMaybeWithLayout::Ty(Ty::new_mut_ptr(tcx, tcx.types.unit)) - } else if i == 1 { - // FIXME(dyn-star) same FIXME as above applies here too - TyMaybeWithLayout::Ty(Ty::new_imm_ref( - tcx, - tcx.lifetimes.re_static, - Ty::new_array(tcx, tcx.types.usize, 3), - )) - } else { - bug!("no field {i} on dyn*") - } - } - ty::Alias(..) | ty::Bound(..) | ty::Placeholder(..) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index c10277c75a79b..973a19d2e607d 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -810,7 +810,6 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { } match repr { ty::Dyn => p!("dyn "), - ty::DynStar => p!("dyn* "), } p!(print(data)); if print_r { diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 58829f72a72f0..4f8e4ba0d0894 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1310,11 +1310,6 @@ impl<'tcx> Ty<'tcx> { matches!(self.kind(), Dynamic(_, _, ty::Dyn)) } - #[inline] - pub fn is_dyn_star(self) -> bool { - matches!(self.kind(), Dynamic(_, _, ty::DynStar)) - } - #[inline] pub fn is_enum(self) -> bool { matches!(self.kind(), Adt(adt_def, _) if adt_def.is_enum()) @@ -1618,8 +1613,6 @@ impl<'tcx> Ty<'tcx> { | ty::Error(_) // Extern types have metadata = (). | ty::Foreign(..) - // `dyn*` has metadata = (). - | ty::Dynamic(_, _, ty::DynStar) // If returned by `struct_tail_raw` this is a unit struct // without any fields, or not a struct, and therefore is Sized. | ty::Adt(..) @@ -1809,8 +1802,7 @@ impl<'tcx> Ty<'tcx> { | ty::Closure(..) | ty::CoroutineClosure(..) | ty::Never - | ty::Error(_) - | ty::Dynamic(_, _, ty::DynStar) => true, + | ty::Error(_) => true, ty::Str | ty::Slice(_) | ty::Dynamic(_, _, ty::Dyn) => match sizedness { SizedTraitKind::Sized => false, diff --git a/compiler/rustc_mir_transform/src/mentioned_items.rs b/compiler/rustc_mir_transform/src/mentioned_items.rs index 9fd8d81d64a26..f011d394f6162 100644 --- a/compiler/rustc_mir_transform/src/mentioned_items.rs +++ b/compiler/rustc_mir_transform/src/mentioned_items.rs @@ -74,8 +74,7 @@ impl<'tcx> Visitor<'tcx> for MentionedItemsVisitor<'_, 'tcx> { match *rvalue { // We need to detect unsizing casts that required vtables. mir::Rvalue::Cast( - mir::CastKind::PointerCoercion(PointerCoercion::Unsize, _) - | mir::CastKind::PointerCoercion(PointerCoercion::DynStar, _), + mir::CastKind::PointerCoercion(PointerCoercion::Unsize, _), ref operand, target_ty, ) => { diff --git a/compiler/rustc_mir_transform/src/validate.rs b/compiler/rustc_mir_transform/src/validate.rs index 7dcdd7999f285..cbb9bbfd12f9f 100644 --- a/compiler/rustc_mir_transform/src/validate.rs +++ b/compiler/rustc_mir_transform/src/validate.rs @@ -1260,9 +1260,6 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { self.fail(location, format!("Unsize coercion, but `{op_ty}` isn't coercible to `{target_type}`")); } } - CastKind::PointerCoercion(PointerCoercion::DynStar, _) => { - // FIXME(dyn-star): make sure nothing needs to be done here. - } CastKind::IntToInt | CastKind::IntToFloat => { let input_valid = op_ty.is_integral() || op_ty.is_char() || op_ty.is_bool(); let target_valid = target_type.is_numeric() || target_type.is_char(); diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index e90e32ebebb9f..eea22719042b4 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -694,8 +694,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { // have to instantiate all methods of the trait being cast to, so we // can build the appropriate vtable. mir::Rvalue::Cast( - mir::CastKind::PointerCoercion(PointerCoercion::Unsize, _) - | mir::CastKind::PointerCoercion(PointerCoercion::DynStar, _), + mir::CastKind::PointerCoercion(PointerCoercion::Unsize, _), ref operand, target_ty, ) => { @@ -710,9 +709,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { // This could also be a different Unsize instruction, like // from a fixed sized array to a slice. But we are only // interested in things that produce a vtable. - if (target_ty.is_trait() && !source_ty.is_trait()) - || (target_ty.is_dyn_star() && !source_ty.is_dyn_star()) - { + if target_ty.is_trait() && !source_ty.is_trait() { create_mono_items_for_vtable_methods( self.tcx, target_ty, @@ -1106,14 +1103,6 @@ fn find_tails_for_unsizing<'tcx>( find_tails_for_unsizing(tcx, source_field, target_field) } - // `T` as `dyn* Trait` unsizes *directly*. - // - // FIXME(dyn_star): This case is a bit awkward, b/c we're not really computing - // a tail here. We probably should handle this separately in the *caller* of - // this function, rather than returning something that is semantically different - // than what we return above. - (_, &ty::Dynamic(_, _, ty::DynStar)) => (source_ty, target_ty), - _ => bug!( "find_vtable_types_for_unsizing: invalid coercion {:?} -> {:?}", source_ty, @@ -1341,9 +1330,7 @@ fn visit_mentioned_item<'tcx>( // This could also be a different Unsize instruction, like // from a fixed sized array to a slice. But we are only // interested in things that produce a vtable. - if (target_ty.is_trait() && !source_ty.is_trait()) - || (target_ty.is_dyn_star() && !source_ty.is_dyn_star()) - { + if target_ty.is_trait() && !source_ty.is_trait() { create_mono_items_for_vtable_methods(tcx, target_ty, source_ty, span, output); } } diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs index f39d32260093c..852221fcd44f4 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs @@ -135,7 +135,6 @@ where | ty::Closure(..) | ty::CoroutineClosure(..) | ty::Never - | ty::Dynamic(_, _, ty::DynStar) | ty::Error(_) => Ok(ty::Binder::dummy(vec![])), // impl {Meta,}Sized for str, [T], dyn Trait 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 d51c87fe68e60..afd7d12b0345c 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 @@ -658,8 +658,7 @@ where | ty::Coroutine(..) | ty::CoroutineWitness(..) | ty::Never - | ty::Foreign(..) - | ty::Dynamic(_, _, ty::DynStar) => Ty::new_unit(cx), + | ty::Foreign(..) => Ty::new_unit(cx), ty::Error(e) => Ty::new_error(cx, e), diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 620a34044d12e..44acd0a1718b4 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -796,16 +796,10 @@ impl<'a> Parser<'a> { /// /// Note that this does *not* parse bare trait objects. fn parse_dyn_ty(&mut self, impl_dyn_multi: &mut bool) -> PResult<'a, TyKind> { - let lo = self.token.span; self.bump(); // `dyn` - // parse dyn* types - let syntax = if self.eat(exp!(Star)) { - self.psess.gated_spans.gate(sym::dyn_star, lo.to(self.prev_token.span)); - TraitObjectSyntax::DynStar - } else { - TraitObjectSyntax::Dyn - }; + // We used to parse `*` for `dyn*` here. + let syntax = TraitObjectSyntax::Dyn; // Always parse bounds greedily for better error recovery. let bounds = self.parse_generic_bounds()?; diff --git a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs index 9d1d3412f8d23..f4a14b36ce5cf 100644 --- a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs +++ b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs @@ -631,7 +631,6 @@ pub(crate) fn encode_ty<'tcx>( // vendor extended type. let mut s = String::from(match kind { ty::Dyn => "u3dynI", - ty::DynStar => "u7dynstarI", }); s.push_str(&encode_predicates(tcx, predicates, dict, options)); s.push_str(&encode_region(*region, dict)); diff --git a/compiler/rustc_smir/src/rustc_internal/internal.rs b/compiler/rustc_smir/src/rustc_internal/internal.rs index c0d9937e34de6..9b73179244c05 100644 --- a/compiler/rustc_smir/src/rustc_internal/internal.rs +++ b/compiler/rustc_smir/src/rustc_internal/internal.rs @@ -369,7 +369,6 @@ impl RustcInternal for DynKind { fn internal<'tcx>(&self, _tables: &mut Tables<'_>, _tcx: TyCtxt<'tcx>) -> Self::T<'tcx> { match self { DynKind::Dyn => rustc_ty::DynKind::Dyn, - DynKind::DynStar => rustc_ty::DynKind::DynStar, } } } diff --git a/compiler/rustc_smir/src/rustc_smir/convert/mir.rs b/compiler/rustc_smir/src/rustc_smir/convert/mir.rs index 42b3e59b73ab9..6da12e5ba42a2 100644 --- a/compiler/rustc_smir/src/rustc_smir/convert/mir.rs +++ b/compiler/rustc_smir/src/rustc_smir/convert/mir.rs @@ -301,11 +301,9 @@ impl<'tcx> Stable<'tcx> for mir::CastKind { type T = stable_mir::mir::CastKind; fn stable(&self, tables: &mut Tables<'_>) -> Self::T { use rustc_middle::mir::CastKind::*; - use rustc_middle::ty::adjustment::PointerCoercion; match self { PointerExposeProvenance => stable_mir::mir::CastKind::PointerExposeAddress, PointerWithExposedProvenance => stable_mir::mir::CastKind::PointerWithExposedProvenance, - PointerCoercion(PointerCoercion::DynStar, _) => stable_mir::mir::CastKind::DynStar, PointerCoercion(c, _) => stable_mir::mir::CastKind::PointerCoercion(c.stable(tables)), IntToInt => stable_mir::mir::CastKind::IntToInt, FloatToInt => stable_mir::mir::CastKind::FloatToInt, diff --git a/compiler/rustc_smir/src/rustc_smir/convert/ty.rs b/compiler/rustc_smir/src/rustc_smir/convert/ty.rs index 2c652c7546e9c..dccbeb3eefbcf 100644 --- a/compiler/rustc_smir/src/rustc_smir/convert/ty.rs +++ b/compiler/rustc_smir/src/rustc_smir/convert/ty.rs @@ -43,7 +43,6 @@ impl<'tcx> Stable<'tcx> for ty::DynKind { fn stable(&self, _: &mut Tables<'_>) -> Self::T { match self { ty::Dyn => stable_mir::ty::DynKind::Dyn, - ty::DynStar => stable_mir::ty::DynKind::DynStar, } } } @@ -120,7 +119,6 @@ impl<'tcx> Stable<'tcx> for ty::adjustment::PointerCoercion { } PointerCoercion::ArrayToPointer => stable_mir::mir::PointerCoercion::ArrayToPointer, PointerCoercion::Unsize => stable_mir::mir::PointerCoercion::Unsize, - PointerCoercion::DynStar => unreachable!("represented as `CastKind::DynStar` in smir"), } } } diff --git a/compiler/rustc_smir/src/stable_mir/mir/body.rs b/compiler/rustc_smir/src/stable_mir/mir/body.rs index 660cd7db0800d..93c215880d15c 100644 --- a/compiler/rustc_smir/src/stable_mir/mir/body.rs +++ b/compiler/rustc_smir/src/stable_mir/mir/body.rs @@ -1021,8 +1021,6 @@ pub enum CastKind { PointerExposeAddress, PointerWithExposedProvenance, PointerCoercion(PointerCoercion), - // FIXME(smir-rename): change this to PointerCoercion(DynStar) - DynStar, IntToInt, FloatToInt, FloatToFloat, diff --git a/compiler/rustc_smir/src/stable_mir/ty.rs b/compiler/rustc_smir/src/stable_mir/ty.rs index 1ae79491642d5..b4afedeabebc3 100644 --- a/compiler/rustc_smir/src/stable_mir/ty.rs +++ b/compiler/rustc_smir/src/stable_mir/ty.rs @@ -1199,7 +1199,6 @@ pub enum BoundRegionKind { #[derive(Clone, Debug, Eq, PartialEq, Serialize)] pub enum DynKind { Dyn, - DynStar, } #[derive(Clone, Debug, Eq, PartialEq, Serialize)] diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index 1db8ad72b321c..fe0f8e6113ef7 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -576,8 +576,6 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> { ty::Dynamic(predicates, r, kind) => { self.push(match kind { ty::Dyn => "D", - // FIXME(dyn-star): need to update v0 mangling docs - ty::DynStar => "D*", }); self.print_dyn_existential(predicates)?; r.print(self)?; diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs index be508c8cee13e..0155983d6c263 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs @@ -353,26 +353,6 @@ impl Trait for X { )); } } - (ty::Dynamic(t, _, ty::DynKind::DynStar), _) - if let Some(def_id) = t.principal_def_id() => - { - let mut has_matching_impl = false; - tcx.for_each_relevant_impl(def_id, values.found, |did| { - if DeepRejectCtxt::relate_rigid_infer(tcx) - .types_may_unify(values.found, tcx.type_of(did).skip_binder()) - { - has_matching_impl = true; - } - }); - if has_matching_impl { - let trait_name = tcx.item_name(def_id); - diag.help(format!( - "`{}` implements `{trait_name}`, `#[feature(dyn_star)]` is likely \ - not enabled; that feature it is currently incomplete", - values.found, - )); - } - } (_, ty::Alias(ty::Opaque, opaque_ty)) | (ty::Alias(ty::Opaque, opaque_ty), _) => { if opaque_ty.def_id.is_local() diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 9c0ccb26e53f6..bf84798f1d38d 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2121,7 +2121,6 @@ impl<'tcx> SelectionContext<'_, 'tcx> { | ty::Closure(..) | ty::CoroutineClosure(..) | ty::Never - | ty::Dynamic(_, _, ty::DynStar) | ty::Error(_) => { // safe for everything Where(ty::Binder::dummy(Vec::new())) diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index d52228224614b..a225b712d4b20 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -449,14 +449,6 @@ fn layout_of_uncached<'tcx>( tcx.mk_layout(LayoutData::scalar_pair(cx, data_ptr, metadata)) } - ty::Dynamic(_, _, ty::DynStar) => { - let mut data = scalar_unit(Pointer(AddressSpace::DATA)); - data.valid_range_mut().start = 0; - let mut vtable = scalar_unit(Pointer(AddressSpace::DATA)); - vtable.valid_range_mut().start = 1; - tcx.mk_layout(LayoutData::scalar_pair(cx, data, vtable)) - } - // Arrays and slices. ty::Array(element, count) => { let count = extract_const_value(cx, ty, count)? diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index d996ee2b60aa4..ff8d504cd87e4 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -38,8 +38,7 @@ fn sizedness_constraint_for_ty<'tcx>( | ty::CoroutineClosure(..) | ty::Coroutine(..) | ty::CoroutineWitness(..) - | ty::Never - | ty::Dynamic(_, _, ty::DynStar) => None, + | ty::Never => None, ty::Str | ty::Slice(..) | ty::Dynamic(_, _, ty::Dyn) => match sizedness { // Never `Sized` @@ -383,8 +382,7 @@ fn impl_self_is_guaranteed_unsized<'tcx>(tcx: TyCtxt<'tcx>, impl_def_id: DefId) | ty::Bound(_, _) | ty::Placeholder(_) | ty::Infer(_) - | ty::Error(_) - | ty::Dynamic(_, _, ty::DynStar) => false, + | ty::Error(_) => false, } } diff --git a/compiler/rustc_type_ir/src/inherent.rs b/compiler/rustc_type_ir/src/inherent.rs index 608efc7515ca9..e53922b179508 100644 --- a/compiler/rustc_type_ir/src/inherent.rs +++ b/compiler/rustc_type_ir/src/inherent.rs @@ -183,8 +183,7 @@ pub trait Ty>: | ty::Bound(_, _) | ty::Placeholder(_) | ty::Infer(_) - | ty::Error(_) - | ty::Dynamic(_, _, ty::DynStar) => false, + | ty::Error(_) => false, } } } diff --git a/compiler/rustc_type_ir/src/ty_kind.rs b/compiler/rustc_type_ir/src/ty_kind.rs index 9669772d1a681..db6fbefcf05cc 100644 --- a/compiler/rustc_type_ir/src/ty_kind.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -20,6 +20,9 @@ use crate::{self as ty, DebruijnIndex, Interner}; mod closure; /// Specifies how a trait object is represented. +/// +/// This used to have a variant `DynStar`, but that variant has been removed, +/// and it's likely this whole enum will be removed soon. #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] #[cfg_attr( feature = "nightly", @@ -28,13 +31,6 @@ mod closure; pub enum DynKind { /// An unsized `dyn Trait` object Dyn, - /// A sized `dyn* Trait` object - /// - /// These objects are represented as a `(data, vtable)` pair where `data` is a value of some - /// ptr-sized and ptr-aligned dynamically determined type `T` and `vtable` is a pointer to the - /// vtable of `impl T for Trait`. This allows a `dyn*` object to be treated agnostically with - /// respect to whether it points to a `Box`, `Rc`, etc. - DynStar, } #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] @@ -371,7 +367,6 @@ impl fmt::Debug for TyKind { UnsafeBinder(binder) => write!(f, "{:?}", binder), Dynamic(p, r, repr) => match repr { DynKind::Dyn => write!(f, "dyn {p:?} + {r:?}"), - DynKind::DynStar => write!(f, "dyn* {p:?} + {r:?}"), }, Closure(d, s) => f.debug_tuple("Closure").field(d).field(&s).finish(), CoroutineClosure(d, s) => f.debug_tuple("CoroutineClosure").field(d).field(&s).finish(), diff --git a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs index e629012b187cd..6a9e41cbf7958 100644 --- a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs +++ b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs @@ -160,10 +160,6 @@ fn check_rvalue<'tcx>( Rvalue::Cast(CastKind::PointerExposeProvenance, _, _) => { Err((span, "casting pointers to ints is unstable in const fn".into())) }, - Rvalue::Cast(CastKind::PointerCoercion(PointerCoercion::DynStar, _), _, _) => { - // FIXME(dyn-star) - unimplemented!() - }, Rvalue::Cast(CastKind::Transmute, _, _) => Err(( span, "transmute can attempt to turn pointers into integers, so is unstable in const fn".into(), diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs index 4edecc864dd42..f5c38f88d8f78 100644 --- a/src/tools/miri/src/helpers.rs +++ b/src/tools/miri/src/helpers.rs @@ -595,10 +595,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } else if matches!(v.layout.fields, FieldsShape::Union(..)) { // A (non-frozen) union. We fall back to whatever the type says. (self.unsafe_cell_action)(v) - } else if matches!(v.layout.ty.kind(), ty::Dynamic(_, _, ty::DynStar)) { - // This needs to read the vtable pointer to proceed type-driven, but we don't - // want to reentrantly read from memory here. - (self.unsafe_cell_action)(v) } else { // We want to not actually read from memory for this visit. So, before // walking this value, we have to make sure it is not a diff --git a/src/tools/miri/tests/pass/dyn-star.rs b/src/tools/miri/tests/pass/dyn-star.rs deleted file mode 100644 index 1ce0dd3c9d50d..0000000000000 --- a/src/tools/miri/tests/pass/dyn-star.rs +++ /dev/null @@ -1,103 +0,0 @@ -#![feature(dyn_star)] -#![allow(incomplete_features)] -#![feature(custom_inner_attributes)] -// rustfmt destroys `dyn* Trait` syntax -#![rustfmt::skip] - -use std::fmt::{Debug, Display}; - -fn main() { - make_dyn_star(); - method(); - box_(); - dispatch_on_pin_mut(); - dyn_star_to_dyn(); - dyn_to_dyn_star(); -} - -fn dyn_star_to_dyn() { - let x: dyn* Debug = &42; - let x = Box::new(x) as Box; - assert_eq!("42", format!("{x:?}")); -} - -fn dyn_to_dyn_star() { - let x: Box = Box::new(42); - let x = &x as dyn* Debug; - assert_eq!("42", format!("{x:?}")); -} - -fn make_dyn_star() { - fn make_dyn_star_coercion(i: usize) { - let _dyn_i: dyn* Debug = i; - } - - fn make_dyn_star_explicit(i: usize) { - let _dyn_i: dyn* Debug = i as dyn* Debug; - } - - make_dyn_star_coercion(42); - make_dyn_star_explicit(42); -} - -fn method() { - trait Foo { - fn get(&self) -> usize; - } - - impl Foo for usize { - fn get(&self) -> usize { - *self - } - } - - fn invoke_dyn_star(i: dyn* Foo) -> usize { - i.get() - } - - fn make_and_invoke_dyn_star(i: usize) -> usize { - let dyn_i: dyn* Foo = i; - invoke_dyn_star(dyn_i) - } - - assert_eq!(make_and_invoke_dyn_star(42), 42); -} - -fn box_() { - fn make_dyn_star() -> dyn* Display { - Box::new(42) as dyn* Display - } - - let x = make_dyn_star(); - assert_eq!(format!("{x}"), "42"); -} - -fn dispatch_on_pin_mut() { - use std::future::Future; - - async fn foo(f: dyn* Future) { - println!("dispatch_on_pin_mut: value: {}", f.await); - } - - async fn async_main() { - foo(Box::pin(async { 1 })).await - } - - // ------------------------------------------------------------------------- // - // Implementation Details Below... - - use std::pin::Pin; - use std::task::*; - - let mut fut = async_main(); - - // Poll loop, just to test the future... - let ctx = &mut Context::from_waker(Waker::noop()); - - loop { - match unsafe { Pin::new_unchecked(&mut fut).poll(ctx) } { - Poll::Pending => {} - Poll::Ready(()) => break, - } - } -} diff --git a/src/tools/rustfmt/src/types.rs b/src/tools/rustfmt/src/types.rs index 7ec1032dcb421..dd1515805e54b 100644 --- a/src/tools/rustfmt/src/types.rs +++ b/src/tools/rustfmt/src/types.rs @@ -835,12 +835,6 @@ impl Rewrite for ast::Ty { .max_width_error(shape.width, self.span())?; (shape, "dyn ") } - ast::TraitObjectSyntax::DynStar => { - let shape = shape - .offset_left(5) - .max_width_error(shape.width, self.span())?; - (shape, "dyn* ") - } ast::TraitObjectSyntax::None => (shape, ""), }; let mut res = bounds.rewrite_result(context, shape)?; diff --git a/src/tools/rustfmt/tests/target/issue_5542.rs b/src/tools/rustfmt/tests/target/issue_5542.rs deleted file mode 100644 index 730bb7b681aed..0000000000000 --- a/src/tools/rustfmt/tests/target/issue_5542.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![feature(dyn_star)] -#![allow(incomplete_features)] - -use core::fmt::Debug; - -fn main() { - let i = 42; - let dyn_i = i as dyn* Debug; - dbg!(dyn_i); -} diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt index 24356c31da49a..10fce73ac908f 100644 --- a/src/tools/tidy/src/issues.txt +++ b/src/tools/tidy/src/issues.txt @@ -930,7 +930,6 @@ ui/dst/issue-90528-unsizing-suggestion-3.rs ui/dst/issue-90528-unsizing-suggestion-4.rs ui/dyn-keyword/issue-5153.rs ui/dyn-keyword/issue-56327-dyn-trait-in-macro-is-okay.rs -ui/dyn-star/issue-102430.rs ui/empty/issue-37026.rs ui/entry-point/issue-118772.rs ui/enum-discriminant/auxiliary/issue-41394.rs diff --git a/tests/codegen/function-arguments.rs b/tests/codegen/function-arguments.rs index f0708a7a109f2..c8cd8526ae513 100644 --- a/tests/codegen/function-arguments.rs +++ b/tests/codegen/function-arguments.rs @@ -1,7 +1,6 @@ //@ compile-flags: -Copt-level=3 -C no-prepopulate-passes #![crate_type = "lib"] #![feature(rustc_attrs)] -#![feature(dyn_star)] #![feature(allocator_api)] use std::marker::PhantomPinned; @@ -277,11 +276,3 @@ pub fn enum_id_1(x: Option>) -> Option> { pub fn enum_id_2(x: Option) -> Option { x } - -// CHECK: { ptr, {{.+}} } @dyn_star(ptr noundef %x.0, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}) %x.1) -// Expect an ABI something like `{ {}*, [3 x i64]* }`, but that's hard to match on generically, -// so do like the `trait_box` test and just match on `{{.+}}` for the vtable. -#[no_mangle] -pub fn dyn_star(x: dyn* Drop) -> dyn* Drop { - x -} diff --git a/tests/crashes/116979.rs b/tests/crashes/116979.rs deleted file mode 100644 index 28bbc972ea340..0000000000000 --- a/tests/crashes/116979.rs +++ /dev/null @@ -1,14 +0,0 @@ -//@ known-bug: #116979 -//@ compile-flags: -Csymbol-mangling-version=v0 -//@ needs-rustc-debug-assertions - -#![feature(dyn_star)] -#![allow(incomplete_features)] - -use std::fmt::Display; - -pub fn require_dyn_star_display(_: dyn* Display) {} - -fn main() { - require_dyn_star_display(1usize); -} diff --git a/tests/crashes/119694.rs b/tests/crashes/119694.rs deleted file mode 100644 index f655ea1cd343c..0000000000000 --- a/tests/crashes/119694.rs +++ /dev/null @@ -1,18 +0,0 @@ -//@ known-bug: #119694 -#![feature(dyn_star)] - -trait Trait { - fn foo(self); -} - -impl Trait for usize { - fn foo(self) {} -} - -fn bar(x: dyn* Trait) { - x.foo(); -} - -fn main() { - bar(0usize); -} diff --git a/tests/ui/SUMMARY.md b/tests/ui/SUMMARY.md index d807e38dab284..23124bb18b0d3 100644 --- a/tests/ui/SUMMARY.md +++ b/tests/ui/SUMMARY.md @@ -482,10 +482,6 @@ The `dyn` keyword is used to highlight that calls to methods on the associated T See [`dyn` keyword](https://doc.rust-lang.org/std/keyword.dyn.html). -## `tests/ui/dyn-star/`: `dyn*`, Sized `dyn`, `#![feature(dyn_star)]` - -See [Tracking issue for dyn-star #102425](https://github.com/rust-lang/rust/issues/102425). - ## `tests/ui/editions/`: Rust edition-specific peculiarities These tests run in specific Rust editions, such as Rust 2015 or Rust 2018, and check errors and functionality related to specific now-deprecated idioms and features. diff --git a/tests/ui/dyn-star/align.normal.stderr b/tests/ui/dyn-star/align.normal.stderr deleted file mode 100644 index d3ee0d3e550ec..0000000000000 --- a/tests/ui/dyn-star/align.normal.stderr +++ /dev/null @@ -1,20 +0,0 @@ -warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/align.rs:3:12 - | -LL | #![feature(dyn_star)] - | ^^^^^^^^ - | - = note: see issue #102425 for more information - = note: `#[warn(incomplete_features)]` on by default - -error[E0277]: `AlignedUsize` needs to have the same ABI as a pointer - --> $DIR/align.rs:14:13 - | -LL | let x = AlignedUsize(12) as dyn* Debug; - | ^^^^^^^^^^^^^^^^ `AlignedUsize` needs to be a pointer-like type - | - = help: the trait `PointerLike` is not implemented for `AlignedUsize` - -error: aborting due to 1 previous error; 1 warning emitted - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/dyn-star/align.over_aligned.stderr b/tests/ui/dyn-star/align.over_aligned.stderr deleted file mode 100644 index d3ee0d3e550ec..0000000000000 --- a/tests/ui/dyn-star/align.over_aligned.stderr +++ /dev/null @@ -1,20 +0,0 @@ -warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/align.rs:3:12 - | -LL | #![feature(dyn_star)] - | ^^^^^^^^ - | - = note: see issue #102425 for more information - = note: `#[warn(incomplete_features)]` on by default - -error[E0277]: `AlignedUsize` needs to have the same ABI as a pointer - --> $DIR/align.rs:14:13 - | -LL | let x = AlignedUsize(12) as dyn* Debug; - | ^^^^^^^^^^^^^^^^ `AlignedUsize` needs to be a pointer-like type - | - = help: the trait `PointerLike` is not implemented for `AlignedUsize` - -error: aborting due to 1 previous error; 1 warning emitted - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/dyn-star/align.rs b/tests/ui/dyn-star/align.rs deleted file mode 100644 index f9ef7063231c9..0000000000000 --- a/tests/ui/dyn-star/align.rs +++ /dev/null @@ -1,16 +0,0 @@ -//@ revisions: normal over_aligned - -#![feature(dyn_star)] -//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - -use std::fmt::Debug; - -#[cfg_attr(over_aligned, repr(C, align(1024)))] -#[cfg_attr(not(over_aligned), repr(C))] -#[derive(Debug)] -struct AlignedUsize(usize); - -fn main() { - let x = AlignedUsize(12) as dyn* Debug; - //~^ ERROR `AlignedUsize` needs to have the same ABI as a pointer -} diff --git a/tests/ui/dyn-star/async-block-dyn-star.rs b/tests/ui/dyn-star/async-block-dyn-star.rs deleted file mode 100644 index db133d94c9187..0000000000000 --- a/tests/ui/dyn-star/async-block-dyn-star.rs +++ /dev/null @@ -1,9 +0,0 @@ -//@ edition:2018 - -#![feature(dyn_star, const_async_blocks)] -//~^ WARN the feature `dyn_star` is incomplete - -static S: dyn* Send + Sync = async { 42 }; -//~^ ERROR needs to have the same ABI as a pointer - -pub fn main() {} diff --git a/tests/ui/dyn-star/async-block-dyn-star.stderr b/tests/ui/dyn-star/async-block-dyn-star.stderr deleted file mode 100644 index f62c85c0ad202..0000000000000 --- a/tests/ui/dyn-star/async-block-dyn-star.stderr +++ /dev/null @@ -1,20 +0,0 @@ -warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/async-block-dyn-star.rs:3:12 - | -LL | #![feature(dyn_star, const_async_blocks)] - | ^^^^^^^^ - | - = note: see issue #102425 for more information - = note: `#[warn(incomplete_features)]` on by default - -error[E0277]: `{async block@$DIR/async-block-dyn-star.rs:6:30: 6:35}` needs to have the same ABI as a pointer - --> $DIR/async-block-dyn-star.rs:6:30 - | -LL | static S: dyn* Send + Sync = async { 42 }; - | ^^^^^^^^^^^^ `{async block@$DIR/async-block-dyn-star.rs:6:30: 6:35}` needs to be a pointer-like type - | - = help: the trait `PointerLike` is not implemented for `{async block@$DIR/async-block-dyn-star.rs:6:30: 6:35}` - -error: aborting due to 1 previous error; 1 warning emitted - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/dyn-star/auxiliary/dyn-star-foreign.rs b/tests/ui/dyn-star/auxiliary/dyn-star-foreign.rs deleted file mode 100644 index ce892088f5000..0000000000000 --- a/tests/ui/dyn-star/auxiliary/dyn-star-foreign.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![feature(dyn_star)] - -use std::fmt::Display; - -pub fn require_dyn_star_display(_: dyn* Display) {} - -fn works_locally() { - require_dyn_star_display(1usize); -} diff --git a/tests/ui/dyn-star/box.rs b/tests/ui/dyn-star/box.rs deleted file mode 100644 index f1c9fd1a01e66..0000000000000 --- a/tests/ui/dyn-star/box.rs +++ /dev/null @@ -1,20 +0,0 @@ -//@ run-pass -//@ revisions: current next -//@ ignore-compare-mode-next-solver (explicit revisions) -//@[current] compile-flags: -C opt-level=0 -//@[next] compile-flags: -Znext-solver -C opt-level=0 - -#![feature(dyn_star)] -#![allow(incomplete_features)] - -use std::fmt::Display; - -fn make_dyn_star() -> dyn* Display { - Box::new(42) as dyn* Display -} - -fn main() { - let x = make_dyn_star(); - - println!("{x}"); -} diff --git a/tests/ui/dyn-star/cell.rs b/tests/ui/dyn-star/cell.rs deleted file mode 100644 index f4c7927a39dc9..0000000000000 --- a/tests/ui/dyn-star/cell.rs +++ /dev/null @@ -1,34 +0,0 @@ -// This test with Cell also indirectly exercises UnsafeCell in dyn*. -// -//@ run-pass - -#![feature(dyn_star)] -#![allow(incomplete_features)] - -use std::cell::Cell; - -trait Rw { - fn read(&self) -> T; - fn write(&self, v: T); -} - -impl Rw for Cell { - fn read(&self) -> T { - self.get() - } - fn write(&self, v: T) { - self.set(v) - } -} - -fn make_dyn_star() -> dyn* Rw { - Cell::new(42usize) as dyn* Rw -} - -fn main() { - let x = make_dyn_star(); - - assert_eq!(x.read(), 42); - x.write(24); - assert_eq!(x.read(), 24); -} diff --git a/tests/ui/dyn-star/check-size-at-cast-polymorphic-bad.current.stderr b/tests/ui/dyn-star/check-size-at-cast-polymorphic-bad.current.stderr deleted file mode 100644 index a0aff69f39681..0000000000000 --- a/tests/ui/dyn-star/check-size-at-cast-polymorphic-bad.current.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error[E0277]: `&T` needs to have the same ABI as a pointer - --> $DIR/check-size-at-cast-polymorphic-bad.rs:15:15 - | -LL | fn polymorphic(t: &T) { - | - this type parameter needs to be `Sized` -LL | dyn_debug(t); - | ^ `&T` needs to be a pointer-like type - | - = note: required for `&T` to implement `PointerLike` -help: consider removing the `?Sized` bound to make the type parameter `Sized` - | -LL - fn polymorphic(t: &T) { -LL + fn polymorphic(t: &T) { - | - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/dyn-star/check-size-at-cast-polymorphic-bad.next.stderr b/tests/ui/dyn-star/check-size-at-cast-polymorphic-bad.next.stderr deleted file mode 100644 index a0aff69f39681..0000000000000 --- a/tests/ui/dyn-star/check-size-at-cast-polymorphic-bad.next.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error[E0277]: `&T` needs to have the same ABI as a pointer - --> $DIR/check-size-at-cast-polymorphic-bad.rs:15:15 - | -LL | fn polymorphic(t: &T) { - | - this type parameter needs to be `Sized` -LL | dyn_debug(t); - | ^ `&T` needs to be a pointer-like type - | - = note: required for `&T` to implement `PointerLike` -help: consider removing the `?Sized` bound to make the type parameter `Sized` - | -LL - fn polymorphic(t: &T) { -LL + fn polymorphic(t: &T) { - | - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/dyn-star/check-size-at-cast-polymorphic-bad.rs b/tests/ui/dyn-star/check-size-at-cast-polymorphic-bad.rs deleted file mode 100644 index acc293a5956e6..0000000000000 --- a/tests/ui/dyn-star/check-size-at-cast-polymorphic-bad.rs +++ /dev/null @@ -1,19 +0,0 @@ -//@ revisions: current next -//@ ignore-compare-mode-next-solver (explicit revisions) -//@[next] compile-flags: -Znext-solver - -#![feature(dyn_star)] -#![allow(incomplete_features)] - -use std::fmt::Debug; - -fn dyn_debug(_: (dyn* Debug + '_)) { - -} - -fn polymorphic(t: &T) { - dyn_debug(t); - //~^ ERROR `&T` needs to have the same ABI as a pointer -} - -fn main() {} diff --git a/tests/ui/dyn-star/check-size-at-cast-polymorphic.rs b/tests/ui/dyn-star/check-size-at-cast-polymorphic.rs deleted file mode 100644 index ceedbafd86b06..0000000000000 --- a/tests/ui/dyn-star/check-size-at-cast-polymorphic.rs +++ /dev/null @@ -1,16 +0,0 @@ -//@ check-pass - -#![feature(dyn_star)] -#![allow(incomplete_features)] - -use std::fmt::Debug; - -fn dyn_debug(_: (dyn* Debug + '_)) { - -} - -fn polymorphic(t: &T) { - dyn_debug(t); -} - -fn main() {} diff --git a/tests/ui/dyn-star/check-size-at-cast.rs b/tests/ui/dyn-star/check-size-at-cast.rs deleted file mode 100644 index e15e090b529ab..0000000000000 --- a/tests/ui/dyn-star/check-size-at-cast.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![feature(dyn_star)] -#![allow(incomplete_features)] - -use std::fmt::Debug; - -fn main() { - let i = [1, 2, 3, 4] as dyn* Debug; - //~^ ERROR `[i32; 4]` needs to have the same ABI as a pointer - dbg!(i); -} diff --git a/tests/ui/dyn-star/check-size-at-cast.stderr b/tests/ui/dyn-star/check-size-at-cast.stderr deleted file mode 100644 index b402403ee6fa1..0000000000000 --- a/tests/ui/dyn-star/check-size-at-cast.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0277]: `[i32; 4]` needs to have the same ABI as a pointer - --> $DIR/check-size-at-cast.rs:7:13 - | -LL | let i = [1, 2, 3, 4] as dyn* Debug; - | ^^^^^^^^^^^^ `[i32; 4]` needs to be a pointer-like type - | - = help: the trait `PointerLike` is not implemented for `[i32; 4]` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/dyn-star/const-and-static.rs b/tests/ui/dyn-star/const-and-static.rs deleted file mode 100644 index cbb64261a66c7..0000000000000 --- a/tests/ui/dyn-star/const-and-static.rs +++ /dev/null @@ -1,10 +0,0 @@ -//@ check-pass - -#![feature(dyn_star)] -//~^ WARN the feature `dyn_star` is incomplete - -const C: dyn* Send + Sync = &(); - -static S: dyn* Send + Sync = &(); - -fn main() {} diff --git a/tests/ui/dyn-star/const-and-static.stderr b/tests/ui/dyn-star/const-and-static.stderr deleted file mode 100644 index df8f42fb0f573..0000000000000 --- a/tests/ui/dyn-star/const-and-static.stderr +++ /dev/null @@ -1,11 +0,0 @@ -warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/const-and-static.rs:3:12 - | -LL | #![feature(dyn_star)] - | ^^^^^^^^ - | - = note: see issue #102425 for more information - = note: `#[warn(incomplete_features)]` on by default - -warning: 1 warning emitted - diff --git a/tests/ui/dyn-star/const.rs b/tests/ui/dyn-star/const.rs deleted file mode 100644 index 036d678dc022d..0000000000000 --- a/tests/ui/dyn-star/const.rs +++ /dev/null @@ -1,14 +0,0 @@ -//@ run-pass -#![feature(dyn_star)] -#![allow(unused, incomplete_features)] - -use std::fmt::Debug; - -fn make_dyn_star() { - let i = 42usize; - let dyn_i: dyn* Debug = i; -} - -fn main() { - make_dyn_star(); -} diff --git a/tests/ui/dyn-star/dispatch-on-pin-mut.rs b/tests/ui/dyn-star/dispatch-on-pin-mut.rs deleted file mode 100644 index be40fa30f0d98..0000000000000 --- a/tests/ui/dyn-star/dispatch-on-pin-mut.rs +++ /dev/null @@ -1,36 +0,0 @@ -//@ run-pass -//@ edition:2021 -//@ check-run-results - -#![feature(dyn_star)] -//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - -use std::future::Future; - -async fn foo(f: dyn* Future) { - println!("value: {}", f.await); -} - -async fn async_main() { - foo(Box::pin(async { 1 })).await -} - -// ------------------------------------------------------------------------- // -// Implementation Details Below... - -use std::pin::pin; -use std::task::*; - -fn main() { - let mut fut = pin!(async_main()); - - // Poll loop, just to test the future... - let ctx = &mut Context::from_waker(Waker::noop()); - - loop { - match fut.as_mut().poll(ctx) { - Poll::Pending => {} - Poll::Ready(()) => break, - } - } -} diff --git a/tests/ui/dyn-star/dispatch-on-pin-mut.run.stdout b/tests/ui/dyn-star/dispatch-on-pin-mut.run.stdout deleted file mode 100644 index 96c5ca6985ffd..0000000000000 --- a/tests/ui/dyn-star/dispatch-on-pin-mut.run.stdout +++ /dev/null @@ -1 +0,0 @@ -value: 1 diff --git a/tests/ui/dyn-star/dispatch-on-pin-mut.stderr b/tests/ui/dyn-star/dispatch-on-pin-mut.stderr deleted file mode 100644 index cb9c781581461..0000000000000 --- a/tests/ui/dyn-star/dispatch-on-pin-mut.stderr +++ /dev/null @@ -1,11 +0,0 @@ -warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/dispatch-on-pin-mut.rs:5:12 - | -LL | #![feature(dyn_star)] - | ^^^^^^^^ - | - = note: see issue #102425 for more information - = note: `#[warn(incomplete_features)]` on by default - -warning: 1 warning emitted - diff --git a/tests/ui/dyn-star/dont-unsize-coerce-dyn-star.rs b/tests/ui/dyn-star/dont-unsize-coerce-dyn-star.rs deleted file mode 100644 index abc66df8b3635..0000000000000 --- a/tests/ui/dyn-star/dont-unsize-coerce-dyn-star.rs +++ /dev/null @@ -1,27 +0,0 @@ -//@ run-pass -//@ check-run-results - -#![feature(dyn_star)] -//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - -trait AddOne { - fn add1(&mut self) -> usize; -} - -impl AddOne for usize { - fn add1(&mut self) -> usize { - *self += 1; - *self - } -} - -fn add_one(i: &mut (dyn* AddOne + '_)) -> usize { - i.add1() -} - -fn main() { - let mut x = 42usize as dyn* AddOne; - - println!("{}", add_one(&mut x)); - println!("{}", add_one(&mut x)); -} diff --git a/tests/ui/dyn-star/dont-unsize-coerce-dyn-star.run.stdout b/tests/ui/dyn-star/dont-unsize-coerce-dyn-star.run.stdout deleted file mode 100644 index b4db3ed707d8d..0000000000000 --- a/tests/ui/dyn-star/dont-unsize-coerce-dyn-star.run.stdout +++ /dev/null @@ -1,2 +0,0 @@ -43 -44 diff --git a/tests/ui/dyn-star/dont-unsize-coerce-dyn-star.stderr b/tests/ui/dyn-star/dont-unsize-coerce-dyn-star.stderr deleted file mode 100644 index bcd014f8dc32d..0000000000000 --- a/tests/ui/dyn-star/dont-unsize-coerce-dyn-star.stderr +++ /dev/null @@ -1,11 +0,0 @@ -warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/dont-unsize-coerce-dyn-star.rs:4:12 - | -LL | #![feature(dyn_star)] - | ^^^^^^^^ - | - = note: see issue #102425 for more information - = note: `#[warn(incomplete_features)]` on by default - -warning: 1 warning emitted - diff --git a/tests/ui/dyn-star/drop.rs b/tests/ui/dyn-star/drop.rs deleted file mode 100644 index bc74633152754..0000000000000 --- a/tests/ui/dyn-star/drop.rs +++ /dev/null @@ -1,28 +0,0 @@ -//@ run-pass -//@ check-run-results -#![feature(dyn_star, pointer_like_trait)] -#![allow(incomplete_features)] - -use std::fmt::Debug; -use std::marker::PointerLike; - -#[derive(Debug)] -#[repr(transparent)] -struct Foo(#[allow(dead_code)] usize); - -// FIXME(dyn_star): Make this into a derive. -impl PointerLike for Foo {} - -impl Drop for Foo { - fn drop(&mut self) { - println!("destructor called"); - } -} - -fn make_dyn_star(i: Foo) { - let _dyn_i: dyn* Debug = i; -} - -fn main() { - make_dyn_star(Foo(42)); -} diff --git a/tests/ui/dyn-star/drop.run.stdout b/tests/ui/dyn-star/drop.run.stdout deleted file mode 100644 index dadb33ccf3ac3..0000000000000 --- a/tests/ui/dyn-star/drop.run.stdout +++ /dev/null @@ -1 +0,0 @@ -destructor called diff --git a/tests/ui/dyn-star/dyn-async-trait.rs b/tests/ui/dyn-star/dyn-async-trait.rs deleted file mode 100644 index a673b26991085..0000000000000 --- a/tests/ui/dyn-star/dyn-async-trait.rs +++ /dev/null @@ -1,36 +0,0 @@ -//@ check-pass -//@ edition: 2021 - -// This test case is meant to demonstrate how close we can get to async -// functions in dyn traits with the current level of dyn* support. - -#![feature(dyn_star)] -#![allow(incomplete_features)] - -use std::future::Future; - -trait DynAsyncCounter { - fn increment<'a>(&'a mut self) -> dyn* Future + 'a; -} - -struct MyCounter { - count: usize, -} - -impl DynAsyncCounter for MyCounter { - fn increment<'a>(&'a mut self) -> dyn* Future + 'a { - Box::pin(async { - self.count += 1; - self.count - }) - } -} - -async fn do_counter(counter: &mut dyn DynAsyncCounter) -> usize { - counter.increment().await -} - -fn main() { - let mut counter = MyCounter { count: 0 }; - let _ = do_counter(&mut counter); -} diff --git a/tests/ui/dyn-star/dyn-pointer-like.rs b/tests/ui/dyn-star/dyn-pointer-like.rs deleted file mode 100644 index f26fa90505cf7..0000000000000 --- a/tests/ui/dyn-star/dyn-pointer-like.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Test that `dyn PointerLike` and `dyn* PointerLike` do not implement `PointerLike`. -// This used to ICE during codegen. - -#![crate_type = "lib"] - -#![feature(pointer_like_trait, dyn_star)] -#![feature(unsized_fn_params)] -#![expect(incomplete_features)] -#![expect(internal_features)] - -use std::marker::PointerLike; - -pub fn lol(x: dyn* PointerLike) { - foo(x); //~ ERROR `dyn* PointerLike` needs to have the same ABI as a pointer -} - -pub fn uwu(x: dyn PointerLike) { - foo(x); //~ ERROR `dyn PointerLike` needs to have the same ABI as a pointer -} - -fn foo(x: T) { - let _: dyn* PointerLike = x; -} diff --git a/tests/ui/dyn-star/dyn-pointer-like.stderr b/tests/ui/dyn-star/dyn-pointer-like.stderr deleted file mode 100644 index 4c558e92d3f91..0000000000000 --- a/tests/ui/dyn-star/dyn-pointer-like.stderr +++ /dev/null @@ -1,39 +0,0 @@ -error[E0277]: `dyn* PointerLike` needs to have the same ABI as a pointer - --> $DIR/dyn-pointer-like.rs:14:9 - | -LL | foo(x); - | --- ^ the trait `PointerLike` is not implemented for `dyn* PointerLike` - | | - | required by a bound introduced by this call - | - = note: the trait bound `dyn* PointerLike: PointerLike` is not satisfied -note: required by a bound in `foo` - --> $DIR/dyn-pointer-like.rs:21:11 - | -LL | fn foo(x: T) { - | ^^^^^^^^^^^ required by this bound in `foo` -help: consider borrowing here - | -LL | foo(&x); - | + -LL | foo(&mut x); - | ++++ - -error[E0277]: `dyn PointerLike` needs to have the same ABI as a pointer - --> $DIR/dyn-pointer-like.rs:18:9 - | -LL | foo(x); - | --- ^ `dyn PointerLike` needs to be a pointer-like type - | | - | required by a bound introduced by this call - | - = help: the trait `PointerLike` is not implemented for `dyn PointerLike` -note: required by a bound in `foo` - --> $DIR/dyn-pointer-like.rs:21:11 - | -LL | fn foo(x: T) { - | ^^^^^^^^^^^ required by this bound in `foo` - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/dyn-star/dyn-star-to-dyn.rs b/tests/ui/dyn-star/dyn-star-to-dyn.rs deleted file mode 100644 index 99f673df868c4..0000000000000 --- a/tests/ui/dyn-star/dyn-star-to-dyn.rs +++ /dev/null @@ -1,17 +0,0 @@ -//@ run-pass - -#![feature(dyn_star)] -//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - -use std::fmt::Debug; - -fn main() { - let x: dyn* Debug = &42; - let x = Box::new(x) as Box; - assert_eq!("42", format!("{x:?}")); - - // Also test opposite direction. - let x: Box = Box::new(42); - let x = &x as dyn* Debug; - assert_eq!("42", format!("{x:?}")); -} diff --git a/tests/ui/dyn-star/dyn-star-to-dyn.stderr b/tests/ui/dyn-star/dyn-star-to-dyn.stderr deleted file mode 100644 index 03aedf5f797a5..0000000000000 --- a/tests/ui/dyn-star/dyn-star-to-dyn.stderr +++ /dev/null @@ -1,11 +0,0 @@ -warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/dyn-star-to-dyn.rs:3:12 - | -LL | #![feature(dyn_star)] - | ^^^^^^^^ - | - = note: see issue #102425 for more information - = note: `#[warn(incomplete_features)]` on by default - -warning: 1 warning emitted - diff --git a/tests/ui/dyn-star/dyn-to-rigid.rs b/tests/ui/dyn-star/dyn-to-rigid.rs deleted file mode 100644 index dc33e288f24e6..0000000000000 --- a/tests/ui/dyn-star/dyn-to-rigid.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![feature(dyn_star)] -#![allow(incomplete_features)] - -trait Tr {} - -fn f(x: dyn* Tr) -> usize { - x as usize - //~^ ERROR non-primitive cast: `(dyn* Tr + 'static)` as `usize` -} - -fn main() {} diff --git a/tests/ui/dyn-star/dyn-to-rigid.stderr b/tests/ui/dyn-star/dyn-to-rigid.stderr deleted file mode 100644 index 49b8f268aa4e9..0000000000000 --- a/tests/ui/dyn-star/dyn-to-rigid.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0605]: non-primitive cast: `(dyn* Tr + 'static)` as `usize` - --> $DIR/dyn-to-rigid.rs:7:5 - | -LL | x as usize - | ^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0605`. diff --git a/tests/ui/dyn-star/enum-cast.rs b/tests/ui/dyn-star/enum-cast.rs deleted file mode 100644 index 3cc7390eb1280..0000000000000 --- a/tests/ui/dyn-star/enum-cast.rs +++ /dev/null @@ -1,23 +0,0 @@ -//@ check-pass - -// This used to ICE, because the compiler confused a pointer-like to dyn* coercion -// with a c-like enum to integer cast. - -#![feature(dyn_star, pointer_like_trait)] -#![expect(incomplete_features)] - -use std::marker::PointerLike; - -#[repr(transparent)] -enum E { - Num(usize), -} - -impl PointerLike for E {} - -trait Trait {} -impl Trait for E {} - -fn main() { - let _ = E::Num(42) as dyn* Trait; -} diff --git a/tests/ui/dyn-star/error.rs b/tests/ui/dyn-star/error.rs deleted file mode 100644 index 1d252d2ce42b2..0000000000000 --- a/tests/ui/dyn-star/error.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![feature(dyn_star)] -#![allow(incomplete_features)] - -use std::fmt::Debug; - -trait Foo {} - -fn make_dyn_star() { - let i = 42usize; - let dyn_i: dyn* Foo = i; //~ ERROR trait bound `usize: Foo` is not satisfied -} - -fn main() {} diff --git a/tests/ui/dyn-star/error.stderr b/tests/ui/dyn-star/error.stderr deleted file mode 100644 index 55981c03bac2b..0000000000000 --- a/tests/ui/dyn-star/error.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0277]: the trait bound `usize: Foo` is not satisfied - --> $DIR/error.rs:10:27 - | -LL | let dyn_i: dyn* Foo = i; - | ^ the trait `Foo` is not implemented for `usize` - | -help: this trait has no implementations, consider adding one - --> $DIR/error.rs:6:1 - | -LL | trait Foo {} - | ^^^^^^^^^ - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/dyn-star/feature-gate-dyn_star.rs b/tests/ui/dyn-star/feature-gate-dyn_star.rs deleted file mode 100644 index b12fd7755be04..0000000000000 --- a/tests/ui/dyn-star/feature-gate-dyn_star.rs +++ /dev/null @@ -1,9 +0,0 @@ -// Feature gate test for dyn_star - -/// dyn* is not necessarily the final surface syntax (if we have one at all), -/// but for now we will support it to aid in writing tests independently. -pub fn dyn_star_parameter(_: &dyn* Send) { - //~^ ERROR `dyn*` trait objects are experimental -} - -fn main() {} diff --git a/tests/ui/dyn-star/feature-gate-dyn_star.stderr b/tests/ui/dyn-star/feature-gate-dyn_star.stderr deleted file mode 100644 index c3e99b20d06ab..0000000000000 --- a/tests/ui/dyn-star/feature-gate-dyn_star.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error[E0658]: `dyn*` trait objects are experimental - --> $DIR/feature-gate-dyn_star.rs:5:31 - | -LL | pub fn dyn_star_parameter(_: &dyn* Send) { - | ^^^^ - | - = note: see issue #102425 for more information - = help: add `#![feature(dyn_star)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/dyn-star/float-as-dyn-star.rs b/tests/ui/dyn-star/float-as-dyn-star.rs deleted file mode 100644 index 1b629c64c25a9..0000000000000 --- a/tests/ui/dyn-star/float-as-dyn-star.rs +++ /dev/null @@ -1,16 +0,0 @@ -//@ only-x86_64 - -#![feature(dyn_star, pointer_like_trait)] -//~^ WARN the feature `dyn_star` is incomplete - -use std::fmt::Debug; -use std::marker::PointerLike; - -fn make_dyn_star() -> dyn* Debug + 'static { - f32::from_bits(0x1) as f64 - //~^ ERROR `f64` needs to have the same ABI as a pointer -} - -fn main() { - println!("{:?}", make_dyn_star()); -} diff --git a/tests/ui/dyn-star/float-as-dyn-star.stderr b/tests/ui/dyn-star/float-as-dyn-star.stderr deleted file mode 100644 index 06071a27afc61..0000000000000 --- a/tests/ui/dyn-star/float-as-dyn-star.stderr +++ /dev/null @@ -1,23 +0,0 @@ -warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/float-as-dyn-star.rs:3:12 - | -LL | #![feature(dyn_star, pointer_like_trait)] - | ^^^^^^^^ - | - = note: see issue #102425 for more information - = note: `#[warn(incomplete_features)]` on by default - -error[E0277]: `f64` needs to have the same ABI as a pointer - --> $DIR/float-as-dyn-star.rs:10:5 - | -LL | f32::from_bits(0x1) as f64 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ `f64` needs to be a pointer-like type - | - = help: the trait `PointerLike` is not implemented for `f64` - = help: the following other types implement trait `PointerLike`: - isize - usize - -error: aborting due to 1 previous error; 1 warning emitted - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/dyn-star/gated-span.rs b/tests/ui/dyn-star/gated-span.rs deleted file mode 100644 index a747987bd2483..0000000000000 --- a/tests/ui/dyn-star/gated-span.rs +++ /dev/null @@ -1,8 +0,0 @@ -macro_rules! t { - ($t:ty) => {} -} - -t!(dyn* Send); -//~^ ERROR `dyn*` trait objects are experimental - -fn main() {} diff --git a/tests/ui/dyn-star/gated-span.stderr b/tests/ui/dyn-star/gated-span.stderr deleted file mode 100644 index 8ba6d7969fc4f..0000000000000 --- a/tests/ui/dyn-star/gated-span.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error[E0658]: `dyn*` trait objects are experimental - --> $DIR/gated-span.rs:5:4 - | -LL | t!(dyn* Send); - | ^^^^ - | - = note: see issue #102425 for more information - = help: add `#![feature(dyn_star)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/dyn-star/illegal.rs b/tests/ui/dyn-star/illegal.rs deleted file mode 100644 index ce0d784fcd22e..0000000000000 --- a/tests/ui/dyn-star/illegal.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![feature(dyn_star)] -//~^ WARN the feature `dyn_star` is incomplete - -trait Foo {} - -pub fn lol(x: dyn* Foo + Send) { - x as dyn* Foo; - //~^ ERROR casting `(dyn* Foo + Send + 'static)` as `dyn* Foo` is invalid -} - -fn lol2(x: &dyn Foo) { - *x as dyn* Foo; - //~^ ERROR `dyn Foo` needs to have the same ABI as a pointer -} - -fn main() {} diff --git a/tests/ui/dyn-star/illegal.stderr b/tests/ui/dyn-star/illegal.stderr deleted file mode 100644 index fdf3c813a231c..0000000000000 --- a/tests/ui/dyn-star/illegal.stderr +++ /dev/null @@ -1,27 +0,0 @@ -warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/illegal.rs:1:12 - | -LL | #![feature(dyn_star)] - | ^^^^^^^^ - | - = note: see issue #102425 for more information - = note: `#[warn(incomplete_features)]` on by default - -error[E0606]: casting `(dyn* Foo + Send + 'static)` as `dyn* Foo` is invalid - --> $DIR/illegal.rs:7:5 - | -LL | x as dyn* Foo; - | ^^^^^^^^^^^^^ - -error[E0277]: `dyn Foo` needs to have the same ABI as a pointer - --> $DIR/illegal.rs:12:5 - | -LL | *x as dyn* Foo; - | ^^ `dyn Foo` needs to be a pointer-like type - | - = help: the trait `PointerLike` is not implemented for `dyn Foo` - -error: aborting due to 2 previous errors; 1 warning emitted - -Some errors have detailed explanations: E0277, E0606. -For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/dyn-star/issue-102430.rs b/tests/ui/dyn-star/issue-102430.rs deleted file mode 100644 index 4e48d5e2f5df0..0000000000000 --- a/tests/ui/dyn-star/issue-102430.rs +++ /dev/null @@ -1,32 +0,0 @@ -//@ check-pass - -#![feature(dyn_star)] -#![allow(incomplete_features)] - -trait AddOne { - fn add1(&mut self) -> usize; -} - -impl AddOne for usize { - fn add1(&mut self) -> usize { - *self += 1; - *self - } -} - -impl AddOne for &mut usize { - fn add1(&mut self) -> usize { - (*self).add1() - } -} - -fn add_one(mut i: dyn* AddOne + '_) -> usize { - i.add1() -} - -fn main() { - let mut x = 42usize; - let y = &mut x as (dyn* AddOne + '_); - - println!("{}", add_one(y)); -} diff --git a/tests/ui/dyn-star/make-dyn-star.rs b/tests/ui/dyn-star/make-dyn-star.rs deleted file mode 100644 index 24004335f0607..0000000000000 --- a/tests/ui/dyn-star/make-dyn-star.rs +++ /dev/null @@ -1,18 +0,0 @@ -//@ run-pass -#![feature(dyn_star)] -#![allow(incomplete_features)] - -use std::fmt::Debug; - -fn make_dyn_star(i: usize) { - let _dyn_i: dyn* Debug = i; -} - -fn make_dyn_star_explicit(i: usize) { - let _dyn_i: dyn* Debug = i as dyn* Debug; -} - -fn main() { - make_dyn_star(42); - make_dyn_star_explicit(42); -} diff --git a/tests/ui/dyn-star/method.rs b/tests/ui/dyn-star/method.rs deleted file mode 100644 index 0d0855eec7fbd..0000000000000 --- a/tests/ui/dyn-star/method.rs +++ /dev/null @@ -1,27 +0,0 @@ -//@ run-pass - -#![feature(dyn_star)] -#![allow(incomplete_features)] - -trait Foo { - fn get(&self) -> usize; -} - -impl Foo for usize { - fn get(&self) -> usize { - *self - } -} - -fn invoke_dyn_star(i: dyn* Foo) -> usize { - i.get() -} - -fn make_and_invoke_dyn_star(i: usize) -> usize { - let dyn_i: dyn* Foo = i; - invoke_dyn_star(dyn_i) -} - -fn main() { - println!("{}", make_and_invoke_dyn_star(42)); -} diff --git a/tests/ui/dyn-star/no-explicit-dyn-star-cast.rs b/tests/ui/dyn-star/no-explicit-dyn-star-cast.rs deleted file mode 100644 index 2d28f516ab5a7..0000000000000 --- a/tests/ui/dyn-star/no-explicit-dyn-star-cast.rs +++ /dev/null @@ -1,13 +0,0 @@ -use std::fmt::Debug; - -fn make_dyn_star() { - let i = 42usize; - let dyn_i: dyn* Debug = i as dyn* Debug; - //~^ ERROR casting `usize` as `dyn* Debug` is invalid - //~| ERROR `dyn*` trait objects are experimental - //~| ERROR `dyn*` trait objects are experimental -} - -fn main() { - make_dyn_star(); -} diff --git a/tests/ui/dyn-star/no-explicit-dyn-star-cast.stderr b/tests/ui/dyn-star/no-explicit-dyn-star-cast.stderr deleted file mode 100644 index bb4c612cedd9b..0000000000000 --- a/tests/ui/dyn-star/no-explicit-dyn-star-cast.stderr +++ /dev/null @@ -1,30 +0,0 @@ -error[E0658]: `dyn*` trait objects are experimental - --> $DIR/no-explicit-dyn-star-cast.rs:5:16 - | -LL | let dyn_i: dyn* Debug = i as dyn* Debug; - | ^^^^ - | - = note: see issue #102425 for more information - = help: add `#![feature(dyn_star)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: `dyn*` trait objects are experimental - --> $DIR/no-explicit-dyn-star-cast.rs:5:34 - | -LL | let dyn_i: dyn* Debug = i as dyn* Debug; - | ^^^^ - | - = note: see issue #102425 for more information - = help: add `#![feature(dyn_star)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0606]: casting `usize` as `dyn* Debug` is invalid - --> $DIR/no-explicit-dyn-star-cast.rs:5:29 - | -LL | let dyn_i: dyn* Debug = i as dyn* Debug; - | ^^^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors - -Some errors have detailed explanations: E0606, E0658. -For more information about an error, try `rustc --explain E0606`. diff --git a/tests/ui/dyn-star/no-explicit-dyn-star.rs b/tests/ui/dyn-star/no-explicit-dyn-star.rs deleted file mode 100644 index 0847597450e5c..0000000000000 --- a/tests/ui/dyn-star/no-explicit-dyn-star.rs +++ /dev/null @@ -1,8 +0,0 @@ -//@ aux-build:dyn-star-foreign.rs - -extern crate dyn_star_foreign; - -fn main() { - dyn_star_foreign::require_dyn_star_display(1usize as _); - //~^ ERROR casting `usize` as `dyn* std::fmt::Display` is invalid -} diff --git a/tests/ui/dyn-star/no-explicit-dyn-star.stderr b/tests/ui/dyn-star/no-explicit-dyn-star.stderr deleted file mode 100644 index 641404aa09e20..0000000000000 --- a/tests/ui/dyn-star/no-explicit-dyn-star.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0606]: casting `usize` as `dyn* std::fmt::Display` is invalid - --> $DIR/no-explicit-dyn-star.rs:6:48 - | -LL | dyn_star_foreign::require_dyn_star_display(1usize as _); - | ^^^^^^^^^^^ - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0606`. diff --git a/tests/ui/dyn-star/no-implicit-dyn-star.rs b/tests/ui/dyn-star/no-implicit-dyn-star.rs deleted file mode 100644 index 7af3f9a734bce..0000000000000 --- a/tests/ui/dyn-star/no-implicit-dyn-star.rs +++ /dev/null @@ -1,8 +0,0 @@ -//@ aux-build:dyn-star-foreign.rs - -extern crate dyn_star_foreign; - -fn main() { - dyn_star_foreign::require_dyn_star_display(1usize); - //~^ ERROR mismatched types -} diff --git a/tests/ui/dyn-star/no-implicit-dyn-star.stderr b/tests/ui/dyn-star/no-implicit-dyn-star.stderr deleted file mode 100644 index d1d3da9ca7024..0000000000000 --- a/tests/ui/dyn-star/no-implicit-dyn-star.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/no-implicit-dyn-star.rs:6:48 - | -LL | dyn_star_foreign::require_dyn_star_display(1usize); - | ------------------------------------------ ^^^^^^ expected `dyn Display`, found `usize` - | | - | arguments to this function are incorrect - | - = note: expected trait object `(dyn* std::fmt::Display + 'static)` - found type `usize` - = help: `usize` implements `Display`, `#[feature(dyn_star)]` is likely not enabled; that feature it is currently incomplete -note: function defined here - --> $DIR/auxiliary/dyn-star-foreign.rs:5:8 - | -LL | pub fn require_dyn_star_display(_: dyn* Display) {} - | ^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/dyn-star/no-unsize-coerce-dyn-trait.rs b/tests/ui/dyn-star/no-unsize-coerce-dyn-trait.rs deleted file mode 100644 index 1702fc1ed490e..0000000000000 --- a/tests/ui/dyn-star/no-unsize-coerce-dyn-trait.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![expect(incomplete_features)] -#![feature(dyn_star)] - -trait A: B {} -trait B {} -impl A for usize {} -impl B for usize {} - -fn main() { - let x: Box = Box::new(1usize as dyn* A); - let y: Box = x; - //~^ ERROR mismatched types -} diff --git a/tests/ui/dyn-star/no-unsize-coerce-dyn-trait.stderr b/tests/ui/dyn-star/no-unsize-coerce-dyn-trait.stderr deleted file mode 100644 index 289d85072e615..0000000000000 --- a/tests/ui/dyn-star/no-unsize-coerce-dyn-trait.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/no-unsize-coerce-dyn-trait.rs:11:26 - | -LL | let y: Box = x; - | ----------- ^ expected trait `B`, found trait `A` - | | - | expected due to this - | - = note: expected struct `Box` - found struct `Box` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/dyn-star/param-env-region-infer.current.stderr b/tests/ui/dyn-star/param-env-region-infer.current.stderr deleted file mode 100644 index 6e464c17014cc..0000000000000 --- a/tests/ui/dyn-star/param-env-region-infer.current.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0282]: type annotations needed - --> $DIR/param-env-region-infer.rs:20:10 - | -LL | t as _ - | ^ cannot infer type - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0282`. diff --git a/tests/ui/dyn-star/param-env-region-infer.rs b/tests/ui/dyn-star/param-env-region-infer.rs deleted file mode 100644 index 842964ad284cc..0000000000000 --- a/tests/ui/dyn-star/param-env-region-infer.rs +++ /dev/null @@ -1,24 +0,0 @@ -//@ revisions: current -//@ incremental - -// FIXME(-Znext-solver): This currently results in unstable query results: -// `normalizes-to(opaque, opaque)` changes from `Maybe(Ambiguous)` to `Maybe(Overflow)` -// once the hidden type of the opaque is already defined to be itself. -//@ unused-revision-names: next - -// checks that we don't ICE if there are region inference variables in the environment -// when computing `PointerLike` builtin candidates. - -#![feature(dyn_star, pointer_like_trait)] -#![allow(incomplete_features)] - -use std::fmt::Debug; -use std::marker::PointerLike; - -fn make_dyn_star<'a, T: PointerLike + Debug + 'a>(t: T) -> impl PointerLike + Debug + 'a { - //[next]~^ ERROR cycle detected when computing - t as _ - //[current]~^ ERROR type annotations needed -} - -fn main() {} diff --git a/tests/ui/dyn-star/pointer-like-impl-rules.rs b/tests/ui/dyn-star/pointer-like-impl-rules.rs deleted file mode 100644 index c234e86e09a84..0000000000000 --- a/tests/ui/dyn-star/pointer-like-impl-rules.rs +++ /dev/null @@ -1,82 +0,0 @@ -//@ check-fail - -#![feature(extern_types)] -#![feature(pointer_like_trait)] - -use std::marker::PointerLike; - -struct NotReprTransparent; -impl PointerLike for NotReprTransparent {} -//~^ ERROR: implementation must be applied to type that -//~| NOTE: the struct `NotReprTransparent` is not `repr(transparent)` - -#[repr(transparent)] -struct FieldIsPl(usize); -impl PointerLike for FieldIsPl {} - -#[repr(transparent)] -struct FieldIsPlAndHasOtherField(usize, ()); -impl PointerLike for FieldIsPlAndHasOtherField {} - -#[repr(transparent)] -struct FieldIsNotPl(u8); -impl PointerLike for FieldIsNotPl {} -//~^ ERROR: implementation must be applied to type that -//~| NOTE: the field `0` of struct `FieldIsNotPl` does not implement `PointerLike` - -#[repr(transparent)] -struct GenericFieldIsNotPl(T); -impl PointerLike for GenericFieldIsNotPl {} -//~^ ERROR: implementation must be applied to type that -//~| NOTE: the field `0` of struct `GenericFieldIsNotPl` does not implement `PointerLike` - -#[repr(transparent)] -struct GenericFieldIsPl(T); -impl PointerLike for GenericFieldIsPl {} - -#[repr(transparent)] -struct IsZeroSized(()); -impl PointerLike for IsZeroSized {} -//~^ ERROR: implementation must be applied to type that -//~| NOTE: the struct `IsZeroSized` is `repr(transparent)`, but does not have a non-trivial field - -trait SomeTrait {} -impl PointerLike for dyn SomeTrait {} -//~^ ERROR: implementation must be applied to type that -//~| NOTE: types of dynamic or unknown size - -extern "C" { - type ExternType; -} -impl PointerLike for ExternType {} -//~^ ERROR: implementation must be applied to type that -//~| NOTE: types of dynamic or unknown size - -struct LocalSizedType(&'static str); -struct LocalUnsizedType(str); - -// This is not a special error but a normal coherence error, -// which should still happen. -impl PointerLike for &LocalSizedType {} -//~^ ERROR: conflicting implementations of trait `PointerLike` -//~| NOTE: conflicting implementation in crate `core` - -impl PointerLike for &LocalUnsizedType {} -//~^ ERROR: implementation must be applied to type that -//~| NOTE: references to dynamically-sized types are too large to be `PointerLike` - -impl PointerLike for Box {} -//~^ ERROR: conflicting implementations of trait `PointerLike` -//~| NOTE: conflicting implementation in crate `alloc` - -impl PointerLike for Box {} -//~^ ERROR: implementation must be applied to type that -//~| NOTE: boxes of dynamically-sized types are too large to be `PointerLike` - -fn expects_pointer_like(x: impl PointerLike) {} - -fn main() { - expects_pointer_like(FieldIsPl(1usize)); - expects_pointer_like(FieldIsPlAndHasOtherField(1usize, ())); - expects_pointer_like(GenericFieldIsPl(1usize)); -} diff --git a/tests/ui/dyn-star/pointer-like-impl-rules.stderr b/tests/ui/dyn-star/pointer-like-impl-rules.stderr deleted file mode 100644 index 39f08f442c443..0000000000000 --- a/tests/ui/dyn-star/pointer-like-impl-rules.stderr +++ /dev/null @@ -1,85 +0,0 @@ -error[E0119]: conflicting implementations of trait `PointerLike` for type `&LocalSizedType` - --> $DIR/pointer-like-impl-rules.rs:60:1 - | -LL | impl PointerLike for &LocalSizedType {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: conflicting implementation in crate `core`: - - impl PointerLike for &T; - -error[E0119]: conflicting implementations of trait `PointerLike` for type `Box` - --> $DIR/pointer-like-impl-rules.rs:68:1 - | -LL | impl PointerLike for Box {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: conflicting implementation in crate `alloc`: - - impl PointerLike for Box; - -error: implementation must be applied to type that has the same ABI as a pointer, or is `repr(transparent)` and whose field is `PointerLike` - --> $DIR/pointer-like-impl-rules.rs:9:1 - | -LL | impl PointerLike for NotReprTransparent {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: the struct `NotReprTransparent` is not `repr(transparent)` - -error: implementation must be applied to type that has the same ABI as a pointer, or is `repr(transparent)` and whose field is `PointerLike` - --> $DIR/pointer-like-impl-rules.rs:23:1 - | -LL | impl PointerLike for FieldIsNotPl {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: the field `0` of struct `FieldIsNotPl` does not implement `PointerLike` - -error: implementation must be applied to type that has the same ABI as a pointer, or is `repr(transparent)` and whose field is `PointerLike` - --> $DIR/pointer-like-impl-rules.rs:29:1 - | -LL | impl PointerLike for GenericFieldIsNotPl {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: the field `0` of struct `GenericFieldIsNotPl` does not implement `PointerLike` - -error: implementation must be applied to type that has the same ABI as a pointer, or is `repr(transparent)` and whose field is `PointerLike` - --> $DIR/pointer-like-impl-rules.rs:39:1 - | -LL | impl PointerLike for IsZeroSized {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: the struct `IsZeroSized` is `repr(transparent)`, but does not have a non-trivial field (it is zero-sized) - -error: implementation must be applied to type that has the same ABI as a pointer, or is `repr(transparent)` and whose field is `PointerLike` - --> $DIR/pointer-like-impl-rules.rs:44:1 - | -LL | impl PointerLike for dyn SomeTrait {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: types of dynamic or unknown size may not implement `PointerLike` - -error: implementation must be applied to type that has the same ABI as a pointer, or is `repr(transparent)` and whose field is `PointerLike` - --> $DIR/pointer-like-impl-rules.rs:51:1 - | -LL | impl PointerLike for ExternType {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: types of dynamic or unknown size may not implement `PointerLike` - -error: implementation must be applied to type that has the same ABI as a pointer, or is `repr(transparent)` and whose field is `PointerLike` - --> $DIR/pointer-like-impl-rules.rs:64:1 - | -LL | impl PointerLike for &LocalUnsizedType {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: references to dynamically-sized types are too large to be `PointerLike` - -error: implementation must be applied to type that has the same ABI as a pointer, or is `repr(transparent)` and whose field is `PointerLike` - --> $DIR/pointer-like-impl-rules.rs:72:1 - | -LL | impl PointerLike for Box {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: boxes of dynamically-sized types are too large to be `PointerLike` - -error: aborting due to 10 previous errors - -For more information about this error, try `rustc --explain E0119`. diff --git a/tests/ui/dyn-star/return.rs b/tests/ui/dyn-star/return.rs deleted file mode 100644 index 47d95d1d643e7..0000000000000 --- a/tests/ui/dyn-star/return.rs +++ /dev/null @@ -1,10 +0,0 @@ -//@ check-pass - -#![feature(dyn_star)] -//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - -fn _foo() -> dyn* Unpin { - 4usize -} - -fn main() {} diff --git a/tests/ui/dyn-star/return.stderr b/tests/ui/dyn-star/return.stderr deleted file mode 100644 index 9c26568290443..0000000000000 --- a/tests/ui/dyn-star/return.stderr +++ /dev/null @@ -1,11 +0,0 @@ -warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/return.rs:3:12 - | -LL | #![feature(dyn_star)] - | ^^^^^^^^ - | - = note: see issue #102425 for more information - = note: `#[warn(incomplete_features)]` on by default - -warning: 1 warning emitted - diff --git a/tests/ui/dyn-star/syntax.rs b/tests/ui/dyn-star/syntax.rs deleted file mode 100644 index d4983404de2b3..0000000000000 --- a/tests/ui/dyn-star/syntax.rs +++ /dev/null @@ -1,11 +0,0 @@ -// Make sure we can parse the `dyn* Trait` syntax -// -//@ check-pass - -#![feature(dyn_star)] -#![allow(incomplete_features)] - -pub fn dyn_star_parameter(_: dyn* Send) { -} - -fn main() {} diff --git a/tests/ui/dyn-star/thin.next.stderr b/tests/ui/dyn-star/thin.next.stderr deleted file mode 100644 index ef251062afcf7..0000000000000 --- a/tests/ui/dyn-star/thin.next.stderr +++ /dev/null @@ -1,11 +0,0 @@ -warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/thin.rs:6:12 - | -LL | #![feature(dyn_star)] - | ^^^^^^^^ - | - = note: see issue #102425 for more information - = note: `#[warn(incomplete_features)]` on by default - -warning: 1 warning emitted - diff --git a/tests/ui/dyn-star/thin.old.stderr b/tests/ui/dyn-star/thin.old.stderr deleted file mode 100644 index ef251062afcf7..0000000000000 --- a/tests/ui/dyn-star/thin.old.stderr +++ /dev/null @@ -1,11 +0,0 @@ -warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/thin.rs:6:12 - | -LL | #![feature(dyn_star)] - | ^^^^^^^^ - | - = note: see issue #102425 for more information - = note: `#[warn(incomplete_features)]` on by default - -warning: 1 warning emitted - diff --git a/tests/ui/dyn-star/thin.rs b/tests/ui/dyn-star/thin.rs deleted file mode 100644 index 6df70f560dec9..0000000000000 --- a/tests/ui/dyn-star/thin.rs +++ /dev/null @@ -1,16 +0,0 @@ -//@check-pass -//@revisions: old next -//@[next] compile-flags: -Znext-solver - -#![feature(ptr_metadata)] -#![feature(dyn_star)] -//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - -use std::fmt::Debug; -use std::ptr::Thin; - -fn check_thin() {} - -fn main() { - check_thin::(); -} diff --git a/tests/ui/dyn-star/union.rs b/tests/ui/dyn-star/union.rs deleted file mode 100644 index ad3a85a937ae7..0000000000000 --- a/tests/ui/dyn-star/union.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![feature(dyn_star)] -//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - -union Union { - x: usize, -} - -trait Trait {} -impl Trait for Union {} - -fn bar(_: dyn* Trait) {} - -fn main() { - bar(Union { x: 0usize }); - //~^ ERROR `Union` needs to have the same ABI as a pointer -} diff --git a/tests/ui/dyn-star/union.stderr b/tests/ui/dyn-star/union.stderr deleted file mode 100644 index 906eb4f5163e5..0000000000000 --- a/tests/ui/dyn-star/union.stderr +++ /dev/null @@ -1,20 +0,0 @@ -warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/union.rs:1:12 - | -LL | #![feature(dyn_star)] - | ^^^^^^^^ - | - = note: see issue #102425 for more information - = note: `#[warn(incomplete_features)]` on by default - -error[E0277]: `Union` needs to have the same ABI as a pointer - --> $DIR/union.rs:14:9 - | -LL | bar(Union { x: 0usize }); - | ^^^^^^^^^^^^^^^^^^^ `Union` needs to be a pointer-like type - | - = help: the trait `PointerLike` is not implemented for `Union` - -error: aborting due to 1 previous error; 1 warning emitted - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/dyn-star/unsize-into-ref-dyn-star.rs b/tests/ui/dyn-star/unsize-into-ref-dyn-star.rs deleted file mode 100644 index 1e8cafe1561e8..0000000000000 --- a/tests/ui/dyn-star/unsize-into-ref-dyn-star.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![feature(dyn_star)] -#![allow(incomplete_features)] - -use std::fmt::Debug; - -fn main() { - let i = 42 as &dyn* Debug; - //~^ ERROR non-primitive cast: `i32` as `&dyn* Debug` -} diff --git a/tests/ui/dyn-star/unsize-into-ref-dyn-star.stderr b/tests/ui/dyn-star/unsize-into-ref-dyn-star.stderr deleted file mode 100644 index b3274580afe0e..0000000000000 --- a/tests/ui/dyn-star/unsize-into-ref-dyn-star.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0605]: non-primitive cast: `i32` as `&dyn* Debug` - --> $DIR/unsize-into-ref-dyn-star.rs:7:13 - | -LL | let i = 42 as &dyn* Debug; - | ^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0605`. diff --git a/tests/ui/dyn-star/upcast.rs b/tests/ui/dyn-star/upcast.rs deleted file mode 100644 index 01e1b94f87e27..0000000000000 --- a/tests/ui/dyn-star/upcast.rs +++ /dev/null @@ -1,32 +0,0 @@ -//@ known-bug: #104800 - -#![feature(dyn_star)] - -trait Foo: Bar { - fn hello(&self); -} - -trait Bar { - fn world(&self); -} - -struct W(usize); - -impl Foo for W { - fn hello(&self) { - println!("hello!"); - } -} - -impl Bar for W { - fn world(&self) { - println!("world!"); - } -} - -fn main() { - let w: dyn* Foo = W(0); - w.hello(); - let w: dyn* Bar = w; - w.world(); -} diff --git a/tests/ui/dyn-star/upcast.stderr b/tests/ui/dyn-star/upcast.stderr deleted file mode 100644 index 3f244d4b6ae8d..0000000000000 --- a/tests/ui/dyn-star/upcast.stderr +++ /dev/null @@ -1,28 +0,0 @@ -warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/upcast.rs:3:12 - | -LL | #![feature(dyn_star)] - | ^^^^^^^^ - | - = note: see issue #102425 for more information - = note: `#[warn(incomplete_features)]` on by default - -error[E0277]: `W` needs to have the same ABI as a pointer - --> $DIR/upcast.rs:28:23 - | -LL | let w: dyn* Foo = W(0); - | ^^^^ `W` needs to be a pointer-like type - | - = help: the trait `PointerLike` is not implemented for `W` - -error[E0277]: `dyn* Foo` needs to have the same ABI as a pointer - --> $DIR/upcast.rs:30:23 - | -LL | let w: dyn* Bar = w; - | ^ `dyn* Foo` needs to be a pointer-like type - | - = help: the trait `PointerLike` is not implemented for `dyn* Foo` - -error: aborting due to 2 previous errors; 1 warning emitted - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/parser/trait-object-delimiters.rs b/tests/ui/parser/trait-object-delimiters.rs index 8f6221c1b9434..b1fb6d0013263 100644 --- a/tests/ui/parser/trait-object-delimiters.rs +++ b/tests/ui/parser/trait-object-delimiters.rs @@ -8,7 +8,7 @@ fn foo2(_: &dyn (Drop + AsRef)) {} //~ ERROR incorrect parentheses around t fn foo2_no_space(_: &dyn(Drop + AsRef)) {} //~ ERROR incorrect parentheses around trait bounds fn foo3(_: &dyn {Drop + AsRef}) {} //~ ERROR expected parameter name, found `{` -//~^ ERROR expected one of `!`, `(`, `)`, `*`, `,`, `?`, `async`, `const`, `for`, `use`, `~`, lifetime, or path, found `{` +//~^ ERROR expected one of `!`, `(`, `)`, `,`, `?`, `async`, `const`, `for`, `use`, `~`, lifetime, or path, found `{` //~| ERROR at least one trait is required for an object type fn foo4(_: &dyn >) {} //~ ERROR expected identifier, found `<` diff --git a/tests/ui/parser/trait-object-delimiters.stderr b/tests/ui/parser/trait-object-delimiters.stderr index be130ac7ab231..0fdae6858e2e9 100644 --- a/tests/ui/parser/trait-object-delimiters.stderr +++ b/tests/ui/parser/trait-object-delimiters.stderr @@ -39,11 +39,11 @@ error: expected parameter name, found `{` LL | fn foo3(_: &dyn {Drop + AsRef}) {} | ^ expected parameter name -error: expected one of `!`, `(`, `)`, `*`, `,`, `?`, `async`, `const`, `for`, `use`, `~`, lifetime, or path, found `{` +error: expected one of `!`, `(`, `)`, `,`, `?`, `async`, `const`, `for`, `use`, `~`, lifetime, or path, found `{` --> $DIR/trait-object-delimiters.rs:10:17 | LL | fn foo3(_: &dyn {Drop + AsRef}) {} - | -^ expected one of 13 possible tokens + | -^ expected one of 12 possible tokens | | | help: missing `,` diff --git a/tests/ui/sized-hierarchy/impls.rs b/tests/ui/sized-hierarchy/impls.rs index 46697e47c4bfa..643f7bc7c46cb 100644 --- a/tests/ui/sized-hierarchy/impls.rs +++ b/tests/ui/sized-hierarchy/impls.rs @@ -3,7 +3,7 @@ #![allow(incomplete_features, internal_features)] #![feature(sized_hierarchy)] -#![feature(coroutines, dyn_star, extern_types, f16, never_type, unsized_fn_params)] +#![feature(coroutines, extern_types, f16, never_type, unsized_fn_params)] use std::fmt::Debug; use std::marker::{MetaSized, PointeeSized}; @@ -151,11 +151,6 @@ fn main() { needs_metasized::(); needs_pointeesized::(); - // `dyn*` - needs_sized::(); - needs_metasized::(); - needs_pointeesized::(); - // `str` needs_sized::(); //~^ ERROR the size for values of type `str` cannot be known at compilation time diff --git a/tests/ui/sized-hierarchy/impls.stderr b/tests/ui/sized-hierarchy/impls.stderr index eebe4e0d706a0..ca70822aad287 100644 --- a/tests/ui/sized-hierarchy/impls.stderr +++ b/tests/ui/sized-hierarchy/impls.stderr @@ -1,5 +1,5 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/impls.rs:240:42 + --> $DIR/impls.rs:235:42 | LL | struct StructAllFieldsMetaSized { x: [u8], y: [u8] } | ^^^^ doesn't have a size known at compile-time @@ -17,7 +17,7 @@ LL | struct StructAllFieldsMetaSized { x: Box<[u8]>, y: [u8] } | ++++ + error[E0277]: the size for values of type `main::Foo` cannot be known at compilation time - --> $DIR/impls.rs:248:40 + --> $DIR/impls.rs:243:40 | LL | struct StructAllFieldsUnsized { x: Foo, y: Foo } | ^^^ doesn't have a size known at compile-time @@ -35,7 +35,7 @@ LL | struct StructAllFieldsUnsized { x: Box, y: Foo } | ++++ + error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/impls.rs:284:44 + --> $DIR/impls.rs:279:44 | LL | enum EnumAllFieldsMetaSized { Qux { x: [u8], y: [u8] } } | ^^^^ doesn't have a size known at compile-time @@ -53,7 +53,7 @@ LL | enum EnumAllFieldsMetaSized { Qux { x: Box<[u8]>, y: [u8] } } | ++++ + error[E0277]: the size for values of type `main::Foo` cannot be known at compilation time - --> $DIR/impls.rs:291:42 + --> $DIR/impls.rs:286:42 | LL | enum EnumAllFieldsUnsized { Qux { x: Foo, y: Foo } } | ^^^ doesn't have a size known at compile-time @@ -71,7 +71,7 @@ LL | enum EnumAllFieldsUnsized { Qux { x: Box, y: Foo } } | ++++ + error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/impls.rs:298:52 + --> $DIR/impls.rs:293:52 | LL | enum EnumLastFieldMetaSized { Qux { x: u32, y: [u8] } } | ^^^^ doesn't have a size known at compile-time @@ -89,7 +89,7 @@ LL | enum EnumLastFieldMetaSized { Qux { x: u32, y: Box<[u8]> } } | ++++ + error[E0277]: the size for values of type `main::Foo` cannot be known at compilation time - --> $DIR/impls.rs:305:50 + --> $DIR/impls.rs:300:50 | LL | enum EnumLastFieldUnsized { Qux { x: u32, y: Foo } } | ^^^ doesn't have a size known at compile-time @@ -107,7 +107,7 @@ LL | enum EnumLastFieldUnsized { Qux { x: u32, y: Box } } | ++++ + error[E0277]: the size for values of type `str` cannot be known at compilation time - --> $DIR/impls.rs:160:19 + --> $DIR/impls.rs:155:19 | LL | needs_sized::(); | ^^^ doesn't have a size known at compile-time @@ -120,7 +120,7 @@ LL | fn needs_sized() { } | ^^^^^ required by this bound in `needs_sized` error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/impls.rs:166:19 + --> $DIR/impls.rs:161:19 | LL | needs_sized::<[u8]>(); | ^^^^ doesn't have a size known at compile-time @@ -133,7 +133,7 @@ LL | fn needs_sized() { } | ^^^^^ required by this bound in `needs_sized` error[E0277]: the size for values of type `dyn Debug` cannot be known at compilation time - --> $DIR/impls.rs:172:19 + --> $DIR/impls.rs:167:19 | LL | needs_sized::(); | ^^^^^^^^^ doesn't have a size known at compile-time @@ -146,7 +146,7 @@ LL | fn needs_sized() { } | ^^^^^ required by this bound in `needs_sized` error[E0277]: the size for values of type `main::Foo` cannot be known at compilation time - --> $DIR/impls.rs:181:19 + --> $DIR/impls.rs:176:19 | LL | needs_sized::(); | ^^^ doesn't have a size known at compile-time @@ -159,7 +159,7 @@ LL | fn needs_sized() { } | ^^^^^ required by this bound in `needs_sized` error[E0277]: the size for values of type `main::Foo` cannot be known - --> $DIR/impls.rs:183:23 + --> $DIR/impls.rs:178:23 | LL | needs_metasized::(); | ^^^ doesn't have a known size @@ -172,7 +172,7 @@ LL | fn needs_metasized() { } | ^^^^^^^^^ required by this bound in `needs_metasized` error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/impls.rs:198:19 + --> $DIR/impls.rs:193:19 | LL | needs_sized::<([u8], [u8])>(); | ^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -181,7 +181,7 @@ LL | needs_sized::<([u8], [u8])>(); = note: only the last element of a tuple may have a dynamically sized type error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/impls.rs:200:23 + --> $DIR/impls.rs:195:23 | LL | needs_metasized::<([u8], [u8])>(); | ^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -190,7 +190,7 @@ LL | needs_metasized::<([u8], [u8])>(); = note: only the last element of a tuple may have a dynamically sized type error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/impls.rs:202:26 + --> $DIR/impls.rs:197:26 | LL | needs_pointeesized::<([u8], [u8])>(); | ^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -199,7 +199,7 @@ LL | needs_pointeesized::<([u8], [u8])>(); = note: only the last element of a tuple may have a dynamically sized type error[E0277]: the size for values of type `main::Foo` cannot be known at compilation time - --> $DIR/impls.rs:206:19 + --> $DIR/impls.rs:201:19 | LL | needs_sized::<(Foo, Foo)>(); | ^^^^^^^^^^ doesn't have a size known at compile-time @@ -208,7 +208,7 @@ LL | needs_sized::<(Foo, Foo)>(); = note: only the last element of a tuple may have a dynamically sized type error[E0277]: the size for values of type `main::Foo` cannot be known at compilation time - --> $DIR/impls.rs:208:23 + --> $DIR/impls.rs:203:23 | LL | needs_metasized::<(Foo, Foo)>(); | ^^^^^^^^^^ doesn't have a size known at compile-time @@ -217,7 +217,7 @@ LL | needs_metasized::<(Foo, Foo)>(); = note: only the last element of a tuple may have a dynamically sized type error[E0277]: the size for values of type `main::Foo` cannot be known - --> $DIR/impls.rs:208:23 + --> $DIR/impls.rs:203:23 | LL | needs_metasized::<(Foo, Foo)>(); | ^^^^^^^^^^ doesn't have a known size @@ -231,7 +231,7 @@ LL | fn needs_metasized() { } | ^^^^^^^^^ required by this bound in `needs_metasized` error[E0277]: the size for values of type `main::Foo` cannot be known at compilation time - --> $DIR/impls.rs:211:26 + --> $DIR/impls.rs:206:26 | LL | needs_pointeesized::<(Foo, Foo)>(); | ^^^^^^^^^^ doesn't have a size known at compile-time @@ -240,7 +240,7 @@ LL | needs_pointeesized::<(Foo, Foo)>(); = note: only the last element of a tuple may have a dynamically sized type error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/impls.rs:215:19 + --> $DIR/impls.rs:210:19 | LL | needs_sized::<(u32, [u8])>(); | ^^^^^^^^^^^ doesn't have a size known at compile-time @@ -254,7 +254,7 @@ LL | fn needs_sized() { } | ^^^^^ required by this bound in `needs_sized` error[E0277]: the size for values of type `main::Foo` cannot be known at compilation time - --> $DIR/impls.rs:221:19 + --> $DIR/impls.rs:216:19 | LL | needs_sized::<(u32, Foo)>(); | ^^^^^^^^^^ doesn't have a size known at compile-time @@ -268,7 +268,7 @@ LL | fn needs_sized() { } | ^^^^^ required by this bound in `needs_sized` error[E0277]: the size for values of type `main::Foo` cannot be known - --> $DIR/impls.rs:223:23 + --> $DIR/impls.rs:218:23 | LL | needs_metasized::<(u32, Foo)>(); | ^^^^^^^^^^ doesn't have a known size @@ -282,14 +282,14 @@ LL | fn needs_metasized() { } | ^^^^^^^^^ required by this bound in `needs_metasized` error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/impls.rs:242:19 + --> $DIR/impls.rs:237:19 | LL | needs_sized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: within `StructAllFieldsMetaSized`, the trait `Sized` is not implemented for `[u8]` note: required because it appears within the type `StructAllFieldsMetaSized` - --> $DIR/impls.rs:240:12 + --> $DIR/impls.rs:235:12 | LL | struct StructAllFieldsMetaSized { x: [u8], y: [u8] } | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -300,14 +300,14 @@ LL | fn needs_sized() { } | ^^^^^ required by this bound in `needs_sized` error[E0277]: the size for values of type `main::Foo` cannot be known at compilation time - --> $DIR/impls.rs:250:19 + --> $DIR/impls.rs:245:19 | LL | needs_sized::(); | ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: within `StructAllFieldsUnsized`, the trait `Sized` is not implemented for `main::Foo` note: required because it appears within the type `StructAllFieldsUnsized` - --> $DIR/impls.rs:248:12 + --> $DIR/impls.rs:243:12 | LL | struct StructAllFieldsUnsized { x: Foo, y: Foo } | ^^^^^^^^^^^^^^^^^^^^^^ @@ -318,14 +318,14 @@ LL | fn needs_sized() { } | ^^^^^ required by this bound in `needs_sized` error[E0277]: the size for values of type `main::Foo` cannot be known - --> $DIR/impls.rs:252:23 + --> $DIR/impls.rs:247:23 | LL | needs_metasized::(); | ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a known size | = help: within `StructAllFieldsUnsized`, the trait `MetaSized` is not implemented for `main::Foo` note: required because it appears within the type `StructAllFieldsUnsized` - --> $DIR/impls.rs:248:12 + --> $DIR/impls.rs:243:12 | LL | struct StructAllFieldsUnsized { x: Foo, y: Foo } | ^^^^^^^^^^^^^^^^^^^^^^ @@ -336,14 +336,14 @@ LL | fn needs_metasized() { } | ^^^^^^^^^ required by this bound in `needs_metasized` error[E0277]: the size for values of type `[u8]` cannot be known at compilation time - --> $DIR/impls.rs:258:19 + --> $DIR/impls.rs:253:19 | LL | needs_sized::(); | ^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: within `StructLastFieldMetaSized`, the trait `Sized` is not implemented for `[u8]` note: required because it appears within the type `StructLastFieldMetaSized` - --> $DIR/impls.rs:257:12 + --> $DIR/impls.rs:252:12 | LL | struct StructLastFieldMetaSized { x: u32, y: [u8] } | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -354,14 +354,14 @@ LL | fn needs_sized() { } | ^^^^^ required by this bound in `needs_sized` error[E0277]: the size for values of type `main::Foo` cannot be known at compilation time - --> $DIR/impls.rs:265:19 + --> $DIR/impls.rs:260:19 | LL | needs_sized::(); | ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | = help: within `StructLastFieldUnsized`, the trait `Sized` is not implemented for `main::Foo` note: required because it appears within the type `StructLastFieldUnsized` - --> $DIR/impls.rs:264:12 + --> $DIR/impls.rs:259:12 | LL | struct StructLastFieldUnsized { x: u32, y: Foo } | ^^^^^^^^^^^^^^^^^^^^^^ @@ -372,14 +372,14 @@ LL | fn needs_sized() { } | ^^^^^ required by this bound in `needs_sized` error[E0277]: the size for values of type `main::Foo` cannot be known - --> $DIR/impls.rs:267:23 + --> $DIR/impls.rs:262:23 | LL | needs_metasized::(); | ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a known size | = help: within `StructLastFieldUnsized`, the trait `MetaSized` is not implemented for `main::Foo` note: required because it appears within the type `StructLastFieldUnsized` - --> $DIR/impls.rs:264:12 + --> $DIR/impls.rs:259:12 | LL | struct StructLastFieldUnsized { x: u32, y: Foo } | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.rs b/tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.rs index 6a273997ee630..2ee6ad91056c5 100644 --- a/tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.rs +++ b/tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.rs @@ -1,5 +1,3 @@ -#![feature(dyn_star)] //~ WARNING the feature `dyn_star` is incomplete - use std::future::Future; pub fn dyn_func( @@ -8,12 +6,6 @@ pub fn dyn_func( Box::new(executor) //~ ERROR may not live long enough } -pub fn dyn_star_func( - executor: impl FnOnce(T) -> dyn* Future, -) -> Box dyn* Future> { - Box::new(executor) //~ ERROR may not live long enough -} - trait Trait { fn method(&self) {} } diff --git a/tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.stderr b/tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.stderr index 1fb3e7d211edb..62943616e3ad0 100644 --- a/tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.stderr +++ b/tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.stderr @@ -1,14 +1,5 @@ -warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:1:12 - | -LL | #![feature(dyn_star)] - | ^^^^^^^^ - | - = note: see issue #102425 for more information - = note: `#[warn(incomplete_features)]` on by default - error[E0599]: no method named `method` found for type parameter `T` in the current scope - --> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:24:7 + --> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:16:7 | LL | pub fn in_ty_param dyn std::fmt::Debug> (t: T) { | - method `method` not found for this type parameter @@ -22,7 +13,7 @@ LL | pub fn in_ty_param (dyn std::fmt::Debug) + Trait> (t: T) { | + +++++++++ error[E0277]: the size for values of type `T` cannot be known at compilation time - --> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:29:21 + --> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:21:21 | LL | fn with_sized &'static (dyn std::fmt::Debug) + ?Sized>() { | - this type parameter needs to be `Sized` @@ -30,7 +21,7 @@ LL | without_sized::(); | ^ doesn't have a size known at compile-time | note: required by an implicit `Sized` bound in `without_sized` - --> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:33:18 + --> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:25:18 | LL | fn without_sized &'static dyn std::fmt::Debug>() {} | ^ required by the implicit `Sized` requirement on this type parameter in `without_sized` @@ -45,7 +36,7 @@ LL | fn without_sized &'static (dyn std::fmt::Debug) + ?Sized>() {} | + ++++++++++ error[E0310]: the parameter type `impl FnOnce(T) -> dyn Future` may not live long enough - --> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:8:5 + --> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:6:5 | LL | Box::new(executor) | ^^^^^^^^^^^^^^^^^^ @@ -58,21 +49,7 @@ help: consider adding an explicit lifetime bound LL | executor: impl FnOnce(T) -> (dyn Future) + 'static, | + +++++++++++ -error[E0310]: the parameter type `impl FnOnce(T) -> dyn* Future` may not live long enough - --> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:14:5 - | -LL | Box::new(executor) - | ^^^^^^^^^^^^^^^^^^ - | | - | the parameter type `impl FnOnce(T) -> dyn* Future` must be valid for the static lifetime... - | ...so that the type `impl FnOnce(T) -> dyn* Future` will meet its required lifetime bounds - | -help: consider adding an explicit lifetime bound - | -LL | executor: impl FnOnce(T) -> (dyn* Future) + 'static, - | + +++++++++++ - -error: aborting due to 4 previous errors; 1 warning emitted +error: aborting due to 3 previous errors Some errors have detailed explanations: E0277, E0310, E0599. For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/dyn-star-drop-principal.rs b/tests/ui/traits/dyn-star-drop-principal.rs deleted file mode 100644 index 1ad99070339ad..0000000000000 --- a/tests/ui/traits/dyn-star-drop-principal.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![feature(dyn_star)] -#![allow(incomplete_features)] - -trait Trait {} -impl Trait for usize {} - -fn main() { - // We allow &dyn Trait + Send -> &dyn Send (i.e. dropping principal), - // but we don't (currently?) allow the same for dyn* - let x: dyn* Trait + Send = 1usize; - x as dyn* Send; //~ error: `dyn* Trait + Send` needs to have the same ABI as a pointer -} diff --git a/tests/ui/traits/dyn-star-drop-principal.stderr b/tests/ui/traits/dyn-star-drop-principal.stderr deleted file mode 100644 index 721ae7e191ef0..0000000000000 --- a/tests/ui/traits/dyn-star-drop-principal.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0277]: `dyn* Trait + Send` needs to have the same ABI as a pointer - --> $DIR/dyn-star-drop-principal.rs:11:5 - | -LL | x as dyn* Send; - | ^ `dyn* Trait + Send` needs to be a pointer-like type - | - = help: the trait `PointerLike` is not implemented for `dyn* Trait + Send` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/trait-upcasting/dyn-to-dyn-star.rs b/tests/ui/traits/trait-upcasting/dyn-to-dyn-star.rs deleted file mode 100644 index 5936c93efad31..0000000000000 --- a/tests/ui/traits/trait-upcasting/dyn-to-dyn-star.rs +++ /dev/null @@ -1,19 +0,0 @@ -// While somewhat nonsensical, this is a cast from a wide pointer to a thin pointer. -// Thus, we don't need to check an unsize goal here; there isn't any vtable casting -// happening at all. - -// Regression test for . - -//@ check-pass - -#![allow(incomplete_features)] -#![feature(dyn_star)] - -trait Foo {} -trait Bar {} - -fn cast(x: *const dyn Foo) { - x as *const dyn* Bar; -} - -fn main() {} diff --git a/tests/ui/unpretty/exhaustive.expanded.stdout b/tests/ui/unpretty/exhaustive.expanded.stdout index ae44d1206afa0..9193609ea859f 100644 --- a/tests/ui/unpretty/exhaustive.expanded.stdout +++ b/tests/ui/unpretty/exhaustive.expanded.stdout @@ -15,7 +15,6 @@ #![feature(const_trait_impl)] #![feature(decl_macro)] #![feature(deref_patterns)] -#![feature(dyn_star)] #![feature(explicit_tail_calls)] #![feature(gen_blocks)] #![feature(more_qualified_paths)] @@ -596,7 +595,6 @@ mod types { let _: dyn Send + 'static; let _: dyn 'static + Send; let _: dyn for<'a> Send; - let _: dyn* Send; } /// TyKind::ImplTrait const fn ty_impl_trait() { diff --git a/tests/ui/unpretty/exhaustive.hir.stderr b/tests/ui/unpretty/exhaustive.hir.stderr index 1c78cf98c59f1..8a68dfb1830c1 100644 --- a/tests/ui/unpretty/exhaustive.hir.stderr +++ b/tests/ui/unpretty/exhaustive.hir.stderr @@ -1,17 +1,17 @@ error[E0697]: closures cannot be static - --> $DIR/exhaustive.rs:210:9 + --> $DIR/exhaustive.rs:209:9 | LL | static || value; | ^^^^^^^^^ error[E0697]: closures cannot be static - --> $DIR/exhaustive.rs:211:9 + --> $DIR/exhaustive.rs:210:9 | LL | static move || value; | ^^^^^^^^^^^^^^ error[E0728]: `await` is only allowed inside `async` functions and blocks - --> $DIR/exhaustive.rs:240:13 + --> $DIR/exhaustive.rs:239:13 | LL | fn expr_await() { | --------------- this is not `async` @@ -20,19 +20,19 @@ LL | fut.await; | ^^^^^ only allowed inside `async` functions and blocks error: in expressions, `_` can only be used on the left-hand side of an assignment - --> $DIR/exhaustive.rs:289:9 + --> $DIR/exhaustive.rs:288:9 | LL | _; | ^ `_` not allowed here error[E0214]: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/exhaustive.rs:299:9 + --> $DIR/exhaustive.rs:298:9 | LL | x::(); | ^^^^^ only `Fn` traits may use parentheses error[E0214]: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/exhaustive.rs:300:9 + --> $DIR/exhaustive.rs:299:9 | LL | x::(T, T) -> T; | ^^^^^^^^^^^^^^ only `Fn` traits may use parentheses @@ -44,31 +44,31 @@ LL + x:: -> T; | error[E0214]: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/exhaustive.rs:301:9 + --> $DIR/exhaustive.rs:300:9 | LL | crate::() -> ()::expressions::() -> ()::expr_path; | ^^^^^^^^^^^^^^^ only `Fn` traits may use parentheses error[E0214]: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/exhaustive.rs:301:26 + --> $DIR/exhaustive.rs:300:26 | LL | crate::() -> ()::expressions::() -> ()::expr_path; | ^^^^^^^^^^^^^^^^^^^^^ only `Fn` traits may use parentheses error[E0214]: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/exhaustive.rs:304:9 + --> $DIR/exhaustive.rs:303:9 | LL | core::()::marker::()::PhantomData; | ^^^^^^^^ only `Fn` traits may use parentheses error[E0214]: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/exhaustive.rs:304:19 + --> $DIR/exhaustive.rs:303:19 | LL | core::()::marker::()::PhantomData; | ^^^^^^^^^^ only `Fn` traits may use parentheses error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks - --> $DIR/exhaustive.rs:391:9 + --> $DIR/exhaustive.rs:390:9 | LL | yield; | ^^^^^ @@ -79,7 +79,7 @@ LL | #[coroutine] fn expr_yield() { | ++++++++++++ error[E0703]: invalid ABI: found `C++` - --> $DIR/exhaustive.rs:471:23 + --> $DIR/exhaustive.rs:470:23 | LL | unsafe extern "C++" {} | ^^^^^ invalid ABI @@ -87,7 +87,7 @@ LL | unsafe extern "C++" {} = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions error: `..` patterns are not allowed here - --> $DIR/exhaustive.rs:678:13 + --> $DIR/exhaustive.rs:677:13 | LL | let ..; | ^^ @@ -95,13 +95,13 @@ LL | let ..; = note: only allowed in tuple, tuple struct, and slice patterns error[E0214]: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/exhaustive.rs:793:16 + --> $DIR/exhaustive.rs:792:16 | LL | let _: T() -> !; | ^^^^^^^^ only `Fn` traits may use parentheses error[E0562]: `impl Trait` is not allowed in the type of variable bindings - --> $DIR/exhaustive.rs:808:16 + --> $DIR/exhaustive.rs:806:16 | LL | let _: impl Send; | ^^^^^^^^^ @@ -112,7 +112,7 @@ LL | let _: impl Send; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0562]: `impl Trait` is not allowed in the type of variable bindings - --> $DIR/exhaustive.rs:809:16 + --> $DIR/exhaustive.rs:807:16 | LL | let _: impl Send + 'static; | ^^^^^^^^^^^^^^^^^^^ @@ -123,7 +123,7 @@ LL | let _: impl Send + 'static; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0562]: `impl Trait` is not allowed in the type of variable bindings - --> $DIR/exhaustive.rs:810:16 + --> $DIR/exhaustive.rs:808:16 | LL | let _: impl 'static + Send; | ^^^^^^^^^^^^^^^^^^^ @@ -134,7 +134,7 @@ LL | let _: impl 'static + Send; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0562]: `impl Trait` is not allowed in the type of variable bindings - --> $DIR/exhaustive.rs:811:16 + --> $DIR/exhaustive.rs:809:16 | LL | let _: impl ?Sized; | ^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL | let _: impl ?Sized; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0562]: `impl Trait` is not allowed in the type of variable bindings - --> $DIR/exhaustive.rs:812:16 + --> $DIR/exhaustive.rs:810:16 | LL | let _: impl ~const Clone; | ^^^^^^^^^^^^^^^^^ @@ -156,7 +156,7 @@ LL | let _: impl ~const Clone; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0562]: `impl Trait` is not allowed in the type of variable bindings - --> $DIR/exhaustive.rs:813:16 + --> $DIR/exhaustive.rs:811:16 | LL | let _: impl for<'a> Send; | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unpretty/exhaustive.hir.stdout b/tests/ui/unpretty/exhaustive.hir.stdout index 2d347ec6e88d3..2b8f3b21396be 100644 --- a/tests/ui/unpretty/exhaustive.hir.stdout +++ b/tests/ui/unpretty/exhaustive.hir.stdout @@ -14,7 +14,6 @@ #![feature(const_trait_impl)] #![feature(decl_macro)] #![feature(deref_patterns)] -#![feature(dyn_star)] #![feature(explicit_tail_calls)] #![feature(gen_blocks)] #![feature(more_qualified_paths)] @@ -661,7 +660,6 @@ mod types { let _: dyn Send + 'static; let _: dyn Send + 'static; let _: dyn for<'a> Send; - let _: dyn* Send; } /// TyKind::ImplTrait const fn ty_impl_trait() { diff --git a/tests/ui/unpretty/exhaustive.rs b/tests/ui/unpretty/exhaustive.rs index ccf907a616533..dd5cc695b197c 100644 --- a/tests/ui/unpretty/exhaustive.rs +++ b/tests/ui/unpretty/exhaustive.rs @@ -14,7 +14,6 @@ #![feature(const_trait_impl)] #![feature(decl_macro)] #![feature(deref_patterns)] -#![feature(dyn_star)] #![feature(explicit_tail_calls)] #![feature(gen_blocks)] #![feature(more_qualified_paths)] @@ -800,7 +799,6 @@ mod types { let _: dyn Send + 'static; let _: dyn 'static + Send; let _: dyn for<'a> Send; - let _: dyn* Send; } /// TyKind::ImplTrait From d1f313649ce215c9b0442354ec6aa03384d7101c Mon Sep 17 00:00:00 2001 From: xizheyin Date: Thu, 26 Jun 2025 23:06:38 +0800 Subject: [PATCH 2/6] Only args in main diag are saved and restored without removing the newly added ones Signed-off-by: xizheyin --- .../src/diagnostics/subdiagnostic.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs index 04fdada802494..dcd0116d804d3 100644 --- a/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs +++ b/compiler/rustc_macros/src/diagnostics/subdiagnostic.rs @@ -220,7 +220,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> { } /// Generates the code for a field with no attributes. - fn generate_field_arg(&mut self, binding_info: &BindingInfo<'_>) -> (TokenStream, TokenStream) { + fn generate_field_arg(&mut self, binding_info: &BindingInfo<'_>) -> TokenStream { let diag = &self.parent.diag; let field = binding_info.ast(); @@ -230,16 +230,12 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> { let ident = field.ident.as_ref().unwrap(); let ident = format_ident!("{}", ident); // strip `r#` prefix, if present - let args = quote! { + quote! { #diag.arg( stringify!(#ident), #field_binding ); - }; - let remove_args = quote! { - #diag.remove_arg(stringify!(#ident)); - }; - (args, remove_args) + } } /// Generates the necessary code for all attributes on a field. @@ -610,7 +606,7 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> { let restore_args = quote! { #diag.restore_args(); }; - let (plain_args, remove_args): (TokenStream, TokenStream) = self + let plain_args: TokenStream = self .variant .bindings() .iter() @@ -623,9 +619,8 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> { // For #[derive(Subdiagnostic)] // // - Store args of the main diagnostic for later restore. - // - add args of subdiagnostic. + // - Add args of subdiagnostic. // - Generate the calls, such as note, label, etc. - // - Remove the arguments for allowing Vec to be used. // - Restore the arguments for allowing main and subdiagnostic share the same fields. Ok(quote! { #init @@ -634,7 +629,6 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> { #store_args #plain_args #calls - #remove_args #restore_args }) } From 3b259ad33c8257944bf7069d3c6f463393bf7bc4 Mon Sep 17 00:00:00 2001 From: binarycat Date: Mon, 9 Jun 2025 15:33:30 -0500 Subject: [PATCH 3/6] rustdoc js: several typechecking improvments non-exhaustive list of changes: * rustdoc.Results has a max_dist field * improve typechecking around pathDist and addIntoResults * give handleNameSearch a type signature * typecheck sortQ * currentCrate is string and not optional * searchState is referenced as a global, not through window --- src/librustdoc/html/static/js/rustdoc.d.ts | 28 ++++--- src/librustdoc/html/static/js/search.js | 92 +++++++--------------- 2 files changed, 43 insertions(+), 77 deletions(-) diff --git a/src/librustdoc/html/static/js/rustdoc.d.ts b/src/librustdoc/html/static/js/rustdoc.d.ts index 6af16441de88b..bbcd96040bec6 100644 --- a/src/librustdoc/html/static/js/rustdoc.d.ts +++ b/src/librustdoc/html/static/js/rustdoc.d.ts @@ -4,6 +4,8 @@ /* eslint-disable */ declare global { + /** Search engine data used by main.js and search.js */ + declare var searchState: rustdoc.SearchState; /** Defined and documented in `storage.js` */ declare function nonnull(x: T|null, msg: string|undefined); /** Defined and documented in `storage.js` */ @@ -17,8 +19,6 @@ declare global { RUSTDOC_TOOLTIP_HOVER_MS: number; /** Used by the popover tooltip code. */ RUSTDOC_TOOLTIP_HOVER_EXIT_MS: number; - /** Search engine data used by main.js and search.js */ - searchState: rustdoc.SearchState; /** Global option, with a long list of "../"'s */ rootPath: string|null; /** @@ -102,20 +102,22 @@ declare namespace rustdoc { currentTab: number; focusedByTab: [number|null, number|null, number|null]; clearInputTimeout: function; - outputElement: function(): HTMLElement|null; - focus: function(); - defocus: function(); - showResults: function(HTMLElement|null|undefined); - removeQueryParameters: function(); - hideResults: function(); - getQueryStringParams: function(): Object.; + outputElement(): HTMLElement|null; + focus(); + defocus(); + // note: an optional param is not the same as + // a nullable/undef-able param. + showResults(elem?: HTMLElement|null); + removeQueryParameters(); + hideResults(); + getQueryStringParams(): Object.; origPlaceholder: string; setup: function(); - setLoadingSearch: function(); + setLoadingSearch(); descShards: Map; loadDesc: function({descShard: SearchDescShard, descIndex: number}): Promise; - loadedDescShard: function(string, number, string); - isDisplayed: function(): boolean, + loadedDescShard(string, number, string); + isDisplayed(): boolean, } interface SearchDescShard { @@ -237,7 +239,7 @@ declare namespace rustdoc { query: ParsedQuery, } - type Results = Map; + type Results = { max_dist?: number } & Map /** * An annotated `Row`, used in the viewmodel. diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index a2c48708512e8..15cad31f555a6 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -2515,13 +2515,17 @@ class DocSearch { * * @param {rustdoc.ParsedQuery} origParsedQuery * - The parsed user query - * @param {Object} [filterCrates] - Crate to search in if defined - * @param {Object} [currentCrate] - Current crate, to rank results from this crate higher + * @param {Object} filterCrates - Crate to search in if defined + * @param {string} currentCrate - Current crate, to rank results from this crate higher * * @return {Promise} */ async execQuery(origParsedQuery, filterCrates, currentCrate) { - const results_others = new Map(), results_in_args = new Map(), + /** @type {rustdoc.Results} */ + const results_others = new Map(), + /** @type {rustdoc.Results} */ + results_in_args = new Map(), + /** @type {rustdoc.Results} */ results_returned = new Map(); /** @type {rustdoc.ParsedQuery} */ @@ -4365,7 +4369,7 @@ class DocSearch { * * The `results` map contains information which will be used to sort the search results: * - * * `fullId` is a `string`` used as the key of the object we use for the `results` map. + * * `fullId` is an `integer`` used as the key of the object we use for the `results` map. * * `id` is the index in the `searchIndex` array for this element. * * `index` is an `integer`` used to sort by the position of the word in the item's name. * * `dist` is the main metric used to sort the search results. @@ -4373,19 +4377,18 @@ class DocSearch { * distance computed for everything other than the last path component. * * @param {rustdoc.Results} results - * @param {string} fullId + * @param {number} fullId * @param {number} id * @param {number} index * @param {number} dist * @param {number} path_dist + * @param {number} maxEditDistance */ - // @ts-expect-error function addIntoResults(results, fullId, id, index, dist, path_dist, maxEditDistance) { if (dist <= maxEditDistance || index !== -1) { if (results.has(fullId)) { const result = results.get(fullId); - // @ts-expect-error - if (result.dontValidate || result.dist <= dist) { + if (result === undefined || result.dontValidate || result.dist <= dist) { return; } } @@ -4452,9 +4455,8 @@ class DocSearch { return; } - // @ts-expect-error results.max_dist = Math.max(results.max_dist || 0, tfpDist); - addIntoResults(results, row.id.toString(), pos, 0, tfpDist, 0, Number.MAX_VALUE); + addIntoResults(results, row.id, pos, 0, tfpDist, 0, Number.MAX_VALUE); } /** @@ -4495,7 +4497,7 @@ class DocSearch { if (parsedQuery.foundElems === 1 && !parsedQuery.hasReturnArrow) { const elem = parsedQuery.elems[0]; // use arrow functions to preserve `this`. - // @ts-expect-error + /** @type {function(number): void} */ const handleNameSearch = id => { const row = this.searchIndex[id]; if (!typePassesFilter(elem.typeFilter, row.ty) || @@ -4505,22 +4507,21 @@ class DocSearch { let pathDist = 0; if (elem.fullPath.length > 1) { - // @ts-expect-error - pathDist = checkPath(elem.pathWithoutLast, row); - if (pathDist === null) { + + const maybePathDist = checkPath(elem.pathWithoutLast, row); + if (maybePathDist === null) { return; } + pathDist = maybePathDist; } if (parsedQuery.literalSearch) { if (row.word === elem.pathLast) { - // @ts-expect-error - addIntoResults(results_others, row.id, id, 0, 0, pathDist); + addIntoResults(results_others, row.id, id, 0, 0, pathDist, 0); } } else { addIntoResults( results_others, - // @ts-expect-error row.id, id, row.normalizedName.indexOf(elem.normalizedPathLast), @@ -4561,31 +4562,23 @@ class DocSearch { const returned = row.type && row.type.output && checkIfInList(row.type.output, elem, row.type.where_clause, null, 0); if (in_args) { - // @ts-expect-error results_in_args.max_dist = Math.max( - // @ts-expect-error results_in_args.max_dist || 0, tfpDist, ); const maxDist = results_in_args.size < MAX_RESULTS ? (tfpDist + 1) : - // @ts-expect-error results_in_args.max_dist; - // @ts-expect-error addIntoResults(results_in_args, row.id, i, -1, tfpDist, 0, maxDist); } if (returned) { - // @ts-expect-error results_returned.max_dist = Math.max( - // @ts-expect-error results_returned.max_dist || 0, tfpDist, ); const maxDist = results_returned.size < MAX_RESULTS ? (tfpDist + 1) : - // @ts-expect-error results_returned.max_dist; - // @ts-expect-error addIntoResults(results_returned, row.id, i, -1, tfpDist, 0, maxDist); } } @@ -4595,18 +4588,17 @@ class DocSearch { // types with generic parameters go last. // That's because of the way unification is structured: it eats off // the end, and hits a fast path if the last item is a simple atom. - // @ts-expect-error + /** @type {function(rustdoc.QueryElement, rustdoc.QueryElement): number} */ const sortQ = (a, b) => { const ag = a.generics.length === 0 && a.bindings.size === 0; const bg = b.generics.length === 0 && b.bindings.size === 0; if (ag !== bg) { - // @ts-expect-error - return ag - bg; + // unary `+` converts booleans into integers. + return +ag - +bg; } - const ai = a.id > 0; - const bi = b.id > 0; - // @ts-expect-error - return ai - bi; + const ai = a.id !== null && a.id > 0; + const bi = b.id !== null && b.id > 0; + return +ai - +bi; }; parsedQuery.elems.sort(sortQ); parsedQuery.returned.sort(sortQ); @@ -4622,9 +4614,7 @@ class DocSearch { const isType = parsedQuery.foundElems !== 1 || parsedQuery.hasReturnArrow; const [sorted_in_args, sorted_returned, sorted_others] = await Promise.all([ - // @ts-expect-error sortResults(results_in_args, "elems", currentCrate), - // @ts-expect-error sortResults(results_returned, "returned", currentCrate), // @ts-expect-error sortResults(results_others, (isType ? "query" : null), currentCrate), @@ -4724,7 +4714,6 @@ function printTab(nb) { iter += 1; }); if (foundCurrentTab && foundCurrentResultSet) { - // @ts-expect-error searchState.currentTab = nb; // Corrections only kick in on type-based searches. const correctionsElem = document.getElementsByClassName("search-corrections"); @@ -4777,7 +4766,6 @@ function getFilterCrates() { // @ts-expect-error function nextTab(direction) { - // @ts-expect-error const next = (searchState.currentTab + direction + 3) % searchState.focusedByTab.length; // @ts-expect-error searchState.focusedByTab[searchState.currentTab] = document.activeElement; @@ -4788,14 +4776,12 @@ function nextTab(direction) { // Focus the first search result on the active tab, or the result that // was focused last time this tab was active. function focusSearchResult() { - // @ts-expect-error const target = searchState.focusedByTab[searchState.currentTab] || document.querySelectorAll(".search-results.active a").item(0) || - // @ts-expect-error document.querySelectorAll("#search-tabs button").item(searchState.currentTab); - // @ts-expect-error searchState.focusedByTab[searchState.currentTab] = null; if (target) { + // @ts-expect-error target.focus(); } } @@ -4947,7 +4933,6 @@ function makeTabHeader(tabNb, text, nbElems) { const fmtNbElems = nbElems < 10 ? `\u{2007}(${nbElems})\u{2007}\u{2007}` : nbElems < 100 ? `\u{2007}(${nbElems})\u{2007}` : `\u{2007}(${nbElems})`; - // @ts-expect-error if (searchState.currentTab === tabNb) { return ""; @@ -4961,7 +4946,6 @@ function makeTabHeader(tabNb, text, nbElems) { * @param {string} filterCrates */ async function showResults(results, go_to_first, filterCrates) { - // @ts-expect-error const search = searchState.outputElement(); if (go_to_first || (results.others.length === 1 && getSettingValue("go-to-only-result") === "true") @@ -4979,7 +4963,6 @@ async function showResults(results, go_to_first, filterCrates) { // will be used, starting search again since the search input is not empty, leading you // back to the previous page again. window.onunload = () => { }; - // @ts-expect-error searchState.removeQueryParameters(); const elem = document.createElement("a"); elem.href = results.others[0].href; @@ -4999,7 +4982,6 @@ async function showResults(results, go_to_first, filterCrates) { // Navigate to the relevant tab if the current tab is empty, like in case users search // for "-> String". If they had selected another tab previously, they have to click on // it again. - // @ts-expect-error let currentTab = searchState.currentTab; if ((currentTab === 0 && results.others.length === 0) || (currentTab === 1 && results.in_args.length === 0) || @@ -5087,8 +5069,8 @@ async function showResults(results, go_to_first, filterCrates) { resultsElem.appendChild(ret_in_args); resultsElem.appendChild(ret_returned); - search.innerHTML = output; // @ts-expect-error + search.innerHTML = output; if (searchState.rustdocToolbar) { // @ts-expect-error search.querySelector(".main-heading").appendChild(searchState.rustdocToolbar); @@ -5097,9 +5079,9 @@ async function showResults(results, go_to_first, filterCrates) { if (crateSearch) { crateSearch.addEventListener("input", updateCrate); } + // @ts-expect-error search.appendChild(resultsElem); // Reset focused elements. - // @ts-expect-error searchState.showResults(search); // @ts-expect-error const elems = document.getElementById("search-tabs").childNodes; @@ -5110,7 +5092,6 @@ async function showResults(results, go_to_first, filterCrates) { const j = i; // @ts-expect-error elem.onclick = () => printTab(j); - // @ts-expect-error searchState.focusedByTab.push(null); i += 1; } @@ -5122,7 +5103,6 @@ function updateSearchHistory(url) { if (!browserSupportsHistoryApi()) { return; } - // @ts-expect-error const params = searchState.getQueryStringParams(); if (!history.state && !params.search) { history.pushState(null, "", url); @@ -5149,10 +5129,8 @@ async function search(forced) { return; } - // @ts-expect-error searchState.setLoadingSearch(); - // @ts-expect-error const params = searchState.getQueryStringParams(); // In case we have no information about the saved crate and there is a URL query parameter, @@ -5162,7 +5140,6 @@ async function search(forced) { } // Update document title to maintain a meaningful browser history - // @ts-expect-error searchState.title = "\"" + query.userQuery + "\" Search - Rust"; // Because searching is incremental by character, only the most @@ -5184,33 +5161,28 @@ async function search(forced) { function onSearchSubmit(e) { // @ts-expect-error e.preventDefault(); - // @ts-expect-error searchState.clearInputTimeout(); search(); } function putBackSearch() { - // @ts-expect-error const search_input = searchState.input; - // @ts-expect-error if (!searchState.input) { return; } // @ts-expect-error if (search_input.value !== "" && !searchState.isDisplayed()) { - // @ts-expect-error searchState.showResults(); if (browserSupportsHistoryApi()) { history.replaceState(null, "", + // @ts-expect-error buildUrl(search_input.value, getFilterCrates())); } - // @ts-expect-error document.title = searchState.title; } } function registerSearchEvents() { - // @ts-expect-error const params = searchState.getQueryStringParams(); // Populate search bar with query string search term when provided, @@ -5224,14 +5196,11 @@ function registerSearchEvents() { } const searchAfter500ms = () => { - // @ts-expect-error searchState.clearInputTimeout(); // @ts-expect-error if (searchState.input.value.length === 0) { - // @ts-expect-error searchState.hideResults(); } else { - // @ts-expect-error searchState.timeout = setTimeout(search, 500); } }; @@ -5248,7 +5217,6 @@ function registerSearchEvents() { return; } // Do NOT e.preventDefault() here. It will prevent pasting. - // @ts-expect-error searchState.clearInputTimeout(); // zero-timeout necessary here because at the time of event handler execution the // pasted content is not in the input field yet. Shouldn’t make any difference for @@ -5274,7 +5242,6 @@ function registerSearchEvents() { // @ts-expect-error previous.focus(); } else { - // @ts-expect-error searchState.focus(); } e.preventDefault(); @@ -5327,7 +5294,6 @@ function registerSearchEvents() { const previousTitle = document.title; window.addEventListener("popstate", e => { - // @ts-expect-error const params = searchState.getQueryStringParams(); // Revert to the previous title manually since the History // API ignores the title parameter. @@ -5355,7 +5321,6 @@ function registerSearchEvents() { searchState.input.value = ""; // When browsing back from search results the main page // visibility must be reset. - // @ts-expect-error searchState.hideResults(); } }); @@ -5368,7 +5333,6 @@ function registerSearchEvents() { // that try to sync state between the URL and the search input. To work around it, // do a small amount of re-init on page show. window.onpageshow = () => { - // @ts-expect-error const qSearch = searchState.getQueryStringParams().search; // @ts-expect-error if (searchState.input.value === "" && qSearch) { From 1365d3ba1fda7c5be7bb8d13042bee8ae724d748 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 25 Jun 2025 18:33:01 +0200 Subject: [PATCH 4/6] codegen_fn_attrs: make comment more precise --- compiler/rustc_codegen_ssa/src/codegen_attrs.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index 94df5e8b361d7..8d1973058b0ae 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -430,7 +430,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { } } - // Apply the minimum function alignment here, so that individual backends don't have to. + // Apply the minimum function alignment here. This ensures that a function's alignment is + // determined by the `-C` flags of the crate it is defined in, not the `-C` flags of the crate + // it happens to be codegen'd (or const-eval'd) in. codegen_fn_attrs.alignment = Ord::max(codegen_fn_attrs.alignment, tcx.sess.opts.unstable_opts.min_function_alignment); From 9e3568407234ba4b8fa772cb4acf8d18b12baa7c Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Wed, 25 Jun 2025 09:36:26 +0200 Subject: [PATCH 5/6] Port `#[used]` to new attribute parsing infrastructure Signed-off-by: Jonathan Brouwer --- .../src/attributes.rs | 14 ++++ .../src/encode_cross_crate.rs | 1 + .../src/attributes/codegen_attrs.rs | 83 ++++++++++++++++++- compiler/rustc_attr_parsing/src/context.rs | 2 + compiler/rustc_codegen_ssa/messages.ftl | 2 - .../rustc_codegen_ssa/src/codegen_attrs.rs | 44 ++-------- compiler/rustc_codegen_ssa/src/errors.rs | 7 -- compiler/rustc_passes/messages.ftl | 3 - compiler/rustc_passes/src/check_attr.rs | 50 +++-------- compiler/rustc_passes/src/errors.rs | 7 -- tests/ui/attributes/used_with_arg.rs | 15 +++- tests/ui/attributes/used_with_arg.stderr | 39 +++++++-- tests/ui/attributes/used_with_multi_args.rs | 2 +- .../ui/attributes/used_with_multi_args.stderr | 16 +++- .../lint/unused/unused-attr-duplicate.stderr | 24 +++--- 15 files changed, 185 insertions(+), 124 deletions(-) diff --git a/compiler/rustc_attr_data_structures/src/attributes.rs b/compiler/rustc_attr_data_structures/src/attributes.rs index d755afad59fb8..60a4f28930691 100644 --- a/compiler/rustc_attr_data_structures/src/attributes.rs +++ b/compiler/rustc_attr_data_structures/src/attributes.rs @@ -131,6 +131,17 @@ impl Deprecation { } } +/// There are three valid forms of the attribute: +/// `#[used]`, which is semantically equivalent to `#[used(linker)]` except that the latter is currently unstable. +/// `#[used(compiler)]` +/// `#[used(linker)]` +#[derive(Encodable, Decodable, Copy, Clone, Debug, PartialEq, Eq, Hash)] +#[derive(HashStable_Generic, PrintAttribute)] +pub enum UsedBy { + Compiler, + Linker, +} + /// Represents parsed *built-in* inert attributes. /// /// ## Overview @@ -285,5 +296,8 @@ pub enum AttributeKind { /// Represents `#[track_caller]` TrackCaller(Span), + + /// Represents `#[used]` + Used { used_by: UsedBy, span: Span }, // tidy-alphabetical-end } diff --git a/compiler/rustc_attr_data_structures/src/encode_cross_crate.rs b/compiler/rustc_attr_data_structures/src/encode_cross_crate.rs index d4402f4e2e63d..64bcf1fe6cce7 100644 --- a/compiler/rustc_attr_data_structures/src/encode_cross_crate.rs +++ b/compiler/rustc_attr_data_structures/src/encode_cross_crate.rs @@ -38,6 +38,7 @@ impl AttributeKind { PubTransparent(..) => Yes, SkipDuringMethodDispatch { .. } => No, TrackCaller(..) => Yes, + Used { .. } => No, } } } diff --git a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs index 5a849e79cc32d..7c412d4fa892b 100644 --- a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs @@ -1,4 +1,4 @@ -use rustc_attr_data_structures::{AttributeKind, OptimizeAttr}; +use rustc_attr_data_structures::{AttributeKind, OptimizeAttr, UsedBy}; use rustc_feature::{AttributeTemplate, template}; use rustc_session::parse::feature_err; use rustc_span::{Span, Symbol, sym}; @@ -228,3 +228,84 @@ impl SingleAttributeParser for NoMangleParser { Some(AttributeKind::NoMangle(cx.attr_span)) } } + +#[derive(Default)] +pub(crate) struct UsedParser { + first_compiler: Option, + first_linker: Option, +} + +// A custom `AttributeParser` is used rather than a Simple attribute parser because +// - Specifying two `#[used]` attributes is a warning (but will be an error in the future) +// - But specifying two conflicting attributes: `#[used(compiler)]` and `#[used(linker)]` is already an error today +// We can change this to a Simple parser once the warning becomes an error +impl AttributeParser for UsedParser { + const ATTRIBUTES: AcceptMapping = &[( + &[sym::used], + template!(Word, List: "compiler|linker"), + |group: &mut Self, cx, args| { + let used_by = match args { + ArgParser::NoArgs => UsedBy::Linker, + ArgParser::List(list) => { + let Some(l) = list.single() else { + cx.expected_single_argument(list.span); + return; + }; + + match l.meta_item().and_then(|i| i.path().word_sym()) { + Some(sym::compiler) => { + if !cx.features().used_with_arg() { + feature_err( + &cx.sess(), + sym::used_with_arg, + cx.attr_span, + "`#[used(compiler)]` is currently unstable", + ) + .emit(); + } + UsedBy::Compiler + } + Some(sym::linker) => { + if !cx.features().used_with_arg() { + feature_err( + &cx.sess(), + sym::used_with_arg, + cx.attr_span, + "`#[used(linker)]` is currently unstable", + ) + .emit(); + } + UsedBy::Linker + } + _ => { + cx.expected_specific_argument(l.span(), vec!["compiler", "linker"]); + return; + } + } + } + ArgParser::NameValue(_) => return, + }; + + let target = match used_by { + UsedBy::Compiler => &mut group.first_compiler, + UsedBy::Linker => &mut group.first_linker, + }; + + let attr_span = cx.attr_span; + if let Some(prev) = *target { + cx.warn_unused_duplicate(prev, attr_span); + } else { + *target = Some(attr_span); + } + }, + )]; + + fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option { + // Ratcheting behaviour, if both `linker` and `compiler` are specified, use `linker` + Some(match (self.first_compiler, self.first_linker) { + (_, Some(span)) => AttributeKind::Used { used_by: UsedBy::Linker, span }, + (Some(span), _) => AttributeKind::Used { used_by: UsedBy::Compiler, span }, + (None, None) => return None, + }) + } +} diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index 83e3c75dedb4e..71bb86ca3d3b8 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -17,6 +17,7 @@ use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym}; use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInternalUnstableParser}; use crate::attributes::codegen_attrs::{ ColdParser, ExportNameParser, NakedParser, NoMangleParser, OptimizeParser, TrackCallerParser, + UsedParser, }; use crate::attributes::confusables::ConfusablesParser; use crate::attributes::deprecation::DeprecationParser; @@ -103,6 +104,7 @@ attribute_parsers!( ConstStabilityParser, NakedParser, StabilityParser, + UsedParser, // tidy-alphabetical-end // tidy-alphabetical-start diff --git a/compiler/rustc_codegen_ssa/messages.ftl b/compiler/rustc_codegen_ssa/messages.ftl index 6362d2edf8554..84d6381934358 100644 --- a/compiler/rustc_codegen_ssa/messages.ftl +++ b/compiler/rustc_codegen_ssa/messages.ftl @@ -48,8 +48,6 @@ codegen_ssa_error_writing_def_file = codegen_ssa_expected_name_value_pair = expected name value pair -codegen_ssa_expected_used_symbol = expected `used`, `used(compiler)` or `used(linker)` - codegen_ssa_extern_funcs_not_found = some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified codegen_ssa_extract_bundled_libs_archive_member = failed to get data from archive member '{$rlib}': {$error} diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index 94df5e8b361d7..716b2d76c6208 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -4,7 +4,7 @@ use rustc_abi::ExternAbi; use rustc_ast::expand::autodiff_attrs::{AutoDiffAttrs, DiffActivity, DiffMode}; use rustc_ast::{LitKind, MetaItem, MetaItemInner, attr}; use rustc_attr_data_structures::{ - AttributeKind, InlineAttr, InstructionSetAttr, OptimizeAttr, ReprAttr, find_attr, + AttributeKind, InlineAttr, InstructionSetAttr, OptimizeAttr, ReprAttr, UsedBy, find_attr, }; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId}; @@ -160,6 +160,10 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { } codegen_fn_attrs.flags |= CodegenFnAttrFlags::TRACK_CALLER } + AttributeKind::Used { used_by, .. } => match used_by { + UsedBy::Compiler => codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED_COMPILER, + UsedBy::Linker => codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED_LINKER, + }, _ => {} } } @@ -181,44 +185,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { sym::rustc_std_internal_symbol => { codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL } - sym::used => { - let inner = attr.meta_item_list(); - match inner.as_deref() { - Some([item]) if item.has_name(sym::linker) => { - if !tcx.features().used_with_arg() { - feature_err( - &tcx.sess, - sym::used_with_arg, - attr.span(), - "`#[used(linker)]` is currently unstable", - ) - .emit(); - } - codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED_LINKER; - } - Some([item]) if item.has_name(sym::compiler) => { - if !tcx.features().used_with_arg() { - feature_err( - &tcx.sess, - sym::used_with_arg, - attr.span(), - "`#[used(compiler)]` is currently unstable", - ) - .emit(); - } - codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED_COMPILER; - } - Some(_) => { - tcx.dcx().emit_err(errors::ExpectedUsedSymbol { span: attr.span() }); - } - None => { - // Unconditionally using `llvm.used` causes issues in handling - // `.init_array` with the gold linker. Luckily gold has been - // deprecated with GCC 15 and rustc now warns about using gold. - codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED_LINKER - } - } - } sym::thread_local => codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL, sym::target_feature => { let Some(sig) = tcx.hir_node_by_def_id(did).fn_sig() else { diff --git a/compiler/rustc_codegen_ssa/src/errors.rs b/compiler/rustc_codegen_ssa/src/errors.rs index db536af0162f1..1950a35b364dd 100644 --- a/compiler/rustc_codegen_ssa/src/errors.rs +++ b/compiler/rustc_codegen_ssa/src/errors.rs @@ -726,13 +726,6 @@ pub struct UnknownArchiveKind<'a> { pub kind: &'a str, } -#[derive(Diagnostic)] -#[diag(codegen_ssa_expected_used_symbol)] -pub(crate) struct ExpectedUsedSymbol { - #[primary_span] - pub span: Span, -} - #[derive(Diagnostic)] #[diag(codegen_ssa_multiple_main_functions)] #[help] diff --git a/compiler/rustc_passes/messages.ftl b/compiler/rustc_passes/messages.ftl index e2995daadfe56..b1c7b0fcd6c62 100644 --- a/compiler/rustc_passes/messages.ftl +++ b/compiler/rustc_passes/messages.ftl @@ -816,9 +816,6 @@ passes_unused_variable_try_prefix = unused variable: `{$name}` .suggestion = if this is intentional, prefix it with an underscore -passes_used_compiler_linker = - `used(compiler)` and `used(linker)` can't be used together - passes_used_static = attribute must be applied to a `static` variable .label = but this is a {$target} diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 491b3699f4c32..877bb9be28961 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -200,6 +200,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> { Attribute::Parsed(AttributeKind::NoMangle(attr_span)) => { self.check_no_mangle(hir_id, *attr_span, span, target) } + Attribute::Parsed(AttributeKind::Used { span: attr_span, .. }) => { + self.check_used(*attr_span, target, span); + } Attribute::Unparsed(attr_item) => { style = Some(attr_item.style); match attr.path().as_slice() { @@ -333,7 +336,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { | sym::cfi_encoding // FIXME(cfi_encoding) | sym::pointee // FIXME(derive_coerce_pointee) | sym::omit_gdb_pretty_printer_section // FIXME(omit_gdb_pretty_printer_section) - | sym::used // handled elsewhere to restrict to static items | sym::instruction_set // broken on stable!!! | sym::windows_subsystem // broken on stable!!! | sym::patchable_function_entry // FIXME(patchable_function_entry) @@ -403,7 +405,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } self.check_repr(attrs, span, target, item, hir_id); - self.check_used(attrs, target, span); self.check_rustc_force_inline(hir_id, attrs, span, target); self.check_mix_no_mangle_export(hir_id, attrs); } @@ -2107,44 +2108,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } } - fn check_used(&self, attrs: &[Attribute], target: Target, target_span: Span) { - let mut used_linker_span = None; - let mut used_compiler_span = None; - for attr in attrs.iter().filter(|attr| attr.has_name(sym::used)) { - if target != Target::Static { - self.dcx().emit_err(errors::UsedStatic { - attr_span: attr.span(), - span: target_span, - target: target.name(), - }); - } - let inner = attr.meta_item_list(); - match inner.as_deref() { - Some([item]) if item.has_name(sym::linker) => { - if used_linker_span.is_none() { - used_linker_span = Some(attr.span()); - } - } - Some([item]) if item.has_name(sym::compiler) => { - if used_compiler_span.is_none() { - used_compiler_span = Some(attr.span()); - } - } - Some(_) => { - // This error case is handled in rustc_hir_analysis::collect. - } - None => { - // Default case (compiler) when arg isn't defined. - if used_compiler_span.is_none() { - used_compiler_span = Some(attr.span()); - } - } - } - } - if let (Some(linker_span), Some(compiler_span)) = (used_linker_span, used_compiler_span) { - self.tcx - .dcx() - .emit_err(errors::UsedCompilerLinker { spans: vec![linker_span, compiler_span] }); + fn check_used(&self, attr_span: Span, target: Target, target_span: Span) { + if target != Target::Static { + self.dcx().emit_err(errors::UsedStatic { + attr_span, + span: target_span, + target: target.name(), + }); } } diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 3286ccc94f210..f89d925202c26 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -641,13 +641,6 @@ pub(crate) struct UsedStatic { pub target: &'static str, } -#[derive(Diagnostic)] -#[diag(passes_used_compiler_linker)] -pub(crate) struct UsedCompilerLinker { - #[primary_span] - pub spans: Vec, -} - #[derive(Diagnostic)] #[diag(passes_allow_internal_unstable)] pub(crate) struct AllowInternalUnstable { diff --git a/tests/ui/attributes/used_with_arg.rs b/tests/ui/attributes/used_with_arg.rs index ad80ff53f0ef0..bc7a6f07442ba 100644 --- a/tests/ui/attributes/used_with_arg.rs +++ b/tests/ui/attributes/used_with_arg.rs @@ -1,3 +1,4 @@ +#![deny(unused_attributes)] #![feature(used_with_arg)] #[used(linker)] @@ -6,14 +7,22 @@ static mut USED_LINKER: [usize; 1] = [0]; #[used(compiler)] static mut USED_COMPILER: [usize; 1] = [0]; -#[used(compiler)] //~ ERROR `used(compiler)` and `used(linker)` can't be used together +#[used(compiler)] #[used(linker)] static mut USED_COMPILER_LINKER2: [usize; 1] = [0]; -#[used(compiler)] //~ ERROR `used(compiler)` and `used(linker)` can't be used together -#[used(linker)] #[used(compiler)] #[used(linker)] +#[used(compiler)] //~ ERROR unused attribute +#[used(linker)] //~ ERROR unused attribute static mut USED_COMPILER_LINKER3: [usize; 1] = [0]; +#[used(compiler)] +#[used] +static mut USED_WITHOUT_ATTR1: [usize; 1] = [0]; + +#[used(linker)] +#[used] //~ ERROR unused attribute +static mut USED_WITHOUT_ATTR2: [usize; 1] = [0]; + fn main() {} diff --git a/tests/ui/attributes/used_with_arg.stderr b/tests/ui/attributes/used_with_arg.stderr index 440e5c4a5a020..9ff91a4e03b3e 100644 --- a/tests/ui/attributes/used_with_arg.stderr +++ b/tests/ui/attributes/used_with_arg.stderr @@ -1,18 +1,43 @@ -error: `used(compiler)` and `used(linker)` can't be used together - --> $DIR/used_with_arg.rs:9:1 +error: unused attribute + --> $DIR/used_with_arg.rs:16:1 + | +LL | #[used(compiler)] + | ^^^^^^^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/used_with_arg.rs:14:1 | LL | #[used(compiler)] | ^^^^^^^^^^^^^^^^^ +note: the lint level is defined here + --> $DIR/used_with_arg.rs:1:9 + | +LL | #![deny(unused_attributes)] + | ^^^^^^^^^^^^^^^^^ + +error: unused attribute + --> $DIR/used_with_arg.rs:17:1 + | +LL | #[used(linker)] + | ^^^^^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/used_with_arg.rs:15:1 + | LL | #[used(linker)] | ^^^^^^^^^^^^^^^ -error: `used(compiler)` and `used(linker)` can't be used together - --> $DIR/used_with_arg.rs:13:1 +error: unused attribute + --> $DIR/used_with_arg.rs:25:1 + | +LL | #[used] + | ^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/used_with_arg.rs:24:1 | -LL | #[used(compiler)] - | ^^^^^^^^^^^^^^^^^ LL | #[used(linker)] | ^^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors diff --git a/tests/ui/attributes/used_with_multi_args.rs b/tests/ui/attributes/used_with_multi_args.rs index d3109cc64442e..1c054f792eb99 100644 --- a/tests/ui/attributes/used_with_multi_args.rs +++ b/tests/ui/attributes/used_with_multi_args.rs @@ -1,6 +1,6 @@ #![feature(used_with_arg)] -#[used(compiler, linker)] //~ ERROR expected `used`, `used(compiler)` or `used(linker)` +#[used(compiler, linker)] //~ ERROR malformed `used` attribute input static mut USED_COMPILER_LINKER: [usize; 1] = [0]; fn main() {} diff --git a/tests/ui/attributes/used_with_multi_args.stderr b/tests/ui/attributes/used_with_multi_args.stderr index d4417a202d5fe..e48209cf20424 100644 --- a/tests/ui/attributes/used_with_multi_args.stderr +++ b/tests/ui/attributes/used_with_multi_args.stderr @@ -1,8 +1,20 @@ -error: expected `used`, `used(compiler)` or `used(linker)` +error[E0805]: malformed `used` attribute input --> $DIR/used_with_multi_args.rs:3:1 | LL | #[used(compiler, linker)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^------------------^ + | | + | expected a single argument here + | +help: try changing it to one of the following valid forms of the attribute + | +LL - #[used(compiler, linker)] +LL + #[used(compiler|linker)] + | +LL - #[used(compiler, linker)] +LL + #[used] + | error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0805`. diff --git a/tests/ui/lint/unused/unused-attr-duplicate.stderr b/tests/ui/lint/unused/unused-attr-duplicate.stderr index 3a520ffcb3df1..a18581192ea66 100644 --- a/tests/ui/lint/unused/unused-attr-duplicate.stderr +++ b/tests/ui/lint/unused/unused-attr-duplicate.stderr @@ -89,18 +89,6 @@ note: attribute also specified here LL | #[automatically_derived] | ^^^^^^^^^^^^^^^^^^^^^^^^ -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:102:1 - | -LL | #[used] - | ^^^^^^^ help: remove this attribute - | -note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:101:1 - | -LL | #[used] - | ^^^^^^^ - error: unused attribute --> $DIR/unused-attr-duplicate.rs:86:5 | @@ -289,5 +277,17 @@ note: attribute also specified here LL | #[no_mangle] | ^^^^^^^^^^^^ +error: unused attribute + --> $DIR/unused-attr-duplicate.rs:102:1 + | +LL | #[used] + | ^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/unused-attr-duplicate.rs:101:1 + | +LL | #[used] + | ^^^^^^^ + error: aborting due to 23 previous errors From c51f05be3094651711072e43bacac47cf7426be9 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 6 Jun 2025 09:28:25 +0000 Subject: [PATCH 6/6] Report infer ty errors during hir ty lowering This centralizes the placeholder type error reporting in one location, but it also exposes the granularity at which we convert things from hir to ty more. E.g. previously infer types in where bounds were errored together with the function signature, but now they are independent. --- compiler/rustc_hir/src/hir.rs | 28 ++ .../rustc_hir_analysis/src/check/wfcheck.rs | 1 - compiler/rustc_hir_analysis/src/collect.rs | 249 +++------- compiler/rustc_middle/src/ty/util.rs | 1 + tests/ui/async-await/issues/issue-95307.rs | 5 +- .../ui/async-await/issues/issue-95307.stderr | 28 +- .../generic_arg_infer/in-signature.rs | 2 + .../generic_arg_infer/in-signature.stderr | 28 +- .../bad-assoc-ty.edition2015.stderr | 86 +--- .../bad-assoc-ty.edition2021.stderr | 86 +--- tests/ui/did_you_mean/bad-assoc-ty.rs | 1 + tests/ui/fn/error-recovery-mismatch.stderr | 6 - ...verlapping-errors-span-issue-123861.stderr | 6 - .../in-trait/not-inferred-generic.stderr | 2 +- tests/ui/macros/issue-118048.rs | 1 + tests/ui/macros/issue-118048.stderr | 20 +- tests/ui/macros/macro-span-issue-116502.rs | 2 + .../ui/macros/macro-span-issue-116502.stderr | 35 +- tests/ui/self/self-infer.stderr | 12 - .../bad-infer-in-trait-impl.stderr | 6 - tests/ui/typeck/issue-74086.rs | 3 +- tests/ui/typeck/issue-74086.stderr | 8 +- tests/ui/typeck/issue-81885.rs | 6 +- tests/ui/typeck/issue-81885.stderr | 16 +- .../ui/typeck/type-placeholder-fn-in-const.rs | 6 +- .../type-placeholder-fn-in-const.stderr | 16 +- .../ui/typeck/typeck_type_placeholder_item.rs | 16 +- .../typeck_type_placeholder_item.stderr | 428 +++++++----------- .../typeck_type_placeholder_item_help.rs | 3 +- .../typeck_type_placeholder_item_help.stderr | 16 +- 30 files changed, 414 insertions(+), 709 deletions(-) diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 88e0ee1cc0be2..75dff588669ab 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -3141,6 +3141,15 @@ pub enum TraitItemKind<'hir> { /// type. Type(GenericBounds<'hir>, Option<&'hir Ty<'hir>>), } +impl TraitItemKind<'_> { + pub fn descr(&self) -> &'static str { + match self { + TraitItemKind::Const(..) => "associated constant", + TraitItemKind::Fn(..) => "function", + TraitItemKind::Type(..) => "associated type", + } + } +} // The bodies for items are stored "out of line", in a separate // hashmap in the `Crate`. Here we just record the hir-id of the item @@ -3202,6 +3211,15 @@ pub enum ImplItemKind<'hir> { /// An associated type. Type(&'hir Ty<'hir>), } +impl ImplItemKind<'_> { + pub fn descr(&self) -> &'static str { + match self { + ImplItemKind::Const(..) => "associated constant", + ImplItemKind::Fn(..) => "function", + ImplItemKind::Type(..) => "associated type", + } + } +} /// A constraint on an associated item. /// @@ -4527,6 +4545,16 @@ pub enum ForeignItemKind<'hir> { Type, } +impl ForeignItemKind<'_> { + pub fn descr(&self) -> &'static str { + match self { + ForeignItemKind::Fn(..) => "function", + ForeignItemKind::Static(..) => "static variable", + ForeignItemKind::Type => "type", + } + } +} + /// A variable captured by a closure. #[derive(Debug, Copy, Clone, HashStable_Generic)] pub struct Upvar { diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 00f9347b1cc81..89ce74879d8eb 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -231,7 +231,6 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<() item.name = ? tcx.def_path_str(def_id) ); crate::collect::lower_item(tcx, item.item_id()); - crate::collect::reject_placeholder_type_signatures_in_item(tcx, item); let res = match item.kind { // Right now we check that every default trait implementation diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index c967e87bfd87c..d7568554669e9 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -29,7 +29,7 @@ use rustc_errors::{ }; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; -use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt, walk_generics}; +use rustc_hir::intravisit::{InferKind, Visitor, VisitorExt}; use rustc_hir::{self as hir, GenericParamKind, HirId, Node, PreciseCapturingArgKind}; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_infer::traits::{DynCompatibilityViolation, ObligationCause}; @@ -154,26 +154,7 @@ impl<'v> Visitor<'v> for HirPlaceholderCollector { } } -/// If there are any placeholder types (`_`), emit an error explaining that this is not allowed -/// and suggest adding type parameters in the appropriate place, taking into consideration any and -/// all already existing generic type parameters to avoid suggesting a name that is already in use. -pub(crate) fn placeholder_type_error<'tcx>( - cx: &dyn HirTyLowerer<'tcx>, - generics: Option<&hir::Generics<'_>>, - placeholder_types: Vec, - suggest: bool, - hir_ty: Option<&hir::Ty<'_>>, - kind: &'static str, -) { - if placeholder_types.is_empty() { - return; - } - - placeholder_type_error_diag(cx, generics, placeholder_types, vec![], suggest, hir_ty, kind) - .emit(); -} - -pub(crate) fn placeholder_type_error_diag<'cx, 'tcx>( +fn placeholder_type_error_diag<'cx, 'tcx>( cx: &'cx dyn HirTyLowerer<'tcx>, generics: Option<&hir::Generics<'_>>, placeholder_types: Vec, @@ -245,37 +226,6 @@ pub(crate) fn placeholder_type_error_diag<'cx, 'tcx>( err } -pub(super) fn reject_placeholder_type_signatures_in_item<'tcx>( - tcx: TyCtxt<'tcx>, - item: &'tcx hir::Item<'tcx>, -) { - let (generics, suggest) = match &item.kind { - hir::ItemKind::Union(_, generics, _) - | hir::ItemKind::Enum(_, generics, _) - | hir::ItemKind::TraitAlias(_, generics, _) - | hir::ItemKind::Trait(_, _, _, generics, ..) - | hir::ItemKind::Impl(hir::Impl { generics, .. }) - | hir::ItemKind::Struct(_, generics, _) => (generics, true), - hir::ItemKind::TyAlias(_, generics, _) => (generics, false), - // `static`, `fn` and `const` are handled elsewhere to suggest appropriate type. - _ => return, - }; - - let mut visitor = HirPlaceholderCollector::default(); - visitor.visit_item(item); - - let icx = ItemCtxt::new(tcx, item.owner_id.def_id); - - placeholder_type_error( - icx.lowerer(), - Some(generics), - visitor.spans, - suggest && !visitor.may_contain_const_infer, - None, - item.kind.descr(), - ); -} - /////////////////////////////////////////////////////////////////////////// // Utility types and common code for the above passes. @@ -313,6 +263,54 @@ impl<'tcx> ItemCtxt<'tcx> { None => Ok(()), } } + + fn report_placeholder_type_error( + &self, + placeholder_types: Vec, + infer_replacements: Vec<(Span, String)>, + ) -> ErrorGuaranteed { + let node = self.tcx.hir_node_by_def_id(self.item_def_id); + let generics = node.generics(); + let kind_id = match node { + Node::GenericParam(_) | Node::WherePredicate(_) | Node::Field(_) => { + self.tcx.local_parent(self.item_def_id) + } + _ => self.item_def_id, + }; + // FIXME: just invoke `tcx.def_descr` instead of going through the HIR + // Can also remove most `descr` methods then. + let kind = match self.tcx.hir_node_by_def_id(kind_id) { + Node::Item(it) => it.kind.descr(), + Node::ImplItem(it) => it.kind.descr(), + Node::TraitItem(it) => it.kind.descr(), + Node::ForeignItem(it) => it.kind.descr(), + Node::OpaqueTy(_) => "opaque type", + Node::Synthetic => self.tcx.def_descr(kind_id.into()), + node => todo!("{node:#?}"), + }; + let mut diag = placeholder_type_error_diag( + self, + generics, + placeholder_types, + infer_replacements.iter().map(|&(span, _)| span).collect(), + false, + None, + kind, + ); + if !infer_replacements.is_empty() { + diag.multipart_suggestion( + format!( + "try replacing `_` with the type{} in the corresponding trait method \ + signature", + rustc_errors::pluralize!(infer_replacements.len()), + ), + infer_replacements, + Applicability::MachineApplicable, + ); + } + + diag.emit() + } } impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> { @@ -346,10 +344,14 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> { } fn ty_infer(&self, _: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx> { + if !self.tcx.dcx().has_stashed_diagnostic(span, StashKey::ItemNoType) { + self.report_placeholder_type_error(vec![span], vec![]); + } Ty::new_error_with_message(self.tcx(), span, "bad placeholder type") } fn ct_infer(&self, _: Option<&ty::GenericParamDef>, span: Span) -> Const<'tcx> { + self.report_placeholder_type_error(vec![span], vec![]); ty::Const::new_error_with_message(self.tcx(), span, "bad placeholder constant") } @@ -524,18 +526,13 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> { fn lower_fn_sig( &self, decl: &hir::FnDecl<'tcx>, - generics: Option<&hir::Generics<'_>>, + _generics: Option<&hir::Generics<'_>>, hir_id: rustc_hir::HirId, - hir_ty: Option<&hir::Ty<'_>>, + _hir_ty: Option<&hir::Ty<'_>>, ) -> (Vec>, Ty<'tcx>) { let tcx = self.tcx(); - // We proactively collect all the inferred type params to emit a single error per fn def. - let mut visitor = HirPlaceholderCollector::default(); - let mut infer_replacements = vec![]; - if let Some(generics) = generics { - walk_generics(&mut visitor, generics); - } + let mut infer_replacements = vec![]; let input_tys = decl .inputs @@ -551,8 +548,6 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> { } } - // Only visit the type looking for `_` if we didn't fix the type above - visitor.visit_ty_unambig(a); self.lowerer().lower_ty(a) }) .collect(); @@ -566,42 +561,15 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> { infer_replacements.push((output.span, suggested_ty.to_string())); Ty::new_error_with_message(tcx, output.span, suggested_ty.to_string()) } else { - visitor.visit_ty_unambig(output); self.lower_ty(output) } } hir::FnRetTy::DefaultReturn(..) => tcx.types.unit, }; - if !(visitor.spans.is_empty() && infer_replacements.is_empty()) { - // We check for the presence of - // `ident_span` to not emit an error twice when we have `fn foo(_: fn() -> _)`. - - let mut diag = crate::collect::placeholder_type_error_diag( - self, - generics, - visitor.spans, - infer_replacements.iter().map(|(s, _)| *s).collect(), - !visitor.may_contain_const_infer, - hir_ty, - "function", - ); - - if !infer_replacements.is_empty() { - diag.multipart_suggestion( - format!( - "try replacing `_` with the type{} in the corresponding trait method \ - signature", - rustc_errors::pluralize!(infer_replacements.len()), - ), - infer_replacements, - Applicability::MachineApplicable, - ); - } - - diag.emit(); + if !infer_replacements.is_empty() { + self.report_placeholder_type_error(vec![], infer_replacements); } - (input_tys, output_ty) } @@ -652,7 +620,6 @@ pub(super) fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { let it = tcx.hir_item(item_id); debug!(item = ?it.kind.ident(), id = %it.hir_id()); let def_id = item_id.owner_id.def_id; - let icx = ItemCtxt::new(tcx, def_id); match &it.kind { // These don't define types. @@ -678,16 +645,6 @@ pub(super) fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { } hir::ForeignItemKind::Static(..) => { tcx.ensure_ok().codegen_fn_attrs(item.owner_id); - let mut visitor = HirPlaceholderCollector::default(); - visitor.visit_foreign_item(item); - placeholder_type_error( - icx.lowerer(), - None, - visitor.spans, - false, - None, - "static variable", - ); } _ => (), } @@ -741,22 +698,10 @@ pub(super) fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { tcx.ensure_ok().predicates_of(def_id); } - hir::ItemKind::Static(_, _, ty, _) | hir::ItemKind::Const(_, _, ty, _) => { + hir::ItemKind::Static(..) | hir::ItemKind::Const(..) => { tcx.ensure_ok().generics_of(def_id); tcx.ensure_ok().type_of(def_id); tcx.ensure_ok().predicates_of(def_id); - if !ty.is_suggestable_infer_ty() { - let mut visitor = HirPlaceholderCollector::default(); - visitor.visit_item(it); - placeholder_type_error( - icx.lowerer(), - None, - visitor.spans, - false, - None, - it.kind.descr(), - ); - } } hir::ItemKind::Fn { .. } => { @@ -773,7 +718,6 @@ pub(crate) fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) let trait_item = tcx.hir_trait_item(trait_item_id); let def_id = trait_item_id.owner_id; tcx.ensure_ok().generics_of(def_id); - let icx = ItemCtxt::new(tcx, def_id.def_id); match trait_item.kind { hir::TraitItemKind::Fn(..) => { @@ -782,58 +726,19 @@ pub(crate) fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) tcx.ensure_ok().fn_sig(def_id); } - hir::TraitItemKind::Const(ty, body_id) => { + hir::TraitItemKind::Const(..) => { tcx.ensure_ok().type_of(def_id); - if !tcx.dcx().has_stashed_diagnostic(ty.span, StashKey::ItemNoType) - && !(ty.is_suggestable_infer_ty() && body_id.is_some()) - { - // Account for `const C: _;`. - let mut visitor = HirPlaceholderCollector::default(); - visitor.visit_trait_item(trait_item); - placeholder_type_error( - icx.lowerer(), - None, - visitor.spans, - false, - None, - "associated constant", - ); - } } hir::TraitItemKind::Type(_, Some(_)) => { tcx.ensure_ok().item_bounds(def_id); tcx.ensure_ok().item_self_bounds(def_id); tcx.ensure_ok().type_of(def_id); - // Account for `type T = _;`. - let mut visitor = HirPlaceholderCollector::default(); - visitor.visit_trait_item(trait_item); - placeholder_type_error( - icx.lowerer(), - None, - visitor.spans, - false, - None, - "associated type", - ); } hir::TraitItemKind::Type(_, None) => { tcx.ensure_ok().item_bounds(def_id); tcx.ensure_ok().item_self_bounds(def_id); - // #74612: Visit and try to find bad placeholders - // even if there is no concrete type. - let mut visitor = HirPlaceholderCollector::default(); - visitor.visit_trait_item(trait_item); - - placeholder_type_error( - icx.lowerer(), - None, - visitor.spans, - false, - None, - "associated type", - ); } }; @@ -846,41 +751,13 @@ pub(super) fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) { tcx.ensure_ok().type_of(def_id); tcx.ensure_ok().predicates_of(def_id); let impl_item = tcx.hir_impl_item(impl_item_id); - let icx = ItemCtxt::new(tcx, def_id.def_id); match impl_item.kind { hir::ImplItemKind::Fn(..) => { tcx.ensure_ok().codegen_fn_attrs(def_id); tcx.ensure_ok().fn_sig(def_id); } - hir::ImplItemKind::Type(_) => { - // Account for `type T = _;` - let mut visitor = HirPlaceholderCollector::default(); - visitor.visit_impl_item(impl_item); - - placeholder_type_error( - icx.lowerer(), - None, - visitor.spans, - false, - None, - "associated type", - ); - } - hir::ImplItemKind::Const(ty, _) => { - // Account for `const T: _ = ..;` - if !ty.is_suggestable_infer_ty() { - let mut visitor = HirPlaceholderCollector::default(); - visitor.visit_impl_item(impl_item); - placeholder_type_error( - icx.lowerer(), - None, - visitor.spans, - false, - None, - "associated constant", - ); - } - } + hir::ImplItemKind::Type(_) => {} + hir::ImplItemKind::Const(..) => {} } } diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 51f57e71ce9b8..69b8be3d9cbc3 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -768,6 +768,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn def_kind_descr(self, def_kind: DefKind, def_id: DefId) -> &'static str { match def_kind { DefKind::AssocFn if self.associated_item(def_id).is_method() => "method", + DefKind::AssocTy if self.opt_rpitit_info(def_id).is_some() => "opaque type", DefKind::Closure if let Some(coroutine_kind) = self.coroutine_kind(def_id) => { match coroutine_kind { hir::CoroutineKind::Desugared( diff --git a/tests/ui/async-await/issues/issue-95307.rs b/tests/ui/async-await/issues/issue-95307.rs index 83df65612b486..40905c239c348 100644 --- a/tests/ui/async-await/issues/issue-95307.rs +++ b/tests/ui/async-await/issues/issue-95307.rs @@ -5,7 +5,10 @@ pub trait C { async fn new() -> [u8; _]; - //~^ ERROR: the placeholder `_` is not allowed within types on item signatures for functions + //~^ ERROR: the placeholder `_` is not allowed within types on item signatures for opaque types + //~| ERROR: the placeholder `_` is not allowed within types on item signatures for opaque types + //~| ERROR: the placeholder `_` is not allowed within types on item signatures for opaque types + //~| ERROR: the placeholder `_` is not allowed within types on item signatures for opaque types } fn main() {} diff --git a/tests/ui/async-await/issues/issue-95307.stderr b/tests/ui/async-await/issues/issue-95307.stderr index c670686f7c9d5..0aae7a215cda0 100644 --- a/tests/ui/async-await/issues/issue-95307.stderr +++ b/tests/ui/async-await/issues/issue-95307.stderr @@ -1,9 +1,33 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions +error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types --> $DIR/issue-95307.rs:7:28 | LL | async fn new() -> [u8; _]; | ^ not allowed in type signatures -error: aborting due to 1 previous error +error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types + --> $DIR/issue-95307.rs:7:28 + | +LL | async fn new() -> [u8; _]; + | ^ not allowed in type signatures + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types + --> $DIR/issue-95307.rs:7:28 + | +LL | async fn new() -> [u8; _]; + | ^ not allowed in type signatures + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types + --> $DIR/issue-95307.rs:7:28 + | +LL | async fn new() -> [u8; _]; + | ^ not allowed in type signatures + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/const-generics/generic_arg_infer/in-signature.rs b/tests/ui/const-generics/generic_arg_infer/in-signature.rs index cd0235bf45aa8..1be8b564224e2 100644 --- a/tests/ui/const-generics/generic_arg_infer/in-signature.rs +++ b/tests/ui/const-generics/generic_arg_infer/in-signature.rs @@ -41,6 +41,7 @@ trait TyAssocConst { trait TyAssocConstMixed { const ARR: Bar<_, _>; //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated constants + //~| ERROR the placeholder `_` is not allowed within types on item signatures for associated constants } trait AssocTy { @@ -57,4 +58,5 @@ impl AssocTy for i16 { impl AssocTy for i32 { type Assoc = Bar<_, _>; //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated types + //~| ERROR the placeholder `_` is not allowed within types on item signatures for associated types } diff --git a/tests/ui/const-generics/generic_arg_infer/in-signature.stderr b/tests/ui/const-generics/generic_arg_infer/in-signature.stderr index f964fc8d2f2c5..b6f2662a93932 100644 --- a/tests/ui/const-generics/generic_arg_infer/in-signature.stderr +++ b/tests/ui/const-generics/generic_arg_infer/in-signature.stderr @@ -103,24 +103,28 @@ LL + static TY_STATIC_MIXED: Bar = Bar::(0); | error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/in-signature.rs:50:23 + --> $DIR/in-signature.rs:51:23 | LL | type Assoc = [u8; _]; | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/in-signature.rs:54:27 + --> $DIR/in-signature.rs:55:27 | LL | type Assoc = Bar; | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/in-signature.rs:58:22 + --> $DIR/in-signature.rs:59:22 | LL | type Assoc = Bar<_, _>; - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types + --> $DIR/in-signature.rs:59:25 + | +LL | type Assoc = Bar<_, _>; + | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants --> $DIR/in-signature.rs:34:21 @@ -138,10 +142,14 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures --> $DIR/in-signature.rs:42:20 | LL | const ARR: Bar<_, _>; - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants + --> $DIR/in-signature.rs:42:23 + | +LL | const ARR: Bar<_, _>; + | ^ not allowed in type signatures -error: aborting due to 15 previous errors +error: aborting due to 17 previous errors For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/did_you_mean/bad-assoc-ty.edition2015.stderr b/tests/ui/did_you_mean/bad-assoc-ty.edition2015.stderr index 0835f766a824d..fe1ce5ad18b14 100644 --- a/tests/ui/did_you_mean/bad-assoc-ty.edition2015.stderr +++ b/tests/ui/did_you_mean/bad-assoc-ty.edition2015.stderr @@ -240,96 +240,52 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures --> $DIR/bad-assoc-ty.rs:56:13 | LL | fn foo>(x: X) {} - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures + | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/bad-assoc-ty.rs:59:34 + --> $DIR/bad-assoc-ty.rs:56:16 + | +LL | fn foo>(x: X) {} + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/bad-assoc-ty.rs:60:34 | LL | fn bar(_: F) where F: Fn() -> _ {} | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn bar(_: F) where F: Fn() -> _ {} -LL + fn bar(_: F) where F: Fn() -> T {} - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/bad-assoc-ty.rs:62:19 + --> $DIR/bad-assoc-ty.rs:63:19 | LL | fn baz _>(_: F) {} | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn baz _>(_: F) {} -LL + fn baz T, T>(_: F) {} - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/bad-assoc-ty.rs:65:33 + --> $DIR/bad-assoc-ty.rs:66:33 | LL | struct L(F) where F: Fn() -> _; | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - struct L(F) where F: Fn() -> _; -LL + struct L(F) where F: Fn() -> T; - | - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/bad-assoc-ty.rs:87:38 - | -LL | fn foo(_: F) where F: Fn() -> _ {} - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn foo(_: F) where F: Fn() -> _ {} -LL + fn foo(_: F) where F: Fn() -> T {} - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/bad-assoc-ty.rs:67:30 + --> $DIR/bad-assoc-ty.rs:68:30 | LL | struct M where F: Fn() -> _ { | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - struct M where F: Fn() -> _ { -LL + struct M where F: Fn() -> T { - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for enums - --> $DIR/bad-assoc-ty.rs:71:28 + --> $DIR/bad-assoc-ty.rs:72:28 | LL | enum N where F: Fn() -> _ { | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - enum N where F: Fn() -> _ { -LL + enum N where F: Fn() -> T { - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for unions - --> $DIR/bad-assoc-ty.rs:76:29 + --> $DIR/bad-assoc-ty.rs:77:29 | LL | union O where F: Fn() -> _ { | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - union O where F: Fn() -> _ { -LL + union O where F: Fn() -> T { - | error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union - --> $DIR/bad-assoc-ty.rs:78:5 + --> $DIR/bad-assoc-ty.rs:79:5 | LL | foo: F, | ^^^^^^ @@ -341,18 +297,18 @@ LL | foo: std::mem::ManuallyDrop, | +++++++++++++++++++++++ + error[E0121]: the placeholder `_` is not allowed within types on item signatures for traits - --> $DIR/bad-assoc-ty.rs:82:29 + --> $DIR/bad-assoc-ty.rs:83:29 | LL | trait P where F: Fn() -> _ { | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/bad-assoc-ty.rs:88:38 | -help: use type parameters instead - | -LL - trait P where F: Fn() -> _ { -LL + trait P where F: Fn() -> T { - | +LL | fn foo(_: F) where F: Fn() -> _ {} + | ^ not allowed in type signatures -error: aborting due to 29 previous errors; 1 warning emitted +error: aborting due to 30 previous errors; 1 warning emitted Some errors have detailed explanations: E0121, E0223, E0740. For more information about an error, try `rustc --explain E0121`. diff --git a/tests/ui/did_you_mean/bad-assoc-ty.edition2021.stderr b/tests/ui/did_you_mean/bad-assoc-ty.edition2021.stderr index 3cc403f9ac429..2cf7a150aa277 100644 --- a/tests/ui/did_you_mean/bad-assoc-ty.edition2021.stderr +++ b/tests/ui/did_you_mean/bad-assoc-ty.edition2021.stderr @@ -222,96 +222,52 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures --> $DIR/bad-assoc-ty.rs:56:13 | LL | fn foo>(x: X) {} - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures + | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/bad-assoc-ty.rs:59:34 + --> $DIR/bad-assoc-ty.rs:56:16 + | +LL | fn foo>(x: X) {} + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/bad-assoc-ty.rs:60:34 | LL | fn bar(_: F) where F: Fn() -> _ {} | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn bar(_: F) where F: Fn() -> _ {} -LL + fn bar(_: F) where F: Fn() -> T {} - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/bad-assoc-ty.rs:62:19 + --> $DIR/bad-assoc-ty.rs:63:19 | LL | fn baz _>(_: F) {} | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn baz _>(_: F) {} -LL + fn baz T, T>(_: F) {} - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/bad-assoc-ty.rs:65:33 + --> $DIR/bad-assoc-ty.rs:66:33 | LL | struct L(F) where F: Fn() -> _; | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - struct L(F) where F: Fn() -> _; -LL + struct L(F) where F: Fn() -> T; - | - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/bad-assoc-ty.rs:87:38 - | -LL | fn foo(_: F) where F: Fn() -> _ {} - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn foo(_: F) where F: Fn() -> _ {} -LL + fn foo(_: F) where F: Fn() -> T {} - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/bad-assoc-ty.rs:67:30 + --> $DIR/bad-assoc-ty.rs:68:30 | LL | struct M where F: Fn() -> _ { | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - struct M where F: Fn() -> _ { -LL + struct M where F: Fn() -> T { - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for enums - --> $DIR/bad-assoc-ty.rs:71:28 + --> $DIR/bad-assoc-ty.rs:72:28 | LL | enum N where F: Fn() -> _ { | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - enum N where F: Fn() -> _ { -LL + enum N where F: Fn() -> T { - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for unions - --> $DIR/bad-assoc-ty.rs:76:29 + --> $DIR/bad-assoc-ty.rs:77:29 | LL | union O where F: Fn() -> _ { | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - union O where F: Fn() -> _ { -LL + union O where F: Fn() -> T { - | error[E0740]: field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union - --> $DIR/bad-assoc-ty.rs:78:5 + --> $DIR/bad-assoc-ty.rs:79:5 | LL | foo: F, | ^^^^^^ @@ -323,18 +279,18 @@ LL | foo: std::mem::ManuallyDrop, | +++++++++++++++++++++++ + error[E0121]: the placeholder `_` is not allowed within types on item signatures for traits - --> $DIR/bad-assoc-ty.rs:82:29 + --> $DIR/bad-assoc-ty.rs:83:29 | LL | trait P where F: Fn() -> _ { | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/bad-assoc-ty.rs:88:38 | -help: use type parameters instead - | -LL - trait P where F: Fn() -> _ { -LL + trait P where F: Fn() -> T { - | +LL | fn foo(_: F) where F: Fn() -> _ {} + | ^ not allowed in type signatures -error: aborting due to 29 previous errors +error: aborting due to 30 previous errors Some errors have detailed explanations: E0121, E0223, E0740, E0782. For more information about an error, try `rustc --explain E0121`. diff --git a/tests/ui/did_you_mean/bad-assoc-ty.rs b/tests/ui/did_you_mean/bad-assoc-ty.rs index 6e56cba24e1ba..9abda4fd962b4 100644 --- a/tests/ui/did_you_mean/bad-assoc-ty.rs +++ b/tests/ui/did_you_mean/bad-assoc-ty.rs @@ -55,6 +55,7 @@ type I = ty!()::AssocTy; trait K {} fn foo>(x: X) {} //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions +//~| ERROR the placeholder `_` is not allowed within types on item signatures for functions fn bar(_: F) where F: Fn() -> _ {} //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions diff --git a/tests/ui/fn/error-recovery-mismatch.stderr b/tests/ui/fn/error-recovery-mismatch.stderr index f281e77f13b9b..c046302cb91cf 100644 --- a/tests/ui/fn/error-recovery-mismatch.stderr +++ b/tests/ui/fn/error-recovery-mismatch.stderr @@ -34,12 +34,6 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures | LL | fn fold(&self, _: T, &self._) {} | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn fold(&self, _: T, &self._) {} -LL + fn fold(&self, _: T, &self.U) {} - | error: aborting due to 4 previous errors; 1 warning emitted diff --git a/tests/ui/generics/overlapping-errors-span-issue-123861.stderr b/tests/ui/generics/overlapping-errors-span-issue-123861.stderr index 9622dffda9f84..7d08d8fed9f92 100644 --- a/tests/ui/generics/overlapping-errors-span-issue-123861.stderr +++ b/tests/ui/generics/overlapping-errors-span-issue-123861.stderr @@ -30,12 +30,6 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures | LL | fn mainIterator<_ = _> {} | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn mainIterator<_ = _> {} -LL + fn mainIterator {} - | error: aborting due to 4 previous errors diff --git a/tests/ui/impl-trait/in-trait/not-inferred-generic.stderr b/tests/ui/impl-trait/in-trait/not-inferred-generic.stderr index 07f029d3bb7dc..c08fc511500c5 100644 --- a/tests/ui/impl-trait/in-trait/not-inferred-generic.stderr +++ b/tests/ui/impl-trait/in-trait/not-inferred-generic.stderr @@ -5,7 +5,7 @@ LL | ().publish_typed(); | ^^^^^^^^^^^^^ cannot infer type of the type parameter `F` declared on the method `publish_typed` | = note: cannot satisfy `_: Clone` - = note: associated types cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl` + = note: opaque types cannot be accessed directly on a `trait`, they can only be accessed through a specific `impl` note: required by a bound in `TypedClient::publish_typed::{anon_assoc#0}` --> $DIR/not-inferred-generic.rs:4:12 | diff --git a/tests/ui/macros/issue-118048.rs b/tests/ui/macros/issue-118048.rs index 15a834fa2df48..3b3ab3b4fc936 100644 --- a/tests/ui/macros/issue-118048.rs +++ b/tests/ui/macros/issue-118048.rs @@ -6,5 +6,6 @@ macro_rules! foo { foo!(_); //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions +//~| ERROR the placeholder `_` is not allowed within types on item signatures for functions fn main() {} diff --git a/tests/ui/macros/issue-118048.stderr b/tests/ui/macros/issue-118048.stderr index 4dc5ef71fec69..f5468b341bce6 100644 --- a/tests/ui/macros/issue-118048.stderr +++ b/tests/ui/macros/issue-118048.stderr @@ -2,20 +2,16 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures --> $DIR/issue-118048.rs:7:6 | LL | foo!(_); - | ^ - | | - | not allowed in type signatures - | not allowed in type signatures - | -help: use type parameters instead + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/issue-118048.rs:7:6 | -LL ~ fn foo(_: $ty, _: $ty) {} -LL | } -LL | } -LL | -LL ~ foo!(T); +LL | foo!(_); + | ^ not allowed in type signatures | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: aborting due to 1 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/macros/macro-span-issue-116502.rs b/tests/ui/macros/macro-span-issue-116502.rs index 4c254289ee684..b5ae383efca03 100644 --- a/tests/ui/macros/macro-span-issue-116502.rs +++ b/tests/ui/macros/macro-span-issue-116502.rs @@ -5,6 +5,8 @@ fn bug() { macro_rules! m { () => { _ //~ ERROR the placeholder `_` is not allowed within types on item signatures for structs + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for structs + //~| ERROR the placeholder `_` is not allowed within types on item signatures for structs }; } struct S(m!(), T) diff --git a/tests/ui/macros/macro-span-issue-116502.stderr b/tests/ui/macros/macro-span-issue-116502.stderr index 2a581f7031b95..68f8874f5d628 100644 --- a/tests/ui/macros/macro-span-issue-116502.stderr +++ b/tests/ui/macros/macro-span-issue-116502.stderr @@ -2,22 +2,35 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures --> $DIR/macro-span-issue-116502.rs:7:13 | LL | _ - | ^ - | | - | not allowed in type signatures - | not allowed in type signatures - | not allowed in type signatures + | ^ not allowed in type signatures ... -LL | struct S(m!(), T) - | ---- ---- in this macro invocation - | | - | in this macro invocation -LL | where LL | T: Trait; | ---- in this macro invocation | = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 1 previous error +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/macro-span-issue-116502.rs:7:13 + | +LL | _ + | ^ not allowed in type signatures +... +LL | struct S(m!(), T) + | ---- in this macro invocation + | + = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/macro-span-issue-116502.rs:7:13 + | +LL | _ + | ^ not allowed in type signatures +... +LL | struct S(m!(), T) + | ---- in this macro invocation + | + = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/self/self-infer.stderr b/tests/ui/self/self-infer.stderr index c6bdff22b6970..f9db559390f51 100644 --- a/tests/ui/self/self-infer.stderr +++ b/tests/ui/self/self-infer.stderr @@ -3,24 +3,12 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures | LL | fn f(self: _) {} | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn f(self: _) {} -LL + fn f(self: T) {} - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions --> $DIR/self-infer.rs:5:17 | LL | fn g(self: &_) {} | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn g(self: &_) {} -LL + fn g(self: &T) {} - | error: aborting due to 2 previous errors diff --git a/tests/ui/suggestions/bad-infer-in-trait-impl.stderr b/tests/ui/suggestions/bad-infer-in-trait-impl.stderr index 68d8f5402e44c..8b7d67ac0412b 100644 --- a/tests/ui/suggestions/bad-infer-in-trait-impl.stderr +++ b/tests/ui/suggestions/bad-infer-in-trait-impl.stderr @@ -3,12 +3,6 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures | LL | fn bar(s: _) {} | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn bar(s: _) {} -LL + fn bar(s: T) {} - | error[E0050]: method `bar` has 1 parameter but the declaration in trait `Foo::bar` has 0 --> $DIR/bad-infer-in-trait-impl.rs:6:15 diff --git a/tests/ui/typeck/issue-74086.rs b/tests/ui/typeck/issue-74086.rs index 9b7c0d7cc6e2e..1993cc7db350e 100644 --- a/tests/ui/typeck/issue-74086.rs +++ b/tests/ui/typeck/issue-74086.rs @@ -1,5 +1,4 @@ fn main() { static BUG: fn(_) -> u8 = |_| 8; - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions [E0121] - //~| ERROR the placeholder `_` is not allowed within types on item signatures for static items + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for static items } diff --git a/tests/ui/typeck/issue-74086.stderr b/tests/ui/typeck/issue-74086.stderr index 95ebf9a906c14..25f454ac0c320 100644 --- a/tests/ui/typeck/issue-74086.stderr +++ b/tests/ui/typeck/issue-74086.stderr @@ -1,15 +1,9 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/issue-74086.rs:2:20 - | -LL | static BUG: fn(_) -> u8 = |_| 8; - | ^ not allowed in type signatures - error[E0121]: the placeholder `_` is not allowed within types on item signatures for static items --> $DIR/issue-74086.rs:2:20 | LL | static BUG: fn(_) -> u8 = |_| 8; | ^ not allowed in type signatures -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/typeck/issue-81885.rs b/tests/ui/typeck/issue-81885.rs index fb3949478a4d3..d73c77b8f3a27 100644 --- a/tests/ui/typeck/issue-81885.rs +++ b/tests/ui/typeck/issue-81885.rs @@ -1,9 +1,7 @@ const TEST4: fn() -> _ = 42; - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions - //~| ERROR the placeholder `_` is not allowed within types on item signatures for constant items +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constant items fn main() { const TEST5: fn() -> _ = 42; - //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions - //~| ERROR the placeholder `_` is not allowed within types on item signatures for constant items + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constant items } diff --git a/tests/ui/typeck/issue-81885.stderr b/tests/ui/typeck/issue-81885.stderr index 91c08bd823502..25a6bb632ef14 100644 --- a/tests/ui/typeck/issue-81885.stderr +++ b/tests/ui/typeck/issue-81885.stderr @@ -1,27 +1,15 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/issue-81885.rs:1:22 - | -LL | const TEST4: fn() -> _ = 42; - | ^ not allowed in type signatures - error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items --> $DIR/issue-81885.rs:1:22 | LL | const TEST4: fn() -> _ = 42; | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/issue-81885.rs:6:26 - | -LL | const TEST5: fn() -> _ = 42; - | ^ not allowed in type signatures - error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items - --> $DIR/issue-81885.rs:6:26 + --> $DIR/issue-81885.rs:5:26 | LL | const TEST5: fn() -> _ = 42; | ^ not allowed in type signatures -error: aborting due to 4 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/typeck/type-placeholder-fn-in-const.rs b/tests/ui/typeck/type-placeholder-fn-in-const.rs index bbb95a5798af5..1600534dd4f8f 100644 --- a/tests/ui/typeck/type-placeholder-fn-in-const.rs +++ b/tests/ui/typeck/type-placeholder-fn-in-const.rs @@ -2,14 +2,12 @@ struct MyStruct; trait Test { const TEST: fn() -> _; - //~^ ERROR: the placeholder `_` is not allowed within types on item signatures for functions [E0121] - //~| ERROR: the placeholder `_` is not allowed within types on item signatures for associated constants [E0121] + //~^ ERROR: the placeholder `_` is not allowed within types on item signatures for associated constants [E0121] } impl Test for MyStruct { const TEST: fn() -> _ = 42; - //~^ ERROR: the placeholder `_` is not allowed within types on item signatures for functions [E0121] - //~| ERROR: the placeholder `_` is not allowed within types on item signatures for associated constants [E0121] + //~^ ERROR: the placeholder `_` is not allowed within types on item signatures for associated constants [E0121] } fn main() {} diff --git a/tests/ui/typeck/type-placeholder-fn-in-const.stderr b/tests/ui/typeck/type-placeholder-fn-in-const.stderr index 92b47bd4781c5..a29752948fe35 100644 --- a/tests/ui/typeck/type-placeholder-fn-in-const.stderr +++ b/tests/ui/typeck/type-placeholder-fn-in-const.stderr @@ -1,17 +1,5 @@ -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/type-placeholder-fn-in-const.rs:10:25 - | -LL | const TEST: fn() -> _ = 42; - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/type-placeholder-fn-in-const.rs:4:25 - | -LL | const TEST: fn() -> _; - | ^ not allowed in type signatures - error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/type-placeholder-fn-in-const.rs:10:25 + --> $DIR/type-placeholder-fn-in-const.rs:9:25 | LL | const TEST: fn() -> _ = 42; | ^ not allowed in type signatures @@ -22,6 +10,6 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures LL | const TEST: fn() -> _; | ^ not allowed in type signatures -error: aborting due to 4 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0121`. diff --git a/tests/ui/typeck/typeck_type_placeholder_item.rs b/tests/ui/typeck/typeck_type_placeholder_item.rs index d7351f2e51a8d..dc7903619193a 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item.rs +++ b/tests/ui/typeck/typeck_type_placeholder_item.rs @@ -33,7 +33,6 @@ fn test7(x: _) { let _x: usize = x; } fn test8(_f: fn() -> _) { } //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions -//~^^ ERROR the placeholder `_` is not allowed within types on item signatures for functions struct Test9; @@ -67,6 +66,8 @@ struct Test10 { a: _, //~^ ERROR the placeholder `_` is not allowed within types on item signatures for structs b: (_, _), + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for structs + //~| ERROR the placeholder `_` is not allowed within types on item signatures for structs } pub fn main() { @@ -99,7 +100,6 @@ pub fn main() { fn fn_test8(_f: fn() -> _) { } //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions - //~^^ ERROR the placeholder `_` is not allowed within types on item signatures for functions struct FnTest9; @@ -123,6 +123,8 @@ pub fn main() { a: _, //~^ ERROR the placeholder `_` is not allowed within types on item signatures for structs b: (_, _), + //~^ ERROR the placeholder `_` is not allowed within types on item signatures for structs + //~| ERROR the placeholder `_` is not allowed within types on item signatures for structs } fn fn_test11(_: _) -> (_, _) { panic!() } @@ -141,12 +143,14 @@ trait T { //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions fn method_test2(&self, x: _) -> _; //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~| ERROR the placeholder `_` is not allowed within types on item signatures for functions fn method_test3(&self) -> _; //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions fn assoc_fn_test1(x: _); //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions fn assoc_fn_test2(x: _) -> _; //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions + //~| ERROR the placeholder `_` is not allowed within types on item signatures for functions fn assoc_fn_test3() -> _; //~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions } @@ -158,9 +162,11 @@ trait BadTrait<_> {} //~^ ERROR expected identifier, found reserved identifier `_` impl BadTrait<_> for BadStruct<_> {} //~^ ERROR the placeholder `_` is not allowed within types on item signatures for implementations +//~| ERROR the placeholder `_` is not allowed within types on item signatures for implementations fn impl_trait() -> impl BadTrait<_> { -//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for opaque types +//~| ERROR the placeholder `_` is not allowed within types on item signatures for opaque types unimplemented!() } @@ -180,7 +186,8 @@ struct Struct; trait Trait {} impl Trait for Struct {} type Y = impl Trait<_>; -//~^ ERROR the placeholder `_` is not allowed within types on item signatures for type aliases +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for opaque types +//~| ERROR the placeholder `_` is not allowed within types on item signatures for opaque types #[define_opaque(Y)] fn foo() -> Y { Struct @@ -197,6 +204,7 @@ trait Qux { // type E: _; // FIXME: make the parser propagate the existence of `B` type F: std::ops::Fn(_); //~^ ERROR the placeholder `_` is not allowed within types on item signatures for associated types + //~| ERROR the placeholder `_` is not allowed within types on item signatures for associated types } impl Qux for Struct { //~^ ERROR not all trait items implemented, missing: `F` diff --git a/tests/ui/typeck/typeck_type_placeholder_item.stderr b/tests/ui/typeck/typeck_type_placeholder_item.stderr index 7184244f5dc9d..53476f6c80749 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_item.stderr @@ -1,35 +1,35 @@ error: expected identifier, found reserved identifier `_` - --> $DIR/typeck_type_placeholder_item.rs:154:18 + --> $DIR/typeck_type_placeholder_item.rs:158:18 | LL | struct BadStruct<_>(_); | ^ expected identifier, found reserved identifier error: expected identifier, found reserved identifier `_` - --> $DIR/typeck_type_placeholder_item.rs:157:16 + --> $DIR/typeck_type_placeholder_item.rs:161:16 | LL | trait BadTrait<_> {} | ^ expected identifier, found reserved identifier error: expected identifier, found reserved identifier `_` - --> $DIR/typeck_type_placeholder_item.rs:167:19 + --> $DIR/typeck_type_placeholder_item.rs:173:19 | LL | struct BadStruct1<_, _>(_); | ^ expected identifier, found reserved identifier error: expected identifier, found reserved identifier `_` - --> $DIR/typeck_type_placeholder_item.rs:167:22 + --> $DIR/typeck_type_placeholder_item.rs:173:22 | LL | struct BadStruct1<_, _>(_); | ^ expected identifier, found reserved identifier error: expected identifier, found reserved identifier `_` - --> $DIR/typeck_type_placeholder_item.rs:172:19 + --> $DIR/typeck_type_placeholder_item.rs:178:19 | LL | struct BadStruct2<_, T>(_, T); | ^ expected identifier, found reserved identifier error: associated constant in `impl` without body - --> $DIR/typeck_type_placeholder_item.rs:207:5 + --> $DIR/typeck_type_placeholder_item.rs:215:5 | LL | const C: _; | ^^^^^^^^^^- @@ -37,7 +37,7 @@ LL | const C: _; | help: provide a definition for the constant: `= ;` error[E0403]: the name `_` is already used for a generic parameter in this item's generic parameters - --> $DIR/typeck_type_placeholder_item.rs:167:22 + --> $DIR/typeck_type_placeholder_item.rs:173:22 | LL | struct BadStruct1<_, _>(_); | - ^ already used @@ -106,72 +106,87 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures | LL | fn test6(_: _) { } | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn test6(_: _) { } -LL + fn test6(_: T) { } - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions --> $DIR/typeck_type_placeholder_item.rs:25:18 | LL | fn test6_b(_: _, _: T) { } | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn test6_b(_: _, _: T) { } -LL + fn test6_b(_: U, _: T) { } - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions --> $DIR/typeck_type_placeholder_item.rs:28:30 | LL | fn test6_c(_: _, _: (T, K, L, A, B)) { } | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn test6_c(_: _, _: (T, K, L, A, B)) { } -LL + fn test6_c(_: U, _: (T, K, L, A, B)) { } - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions --> $DIR/typeck_type_placeholder_item.rs:31:13 | LL | fn test7(x: _) { let _x: usize = x; } | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn test7(x: _) { let _x: usize = x; } -LL + fn test7(x: T) { let _x: usize = x; } - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions --> $DIR/typeck_type_placeholder_item.rs:34:22 | LL | fn test8(_f: fn() -> _) { } - | ^ - | | - | not allowed in type signatures - | help: use type parameters instead: `T` + | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:34:22 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:66:8 | -LL | fn test8(_f: fn() -> _) { } - | ^ not allowed in type signatures +LL | a: _, + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:68:9 | -help: use type parameters instead +LL | b: (_, _), + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:68:12 + | +LL | b: (_, _), + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:123:12 + | +LL | a: _, + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:125:13 + | +LL | b: (_, _), + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:125:16 + | +LL | b: (_, _), + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:158:21 + | +LL | struct BadStruct<_>(_); + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:173:25 | -LL - fn test8(_f: fn() -> _) { } -LL + fn test8(_f: fn() -> T) { } +LL | struct BadStruct1<_, _>(_); + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs + --> $DIR/typeck_type_placeholder_item.rs:178:25 | +LL | struct BadStruct2<_, T>(_, T); + | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:48:26 + --> $DIR/typeck_type_placeholder_item.rs:47:26 | LL | fn test11(x: &usize) -> &_ { | -^ @@ -180,7 +195,7 @@ LL | fn test11(x: &usize) -> &_ { | help: replace with the correct return type: `&&usize` error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:53:52 + --> $DIR/typeck_type_placeholder_item.rs:52:52 | LL | unsafe fn test12(x: *const usize) -> *const *const _ { | --------------^ @@ -189,7 +204,7 @@ LL | unsafe fn test12(x: *const usize) -> *const *const _ { | help: replace with the correct return type: `*const *const usize` error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:59:24 + --> $DIR/typeck_type_placeholder_item.rs:58:24 | LL | fn clone(&self) -> _ { Test9 } | ^ not allowed in type signatures @@ -201,7 +216,7 @@ LL + fn clone(&self) -> Test9 { Test9 } | error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:62:37 + --> $DIR/typeck_type_placeholder_item.rs:61:37 | LL | fn clone_from(&mut self, other: _) { *self = Test9; } | ^ not allowed in type signatures @@ -212,33 +227,14 @@ LL - fn clone_from(&mut self, other: _) { *self = Test9; } LL + fn clone_from(&mut self, other: &Test9) { *self = Test9; } | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:67:8 - | -LL | a: _, - | ^ not allowed in type signatures -LL | -LL | b: (_, _), - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures - | -help: use type parameters instead - | -LL ~ struct Test10 { -LL ~ a: T, -LL | -LL ~ b: (T, T), - | - error: missing type for `static` item - --> $DIR/typeck_type_placeholder_item.rs:73:13 + --> $DIR/typeck_type_placeholder_item.rs:74:13 | LL | static A = 42; | ^ help: provide a type for the static variable: `: i32` error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:75:15 + --> $DIR/typeck_type_placeholder_item.rs:76:15 | LL | static B: _ = 42; | ^ not allowed in type signatures @@ -250,7 +246,7 @@ LL + static B: i32 = 42; | error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:77:22 + --> $DIR/typeck_type_placeholder_item.rs:78:22 | LL | static C: Option<_> = Some(42); | ^ not allowed in type signatures @@ -262,7 +258,7 @@ LL + static C: Option = Some(42); | error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:79:21 + --> $DIR/typeck_type_placeholder_item.rs:80:21 | LL | fn fn_test() -> _ { 5 } | ^ @@ -271,7 +267,7 @@ LL | fn fn_test() -> _ { 5 } | help: replace with the correct return type: `i32` error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:82:23 + --> $DIR/typeck_type_placeholder_item.rs:83:23 | LL | fn fn_test2() -> (_, _) { (5, 5) } | -^--^- @@ -281,7 +277,7 @@ LL | fn fn_test2() -> (_, _) { (5, 5) } | help: replace with the correct return type: `(i32, i32)` error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:85:22 + --> $DIR/typeck_type_placeholder_item.rs:86:22 | LL | static FN_TEST3: _ = "test"; | ^ not allowed in type signatures @@ -293,7 +289,7 @@ LL + static FN_TEST3: &str = "test"; | error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:88:22 + --> $DIR/typeck_type_placeholder_item.rs:89:22 | LL | static FN_TEST4: _ = 145; | ^ not allowed in type signatures @@ -305,7 +301,7 @@ LL + static FN_TEST4: i32 = 145; | error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:91:23 + --> $DIR/typeck_type_placeholder_item.rs:92:23 | LL | static FN_TEST5: (_, _) = (1, 2); | ^ ^ not allowed in type signatures @@ -319,49 +315,22 @@ LL + static FN_TEST5: (i32, i32) = (1, 2); | error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:94:20 + --> $DIR/typeck_type_placeholder_item.rs:95:20 | LL | fn fn_test6(_: _) { } | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn fn_test6(_: _) { } -LL + fn fn_test6(_: T) { } - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:97:20 + --> $DIR/typeck_type_placeholder_item.rs:98:20 | LL | fn fn_test7(x: _) { let _x: usize = x; } | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn fn_test7(x: _) { let _x: usize = x; } -LL + fn fn_test7(x: T) { let _x: usize = x; } - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:100:29 - | -LL | fn fn_test8(_f: fn() -> _) { } - | ^ - | | - | not allowed in type signatures - | help: use type parameters instead: `T` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:100:29 + --> $DIR/typeck_type_placeholder_item.rs:101:29 | LL | fn fn_test8(_f: fn() -> _) { } | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn fn_test8(_f: fn() -> _) { } -LL + fn fn_test8(_f: fn() -> T) { } - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions --> $DIR/typeck_type_placeholder_item.rs:115:28 @@ -387,33 +356,14 @@ LL - fn clone_from(&mut self, other: _) { *self = FnTest9; } LL + fn clone_from(&mut self, other: &FnTest9) { *self = FnTest9; } | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:123:12 - | -LL | a: _, - | ^ not allowed in type signatures -LL | -LL | b: (_, _), - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures - | -help: use type parameters instead - | -LL ~ struct FnTest10 { -LL ~ a: T, -LL | -LL ~ b: (T, T), - | - error[E0282]: type annotations needed - --> $DIR/typeck_type_placeholder_item.rs:128:21 + --> $DIR/typeck_type_placeholder_item.rs:130:21 | LL | fn fn_test11(_: _) -> (_, _) { panic!() } | ^ cannot infer type error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:128:28 + --> $DIR/typeck_type_placeholder_item.rs:130:28 | LL | fn fn_test11(_: _) -> (_, _) { panic!() } | ^ ^ not allowed in type signatures @@ -421,7 +371,7 @@ LL | fn fn_test11(_: _) -> (_, _) { panic!() } | not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:132:30 + --> $DIR/typeck_type_placeholder_item.rs:134:30 | LL | fn fn_test12(x: i32) -> (_, _) { (x, x) } | -^--^- @@ -431,7 +381,7 @@ LL | fn fn_test12(x: i32) -> (_, _) { (x, x) } | help: replace with the correct return type: `(i32, i32)` error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:135:33 + --> $DIR/typeck_type_placeholder_item.rs:137:33 | LL | fn fn_test13(x: _) -> (i32, _) { (x, x) } | ------^- @@ -439,152 +389,116 @@ LL | fn fn_test13(x: _) -> (i32, _) { (x, x) } | | not allowed in type signatures | help: replace with the correct return type: `(i32, i32)` -error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:154:21 - | -LL | struct BadStruct<_>(_); - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - struct BadStruct<_>(_); -LL + struct BadStruct(T); - | - error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:140:31 + --> $DIR/typeck_type_placeholder_item.rs:142:31 | LL | fn method_test1(&self, x: _); | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn method_test1(&self, x: _); -LL + fn method_test1(&self, x: T); - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:142:31 + --> $DIR/typeck_type_placeholder_item.rs:144:31 | LL | fn method_test2(&self, x: _) -> _; - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures - | -help: use type parameters instead - | -LL - fn method_test2(&self, x: _) -> _; -LL + fn method_test2(&self, x: T) -> T; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:144:37 | +LL | fn method_test2(&self, x: _) -> _; + | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:144:31 + --> $DIR/typeck_type_placeholder_item.rs:147:31 | LL | fn method_test3(&self) -> _; | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn method_test3(&self) -> _; -LL + fn method_test3(&self) -> T; - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:146:26 + --> $DIR/typeck_type_placeholder_item.rs:149:26 | LL | fn assoc_fn_test1(x: _); | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn assoc_fn_test1(x: _); -LL + fn assoc_fn_test1(x: T); - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:148:26 + --> $DIR/typeck_type_placeholder_item.rs:151:26 | LL | fn assoc_fn_test2(x: _) -> _; - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures - | -help: use type parameters instead - | -LL - fn assoc_fn_test2(x: _) -> _; -LL + fn assoc_fn_test2(x: T) -> T; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions + --> $DIR/typeck_type_placeholder_item.rs:151:32 | +LL | fn assoc_fn_test2(x: _) -> _; + | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:150:28 + --> $DIR/typeck_type_placeholder_item.rs:154:28 | LL | fn assoc_fn_test3() -> _; | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for implementations + --> $DIR/typeck_type_placeholder_item.rs:163:32 | -help: use type parameters instead - | -LL - fn assoc_fn_test3() -> _; -LL + fn assoc_fn_test3() -> T; - | +LL | impl BadTrait<_> for BadStruct<_> {} + | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for implementations - --> $DIR/typeck_type_placeholder_item.rs:159:15 + --> $DIR/typeck_type_placeholder_item.rs:163:15 | LL | impl BadTrait<_> for BadStruct<_> {} - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures + | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:162:34 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types + --> $DIR/typeck_type_placeholder_item.rs:167:34 | LL | fn impl_trait() -> impl BadTrait<_> { | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:167:25 - | -LL | struct BadStruct1<_, _>(_); - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - struct BadStruct1<_, _>(_); -LL + struct BadStruct1(T); +error[E0121]: the placeholder `_` is not allowed within types on item signatures for type aliases + --> $DIR/typeck_type_placeholder_item.rs:182:14 | +LL | type X = Box<_>; + | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:172:25 - | -LL | struct BadStruct2<_, T>(_, T); - | ^ not allowed in type signatures +error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types + --> $DIR/typeck_type_placeholder_item.rs:188:21 | -help: use type parameters instead +LL | type Y = impl Trait<_>; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types + --> $DIR/typeck_type_placeholder_item.rs:198:14 | -LL - struct BadStruct2<_, T>(_, T); -LL + struct BadStruct2(U, T); +LL | type B = _; + | ^ not allowed in type signatures + +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types + --> $DIR/typeck_type_placeholder_item.rs:211:14 | +LL | type A = _; + | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for type aliases - --> $DIR/typeck_type_placeholder_item.rs:176:14 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types + --> $DIR/typeck_type_placeholder_item.rs:213:14 | -LL | type X = Box<_>; +LL | type B = _; | ^ not allowed in type signatures -error[E0121]: the placeholder `_` is not allowed within types on item signatures for type aliases - --> $DIR/typeck_type_placeholder_item.rs:182:21 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants + --> $DIR/typeck_type_placeholder_item.rs:200:14 | -LL | type Y = impl Trait<_>; - | ^ not allowed in type signatures +LL | const C: _; + | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/typeck_type_placeholder_item.rs:207:14 + --> $DIR/typeck_type_placeholder_item.rs:215:14 | LL | const C: _; | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/typeck_type_placeholder_item.rs:195:14 + --> $DIR/typeck_type_placeholder_item.rs:202:14 | LL | const D: _ = 42; | ^ not allowed in type signatures @@ -596,13 +510,13 @@ LL + const D: i32 = 42; | error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/typeck_type_placeholder_item.rs:210:14 + --> $DIR/typeck_type_placeholder_item.rs:218:14 | LL | const D: _ = 42; | ^ not allowed in type signatures error[E0046]: not all trait items implemented, missing: `F` - --> $DIR/typeck_type_placeholder_item.rs:201:1 + --> $DIR/typeck_type_placeholder_item.rs:209:1 | LL | type F: std::ops::Fn(_); | ----------------------- `F` from trait @@ -611,7 +525,7 @@ LL | impl Qux for Struct { | ^^^^^^^^^^^^^^^^^^^ missing `F` in implementation error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:218:31 + --> $DIR/typeck_type_placeholder_item.rs:226:31 | LL | fn value() -> Option<&'static _> { | ----------------^- @@ -620,7 +534,7 @@ LL | fn value() -> Option<&'static _> { | help: replace with the correct return type: `Option<&'static u8>` error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants - --> $DIR/typeck_type_placeholder_item.rs:223:17 + --> $DIR/typeck_type_placeholder_item.rs:231:17 | LL | const _: Option<_> = map(value); | ^ not allowed in type signatures @@ -632,7 +546,7 @@ LL + const _: Option = map(value); | error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:227:31 + --> $DIR/typeck_type_placeholder_item.rs:235:31 | LL | fn evens_squared(n: usize) -> _ { | ^ @@ -641,19 +555,19 @@ LL | fn evens_squared(n: usize) -> _ { | help: replace with an appropriate return type: `impl Iterator` error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants - --> $DIR/typeck_type_placeholder_item.rs:232:10 + --> $DIR/typeck_type_placeholder_item.rs:240:10 | LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); | ^ not allowed in type signatures | -note: however, the inferred type `Map, {closure@typeck_type_placeholder_item.rs:232:29}>, {closure@typeck_type_placeholder_item.rs:232:49}>` cannot be named - --> $DIR/typeck_type_placeholder_item.rs:232:14 +note: however, the inferred type `Map, {closure@typeck_type_placeholder_item.rs:240:29}>, {closure@typeck_type_placeholder_item.rs:240:49}>` cannot be named + --> $DIR/typeck_type_placeholder_item.rs:240:14 | LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:41:24 + --> $DIR/typeck_type_placeholder_item.rs:40:24 | LL | fn test9(&self) -> _ { () } | ^ @@ -662,16 +576,10 @@ LL | fn test9(&self) -> _ { () } | help: replace with the correct return type: `()` error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:44:27 + --> $DIR/typeck_type_placeholder_item.rs:43:27 | LL | fn test10(&self, _x : _) { } | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn test10(&self, _x : _) { } -LL + fn test10(&self, _x : T) { } - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types --> $DIR/typeck_type_placeholder_item.rs:107:31 @@ -687,68 +595,62 @@ error[E0121]: the placeholder `_` is not allowed within types on item signatures | LL | fn fn_test10(&self, _x : _) { } | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL - fn fn_test10(&self, _x : _) { } -LL + fn fn_test10(&self, _x : T) { } - | error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/typeck_type_placeholder_item.rs:203:14 + --> $DIR/typeck_type_placeholder_item.rs:205:26 | -LL | type A = _; - | ^ not allowed in type signatures +LL | type F: std::ops::Fn(_); + | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/typeck_type_placeholder_item.rs:205:14 + --> $DIR/typeck_type_placeholder_item.rs:205:26 | -LL | type B = _; - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/typeck_type_placeholder_item.rs:191:14 +LL | type F: std::ops::Fn(_); + | ^ not allowed in type signatures | -LL | type B = _; - | ^ not allowed in type signatures + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/typeck_type_placeholder_item.rs:193:14 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types + --> $DIR/typeck_type_placeholder_item.rs:167:34 | -LL | const C: _; - | ^ not allowed in type signatures +LL | fn impl_trait() -> impl BadTrait<_> { + | ^ not allowed in type signatures + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/typeck_type_placeholder_item.rs:198:26 +error[E0121]: the placeholder `_` is not allowed within types on item signatures for opaque types + --> $DIR/typeck_type_placeholder_item.rs:188:21 | -LL | type F: std::ops::Fn(_); - | ^ not allowed in type signatures +LL | type Y = impl Trait<_>; + | ^ not allowed in type signatures + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0015]: cannot call non-const function `map::` in constants - --> $DIR/typeck_type_placeholder_item.rs:223:22 + --> $DIR/typeck_type_placeholder_item.rs:231:22 | LL | const _: Option<_> = map(value); | ^^^^^^^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants -error[E0015]: cannot call non-const method ` as Iterator>::filter::<{closure@$DIR/typeck_type_placeholder_item.rs:232:29: 232:32}>` in constants - --> $DIR/typeck_type_placeholder_item.rs:232:22 +error[E0015]: cannot call non-const method ` as Iterator>::filter::<{closure@$DIR/typeck_type_placeholder_item.rs:240:29: 240:32}>` in constants + --> $DIR/typeck_type_placeholder_item.rs:240:22 | LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); | ^^^^^^^^^^^^^^^^^^^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants -error[E0015]: cannot call non-const method `, {closure@$DIR/typeck_type_placeholder_item.rs:232:29: 232:32}> as Iterator>::map::` in constants - --> $DIR/typeck_type_placeholder_item.rs:232:45 +error[E0015]: cannot call non-const method `, {closure@$DIR/typeck_type_placeholder_item.rs:240:29: 240:32}> as Iterator>::map::` in constants + --> $DIR/typeck_type_placeholder_item.rs:240:45 | LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); | ^^^^^^^^^^^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants -error: aborting due to 75 previous errors +error: aborting due to 83 previous errors Some errors have detailed explanations: E0015, E0046, E0121, E0282, E0403. For more information about an error, try `rustc --explain E0015`. diff --git a/tests/ui/typeck/typeck_type_placeholder_item_help.rs b/tests/ui/typeck/typeck_type_placeholder_item_help.rs index ff6182588c720..ab433aaaf1620 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item_help.rs +++ b/tests/ui/typeck/typeck_type_placeholder_item_help.rs @@ -11,8 +11,7 @@ const TEST3: _ = Some(42); //~^ ERROR the placeholder `_` is not allowed within types on item signatures for constants const TEST4: fn() -> _ = 42; -//~^ ERROR the placeholder `_` is not allowed within types on item signatures for functions -//~| ERROR the placeholder `_` is not allowed within types on item signatures for constant items +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for constant items trait Test5 { const TEST5: _ = 42; diff --git a/tests/ui/typeck/typeck_type_placeholder_item_help.stderr b/tests/ui/typeck/typeck_type_placeholder_item_help.stderr index afdd58e0a0384..5066e2eaa523b 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item_help.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_item_help.stderr @@ -31,12 +31,6 @@ LL - const TEST3: _ = Some(42); LL + const TEST3: Option = Some(42); | -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item_help.rs:13:22 - | -LL | const TEST4: fn() -> _ = 42; - | ^ not allowed in type signatures - error[E0121]: the placeholder `_` is not allowed within types on item signatures for constant items --> $DIR/typeck_type_placeholder_item_help.rs:13:22 | @@ -44,7 +38,7 @@ LL | const TEST4: fn() -> _ = 42; | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/typeck_type_placeholder_item_help.rs:25:18 + --> $DIR/typeck_type_placeholder_item_help.rs:24:18 | LL | const TEST6: _ = 13; | ^ not allowed in type signatures @@ -56,7 +50,7 @@ LL + const TEST6: i32 = 13; | error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/typeck_type_placeholder_item_help.rs:18:18 + --> $DIR/typeck_type_placeholder_item_help.rs:17:18 | LL | const TEST5: _ = 42; | ^ not allowed in type signatures @@ -68,7 +62,7 @@ LL + const TEST5: i32 = 42; | error[E0308]: mismatched types - --> $DIR/typeck_type_placeholder_item_help.rs:30:28 + --> $DIR/typeck_type_placeholder_item_help.rs:29:28 | LL | let _: Option = test1(); | ------------- ^^^^^^^ expected `Option`, found `Option` @@ -79,7 +73,7 @@ LL | let _: Option = test1(); found enum `Option` error[E0308]: mismatched types - --> $DIR/typeck_type_placeholder_item_help.rs:31:18 + --> $DIR/typeck_type_placeholder_item_help.rs:30:18 | LL | let _: f64 = test1(); | --- ^^^^^^^ expected `f64`, found `Option` @@ -89,7 +83,7 @@ LL | let _: f64 = test1(); = note: expected type `f64` found enum `Option` -error: aborting due to 9 previous errors +error: aborting due to 8 previous errors Some errors have detailed explanations: E0121, E0308. For more information about an error, try `rustc --explain E0121`.