Skip to content

Commit c9588d5

Browse files
committed
Hackily fix an opaque type ICE
1 parent e405dab commit c9588d5

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ use rustc_infer::infer::{
1818
use rustc_middle::hir::place::PlaceBase;
1919
use rustc_middle::mir::{ConstraintCategory, ReturnConstraint};
2020
use rustc_middle::ty::subst::InternalSubsts;
21-
use rustc_middle::ty::Region;
2221
use rustc_middle::ty::TypeVisitor;
2322
use rustc_middle::ty::{self, RegionVid, Ty};
23+
use rustc_middle::ty::{Region, TyCtxt};
2424
use rustc_span::symbol::{kw, Ident};
2525
use rustc_span::{Span, DUMMY_SP};
2626

@@ -70,14 +70,16 @@ impl<'tcx> ConstraintDescription for ConstraintCategory<'tcx> {
7070
///
7171
/// Usually we expect this to either be empty or contain a small number of items, so we can avoid
7272
/// allocation most of the time.
73-
#[derive(Default)]
74-
pub(crate) struct RegionErrors<'tcx>(Vec<RegionErrorKind<'tcx>>);
73+
pub(crate) struct RegionErrors<'tcx>(Vec<RegionErrorKind<'tcx>>, TyCtxt<'tcx>);
7574

7675
impl<'tcx> RegionErrors<'tcx> {
76+
pub fn new(tcx: TyCtxt<'tcx>) -> Self {
77+
Self(vec![], tcx)
78+
}
7779
#[track_caller]
7880
pub fn push(&mut self, val: impl Into<RegionErrorKind<'tcx>>) {
7981
let val = val.into();
80-
ty::tls::with(|tcx| tcx.sess.delay_span_bug(DUMMY_SP, "{val:?}"));
82+
self.1.sess.delay_span_bug(DUMMY_SP, "{val:?}");
8183
self.0.push(val);
8284
}
8385
pub fn is_empty(&self) -> bool {

compiler/rustc_borrowck/src/region_infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
562562
let mir_def_id = body.source.def_id();
563563
self.propagate_constraints(body);
564564

565-
let mut errors_buffer = RegionErrors::default();
565+
let mut errors_buffer = RegionErrors::new(infcx.tcx);
566566

567567
// If this is a closure, we can propagate unsatisfied
568568
// `outlives_requirements` to our creator, so create a vector

compiler/rustc_borrowck/src/type_check/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
11591159
let tcx = self.infcx.tcx;
11601160

11611161
for proj in &user_ty.projs {
1162+
if let ty::Alias(ty::Opaque, ..) = curr_projected_ty.ty.kind() {
1163+
// There is nothing that we can compare here if we go through an opaque type.
1164+
// We're always in its defining scope as we can otherwise not project through
1165+
// it, so we're constraining it anyways.
1166+
return Ok(());
1167+
}
11621168
let projected_ty = curr_projected_ty.projection_ty_core(
11631169
tcx,
11641170
self.param_env,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
// check-pass
4+
5+
// issue: https://github.com/rust-lang/rust/issues/104551
6+
7+
fn main() {
8+
type T = impl Sized;
9+
let (_a, _b): T = (1u32, 2u32);
10+
}

0 commit comments

Comments
 (0)