`winit` error with rust-analyzer on Linux

I am editing the winit project on Linux in VS Code and rust-analyzer says there is an error. It is trying to include some macOS specific code. It builds and checks fine with cargo. I filed a report with the project:

I'm on rust-analyzer version 0.3.2593 and I've tried the pre-release version too.

Is this a manifestation of a known issue? Any ideas about how to debug it?

What are your full rust-analyzer settings?

I haven't made any changes to the settings. I have copied the configuration data from the OUTPUT in VS Code in the rust-analyzer Extension drop down option:

Version and Configuration data

2025-09-04 19:27:00.126 [info] Extension version: 0.3.2593
2025-09-04 19:27:00.126 [info] Using configuration {
restartServerOnConfigChange: false,
showUnlinkedFileNotification: true,
showRequestFailedErrorNotification: true,
showDependenciesExplorer: true,
showSyntaxTree: false,
testExplorer: false,
initializeStopped: false,
runnables: {
extraEnv: null,
problemMatcher: [ '$rustc' ],
askBeforeUpdateTest: true,
command: null,
extraArgs: ,
extraTestBinaryArgs: [ '--show-output' ]
},
statusBar: {
clickAction: 'openLogs',
showStatusBar: {
documentSelector: [
{ language: 'rust' },
{ pattern: '/Cargo.toml' },
{ pattern: '
/Cargo.lock' },
{
scheme: 'output',
pattern: 'extension-output-rust-lang.rust-analyzer*'
}
]
}
},
server: { path: null, extraEnv: null },
trace: { server: 'off', extension: false },
debug: {
engine: 'auto',
sourceFileMap: {
'/rustc/': '${env:USERPROFILE}/.rustup/toolchains//lib/rustlib/src/rust'
},
buildBeforeRestart: false,
engineSettings: {}
},
typing: { continueCommentsOnNewline: true, triggerChars: '=.' },
diagnostics: {
previewRustcOutput: false,
useRustcErrorCode: false,
disabled: ,
enable: true,
experimental: { enable: false },
remapPrefix: {},
styleLints: { enable: false },
warningsAsHint: ,
warningsAsInfo:
},
assist: {
emitMustUse: false,
expressionFillDefault: 'todo',
preferSelf: false,
termSearch: { borrowcheck: true, fuel: 1800 }
},
cachePriming: { enable: true, numThreads: 'physical' },
cargo: {
allTargets: true,
autoreload: true,
buildScripts: {
enable: true,
invocationStrategy: 'per_workspace',
overrideCommand: null,
rebuildOnSave: true,
useRustcWrapper: true
},
cfgs: [ 'debug_assertions', 'miri' ],
extraArgs: ,
extraEnv: {},
features: ,
noDefaultFeatures: false,
noDeps: false,
sysroot: 'discover',
sysrootSrc: null,
target: null,
targetDir: null
},
cfg: { setTest: true },
checkOnSave: true,
check: {
allTargets: null,
command: 'check',
extraArgs: ,
extraEnv: {},
features: null,
ignore: ,
invocationStrategy: 'per_workspace',
noDefaultFeatures: null,
overrideCommand: null,
targets: null,
workspace: true
},
completion: {
addSemicolonToUnit: true,
autoAwait: { enable: true },
autoIter: { enable: true },
autoimport: {
enable: true,
exclude: [
{ path: 'core::borrow::Borrow', type: 'methods' },
{ path: 'core::borrow::BorrowMut', type: 'methods' }
]
},
autoself: { enable: true },
callable: { snippets: 'fill_arguments' },
excludeTraits: ,
fullFunctionSignatures: { enable: false },
hideDeprecated: false,
limit: null,
postfix: { enable: true },
privateEditable: { enable: false },
snippets: {
custom: {
Ok: {
postfix: 'ok',
body: 'Ok(${receiver})',
description: 'Wrap the expression in a Result::Ok',
scope: 'expr'
},
'Box::pin': {
postfix: 'pinbox',
body: 'Box::pin(${receiver})',
requires: 'std::boxed::Box',
description: 'Put the expression into a pinned Box',
scope: 'expr'
},
'Arc::new': {
postfix: 'arc',
body: 'Arc::new(${receiver})',
requires: 'std::sync::Arc',
description: 'Put the expression into an Arc',
scope: 'expr'
},
Some: {
postfix: 'some',
body: 'Some(${receiver})',
description: 'Wrap the expression in an Option::Some',
scope: 'expr'
},
Err: {
postfix: 'err',
body: 'Err(${receiver})',
description: 'Wrap the expression in a Result::Err',
scope: 'expr'
},
'Rc::new': {
postfix: 'rc',
body: 'Rc::new(${receiver})',
requires: 'std::rc::Rc',
description: 'Put the expression into an Rc',
scope: 'expr'
}
}
},
termSearch: { enable: false, fuel: 1000 }
},
document: { symbol: { search: { excludeLocals: true } } },
files: { exclude: , watcher: 'client' },
highlightRelated: {
branchExitPoints: { enable: true },
breakPoints: { enable: true },
closureCaptures: { enable: true },
exitPoints: { enable: true },
references: { enable: true },
yieldPoints: { enable: true }
},
hover: {
actions: {
debug: { enable: true },
enable: true,
gotoTypeDef: { enable: true },
implementations: { enable: true },
references: { enable: false },
run: { enable: true },
updateTest: { enable: true }
},
documentation: { enable: true, keywords: { enable: true } },
dropGlue: { enable: true },
links: { enable: true },
maxSubstitutionLength: 20,
memoryLayout: {
alignment: 'hexadecimal',
enable: true,
niches: false,
offset: 'hexadecimal',
padding: null,
size: 'both'
},
show: { enumVariants: 5, fields: 5, traitAssocItems: null }
},
imports: {
granularity: { enforce: false, group: 'crate' },
group: { enable: true },
merge: { glob: true },
preferNoStd: false,
preferPrelude: false,
prefix: 'crate',
prefixExternPrelude: false
},
inlayHints: {
bindingModeHints: { enable: false },
chainingHints: { enable: true },
closingBraceHints: { enable: true, minLines: 25 },
closureCaptureHints: { enable: false },
closureReturnTypeHints: { enable: 'never' },
closureStyle: 'impl_fn',
discriminantHints: { enable: 'never' },
expressionAdjustmentHints: { enable: 'never', hideOutsideUnsafe: false, mode: 'prefix' },
genericParameterHints: {
const: { enable: true },
lifetime: { enable: false },
type: { enable: false }
},
implicitDrops: { enable: false },
implicitSizedBoundHints: { enable: false },
lifetimeElisionHints: { enable: 'never', useParameterNames: false },
maxLength: 25,
parameterHints: { enable: true },
rangeExclusiveHints: { enable: false },
reborrowHints: { enable: 'never' },
renderColons: true,
typeHints: {
enable: true,
hideClosureInitialization: false,
hideClosureParameter: false,
hideNamedConstructor: false
}
},
interpret: { tests: false },
joinLines: {
joinAssignments: true,
joinElseIf: true,
removeTrailingComma: true,
unwrapTrivialBlock: true
},
lens: {
debug: { enable: true },
enable: true,
implementations: { enable: true },
location: 'above_name',
references: {
adt: { enable: false },
enumVariant: { enable: false },
method: { enable: false },
trait: { enable: false }
},
run: { enable: true },
updateTest: { enable: true }
},
linkedProjects: ,
lru: { capacity: null, query: { capacities: {} } },
notifications: { cargoTomlNotFound: true },
numThreads: null,
procMacro: {
attributes: { enable: true },
enable: true,
ignored: {},
server: null
},
references: { excludeImports: false, excludeTests: false },
rustc: { source: null },
rustfmt: {
extraArgs: ,
overrideCommand: null,
rangeFormatting: { enable: false }
},
semanticHighlighting: {
doc: { comment: { inject: { enable: true } } },
nonStandardTokens: true,
operator: { enable: true, specialization: { enable: false } },
punctuation: {
enable: false,
separate: { macro: { bang: false } },
specialization: { enable: false }
},
strings: { enable: true }
},
signatureInfo: { detail: 'full', documentation: { enable: true } },
vfs: { extraIncludes: },
workspace: {
discoverConfig: null,
symbol: {
search: {
excludeImports: false,
kind: 'only_types',
limit: 128,
scope: 'workspace'
}
}
}
}

Is that what you asked for? Thank you!

Wait, where are you getting the rust-analyzer error? Can you attach a screenshot?

The error is in the PROBLEMS tab in VS Code. I have attached a screenshot below:

Okay. This message comes from rustc (you can see in the error), not rust-analyzer, rust-analyzer is just forwarding it. This precludes the chance that this is a bug in rust-analyzer, and means this is most likely a misconfiguration on your part. What is the result if you run the command cargo check --workspace --manifest-path=<path_to_top_level_cargo_toml> --keep-going --all-targets (replace <path_to_top_level_cargo_toml> with the path to the top-level Cargo.toml file)?

Thank you so much! Running cargo check --workspace --manifest-path=./Cargo.toml --keep-going --all-targets gives me the error:

Checking objc2 v0.6.2
error: `objc2` only works on Apple platforms. Pass `--target aarch64-apple-darwin` or similar to compile for macOS.
       (If you're absolutely certain that you're using GNUStep, you can specify that with the `gnustep-x-y` Cargo feature instead).
   --> /home/michael/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/objc2-0.6.2/src/lib.rs:218:1
    |
218 | compile_error!("`objc2` on...gnustep-x-y` Cargo feature instead).");
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^...^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: could not compile `objc2` (lib) due to 1 previous error

It even reproduces with just cargo check --workspace. I'm not that familiar with workspaces so I'm surprised that a normal cargo check in the top level directory doesn't catch the error. Maybe the winit crate should have that --workspace flag in the CI configuration?

I at least have enough info to bisect the issue in the winit crate. It is not present in v0.30.12 but only in master.

Do you have any tips for cargo flags to help me figure out where the problem is coming from?

This is likely some crate in their workspace which they're not checking and fails to compile.

I suggest you report that to them.

Thank you again for the help! They managed to figure it out.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.