@@ -3551,35 +3551,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
35513551 ) ;
35523552 // Try to give some advice about indexing tuples.
35533553 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:
35573558 if let ExprKind :: Lit ( lit) = idx. kind
35583559 && 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" )
35643561 {
35653562 err. span_suggestion (
35663563 brackets_span,
3567- "to access tuple elements , use" ,
3564+ format ! ( "to access tuple element `{i}` , use" ) ,
35683565 format ! ( ".{i}" ) ,
35693566 Applicability :: MachineApplicable ,
35703567 ) ;
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- ) ;
35833568 }
35843569 }
35853570
0 commit comments