about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-07-07 22:12:16 -0700
committerGitHub <noreply@github.com>2023-07-07 22:12:16 -0700
commita13b57e636354c6bc926c710500873fe73ddab04 (patch)
tree7fc602f8fb25574b563a865faa0c73586414ebd3
parent77a6c7f3a16910878f3d03e52f6638ab276d3008 (diff)
parentb7191d8388abfb7c66b5fea9120cdf07c640edfa (diff)
downloadrust-a13b57e636354c6bc926c710500873fe73ddab04.tar.gz
rust-a13b57e636354c6bc926c710500873fe73ddab04.zip
Rollup merge of #113426 - compiler-errors:rtn-in-impl-header, r=fee1-dead
Don't ICE in `resolve_bound_vars` when associated return-type bounds are in bad positions

I couldn't find a better way to avoid hitting this ICE, so let's just delay it.

The problem is that we really shouldn't even be *trying* to visit associated type bounds in `resolve_bound_vars` when they show up in impl headers, but we don't have enough context to do this.

Fixes #113423
-rw-r--r--compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs14
-rw-r--r--tests/ui/async-await/return-type-notation/rtn-in-impl-signature.rs13
-rw-r--r--tests/ui/async-await/return-type-notation/rtn-in-impl-signature.stderr18
3 files changed, 43 insertions, 2 deletions
diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs
index 97a3e01c52a..acd0bcd8e5c 100644
--- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs
+++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs
@@ -22,7 +22,7 @@ use rustc_middle::ty::{self, TyCtxt, TypeSuperVisitable, TypeVisitor};
 use rustc_session::lint;
 use rustc_span::def_id::DefId;
 use rustc_span::symbol::{sym, Ident};
-use rustc_span::Span;
+use rustc_span::{Span, DUMMY_SP};
 use std::fmt;
 
 use crate::errors;
@@ -338,7 +338,17 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
 
                 Scope::TraitRefBoundary { .. } => {
                     // We should only see super trait lifetimes if there is a `Binder` above
-                    assert!(supertrait_bound_vars.is_empty());
+                    // though this may happen when we call `poly_trait_ref_binder_info` with
+                    // an (erroneous, #113423) associated return type bound in an impl header.
+                    if !supertrait_bound_vars.is_empty() {
+                        self.tcx.sess.delay_span_bug(
+                            DUMMY_SP,
+                            format!(
+                                "found supertrait lifetimes without a binder to append \
+                                them to: {supertrait_bound_vars:?}"
+                            ),
+                        );
+                    }
                     break (vec![], BinderScopeType::Normal);
                 }
 
diff --git a/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.rs b/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.rs
new file mode 100644
index 00000000000..1b16a492a7a
--- /dev/null
+++ b/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.rs
@@ -0,0 +1,13 @@
+#![feature(return_type_notation)]
+//~^ WARN the feature `return_type_notation` is incomplete
+
+// Shouldn't ICE when we have a (bad) RTN in an impl header
+
+trait Super1<'a> {
+    fn bar<'b>() -> bool;
+}
+
+impl Super1<'_, bar(): Send> for () {}
+//~^ ERROR associated type bindings are not allowed here
+
+fn main() {}
diff --git a/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.stderr b/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.stderr
new file mode 100644
index 00000000000..52d8168c9d8
--- /dev/null
+++ b/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.stderr
@@ -0,0 +1,18 @@
+warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
+  --> $DIR/rtn-in-impl-signature.rs:1:12
+   |
+LL | #![feature(return_type_notation)]
+   |            ^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
+   = note: `#[warn(incomplete_features)]` on by default
+
+error[E0229]: associated type bindings are not allowed here
+  --> $DIR/rtn-in-impl-signature.rs:10:17
+   |
+LL | impl Super1<'_, bar(): Send> for () {}
+   |                 ^^^^^^^^^^^ associated type not allowed here
+
+error: aborting due to previous error; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0229`.