Skip to content

Commit a13b57e

Browse files
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
2 parents 77a6c7f + b7191d8 commit a13b57e

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_middle::ty::{self, TyCtxt, TypeSuperVisitable, TypeVisitor};
2222
use rustc_session::lint;
2323
use rustc_span::def_id::DefId;
2424
use rustc_span::symbol::{sym, Ident};
25-
use rustc_span::Span;
25+
use rustc_span::{Span, DUMMY_SP};
2626
use std::fmt;
2727

2828
use crate::errors;
@@ -338,7 +338,17 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
338338

339339
Scope::TraitRefBoundary { .. } => {
340340
// We should only see super trait lifetimes if there is a `Binder` above
341-
assert!(supertrait_bound_vars.is_empty());
341+
// though this may happen when we call `poly_trait_ref_binder_info` with
342+
// an (erroneous, #113423) associated return type bound in an impl header.
343+
if !supertrait_bound_vars.is_empty() {
344+
self.tcx.sess.delay_span_bug(
345+
DUMMY_SP,
346+
format!(
347+
"found supertrait lifetimes without a binder to append \
348+
them to: {supertrait_bound_vars:?}"
349+
),
350+
);
351+
}
342352
break (vec![], BinderScopeType::Normal);
343353
}
344354

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(return_type_notation)]
2+
//~^ WARN the feature `return_type_notation` is incomplete
3+
4+
// Shouldn't ICE when we have a (bad) RTN in an impl header
5+
6+
trait Super1<'a> {
7+
fn bar<'b>() -> bool;
8+
}
9+
10+
impl Super1<'_, bar(): Send> for () {}
11+
//~^ ERROR associated type bindings are not allowed here
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/rtn-in-impl-signature.rs:1:12
3+
|
4+
LL | #![feature(return_type_notation)]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error[E0229]: associated type bindings are not allowed here
11+
--> $DIR/rtn-in-impl-signature.rs:10:17
12+
|
13+
LL | impl Super1<'_, bar(): Send> for () {}
14+
| ^^^^^^^^^^^ associated type not allowed here
15+
16+
error: aborting due to previous error; 1 warning emitted
17+
18+
For more information about this error, try `rustc --explain E0229`.

0 commit comments

Comments
 (0)