summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorLeón Orell Valerian Liehr <me@fmease.dev>2025-09-10 21:41:00 +0200
committerLeón Orell Valerian Liehr <me@fmease.dev>2025-09-11 06:39:27 +0200
commit58afb55adc1e4b66c39870da5a1b0a11aa129225 (patch)
tree977de41e0ffc244346fe07d9cf38ad478d9df5e2 /tests
parent1c785abde778e1173dce1aba1ae471814c8fa1ab (diff)
downloadrust-58afb55adc1e4b66c39870da5a1b0a11aa129225.tar.gz
rust-58afb55adc1e4b66c39870da5a1b0a11aa129225.zip
Less greedily parse `[const]` bounds
(cherry picked from commit f5dad62d4cd)
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/traits/const-traits/macro-maybe-const-trait-bounds.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/ui/traits/const-traits/macro-maybe-const-trait-bounds.rs b/tests/ui/traits/const-traits/macro-maybe-const-trait-bounds.rs
new file mode 100644
index 00000000000..75077577b8c
--- /dev/null
+++ b/tests/ui/traits/const-traits/macro-maybe-const-trait-bounds.rs
@@ -0,0 +1,25 @@
+// Ensure that we don't consider `[` to begin trait bounds to contain breakages.
+// Only `[const]` in its entirety begins a trait bound.
+// See also test `macro-const-trait-bound-theoretical-regression.rs`.
+
+//@ check-pass (KEEP THIS AS A PASSING TEST!)
+// Setting the edition to >2015 since we didn't regress `check! { dyn [const] Trait }` in Rust 2015.
+// See also test `traits/const-traits/macro-dyn-const-2015.rs`.
+//@ edition:2018
+
+macro_rules! check {
+    ($ty:ty) => { compile_error!("ty"); }; // KEEP THIS RULE FIRST AND AS IS!
+
+    // DON'T MODIFY THE MATCHERS BELOW UNLESS THE CONST TRAIT MODIFIER SYNTAX CHANGES!
+
+    (dyn [$($any:tt)*] Trait) => { /* KEEP THIS EMPTY! */ };
+    (impl [$($any:tt)*] Trait) => { /* KEEP THIS EMPTY! */ };
+}
+
+check!(dyn [T] Trait);
+
+// issue: <https://github.com/rust-lang/rust/issues/146417>
+check!(impl [T] Trait);
+check!(impl [T: Bound] Trait);
+
+fn main() {}