about summary refs log tree commit diff
path: root/library/alloc
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2021-01-17 12:24:54 +0000
committerGitHub <noreply@github.com>2021-01-17 12:24:54 +0000
commit19370a486057b1bc7c7911c869640f3bf8d7977d (patch)
tree908116cc9f209e8e40e2b68d8e6dd9ef74b8a314 /library/alloc
parent92dbfb541a2ab1cef3c680fe54c14e6bbc1f43f6 (diff)
parentc127ed6e97535e4a20873d6cfe4fff364a2b9d9b (diff)
downloadrust-19370a486057b1bc7c7911c869640f3bf8d7977d.tar.gz
rust-19370a486057b1bc7c7911c869640f3bf8d7977d.zip
Rollup merge of #81080 - bugadani:vec-diag, r=oli-obk,m-ou-se
Force vec![] to expression position only

r? `@oli-obk`

I went with the lazy way of only changing what broke. I moved the test to ui/macros because the diagnostics no longer give suggestions.

Closes #61933
Diffstat (limited to 'library/alloc')
-rw-r--r--library/alloc/src/lib.rs8
-rw-r--r--library/alloc/src/macros.rs8
2 files changed, 12 insertions, 4 deletions
diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs
index d0bfa038aa1..14a10aac061 100644
--- a/library/alloc/src/lib.rs
+++ b/library/alloc/src/lib.rs
@@ -140,6 +140,7 @@
 #![feature(type_alias_impl_trait)]
 #![feature(associated_type_bounds)]
 #![feature(slice_group_by)]
+#![feature(decl_macro)]
 // Allow testing this library
 
 #[cfg(test)]
@@ -193,4 +194,11 @@ mod std {
 #[unstable(feature = "liballoc_internals", issue = "none", reason = "implementation detail")]
 pub mod __export {
     pub use core::format_args;
+
+    /// Force AST node to an expression to improve diagnostics in pattern position.
+    #[rustc_macro_transparency = "semitransparent"]
+    #[unstable(feature = "liballoc_internals", issue = "none", reason = "implementation detail")]
+    pub macro force_expr($e:expr) {
+        $e
+    }
 }
diff --git a/library/alloc/src/macros.rs b/library/alloc/src/macros.rs
index 7d4eff6185d..3a46763c3f6 100644
--- a/library/alloc/src/macros.rs
+++ b/library/alloc/src/macros.rs
@@ -37,16 +37,16 @@
 #[cfg(not(test))]
 #[macro_export]
 #[stable(feature = "rust1", since = "1.0.0")]
-#[allow_internal_unstable(box_syntax)]
+#[allow_internal_unstable(box_syntax, liballoc_internals)]
 macro_rules! vec {
     () => (
-        $crate::vec::Vec::new()
+        $crate::__export::force_expr!($crate::vec::Vec::new())
     );
     ($elem:expr; $n:expr) => (
-        $crate::vec::from_elem($elem, $n)
+        $crate::__export::force_expr!($crate::vec::from_elem($elem, $n))
     );
     ($($x:expr),+ $(,)?) => (
-        <[_]>::into_vec(box [$($x),+])
+        $crate::__export::force_expr!(<[_]>::into_vec(box [$($x),+]))
     );
 }