about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_ast/src/lib.rs1
-rw-r--r--compiler/rustc_ast/src/tokenstream.rs27
2 files changed, 13 insertions, 15 deletions
diff --git a/compiler/rustc_ast/src/lib.rs b/compiler/rustc_ast/src/lib.rs
index e5435e3a3d4..4d3620ee8b0 100644
--- a/compiler/rustc_ast/src/lib.rs
+++ b/compiler/rustc_ast/src/lib.rs
@@ -15,6 +15,7 @@
 #![feature(if_let_guard)]
 #![cfg_attr(bootstrap, feature(label_break_value))]
 #![feature(let_chains)]
+#![feature(let_else)]
 #![feature(min_specialization)]
 #![feature(negative_impls)]
 #![feature(slice_internals)]
diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs
index debcd172b1a..b27eba9620d 100644
--- a/compiler/rustc_ast/src/tokenstream.rs
+++ b/compiler/rustc_ast/src/tokenstream.rs
@@ -410,19 +410,6 @@ impl TokenStream {
         TokenStream(Lrc::new(self.0.iter().enumerate().map(|(i, tree)| f(i, tree)).collect()))
     }
 
-    fn opt_from_ast(node: &(impl HasAttrs + HasTokens)) -> Option<TokenStream> {
-        let tokens = node.tokens()?;
-        let attrs = node.attrs();
-        let attr_stream = if attrs.is_empty() {
-            tokens.create_token_stream()
-        } else {
-            let attr_data =
-                AttributesData { attrs: attrs.iter().cloned().collect(), tokens: tokens.clone() };
-            AttrTokenStream::new(vec![AttrTokenTree::Attributes(attr_data)])
-        };
-        Some(attr_stream.to_tokenstream())
-    }
-
     // Create a token stream containing a single token with alone spacing.
     pub fn token_alone(kind: TokenKind, span: Span) -> TokenStream {
         TokenStream::new(vec![TokenTree::token_alone(kind, span)])
@@ -439,8 +426,18 @@ impl TokenStream {
     }
 
     pub fn from_ast(node: &(impl HasAttrs + HasSpan + HasTokens + fmt::Debug)) -> TokenStream {
-        TokenStream::opt_from_ast(node)
-            .unwrap_or_else(|| panic!("missing tokens for node at {:?}: {:?}", node.span(), node))
+        let Some(tokens) = node.tokens() else {
+            panic!("missing tokens for node at {:?}: {:?}", node.span(), node);
+        };
+        let attrs = node.attrs();
+        let attr_stream = if attrs.is_empty() {
+            tokens.create_token_stream()
+        } else {
+            let attr_data =
+                AttributesData { attrs: attrs.iter().cloned().collect(), tokens: tokens.clone() };
+            AttrTokenStream::new(vec![AttrTokenTree::Attributes(attr_data)])
+        };
+        attr_stream.to_tokenstream()
     }
 
     pub fn from_nonterminal_ast(nt: &Nonterminal) -> TokenStream {