From 0b888b841444281f3cb7a0c396705b541f499404 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 2 Nov 2020 01:17:37 +0100 Subject: [PATCH] Make Vec::len() and Vec::is_empty() const --- library/alloc/src/vec.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/alloc/src/vec.rs b/library/alloc/src/vec.rs index 202e3a836384d..ec1121225d5db 100644 --- a/library/alloc/src/vec.rs +++ b/library/alloc/src/vec.rs @@ -1362,7 +1362,8 @@ impl Vec { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn len(&self) -> usize { + #[rustc_const_stable(feature = "const_vec_len", since = "1.49.0")] + pub const fn len(&self) -> usize { self.len } @@ -1378,7 +1379,8 @@ impl Vec { /// assert!(!v.is_empty()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - pub fn is_empty(&self) -> bool { + #[rustc_const_stable(feature = "const_vec_len", since = "1.49.0")] + pub const fn is_empty(&self) -> bool { self.len() == 0 }