@@ -3552,35 +3552,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3552
3552
) ;
3553
3553
// Try to give some advice about indexing tuples.
3554
3554
if let ty:: Tuple ( types) = base_t. kind ( ) {
3555
- let mut needs_note = true ;
3556
- // If the index is an integer, we can show the actual
3557
- // fixed expression:
3555
+ err. help (
3556
+ "tuples are indexed with dot (`._`): tuple = (tuple.0, tuple.1, ...)" ,
3557
+ ) ;
3558
+ // If index is an unsuffixed integer, show the fixed expression:
3558
3559
if let ExprKind :: Lit ( lit) = idx. kind
3559
3560
&& let ast:: LitKind :: Int ( i, ast:: LitIntType :: Unsuffixed ) = lit. node
3560
- && i. get ( )
3561
- < types
3562
- . len ( )
3563
- . try_into ( )
3564
- . expect ( "expected tuple index to be < usize length" )
3561
+ && i. get ( ) < types. len ( ) . try_into ( ) . expect ( "tuple length fits in u128" )
3565
3562
{
3566
3563
err. span_suggestion (
3567
3564
brackets_span,
3568
- "to access tuple elements , use" ,
3565
+ format ! ( "to access tuple element `{i}` , use" ) ,
3569
3566
format ! ( ".{i}" ) ,
3570
3567
Applicability :: MachineApplicable ,
3571
3568
) ;
3572
- needs_note = false ;
3573
- } else if let ExprKind :: Path ( ..) = idx. peel_borrows ( ) . kind {
3574
- err. span_label (
3575
- idx. span ,
3576
- "cannot access tuple elements at a variable index" ,
3577
- ) ;
3578
- }
3579
- if needs_note {
3580
- err. help (
3581
- "to access tuple elements, use tuple indexing \
3582
- syntax (e.g., `tuple.0`)",
3583
- ) ;
3584
3569
}
3585
3570
}
3586
3571
0 commit comments