3 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -183,9 +183,17 @@ impl TaitConstraintLocator<'_> {
183
183
} ;
184
184
185
185
// Use borrowck to get the type with unerased regions.
186
- let concrete_opaque_types = & self . tcx . mir_borrowck ( item_def_id) . concrete_opaque_types ;
187
- debug ! ( ?concrete_opaque_types) ;
188
- if let Some ( & concrete_type) = concrete_opaque_types. get ( & self . def_id ) {
186
+ let borrowck_results = & self . tcx . mir_borrowck ( item_def_id) ;
187
+
188
+ // If the body was tainted, then assume the opaque may have been constrained and just set it to error.
189
+ if let Some ( guar) = borrowck_results. tainted_by_errors {
190
+ self . found =
191
+ Some ( ty:: OpaqueHiddenType { span : DUMMY_SP , ty : Ty :: new_error ( self . tcx , guar) } ) ;
192
+ return ;
193
+ }
194
+
195
+ debug ! ( ?borrowck_results. concrete_opaque_types) ;
196
+ if let Some ( & concrete_type) = borrowck_results. concrete_opaque_types . get ( & self . def_id ) {
189
197
debug ! ( ?concrete_type, "found constraint" ) ;
190
198
if let Some ( prev) = & mut self . found {
191
199
if concrete_type. ty != prev. ty && !( concrete_type, prev. ty ) . references_error ( ) {
Original file line number Diff line number Diff line change
1
+ #![ feature( type_alias_impl_trait) ]
2
+
3
+ type Tait = impl Copy ;
4
+ // Make sure that this TAIT isn't considered unconstrained...
5
+
6
+ fn empty_opaque ( ) -> Tait {
7
+ if false {
8
+ match empty_opaque ( ) { }
9
+ //~^ ERROR non-empty
10
+ }
11
+ 0u8
12
+ }
13
+
14
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error[E0004]: non-exhaustive patterns: type `Tait` is non-empty
2
+ --> $DIR/unconstrained-due-to-bad-pattern.rs:8:15
3
+ |
4
+ LL | match empty_opaque() {}
5
+ | ^^^^^^^^^^^^^^
6
+ |
7
+ = note: the matched value is of type `Tait`
8
+ help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
9
+ |
10
+ LL ~ match empty_opaque() {
11
+ LL + _ => todo!(),
12
+ LL + }
13
+ |
14
+
15
+ error: aborting due to previous error
16
+
17
+ For more information about this error, try `rustc --explain E0004`.
0 commit comments