Skip to content

cargo fmt fails to write fixes for "trailing whitespace" despite correct file permissions #6719

@altunenes

Description

@altunenes

Hi! When running cargo fmt, rustfmt correctly identifies "left behind trailing whitespace" errors, but it fails to write the fixes to the file. It exits with the error warning: rustfmt has failed to format.

This issue occurs even when:

  • File and directory permissions are all correct (owner rw- on the file, rwx on the directory).
  • The file has no immutable flags (like uchg on macOS).
  • The file is demonstrably writable by the same user (e.g., echo " " >> ... works successfully).
  • No other programs (like an IDE) have the file open.
  • It made other adjustments for this specific file -video.rs- (meaning the fmt command made changes to the file but caused errors in some places).

errors:

cuneus git:(cargo-fmt) cargo fmt
error[internal]: left behind trailing whitespace
   --> /Users/enes/Desktop/cuneus/src/gst/video.rs:185:185:1
    |
185 |             
    | ^^^^^^^^^^^^
    |

error[internal]: left behind trailing whitespace
   --> /Users/enes/Desktop/cuneus/src/gst/video.rs:190:190:1
    |
190 |             
    | ^^^^^^^^^^^^
    |

error[internal]: left behind trailing whitespace
   --> /Users/enes/Desktop/cuneus/src/gst/video.rs:195:195:1
    |
195 |                         
    | ^^^^^^^^^^^^^^^^^^^^^^^^
    |

error[internal]: left behind trailing whitespace
   --> /Users/enes/Desktop/cuneus/src/gst/video.rs:200:200:1
    |
200 |                             
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |

error[internal]: left behind trailing whitespace
   --> /Users/enes/Desktop/cuneus/src/gst/video.rs:203:203:1
    |
203 |                             
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |

error[internal]: left behind trailing whitespace
   --> /Users/enes/Desktop/cuneus/src/gst/video.rs:218:218:1
    |
218 |                             
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |

error[internal]: left behind trailing whitespace
   --> /Users/enes/Desktop/cuneus/src/gst/video.rs:225:225:1
    |
225 |                             
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |

error[internal]: left behind trailing whitespace
   --> /Users/enes/Desktop/cuneus/src/gst/video.rs:229:229:1
    |
229 |                             
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |

error[internal]: left behind trailing whitespace
   --> /Users/enes/Desktop/cuneus/src/gst/video.rs:243:243:1
    |
243 |                                 
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |

error[internal]: left behind trailing whitespace
   --> /Users/enes/Desktop/cuneus/src/gst/video.rs:246:246:1
    |
246 |                                 
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |

error[internal]: left behind trailing whitespace
   --> /Users/enes/Desktop/cuneus/src/gst/video.rs:250:250:1
    |
250 |                                 
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |

error[internal]: left behind trailing whitespace
   --> /Users/enes/Desktop/cuneus/src/gst/video.rs:254:254:116
    |
254 |                                     .max_by(|(_, a), (_, b)| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal)) 
    |                                                                                                                    ^
    |

error[internal]: left behind trailing whitespace
   --> /Users/enes/Desktop/cuneus/src/gst/video.rs:258:258:1
    |
258 |                                 
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |

error[internal]: left behind trailing whitespace
   --> /Users/enes/Desktop/cuneus/src/gst/video.rs:293:293:1
    |
293 |                                 
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |

error[internal]: left behind trailing whitespace
   --> /Users/enes/Desktop/cuneus/src/gst/video.rs:306:306:1
    |
306 |             
    | ^^^^^^^^^^^^
    |

warning: rustfmt has failed to format. See previous 15 errors.

file:
https://github.com/altunenes/cuneus/blob/cargo-fmt/src/gst/video.rs

rustc --version && rustfmt --version && sw_vers
rustc 1.88.0 (6b00bc388 2025-06-23)
rustfmt 1.8.0-stable (6b00bc3880 2025-06-23)
ProductName:		macOS
ProductVersion:		26.0.1
BuildVersion:		25A362

to fix it manually:

sed -i '' 's/[[:space:]]*$//' /Users/enes/Desktop/cuneus/src/gst/video.rs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions