]> git.lizzy.rs Git - rust.git/commitdiff
Hackily fix an opaque type ICE
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Mon, 19 Dec 2022 13:14:22 +0000 (13:14 +0000)
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Tue, 20 Dec 2022 13:43:41 +0000 (13:43 +0000)
compiler/rustc_borrowck/src/diagnostics/region_errors.rs
compiler/rustc_borrowck/src/region_infer/mod.rs
compiler/rustc_borrowck/src/type_check/mod.rs
src/test/ui/type-alias-impl-trait/destructuring.rs [new file with mode: 0644]

index 500ce9038bbb9f79c02245b03fe38bf74db1c2d4..bcc8afbfd952d15763d32cd6239c5c129ee8f35b 100644 (file)
@@ -18,9 +18,9 @@
 use rustc_middle::hir::place::PlaceBase;
 use rustc_middle::mir::{ConstraintCategory, ReturnConstraint};
 use rustc_middle::ty::subst::InternalSubsts;
-use rustc_middle::ty::Region;
 use rustc_middle::ty::TypeVisitor;
 use rustc_middle::ty::{self, RegionVid, Ty};
+use rustc_middle::ty::{Region, TyCtxt};
 use rustc_span::symbol::{kw, Ident};
 use rustc_span::{Span, DUMMY_SP};
 
@@ -70,14 +70,16 @@ fn description(&self) -> &'static str {
 ///
 /// Usually we expect this to either be empty or contain a small number of items, so we can avoid
 /// allocation most of the time.
-#[derive(Default)]
-pub(crate) struct RegionErrors<'tcx>(Vec<RegionErrorKind<'tcx>>);
+pub(crate) struct RegionErrors<'tcx>(Vec<RegionErrorKind<'tcx>>, TyCtxt<'tcx>);
 
 impl<'tcx> RegionErrors<'tcx> {
+    pub fn new(tcx: TyCtxt<'tcx>) -> Self {
+        Self(vec![], tcx)
+    }
     #[track_caller]
     pub fn push(&mut self, val: impl Into<RegionErrorKind<'tcx>>) {
         let val = val.into();
-        ty::tls::with(|tcx| tcx.sess.delay_span_bug(DUMMY_SP, "{val:?}"));
+        self.1.sess.delay_span_bug(DUMMY_SP, "{val:?}");
         self.0.push(val);
     }
     pub fn is_empty(&self) -> bool {
index 931732af9041467a3390e5b58fa4be5729dc8d78..308f6e19a73e86b2277985a092a5748a77827bd2 100644 (file)
@@ -562,7 +562,7 @@ pub(super) fn solve(
         let mir_def_id = body.source.def_id();
         self.propagate_constraints(body);
 
-        let mut errors_buffer = RegionErrors::default();
+        let mut errors_buffer = RegionErrors::new(infcx.tcx);
 
         // If this is a closure, we can propagate unsatisfied
         // `outlives_requirements` to our creator, so create a vector
index 2973f8b7f85f9b111c712bc8788b3869b498e6ff..247607ff29e20717196020ee862ae279fbb268b6 100644 (file)
@@ -1159,6 +1159,12 @@ fn relate_type_and_user_type(
         let tcx = self.infcx.tcx;
 
         for proj in &user_ty.projs {
+            if let ty::Alias(ty::Opaque, ..) = curr_projected_ty.ty.kind() {
+                // There is nothing that we can compare here if we go through an opaque type.
+                // We're always in its defining scope as we can otherwise not project through
+                // it, so we're constraining it anyways.
+                return Ok(());
+            }
             let projected_ty = curr_projected_ty.projection_ty_core(
                 tcx,
                 self.param_env,
diff --git a/src/test/ui/type-alias-impl-trait/destructuring.rs b/src/test/ui/type-alias-impl-trait/destructuring.rs
new file mode 100644 (file)
index 0000000..b752e58
--- /dev/null
@@ -0,0 +1,10 @@
+#![feature(type_alias_impl_trait)]
+
+// check-pass
+
+// issue: https://github.com/rust-lang/rust/issues/104551
+
+fn main() {
+    type T = impl Sized;
+    let (_a, _b): T = (1u32, 2u32);
+}