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