diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index e8cbd7b69fbe0..59e3976f0d12c 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2993,7 +2993,7 @@ pub enum ItemKind { Union(VariantData, Generics), /// A trait declaration (`trait`). /// - /// E.g., `trait Foo { .. }`, `trait Foo { .. }` or `auto trait Foo {}`. + /// E.g., `trait Foo { .. }`, `trait Foo { .. }`. Trait(Box), /// Trait alias /// diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index edc1e2f0b84d9..6936aad850ee7 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -149,7 +149,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> { hir::ItemKind::Impl(impl_) => { lctx.is_in_trait_impl = impl_.of_trait.is_some(); } - hir::ItemKind::Trait(_, _, generics, _, _) if lctx.tcx.features().effects => { + hir::ItemKind::Trait(_, generics, _, _) if lctx.tcx.features().effects => { lctx.host_param_id = generics .params .iter() @@ -443,7 +443,8 @@ impl<'hir> LoweringContext<'_, 'hir> { items: new_impl_items, })) } - ItemKind::Trait(box Trait { is_auto, unsafety, generics, bounds, items }) => { + // We intentionally ignore `is_auto` since `auto` is now meaningless. + ItemKind::Trait(box Trait { is_auto: _, unsafety, generics, bounds, items }) => { // FIXME(const_trait_impl, effects, fee1-dead) this should be simplified if possible let constness = attrs .unwrap_or(&[]) @@ -467,7 +468,7 @@ impl<'hir> LoweringContext<'_, 'hir> { (unsafety, items, bounds) }, ); - hir::ItemKind::Trait(*is_auto, unsafety, generics, bounds, items) + hir::ItemKind::Trait(unsafety, generics, bounds, items) } ItemKind::TraitAlias(generics, bounds) => { let (generics, bounds) = self.lower_generics( diff --git a/compiler/rustc_ast_passes/messages.ftl b/compiler/rustc_ast_passes/messages.ftl index 43020a930788f..f7b1e1ed9484c 100644 --- a/compiler/rustc_ast_passes/messages.ftl +++ b/compiler/rustc_ast_passes/messages.ftl @@ -184,8 +184,8 @@ ast_passes_nested_lifetimes = nested quantification of lifetimes ast_passes_nomangle_ascii = `#[no_mangle]` requires ASCII identifier -ast_passes_obsolete_auto = `impl Trait for .. {"{}"}` is an obsolete syntax - .help = use `auto trait Trait {"{}"}` instead +ast_passes_obsolete_auto_syntax = `{$syntax}` is an obsolete syntax for auto traits + .help = use `#[rustc_auto_trait] trait Trait {"{}"}` instead ast_passes_optional_const_exclusive = `~const` and `{$modifier}` are mutually exclusive diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index 743fad8e86502..a9b07a5bb6dc4 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -810,7 +810,10 @@ impl<'a> Visitor<'a> for AstValidator<'a> { errors::VisibilityNotPermittedNote::TraitImpl, ); if let TyKind::Err = self_ty.kind { - this.err_handler().emit_err(errors::ObsoleteAuto { span: item.span }); + this.err_handler().emit_err(errors::ObsoleteAutoSyntax { + span: item.span, + syntax: "impl Trait for .. {}", + }); } if let (&Unsafe::Yes(span), &ImplPolarity::Negative(sp)) = (unsafety, polarity) { @@ -941,10 +944,11 @@ impl<'a> Visitor<'a> for AstValidator<'a> { } } } - ItemKind::Trait(box Trait { is_auto, generics, bounds, items, .. }) => { + // We intentionally ignore `is_auto` since `auto` is now meaningless. + ItemKind::Trait(box Trait { is_auto: _, generics, bounds, items, .. }) => { let is_const_trait = attr::contains_name(&item.attrs, sym::const_trait); self.with_in_trait(is_const_trait, |this| { - if *is_auto == IsAuto::Yes { + if attr::contains_name(&item.attrs, sym::rustc_auto_trait) { // Auto traits cannot have generics, super traits nor contain items. this.deny_generic_params(generics, item.ident.span); this.deny_super_traits(bounds, item.ident.span); diff --git a/compiler/rustc_ast_passes/src/errors.rs b/compiler/rustc_ast_passes/src/errors.rs index e74d94e43474d..9bb1d887fcc18 100644 --- a/compiler/rustc_ast_passes/src/errors.rs +++ b/compiler/rustc_ast_passes/src/errors.rs @@ -417,11 +417,12 @@ pub struct OutOfOrderParams<'a> { } #[derive(Diagnostic)] -#[diag(ast_passes_obsolete_auto)] +#[diag(ast_passes_obsolete_auto_syntax)] #[help] -pub struct ObsoleteAuto { +pub struct ObsoleteAutoSyntax { #[primary_span] pub span: Span, + pub syntax: &'static str, } #[derive(Diagnostic)] diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 62dc7ae58a2f0..3edb7a8189163 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -298,12 +298,11 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { } ast::ItemKind::Trait(box ast::Trait { is_auto: ast::IsAuto::Yes, .. }) => { - gate_feature_post!( - &self, - auto_traits, - i.span, - "auto traits are experimental and possibly buggy" - ); + // FIXME: Consider using a structured suggestion. + self.sess.emit_err(errors::ObsoleteAutoSyntax { + span: i.span, + syntax: "auto trait Trait {}", + }); } ast::ItemKind::TraitAlias(..) => { diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 8ca57383e82d2..5c9b8497fb99c 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -673,8 +673,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { true, td.as_local().and_then(|tld| match hir_map.find_by_def_id(tld) { Some(Node::Item(hir::Item { - kind: hir::ItemKind::Trait(_, _, _, _, items), - .. + kind: hir::ItemKind::Trait(_, _, _, items), .. })) => { let mut f_in_trait_opt = None; for hir::TraitItemRef { id: fi, kind: k, .. } in *items { diff --git a/compiler/rustc_codegen_cranelift/example/mini_core.rs b/compiler/rustc_codegen_cranelift/example/mini_core.rs index 34c7e44b2881c..c3d0e9d27363c 100644 --- a/compiler/rustc_codegen_cranelift/example/mini_core.rs +++ b/compiler/rustc_codegen_cranelift/example/mini_core.rs @@ -7,7 +7,6 @@ decl_macro, rustc_attrs, transparent_unions, - auto_traits, thread_local )] #![no_core] @@ -93,7 +92,8 @@ unsafe impl<'a, T: ?Sized> Sync for &'a T {} unsafe impl Sync for [u8; 16] {} #[lang = "freeze"] -unsafe auto trait Freeze {} +#[rustc_auto_trait] +unsafe trait Freeze {} unsafe impl Freeze for PhantomData {} unsafe impl Freeze for *const T {} @@ -503,7 +503,8 @@ pub unsafe fn drop_in_place(to_drop: *mut T) { } #[lang = "unpin"] -pub auto trait Unpin {} +#[rustc_auto_trait] +pub trait Unpin {} #[lang = "deref"] pub trait Deref { diff --git a/compiler/rustc_codegen_gcc/example/mini_core.rs b/compiler/rustc_codegen_gcc/example/mini_core.rs index 0cd7e6047c20a..1816b5d86824f 100644 --- a/compiler/rustc_codegen_gcc/example/mini_core.rs +++ b/compiler/rustc_codegen_gcc/example/mini_core.rs @@ -1,6 +1,6 @@ #![feature( no_core, lang_items, intrinsics, unboxed_closures, type_ascription, extern_types, - decl_macro, rustc_attrs, transparent_unions, auto_traits, + decl_macro, rustc_attrs, transparent_unions, thread_local )] #![no_core] @@ -89,7 +89,8 @@ unsafe impl<'a, T: ?Sized> Sync for &'a T {} unsafe impl Sync for [u8; 16] {} #[lang = "freeze"] -unsafe auto trait Freeze {} +#[rustc_auto_trait] +unsafe trait Freeze {} unsafe impl Freeze for PhantomData {} unsafe impl Freeze for *const T {} @@ -452,7 +453,8 @@ pub unsafe fn drop_in_place(to_drop: *mut T) { } #[lang = "unpin"] -pub auto trait Unpin {} +#[rustc_auto_trait] +pub trait Unpin {} #[lang = "deref"] pub trait Deref { diff --git a/compiler/rustc_codegen_gcc/tests/run/abort1.rs b/compiler/rustc_codegen_gcc/tests/run/abort1.rs index 25041d93e748a..7b21e8b690802 100644 --- a/compiler/rustc_codegen_gcc/tests/run/abort1.rs +++ b/compiler/rustc_codegen_gcc/tests/run/abort1.rs @@ -3,7 +3,7 @@ // Run-time: // status: signal -#![feature(auto_traits, lang_items, no_core, start, intrinsics)] +#![feature(rustc_attrs, lang_items, no_core, start, intrinsics)] #![no_std] #![no_core] @@ -27,7 +27,8 @@ trait Receiver { } #[lang = "freeze"] -pub(crate) unsafe auto trait Freeze {} +#[rustc_auto_trait] +pub(crate) unsafe trait Freeze {} mod intrinsics { use super::Sized; diff --git a/compiler/rustc_codegen_gcc/tests/run/abort2.rs b/compiler/rustc_codegen_gcc/tests/run/abort2.rs index e7443c8dbe5b2..533b00c1df3a4 100644 --- a/compiler/rustc_codegen_gcc/tests/run/abort2.rs +++ b/compiler/rustc_codegen_gcc/tests/run/abort2.rs @@ -3,7 +3,7 @@ // Run-time: // status: signal -#![feature(auto_traits, lang_items, no_core, start, intrinsics)] +#![feature(rustc_attrs, lang_items, no_core, start, intrinsics)] #![no_std] #![no_core] @@ -27,7 +27,8 @@ trait Receiver { } #[lang = "freeze"] -pub(crate) unsafe auto trait Freeze {} +#[rustc_auto_trait] +pub(crate) unsafe trait Freeze {} mod intrinsics { use super::Sized; diff --git a/compiler/rustc_codegen_gcc/tests/run/array.rs b/compiler/rustc_codegen_gcc/tests/run/array.rs index 49b28d98f2fec..da5137068c214 100644 --- a/compiler/rustc_codegen_gcc/tests/run/array.rs +++ b/compiler/rustc_codegen_gcc/tests/run/array.rs @@ -7,7 +7,7 @@ // 5 // 10 -#![feature(arbitrary_self_types, auto_traits, lang_items, no_core, start, intrinsics)] +#![feature(arbitrary_self_types, rustc_attrs, lang_items, no_core, start, intrinsics)] #![no_std] #![no_core] @@ -36,7 +36,8 @@ trait Receiver { } #[lang = "freeze"] -pub(crate) unsafe auto trait Freeze {} +#[rustc_auto_trait] +pub(crate) unsafe trait Freeze {} mod libc { #[link(name = "c")] diff --git a/compiler/rustc_codegen_gcc/tests/run/assign.rs b/compiler/rustc_codegen_gcc/tests/run/assign.rs index 427c1a2503397..1d3b620906cb3 100644 --- a/compiler/rustc_codegen_gcc/tests/run/assign.rs +++ b/compiler/rustc_codegen_gcc/tests/run/assign.rs @@ -6,7 +6,7 @@ // 10 #![allow(unused_attributes)] -#![feature(auto_traits, lang_items, no_core, start, intrinsics, track_caller)] +#![feature(rustc_attrs, lang_items, no_core, start, intrinsics, track_caller)] #![no_std] #![no_core] @@ -35,7 +35,8 @@ trait Receiver { } #[lang = "freeze"] -pub(crate) unsafe auto trait Freeze {} +#[rustc_auto_trait] +pub(crate) unsafe trait Freeze {} #[lang = "panic_location"] struct PanicLocation { diff --git a/compiler/rustc_codegen_gcc/tests/run/closure.rs b/compiler/rustc_codegen_gcc/tests/run/closure.rs index 8daa681abf7da..48e592e5d52d0 100644 --- a/compiler/rustc_codegen_gcc/tests/run/closure.rs +++ b/compiler/rustc_codegen_gcc/tests/run/closure.rs @@ -8,7 +8,7 @@ // Int argument: 2 // Both args: 11 -#![feature(arbitrary_self_types, auto_traits, lang_items, no_core, start, intrinsics, +#![feature(arbitrary_self_types, rustc_attrs, lang_items, no_core, start, intrinsics, unboxed_closures)] #![no_std] @@ -38,7 +38,8 @@ trait Receiver { } #[lang = "freeze"] -pub(crate) unsafe auto trait Freeze {} +#[rustc_auto_trait] +pub(crate) unsafe trait Freeze {} mod libc { #[link(name = "c")] diff --git a/compiler/rustc_codegen_gcc/tests/run/condition.rs b/compiler/rustc_codegen_gcc/tests/run/condition.rs index b7a13081deae0..50565110c289f 100644 --- a/compiler/rustc_codegen_gcc/tests/run/condition.rs +++ b/compiler/rustc_codegen_gcc/tests/run/condition.rs @@ -5,7 +5,7 @@ // stdout: true // 1 -#![feature(arbitrary_self_types, auto_traits, lang_items, no_core, start, intrinsics)] +#![feature(arbitrary_self_types, rustc_attrs, lang_items, no_core, start, intrinsics)] #![no_std] #![no_core] @@ -39,7 +39,8 @@ trait Receiver { } #[lang = "freeze"] -pub(crate) unsafe auto trait Freeze {} +#[rustc_auto_trait] +pub(crate) unsafe trait Freeze {} mod libc { #[link(name = "c")] diff --git a/compiler/rustc_codegen_gcc/tests/run/empty_main.rs b/compiler/rustc_codegen_gcc/tests/run/empty_main.rs index c02cfd2a85f03..ede6a4c0dd368 100644 --- a/compiler/rustc_codegen_gcc/tests/run/empty_main.rs +++ b/compiler/rustc_codegen_gcc/tests/run/empty_main.rs @@ -3,7 +3,7 @@ // Run-time: // status: 0 -#![feature(auto_traits, lang_items, no_core, start)] +#![feature(rustc_attrs, lang_items, no_core, start)] #![no_std] #![no_core] @@ -27,7 +27,8 @@ trait Receiver { } #[lang = "freeze"] -pub(crate) unsafe auto trait Freeze {} +#[rustc_auto_trait] +pub(crate) unsafe trait Freeze {} /* * Code diff --git a/compiler/rustc_codegen_gcc/tests/run/exit.rs b/compiler/rustc_codegen_gcc/tests/run/exit.rs index 956e53dd4aa65..73356b895e6e8 100644 --- a/compiler/rustc_codegen_gcc/tests/run/exit.rs +++ b/compiler/rustc_codegen_gcc/tests/run/exit.rs @@ -3,7 +3,7 @@ // Run-time: // status: 2 -#![feature(auto_traits, lang_items, no_core, start, intrinsics)] +#![feature(rustc_attrs, lang_items, no_core, start, intrinsics)] #![no_std] #![no_core] @@ -34,7 +34,8 @@ trait Receiver { } #[lang = "freeze"] -pub(crate) unsafe auto trait Freeze {} +#[rustc_auto_trait] +pub(crate) unsafe trait Freeze {} /* * Code diff --git a/compiler/rustc_codegen_gcc/tests/run/exit_code.rs b/compiler/rustc_codegen_gcc/tests/run/exit_code.rs index eeab352095123..51f1f8b55e2d5 100644 --- a/compiler/rustc_codegen_gcc/tests/run/exit_code.rs +++ b/compiler/rustc_codegen_gcc/tests/run/exit_code.rs @@ -3,7 +3,7 @@ // Run-time: // status: 1 -#![feature(auto_traits, lang_items, no_core, start)] +#![feature(rustc_attrs, lang_items, no_core, start)] #![no_std] #![no_core] @@ -27,7 +27,8 @@ trait Receiver { } #[lang = "freeze"] -pub(crate) unsafe auto trait Freeze {} +#[rustc_auto_trait] +pub(crate) unsafe trait Freeze {} /* * Code diff --git a/compiler/rustc_codegen_gcc/tests/run/fun_ptr.rs b/compiler/rustc_codegen_gcc/tests/run/fun_ptr.rs index 8a196f774c82b..4b5682772832c 100644 --- a/compiler/rustc_codegen_gcc/tests/run/fun_ptr.rs +++ b/compiler/rustc_codegen_gcc/tests/run/fun_ptr.rs @@ -4,7 +4,7 @@ // status: 0 // stdout: 1 -#![feature(arbitrary_self_types, auto_traits, lang_items, no_core, start, intrinsics)] +#![feature(arbitrary_self_types, rustc_attrs, lang_items, no_core, start, intrinsics)] #![no_std] #![no_core] @@ -33,7 +33,8 @@ trait Receiver { } #[lang = "freeze"] -pub(crate) unsafe auto trait Freeze {} +#[rustc_auto_trait] +pub(crate) unsafe trait Freeze {} mod libc { #[link(name = "c")] diff --git a/compiler/rustc_codegen_gcc/tests/run/int_overflow.rs b/compiler/rustc_codegen_gcc/tests/run/int_overflow.rs index c3fcb3c0a2a06..271fa1d2d2f07 100644 --- a/compiler/rustc_codegen_gcc/tests/run/int_overflow.rs +++ b/compiler/rustc_codegen_gcc/tests/run/int_overflow.rs @@ -5,7 +5,7 @@ // status: signal #![allow(unused_attributes)] -#![feature(auto_traits, lang_items, no_core, start, intrinsics)] +#![feature(rustc_attrs, lang_items, no_core, start, intrinsics)] #![no_std] #![no_core] @@ -34,7 +34,8 @@ trait Receiver { } #[lang = "freeze"] -pub(crate) unsafe auto trait Freeze {} +#[rustc_auto_trait] +pub(crate) unsafe trait Freeze {} #[lang = "panic_location"] struct PanicLocation { diff --git a/compiler/rustc_codegen_gcc/tests/run/mut_ref.rs b/compiler/rustc_codegen_gcc/tests/run/mut_ref.rs index 2a2ea8b8bf0ab..cd0a7ddf526ad 100644 --- a/compiler/rustc_codegen_gcc/tests/run/mut_ref.rs +++ b/compiler/rustc_codegen_gcc/tests/run/mut_ref.rs @@ -8,7 +8,7 @@ // 11 #![allow(unused_attributes)] -#![feature(auto_traits, lang_items, no_core, start, intrinsics, track_caller)] +#![feature(rustc_attrs, lang_items, no_core, start, intrinsics, track_caller)] #![no_std] #![no_core] @@ -37,7 +37,8 @@ trait Receiver { } #[lang = "freeze"] -pub(crate) unsafe auto trait Freeze {} +#[rustc_auto_trait] +pub(crate) unsafe trait Freeze {} #[lang = "panic_location"] struct PanicLocation { diff --git a/compiler/rustc_codegen_gcc/tests/run/operations.rs b/compiler/rustc_codegen_gcc/tests/run/operations.rs index 67b9f241dbbb3..da9355e39db5a 100644 --- a/compiler/rustc_codegen_gcc/tests/run/operations.rs +++ b/compiler/rustc_codegen_gcc/tests/run/operations.rs @@ -6,7 +6,7 @@ // 10 #![allow(unused_attributes)] -#![feature(auto_traits, lang_items, no_core, start, intrinsics, arbitrary_self_types)] +#![feature(rustc_attrs, lang_items, no_core, start, intrinsics, arbitrary_self_types)] #![no_std] #![no_core] @@ -43,7 +43,8 @@ trait Receiver { } #[lang = "freeze"] -pub(crate) unsafe auto trait Freeze {} +#[rustc_auto_trait] +pub(crate) unsafe trait Freeze {} #[lang = "panic_location"] struct PanicLocation { diff --git a/compiler/rustc_codegen_gcc/tests/run/ptr_cast.rs b/compiler/rustc_codegen_gcc/tests/run/ptr_cast.rs index da8a8295d564c..3391868f74382 100644 --- a/compiler/rustc_codegen_gcc/tests/run/ptr_cast.rs +++ b/compiler/rustc_codegen_gcc/tests/run/ptr_cast.rs @@ -4,7 +4,7 @@ // status: 0 // stdout: 1 -#![feature(arbitrary_self_types, auto_traits, lang_items, no_core, start, intrinsics)] +#![feature(arbitrary_self_types, rustc_attrs, lang_items, no_core, start, intrinsics)] #![no_std] #![no_core] @@ -33,7 +33,8 @@ trait Receiver { } #[lang = "freeze"] -pub(crate) unsafe auto trait Freeze {} +#[rustc_auto_trait] +pub(crate) unsafe trait Freeze {} mod libc { #[link(name = "c")] diff --git a/compiler/rustc_codegen_gcc/tests/run/return-tuple.rs b/compiler/rustc_codegen_gcc/tests/run/return-tuple.rs index 6fa10dca06f67..208226c74b7b3 100644 --- a/compiler/rustc_codegen_gcc/tests/run/return-tuple.rs +++ b/compiler/rustc_codegen_gcc/tests/run/return-tuple.rs @@ -6,7 +6,7 @@ // 10 // 42 -#![feature(auto_traits, lang_items, no_core, start, intrinsics)] +#![feature(rustc_attrs, lang_items, no_core, start, intrinsics)] #![no_std] #![no_core] @@ -47,7 +47,8 @@ trait Receiver { } #[lang = "freeze"] -pub(crate) unsafe auto trait Freeze {} +#[rustc_auto_trait] +pub(crate) unsafe trait Freeze {} /* * Code diff --git a/compiler/rustc_codegen_gcc/tests/run/slice.rs b/compiler/rustc_codegen_gcc/tests/run/slice.rs index 96f1c4792e58f..01c6055db9525 100644 --- a/compiler/rustc_codegen_gcc/tests/run/slice.rs +++ b/compiler/rustc_codegen_gcc/tests/run/slice.rs @@ -4,7 +4,7 @@ // status: 0 // stdout: 5 -#![feature(arbitrary_self_types, auto_traits, lang_items, no_core, start, intrinsics)] +#![feature(arbitrary_self_types, rustc_attrs, lang_items, no_core, start, intrinsics)] #![no_std] #![no_core] @@ -31,7 +31,8 @@ trait Receiver { } #[lang = "freeze"] -pub(crate) unsafe auto trait Freeze {} +#[rustc_auto_trait] +pub(crate) unsafe trait Freeze {} mod libc { #[link(name = "c")] diff --git a/compiler/rustc_codegen_gcc/tests/run/static.rs b/compiler/rustc_codegen_gcc/tests/run/static.rs index 19201f1df2667..ae1c956c8376b 100644 --- a/compiler/rustc_codegen_gcc/tests/run/static.rs +++ b/compiler/rustc_codegen_gcc/tests/run/static.rs @@ -9,7 +9,7 @@ // 12 // 1 -#![feature(auto_traits, lang_items, no_core, start, intrinsics)] +#![feature(rustc_attrs, lang_items, no_core, start, intrinsics)] #![no_std] #![no_core] @@ -39,7 +39,8 @@ trait Receiver { } #[lang = "freeze"] -pub(crate) unsafe auto trait Freeze {} +#[rustc_auto_trait] +pub(crate) unsafe trait Freeze {} mod intrinsics { use super::Sized; diff --git a/compiler/rustc_codegen_gcc/tests/run/structs.rs b/compiler/rustc_codegen_gcc/tests/run/structs.rs index 6c8884855ac35..076546731e936 100644 --- a/compiler/rustc_codegen_gcc/tests/run/structs.rs +++ b/compiler/rustc_codegen_gcc/tests/run/structs.rs @@ -5,7 +5,7 @@ // stdout: 1 // 2 -#![feature(auto_traits, lang_items, no_core, start, intrinsics)] +#![feature(rustc_attrs, lang_items, no_core, start, intrinsics)] #![no_std] #![no_core] @@ -29,7 +29,8 @@ trait Receiver { } #[lang = "freeze"] -pub(crate) unsafe auto trait Freeze {} +#[rustc_auto_trait] +pub(crate) unsafe trait Freeze {} mod libc { #[link(name = "c")] diff --git a/compiler/rustc_codegen_gcc/tests/run/tuple.rs b/compiler/rustc_codegen_gcc/tests/run/tuple.rs index 0b670bf267424..c210bb3ca8023 100644 --- a/compiler/rustc_codegen_gcc/tests/run/tuple.rs +++ b/compiler/rustc_codegen_gcc/tests/run/tuple.rs @@ -4,7 +4,7 @@ // status: 0 // stdout: 3 -#![feature(auto_traits, lang_items, no_core, start, intrinsics)] +#![feature(rustc_attrs, lang_items, no_core, start, intrinsics)] #![no_std] #![no_core] @@ -28,7 +28,8 @@ trait Receiver { } #[lang = "freeze"] -pub(crate) unsafe auto trait Freeze {} +#[rustc_auto_trait] +pub(crate) unsafe trait Freeze {} mod libc { #[link(name = "c")] diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index 461ec3a90ed97..84a28d3fbb4dc 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -9,7 +9,7 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![feature(array_windows)] #![feature(associated_type_bounds)] -#![feature(auto_traits)] +#![cfg_attr(bootstrap, feature(auto_traits))] #![feature(cell_leak)] #![feature(core_intrinsics)] #![feature(extend_one)] diff --git a/compiler/rustc_data_structures/src/marker.rs b/compiler/rustc_data_structures/src/marker.rs index b067f9d4502df..dd1d74e298fda 100644 --- a/compiler/rustc_data_structures/src/marker.rs +++ b/compiler/rustc_data_structures/src/marker.rs @@ -1,28 +1,57 @@ cfg_if!( if #[cfg(not(parallel_compiler))] { + #[cfg(bootstrap)] pub auto trait DynSend {} + + #[cfg(not(bootstrap))] + #[rustc_auto_trait] + pub trait DynSend {} + + #[cfg(bootstrap)] pub auto trait DynSync {} + #[cfg(not(bootstrap))] + #[rustc_auto_trait] + pub trait DynSync {} + impl DynSend for T {} impl DynSync for T {} } else { + #[cfg(bootstrap)] + #[rustc_on_unimplemented( + message = "`{Self}` doesn't implement `DynSend`. \ + Add it to `rustc_data_structures::marker` or use `IntoDynSyncSend` if it's already `Send`" + )] + pub unsafe auto trait DynSend {} + + #[cfg(not(bootstrap))] #[rustc_on_unimplemented( message = "`{Self}` doesn't implement `DynSend`. \ Add it to `rustc_data_structures::marker` or use `IntoDynSyncSend` if it's already `Send`" )] + #[rustc_auto_trait] // This is an auto trait for types which can be sent across threads if `sync::is_dyn_thread_safe()` // is true. These types can be wrapped in a `FromDyn` to get a `Send` type. Wrapping a // `Send` type in `IntoDynSyncSend` will create a `DynSend` type. - pub unsafe auto trait DynSend {} + pub unsafe trait DynSend {} + + #[cfg(bootstrap)] + #[rustc_on_unimplemented( + message = "`{Self}` doesn't implement `DynSync`. \ + Add it to `rustc_data_structures::marker` or use `IntoDynSyncSend` if it's already `Sync`" + )] + pub unsafe auto trait DynSync {} + #[cfg(not(bootstrap))] #[rustc_on_unimplemented( message = "`{Self}` doesn't implement `DynSync`. \ Add it to `rustc_data_structures::marker` or use `IntoDynSyncSend` if it's already `Sync`" )] + #[rustc_auto_trait] // This is an auto trait for types which can be shared across threads if `sync::is_dyn_thread_safe()` // is true. These types can be wrapped in a `FromDyn` to get a `Sync` type. Wrapping a // `Sync` type in `IntoDynSyncSend` will create a `DynSync` type. - pub unsafe auto trait DynSync {} + pub unsafe trait DynSync {} // Same with `Sync` and `Send`. unsafe impl DynSend for &T {} diff --git a/compiler/rustc_data_structures/src/sync.rs b/compiler/rustc_data_structures/src/sync.rs index cca043ba0d18d..f19bb41d1a3a6 100644 --- a/compiler/rustc_data_structures/src/sync.rs +++ b/compiler/rustc_data_structures/src/sync.rs @@ -114,8 +114,17 @@ cfg_if! { use std::ops::Add; use std::cell::Cell; + #[cfg(bootstrap)] pub unsafe auto trait Send {} + #[cfg(not(bootstrap))] + #[rustc_auto_trait] + pub unsafe trait Send {} + + #[cfg(bootstrap)] pub unsafe auto trait Sync {} + #[cfg(not(bootstrap))] + #[rustc_auto_trait] + pub unsafe trait Sync {} unsafe impl Send for T {} unsafe impl Sync for T {} diff --git a/compiler/rustc_error_codes/src/error_codes/E0198.md b/compiler/rustc_error_codes/src/error_codes/E0198.md index 1238165cb88d4..7490d799bb5c5 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0198.md +++ b/compiler/rustc_error_codes/src/error_codes/E0198.md @@ -15,14 +15,12 @@ unsafe. This will compile: -```ignore (ignore auto_trait future compatibility warning) -#![feature(auto_traits)] +``` +#![feature(negative_impls)] struct Foo; -auto trait Enterprise {} +trait Enterprise {} impl !Enterprise for Foo { } ``` - -Please note that negative impls are only allowed for auto traits. diff --git a/compiler/rustc_error_codes/src/error_codes/E0321.md b/compiler/rustc_error_codes/src/error_codes/E0321.md index bcfc12897c5c3..890e5e2691652 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0321.md +++ b/compiler/rustc_error_codes/src/error_codes/E0321.md @@ -1,10 +1,10 @@ -A cross-crate opt-out trait was implemented on something which wasn't a struct +A cross-crate auto trait was implemented on something which wasn't a struct or enum type. Erroneous code example: ```compile_fail,E0321 -#![feature(auto_traits)] +#![feature(negative_impls)] struct Foo; @@ -16,6 +16,6 @@ unsafe impl Send for &'static Foo {} // `&'static Foo` ``` -Only structs and enums are permitted to impl Send, Sync, and other opt-out +Only structs and enums are permitted to impl Send, Sync, and other auto trait, and the struct or enum must be local to the current crate. So, for example, `unsafe impl Send for Rc` is not allowed. diff --git a/compiler/rustc_error_codes/src/error_codes/E0380.md b/compiler/rustc_error_codes/src/error_codes/E0380.md index 638f0c8ecc65f..a13b26c27d550 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0380.md +++ b/compiler/rustc_error_codes/src/error_codes/E0380.md @@ -3,7 +3,8 @@ An auto trait was declared with a method or an associated item. Erroneous code example: ```compile_fail,E0380 -unsafe auto trait Trait { +#[rustc_auto_trait] +unsafe trait Trait { type Output; // error! } ``` diff --git a/compiler/rustc_error_codes/src/error_codes/E0567.md b/compiler/rustc_error_codes/src/error_codes/E0567.md index bc13ee4c04cb2..a9c4cc2e2ed17 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0567.md +++ b/compiler/rustc_error_codes/src/error_codes/E0567.md @@ -3,9 +3,10 @@ Generics have been used on an auto trait. Erroneous code example: ```compile_fail,E0567 -#![feature(auto_traits)] +#![feature(rustc_attrs)] -auto trait Generic {} // error! +#[rustc_auto_trait] +trait Generic {} // error! # fn main() {} ``` @@ -16,8 +17,9 @@ parameters. To fix this issue, just remove the generics: ``` -#![feature(auto_traits)] +#![feature(rustc_attrs)] -auto trait Generic {} // ok! +#[rustc_auto_trait] +trait Generic {} // ok! # fn main() {} ``` diff --git a/compiler/rustc_error_codes/src/error_codes/E0568.md b/compiler/rustc_error_codes/src/error_codes/E0568.md index 17b3f5e31bdf9..30af8cd577881 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0568.md +++ b/compiler/rustc_error_codes/src/error_codes/E0568.md @@ -3,9 +3,10 @@ A super trait has been added to an auto trait. Erroneous code example: ```compile_fail,E0568 -#![feature(auto_traits)] +#![feature(rustc_attrs)] -auto trait Bound : Copy {} // error! +#[rustc_auto_trait] +trait Bound : Copy {} // error! fn main() {} ``` @@ -18,9 +19,10 @@ all the existing types could implement `Bound` because very few of them have the To fix this issue, just remove the super trait: ``` -#![feature(auto_traits)] +#![feature(rustc_attrs)] -auto trait Bound {} // ok! +#[rustc_auto_trait] +trait Bound {} // ok! fn main() {} ``` diff --git a/compiler/rustc_error_codes/src/error_codes/E0785.md b/compiler/rustc_error_codes/src/error_codes/E0785.md index 373320539ef64..1b8e27f87c497 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0785.md +++ b/compiler/rustc_error_codes/src/error_codes/E0785.md @@ -3,9 +3,10 @@ An inherent `impl` was written on a dyn auto trait. Erroneous code example: ```compile_fail,E0785 -#![feature(auto_traits)] +#![feature(rustc_attrs)] -auto trait AutoTrait {} +#[rustc_auto_trait] +trait AutoTrait {} impl dyn AutoTrait {} ``` @@ -20,11 +21,12 @@ trait, it cannot be implemented at all. Working example: ``` -#![feature(auto_traits)] +#![feature(rustc_attrs)] trait PrincipalTrait {} -auto trait AutoTrait {} +#[rustc_auto_trait] +trait AutoTrait {} impl dyn PrincipalTrait + AutoTrait + Send {} ``` diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index a02c04ecd3ecb..d5f121436544e 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -223,9 +223,6 @@ declare_features! ( // feature-group-start: internal feature gates // ------------------------------------------------------------------------- - /// Allows features specific to auto traits. - /// Renamed from `optin_builtin_traits`. - (active, auto_traits, "1.50.0", Some(13231), None), /// Allows using `box` in patterns (RFC 469). (active, box_patterns, "1.0.0", Some(29641), None), /// Allows `#[doc(notable_trait)]`. diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 65e697c8f3b80..fa5fb5d1759f0 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -550,6 +550,10 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ may_dangle, Normal, template!(Word), WarnFollowing, dropck_eyepatch, "`may_dangle` has unstable semantics and may be removed in the future", ), + rustc_attr!( + rustc_auto_trait, Normal, template!(Word), WarnFollowing, + "`#[rustc_auto_trait]` is used to mark auto traits, only intended to be used in `core`", + ), // ========================================================================== // Internal attributes: Runtime related: @@ -712,7 +716,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ ), rustc_attr!( rustc_coinductive, AttributeType::Normal, template!(Word), WarnFollowing, @only_local: true, - "#![rustc_coinductive] changes a trait to be coinductive, allowing cycles in the trait solver." + "#[rustc_coinductive] changes a trait to be coinductive, allowing cycles in the trait solver." ), rustc_attr!( rustc_allow_incoherent_impl, AttributeType::Normal, template!(Word), ErrorFollowing, @only_local: true, diff --git a/compiler/rustc_feature/src/removed.rs b/compiler/rustc_feature/src/removed.rs index da18cb2a239e8..a95bffd998f20 100644 --- a/compiler/rustc_feature/src/removed.rs +++ b/compiler/rustc_feature/src/removed.rs @@ -50,6 +50,9 @@ declare_features! ( (removed, allocator, "1.0.0", None, None, None), /// Allows a test to fail without failing the whole suite. (removed, allow_fail, "1.19.0", Some(46488), None, Some("removed due to no clear use cases")), + /// Allows features specific to auto traits. + /// Renamed from `optin_builtin_traits`. + (removed, auto_traits, "1.50.0", Some(13231), None, Some("removed in favor of `#[rustc_auto_trait]`")), (removed, await_macro, "1.38.0", Some(50547), None, Some("subsumed by `.await` syntax")), /// Allows using the `box $expr` syntax. @@ -147,9 +150,8 @@ declare_features! ( /// A way to temporarily opt out of opt-in copy. This will *never* be accepted. (removed, opt_out_copy, "1.0.0", None, None, None), /// Allows features specific to OIBIT (now called auto traits). - /// Renamed to `auto_traits`. - (removed, optin_builtin_traits, "1.0.0", Some(13231), None, - Some("renamed to `auto_traits`")), + /// Renamed to `auto_traits` which has then been removed in favor of `rustc_attrs`. + (removed, optin_builtin_traits, "1.0.0", Some(13231), None, Some("removed in favor of `#[rustc_auto_trait]`")), /// Allows overlapping impls of marker traits. (removed, overlapping_marker_traits, "1.42.0", Some(29864), None, Some("removed in favor of `#![feature(marker_trait_attr)]`")), diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 3eec66611edd1..704b52aaff7c7 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -7,7 +7,7 @@ use crate::LangItem; use rustc_ast as ast; use rustc_ast::util::parser::ExprPrecedence; use rustc_ast::{Attribute, FloatTy, IntTy, Label, LitKind, TraitObjectSyntax, UintTy}; -pub use rustc_ast::{BindingAnnotation, BorrowKind, ByRef, ImplPolarity, IsAuto}; +pub use rustc_ast::{BindingAnnotation, BorrowKind, ByRef, ImplPolarity}; pub use rustc_ast::{CaptureBy, Movability, Mutability}; use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; use rustc_data_structures::fingerprint::Fingerprint; @@ -3216,11 +3216,11 @@ impl<'hir> Item<'hir> { #[track_caller] pub fn expect_trait( self, - ) -> (IsAuto, Unsafety, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]) { - let ItemKind::Trait(is_auto, unsafety, gen, bounds, items) = self.kind else { + ) -> (Unsafety, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]) { + let ItemKind::Trait(unsafety, gen, bounds, items) = self.kind else { self.expect_failed("a trait") }; - (is_auto, unsafety, gen, bounds, items) + (unsafety, gen, bounds, items) } /// Expect an [`ItemKind::TraitAlias`] or panic. @@ -3347,7 +3347,7 @@ pub enum ItemKind<'hir> { /// A union definition, e.g., `union Foo {x: A, y: B}`. Union(VariantData<'hir>, &'hir Generics<'hir>), /// A trait definition. - Trait(IsAuto, Unsafety, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]), + Trait(Unsafety, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]), /// A trait alias. TraitAlias(&'hir Generics<'hir>, GenericBounds<'hir>), @@ -3382,7 +3382,7 @@ impl ItemKind<'_> { | ItemKind::Enum(_, ref generics) | ItemKind::Struct(_, ref generics) | ItemKind::Union(_, ref generics) - | ItemKind::Trait(_, _, ref generics, _, _) + | ItemKind::Trait(_, ref generics, _, _) | ItemKind::TraitAlias(ref generics, _) | ItemKind::Impl(Impl { ref generics, .. }) => generics, _ => return None, diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index c4fdffb02618a..f4759ca61ce41 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1114,7 +1114,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) { }); // Only check traits, don't check trait aliases - if let hir::ItemKind::Trait(_, _, _, _, items) = item.kind { + if let hir::ItemKind::Trait(_, _, _, items) = item.kind { check_gat_where_clauses(tcx, items); } } diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index 69020b1f11dc6..c4a63ec365d2f 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -71,7 +71,8 @@ fn do_orphan_check_impl<'tcx>( // // ``` // // Crate A - // auto trait Foo { } + // #[rustc_auto_trait] + // trait Foo { } // fn two_foos(..) { // one_foo::<(A,B)>(..) // } @@ -127,7 +128,8 @@ fn do_orphan_check_impl<'tcx>( // This is necessary in order for autotrait bounds on methods of trait // objects to be sound. // - // auto trait AutoTrait {} + // #[rustc_auto_trait] + // trait AutoTrait {} // // trait ObjectSafeTrait { // fn f(&self) where Self: AutoTrait; diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 221df4e36b296..1c7108eb1accb 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -253,7 +253,7 @@ fn reject_placeholder_type_signatures_in_item<'tcx>( hir::ItemKind::Union(_, generics) | hir::ItemKind::Enum(_, generics) | hir::ItemKind::TraitAlias(generics, _) - | hir::ItemKind::Trait(_, _, generics, ..) + | hir::ItemKind::Trait(_, generics, ..) | hir::ItemKind::Impl(hir::Impl { generics, .. }) | hir::ItemKind::Struct(_, generics) => (generics, true), hir::ItemKind::OpaqueTy(hir::OpaqueTy { generics, .. }) @@ -894,11 +894,9 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> { fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef { let item = tcx.hir().expect_item(def_id); - let (is_auto, unsafety, items) = match item.kind { - hir::ItemKind::Trait(is_auto, unsafety, .., items) => { - (is_auto == hir::IsAuto::Yes, unsafety, items) - } - hir::ItemKind::TraitAlias(..) => (false, hir::Unsafety::Normal, &[][..]), + let (unsafety, items) = match item.kind { + hir::ItemKind::Trait(unsafety, .., items) => (unsafety, items), + hir::ItemKind::TraitAlias(..) => (hir::Unsafety::Normal, &[][..]), _ => span_bug!(item.span, "trait_def_of_item invoked on non-trait"), }; @@ -908,7 +906,8 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef { } let is_marker = tcx.has_attr(def_id, sym::marker); - let rustc_coinductive = tcx.has_attr(def_id, sym::rustc_coinductive); + let is_auto = tcx.has_attr(def_id, sym::rustc_auto_trait); + let is_coinductive = tcx.has_attr(def_id, sym::rustc_coinductive); let skip_array_during_method_dispatch = tcx.has_attr(def_id, sym::rustc_skip_array_during_method_dispatch); let specialization_kind = if tcx.has_attr(def_id, sym::rustc_unsafe_specialization_marker) { @@ -1043,7 +1042,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef { paren_sugar, has_auto_impl: is_auto, is_marker, - is_coinductive: rustc_coinductive || is_auto, + is_coinductive: is_coinductive || is_auto, skip_array_during_method_dispatch, specialization_kind, must_implement_one_of, diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index 1298c08608716..01429f47955e1 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -143,7 +143,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen | ItemKind::Struct(_, generics) | ItemKind::Union(_, generics) => generics, - ItemKind::Trait(_, _, generics, self_bounds, ..) + ItemKind::Trait(_, generics, self_bounds, ..) | ItemKind::TraitAlias(generics, self_bounds) => { is_trait = Some(self_bounds); generics @@ -703,7 +703,7 @@ pub(super) fn type_param_predicates( | ItemKind::Enum(_, generics) | ItemKind::Struct(_, generics) | ItemKind::Union(_, generics) => generics, - ItemKind::Trait(_, _, generics, ..) => { + ItemKind::Trait(_, generics, ..) => { // Implied `Self: Trait` and supertrait bounds. if param_id == item_hir_id { let identity_trait_ref = diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index eb4466449a09f..a1fe5d2e86ae6 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -589,7 +589,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> { | hir::ItemKind::Enum(_, generics) | hir::ItemKind::Struct(_, generics) | hir::ItemKind::Union(_, generics) - | hir::ItemKind::Trait(_, _, generics, ..) + | hir::ItemKind::Trait(_, generics, ..) | hir::ItemKind::TraitAlias(generics, ..) | hir::ItemKind::Impl(&hir::Impl { generics, .. }) => { // These kinds of items have only early-bound lifetime parameters. diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 8587b009f25aa..a5221a55a2ab6 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -663,9 +663,8 @@ impl<'a> State<'a> { } self.bclose(item.span); } - hir::ItemKind::Trait(is_auto, unsafety, generics, bounds, trait_items) => { + hir::ItemKind::Trait(unsafety, generics, bounds, trait_items) => { self.head(""); - self.print_is_auto(is_auto); self.print_unsafety(unsafety); self.word_nbsp("trait"); self.print_ident(item.ident); @@ -2330,13 +2329,6 @@ impl<'a> State<'a> { hir::Unsafety::Unsafe => self.word_nbsp("unsafe"), } } - - pub fn print_is_auto(&mut self, s: hir::IsAuto) { - match s { - hir::IsAuto::Yes => self.word_nbsp("auto"), - hir::IsAuto::No => {} - } - } } /// Does this expression require a semicolon to be treated diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 07c48ec6392a8..b3cb57574e240 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -804,21 +804,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } entry.1.insert((self_ty.span, "")); } - Some(Node::Item(hir::Item { - kind: hir::ItemKind::Trait(rustc_ast::ast::IsAuto::Yes, ..), - span: item_span, - .. - })) => { - tcx.sess.delay_span_bug( - *item_span, - "auto trait is invoked with no method error, but no error reported?", - ); - } Some(Node::Item(hir::Item { ident, kind: hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..), + span: item_span, .. })) => { + if tcx.has_attr(item_def_id, sym::rustc_auto_trait) { + tcx.sess.delay_span_bug( + *item_span, + "auto trait is invoked with no method error, but no error reported?", + ); + continue; + } + skip_list.insert(p); let entry = spanned_predicates.entry(ident.span); let entry = entry.or_insert_with(|| { diff --git a/compiler/rustc_lint/src/multiple_supertrait_upcastable.rs b/compiler/rustc_lint/src/multiple_supertrait_upcastable.rs index 84558ee1f020c..3fa98d555eb70 100644 --- a/compiler/rustc_lint/src/multiple_supertrait_upcastable.rs +++ b/compiler/rustc_lint/src/multiple_supertrait_upcastable.rs @@ -39,7 +39,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleSupertraitUpcastable { let def_id = item.owner_id.to_def_id(); // NOTE(nbdd0121): use `object_safety_violations` instead of `check_is_object_safe` because // the latter will report `where_clause_object_safety` lint. - if let hir::ItemKind::Trait(_, _, _, _, _) = item.kind + if let hir::ItemKind::Trait(_, _, _, _) = item.kind && cx.tcx.object_safety_violations(def_id).is_empty() { let direct_super_traits_iter = cx.tcx diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 4af2d83e9c721..1b4599c90eb5c 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -996,7 +996,7 @@ impl<'hir> Map<'hir> { }) => until_within(*outer_span, ty.span), // With generics and bounds. Node::Item(Item { - kind: ItemKind::Trait(_, _, generics, bounds, _), + kind: ItemKind::Trait(_, generics, bounds, _), span: outer_span, .. }) diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 99b750c9afc8c..01511f4ba24f3 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -160,21 +160,17 @@ impl<'tcx> ObligationCause<'tcx> { self.code = f(std::mem::take(&mut self.code)).into(); } + /// Creates a cause for obligations that are derived from `obligation` by a recursive search. + /// + /// E.g., for a builtin bound, or eventually a `#[rustc_auto_trait] trait Foo`. + /// If `obligation` is itself a derived obligation, this is just a clone, but + /// otherwise we create a "derived obligation" cause so as to keep track of the + /// original root obligation for error reporting. pub fn derived_cause( mut self, parent_trait_pred: ty::PolyTraitPredicate<'tcx>, variant: impl FnOnce(DerivedObligationCause<'tcx>) -> ObligationCauseCode<'tcx>, ) -> ObligationCause<'tcx> { - /*! - * Creates a cause for obligations that are derived from - * `obligation` by a recursive search (e.g., for a builtin - * bound, or eventually a `auto trait Foo`). If `obligation` - * is itself a derived obligation, this is just a clone, but - * otherwise we create a "derived obligation" cause so as to - * keep track of the original root obligation for error - * reporting. - */ - // NOTE(flaper87): As of now, it keeps track of the whole error // chain. Ideally, we should have a way to configure this either // by using -Z verbose or just a CLI argument. diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index aa1e7f216a069..36adef37eff40 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -2422,8 +2422,8 @@ impl<'tcx> TyCtxt<'tcx> { self.trait_def(trait_def_id).has_auto_impl } - /// Returns `true` if this is coinductive, either because it is - /// an auto trait or because it has the `#[rustc_coinductive]` attribute. + /// Returns `true` if this is coinductive, because it has the + /// `#[rustc_auto_trait]` or `#[rustc_coinductive]` attribute. pub fn trait_is_coinductive(self, trait_def_id: DefId) -> bool { self.trait_def(trait_def_id).is_coinductive } diff --git a/compiler/rustc_middle/src/ty/trait_def.rs b/compiler/rustc_middle/src/ty/trait_def.rs index bf9b244936fc6..7756cc7e4e350 100644 --- a/compiler/rustc_middle/src/ty/trait_def.rs +++ b/compiler/rustc_middle/src/ty/trait_def.rs @@ -31,8 +31,8 @@ pub struct TraitDef { /// and thus `impl`s of it are allowed to overlap. pub is_marker: bool, - /// If `true`, then this trait has to `#[rustc_coinductive]` attribute or - /// is an auto trait. This indicates that trait solver cycles involving an + /// If `true`, then this trait has the `#[rustc_auto_trait]` or `#[rustc_coinductive]` + /// attribute. This indicates that trait solver cycles involving an /// `X: ThisTrait` goal are accepted. /// /// In the future all traits should be coinductive, but we need a better diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 9a7564cb213d7..abb01bdc40c1c 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -167,10 +167,13 @@ impl CheckAttrVisitor<'_> { | sym::rustc_dirty | sym::rustc_if_this_changed | sym::rustc_then_this_would_need => self.check_rustc_dirty_clean(&attr), - sym::rustc_coinductive - | sym::rustc_must_implement_one_of + sym::const_trait + | sym::rustc_auto_trait + | sym::rustc_coinductive | sym::rustc_deny_explicit_impl - | sym::const_trait => self.check_must_be_applied_to_trait(&attr, span, target), + | sym::rustc_must_implement_one_of => { + self.check_must_be_applied_to_trait(&attr, span, target) + } sym::cmse_nonsecure_entry => { self.check_cmse_nonsecure_entry(hir_id, attr, span, target) } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index e4fafbc12d355..74765eba734ef 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1291,6 +1291,7 @@ symbols! { rustc_allow_incoherent_impl, rustc_allowed_through_unstable_modules, rustc_attrs, + rustc_auto_trait, rustc_box, rustc_builtin_macro, rustc_capture_analysis, diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 9a728b1060fb1..ea5b5ff4a170e 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -2452,7 +2452,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ); if let Some(local_def_id) = data.trait_ref.def_id.as_local() - && let Some(hir::Node::Item(hir::Item { ident: trait_name, kind: hir::ItemKind::Trait(_, _, _, _, trait_item_refs), .. })) = self.tcx.hir().find_by_def_id(local_def_id) + && let Some(hir::Node::Item(hir::Item { ident: trait_name, kind: hir::ItemKind::Trait(_, _, _, trait_item_refs), .. })) = self.tcx.hir().find_by_def_id(local_def_id) && let Some(method_ref) = trait_item_refs.iter().find(|item_ref| item_ref.ident == *assoc_item_name) { err.span_label(method_ref.span, format!("`{trait_name}::{assoc_item_name}` defined here")); } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 15f2ba809a4a6..692100f073c89 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -511,7 +511,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { match node { hir::Node::Item(hir::Item { ident, - kind: hir::ItemKind::Trait(_, _, generics, bounds, _), + kind: hir::ItemKind::Trait(_, generics, bounds, _), .. }) if self_ty == self.tcx.types.self_param => { assert!(param_ty); @@ -573,7 +573,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } hir::Node::Item(hir::Item { kind: - hir::ItemKind::Trait(_, _, generics, ..) + hir::ItemKind::Trait(_, generics, ..) | hir::ItemKind::Impl(hir::Impl { generics, .. }), .. }) if projection.is_some() => { @@ -597,7 +597,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { hir::ItemKind::Struct(_, generics) | hir::ItemKind::Enum(_, generics) | hir::ItemKind::Union(_, generics) - | hir::ItemKind::Trait(_, _, generics, ..) + | hir::ItemKind::Trait(_, generics, ..) | hir::ItemKind::Impl(hir::Impl { generics, .. }) | hir::ItemKind::Fn(_, generics, _) | hir::ItemKind::TyAlias(_, generics) @@ -663,7 +663,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { hir::ItemKind::Struct(_, generics) | hir::ItemKind::Enum(_, generics) | hir::ItemKind::Union(_, generics) - | hir::ItemKind::Trait(_, _, generics, ..) + | hir::ItemKind::Trait(_, generics, ..) | hir::ItemKind::Impl(hir::Impl { generics, .. }) | hir::ItemKind::Fn(_, generics, _) | hir::ItemKind::TyAlias(_, generics) @@ -3006,13 +3006,13 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let mut is_auto_trait = false; match self.tcx.hir().get_if_local(data.impl_or_alias_def_id) { Some(Node::Item(hir::Item { - kind: hir::ItemKind::Trait(is_auto, ..), + kind: hir::ItemKind::Trait(..), ident, .. })) => { // FIXME: we should do something else so that it works even on crate foreign // auto traits. - is_auto_trait = matches!(is_auto, hir::IsAuto::Yes); + is_auto_trait = tcx.has_attr(data.impl_or_alias_def_id, sym::rustc_auto_trait); err.span_note(ident.span, msg); } Some(Node::Item(hir::Item { diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 5823b4508d94e..8b4b2e729ba08 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -561,7 +561,8 @@ fn virtual_call_violation_for_method<'tcx>( // dyn Trait is okay: // - // auto trait AutoTrait {} + // #[rustc_auto_trait] + // trait AutoTrait {} // // trait Trait { // fn f(&self) where Self: AutoTrait; @@ -580,7 +581,7 @@ fn virtual_call_violation_for_method<'tcx>( && tcx.trait_is_auto(pred_trait_ref.def_id) { // Consider bounds like `Self: Bound`. Auto traits are not - // allowed to have generic parameters so `auto trait Bound {}` + // allowed to have generic parameters so `#[rustc_auto_trait] trait Bound {}` // would already have reported an error at the definition of the // auto trait. if pred_trait_ref.args.len() != 1 { diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 08ee9c73bf8aa..42de4bd552cfd 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -354,7 +354,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { Ok(fully_flattened) } - /// This handles the case where an `auto trait Foo` impl is being used. + /// This handles the case where an auto trait `Foo` impl is being used. /// The idea is that the impl applies to `X : Foo` if the following conditions are met: /// /// 1. For each constituent type `Y` in `X`, `Y : Foo` holds diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index ab8d9f33b08b4..0b0553f011be4 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -196,6 +196,7 @@ // // Language features: // tidy-alphabetical-start +#![cfg_attr(bootstrap, feature(auto_traits))] #![cfg_attr(not(bootstrap), feature(effects))] #![feature(abi_unadjusted)] #![feature(adt_const_params)] @@ -203,7 +204,6 @@ #![feature(allow_internal_unstable)] #![feature(asm_const)] #![feature(associated_type_bounds)] -#![feature(auto_traits)] #![feature(c_unwind)] #![feature(cfg_sanitize)] #![feature(cfg_target_has_atomic)] diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 5ed82e26a0ae7..2241e6077f753 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -56,6 +56,12 @@ macro marker_impls { ( $(#[$($meta:tt)*])* unsafe $Trait:ident for ) => {}, } +#[cfg(bootstrap)] +#[stable(feature = "rust1", since = "1.0.0")] +#[cfg_attr(not(test), rustc_diagnostic_item = "Send")] +#[allow(missing_docs)] +pub unsafe auto trait Send {} + /// Types that can be transferred across thread boundaries. /// /// This trait is automatically implemented when the compiler determines it's @@ -73,13 +79,15 @@ macro marker_impls { /// [`Rc`]: ../../std/rc/struct.Rc.html /// [arc]: ../../std/sync/struct.Arc.html /// [ub]: ../../reference/behavior-considered-undefined.html +#[cfg(not(bootstrap))] #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "Send")] #[rustc_on_unimplemented( message = "`{Self}` cannot be sent between threads safely", label = "`{Self}` cannot be sent between threads safely" )] -pub unsafe auto trait Send { +#[rustc_auto_trait] +pub unsafe trait Send { // empty. } @@ -498,6 +506,13 @@ impl Copy for ! {} #[stable(feature = "rust1", since = "1.0.0")] impl Copy for &T {} +#[cfg(bootstrap)] +#[stable(feature = "rust1", since = "1.0.0")] +#[cfg_attr(not(test), rustc_diagnostic_item = "Sync")] +#[lang = "sync"] +#[allow(missing_docs)] +pub unsafe auto trait Sync {} + /// Types for which it is safe to share references between threads. /// /// This trait is automatically implemented when the compiler determines @@ -568,6 +583,7 @@ impl Copy for &T {} /// [ub]: ../../reference/behavior-considered-undefined.html /// [transmute]: crate::mem::transmute /// [nomicon-send-and-sync]: ../../nomicon/send-and-sync.html +#[cfg(not(bootstrap))] #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "Sync")] #[lang = "sync"] @@ -631,7 +647,8 @@ impl Copy for &T {} message = "`{Self}` cannot be shared between threads safely", label = "`{Self}` cannot be shared between threads safely" )] -pub unsafe auto trait Sync { +#[rustc_auto_trait] +pub unsafe trait Sync { // FIXME(estebank): once support to add notes in `rustc_on_unimplemented` // lands in beta, and it has been extended to check whether a closure is // anywhere in the requirement chain, extend it as such (#48534): @@ -862,12 +879,18 @@ pub trait DiscriminantKind { type Discriminant: Clone + Copy + Debug + Eq + PartialEq + Hash + Send + Sync + Unpin; } +#[cfg(bootstrap)] +#[lang = "freeze"] +pub(crate) unsafe auto trait Freeze {} + /// Compiler-internal trait used to determine whether a type contains /// any `UnsafeCell` internally, but not through an indirection. /// This affects, for example, whether a `static` of that type is /// placed in read-only static memory or writable static memory. +#[cfg(not(bootstrap))] #[lang = "freeze"] -pub(crate) unsafe auto trait Freeze {} +#[rustc_auto_trait] +pub(crate) unsafe trait Freeze {} impl !Freeze for UnsafeCell {} marker_impls! { @@ -879,6 +902,12 @@ marker_impls! { {T: ?Sized} &mut T, } +#[cfg(bootstrap)] +#[stable(feature = "pin", since = "1.33.0")] +#[lang = "unpin"] +#[allow(missing_docs)] +pub auto trait Unpin {} + /// Types that can be safely moved after being pinned. /// /// Rust itself has no notion of immovable types, and considers moves (e.g., @@ -920,13 +949,15 @@ marker_impls! { /// [`mem::replace`]: crate::mem::replace /// [Pin]: crate::pin::Pin /// [`pin` module]: crate::pin +#[cfg(not(bootstrap))] #[stable(feature = "pin", since = "1.33.0")] #[rustc_on_unimplemented( note = "consider using the `pin!` macro\nconsider using `Box::pin` if you need to access the pinned value outside of the current scope", message = "`{Self}` cannot be unpinned" )] #[lang = "unpin"] -pub auto trait Unpin {} +#[rustc_auto_trait] +pub trait Unpin {} /// A marker type which does not implement `Unpin`. /// diff --git a/library/core/src/panic/unwind_safe.rs b/library/core/src/panic/unwind_safe.rs index 7e7b6b4dbe9b1..bef52e97aa085 100644 --- a/library/core/src/panic/unwind_safe.rs +++ b/library/core/src/panic/unwind_safe.rs @@ -7,6 +7,12 @@ use crate::pin::Pin; use crate::ptr::{NonNull, Unique}; use crate::task::{Context, Poll}; +#[cfg(bootstrap)] +#[stable(feature = "catch_unwind", since = "1.9.0")] +#[cfg_attr(not(test), rustc_diagnostic_item = "unwind_safe_trait")] +#[allow(missing_docs)] +pub auto trait UnwindSafe {} + /// A marker trait which represents "panic safe" types in Rust. /// /// This trait is implemented by default for many types and behaves similarly in @@ -81,13 +87,21 @@ use crate::task::{Context, Poll}; /// above, the lack of `unsafe` means it is mostly an advisory. The /// [`AssertUnwindSafe`] wrapper struct can be used to force this trait to be /// implemented for any closed over variables passed to `catch_unwind`. +#[cfg(not(bootstrap))] #[stable(feature = "catch_unwind", since = "1.9.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "unwind_safe_trait")] #[rustc_on_unimplemented( message = "the type `{Self}` may not be safely transferred across an unwind boundary", label = "`{Self}` may not be safely transferred across an unwind boundary" )] -pub auto trait UnwindSafe {} +#[rustc_auto_trait] +pub trait UnwindSafe {} + +#[cfg(bootstrap)] +#[stable(feature = "catch_unwind", since = "1.9.0")] +#[cfg_attr(not(test), rustc_diagnostic_item = "ref_unwind_safe_trait")] +#[allow(missing_docs)] +pub auto trait RefUnwindSafe {} /// A marker trait representing types where a shared reference is considered /// unwind safe. @@ -97,6 +111,7 @@ pub auto trait UnwindSafe {} /// /// This is a "helper marker trait" used to provide impl blocks for the /// [`UnwindSafe`] trait, for more information see that documentation. +#[cfg(not(bootstrap))] #[stable(feature = "catch_unwind", since = "1.9.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "ref_unwind_safe_trait")] #[rustc_on_unimplemented( @@ -105,7 +120,8 @@ pub auto trait UnwindSafe {} label = "`{Self}` may contain interior mutability and a reference may not be safely \ transferrable across a catch_unwind boundary" )] -pub auto trait RefUnwindSafe {} +#[rustc_auto_trait] +pub trait RefUnwindSafe {} /// A simple wrapper around a type to assert that it is unwind safe. /// diff --git a/library/rtstartup/rsbegin.rs b/library/rtstartup/rsbegin.rs index 1df0c89705380..c4bb78b7c3b87 100644 --- a/library/rtstartup/rsbegin.rs +++ b/library/rtstartup/rsbegin.rs @@ -14,19 +14,21 @@ #![feature(no_core)] #![feature(lang_items)] -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![crate_type = "rlib"] #![no_core] -#![allow(non_camel_case_types)] +#![allow(internal_features, non_camel_case_types)] #[lang = "sized"] trait Sized {} #[lang = "sync"] -auto trait Sync {} +#[rustc_auto_trait] +trait Sync {} #[lang = "copy"] trait Copy {} #[lang = "freeze"] -auto trait Freeze {} +#[rustc_auto_trait] +trait Freeze {} #[lang = "drop_in_place"] #[inline] diff --git a/library/rtstartup/rsend.rs b/library/rtstartup/rsend.rs index d5aca80edf9e0..56d59cdea2dea 100644 --- a/library/rtstartup/rsend.rs +++ b/library/rtstartup/rsend.rs @@ -2,9 +2,10 @@ #![feature(no_core)] #![feature(lang_items)] -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![crate_type = "rlib"] #![no_core] +#![allow(internal_features)] #[lang = "sized"] trait Sized {} @@ -14,7 +15,8 @@ impl Sync for T {} #[lang = "copy"] trait Copy {} #[lang = "freeze"] -auto trait Freeze {} +#[rustc_auto_trait] +trait Freeze {} #[lang = "drop_in_place"] #[inline] diff --git a/src/doc/unstable-book/src/language-features/auto-traits.md b/src/doc/unstable-book/src/language-features/auto-traits.md deleted file mode 100644 index 014e15d1ada68..0000000000000 --- a/src/doc/unstable-book/src/language-features/auto-traits.md +++ /dev/null @@ -1,106 +0,0 @@ -# `auto_traits` - -The tracking issue for this feature is [#13231] - -[#13231]: https://github.com/rust-lang/rust/issues/13231 - ----- - -The `auto_traits` feature gate allows you to define auto traits. - -Auto traits, like [`Send`] or [`Sync`] in the standard library, are marker traits -that are automatically implemented for every type, unless the type, or a type it contains, -has explicitly opted out via a negative impl. (Negative impls are separately controlled -by the `negative_impls` feature.) - -[`Send`]: ../../std/marker/trait.Send.html -[`Sync`]: ../../std/marker/trait.Sync.html - -```rust,ignore (partial-example) -impl !Trait for Type {} -``` - -Example: - -```rust -#![feature(negative_impls)] -#![feature(auto_traits)] - -auto trait Valid {} - -struct True; -struct False; - -impl !Valid for False {} - -struct MaybeValid(T); - -fn must_be_valid(_t: T) { } - -fn main() { - // works - must_be_valid( MaybeValid(True) ); - - // compiler error - trait bound not satisfied - // must_be_valid( MaybeValid(False) ); -} -``` - -## Automatic trait implementations - -When a type is declared as an `auto trait`, we will automatically -create impls for every struct/enum/union, unless an explicit impl is -provided. These automatic impls contain a where clause for each field -of the form `T: AutoTrait`, where `T` is the type of the field and -`AutoTrait` is the auto trait in question. As an example, consider the -struct `List` and the auto trait `Send`: - -```rust -struct List { - data: T, - next: Option>>, -} -``` - -Presuming that there is no explicit impl of `Send` for `List`, the -compiler will supply an automatic impl of the form: - -```rust -struct List { - data: T, - next: Option>>, -} - -unsafe impl Send for List -where - T: Send, // from the field `data` - Option>>: Send, // from the field `next` -{ } -``` - -Explicit impls may be either positive or negative. They take the form: - -```rust,ignore (partial-example) -impl<...> AutoTrait for StructName<..> { } -impl<...> !AutoTrait for StructName<..> { } -``` - -## Coinduction: Auto traits permit cyclic matching - -Unlike ordinary trait matching, auto traits are **coinductive**. This -means, in short, that cycles which occur in trait matching are -considered ok. As an example, consider the recursive struct `List` -introduced in the previous section. In attempting to determine whether -`List: Send`, we would wind up in a cycle: to apply the impl, we must -show that `Option>: Send`, which will in turn require -`Box: Send` and then finally `List: Send` again. Under ordinary -trait matching, this cycle would be an error, but for an auto trait it -is considered a successful match. - -## Items - -Auto traits cannot have any trait items, such as methods or associated types. This ensures that we can generate default implementations. - -## Supertraits - -Auto traits cannot have supertraits. This is for soundness reasons, as the interaction of coinduction with implied bounds is difficult to reconcile. diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 5a1612e76e306..ea36cb2b72bc3 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2804,7 +2804,7 @@ fn clean_maybe_renamed_item<'tcx>( ItemKind::Fn(ref sig, generics, body_id) => { clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx) } - ItemKind::Trait(_, _, generics, bounds, item_ids) => { + ItemKind::Trait(_, generics, bounds, item_ids) => { let items = item_ids .iter() .map(|ti| clean_trait_item(cx.tcx.hir().trait_item(ti.id), cx)) diff --git a/src/librustdoc/html/render/span_map.rs b/src/librustdoc/html/render/span_map.rs index 5f130f1875aae..7bbfdcd6acf32 100644 --- a/src/librustdoc/html/render/span_map.rs +++ b/src/librustdoc/html/render/span_map.rs @@ -226,7 +226,7 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> { | ItemKind::Enum(_, _) | ItemKind::Struct(_, _) | ItemKind::Union(_, _) - | ItemKind::Trait(_, _, _, _, _) + | ItemKind::Trait(_, _, _, _) | ItemKind::TraitAlias(_, _) => self.extract_info_from_hir_id(item.hir_id()), ItemKind::Impl(_) | ItemKind::Use(_, _) diff --git a/src/tools/clippy/clippy_lints/src/doc.rs b/src/tools/clippy/clippy_lints/src/doc.rs index e789e0da6797a..88043e2960a38 100644 --- a/src/tools/clippy/clippy_lints/src/doc.rs +++ b/src/tools/clippy/clippy_lints/src/doc.rs @@ -314,7 +314,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown { hir::ItemKind::Impl(impl_) => { self.in_trait_impl = impl_.of_trait.is_some(); }, - hir::ItemKind::Trait(_, unsafety, ..) => match (headers.safety, unsafety) { + hir::ItemKind::Trait(unsafety, ..) => match (headers.safety, unsafety) { (false, hir::Unsafety::Unsafe) => span_lint( cx, MISSING_SAFETY_DOC, diff --git a/src/tools/clippy/clippy_lints/src/escape.rs b/src/tools/clippy/clippy_lints/src/escape.rs index dbe3453e7bfa0..634218bc2ae19 100644 --- a/src/tools/clippy/clippy_lints/src/escape.rs +++ b/src/tools/clippy/clippy_lints/src/escape.rs @@ -86,7 +86,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { } // find `self` ty for this trait if relevant - if let ItemKind::Trait(_, _, _, _, items) = item.kind { + if let ItemKind::Trait(_, _, _, items) = item.kind { for trait_item in items { if trait_item.id.owner_id.def_id == fn_def_id { // be sure we have `self` parameter in this function diff --git a/src/tools/clippy/clippy_lints/src/len_zero.rs b/src/tools/clippy/clippy_lints/src/len_zero.rs index c06b35ca0dabf..65f44540f232f 100644 --- a/src/tools/clippy/clippy_lints/src/len_zero.rs +++ b/src/tools/clippy/clippy_lints/src/len_zero.rs @@ -125,7 +125,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero { return; } - if let ItemKind::Trait(_, _, _, _, trait_items) = item.kind { + if let ItemKind::Trait(_, _, _, trait_items) = item.kind { check_trait_items(cx, item, trait_items); } } diff --git a/src/tools/clippy/clippy_lints/src/missing_inline.rs b/src/tools/clippy/clippy_lints/src/missing_inline.rs index 93f6025c71d67..e00b9514f2123 100644 --- a/src/tools/clippy/clippy_lints/src/missing_inline.rs +++ b/src/tools/clippy/clippy_lints/src/missing_inline.rs @@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { let attrs = cx.tcx.hir().attrs(it.hir_id()); check_missing_inline_attrs(cx, attrs, it.span, desc); }, - hir::ItemKind::Trait(ref _is_auto, ref _unsafe, _generics, _bounds, trait_items) => { + hir::ItemKind::Trait(ref _unsafe, _generics, _bounds, trait_items) => { // note: we need to check if the trait is exported so we can't use // `LateLintPass::check_trait_item` here. for tit in trait_items { diff --git a/src/tools/clippy/clippy_lints/src/trait_bounds.rs b/src/tools/clippy/clippy_lints/src/trait_bounds.rs index 6db330dfa617b..fb637c8460f05 100644 --- a/src/tools/clippy/clippy_lints/src/trait_bounds.rs +++ b/src/tools/clippy/clippy_lints/src/trait_bounds.rs @@ -112,7 +112,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds { // special handling for self trait bounds as these are not considered generics // ie. trait Foo: Display {} if let Item { - kind: ItemKind::Trait(_, _, _, bounds, ..), + kind: ItemKind::Trait(_, _, bounds, ..), .. } = item { @@ -135,7 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds { if let Some( Node::Item( Item { - kind: ItemKind::Trait(_, _, _, self_bounds, _), + kind: ItemKind::Trait(_, _, self_bounds, _), .. } ) ) = cx.tcx.hir().get_if_local(*def_id); diff --git a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs index 6be8b8bb91696..ddb88ae5e9013 100644 --- a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs +++ b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs @@ -18,7 +18,7 @@ use rustc_ast::AttrStyle; use rustc_hir::intravisit::FnKind; use rustc_hir::{ Block, BlockCheckMode, Body, Closure, Destination, Expr, ExprKind, FieldDef, FnHeader, HirId, Impl, ImplItem, - ImplItemKind, IsAuto, Item, ItemKind, LoopSource, MatchSource, MutTy, Node, QPath, TraitItem, TraitItemKind, Ty, + ImplItemKind, Item, ItemKind, LoopSource, MatchSource, MutTy, Node, QPath, TraitItem, TraitItemKind, Ty, TyKind, UnOp, UnsafeSource, Unsafety, Variant, VariantData, YieldSource, }; use rustc_lint::{LateContext, LintContext}; @@ -205,12 +205,11 @@ fn item_search_pat(item: &Item<'_>) -> (Pat, Pat) { ItemKind::Struct(VariantData::Struct(..), _) => (Pat::Str("struct"), Pat::Str("}")), ItemKind::Struct(..) => (Pat::Str("struct"), Pat::Str(";")), ItemKind::Union(..) => (Pat::Str("union"), Pat::Str("}")), - ItemKind::Trait(_, Unsafety::Unsafe, ..) + ItemKind::Trait(Unsafety::Unsafe, ..) | ItemKind::Impl(Impl { unsafety: Unsafety::Unsafe, .. }) => (Pat::Str("unsafe"), Pat::Str("}")), - ItemKind::Trait(IsAuto::Yes, ..) => (Pat::Str("auto"), Pat::Str("}")), ItemKind::Trait(..) => (Pat::Str("trait"), Pat::Str("}")), ItemKind::Impl(_) => (Pat::Str("impl"), Pat::Str("}")), _ => return (Pat::Str(""), Pat::Str("")), diff --git a/tests/pretty/auto-trait.rs b/tests/pretty/auto-trait.rs deleted file mode 100644 index c3c47cff5eda9..0000000000000 --- a/tests/pretty/auto-trait.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![feature(auto_traits)] - -// pp-exact - -auto trait MyTrait {} - -unsafe auto trait UnsafeMyTrait {} - -pub fn main() {} diff --git a/tests/run-make/simd-ffi/simd.rs b/tests/run-make/simd-ffi/simd.rs index d11cfd77c5bf9..3e175d7411624 100644 --- a/tests/run-make/simd-ffi/simd.rs +++ b/tests/run-make/simd-ffi/simd.rs @@ -2,9 +2,8 @@ #![crate_type = "lib"] // we can compile to a variety of platforms, because we don't need // cross-compiled standard libraries. -#![feature(no_core, auto_traits)] +#![feature(no_core, repr_simd, simd_ffi, link_llvm_intrinsics, lang_items, rustc_attrs)] #![no_core] -#![feature(repr_simd, simd_ffi, link_llvm_intrinsics, lang_items, rustc_attrs)] #[derive(Copy)] #[repr(simd)] @@ -68,7 +67,8 @@ pub mod marker { } #[lang = "freeze"] -auto trait Freeze {} +#[rustc_auto_trait] +trait Freeze {} #[macro_export] #[rustc_builtin_macro] diff --git a/tests/run-make/target-specs/foo.rs b/tests/run-make/target-specs/foo.rs index 22939e87912c1..d5d6cc3258208 100644 --- a/tests/run-make/target-specs/foo.rs +++ b/tests/run-make/target-specs/foo.rs @@ -1,4 +1,4 @@ -#![feature(lang_items, no_core, auto_traits)] +#![feature(lang_items, no_core, rustc_attrs)] #![no_core] #[lang = "copy"] @@ -8,7 +8,8 @@ trait Copy {} trait Sized {} #[lang = "freeze"] -auto trait Freeze {} +#[rustc_auto_trait] +trait Freeze {} #[lang = "start"] fn start(_main: fn() -> T, _argc: isize, _argv: *const *const u8, _sigpipe: u8) -> isize { diff --git a/tests/rustdoc-json/impls/auto.rs b/tests/rustdoc-json/impls/auto.rs index ace37e5b3dfe3..59ed83f551ade 100644 --- a/tests/rustdoc-json/impls/auto.rs +++ b/tests/rustdoc-json/impls/auto.rs @@ -1,10 +1,11 @@ -#![feature(no_core, auto_traits, lang_items)] +#![feature(no_core, rustc_attrs, lang_items)] #![no_core] #[lang = "sized"] trait Sized {} -pub auto trait Bar {} +#[rustc_auto_trait] +pub trait Bar {} /// has span impl Foo { @@ -12,8 +13,8 @@ impl Foo { } // Testing spans, so all tests below code -// @is "$.index[*][?(@.docs=='has span')].span.begin" "[10, 0]" -// @is "$.index[*][?(@.docs=='has span')].span.end" "[12, 1]" +// @is "$.index[*][?(@.docs=='has span')].span.begin" "[11, 0]" +// @is "$.index[*][?(@.docs=='has span')].span.end" "[13, 1]" // FIXME: this doesn't work due to https://github.com/freestrings/jsonpath/issues/91 // is "$.index[*][?(@.inner.impl.synthetic==true)].span" null pub struct Foo; diff --git a/tests/rustdoc/auto-traits.rs b/tests/rustdoc/auto-traits.rs index 93d4bf2f656a3..155c9270ac911 100644 --- a/tests/rustdoc/auto-traits.rs +++ b/tests/rustdoc/auto-traits.rs @@ -1,13 +1,16 @@ // aux-build:auto-traits.rs -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![crate_name = "foo"] extern crate auto_traits; +// FIXME(auto_traits): Don't render the contextual keyword `auto` but a "text in an outline" // @has 'foo/trait.Foo.html' '//pre' 'pub unsafe auto trait Foo' -pub unsafe auto trait Foo {} +#[rustc_auto_trait] +pub unsafe trait Foo {} +// FIXME(auto_traits): Don't render the contextual keyword `auto` but a "text in an outline" // @has 'foo/trait.Bar.html' '//pre' 'pub unsafe auto trait Bar' pub use auto_traits::Bar; diff --git a/tests/rustdoc/auto_aliases.rs b/tests/rustdoc/auto_aliases.rs index a047c76b637d4..5128e88b05602 100644 --- a/tests/rustdoc/auto_aliases.rs +++ b/tests/rustdoc/auto_aliases.rs @@ -1,6 +1,7 @@ -#![feature(auto_traits)] +#![feature(rustc_attrs)] // @has auto_aliases/trait.Bar.html '//*[@data-aliases="auto_aliases::Foo"]' 'impl Bar for Foo' pub struct Foo; -pub auto trait Bar {} +#[rustc_auto_trait] +pub trait Bar {} diff --git a/tests/rustdoc/auxiliary/auto-traits.rs b/tests/rustdoc/auxiliary/auto-traits.rs index 84976c73beed5..f937da50fb241 100644 --- a/tests/rustdoc/auxiliary/auto-traits.rs +++ b/tests/rustdoc/auxiliary/auto-traits.rs @@ -1,3 +1,4 @@ -#![feature(auto_traits)] +#![feature(rustc_attrs)] -pub unsafe auto trait Bar {} +#[rustc_auto_trait] +pub unsafe trait Bar {} diff --git a/tests/rustdoc/auxiliary/rustdoc-default-impl.rs b/tests/rustdoc/auxiliary/rustdoc-default-impl.rs index 032db3b25e673..28948263e50db 100644 --- a/tests/rustdoc/auxiliary/rustdoc-default-impl.rs +++ b/tests/rustdoc/auxiliary/rustdoc-default-impl.rs @@ -1,9 +1,10 @@ -#![feature(auto_traits)] +#![feature(rustc_attrs)] pub mod bar { use std::marker; - pub auto trait Bar {} + #[rustc_auto_trait] + pub trait Bar {} pub trait Foo { fn foo(&self) {} diff --git a/tests/rustdoc/auxiliary/rustdoc-impl-parts-crosscrate.rs b/tests/rustdoc/auxiliary/rustdoc-impl-parts-crosscrate.rs index 135987fc00d51..6a2f885f6ff6c 100644 --- a/tests/rustdoc/auxiliary/rustdoc-impl-parts-crosscrate.rs +++ b/tests/rustdoc/auxiliary/rustdoc-impl-parts-crosscrate.rs @@ -1,3 +1,4 @@ -#![feature(auto_traits)] +#![feature(rustc_attrs)] -pub auto trait AnAutoTrait {} +#[rustc_auto_trait] +pub trait AnAutoTrait {} diff --git a/tests/rustdoc/impl-parts.rs b/tests/rustdoc/impl-parts.rs index f7738060e993c..8d76ea00657b4 100644 --- a/tests/rustdoc/impl-parts.rs +++ b/tests/rustdoc/impl-parts.rs @@ -1,7 +1,8 @@ #![feature(negative_impls)] -#![feature(auto_traits)] +#![feature(rustc_attrs)] -pub auto trait AnAutoTrait {} +#[rustc_auto_trait] +pub trait AnAutoTrait {} pub struct Foo { field: T } diff --git a/tests/rustdoc/synthetic_auto/crate-local.rs b/tests/rustdoc/synthetic_auto/crate-local.rs index ed01f63f998b9..f36b78c03ddc7 100644 --- a/tests/rustdoc/synthetic_auto/crate-local.rs +++ b/tests/rustdoc/synthetic_auto/crate-local.rs @@ -1,6 +1,7 @@ -#![feature(auto_traits)] +#![feature(rustc_attrs)] -pub auto trait Banana {} +#[rustc_auto_trait] +pub trait Banana {} // @has crate_local/struct.Peach.html // @has - '//h3[@class="code-header"]' 'impl Banana for Peach' diff --git a/tests/ui/associated-inherent-types/dispatch-on-self-type-1.rs b/tests/ui/associated-inherent-types/dispatch-on-self-type-1.rs index 9b0fa8dc6f32c..00dd0d47f94b0 100644 --- a/tests/ui/associated-inherent-types/dispatch-on-self-type-1.rs +++ b/tests/ui/associated-inherent-types/dispatch-on-self-type-1.rs @@ -1,6 +1,6 @@ // check-pass -#![feature(inherent_associated_types, auto_traits, negative_impls)] +#![feature(inherent_associated_types, rustc_attrs, negative_impls)] #![allow(incomplete_features)] use std::cmp::Ordering; @@ -36,4 +36,5 @@ enum Special {} impl !Ordinary for Special {} -auto trait Ordinary {} +#[rustc_auto_trait] +trait Ordinary {} diff --git a/tests/ui/async-await/issue-64130-3-other.rs b/tests/ui/async-await/issue-64130-3-other.rs index 074d67aa3fb87..14756e6d3bd74 100644 --- a/tests/ui/async-await/issue-64130-3-other.rs +++ b/tests/ui/async-await/issue-64130-3-other.rs @@ -1,11 +1,12 @@ -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![feature(negative_impls)] // edition:2018 // This tests the unspecialized async-await-specific error when futures don't implement an // auto trait (which is not Send or Sync) due to some type that was captured. -auto trait Qux {} +#[rustc_auto_trait] +trait Qux {} struct Foo; diff --git a/tests/ui/async-await/issue-64130-3-other.stderr b/tests/ui/async-await/issue-64130-3-other.stderr index 573da1034c573..2b6d38b290239 100644 --- a/tests/ui/async-await/issue-64130-3-other.stderr +++ b/tests/ui/async-await/issue-64130-3-other.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `Foo: Qux` is not satisfied in `impl Future` - --> $DIR/issue-64130-3-other.rs:25:12 + --> $DIR/issue-64130-3-other.rs:26:12 | LL | async fn bar() { | - within this `impl Future` @@ -8,14 +8,14 @@ LL | is_qux(bar()); | ^^^^^ within `impl Future`, the trait `Qux` is not implemented for `Foo` | note: future does not implement `Qux` as this value is used across an await - --> $DIR/issue-64130-3-other.rs:18:11 + --> $DIR/issue-64130-3-other.rs:19:11 | LL | let x = Foo; | - has type `Foo` which does not implement `Qux` LL | baz().await; | ^^^^^ await occurs here, with `x` maybe used later note: required by a bound in `is_qux` - --> $DIR/issue-64130-3-other.rs:14:14 + --> $DIR/issue-64130-3-other.rs:15:14 | LL | fn is_qux(t: T) {} | ^^^ required by this bound in `is_qux` diff --git a/tests/ui/auto-traits/auto-trait-validation.fixed b/tests/ui/auto-traits/auto-trait-validation.fixed index da878ac6222bb..2d002f7783cd4 100644 --- a/tests/ui/auto-traits/auto-trait-validation.fixed +++ b/tests/ui/auto-traits/auto-trait-validation.fixed @@ -1,13 +1,18 @@ -#![feature(auto_traits)] +#![feature(rustc_attrs)] // run-rustfix -auto trait Generic {} +#[rustc_auto_trait] +trait Generic {} //~^ auto traits cannot have generic parameters [E0567] -auto trait Bound {} +#[rustc_auto_trait] +trait Bound {} //~^ auto traits cannot have super traits or lifetime bounds [E0568] -auto trait LifetimeBound {} +#[rustc_auto_trait] +trait LifetimeBound {} //~^ auto traits cannot have super traits or lifetime bounds [E0568] -auto trait MyTrait { } +#[rustc_auto_trait] +trait MyTrait { } //~^ auto traits cannot have associated items [E0380] + fn main() {} diff --git a/tests/ui/auto-traits/auto-trait-validation.rs b/tests/ui/auto-traits/auto-trait-validation.rs index d43055e270bd5..6a8892df90063 100644 --- a/tests/ui/auto-traits/auto-trait-validation.rs +++ b/tests/ui/auto-traits/auto-trait-validation.rs @@ -1,13 +1,18 @@ -#![feature(auto_traits)] +#![feature(rustc_attrs)] // run-rustfix -auto trait Generic {} +#[rustc_auto_trait] +trait Generic {} //~^ auto traits cannot have generic parameters [E0567] -auto trait Bound : Copy {} +#[rustc_auto_trait] +trait Bound : Copy {} //~^ auto traits cannot have super traits or lifetime bounds [E0568] -auto trait LifetimeBound : 'static {} +#[rustc_auto_trait] +trait LifetimeBound : 'static {} //~^ auto traits cannot have super traits or lifetime bounds [E0568] -auto trait MyTrait { fn foo() {} } +#[rustc_auto_trait] +trait MyTrait { fn foo() {} } //~^ auto traits cannot have associated items [E0380] + fn main() {} diff --git a/tests/ui/auto-traits/auto-trait-validation.stderr b/tests/ui/auto-traits/auto-trait-validation.stderr index 89b63d23d4c8e..166864e3ad166 100644 --- a/tests/ui/auto-traits/auto-trait-validation.stderr +++ b/tests/ui/auto-traits/auto-trait-validation.stderr @@ -1,35 +1,35 @@ error[E0567]: auto traits cannot have generic parameters - --> $DIR/auto-trait-validation.rs:5:19 + --> $DIR/auto-trait-validation.rs:6:14 | -LL | auto trait Generic {} - | -------^^^ help: remove the parameters - | | - | auto trait cannot have generic parameters +LL | trait Generic {} + | -------^^^ help: remove the parameters + | | + | auto trait cannot have generic parameters error[E0568]: auto traits cannot have super traits or lifetime bounds - --> $DIR/auto-trait-validation.rs:7:17 + --> $DIR/auto-trait-validation.rs:9:12 | -LL | auto trait Bound : Copy {} - | -----^^^^^^^ help: remove the super traits or lifetime bounds - | | - | auto traits cannot have super traits or lifetime bounds +LL | trait Bound : Copy {} + | -----^^^^^^^ help: remove the super traits or lifetime bounds + | | + | auto traits cannot have super traits or lifetime bounds error[E0568]: auto traits cannot have super traits or lifetime bounds - --> $DIR/auto-trait-validation.rs:9:25 + --> $DIR/auto-trait-validation.rs:12:20 | -LL | auto trait LifetimeBound : 'static {} - | -------------^^^^^^^^^^ help: remove the super traits or lifetime bounds - | | - | auto traits cannot have super traits or lifetime bounds +LL | trait LifetimeBound : 'static {} + | -------------^^^^^^^^^^ help: remove the super traits or lifetime bounds + | | + | auto traits cannot have super traits or lifetime bounds error[E0380]: auto traits cannot have associated items - --> $DIR/auto-trait-validation.rs:11:25 + --> $DIR/auto-trait-validation.rs:15:20 | -LL | auto trait MyTrait { fn foo() {} } - | ------- ---^^^----- - | | | - | | help: remove these associated items - | auto traits cannot have associated items +LL | trait MyTrait { fn foo() {} } + | ------- ---^^^----- + | | | + | | help: remove these associated items + | auto traits cannot have associated items error: aborting due to 4 previous errors diff --git a/tests/ui/auto-traits/auto-traits.rs b/tests/ui/auto-traits/auto-traits.rs index 7b52d9c176e88..21cd0c7c75953 100644 --- a/tests/ui/auto-traits/auto-traits.rs +++ b/tests/ui/auto-traits/auto-traits.rs @@ -1,10 +1,12 @@ // run-pass #![allow(unused_doc_comments)] -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![feature(negative_impls)] -auto trait Auto {} -unsafe auto trait AutoUnsafe {} +#[rustc_auto_trait] +trait Auto {} +#[rustc_auto_trait] +unsafe trait AutoUnsafe {} impl !Auto for bool {} impl !AutoUnsafe for bool {} @@ -19,8 +21,10 @@ fn take_auto_unsafe(_: T) {} fn main() { // Parse inside functions. - auto trait AutoInner {} - unsafe auto trait AutoUnsafeInner {} + #[rustc_auto_trait] + trait AutoInner {} + #[rustc_auto_trait] + unsafe trait AutoUnsafeInner {} take_auto(0); take_auto(AutoBool(true)); diff --git a/tests/ui/auto-traits/bad-generics-on-dyn.rs b/tests/ui/auto-traits/bad-generics-on-dyn.rs index 3f8ac14c72d95..d62cd3894cc2c 100644 --- a/tests/ui/auto-traits/bad-generics-on-dyn.rs +++ b/tests/ui/auto-traits/bad-generics-on-dyn.rs @@ -1,6 +1,7 @@ -#![feature(auto_traits)] +#![feature(rustc_attrs)] -auto trait Trait1<'a> {} +#[rustc_auto_trait] +trait Trait1<'a> {} //~^ ERROR auto traits cannot have generic parameters fn f<'a>(x: &dyn Trait1<'a>) diff --git a/tests/ui/auto-traits/bad-generics-on-dyn.stderr b/tests/ui/auto-traits/bad-generics-on-dyn.stderr index ade69ced6060d..40460c9a91314 100644 --- a/tests/ui/auto-traits/bad-generics-on-dyn.stderr +++ b/tests/ui/auto-traits/bad-generics-on-dyn.stderr @@ -1,10 +1,10 @@ error[E0567]: auto traits cannot have generic parameters - --> $DIR/bad-generics-on-dyn.rs:3:18 + --> $DIR/bad-generics-on-dyn.rs:4:13 | -LL | auto trait Trait1<'a> {} - | ------^^^^ help: remove the parameters - | | - | auto trait cannot have generic parameters +LL | trait Trait1<'a> {} + | ------^^^^ help: remove the parameters + | | + | auto trait cannot have generic parameters error: aborting due to previous error diff --git a/tests/ui/auto-traits/feature-gate.rs b/tests/ui/auto-traits/feature-gate.rs new file mode 100644 index 0000000000000..a9ddc73c73c22 --- /dev/null +++ b/tests/ui/auto-traits/feature-gate.rs @@ -0,0 +1,7 @@ +// Test that auto traits are gated by the `rustc_attrs` feature gate. + +#[rustc_auto_trait] +//~^ ERROR `#[rustc_auto_trait]` is used to mark auto traits, only intended to be used in `core` +trait AutoDummyTrait {} + +fn main() {} diff --git a/tests/ui/auto-traits/feature-gate.stderr b/tests/ui/auto-traits/feature-gate.stderr new file mode 100644 index 0000000000000..b97a67e240b61 --- /dev/null +++ b/tests/ui/auto-traits/feature-gate.stderr @@ -0,0 +1,11 @@ +error[E0658]: `#[rustc_auto_trait]` is used to mark auto traits, only intended to be used in `core` + --> $DIR/feature-gate.rs:3:1 + | +LL | #[rustc_auto_trait] + | ^^^^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(rustc_attrs)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/auto-traits/issue-23080-2.current.stderr b/tests/ui/auto-traits/issue-23080-2.current.stderr index a57c6d9b0cbf9..6a380db7e61f5 100644 --- a/tests/ui/auto-traits/issue-23080-2.current.stderr +++ b/tests/ui/auto-traits/issue-23080-2.current.stderr @@ -1,8 +1,8 @@ error[E0380]: auto traits cannot have associated items - --> $DIR/issue-23080-2.rs:8:10 + --> $DIR/issue-23080-2.rs:9:10 | -LL | unsafe auto trait Trait { - | ----- auto traits cannot have associated items +LL | unsafe trait Trait { + | ----- auto traits cannot have associated items LL | type Output; | -----^^^^^^- help: remove these associated items diff --git a/tests/ui/auto-traits/issue-23080-2.next.stderr b/tests/ui/auto-traits/issue-23080-2.next.stderr index a57c6d9b0cbf9..6a380db7e61f5 100644 --- a/tests/ui/auto-traits/issue-23080-2.next.stderr +++ b/tests/ui/auto-traits/issue-23080-2.next.stderr @@ -1,8 +1,8 @@ error[E0380]: auto traits cannot have associated items - --> $DIR/issue-23080-2.rs:8:10 + --> $DIR/issue-23080-2.rs:9:10 | -LL | unsafe auto trait Trait { - | ----- auto traits cannot have associated items +LL | unsafe trait Trait { + | ----- auto traits cannot have associated items LL | type Output; | -----^^^^^^- help: remove these associated items diff --git a/tests/ui/auto-traits/issue-23080-2.rs b/tests/ui/auto-traits/issue-23080-2.rs index 882b8f3938428..2bb34b2cdd77f 100644 --- a/tests/ui/auto-traits/issue-23080-2.rs +++ b/tests/ui/auto-traits/issue-23080-2.rs @@ -1,10 +1,11 @@ // revisions: current next //[next] compile-flags: -Ztrait-solver=next -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![feature(negative_impls)] -unsafe auto trait Trait { +#[rustc_auto_trait] +unsafe trait Trait { type Output; //~ ERROR E0380 } diff --git a/tests/ui/auto-traits/issue-23080.rs b/tests/ui/auto-traits/issue-23080.rs index 84e2ce66f9dbd..a0fd8148f8407 100644 --- a/tests/ui/auto-traits/issue-23080.rs +++ b/tests/ui/auto-traits/issue-23080.rs @@ -1,7 +1,8 @@ -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![feature(negative_impls)] -unsafe auto trait Trait { +#[rustc_auto_trait] +unsafe trait Trait { fn method(&self) { //~ ERROR E0380 println!("Hello"); } diff --git a/tests/ui/auto-traits/issue-23080.stderr b/tests/ui/auto-traits/issue-23080.stderr index f5d607298b797..677920d55b963 100644 --- a/tests/ui/auto-traits/issue-23080.stderr +++ b/tests/ui/auto-traits/issue-23080.stderr @@ -1,8 +1,8 @@ error[E0380]: auto traits cannot have associated items - --> $DIR/issue-23080.rs:5:8 + --> $DIR/issue-23080.rs:6:8 | -LL | unsafe auto trait Trait { - | ----- auto traits cannot have associated items +LL | unsafe trait Trait { + | ----- auto traits cannot have associated items LL | fn method(&self) { | _____- ^^^^^^ LL | | println!("Hello"); diff --git a/tests/ui/auto-traits/issue-84075.rs b/tests/ui/auto-traits/issue-84075.rs index a6afe24ea4c8b..0d5a848ff4729 100644 --- a/tests/ui/auto-traits/issue-84075.rs +++ b/tests/ui/auto-traits/issue-84075.rs @@ -1,8 +1,9 @@ // Regression test for issue #84075. -#![feature(auto_traits)] +#![feature(rustc_attrs)] -auto trait Magic where Self: Copy {} //~ ERROR E0568 +#[rustc_auto_trait] +trait Magic where Self: Copy {} //~ ERROR E0568 impl Magic for T {} fn copy(x: T) -> (T, T) { (x, x) } diff --git a/tests/ui/auto-traits/issue-84075.stderr b/tests/ui/auto-traits/issue-84075.stderr index 6fbdc669b6ffb..40c24211177fc 100644 --- a/tests/ui/auto-traits/issue-84075.stderr +++ b/tests/ui/auto-traits/issue-84075.stderr @@ -1,10 +1,10 @@ error[E0568]: auto traits cannot have super traits or lifetime bounds - --> $DIR/issue-84075.rs:5:18 + --> $DIR/issue-84075.rs:6:13 | -LL | auto trait Magic where Self: Copy {} - | ----- ^^^^^^^^^^^^^^^^ help: remove the super traits or lifetime bounds - | | - | auto traits cannot have super traits or lifetime bounds +LL | trait Magic where Self: Copy {} + | ----- ^^^^^^^^^^^^^^^^ help: remove the super traits or lifetime bounds + | | + | auto traits cannot have super traits or lifetime bounds error: aborting due to previous error diff --git a/tests/ui/auto-traits/str-contains-slice-conceptually.rs b/tests/ui/auto-traits/str-contains-slice-conceptually.rs index 6a16fdcf2842f..08e3c80e7eae5 100644 --- a/tests/ui/auto-traits/str-contains-slice-conceptually.rs +++ b/tests/ui/auto-traits/str-contains-slice-conceptually.rs @@ -1,7 +1,8 @@ #![feature(negative_impls)] -#![feature(auto_traits)] +#![feature(rustc_attrs)] -auto trait AutoTrait {} +#[rustc_auto_trait] +trait AutoTrait {} impl !AutoTrait for [T] {} diff --git a/tests/ui/auto-traits/str-contains-slice-conceptually.stderr b/tests/ui/auto-traits/str-contains-slice-conceptually.stderr index 1cf16cebddd15..bf96300d213e2 100644 --- a/tests/ui/auto-traits/str-contains-slice-conceptually.stderr +++ b/tests/ui/auto-traits/str-contains-slice-conceptually.stderr @@ -1,12 +1,12 @@ error[E0277]: the trait bound `[u8]: AutoTrait` is not satisfied in `str` - --> $DIR/str-contains-slice-conceptually.rs:11:22 + --> $DIR/str-contains-slice-conceptually.rs:12:22 | LL | needs_auto_trait::(); | ^^^ within `str`, the trait `AutoTrait` is not implemented for `[u8]` | = note: `str` is considered to contain a `[u8]` slice for auto trait purposes note: required by a bound in `needs_auto_trait` - --> $DIR/str-contains-slice-conceptually.rs:8:24 + --> $DIR/str-contains-slice-conceptually.rs:9:24 | LL | fn needs_auto_trait() {} | ^^^^^^^^^ required by this bound in `needs_auto_trait` diff --git a/tests/ui/auto-traits/typeck-auto-trait-no-supertraits-2.rs b/tests/ui/auto-traits/typeck-auto-trait-no-supertraits-2.rs index 98359ef51b764..219fd020c0424 100644 --- a/tests/ui/auto-traits/typeck-auto-trait-no-supertraits-2.rs +++ b/tests/ui/auto-traits/typeck-auto-trait-no-supertraits-2.rs @@ -1,9 +1,10 @@ -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![feature(negative_impls)] -auto trait Magic : Sized where Option : Magic {} //~ ERROR E0568 +#[rustc_auto_trait] +trait Magic : Sized where Option : Magic {} //~ ERROR E0568 //~^ ERROR E0568 -impl Magic for T {} +impl Magic for T {} fn copy(x: T) -> (T, T) { (x, x) } diff --git a/tests/ui/auto-traits/typeck-auto-trait-no-supertraits-2.stderr b/tests/ui/auto-traits/typeck-auto-trait-no-supertraits-2.stderr index 547b4bb54489d..71d7c3ca686ad 100644 --- a/tests/ui/auto-traits/typeck-auto-trait-no-supertraits-2.stderr +++ b/tests/ui/auto-traits/typeck-auto-trait-no-supertraits-2.stderr @@ -1,18 +1,18 @@ error[E0568]: auto traits cannot have super traits or lifetime bounds - --> $DIR/typeck-auto-trait-no-supertraits-2.rs:4:17 + --> $DIR/typeck-auto-trait-no-supertraits-2.rs:5:12 | -LL | auto trait Magic : Sized where Option : Magic {} - | -----^^^^^^^^ help: remove the super traits or lifetime bounds - | | - | auto traits cannot have super traits or lifetime bounds +LL | trait Magic : Sized where Option : Magic {} + | -----^^^^^^^^ help: remove the super traits or lifetime bounds + | | + | auto traits cannot have super traits or lifetime bounds error[E0568]: auto traits cannot have super traits or lifetime bounds - --> $DIR/typeck-auto-trait-no-supertraits-2.rs:4:26 + --> $DIR/typeck-auto-trait-no-supertraits-2.rs:5:21 | -LL | auto trait Magic : Sized where Option : Magic {} - | ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the super traits or lifetime bounds - | | - | auto traits cannot have super traits or lifetime bounds +LL | trait Magic : Sized where Option : Magic {} + | ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the super traits or lifetime bounds + | | + | auto traits cannot have super traits or lifetime bounds error: aborting due to 2 previous errors diff --git a/tests/ui/auto-traits/typeck-auto-trait-no-supertraits.rs b/tests/ui/auto-traits/typeck-auto-trait-no-supertraits.rs index 2a76893febc79..d18cb18f3fcee 100644 --- a/tests/ui/auto-traits/typeck-auto-trait-no-supertraits.rs +++ b/tests/ui/auto-traits/typeck-auto-trait-no-supertraits.rs @@ -22,11 +22,12 @@ // println!("{:?} {:?}", a, b); // } -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![feature(negative_impls)] -auto trait Magic: Copy {} //~ ERROR E0568 -impl Magic for T {} +#[rustc_auto_trait] +trait Magic: Copy {} //~ ERROR E0568 +impl Magic for T {} fn copy(x: T) -> (T, T) { (x, x) } diff --git a/tests/ui/auto-traits/typeck-auto-trait-no-supertraits.stderr b/tests/ui/auto-traits/typeck-auto-trait-no-supertraits.stderr index 80f0741038127..9a1eeff03ade3 100644 --- a/tests/ui/auto-traits/typeck-auto-trait-no-supertraits.stderr +++ b/tests/ui/auto-traits/typeck-auto-trait-no-supertraits.stderr @@ -1,10 +1,10 @@ error[E0568]: auto traits cannot have super traits or lifetime bounds - --> $DIR/typeck-auto-trait-no-supertraits.rs:28:17 + --> $DIR/typeck-auto-trait-no-supertraits.rs:29:12 | -LL | auto trait Magic: Copy {} - | -----^^^^^^ help: remove the super traits or lifetime bounds - | | - | auto traits cannot have super traits or lifetime bounds +LL | trait Magic: Copy {} + | -----^^^^^^ help: remove the super traits or lifetime bounds + | | + | auto traits cannot have super traits or lifetime bounds error: aborting due to previous error diff --git a/tests/ui/auto-traits/typeck-default-trait-impl-constituent-types-2.rs b/tests/ui/auto-traits/typeck-default-trait-impl-constituent-types-2.rs index f2fb67f1108f9..f2752f10bbf0d 100644 --- a/tests/ui/auto-traits/typeck-default-trait-impl-constituent-types-2.rs +++ b/tests/ui/auto-traits/typeck-default-trait-impl-constituent-types-2.rs @@ -1,7 +1,8 @@ -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![feature(negative_impls)] -auto trait MyTrait {} +#[rustc_auto_trait] +trait MyTrait {} struct MyS; diff --git a/tests/ui/auto-traits/typeck-default-trait-impl-constituent-types-2.stderr b/tests/ui/auto-traits/typeck-default-trait-impl-constituent-types-2.stderr index 0c4970a72591f..3979c4c7ff75f 100644 --- a/tests/ui/auto-traits/typeck-default-trait-impl-constituent-types-2.stderr +++ b/tests/ui/auto-traits/typeck-default-trait-impl-constituent-types-2.stderr @@ -1,12 +1,12 @@ error[E0277]: the trait bound `MyS2: MyTrait` is not satisfied in `(MyS2, MyS)` - --> $DIR/typeck-default-trait-impl-constituent-types-2.rs:17:18 + --> $DIR/typeck-default-trait-impl-constituent-types-2.rs:18:18 | LL | is_mytrait::<(MyS2, MyS)>(); | ^^^^^^^^^^^ within `(MyS2, MyS)`, the trait `MyTrait` is not implemented for `MyS2` | = note: required because it appears within the type `(MyS2, MyS)` note: required by a bound in `is_mytrait` - --> $DIR/typeck-default-trait-impl-constituent-types-2.rs:12:18 + --> $DIR/typeck-default-trait-impl-constituent-types-2.rs:13:18 | LL | fn is_mytrait() {} | ^^^^^^^ required by this bound in `is_mytrait` diff --git a/tests/ui/auto-traits/typeck-default-trait-impl-constituent-types.rs b/tests/ui/auto-traits/typeck-default-trait-impl-constituent-types.rs index 73ff46d05e466..acf454935dcb8 100644 --- a/tests/ui/auto-traits/typeck-default-trait-impl-constituent-types.rs +++ b/tests/ui/auto-traits/typeck-default-trait-impl-constituent-types.rs @@ -1,7 +1,8 @@ -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![feature(negative_impls)] -auto trait MyTrait {} +#[rustc_auto_trait] +trait MyTrait {} impl !MyTrait for *mut T {} diff --git a/tests/ui/auto-traits/typeck-default-trait-impl-constituent-types.stderr b/tests/ui/auto-traits/typeck-default-trait-impl-constituent-types.stderr index c575c485a85f7..2d34e05b5337e 100644 --- a/tests/ui/auto-traits/typeck-default-trait-impl-constituent-types.stderr +++ b/tests/ui/auto-traits/typeck-default-trait-impl-constituent-types.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `MyS2: MyTrait` is not satisfied - --> $DIR/typeck-default-trait-impl-constituent-types.rs:21:18 + --> $DIR/typeck-default-trait-impl-constituent-types.rs:22:18 | LL | is_mytrait::(); | ^^^^ the trait `MyTrait` is not implemented for `MyS2` | note: required by a bound in `is_mytrait` - --> $DIR/typeck-default-trait-impl-constituent-types.rs:16:18 + --> $DIR/typeck-default-trait-impl-constituent-types.rs:17:18 | LL | fn is_mytrait() {} | ^^^^^^^ required by this bound in `is_mytrait` diff --git a/tests/ui/auto-traits/typeck-default-trait-impl-negation.rs b/tests/ui/auto-traits/typeck-default-trait-impl-negation.rs index f7f56f97f614e..3ceb8a80863b8 100644 --- a/tests/ui/auto-traits/typeck-default-trait-impl-negation.rs +++ b/tests/ui/auto-traits/typeck-default-trait-impl-negation.rs @@ -1,9 +1,11 @@ -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![feature(negative_impls)] -auto trait MyTrait {} +#[rustc_auto_trait] +trait MyTrait {} -unsafe auto trait MyUnsafeTrait {} +#[rustc_auto_trait] +unsafe trait MyUnsafeTrait {} struct ThisImplsTrait; diff --git a/tests/ui/auto-traits/typeck-default-trait-impl-negation.stderr b/tests/ui/auto-traits/typeck-default-trait-impl-negation.stderr index fa8dd41da237b..90b300ad68f3f 100644 --- a/tests/ui/auto-traits/typeck-default-trait-impl-negation.stderr +++ b/tests/ui/auto-traits/typeck-default-trait-impl-negation.stderr @@ -1,23 +1,23 @@ error[E0277]: the trait bound `ThisImplsUnsafeTrait: MyTrait` is not satisfied - --> $DIR/typeck-default-trait-impl-negation.rs:22:19 + --> $DIR/typeck-default-trait-impl-negation.rs:24:19 | LL | is_my_trait::(); | ^^^^^^^^^^^^^^^^^^^^ the trait `MyTrait` is not implemented for `ThisImplsUnsafeTrait` | note: required by a bound in `is_my_trait` - --> $DIR/typeck-default-trait-impl-negation.rs:17:19 + --> $DIR/typeck-default-trait-impl-negation.rs:19:19 | LL | fn is_my_trait() {} | ^^^^^^^ required by this bound in `is_my_trait` error[E0277]: the trait bound `ThisImplsTrait: MyUnsafeTrait` is not satisfied - --> $DIR/typeck-default-trait-impl-negation.rs:25:26 + --> $DIR/typeck-default-trait-impl-negation.rs:27:26 | LL | is_my_unsafe_trait::(); | ^^^^^^^^^^^^^^ the trait `MyUnsafeTrait` is not implemented for `ThisImplsTrait` | note: required by a bound in `is_my_unsafe_trait` - --> $DIR/typeck-default-trait-impl-negation.rs:18:26 + --> $DIR/typeck-default-trait-impl-negation.rs:20:26 | LL | fn is_my_unsafe_trait() {} | ^^^^^^^^^^^^^ required by this bound in `is_my_unsafe_trait` diff --git a/tests/ui/auto-traits/typeck-default-trait-impl-precedence.rs b/tests/ui/auto-traits/typeck-default-trait-impl-precedence.rs index 2bbe82270bd06..0226b855c174a 100644 --- a/tests/ui/auto-traits/typeck-default-trait-impl-precedence.rs +++ b/tests/ui/auto-traits/typeck-default-trait-impl-precedence.rs @@ -3,10 +3,11 @@ // other words, the auto impl only applies if there are no existing // impls whose types unify. -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![feature(negative_impls)] -auto trait Defaulted { } +#[rustc_auto_trait] +trait Defaulted { } impl<'a,T:Signed> Defaulted for &'a T { } impl<'a,T:Signed> Defaulted for &'a mut T { } fn is_defaulted() { } diff --git a/tests/ui/auto-traits/typeck-default-trait-impl-precedence.stderr b/tests/ui/auto-traits/typeck-default-trait-impl-precedence.stderr index bd7aaf6fb6dfc..00066e41d0829 100644 --- a/tests/ui/auto-traits/typeck-default-trait-impl-precedence.stderr +++ b/tests/ui/auto-traits/typeck-default-trait-impl-precedence.stderr @@ -1,18 +1,18 @@ error[E0277]: the trait bound `u32: Signed` is not satisfied - --> $DIR/typeck-default-trait-impl-precedence.rs:19:20 + --> $DIR/typeck-default-trait-impl-precedence.rs:20:20 | LL | is_defaulted::<&'static u32>(); | ^^^^^^^^^^^^ the trait `Signed` is not implemented for `u32` | note: required for `&'static u32` to implement `Defaulted` - --> $DIR/typeck-default-trait-impl-precedence.rs:10:19 + --> $DIR/typeck-default-trait-impl-precedence.rs:11:19 | LL | impl<'a,T:Signed> Defaulted for &'a T { } | ------ ^^^^^^^^^ ^^^^^ | | | unsatisfied trait bound introduced here note: required by a bound in `is_defaulted` - --> $DIR/typeck-default-trait-impl-precedence.rs:12:19 + --> $DIR/typeck-default-trait-impl-precedence.rs:13:19 | LL | fn is_defaulted() { } | ^^^^^^^^^ required by this bound in `is_defaulted` diff --git a/tests/ui/check-cfg/values-target-json.rs b/tests/ui/check-cfg/values-target-json.rs index 2ef5a44592b81..e815be770e408 100644 --- a/tests/ui/check-cfg/values-target-json.rs +++ b/tests/ui/check-cfg/values-target-json.rs @@ -4,7 +4,7 @@ // needs-llvm-components: x86 // compile-flags: --crate-type=lib --check-cfg=values() --target={{src-base}}/check-cfg/my-awesome-platform.json -Z unstable-options -#![feature(lang_items, no_core, auto_traits)] +#![feature(lang_items, no_core, rustc_attrs)] #![no_core] #[lang = "sized"] diff --git a/tests/ui/coherence/coherence-default-trait-impl.rs b/tests/ui/coherence/coherence-default-trait-impl.rs index d57fb47775403..2972d20bc6ab9 100644 --- a/tests/ui/coherence/coherence-default-trait-impl.rs +++ b/tests/ui/coherence/coherence-default-trait-impl.rs @@ -1,14 +1,16 @@ -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![feature(negative_impls)] -auto trait MySafeTrait {} +#[rustc_auto_trait] +trait MySafeTrait {} struct Foo; unsafe impl MySafeTrait for Foo {} //~^ ERROR E0199 -unsafe auto trait MyUnsafeTrait {} +#[rustc_auto_trait] +unsafe trait MyUnsafeTrait {} impl MyUnsafeTrait for Foo {} //~^ ERROR E0200 diff --git a/tests/ui/coherence/coherence-default-trait-impl.stderr b/tests/ui/coherence/coherence-default-trait-impl.stderr index 7be5b92a7def0..452bdeb7aadaa 100644 --- a/tests/ui/coherence/coherence-default-trait-impl.stderr +++ b/tests/ui/coherence/coherence-default-trait-impl.stderr @@ -1,5 +1,5 @@ error[E0199]: implementing the trait `MySafeTrait` is not unsafe - --> $DIR/coherence-default-trait-impl.rs:8:1 + --> $DIR/coherence-default-trait-impl.rs:9:1 | LL | unsafe impl MySafeTrait for Foo {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -11,7 +11,7 @@ LL + impl MySafeTrait for Foo {} | error[E0200]: the trait `MyUnsafeTrait` requires an `unsafe impl` declaration - --> $DIR/coherence-default-trait-impl.rs:13:1 + --> $DIR/coherence-default-trait-impl.rs:15:1 | LL | impl MyUnsafeTrait for Foo {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/coherence/coherence-impl-trait-for-marker-trait-negative.rs b/tests/ui/coherence/coherence-impl-trait-for-marker-trait-negative.rs index 98f1558b7ffe1..137d152372443 100644 --- a/tests/ui/coherence/coherence-impl-trait-for-marker-trait-negative.rs +++ b/tests/ui/coherence/coherence-impl-trait-for-marker-trait-negative.rs @@ -1,4 +1,4 @@ -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![feature(negative_impls)] // Test for issue #56934 - that it is impossible to redundantly @@ -6,8 +6,10 @@ // Negative impl variant. -auto trait Marker1 {} -auto trait Marker2 {} +#[rustc_auto_trait] +trait Marker1 {} +#[rustc_auto_trait] +trait Marker2 {} trait Object: Marker1 {} @@ -28,10 +30,12 @@ impl !Send for dyn Object {} //~ ERROR E0321 impl !Send for dyn Object + Marker2 {} //~ ERROR E0321 // Blanket impl that applies to dyn Object is equally problematic. -auto trait Marker3 {} +#[rustc_auto_trait] +trait Marker3 {} impl !Marker3 for T {} //~ ERROR E0321 -auto trait Marker4 {} +#[rustc_auto_trait] +trait Marker4 {} impl !Marker4 for T {} // okay fn main() {} diff --git a/tests/ui/coherence/coherence-impl-trait-for-marker-trait-negative.stderr b/tests/ui/coherence/coherence-impl-trait-for-marker-trait-negative.stderr index ea38afc40ce80..64ea26e3b8784 100644 --- a/tests/ui/coherence/coherence-impl-trait-for-marker-trait-negative.stderr +++ b/tests/ui/coherence/coherence-impl-trait-for-marker-trait-negative.stderr @@ -1,11 +1,11 @@ error[E0371]: the object type `(dyn Object + Marker2 + 'static)` automatically implements the trait `Marker1` - --> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:15:1 + --> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:17:1 | LL | impl !Marker1 for dyn Object + Marker2 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn Object + Marker2 + 'static)` automatically implements trait `Marker1` error[E0321]: traits with a default impl, like `Marker1`, cannot be implemented for trait object `(dyn Object + Marker2 + 'static)` - --> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:15:1 + --> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:17:1 | LL | impl !Marker1 for dyn Object + Marker2 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,13 +13,13 @@ LL | impl !Marker1 for dyn Object + Marker2 {} = note: a trait object implements `Marker1` if and only if `Marker1` is one of the trait object's trait bounds error[E0371]: the object type `(dyn Object + Marker2 + 'static)` automatically implements the trait `Marker2` - --> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:18:1 + --> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:20:1 | LL | impl !Marker2 for dyn Object + Marker2 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn Object + Marker2 + 'static)` automatically implements trait `Marker2` error[E0321]: traits with a default impl, like `Marker2`, cannot be implemented for trait object `(dyn Object + Marker2 + 'static)` - --> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:18:1 + --> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:20:1 | LL | impl !Marker2 for dyn Object + Marker2 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -27,7 +27,7 @@ LL | impl !Marker2 for dyn Object + Marker2 {} = note: a trait object implements `Marker2` if and only if `Marker2` is one of the trait object's trait bounds error[E0321]: traits with a default impl, like `Marker2`, cannot be implemented for trait object `(dyn Object + 'static)` - --> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:26:1 + --> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:28:1 | LL | impl !Marker2 for dyn Object {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -35,7 +35,7 @@ LL | impl !Marker2 for dyn Object {} = note: a trait object implements `Marker2` if and only if `Marker2` is one of the trait object's trait bounds error[E0117]: only traits defined in the current crate can be implemented for arbitrary types - --> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:22:1 + --> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:24:1 | LL | impl !Send for dyn Marker2 {} | ^^^^^^^^^^^^^^^----------- @@ -46,19 +46,19 @@ LL | impl !Send for dyn Marker2 {} = note: define and implement a trait or new type instead error[E0321]: cross-crate traits with a default impl, like `Send`, can only be implemented for a struct/enum type, not `(dyn Object + 'static)` - --> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:27:1 + --> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:29:1 | LL | impl !Send for dyn Object {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait with a default impl for non-struct/enum type error[E0321]: cross-crate traits with a default impl, like `Send`, can only be implemented for a struct/enum type, not `(dyn Object + Marker2 + 'static)` - --> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:28:1 + --> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:30:1 | LL | impl !Send for dyn Object + Marker2 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait with a default impl for non-struct/enum type error[E0321]: traits with a default impl, like `Marker3`, cannot be implemented for generic type `T` - --> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:32:1 + --> $DIR/coherence-impl-trait-for-marker-trait-negative.rs:35:1 | LL | impl !Marker3 for T {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/coherence/coherence-impl-trait-for-marker-trait-positive.rs b/tests/ui/coherence/coherence-impl-trait-for-marker-trait-positive.rs index db2e2b4509a2a..257ba9a9a7f18 100644 --- a/tests/ui/coherence/coherence-impl-trait-for-marker-trait-positive.rs +++ b/tests/ui/coherence/coherence-impl-trait-for-marker-trait-positive.rs @@ -1,4 +1,4 @@ -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![feature(negative_impls)] // Test for issue #56934 - that it is impossible to redundantly @@ -6,8 +6,10 @@ // Positive impl variant. -auto trait Marker1 {} -auto trait Marker2 {} +#[rustc_auto_trait] +trait Marker1 {} +#[rustc_auto_trait] +trait Marker2 {} trait Object: Marker1 {} @@ -28,10 +30,12 @@ unsafe impl Send for dyn Object {} //~ ERROR E0321 unsafe impl Send for dyn Object + Marker2 {} //~ ERROR E0321 // Blanket impl that applies to dyn Object is equally problematic. -auto trait Marker3 {} +#[rustc_auto_trait] +trait Marker3 {} impl Marker3 for T {} //~ ERROR E0321 -auto trait Marker4 {} +#[rustc_auto_trait] +trait Marker4 {} impl Marker4 for T {} // okay fn main() {} diff --git a/tests/ui/coherence/coherence-impl-trait-for-marker-trait-positive.stderr b/tests/ui/coherence/coherence-impl-trait-for-marker-trait-positive.stderr index 2a8713bc32794..f4572e04244b4 100644 --- a/tests/ui/coherence/coherence-impl-trait-for-marker-trait-positive.stderr +++ b/tests/ui/coherence/coherence-impl-trait-for-marker-trait-positive.stderr @@ -1,11 +1,11 @@ error[E0371]: the object type `(dyn Object + Marker2 + 'static)` automatically implements the trait `Marker1` - --> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:15:1 + --> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:17:1 | LL | impl Marker1 for dyn Object + Marker2 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn Object + Marker2 + 'static)` automatically implements trait `Marker1` error[E0321]: traits with a default impl, like `Marker1`, cannot be implemented for trait object `(dyn Object + Marker2 + 'static)` - --> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:15:1 + --> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:17:1 | LL | impl Marker1 for dyn Object + Marker2 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,13 +13,13 @@ LL | impl Marker1 for dyn Object + Marker2 {} = note: a trait object implements `Marker1` if and only if `Marker1` is one of the trait object's trait bounds error[E0371]: the object type `(dyn Object + Marker2 + 'static)` automatically implements the trait `Marker2` - --> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:18:1 + --> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:20:1 | LL | impl Marker2 for dyn Object + Marker2 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn Object + Marker2 + 'static)` automatically implements trait `Marker2` error[E0321]: traits with a default impl, like `Marker2`, cannot be implemented for trait object `(dyn Object + Marker2 + 'static)` - --> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:18:1 + --> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:20:1 | LL | impl Marker2 for dyn Object + Marker2 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -27,7 +27,7 @@ LL | impl Marker2 for dyn Object + Marker2 {} = note: a trait object implements `Marker2` if and only if `Marker2` is one of the trait object's trait bounds error[E0321]: traits with a default impl, like `Marker2`, cannot be implemented for trait object `(dyn Object + 'static)` - --> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:26:1 + --> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:28:1 | LL | impl Marker2 for dyn Object {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -35,7 +35,7 @@ LL | impl Marker2 for dyn Object {} = note: a trait object implements `Marker2` if and only if `Marker2` is one of the trait object's trait bounds error[E0117]: only traits defined in the current crate can be implemented for arbitrary types - --> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:22:1 + --> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:24:1 | LL | unsafe impl Send for dyn Marker2 {} | ^^^^^^^^^^^^^^^^^^^^^----------- @@ -46,19 +46,19 @@ LL | unsafe impl Send for dyn Marker2 {} = note: define and implement a trait or new type instead error[E0321]: cross-crate traits with a default impl, like `Send`, can only be implemented for a struct/enum type, not `(dyn Object + 'static)` - --> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:27:1 + --> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:29:1 | LL | unsafe impl Send for dyn Object {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait with a default impl for non-struct/enum type error[E0321]: cross-crate traits with a default impl, like `Send`, can only be implemented for a struct/enum type, not `(dyn Object + Marker2 + 'static)` - --> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:28:1 + --> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:30:1 | LL | unsafe impl Send for dyn Object + Marker2 {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait with a default impl for non-struct/enum type error[E0321]: traits with a default impl, like `Marker3`, cannot be implemented for generic type `T` - --> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:32:1 + --> $DIR/coherence-impl-trait-for-marker-trait-positive.rs:35:1 | LL | impl Marker3 for T {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/coherence/coherence-overlap-negative-impls.rs b/tests/ui/coherence/coherence-overlap-negative-impls.rs index cd1df53a52889..47a48c02367ee 100644 --- a/tests/ui/coherence/coherence-overlap-negative-impls.rs +++ b/tests/ui/coherence/coherence-overlap-negative-impls.rs @@ -7,7 +7,7 @@ // `Is: NotNil` is true because of `auto trait` and lack of negative impl. #![feature(negative_impls)] -#![feature(auto_traits)] +#![feature(rustc_attrs)] struct Nil; struct Cons(H); @@ -32,7 +32,8 @@ mod private { use crate::Nil; pub struct Is(T); - pub auto trait NotNil {} + #[rustc_auto_trait] + pub trait NotNil {} #[allow(suspicious_auto_trait_impls)] impl !NotNil for Is {} diff --git a/tests/ui/coherence/issue-85026.rs b/tests/ui/coherence/issue-85026.rs index 8b116545aa696..243d967842330 100644 --- a/tests/ui/coherence/issue-85026.rs +++ b/tests/ui/coherence/issue-85026.rs @@ -1,5 +1,7 @@ -#![feature(auto_traits)] -auto trait AutoTrait {} +#![feature(rustc_attrs)] + +#[rustc_auto_trait] +trait AutoTrait {} // You cannot impl your own `dyn AutoTrait`. impl dyn AutoTrait {} //~ERROR E0785 diff --git a/tests/ui/coherence/issue-85026.stderr b/tests/ui/coherence/issue-85026.stderr index fb6e9976583b2..0592780976673 100644 --- a/tests/ui/coherence/issue-85026.stderr +++ b/tests/ui/coherence/issue-85026.stderr @@ -1,5 +1,5 @@ error[E0785]: cannot define inherent `impl` for a dyn auto trait - --> $DIR/issue-85026.rs:5:1 + --> $DIR/issue-85026.rs:7:1 | LL | impl dyn AutoTrait {} | ^^^^^^^^^^^^^^^^^^ impl requires at least one non-auto trait @@ -7,7 +7,7 @@ LL | impl dyn AutoTrait {} = note: define and implement a new trait or type instead error[E0785]: cannot define inherent `impl` for a dyn auto trait - --> $DIR/issue-85026.rs:8:1 + --> $DIR/issue-85026.rs:10:1 | LL | impl dyn Unpin {} | ^^^^^^^^^^^^^^ impl requires at least one non-auto trait diff --git a/tests/ui/feature-gates/feature-gate-auto-traits.rs b/tests/ui/feature-gates/feature-gate-auto-traits.rs deleted file mode 100644 index 80cfa9cee8959..0000000000000 --- a/tests/ui/feature-gates/feature-gate-auto-traits.rs +++ /dev/null @@ -1,12 +0,0 @@ -// Test that default and negative trait implementations are gated by -// `auto_traits` feature gate - -struct DummyStruct; - -auto trait AutoDummyTrait {} -//~^ ERROR auto traits are experimental and possibly buggy - -impl !AutoDummyTrait for DummyStruct {} -//~^ ERROR negative trait bounds are not yet fully implemented; use marker types for now - -fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-auto-traits.stderr b/tests/ui/feature-gates/feature-gate-auto-traits.stderr deleted file mode 100644 index e015418161e5a..0000000000000 --- a/tests/ui/feature-gates/feature-gate-auto-traits.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0658]: auto traits are experimental and possibly buggy - --> $DIR/feature-gate-auto-traits.rs:6:1 - | -LL | auto trait AutoDummyTrait {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #13231 for more information - = help: add `#![feature(auto_traits)]` to the crate attributes to enable - -error[E0658]: negative trait bounds are not yet fully implemented; use marker types for now - --> $DIR/feature-gate-auto-traits.rs:9:6 - | -LL | impl !AutoDummyTrait for DummyStruct {} - | ^^^^^^^^^^^^^^^ - | - = note: see issue #68318 for more information - = help: add `#![feature(negative_impls)]` to the crate attributes to enable - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/generator/auto-trait-regions.rs b/tests/ui/generator/auto-trait-regions.rs index aa4218e13a46b..fe1c1bc653077 100644 --- a/tests/ui/generator/auto-trait-regions.rs +++ b/tests/ui/generator/auto-trait-regions.rs @@ -1,8 +1,9 @@ #![feature(generators)] -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![feature(negative_impls)] -auto trait Foo {} +#[rustc_auto_trait] +trait Foo {} struct No; diff --git a/tests/ui/generator/auto-trait-regions.stderr b/tests/ui/generator/auto-trait-regions.stderr index a9a0bde2ba019..6ae29d749f216 100644 --- a/tests/ui/generator/auto-trait-regions.stderr +++ b/tests/ui/generator/auto-trait-regions.stderr @@ -1,5 +1,5 @@ error[E0716]: temporary value dropped while borrowed - --> $DIR/auto-trait-regions.rs:45:24 + --> $DIR/auto-trait-regions.rs:46:24 | LL | let a = A(&mut true, &mut true, No); | ^^^^ - temporary value is freed at the end of this statement @@ -16,7 +16,7 @@ LL ~ let a = A(&mut binding, &mut true, No); | error[E0716]: temporary value dropped while borrowed - --> $DIR/auto-trait-regions.rs:45:35 + --> $DIR/auto-trait-regions.rs:46:35 | LL | let a = A(&mut true, &mut true, No); | ^^^^ - temporary value is freed at the end of this statement @@ -33,7 +33,7 @@ LL ~ let a = A(&mut true, &mut binding, No); | error: implementation of `Foo` is not general enough - --> $DIR/auto-trait-regions.rs:31:5 + --> $DIR/auto-trait-regions.rs:32:5 | LL | assert_foo(gen); | ^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough @@ -42,7 +42,7 @@ LL | assert_foo(gen); = note: ...but `Foo` is actually implemented for the type `&'static OnlyFooIfStaticRef` error: implementation of `Foo` is not general enough - --> $DIR/auto-trait-regions.rs:51:5 + --> $DIR/auto-trait-regions.rs:52:5 | LL | assert_foo(gen); | ^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough diff --git a/tests/ui/issues/issue-29516.rs b/tests/ui/issues/issue-29516.rs index 6779d508dd6c6..0233ce03fc1c2 100644 --- a/tests/ui/issues/issue-29516.rs +++ b/tests/ui/issues/issue-29516.rs @@ -1,8 +1,9 @@ // check-pass -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![feature(negative_impls)] -auto trait NotSame {} +#[rustc_auto_trait] +trait NotSame {} impl !NotSame for (A, A) {} diff --git a/tests/ui/macros/stringify.rs b/tests/ui/macros/stringify.rs index 816f99baa8495..31aeee929363b 100644 --- a/tests/ui/macros/stringify.rs +++ b/tests/ui/macros/stringify.rs @@ -569,19 +569,13 @@ fn test_item() { // ItemKind::Trait assert_eq!( stringify_item!( - pub unsafe auto trait Send {} - ), - "pub unsafe auto trait Send {}", - ); - assert_eq!( - stringify_item!( - trait Trait<'a>: Sized + pub unsafe trait Trait<'a>: Sized where Self: 'a, { } ), - "trait Trait<'a>: Sized where Self: 'a {}", + "pub unsafe trait Trait<'a>: Sized where Self: 'a {}", ); // ItemKind::TraitAlias diff --git a/tests/ui/methods/issues/issue-105732.rs b/tests/ui/methods/issues/issue-105732.rs index d7005065813a8..49f9ab1bfece8 100644 --- a/tests/ui/methods/issues/issue-105732.rs +++ b/tests/ui/methods/issues/issue-105732.rs @@ -1,6 +1,7 @@ -#![feature(auto_traits)] +#![feature(rustc_attrs)] -auto trait Foo { +#[rustc_auto_trait] +trait Foo { fn g(&self); //~ ERROR auto traits cannot have associated items } diff --git a/tests/ui/methods/issues/issue-105732.stderr b/tests/ui/methods/issues/issue-105732.stderr index 19ccd2de685a1..eac84c254532b 100644 --- a/tests/ui/methods/issues/issue-105732.stderr +++ b/tests/ui/methods/issues/issue-105732.stderr @@ -1,13 +1,13 @@ error[E0380]: auto traits cannot have associated items - --> $DIR/issue-105732.rs:4:8 + --> $DIR/issue-105732.rs:5:8 | -LL | auto trait Foo { - | --- auto traits cannot have associated items +LL | trait Foo { + | --- auto traits cannot have associated items LL | fn g(&self); | ---^-------- help: remove these associated items error[E0599]: no method named `g` found for reference `&Self` in the current scope - --> $DIR/issue-105732.rs:10:14 + --> $DIR/issue-105732.rs:11:14 | LL | self.g(); | ^ help: there is a method with a similar name: `f` diff --git a/tests/ui/never_type/auto-traits.rs b/tests/ui/never_type/auto-traits.rs index 42ede708e66df..9514f7c5976e8 100644 --- a/tests/ui/never_type/auto-traits.rs +++ b/tests/ui/never_type/auto-traits.rs @@ -1,13 +1,14 @@ // check-pass -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![feature(negative_impls)] #![feature(never_type)] fn main() { enum Void {} - auto trait Auto {} + #[rustc_auto_trait] + trait Auto {} fn assert_auto() {} assert_auto::(); assert_auto::(); diff --git a/tests/ui/parser/issues/issue-27255.rs b/tests/ui/parser/issues/issue-27255.rs index d619688e10183..7d94e1f764264 100644 --- a/tests/ui/parser/issues/issue-27255.rs +++ b/tests/ui/parser/issues/issue-27255.rs @@ -2,7 +2,7 @@ trait A {} impl A .. {} //~^ ERROR missing `for` in a trait impl -//~| ERROR `impl Trait for .. {}` is an obsolete syntax +//~| ERROR `impl Trait for .. {}` is an obsolete syntax for auto traits impl A usize {} //~^ ERROR missing `for` in a trait impl diff --git a/tests/ui/parser/issues/issue-27255.stderr b/tests/ui/parser/issues/issue-27255.stderr index 391a23556c4e0..4443502a02d6f 100644 --- a/tests/ui/parser/issues/issue-27255.stderr +++ b/tests/ui/parser/issues/issue-27255.stderr @@ -10,13 +10,13 @@ error: missing `for` in a trait impl LL | impl A usize {} | ^^^^^^ help: add `for` here -error: `impl Trait for .. {}` is an obsolete syntax +error: `impl Trait for .. {}` is an obsolete syntax for auto traits --> $DIR/issue-27255.rs:3:1 | LL | impl A .. {} | ^^^^^^^^^^^^ | - = help: use `auto trait Trait {}` instead + = help: use `#[rustc_auto_trait] trait Trait {}` instead error: aborting due to 3 previous errors diff --git a/tests/ui/parser/obsolete-auto-trait-syntax.failure.stderr b/tests/ui/parser/obsolete-auto-trait-syntax.failure.stderr new file mode 100644 index 0000000000000..889fc69fdb5f7 --- /dev/null +++ b/tests/ui/parser/obsolete-auto-trait-syntax.failure.stderr @@ -0,0 +1,18 @@ +error: `impl Trait for .. {}` is an obsolete syntax for auto traits + --> $DIR/obsolete-auto-trait-syntax.rs:7:1 + | +LL | impl Trait1 for .. {} + | ^^^^^^^^^^^^^^^^^^^^^ + | + = help: use `#[rustc_auto_trait] trait Trait {}` instead + +error: `auto trait Trait {}` is an obsolete syntax for auto traits + --> $DIR/obsolete-auto-trait-syntax.rs:10:1 + | +LL | auto trait Trait2 {} + | ^^^^^^^^^^^^^^^^^^^^ + | + = help: use `#[rustc_auto_trait] trait Trait {}` instead + +error: aborting due to 2 previous errors + diff --git a/tests/ui/parser/obsolete-auto-trait-syntax.rs b/tests/ui/parser/obsolete-auto-trait-syntax.rs new file mode 100644 index 0000000000000..8144d0abff148 --- /dev/null +++ b/tests/ui/parser/obsolete-auto-trait-syntax.rs @@ -0,0 +1,12 @@ +// revisions: success failure +//[success] check-pass + +trait Trait1 {} + +#[cfg(failure)] +impl Trait1 for .. {} //[failure]~ ERROR `impl Trait for .. {}` is an obsolete syntax for auto traits + +#[cfg(failure)] +auto trait Trait2 {} //[failure]~ ERROR `auto trait Trait {}` is an obsolete syntax for auto traits + +fn main() {} diff --git a/tests/ui/parser/obsolete-syntax-impl-for-dotdot.rs b/tests/ui/parser/obsolete-syntax-impl-for-dotdot.rs deleted file mode 100644 index e928f09aa6d37..0000000000000 --- a/tests/ui/parser/obsolete-syntax-impl-for-dotdot.rs +++ /dev/null @@ -1,9 +0,0 @@ -trait Trait1 {} -trait Trait2 {} - -#[cfg(not_enabled)] -impl Trait1 for .. {} - -impl Trait2 for .. {} //~ ERROR `impl Trait for .. {}` is an obsolete syntax - -fn main() {} diff --git a/tests/ui/parser/obsolete-syntax-impl-for-dotdot.stderr b/tests/ui/parser/obsolete-syntax-impl-for-dotdot.stderr deleted file mode 100644 index b7108ced0d763..0000000000000 --- a/tests/ui/parser/obsolete-syntax-impl-for-dotdot.stderr +++ /dev/null @@ -1,10 +0,0 @@ -error: `impl Trait for .. {}` is an obsolete syntax - --> $DIR/obsolete-syntax-impl-for-dotdot.rs:7:1 - | -LL | impl Trait2 for .. {} - | ^^^^^^^^^^^^^^^^^^^^^ - | - = help: use `auto trait Trait {}` instead - -error: aborting due to previous error - diff --git a/tests/ui/parser/trait-object-bad-parens.rs b/tests/ui/parser/trait-object-bad-parens.rs index 8e267c7448feb..af12704161ad4 100644 --- a/tests/ui/parser/trait-object-bad-parens.rs +++ b/tests/ui/parser/trait-object-bad-parens.rs @@ -1,8 +1,9 @@ -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![feature(negative_impls)] #![allow(bare_trait_objects)] -auto trait Auto {} +#[rustc_auto_trait] +trait Auto {} fn main() { let _: Box<((Auto)) + Auto>; diff --git a/tests/ui/parser/trait-object-bad-parens.stderr b/tests/ui/parser/trait-object-bad-parens.stderr index 74e484eebee1f..a36727ffeaf10 100644 --- a/tests/ui/parser/trait-object-bad-parens.stderr +++ b/tests/ui/parser/trait-object-bad-parens.stderr @@ -1,23 +1,23 @@ error[E0178]: expected a path on the left-hand side of `+`, not `((Auto))` - --> $DIR/trait-object-bad-parens.rs:8:16 + --> $DIR/trait-object-bad-parens.rs:9:16 | LL | let _: Box<((Auto)) + Auto>; | ^^^^^^^^^^^^^^^ expected a path error[E0178]: expected a path on the left-hand side of `+`, not `(Auto + Auto)` - --> $DIR/trait-object-bad-parens.rs:10:16 + --> $DIR/trait-object-bad-parens.rs:11:16 | LL | let _: Box<(Auto + Auto) + Auto>; | ^^^^^^^^^^^^^^^^^^^^ expected a path error[E0178]: expected a path on the left-hand side of `+`, not `(Auto)` - --> $DIR/trait-object-bad-parens.rs:12:16 + --> $DIR/trait-object-bad-parens.rs:13:16 | LL | let _: Box<(Auto +) + Auto>; | ^^^^^^^^^^^^^^^ expected a path error[E0178]: expected a path on the left-hand side of `+`, not `(dyn Auto)` - --> $DIR/trait-object-bad-parens.rs:14:16 + --> $DIR/trait-object-bad-parens.rs:15:16 | LL | let _: Box<(dyn Auto) + Auto>; | ^^^^^^^^^^^^^^^^^ expected a path diff --git a/tests/ui/phantom-auto-trait.rs b/tests/ui/phantom-auto-trait.rs index 0172ca335c32a..0b6a967c16322 100644 --- a/tests/ui/phantom-auto-trait.rs +++ b/tests/ui/phantom-auto-trait.rs @@ -1,11 +1,12 @@ // Ensure that auto trait checks `T` when it encounters a `PhantomData` field, instead of // checking the `PhantomData` type itself (which almost always implements an auto trait). -#![feature(auto_traits)] +#![feature(rustc_attrs)] use std::marker::{PhantomData}; -unsafe auto trait Zen {} +#[rustc_auto_trait] +unsafe trait Zen {} unsafe impl<'a, T: 'a> Zen for &'a T where T: Sync {} diff --git a/tests/ui/phantom-auto-trait.stderr b/tests/ui/phantom-auto-trait.stderr index 5af648f6a0cf1..080f05280420a 100644 --- a/tests/ui/phantom-auto-trait.stderr +++ b/tests/ui/phantom-auto-trait.stderr @@ -1,5 +1,5 @@ error[E0277]: `T` cannot be shared between threads safely - --> $DIR/phantom-auto-trait.rs:21:12 + --> $DIR/phantom-auto-trait.rs:22:12 | LL | is_zen(x) | ------ ^ `T` cannot be shared between threads safely @@ -7,19 +7,19 @@ LL | is_zen(x) | required by a bound introduced by this call | note: required for `&T` to implement `Zen` - --> $DIR/phantom-auto-trait.rs:10:24 + --> $DIR/phantom-auto-trait.rs:11:24 | LL | unsafe impl<'a, T: 'a> Zen for &'a T where T: Sync {} | ^^^ ^^^^^ ---- unsatisfied trait bound introduced here note: required because it appears within the type `PhantomData<&T>` --> $SRC_DIR/core/src/marker.rs:LL:COL note: required because it appears within the type `Guard<'_, T>` - --> $DIR/phantom-auto-trait.rs:12:8 + --> $DIR/phantom-auto-trait.rs:13:8 | LL | struct Guard<'a, T: 'a> { | ^^^^^ note: required by a bound in `is_zen` - --> $DIR/phantom-auto-trait.rs:18:14 + --> $DIR/phantom-auto-trait.rs:19:14 | LL | fn is_zen(_: T) {} | ^^^ required by this bound in `is_zen` @@ -29,7 +29,7 @@ LL | fn not_sync(x: Guard) { | +++++++++++++++++++ error[E0277]: `T` cannot be shared between threads safely - --> $DIR/phantom-auto-trait.rs:26:12 + --> $DIR/phantom-auto-trait.rs:27:12 | LL | is_zen(x) | ------ ^ `T` cannot be shared between threads safely @@ -37,24 +37,24 @@ LL | is_zen(x) | required by a bound introduced by this call | note: required for `&T` to implement `Zen` - --> $DIR/phantom-auto-trait.rs:10:24 + --> $DIR/phantom-auto-trait.rs:11:24 | LL | unsafe impl<'a, T: 'a> Zen for &'a T where T: Sync {} | ^^^ ^^^^^ ---- unsatisfied trait bound introduced here note: required because it appears within the type `PhantomData<&T>` --> $SRC_DIR/core/src/marker.rs:LL:COL note: required because it appears within the type `Guard<'_, T>` - --> $DIR/phantom-auto-trait.rs:12:8 + --> $DIR/phantom-auto-trait.rs:13:8 | LL | struct Guard<'a, T: 'a> { | ^^^^^ note: required because it appears within the type `Nested>` - --> $DIR/phantom-auto-trait.rs:16:8 + --> $DIR/phantom-auto-trait.rs:17:8 | LL | struct Nested(T); | ^^^^^^ note: required by a bound in `is_zen` - --> $DIR/phantom-auto-trait.rs:18:14 + --> $DIR/phantom-auto-trait.rs:19:14 | LL | fn is_zen(_: T) {} | ^^^ required by this bound in `is_zen` diff --git a/tests/ui/privacy/private-in-public-non-principal-2.rs b/tests/ui/privacy/private-in-public-non-principal-2.rs index d7223c647c0a3..00976204f1762 100644 --- a/tests/ui/privacy/private-in-public-non-principal-2.rs +++ b/tests/ui/privacy/private-in-public-non-principal-2.rs @@ -1,10 +1,11 @@ -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![feature(negative_impls)] #[allow(private_interfaces)] mod m { pub trait PubPrincipal {} - auto trait PrivNonPrincipal {} + #[rustc_auto_trait] + trait PrivNonPrincipal {} pub fn leak_dyn_nonprincipal() -> Box { loop {} } } diff --git a/tests/ui/privacy/private-in-public-non-principal-2.stderr b/tests/ui/privacy/private-in-public-non-principal-2.stderr index 7cc8bf0de2b9c..d33379df76972 100644 --- a/tests/ui/privacy/private-in-public-non-principal-2.stderr +++ b/tests/ui/privacy/private-in-public-non-principal-2.stderr @@ -1,5 +1,5 @@ error: trait `PrivNonPrincipal` is private - --> $DIR/private-in-public-non-principal-2.rs:12:5 + --> $DIR/private-in-public-non-principal-2.rs:13:5 | LL | m::leak_dyn_nonprincipal(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ private trait diff --git a/tests/ui/privacy/private-in-public-non-principal.rs b/tests/ui/privacy/private-in-public-non-principal.rs index e348a181651cf..44c01e8315c84 100644 --- a/tests/ui/privacy/private-in-public-non-principal.rs +++ b/tests/ui/privacy/private-in-public-non-principal.rs @@ -1,8 +1,9 @@ -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![feature(negative_impls)] pub trait PubPrincipal {} -auto trait PrivNonPrincipal {} +#[rustc_auto_trait] +trait PrivNonPrincipal {} pub fn leak_dyn_nonprincipal() -> Box { loop {} } //~^ WARN trait `PrivNonPrincipal` is more private than the item `leak_dyn_nonprincipal` diff --git a/tests/ui/privacy/private-in-public-non-principal.stderr b/tests/ui/privacy/private-in-public-non-principal.stderr index 63512f462f518..6ff142e37e22f 100644 --- a/tests/ui/privacy/private-in-public-non-principal.stderr +++ b/tests/ui/privacy/private-in-public-non-principal.stderr @@ -1,24 +1,24 @@ warning: trait `PrivNonPrincipal` is more private than the item `leak_dyn_nonprincipal` - --> $DIR/private-in-public-non-principal.rs:7:1 + --> $DIR/private-in-public-non-principal.rs:8:1 | LL | pub fn leak_dyn_nonprincipal() -> Box { loop {} } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `leak_dyn_nonprincipal` is reachable at visibility `pub` | note: but trait `PrivNonPrincipal` is only usable at visibility `pub(crate)` - --> $DIR/private-in-public-non-principal.rs:5:1 + --> $DIR/private-in-public-non-principal.rs:6:1 | -LL | auto trait PrivNonPrincipal {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | trait PrivNonPrincipal {} + | ^^^^^^^^^^^^^^^^^^^^^^ = note: `#[warn(private_interfaces)]` on by default error: missing documentation for an associated function - --> $DIR/private-in-public-non-principal.rs:13:9 + --> $DIR/private-in-public-non-principal.rs:14:9 | LL | pub fn check_doc_lint() {} | ^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here - --> $DIR/private-in-public-non-principal.rs:10:8 + --> $DIR/private-in-public-non-principal.rs:11:8 | LL | #[deny(missing_docs)] | ^^^^^^^^^^^^ diff --git a/tests/ui/specialization/specialization-polarity.rs b/tests/ui/specialization/specialization-polarity.rs index b3cd8255bb9b1..dcfb9c3bd3ee4 100644 --- a/tests/ui/specialization/specialization-polarity.rs +++ b/tests/ui/specialization/specialization-polarity.rs @@ -1,15 +1,17 @@ // Make sure specialization cannot change impl polarity -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![feature(negative_impls)] #![feature(specialization)] //~ WARN the feature `specialization` is incomplete -auto trait Foo {} +#[rustc_auto_trait] +trait Foo {} impl Foo for T {} impl !Foo for u8 {} //~ ERROR E0751 -auto trait Bar {} +#[rustc_auto_trait] +trait Bar {} impl !Bar for T {} impl Bar for u8 {} //~ ERROR E0751 diff --git a/tests/ui/specialization/specialization-polarity.stderr b/tests/ui/specialization/specialization-polarity.stderr index f287018ba7f71..0f6a32ec6da19 100644 --- a/tests/ui/specialization/specialization-polarity.stderr +++ b/tests/ui/specialization/specialization-polarity.stderr @@ -9,7 +9,7 @@ LL | #![feature(specialization)] = note: `#[warn(incomplete_features)]` on by default error[E0751]: found both positive and negative implementation of trait `Foo` for type `u8`: - --> $DIR/specialization-polarity.rs:10:1 + --> $DIR/specialization-polarity.rs:11:1 | LL | impl Foo for T {} | ----------------- positive implementation here @@ -17,7 +17,7 @@ LL | impl !Foo for u8 {} | ^^^^^^^^^^^^^^^^ negative implementation here error[E0751]: found both positive and negative implementation of trait `Bar` for type `u8`: - --> $DIR/specialization-polarity.rs:15:1 + --> $DIR/specialization-polarity.rs:17:1 | LL | impl !Bar for T {} | ------------------ negative implementation here diff --git a/tests/ui/symbol-names/impl1.legacy.stderr b/tests/ui/symbol-names/impl1.legacy.stderr index 3d438df92b85d..4eccf7aad7009 100644 --- a/tests/ui/symbol-names/impl1.legacy.stderr +++ b/tests/ui/symbol-names/impl1.legacy.stderr @@ -47,25 +47,25 @@ LL | #[rustc_def_path] | ^^^^^^^^^^^^^^^^^ error: symbol-name(_ZN209_$LT$$u5b$$RF$dyn$u20$impl1..Foo$u2b$Assoc$u20$$u3d$$u20$extern$u20$$u22$C$u22$$u20$fn$LP$$RF$u8$C$$u20$...$RP$$u2b$impl1..AutoTrait$u3b$$u20$3$u5d$$u20$as$u20$impl1..main..$u7b$$u7b$closure$u7d$$u7d$..Bar$GT$6method17) - --> $DIR/impl1.rs:62:13 + --> $DIR/impl1.rs:63:13 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ error: demangling(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; 3] as impl1::main::{{closure}}::Bar>::method::) - --> $DIR/impl1.rs:62:13 + --> $DIR/impl1.rs:63:13 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ error: demangling-alt(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8, ::.)+impl1::AutoTrait; 3] as impl1::main::{{closure}}::Bar>::method) - --> $DIR/impl1.rs:62:13 + --> $DIR/impl1.rs:63:13 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ error: def-path(<[&dyn Foo extern "C" fn(&'a u8, ...)> + AutoTrait; 3] as main::{closure#1}::Bar>::method) - --> $DIR/impl1.rs:69:13 + --> $DIR/impl1.rs:70:13 | LL | #[rustc_def_path] | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/symbol-names/impl1.rs b/tests/ui/symbol-names/impl1.rs index 629c2f33ddcc6..2a64de50c59d1 100644 --- a/tests/ui/symbol-names/impl1.rs +++ b/tests/ui/symbol-names/impl1.rs @@ -4,7 +4,7 @@ //[v0]compile-flags: -C symbol-mangling-version=v0 //[legacy]normalize-stderr-test: "h[\w]{16}E?\)" -> ")" -#![feature(auto_traits, rustc_attrs)] +#![feature(rustc_attrs)] #![allow(dead_code)] mod foo { @@ -47,7 +47,8 @@ trait Foo { type Assoc; } -auto trait AutoTrait {} +#[rustc_auto_trait] +trait AutoTrait {} fn main() { // Test closure mangling, and disambiguators. diff --git a/tests/ui/symbol-names/impl1.v0.stderr b/tests/ui/symbol-names/impl1.v0.stderr index a7cc5fc8ed211..452d9b742af30 100644 --- a/tests/ui/symbol-names/impl1.v0.stderr +++ b/tests/ui/symbol-names/impl1.v0.stderr @@ -47,25 +47,25 @@ LL | #[rustc_def_path] | ^^^^^^^^^^^^^^^^^ error: symbol-name(_RNvXNCNvCsCRATE_HASH_5impl14mains_0ARDNtB_3Foop5AssocFG_KCRL0_hvEuNtB_9AutoTraitEL_j3_NtB_3Bar6method) - --> $DIR/impl1.rs:62:13 + --> $DIR/impl1.rs:63:13 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ error: demangling(<[&dyn impl1[d5591eb39db23cbb]::Foo extern "C" fn(&'a u8, ...)> + impl1[d5591eb39db23cbb]::AutoTrait; 3usize] as impl1[d5591eb39db23cbb]::main::{closure#1}::Bar>::method) - --> $DIR/impl1.rs:62:13 + --> $DIR/impl1.rs:63:13 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ error: demangling-alt(<[&dyn impl1::Foo extern "C" fn(&'a u8, ...)> + impl1::AutoTrait; 3] as impl1::main::{closure#1}::Bar>::method) - --> $DIR/impl1.rs:62:13 + --> $DIR/impl1.rs:63:13 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ error: def-path(<[&dyn Foo extern "C" fn(&'a u8, ...)> + AutoTrait; 3] as main::{closure#1}::Bar>::method) - --> $DIR/impl1.rs:69:13 + --> $DIR/impl1.rs:70:13 | LL | #[rustc_def_path] | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/traits/alias/syntax-fail.rs b/tests/ui/traits/alias/syntax-fail.rs index 039bbce8c1ed0..e171e50d6b8b8 100644 --- a/tests/ui/traits/alias/syntax-fail.rs +++ b/tests/ui/traits/alias/syntax-fail.rs @@ -1,7 +1,10 @@ #![feature(trait_alias)] trait Foo {} -auto trait A = Foo; //~ ERROR trait aliases cannot be `auto` +#[rustc_auto_trait] +//~^ ERROR attribute should be applied to a trait +//~| ERROR `#[rustc_auto_trait]` is used to mark auto traits, only intended to be used in `core` +trait A = Foo; unsafe trait B = Foo; //~ ERROR trait aliases cannot be `unsafe` trait C: Ord = Eq; //~ ERROR bounds are not allowed on trait aliases diff --git a/tests/ui/traits/alias/syntax-fail.stderr b/tests/ui/traits/alias/syntax-fail.stderr index 748b92056d105..945c4a8740e5d 100644 --- a/tests/ui/traits/alias/syntax-fail.stderr +++ b/tests/ui/traits/alias/syntax-fail.stderr @@ -1,26 +1,38 @@ -error: trait aliases cannot be `auto` - --> $DIR/syntax-fail.rs:4:1 - | -LL | auto trait A = Foo; - | ^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `auto` - error: trait aliases cannot be `unsafe` - --> $DIR/syntax-fail.rs:5:1 + --> $DIR/syntax-fail.rs:8:1 | LL | unsafe trait B = Foo; | ^^^^^^^^^^^^^^^^^^^^^ trait aliases cannot be `unsafe` error: bounds are not allowed on trait aliases - --> $DIR/syntax-fail.rs:7:8 + --> $DIR/syntax-fail.rs:10:8 | LL | trait C: Ord = Eq; | ^^^^^ error: bounds are not allowed on trait aliases - --> $DIR/syntax-fail.rs:8:8 + --> $DIR/syntax-fail.rs:11:8 | LL | trait D: = Eq; | ^ -error: aborting due to 4 previous errors +error[E0658]: `#[rustc_auto_trait]` is used to mark auto traits, only intended to be used in `core` + --> $DIR/syntax-fail.rs:4:1 + | +LL | #[rustc_auto_trait] + | ^^^^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(rustc_attrs)]` to the crate attributes to enable + +error: attribute should be applied to a trait + --> $DIR/syntax-fail.rs:4:1 + | +LL | #[rustc_auto_trait] + | ^^^^^^^^^^^^^^^^^^^ +... +LL | trait A = Foo; + | -------------- not a trait + +error: aborting due to 5 previous errors +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/traits/inductive-overflow/supertrait-auto-trait.rs b/tests/ui/traits/inductive-overflow/supertrait-auto-trait.rs index 5fea47a1be87d..31e3e6bced9ba 100644 --- a/tests/ui/traits/inductive-overflow/supertrait-auto-trait.rs +++ b/tests/ui/traits/inductive-overflow/supertrait-auto-trait.rs @@ -2,10 +2,11 @@ // a simple auto trait `..` impl alone still doesn't allow arbitrary bounds // to be synthesized. -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![feature(negative_impls)] -auto trait Magic: Copy {} //~ ERROR E0568 +#[rustc_auto_trait] +trait Magic: Copy {} //~ ERROR E0568 fn copy(x: T) -> (T, T) { (x, x) } diff --git a/tests/ui/traits/inductive-overflow/supertrait-auto-trait.stderr b/tests/ui/traits/inductive-overflow/supertrait-auto-trait.stderr index e723c7c51814a..116dbacd9153f 100644 --- a/tests/ui/traits/inductive-overflow/supertrait-auto-trait.stderr +++ b/tests/ui/traits/inductive-overflow/supertrait-auto-trait.stderr @@ -1,13 +1,13 @@ error[E0568]: auto traits cannot have super traits or lifetime bounds - --> $DIR/supertrait-auto-trait.rs:8:17 + --> $DIR/supertrait-auto-trait.rs:9:12 | -LL | auto trait Magic: Copy {} - | -----^^^^^^ help: remove the super traits or lifetime bounds - | | - | auto traits cannot have super traits or lifetime bounds +LL | trait Magic: Copy {} + | -----^^^^^^ help: remove the super traits or lifetime bounds + | | + | auto traits cannot have super traits or lifetime bounds error[E0277]: the trait bound `NoClone: Copy` is not satisfied - --> $DIR/supertrait-auto-trait.rs:16:23 + --> $DIR/supertrait-auto-trait.rs:17:23 | LL | let (a, b) = copy(NoClone); | ---- ^^^^^^^ the trait `Copy` is not implemented for `NoClone` @@ -15,12 +15,12 @@ LL | let (a, b) = copy(NoClone); | required by a bound introduced by this call | note: required for `NoClone` to implement `Magic` - --> $DIR/supertrait-auto-trait.rs:8:12 + --> $DIR/supertrait-auto-trait.rs:9:7 | -LL | auto trait Magic: Copy {} - | ^^^^^ +LL | trait Magic: Copy {} + | ^^^^^ note: required by a bound in `copy` - --> $DIR/supertrait-auto-trait.rs:10:12 + --> $DIR/supertrait-auto-trait.rs:11:12 | LL | fn copy(x: T) -> (T, T) { (x, x) } | ^^^^^ required by this bound in `copy` diff --git a/tests/ui/traits/new-solver/cycles/provisional-result-done.rs b/tests/ui/traits/new-solver/cycles/provisional-result-done.rs index 589d34dd7abb1..6d72deb57efe2 100644 --- a/tests/ui/traits/new-solver/cycles/provisional-result-done.rs +++ b/tests/ui/traits/new-solver/cycles/provisional-result-done.rs @@ -3,8 +3,10 @@ // This tests checks that we update results in the provisional cache when // we pop a goal from the stack. -#![feature(auto_traits)] -auto trait Coinductive {} +#![feature(rustc_attrs)] + +#[rustc_auto_trait] +trait Coinductive {} struct Foo(T); struct Bar(T); diff --git a/tests/ui/traits/new-solver/stall-num-var-auto-trait.fallback.stderr b/tests/ui/traits/new-solver/stall-num-var-auto-trait.fallback.stderr index a3ab7836c193b..b1d6963e7c126 100644 --- a/tests/ui/traits/new-solver/stall-num-var-auto-trait.fallback.stderr +++ b/tests/ui/traits/new-solver/stall-num-var-auto-trait.fallback.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `i32: Foo` is not satisfied - --> $DIR/stall-num-var-auto-trait.rs:18:15 + --> $DIR/stall-num-var-auto-trait.rs:19:15 | LL | needs_foo(x); | --------- ^ the trait `Foo` is not implemented for `i32` @@ -7,7 +7,7 @@ LL | needs_foo(x); | required by a bound introduced by this call | note: required by a bound in `needs_foo` - --> $DIR/stall-num-var-auto-trait.rs:14:22 + --> $DIR/stall-num-var-auto-trait.rs:15:22 | LL | fn needs_foo(x: impl Foo) {} | ^^^ required by this bound in `needs_foo` diff --git a/tests/ui/traits/new-solver/stall-num-var-auto-trait.rs b/tests/ui/traits/new-solver/stall-num-var-auto-trait.rs index 0539c3a4292fe..6262a4ef9118e 100644 --- a/tests/ui/traits/new-solver/stall-num-var-auto-trait.rs +++ b/tests/ui/traits/new-solver/stall-num-var-auto-trait.rs @@ -5,9 +5,10 @@ // Tests that we stall the `{integer}: Foo` obligation until after we // constrain the int type (or fallback occurs). -#![feature(negative_impls, auto_traits)] +#![feature(negative_impls, rustc_attrs)] -auto trait Foo {} +#[rustc_auto_trait] +trait Foo {} impl !Foo for i32 {} diff --git a/tests/ui/type-alias-impl-trait/impl_for_weak_alias.rs b/tests/ui/type-alias-impl-trait/impl_for_weak_alias.rs index 00d1a1a226d2f..9a7a557cea83b 100644 --- a/tests/ui/type-alias-impl-trait/impl_for_weak_alias.rs +++ b/tests/ui/type-alias-impl-trait/impl_for_weak_alias.rs @@ -1,9 +1,10 @@ #![feature(type_alias_impl_trait)] -#![feature(auto_traits)] +#![feature(rustc_attrs)] type Alias = (impl Sized, u8); -auto trait Trait {} +#[rustc_auto_trait] +trait Trait {} impl Trait for Alias {} //~^ ERROR traits with a default impl, like `Trait`, cannot be implemented for type alias `Alias` diff --git a/tests/ui/type-alias-impl-trait/impl_for_weak_alias.stderr b/tests/ui/type-alias-impl-trait/impl_for_weak_alias.stderr index c312ee7dece8d..97b6c23f347a7 100644 --- a/tests/ui/type-alias-impl-trait/impl_for_weak_alias.stderr +++ b/tests/ui/type-alias-impl-trait/impl_for_weak_alias.stderr @@ -1,5 +1,5 @@ error[E0321]: traits with a default impl, like `Trait`, cannot be implemented for type alias `Alias` - --> $DIR/impl_for_weak_alias.rs:7:1 + --> $DIR/impl_for_weak_alias.rs:8:1 | LL | impl Trait for Alias {} | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/typeck/auxiliary/tdticc_coherence_lib.rs b/tests/ui/typeck/auxiliary/tdticc_coherence_lib.rs index ef2cd415fcaaa..3eefcba6cb247 100644 --- a/tests/ui/typeck/auxiliary/tdticc_coherence_lib.rs +++ b/tests/ui/typeck/auxiliary/tdticc_coherence_lib.rs @@ -1,6 +1,7 @@ -#![feature(auto_traits, core)] +#![feature(rustc_attrs, core)] #![crate_type = "rlib"] -pub auto trait DefaultedTrait { } +#[rustc_auto_trait] +pub trait DefaultedTrait { } pub struct Something { t: T } diff --git a/tests/ui/where-clauses/self-in-where-clause-allowed.rs b/tests/ui/where-clauses/self-in-where-clause-allowed.rs index 6cf5ed2e46aec..eb0a1949dbaed 100644 --- a/tests/ui/where-clauses/self-in-where-clause-allowed.rs +++ b/tests/ui/where-clauses/self-in-where-clause-allowed.rs @@ -1,9 +1,10 @@ // check-fail -#![feature(auto_traits)] +#![feature(rustc_attrs)] #![deny(where_clauses_object_safety)] -auto trait AutoTrait {} +#[rustc_auto_trait] +trait AutoTrait {} trait Trait { fn static_lifetime_bound(&self) where Self: 'static {} diff --git a/tests/ui/where-clauses/self-in-where-clause-allowed.stderr b/tests/ui/where-clauses/self-in-where-clause-allowed.stderr index ea51f5084f875..2c5d63dcdbe11 100644 --- a/tests/ui/where-clauses/self-in-where-clause-allowed.stderr +++ b/tests/ui/where-clauses/self-in-where-clause-allowed.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `dyn Trait: AutoTrait` is not satisfied - --> $DIR/self-in-where-clause-allowed.rs:22:18 + --> $DIR/self-in-where-clause-allowed.rs:23:18 | LL | trait_object.autotrait_bound(); | ^^^^^^^^^^^^^^^ the trait `AutoTrait` is not implemented for `dyn Trait` | note: required by a bound in `Trait::autotrait_bound` - --> $DIR/self-in-where-clause-allowed.rs:13:43 + --> $DIR/self-in-where-clause-allowed.rs:14:43 | LL | fn autotrait_bound(&self) where Self: AutoTrait {} | ^^^^^^^^^ required by this bound in `Trait::autotrait_bound`