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