Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare removal of auto trait syntax in favor of new attribute #[rustc_auto_trait] #116126

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2993,7 +2993,7 @@ pub enum ItemKind {
Union(VariantData, Generics),
/// A trait declaration (`trait`).
///
/// E.g., `trait Foo { .. }`, `trait Foo<T> { .. }` or `auto trait Foo {}`.
/// E.g., `trait Foo { .. }`, `trait Foo<T> { .. }`.
Trait(Box<Trait>),
/// Trait alias
///
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(&[])
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 7 additions & 3 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not having one is fine imo, but you can add one if you want to

self.sess.emit_err(errors::ObsoleteAutoSyntax {
span: i.span,
syntax: "auto trait Trait {}",
});
}

ast::ItemKind::TraitAlias(..) => {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_codegen_cranelift/example/mini_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
decl_macro,
rustc_attrs,
transparent_unions,
auto_traits,
thread_local
)]
#![no_core]
Expand Down Expand Up @@ -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<T: ?Sized> Freeze for PhantomData<T> {}
unsafe impl<T: ?Sized> Freeze for *const T {}
Expand Down Expand Up @@ -503,7 +503,8 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
}

#[lang = "unpin"]
pub auto trait Unpin {}
#[rustc_auto_trait]
pub trait Unpin {}

#[lang = "deref"]
pub trait Deref {
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_codegen_gcc/example/mini_core.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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<T: ?Sized> Freeze for PhantomData<T> {}
unsafe impl<T: ?Sized> Freeze for *const T {}
Expand Down Expand Up @@ -452,7 +453,8 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
}

#[lang = "unpin"]
pub auto trait Unpin {}
#[rustc_auto_trait]
pub trait Unpin {}

#[lang = "deref"]
pub trait Deref {
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_gcc/tests/run/abort1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_gcc/tests/run/abort2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_gcc/tests/run/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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")]
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_gcc/tests/run/assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_gcc/tests/run/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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")]
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_gcc/tests/run/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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")]
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_gcc/tests/run/empty_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -27,7 +27,8 @@ trait Receiver {
}

#[lang = "freeze"]
pub(crate) unsafe auto trait Freeze {}
#[rustc_auto_trait]
pub(crate) unsafe trait Freeze {}

/*
* Code
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_gcc/tests/run/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -34,7 +34,8 @@ trait Receiver {
}

#[lang = "freeze"]
pub(crate) unsafe auto trait Freeze {}
#[rustc_auto_trait]
pub(crate) unsafe trait Freeze {}

/*
* Code
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_gcc/tests/run/exit_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -27,7 +27,8 @@ trait Receiver {
}

#[lang = "freeze"]
pub(crate) unsafe auto trait Freeze {}
#[rustc_auto_trait]
pub(crate) unsafe trait Freeze {}

/*
* Code
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_gcc/tests/run/fun_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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")]
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_codegen_gcc/tests/run/int_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 {
Expand Down
Loading