@@ -349,10 +349,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
349
349
fn on_unimplemented_note (
350
350
& self ,
351
351
trait_ref : ty:: PolyTraitRef < ' tcx > ,
352
- obligation : & PredicateObligation < ' tcx > ) ->
353
- OnUnimplementedNote
354
- {
355
- let def_id = self . impl_similar_to ( trait_ref, obligation)
352
+ obligation : & PredicateObligation < ' tcx > ,
353
+ ) -> OnUnimplementedNote {
354
+ let def_id = self . impl_similar_to ( trait_ref, obligation)
356
355
. unwrap_or ( trait_ref. def_id ( ) ) ;
357
356
let trait_ref = * trait_ref. skip_binder ( ) ;
358
357
@@ -410,6 +409,37 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
410
409
flags. push ( ( "crate_local" . to_owned ( ) , None ) ) ;
411
410
}
412
411
412
+ // Allow targetting all integers using `{integral}`, even if the exact type was resolved
413
+ if self_ty. is_integral ( ) {
414
+ flags. push ( ( "_Self" . to_owned ( ) , Some ( "{integral}" . to_owned ( ) ) ) ) ;
415
+ }
416
+
417
+ if let ty:: Array ( aty, len) = self_ty. sty {
418
+ flags. push ( ( "_Self" . to_owned ( ) , Some ( "[]" . to_owned ( ) ) ) ) ;
419
+ flags. push ( ( "_Self" . to_owned ( ) , Some ( format ! ( "[{}]" , aty) ) ) ) ;
420
+ if let Some ( def) = aty. ty_adt_def ( ) {
421
+ // We also want to be able to select the array's type's original
422
+ // signature with no type arguments resolved
423
+ flags. push ( (
424
+ "_Self" . to_owned ( ) ,
425
+ Some ( format ! ( "[{}]" , self . tcx. type_of( def. did) . to_string( ) ) ) ,
426
+ ) ) ;
427
+ if let Some ( len) = len. val . try_to_scalar ( ) . and_then ( |scalar| {
428
+ scalar. to_u64 ( ) . ok ( )
429
+ } ) {
430
+ flags. push ( (
431
+ "_Self" . to_owned ( ) ,
432
+ Some ( format ! ( "[{}; {}]" , self . tcx. type_of( def. did) . to_string( ) , len) ) ,
433
+ ) ) ;
434
+ } else {
435
+ flags. push ( (
436
+ "_Self" . to_owned ( ) ,
437
+ Some ( format ! ( "[{}; _]" , self . tcx. type_of( def. did) . to_string( ) ) ) ,
438
+ ) ) ;
439
+ }
440
+ }
441
+ }
442
+
413
443
if let Ok ( Some ( command) ) = OnUnimplementedDirective :: of_item (
414
444
self . tcx , trait_ref. def_id , def_id
415
445
) {
0 commit comments