From 39a03779f8412c776cebaca7173369dbc0025d50 Mon Sep 17 00:00:00 2001 From: lcnr Date: Thu, 28 Apr 2022 13:48:54 +0200 Subject: correctly deal with user type ascriptions in pat --- compiler/rustc_middle/src/thir.rs | 50 +++++++-------------------------------- 1 file changed, 9 insertions(+), 41 deletions(-) (limited to 'compiler/rustc_middle/src') diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index 26e070af764..b99e7573000 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -18,15 +18,11 @@ use rustc_index::vec::IndexVec; use rustc_middle::infer::canonical::Canonical; use rustc_middle::middle::region; use rustc_middle::mir::interpret::AllocId; -use rustc_middle::mir::{ - self, BinOp, BorrowKind, FakeReadCause, Field, Mutability, UnOp, UserTypeProjection, -}; +use rustc_middle::mir::{self, BinOp, BorrowKind, FakeReadCause, Field, Mutability, UnOp}; use rustc_middle::ty::adjustment::PointerCast; use rustc_middle::ty::subst::SubstsRef; +use rustc_middle::ty::CanonicalUserTypeAnnotation; use rustc_middle::ty::{self, AdtDef, Ty, UpvarSubsts, UserType}; -use rustc_middle::ty::{ - CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, -}; use rustc_span::{Span, Symbol, DUMMY_SP}; use rustc_target::abi::VariantIdx; use rustc_target::asm::InlineAsmRegOrRegClass; @@ -540,13 +536,13 @@ pub enum BindingMode { ByRef(BorrowKind), } -#[derive(Clone, Debug, PartialEq, HashStable)] +#[derive(Clone, Debug, HashStable)] pub struct FieldPat<'tcx> { pub field: Field, pub pattern: Pat<'tcx>, } -#[derive(Clone, Debug, PartialEq, HashStable)] +#[derive(Clone, Debug, HashStable)] pub struct Pat<'tcx> { pub ty: Ty<'tcx>, pub span: Span, @@ -559,37 +555,10 @@ impl<'tcx> Pat<'tcx> { } } -#[derive(Copy, Clone, Debug, PartialEq, HashStable)] -pub struct PatTyProj<'tcx> { - pub user_ty: CanonicalUserType<'tcx>, -} - -impl<'tcx> PatTyProj<'tcx> { - pub fn from_user_type(user_annotation: CanonicalUserType<'tcx>) -> Self { - Self { user_ty: user_annotation } - } - - pub fn user_ty( - self, - annotations: &mut CanonicalUserTypeAnnotations<'tcx>, - inferred_ty: Ty<'tcx>, - span: Span, - ) -> UserTypeProjection { - UserTypeProjection { - base: annotations.push(CanonicalUserTypeAnnotation { - span, - user_ty: self.user_ty, - inferred_ty, - }), - projs: Vec::new(), - } - } -} - -#[derive(Copy, Clone, Debug, PartialEq, HashStable)] +#[derive(Clone, Debug, HashStable)] pub struct Ascription<'tcx> { - pub user_ty: PatTyProj<'tcx>, - /// Variance to use when relating the type `user_ty` to the **type of the value being + pub annotation: CanonicalUserTypeAnnotation<'tcx>, + /// Variance to use when relating the `user_ty` to the **type of the value being /// matched**. Typically, this is `Variance::Covariant`, since the value being matched must /// have a type that is some subtype of the ascribed type. /// @@ -608,12 +577,11 @@ pub struct Ascription<'tcx> { /// probably be checking for a `PartialEq` impl instead, but this preserves the behavior /// of the old type-check for now. See #57280 for details. pub variance: ty::Variance, - pub user_ty_span: Span, } -#[derive(Clone, Debug, PartialEq, HashStable)] +#[derive(Clone, Debug, HashStable)] pub enum PatKind<'tcx> { - /// A wildward pattern: `_`. + /// A wildcard pattern: `_`. Wild, AscribeUserType { -- cgit 1.4.1-3-g733a5 From db11c1939cfca105116a5cdf13f63e5005471aad Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 20 May 2022 14:46:18 +0200 Subject: update mir user type printing and apparently fix an ICE --- compiler/rustc_middle/src/mir/pretty.rs | 5 ++-- .../cross_inference_pattern_bug.rs | 20 ++----------- .../cross_inference_pattern_bug.stderr | 34 ++++------------------ 3 files changed, 11 insertions(+), 48 deletions(-) (limited to 'compiler/rustc_middle/src') diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index 8111409b8bc..eaa68bf1b38 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -1007,10 +1007,11 @@ fn write_user_type_annotations( for (index, annotation) in body.user_type_annotations.iter_enumerated() { writeln!( w, - "| {:?}: {:?} at {}", + "| {:?}: user_ty: {:?}, span: {}, inferred_ty: {:?}", index.index(), annotation.user_ty, - tcx.sess.source_map().span_to_embeddable_string(annotation.span) + tcx.sess.source_map().span_to_embeddable_string(annotation.span), + annotation.inferred_ty, )?; } if !body.user_type_annotations.is_empty() { diff --git a/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug.rs b/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug.rs index 9ad7cad39d0..811832848d9 100644 --- a/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug.rs +++ b/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug.rs @@ -1,24 +1,8 @@ -// known-bug -// failure-status: 101 -// compile-flags: --edition=2021 --crate-type=lib -// rustc-env:RUST_BACKTRACE=0 - -// normalize-stderr-test "thread 'rustc' panicked.*" -> "thread 'rustc' panicked" -// normalize-stderr-test "note:.*RUST_BACKTRACE=1.*\n" -> "" -// normalize-stderr-test "\nerror: internal compiler error.*\n\n" -> "" -// normalize-stderr-test "note:.*unexpectedly panicked.*\n\n" -> "" -// normalize-stderr-test "note: we would appreciate a bug report.*\n\n" -> "" -// normalize-stderr-test "note: compiler flags.*\n\n" -> "" -// normalize-stderr-test "note: rustc.*running on.*\n\n" -> "" -// normalize-stderr-test "#.*\n" -> "" -// normalize-stderr-test ".*delayed.*\n" -> "" - -// tracked in https://github.com/rust-lang/rust/issues/96572 - +// compile-flags: --edition=2021 #![feature(type_alias_impl_trait)] fn main() { - type T = impl Copy; + type T = impl Copy; //~ ERROR unconstrained opaque type let foo: T = (1u32, 2u32); let (a, b): (u32, u32) = foo; } diff --git a/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug.stderr b/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug.stderr index 84d2705bf24..03b172e6de5 100644 --- a/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug.stderr +++ b/src/test/ui/type-alias-impl-trait/cross_inference_pattern_bug.stderr @@ -1,32 +1,10 @@ -error: internal compiler error: no errors encountered even though `delay_span_bug` issued - -error: internal compiler error: broken MIR in DefId(0:3 ~ cross_inference_pattern_bug[646d]::main) ((_1.0: u32)): can't project out of PlaceTy { ty: main::T, variant_index: None } - --> $DIR/cross_inference_pattern_bug.rs:23:10 - | -LL | let (a, b): (u32, u32) = foo; - | ^ - | - -error: internal compiler error: TyKind::Error constructed but no error reported - | - -error: internal compiler error: TyKind::Error constructed but no error reported +error: unconstrained opaque type + --> $DIR/cross_inference_pattern_bug.rs:5:14 | - -error: internal compiler error: broken MIR in DefId(0:3 ~ cross_inference_pattern_bug[646d]::main) ((_1.1: u32)): can't project out of PlaceTy { ty: main::T, variant_index: None } - --> $DIR/cross_inference_pattern_bug.rs:23:13 - | -LL | let (a, b): (u32, u32) = foo; - | ^ - | - -error: internal compiler error: TyKind::Error constructed but no error reported - | - -error: internal compiler error: TyKind::Error constructed but no error reported +LL | type T = impl Copy; + | ^^^^^^^^^ | + = note: `T` must be used in combination with a concrete type within the same module -thread 'rustc' panicked +error: aborting due to previous error -query stack during panic: -end of query stack -- cgit 1.4.1-3-g733a5