Skip to content

Commit 705671e

Browse files
authored
Rollup merge of #72019 - matthewjasper:dont-skip-binder, r=davidtwco
Fix debug assertion in error code Closes #70813
2 parents dd595fa + 619c605 commit 705671e

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

Diff for: src/librustc_trait_selection/traits/error_reporting/suggestions.rs

+9
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
691691
}
692692

693693
if let ty::Ref(region, t_type, mutability) = trait_ref.skip_binder().self_ty().kind {
694+
if region.is_late_bound() || t_type.has_escaping_bound_vars() {
695+
// Avoid debug assertion in `mk_obligation_for_def_id`.
696+
//
697+
// If the self type has escaping bound vars then it's not
698+
// going to be the type of an expression, so the suggestion
699+
// probably won't apply anyway.
700+
return;
701+
}
702+
694703
let trait_type = match mutability {
695704
hir::Mutability::Mut => self.tcx.mk_imm_ref(region, t_type),
696705
hir::Mutability::Not => self.tcx.mk_mut_ref(region, t_type),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Regression test for #70813 (this used to trigger a debug assertion)
2+
3+
trait Trait {}
4+
5+
struct S;
6+
7+
impl<'a> Trait for &'a mut S {}
8+
9+
fn foo<X>(_: X)
10+
where
11+
for<'b> &'b X: Trait,
12+
{
13+
}
14+
15+
fn main() {
16+
let s = S;
17+
foo::<S>(s); //~ ERROR the trait bound `for<'b> &'b S: Trait` is not satisfied
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0277]: the trait bound `for<'b> &'b S: Trait` is not satisfied
2+
--> $DIR/imm-ref-trait-object-literal-bound-regions.rs:17:5
3+
|
4+
LL | fn foo<X>(_: X)
5+
| --- required by a bound in this
6+
LL | where
7+
LL | for<'b> &'b X: Trait,
8+
| ----- required by this bound in `foo`
9+
...
10+
LL | foo::<S>(s);
11+
| ^^^^^^^^ the trait `for<'b> Trait` is not implemented for `&'b S`
12+
|
13+
= help: the following implementations were found:
14+
<&'a mut S as Trait>
15+
16+
error: aborting due to previous error
17+
18+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)