{"record":{"id":"6be69f8283e5a471","repo":"rust-lang/rust","slug":"file-locks-not-supported-on-this-platform","errorCode":null,"errorMessage":"file locks not supported on this platform","messagePattern":"file locks not supported on this platform","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"compiler/rustc_data_structures/src/flock/unsupported.rs","lineNumber":10,"sourceCode":"use std::io;\nuse std::path::Path;\n\n#[derive(Debug)]\npub struct Lock(());\n\nimpl Lock {\n    pub fn new(_p: &Path, _wait: bool, _create: bool, _exclusive: bool) -> io::Result<Lock> {\n        let msg = \"file locks not supported on this platform\";\n        Err(io::Error::new(io::ErrorKind::Other, msg))\n    }\n\n    pub fn error_unsupported(_err: &io::Error) -> bool {\n        true\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":17,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_data_structures/src/flock/unsupported.rs#L1-L17","documentation":"Returned by rustc_data_structures::flock::Lock::new on platforms that have no file-locking backend. The cfg_select! block in flock.rs selects a platform-specific module: linux for Linux/Redox, unix for other Unix, windows for Windows, and unsupported for everything else (the _ catch-all). The unsupported module's Lock::new unconditionally returns Err with this message. This means incremental compilation's file locking is entirely unavailable on such targets.","triggerScenarios":"Running rustc (or a tool that uses rustc_data_structures::flock, such as rustdoc or cargo) on a platform that is not Linux, Redox, macOS/other-Unix, or Windows. Examples include WASM targets, certain embedded OSes, or any target where none of the cfg_select arms match except _.","commonSituations":"Cross-compiling from an exotic host; running rustc under a WASM-based sandbox or container; building rustc itself for a tier-3 platform. On mainstream platforms (x86_64-linux, aarch64-darwin, x86_64-windows) this error should never appear.","solutions":["If building rustc for a new platform, implement a flock backend in a new module under src/flock/ and add a cfg_select arm for your target_os.","As a workaround, disable incremental compilation (-C incremental=false or unset CARGO_INCREMENTAL) since the primary consumer of flock is the incremental compilation cache.","If on a mainstream platform, verify your target triple is correct — a misconfigured target can accidentally fall through to unsupported.","For WASM/wasi targets, use a different build strategy that doesn't rely on local file locking."],"exampleFix":"// before: unsupported.rs always errors\npub fn new(_p: &Path, _wait: bool, _create: bool, _exclusive: bool) -> io::Result<Lock> {\n    Err(io::Error::new(io::ErrorKind::Other, \"file locks not supported on this platform\"))\n}\n// after: disable incremental compilation to avoid flock\n// in build config or environment:\n//   CARGO_INCREMENTAL=0\n//   RUSTFLAGS=\"-C incremental=false\"","handlingStrategy":"validation","validationCode":"// Before relying on file locks, check if the platform supports them.\n// On unsupported platforms, disable incremental compilation.\nfn check_flock_available() -> Result<(), String> {\n    let tmp = std::env::temp_dir().join(\"flock_test\");\n    std::fs::write(&tmp, b\"\").ok();\n    match rustc_data_structures::flock::Lock::new(&tmp, false, false, true) {\n        Ok(_) => { std::fs::remove_file(&tmp).ok(); Ok(()) }\n        Err(e) => {\n            std::fs::remove_file(&tmp).ok();\n            Err(format!(\"file locks unavailable: {e}\"))\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"// Lock::new returns io::Result<Lock>. In code that uses flock directly:\nmatch rustc_data_structures::flock::Lock::new(path, wait, create, exclusive) {\n    Ok(lock) => { /* use lock */ },\n    Err(e) if rustc_data_structures::flock::Lock::error_unsupported(&e) => {\n        // gracefully degrade — skip locking on unsupported platforms\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["On exotic platforms, set CARGO_INCREMENTAL=0 to avoid flock entirely.","When porting rustc to a new platform, implement a flock backend module under src/flock/.","Check the target triple — if it falls through to the unsupported module, incremental compilation won't work.","Use cfg_select-compatible platform detection rather than guessing."],"tags":["rustc","flock","platform","incremental-compilation","unsupported"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}