From 80d730b52618d4dcc52dae25c0e3fceea12d4b33 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Mon, 23 Jan 2023 13:10:27 -0300 Subject: [PATCH] Add MCP 563 syntax --- compiler/rustc_feature/src/builtin_attrs.rs | 2 +- compiler/rustc_span/src/symbol.rs | 1 + .../dropck/mcp563-dropck-eyepatch-syntax.rs | 26 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/ui/dropck/mcp563-dropck-eyepatch-syntax.rs diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index af56a0b245987..53319c748db73 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -540,7 +540,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ gated!(fundamental, Normal, template!(Word), WarnFollowing, experimental!(fundamental)), gated!( - may_dangle, Normal, template!(Word), WarnFollowing, dropck_eyepatch, + may_dangle, Normal, template!(Word, List: "borrow"), WarnFollowing, dropck_eyepatch, "`may_dangle` has unstable semantics and may be removed in the future", ), diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 7597b8d126a9c..19f122d096436 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -425,6 +425,7 @@ symbols! { black_box, block, bool, + borrow, borrowck_graphviz_format, borrowck_graphviz_postflow, box_free, diff --git a/tests/ui/dropck/mcp563-dropck-eyepatch-syntax.rs b/tests/ui/dropck/mcp563-dropck-eyepatch-syntax.rs new file mode 100644 index 0000000000000..5ade731bc4760 --- /dev/null +++ b/tests/ui/dropck/mcp563-dropck-eyepatch-syntax.rs @@ -0,0 +1,26 @@ +#![feature(dropck_eyepatch)] + +// This test checks the `#[may_dangle]` attribute syntax. + +struct Foo(*const T); + +// No error: "drops" bound +unsafe impl<#[may_dangle] T> Drop for Foo { + fn drop(&mut self) { } +} + +struct Bar(*const T); + +// No error: "borrows" bound +unsafe impl<#[may_dangle(borrow)] T> Drop for Bar { + fn drop(&mut self) { } +} + +struct Baz(*const T); + +// Error: invalid syntax +unsafe impl<#[may_dangle(invalid)] T> Drop for Baz { + fn drop(&mut self) { } +} + +pub fn main() { }