@@ -12,6 +12,7 @@ use rustc_middle::mir::coverage::CoverageKind;
12
12
use rustc_middle:: mir:: visit:: { NonUseContext , PlaceContext , Visitor } ;
13
13
use rustc_middle:: mir:: * ;
14
14
use rustc_middle:: ty:: adjustment:: PointerCoercion ;
15
+ use rustc_middle:: ty:: print:: with_no_trimmed_paths;
15
16
use rustc_middle:: ty:: {
16
17
self , CoroutineArgsExt , InstanceKind , ScalarInt , Ty , TyCtxt , TypeVisitableExt , Upcast , Variance ,
17
18
} ;
@@ -56,7 +57,7 @@ impl<'tcx> crate::MirPass<'tcx> for Validator {
56
57
ty:: Coroutine ( ..) => ExternAbi :: Rust ,
57
58
// No need to do MIR validation on error bodies
58
59
ty:: Error ( _) => return ,
59
- _ => span_bug ! ( body. span, "unexpected body ty: {body_ty:? }" ) ,
60
+ _ => span_bug ! ( body. span, "unexpected body ty: {body_ty}" ) ,
60
61
} ;
61
62
62
63
ty:: layout:: fn_can_unwind ( tcx, Some ( def_id) , body_abi)
@@ -543,7 +544,13 @@ pub(super) fn validate_types<'tcx>(
543
544
caller_body : & Body < ' tcx > ,
544
545
) -> Vec < ( Location , String ) > {
545
546
let mut type_checker = TypeChecker { body, caller_body, tcx, typing_env, failures : Vec :: new ( ) } ;
546
- type_checker. visit_body ( body) ;
547
+ // The type checker formats a bunch of strings with type names in it, but these strings
548
+ // are not always going to be encountered on the error path since the inliner also uses
549
+ // the validator, and there are certain kinds of inlining (even for valid code) that
550
+ // can cause validation errors (mostly around where clauses and rigid projections).
551
+ with_no_trimmed_paths ! ( {
552
+ type_checker. visit_body( body) ;
553
+ } ) ;
547
554
type_checker. failures
548
555
}
549
556
@@ -655,7 +662,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
655
662
ProjectionElem :: Index ( index) => {
656
663
let index_ty = self . body . local_decls [ index] . ty ;
657
664
if index_ty != self . tcx . types . usize {
658
- self . fail ( location, format ! ( "bad index ({index_ty:? } != usize)" ) )
665
+ self . fail ( location, format ! ( "bad index ({index_ty} != usize)" ) )
659
666
}
660
667
}
661
668
ProjectionElem :: Deref
@@ -664,10 +671,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
664
671
let base_ty = place_ref. ty ( & self . body . local_decls , self . tcx ) . ty ;
665
672
666
673
if base_ty. is_box ( ) {
667
- self . fail (
668
- location,
669
- format ! ( "{base_ty:?} dereferenced after ElaborateBoxDerefs" ) ,
670
- )
674
+ self . fail ( location, format ! ( "{base_ty} dereferenced after ElaborateBoxDerefs" ) )
671
675
}
672
676
}
673
677
ProjectionElem :: Field ( f, ty) => {
@@ -680,7 +684,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
680
684
this. fail (
681
685
location,
682
686
format ! (
683
- "Field projection `{place_ref:?}.{f:?}` specified type `{ty:? }`, but actual type is `{f_ty:? }`"
687
+ "Field projection `{place_ref:?}.{f:?}` specified type `{ty}`, but actual type is `{f_ty}`"
684
688
)
685
689
)
686
690
}
@@ -806,7 +810,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
806
810
self . fail (
807
811
location,
808
812
format ! (
809
- "Failed subtyping {ty:#? } and {:#? }" ,
813
+ "Failed subtyping {ty} and {}" ,
810
814
place_ref. ty( & self . body. local_decls, self . tcx) . ty
811
815
) ,
812
816
)
@@ -826,7 +830,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
826
830
self . fail (
827
831
location,
828
832
format ! (
829
- "Cannot unwrap unsafe binder {binder_ty:?} into type {unwrapped_ty:? }"
833
+ "Cannot unwrap unsafe binder {binder_ty:?} into type {unwrapped_ty}"
830
834
) ,
831
835
) ;
832
836
}
@@ -841,7 +845,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
841
845
if ty. is_union ( ) || ty. is_enum ( ) {
842
846
self . fail (
843
847
START_BLOCK . start_location ( ) ,
844
- format ! ( "invalid type {ty:? } in debuginfo for {:?}" , debuginfo. name) ,
848
+ format ! ( "invalid type {ty} in debuginfo for {:?}" , debuginfo. name) ,
845
849
) ;
846
850
}
847
851
if projection. is_empty ( ) {
@@ -1064,15 +1068,13 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
1064
1068
if !self . mir_assign_valid_types ( a, b) {
1065
1069
self . fail (
1066
1070
location,
1067
- format ! ( "Cannot {op:?} compare incompatible types {a:? } and {b:? }" ) ,
1071
+ format ! ( "Cannot {op:?} compare incompatible types {a} and {b}" ) ,
1068
1072
) ;
1069
1073
}
1070
1074
} else if a != b {
1071
1075
self . fail (
1072
1076
location,
1073
- format ! (
1074
- "Cannot perform binary op {op:?} on unequal types {a:?} and {b:?}"
1075
- ) ,
1077
+ format ! ( "Cannot perform binary op {op:?} on unequal types {a} and {b}" ) ,
1076
1078
) ;
1077
1079
}
1078
1080
}
@@ -1081,7 +1083,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
1081
1083
Offset => {
1082
1084
check_kinds ! ( a, "Cannot offset non-pointer type {:?}" , ty:: RawPtr ( ..) ) ;
1083
1085
if b != self . tcx . types . isize && b != self . tcx . types . usize {
1084
- self . fail ( location, format ! ( "Cannot offset by non-isize type {b:? }" ) ) ;
1086
+ self . fail ( location, format ! ( "Cannot offset by non-isize type {b}" ) ) ;
1085
1087
}
1086
1088
}
1087
1089
Eq | Lt | Le | Ne | Ge | Gt => {
@@ -1313,7 +1315,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
1313
1315
{
1314
1316
self . fail (
1315
1317
location,
1316
- format ! ( "Cannot transmute from non-`Sized` type {op_ty:? }" ) ,
1318
+ format ! ( "Cannot transmute from non-`Sized` type {op_ty}" ) ,
1317
1319
) ;
1318
1320
}
1319
1321
if !self
@@ -1340,7 +1342,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
1340
1342
}
1341
1343
Rvalue :: NullaryOp ( NullOp :: OffsetOf ( indices) , container) => {
1342
1344
let fail_out_of_bounds = |this : & mut Self , location, field, ty| {
1343
- this. fail ( location, format ! ( "Out of bounds field {field:?} for {ty:? }" ) ) ;
1345
+ this. fail ( location, format ! ( "Out of bounds field {field:?} for {ty}" ) ) ;
1344
1346
} ;
1345
1347
1346
1348
let mut current_ty = * container;
@@ -1374,7 +1376,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
1374
1376
_ => {
1375
1377
self . fail (
1376
1378
location,
1377
- format ! ( "Cannot get offset ({variant:?}, {field:?}) from type {current_ty:? }" ) ,
1379
+ format ! ( "Cannot get offset ({variant:?}, {field:?}) from type {current_ty}" ) ,
1378
1380
) ;
1379
1381
return ;
1380
1382
}
@@ -1403,7 +1405,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
1403
1405
if !self . mir_assign_valid_types ( unwrapped_ty, binder_inner_ty) {
1404
1406
self . fail (
1405
1407
location,
1406
- format ! ( "Cannot wrap {unwrapped_ty:? } into unsafe binder {binder_ty:?}" ) ,
1408
+ format ! ( "Cannot wrap {unwrapped_ty} into unsafe binder {binder_ty:?}" ) ,
1407
1409
) ;
1408
1410
}
1409
1411
}
@@ -1489,24 +1491,27 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
1489
1491
// since CopyNonOverlapping is parametrized by 1 type,
1490
1492
// we only need to check that they are equal and not keep an extra parameter.
1491
1493
if !self . mir_assign_valid_types ( op_src_ty, op_dst_ty) {
1492
- self . fail ( location, format ! ( "bad arg ({op_src_ty:? } != {op_dst_ty:? })" ) ) ;
1494
+ self . fail ( location, format ! ( "bad arg ({op_src_ty} != {op_dst_ty})" ) ) ;
1493
1495
}
1494
1496
1495
1497
let op_cnt_ty = count. ty ( & self . body . local_decls , self . tcx ) ;
1496
1498
if op_cnt_ty != self . tcx . types . usize {
1497
- self . fail ( location, format ! ( "bad arg ({op_cnt_ty:? } != usize)" ) )
1499
+ self . fail ( location, format ! ( "bad arg ({op_cnt_ty} != usize)" ) )
1498
1500
}
1499
1501
}
1500
1502
StatementKind :: SetDiscriminant { place, .. } => {
1501
1503
if self . body . phase < MirPhase :: Runtime ( RuntimePhase :: Initial ) {
1502
1504
self . fail ( location, "`SetDiscriminant`is not allowed until deaggregation" ) ;
1503
1505
}
1504
- let pty = place. ty ( & self . body . local_decls , self . tcx ) . ty . kind ( ) ;
1505
- if !matches ! ( pty, ty:: Adt ( ..) | ty:: Coroutine ( ..) | ty:: Alias ( ty:: Opaque , ..) ) {
1506
+ let pty = place. ty ( & self . body . local_decls , self . tcx ) . ty ;
1507
+ if !matches ! (
1508
+ pty. kind( ) ,
1509
+ ty:: Adt ( ..) | ty:: Coroutine ( ..) | ty:: Alias ( ty:: Opaque , ..)
1510
+ ) {
1506
1511
self . fail (
1507
1512
location,
1508
1513
format ! (
1509
- "`SetDiscriminant` is only allowed on ADTs and coroutines, not {pty:? }"
1514
+ "`SetDiscriminant` is only allowed on ADTs and coroutines, not {pty}"
1510
1515
) ,
1511
1516
) ;
1512
1517
}
@@ -1555,7 +1560,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
1555
1560
if ScalarInt :: try_from_uint ( value, size) . is_none ( ) {
1556
1561
self . fail (
1557
1562
location,
1558
- format ! ( "the value {value:#x} is not a proper {switch_ty:? }" ) ,
1563
+ format ! ( "the value {value:#x} is not a proper {switch_ty}" ) ,
1559
1564
)
1560
1565
}
1561
1566
}
0 commit comments