about summary refs log tree commit diff
path: root/compiler/rustc_parse
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-07-10 17:49:50 -0400
committerMichael Goulet <michael@errs.io>2024-07-10 17:49:50 -0400
commit898ed2ffa6c485530af1fbe6117c0deb4290715f (patch)
tree4813396f722c85139d412395a3a9a9c05858de40 /compiler/rustc_parse
parent32c8bfdb11e519c6608ead730b6dfafc6cafb9c5 (diff)
downloadrust-898ed2ffa6c485530af1fbe6117c0deb4290715f.tar.gz
rust-898ed2ffa6c485530af1fbe6117c0deb4290715f.zip
Enforce that ? and for<...> are not combined
Diffstat (limited to 'compiler/rustc_parse')
-rw-r--r--compiler/rustc_parse/messages.ftl3
-rw-r--r--compiler/rustc_parse/src/errors.rs10
-rw-r--r--compiler/rustc_parse/src/parser/ty.rs13
3 files changed, 26 insertions, 0 deletions
diff --git a/compiler/rustc_parse/messages.ftl b/compiler/rustc_parse/messages.ftl
index 5fb59eeb4f3..5b4a5f4dd38 100644
--- a/compiler/rustc_parse/messages.ftl
+++ b/compiler/rustc_parse/messages.ftl
@@ -53,6 +53,9 @@ parse_bare_cr = {$double_quotes ->
 
 parse_bare_cr_in_raw_string = bare CR not allowed in raw string
 
+parse_binder_and_polarity = `for<...>` binder not allowed with `{$polarity}` trait polarity modifier
+    .label = there is not a well-defined meaning for a higher-ranked `{$polarity}` trait
+
 parse_binder_before_modifiers = `for<...>` binder should be placed before trait bound modifiers
     .label = place the `for<...>` binder before any modifiers
 
diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs
index 6738cc4a120..9b18a771fde 100644
--- a/compiler/rustc_parse/src/errors.rs
+++ b/compiler/rustc_parse/src/errors.rs
@@ -3050,3 +3050,13 @@ pub struct BinderBeforeModifiers {
     #[label]
     pub modifiers_span: Span,
 }
+
+#[derive(Diagnostic)]
+#[diag(parse_binder_and_polarity)]
+pub struct BinderAndPolarity {
+    #[primary_span]
+    pub polarity_span: Span,
+    #[label]
+    pub binder_span: Span,
+    pub polarity: &'static str,
+}
diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs
index 306029ca94c..6de778fa9f2 100644
--- a/compiler/rustc_parse/src/parser/ty.rs
+++ b/compiler/rustc_parse/src/parser/ty.rs
@@ -994,6 +994,19 @@ impl<'a> Parser<'a> {
         let modifiers = self.parse_trait_bound_modifiers()?;
         let modifiers_span = modifiers_lo.to(self.prev_token.span);
 
+        if let Some(binder_span) = binder_span {
+            match modifiers.polarity {
+                BoundPolarity::Negative(polarity_span) | BoundPolarity::Maybe(polarity_span) => {
+                    self.dcx().emit_err(errors::BinderAndPolarity {
+                        binder_span,
+                        polarity_span,
+                        polarity: modifiers.polarity.as_str(),
+                    });
+                }
+                BoundPolarity::Positive => {}
+            }
+        }
+
         // Recover erroneous lifetime bound with modifiers or binder.
         // e.g. `T: for<'a> 'a` or `T: ~const 'a`.
         if self.token.is_lifetime() {