{"record":{"id":"03d1fae8803620b7","repo":"transact-rs/sqlx","slug":"paths-relative-to-the-current-file-s-directory-are","errorCode":null,"errorMessage":"paths relative to the current file's directory are not currently supported","messagePattern":"paths relative to the current file's directory are not currently supported","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"sqlx-macros-core/src/common.rs","lineNumber":21,"sourceCode":"\npub(crate) fn resolve_path(path: impl AsRef<Path>, err_span: Span) -> syn::Result<PathBuf> {\n    let path = path.as_ref();\n\n    if path.is_absolute() {\n        return Err(syn::Error::new(\n            err_span,\n            \"absolute paths will only work on the current machine\",\n        ));\n    }\n\n    // requires `proc_macro::SourceFile::path()` to be stable\n    // https://github.com/rust-lang/rust/issues/54725\n    if path.is_relative()\n        && path\n            .parent()\n            .is_none_or(|parent| parent.as_os_str().is_empty())\n    {\n        return Err(syn::Error::new(\n            err_span,\n            \"paths relative to the current file's directory are not currently supported\",\n        ));\n    }\n\n    let mut out_path = crate::manifest_dir().map_err(|e| syn::Error::new(err_span, e))?;\n\n    out_path.push(path);\n\n    Ok(out_path)\n}\n","sourceCodeStart":3,"sourceCodeEnd":33,"githubUrl":"https://github.com/transact-rs/sqlx/blob/03af8bcc5711a1935580a54bea249c219a0c217d/sqlx-macros-core/src/common.rs#L3-L33","documentation":"Beyond rejecting absolute paths, sqlx macros also reject bare relative paths that point directly at a file (no parent directory component). Because the macro can only resolve relative to the manifest directory (rustc's `SourceFile::path()` relative resolution is unstable, see rust issue 54725), a single-component path like `\"users.sql\"` is ambiguous and unsupported.","triggerScenarios":"Writing `query_file!(\"users.sql\")` or `query_file!(\"./users.sql\")` — a relative path with no directory component — in any `*_file!` macro.","commonSituations":"Placing a .sql file next to the source file and referencing it by bare filename; assuming the macro resolves relative to the current .rs file; refactoring a nested path down to a bare filename.","solutions":["Prefix the path with a directory relative to the crate root, e.g. `src/queries/users.sql` or `./src/users.sql`","Move the .sql file into a directory (e.g. `queries/`) and reference it as `queries/users.sql`","Remember: paths resolve from the crate's manifest directory, not the current source file"],"exampleFix":"// before\nlet q = query_file!(\"users.sql\");\n// after\nlet q = query_file!(\"src/queries/users.sql\");","handlingStrategy":"validation","validationCode":"let p = std::path::Path::new(file_arg);\nassert!(p.is_relative() && p.parent().map_or(false, |d| !d.as_os_str().is_empty()),\n    \"query file path must include a directory component relative to the crate root\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reference query files with at least one directory, e.g. src/queries/x.sql","Keep .sql files in a dedicated subdirectory of the crate","Remember paths resolve from the manifest dir, not the current .rs file"],"tags":["rust","sqlx","macros","compile-time","paths"],"backgroundTag":"relative-path-unsupported","analyzedSha":"03af8bcc5711a1935580a54bea249c219a0c217d","analyzedAt":"2026-09-03T15:01:28.752Z","contentChangedAt":"2026-09-03T15:01:28.752Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}