Make trailing wildcard unnecessary in assert_rs_matches.

PiperOrigin-RevId: 649128939
Change-Id: I73081ec725db9a9c12a07ea4e0d3d1b6425083a0
diff --git a/bazel/llvm.bzl b/bazel/llvm.bzl
index 2be7eff..68f95fc 100644
--- a/bazel/llvm.bzl
+++ b/bazel/llvm.bzl
@@ -53,7 +53,7 @@
             executable = False,
         )
 
-LLVM_COMMIT_SHA = "c5b67dde981d81f9bbd9a6328d5c1eb4297ed3b4"
+LLVM_COMMIT_SHA = "6461b921fd06b1c812f1172685b8b7edc0608af7"
 
 def llvm_loader_repository_dependencies():
     # This *declares* the dependency, but it won't actually be *downloaded* unless it's used.
diff --git a/common/BUILD b/common/BUILD
index 71aa63c..b552c2f 100644
--- a/common/BUILD
+++ b/common/BUILD
@@ -174,6 +174,7 @@
         ":token_stream_printer",
         "@crate_index//:anyhow",
         "@crate_index//:proc-macro2",
+        "@crate_index//:quote",
     ],
 )
 
diff --git a/common/token_stream_matchers.rs b/common/token_stream_matchers.rs
index 8db1576..c3ecde0 100644
--- a/common/token_stream_matchers.rs
+++ b/common/token_stream_matchers.rs
@@ -37,6 +37,7 @@
 ///       quote!{ void foo() { bar(); } },
 ///       quote!{ void ... bar() });
 /// ```
+
 #[macro_export]
 macro_rules! assert_cc_matches {
     ($input:expr, $pattern:expr $(,)*) => {
@@ -98,6 +99,7 @@
     use anyhow::{anyhow, Result};
     pub use proc_macro2::TokenStream;
     use proc_macro2::TokenTree;
+    use quote::quote;
     use std::iter;
     pub use token_stream_printer::{
         cc_tokens_to_formatted_string_for_tests, rs_tokens_to_formatted_string,
@@ -163,11 +165,16 @@
 
         let iter = input.clone().into_iter();
         let mut best_mismatch = Mismatch::for_no_partial_match();
+        let preprocessed_pattern = if !format!("{}", pattern).ends_with("...") {
+            quote! { #pattern ... }
+        } else {
+            pattern.clone()
+        };
 
         let mut stack = vec![iter];
         while let Some(mut iter) = stack.pop() {
             loop {
-                match match_prefix(iter.clone(), pattern.clone()) {
+                match match_prefix(iter.clone(), preprocessed_pattern.clone()) {
                     MatchInfo::Match { input_suffix: _ } => return Ok(()),
                     MatchInfo::Mismatch(mismatch) => {
                         if best_mismatch.match_length < mismatch.match_length {
@@ -280,7 +287,6 @@
         if is_wildcard(to_stream(&pattern_iter)) {
             return MatchInfo::Match { input_suffix: TokenStream::new() };
         }
-
         update_best_mismatch(Mismatch::for_input_ended(
             match_counter,
             to_stream(&pattern_iter),
@@ -504,7 +510,7 @@
             r#"expected 'B' but got 'A'
 
 Caused by:
-    0: expected 'struct B' got 'struct A { int a ; int b ; } ;'
+    0: expected 'struct B ...' got 'struct A { int a ; int b ; } ;'
     1: input:
        
        ```
@@ -531,7 +537,7 @@
             "expected 'B' but got 'A'
 
 Caused by:
-    0: expected 'struct B' got 'struct A { a : i64 , b : i64 }'
+    0: expected 'struct B ...' got 'struct A { a : i64 , b : i64 }'
     1: input:\n       \n       ```
        struct A {
            a: i64,
@@ -552,7 +558,7 @@
                 )
                 .expect_err("unexpected match")
             ),
-            r#"expected 'struct X { }' but the input already ended: expected 'fn foo () { } struct X { }' got 'fn foo () { }': input:
+            r#"expected 'struct X { } ...' but the input already ended: expected 'fn foo () { } struct X { } ...' got 'fn foo () { }': input:
 
 ```
 fn foo() {}
@@ -573,7 +579,7 @@
                 )
                 .expect_err("unexpected match")
             ),
-            r#"expected delimiter Parenthesis for group '()' but got Brace for group '{ }': expected 'fn foo () ()' got 'fn foo () { }': input:
+            r#"expected delimiter Parenthesis for group '()' but got Brace for group '{ }': expected 'fn foo () () ...' got 'fn foo () { }': input:
 
 ```
 fn foo() {}
@@ -596,7 +602,7 @@
             ),
             "expected 'c' but got 'b': \
              expected 'let a = 1 ; let c = 2 ;' got 'let a = 1 ; let b = 2 ;': \
-             expected 'fn foo () { let a = 1 ; let c = 2 ; }' \
+             expected 'fn foo () { let a = 1 ; let c = 2 ; } ...' \
              got 'fn foo () { let a = 1 ; let b = 2 ; }': \
              input:\n\n```\nfn foo() {\n    let a = 1;\n    let b = 2;\n}\n\n```"
         );
@@ -640,7 +646,7 @@
                 )
                 .expect_err("unexpected match")
             ),
-            r#"matched the entire pattern but the input still contained 'drop_impl () ;': expected 'fn drop (& mut self) { }' got 'fn drop (& mut self) { drop_impl () ; }': input:
+            r#"matched the entire pattern but the input still contained 'drop_impl () ;': expected 'fn drop (& mut self) { } ...' got 'fn drop (& mut self) { drop_impl () ; }': input:
 
 ```
 impl Drop {
@@ -661,7 +667,7 @@
                 )
                 .expect_err("unexpected match")
             ),
-            r#"matched the entire pattern but the input still contained 'drop_impl2 () ;': expected 'fn drop (& mut self) { drop_impl1 () ; }' got 'fn drop (& mut self) { drop_impl1 () ; drop_impl2 () ; }': input:
+            r#"matched the entire pattern but the input still contained 'drop_impl2 () ;': expected 'fn drop (& mut self) { drop_impl1 () ; } ...' got 'fn drop (& mut self) { drop_impl1 () ; drop_impl2 () ; }': input:
 
 ```
 impl Drop {
@@ -735,7 +741,7 @@
             // the error message shows "longer match" with more tokens consumed by the wildcard
             "expected 'c' but got 'b': \
             expected 'c' got 'b b': \
-            expected '[a ... c]' got '[a b b]': \
+            expected '[a ... c] ...' got '[a b b]': \
             input:\n\n```\n[a b b]\n```"
         );
         assert_eq!(
@@ -751,7 +757,7 @@
             // the error message shows "longer match" with branching off the wildcard earlier
             "expected 'c' but got 'b': \
             expected 'b c' got 'b b': \
-            expected '[a ... b c]' got '[a b b]': \
+            expected '[a ... b c] ...' got '[a b b]': \
             input:\n\n```\n[a b b]\n```"
         );
     }
@@ -783,4 +789,17 @@
             },
         );
     }
+
+    #[test]
+    fn test_assert_rs_matches_does_not_need_trailing_wildcard() {
+        assert_rs_matches!(
+            quote! {
+                fn f() -> f32 {}
+                fn g() {}
+            },
+            quote! {
+                fn ...() -> f32 {}
+            }
+        );
+    }
 }