Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust-lang/rust: "file not included in module tree" in libcore, broken go to definition #9203

Closed
Tracked by #8915
lf- opened this issue Jun 10, 2021 · 15 comments · Fixed by #9227
Closed
Tracked by #8915

rust-lang/rust: "file not included in module tree" in libcore, broken go to definition #9203

lf- opened this issue Jun 10, 2021 · 15 comments · Fixed by #9227

Comments

@lf-
Copy link
Contributor

lf- commented Jun 10, 2021

When I open library/core/src/str/converts.rs in my editor, I get a "file not included in module tree" diagnostic and go to definition doesn't work. Also, go to definition on e.g. pub mod ffi in library/core/src/lib.rs does not work. This is unfortunate for working on libcore.

I am using this config from the recommended page:

{
    "rust-analyzer.checkOnSave.overrideCommand": [
        "./x.py",
        "check",
        "--json-output"
    ],
    "rust-analyzer.rustfmt.overrideCommand": [
      "./build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt"
    ],
    "rust-analyzer.cargo.runBuildScripts": false,
    "rust-analyzer.procMacro.enable": false
}
Log

[INFO rust_analyzer] server version 09e40391b 2021-06-10 dev will start
[INFO rust_analyzer] InitializeParams: {"processId":1303302,"rootPath":"/home/jade/dev/rust","rootUri":"file:///home/jade/dev/rust","capabilities":{"workspace":{"applyEdit":true,"workspaceEdit":{"documentChanges":true,"resourceOperations":["create","rename","delete"],"failureHandling":"textOnlyTransactional"},"didChangeConfiguration":{"dynamicRegistration"
:true},"didChangeWatchedFiles":{"dynamicRegistration":true},"symbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"tagSupport":{"valueSet":[1]}},"executeCommand":{"dynamicRegistration":true},"configuration":true,"workspaceFolders":true},"textDocument":{"publishDiagnostics":{"relatedInformation":true,"versionSupport":false,"tagSupport":{"valueSet":[1,2]}},"synchronization":{"dynamicRegistration":true,"willSave":true,"willSaveWaitUntil":true,"didSave":true},"completion":{"dynamicRegistration":true,"contextSupport":true,"completionItem":{"snippetSupport":true,"commitCharactersSupport":true,"documentationFormat":["markdown","plaintext"],"deprecatedSupport":true,"preselectSupport":true,"tagSupport":{"valueSet":[1]},"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]}
},"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]}},"hover":{"dynamicRegistration":true,"contentFormat":["markdown","plaintext"]},"signatureHelp":{"dynamicRegistration":true,"contextSupport":true,"signatureInformation":{"documentationFormat":["markdown","plaintext"],"activeParameterSupport":true,"parameterInformation":{"labelOffsetSupport":true}}},"definition":{"dynamicRegistration":true},"references":{"dynamicRegistration":true},"documentHighlight":{"dynamicRegistration":true},"documentSymbol":{"dynamicRegistration":true,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalDocumentSymbolSupport":true,"tagSupport":{"valueSet":[1]}},"codeAction":{"dynamicRegistration":true,"isPreferredSupport"
:true,"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}},"resolveSupport":{"properties":["edit"]}},"codeLens":{"dynamicRegistration":true},"formatting":{"dynamicRegistration":true},"rangeFormatting":{"dynamicRegistration":true},"onTypeFormatting":{"dynamicRegistration":true},"rename":{"dynamicRegistration":true,"prepareSupport":true},"documentLink":{"dynamicRegistration":true,"tooltipSupport":true},"typeDefinition":{"dynamicRegistration":true},"implementation":{"dynamicRegistration":true},"declaration":{"dynamicRegistration":true},"colorProvider":{"dynamicRegistration":true},"foldingRange":{"dynamicRegistration":true,"rangeLimit":5000,"lineFoldingOnly":true},"selectionRange":{"dynamicRegistration":true}},"window":{"workDoneProgress":true},"experimental":{"snippetTextEdit":true,"resolveCodeAction":true,"serverStatusNotification":true}},"initializationOptions":{"enable":true,"terminal":{"startinsert":false},"debug":{"runtime":"termdebug"
,"vimspector":{"configuration":{"name":"launch"}}},"inlayHints":{"enable":true,"typeHintsSeparator":"‣","typeHintsWithVariable":true,"chainingHintsSeparator":"‣","refreshOnInsertMode":false,"chainingHints":true,"maxLength":25,"typeHints":true},"trace":{"server":"off"},"updates":{"prompt":true,"channel":"nightly"},"assist":{"importMergeBehavior":"full","importPrefix":"plain","importGroup":true},"callInfo":{"full":true},"cargo":{"autoreload":true,"allFeatures":false,"features":[],"runBuildScripts":false,"useRustcWrapperForBuildScripts":true,"noDefaultFeatures":false,"noSysroot":false},"checkOnSave":{"enable":true,"allTargets":true,"command":"check","extraArgs":[],"overrideCommand":["./x.py","check","--json-output"]},"completion":{"addCallArgumentSnippets":true,"addCallParenthesis":true,"postfix":{"enable":true},"autoimport":{
"enable":true}},"diagnostics":{"enable":true,"enableExperimental":true,"disabled":["incorrect-ident-case"],"remapPrefix":{},"warningsAsHint":[],"warningsAsInfo":[]},"files":{"watcher":"client","excludeDirs":[]},"hoverActions":{"enable":true,"linksInHover":true},"lens":{"enable":true,"implementations":true,"run":true,"methodReferences":false,"references":false},"linkedProjects":[],"notifications":{"cargoTomlNotFound":true},"procMacro":{"enable":false},"runnables":{"cargoExtraArgs":[]},"rustfmt":{"extraArgs":[],"overrideCommand":["./build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt"]},"server":{"extraEnv":{"RA_LOG":"info,salsa::derived::slot=warn,flycheck=trace,rust_analyzer::main_loop=warn,ide_db::apply_change=warn,project_model=debug,proc_macro_api=debug,hir_expand::db=error"},"path":"/home/jade/dev/rust-analyzer/target/release/rust-analyzer"}},"trace":"off","workspaceFolders":[{"uri":"file:///home/jade/.dotfiles","name":"/home/jade"},{"uri":"file:///home/jade/dev/rust","name":"/home/jade/dev"}],"clientInfo":{"name":"coc.nvim","version":"0.0.80"}}

[INFO rust_analyzer::config] updating config from JSON: {
"enable": true,
"terminal": {
"startinsert": false
},
"debug": {
"runtime": "termdebug",
"vimspector": {
"configuration": {
"name": "launch"
}
}
},
"inlayHints": {
"enable": true,
"typeHintsSeparator
": "‣",
"typeHintsWithVariable": true,
"chainingHintsSeparator": "‣",
"refreshOnInsertMode": false,
"chainingHints": true,
"maxLength": 25,
"typeHints": true
},
"trace": {
"server": "off"
},
"updates": {
"prompt": true,
"channel": "nightly"
},
"assist": {
"importMergeBehavior": "full",
"importPrefix": "plain",
"importGroup": true
},
"callInfo": {
"full": true
},
"cargo": {
"autoreload": true,
"allFeatures": false,
"features": [],
"runBuildScripts": false,
"useRustcWrapperForBuildScripts": true,
"noDefaultFeatures": false,
"noSysroot": false
},
"checkOnSave": {
"enable"
: true,
"allTargets": true,
"command": "check",
"extraArgs": [],
"overrideCommand": [
"./x.py",
"check",
"--json-output"
]
},
"completion": {
"addCallArgumentSnippets": true,
"addCallParenthesis": true,
"postfix": {
"enable": true
},
"autoimport": {
"enable": true
}
},
"diagnostics": {
"enable": true,
"enableExperimental": true,
"disabled": [
"incorrect-ident-case"
],
"remapPrefix": {},
"warningsAsHint": [],
"warningsAsInfo": []
},
"files": {
"watcher": "client",
"excludeDirs": []
},
"hoverActions": {
"enable": true,
"linksInHover": true
},
"lens": {
"enable": true,
"implementations": true,
"
run": true,
"methodReferences": false,
"references": false
},
"linkedProjects": [],
"notifications": {
"cargoTomlNotFound": true
},
"procMacro": {
"enable": false
},
"runnables": {
"cargoExtraArgs": []
},
"rustfmt": {
"extraArgs": [],
"overrideCommand": [
"./build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt"
]
},
"server": {
"extraEnv": {
"RA_LOG": "info,salsa::derived::slot=warn,flycheck=trace,rust_analyzer::main_loop=warn,ide_db::apply_change=warn,project_model=debug,proc_macro_api=debug,hir_expand::db=error"
},
"path": "/home/jade/dev/rust-analyzer/target/release/rust-analyzer"
}
}
[INFO rust_analyzer] Client 'coc.nvim' 0.0.80
[INFO rust_analyzer] discovered projects: [CargoToml(AbsPathBuf("/home/jade/dev/rust/Cargo.toml"))]
[INFO rust_analyzer::reload] will fetch workspaces
[INFO rust_analyzer::reload] Requesting workspace reload because of the following changes: /home/jade/dev/rust/library/core/src/lib.rs: Create
[INFO rust_analyzer::global_state] handled req#1 in 2.86µs
[DEBUG project_model::cargo_workspace] Discovering cargo config target by "cargo" "-Z" "unstable-options"
[INFO rust_analyzer::global_state] handled req#2 in 2.63µs
[INFO rust_analyzer::global_state] handled req#3 in 2.07µs
[INFO rust_analyzer::global_state] handled req#4 in 480ns
[Error - 5:24:33 a.m.] Request textDocument/codeLens failed.
Message: waiting for cargo metadata or cargo check
Code: -32801
[DEBUG project_model::cargo_workspace] Discovering host platform by "rustc" "-vV"
[Error - 5:24:33 a.m.] Request textDocument/codeLens failed.
Message: waiting for cargo metadata or cargo check
Code: -32801
[INFO rust_analyzer::global_state] handled req#5 in
2.13µs
[DEBUG project_model::sysroot] Discovering sysroot for /home/jade/dev/rust/Cargo.toml
[DEBUG project_model::sysroot] Discovering sysroot by "rustc" "--print" "sysroot"
[DEBUG project_model::sysroot] Checking sysroot (looking for library and src dirs): /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust
[INFO rust_analyzer::reload] did fetch workspaces [
Ok(Cargo { root: Some("rust"), n_packages: 484, n_sysroot_crates: 10, n_rustc_compiler_crates: 0, n_rustc_cfg: 42 })]
[INFO rust_analyzer::reload] will switch workspaces
[WARN rust_analyzer::reload] failed to load /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/derive_more-0.99.9/examples/deny_missing_docs.rs
[WARN rust_analyzer::reload] failed to load /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/tests/filters.rs
[WARN rust_analyzer::reload] failed to load /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/tests/macros.rs
[WARN rust_analyzer::reload] failed to load /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.6.22/test/mod.rs
[WARN rust_analyzer::reload] failed to load /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/url-2.2.2/benches/parse_url.rs
[ERROR project_model::workspace] cyclic deps: rustc_std_workspace_core(CrateId(1193)) -> core(CrateId(190))
[DEBUG project_model::workspace] Patched std to depend on cfg-if
[INFO rust_analyzer::reload] did switch workspaces
[INFO rust_analyzer::reload] will fetch workspaces
[DEBUG project_model::cargo_workspace] Discovering cargo config target by "cargo" "-Z" "unstable-op
tions" "config" "get" "build.target"
[DEBUG project_model::cargo_workspace] Discovering host platform by "rustc" "-
vV"
[DEBUG project_model::sysroot] Discovering sysroot for /home/jade/dev/rust/Cargo.toml
[DEBUG project_model::sysroot] Discovering sysroot by "rustc" "--print" "sysroot"
[DEBUG project_model::sysroot] Checking sysroot (looking for library and src dirs): /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust
[INFO rust_analyzer::reload] did fetch workspaces [Ok(Cargo { root: Some("rust"
), n_packages: 484, n_sysroot_crates: 10, n_rustc_compiler_crates: 0, n_rustc_cfg: 42 })]
[INFO rust_analyzer::reload] will switch workspaces
[WARN rust_analyzer::reload] failed to load /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/derive_more-0.99.9/examples/deny_missing_docs.rs
[WARN rust_analyzer::reload] failed to load /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/tests/filters.rs
[WARN rust_analyzer::reload] failed to load /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/tests/macros.rs
[WARN rust_analyzer::reload] failed to load /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.6.22/test/mod.rs
[WARN rust_analyzer::reload] failed to load /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/url-2.2.2/benches/parse_url.rs
[ERROR project_model::workspace] cyclic deps: rustc_std_workspace_core(CrateId(1193)) -> core(CrateId(190))
[DEBUG project_model::workspace] Patched std to depend on cfg-if
[INFO rust_analyzer::reload] did switch workspaces
[INFO rust_analyzer::global_state] handled req#6 in 487.479543ms
[INFO rust_analyzer::reload] will fetch workspaces
[DEBUG project_model::cargo_workspace] Discovering cargo config target by "cargo" "-Z" "unstable-options" "con
fig" "get" "build.target"
[DEBUG project_model::cargo_workspace] Discovering host platform by "rustc" "-vV"
[DEBUG project_model::sysroot] Discovering sysroot for /home/jade/dev/rust/Cargo.toml
[DEBUG project_model::sysroot] Discovering sysroot by "rustc" "--print" "sysroot"
[DEBUG project_model::sysroot] Checking sysroot (looking for library and src dirs): /home/jade/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust
[INFO rust_analyzer::reload] did fetch workspaces [Ok(Cargo
{ root: Some("rust"), n_packages: 484, n_sysroot_crates: 10, n_rustc_compiler_crates: 0, n_rustc_cfg: 42 })]
[INFO rust_analyzer::reload] will switch workspaces

[WARN rust_analyzer::reload] failed to load /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/derive_more-0.99.9/examples/deny_missing_docs.rs
[WARN rust_analyzer::reload] failed to load /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/tests/filters.rs
[WARN rust_analyzer::reload] failed to load /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/log-0.4.14/tests/macros.rs
[WARN rust_analyzer::reload] failed to load /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/mio-0.6.22/test/mod.rs
[WARN rust_analyzer::reload] failed to load /home/jade/.cargo/registry/src/github.com-1ecc6299db9ec823/url-2.2.2/benches/parse_url.rs
[ERROR project_model::workspace] cyclic deps: rustc_std_workspace_core(CrateId(1193)) -> core(CrateId(190))
[DEBUG project_model::workspace] Patched std to depend on cfg-if
[INFO rust_analyzer::reload] did switch workspaces
[INFO flycheck] restart flycheck "./x.py" "check" "--json-output"
in "/home/jade/dev/rust"
[INFO rust_analyzer::global_state] handled req#7 in 361.658µs

cc #8915

@lf- lf- changed the title rust-lang/rust: "file not included in module tree" in libcore rust-lang/rust: "file not included in module tree" in libcore, broken go to definition Jun 10, 2021
@flodiebold
Copy link
Member

flodiebold commented Jun 10, 2021

Hm. library/core doesn't seem to be part of the main workspace; I'd suspect that might be causing the issues. (It's depended on as a path dependency in std, which is part of the workspace, though. It'd probably be useful to look into how that looks in cargo metadata.)

@lf-
Copy link
Contributor Author

lf- commented Jun 12, 2021

Hm. library/core doesn't seem to be part of the main workspace; I'd suspect that might be causing the issues. (It's depended on as a path dependency in std, which is part of the workspace, though. It'd probably be useful to look into how that looks in cargo metadata.)

This is definitely supposed to put it into a workspace, so this would be a bug.

@flodiebold
Copy link
Member

That would be a bug on cargo metadata's side, which seems unlikely. As I wrote, I think probably the first step is to check how it looks there.

@flodiebold
Copy link
Member

flodiebold commented Jun 12, 2021

Another possibility is that the way we're injecting the sysroot dependencies is interfering with the explicit core dependency. I wonder whether dependencies named core work in a simple workspace? That wouldn't quite explain why core isn't part of the crate graph at all though.

@lf-
Copy link
Contributor Author

lf- commented Jun 12, 2021

Another possibility is that the way we're injecting the sysroot dependencies is interfering with the explicit core dependency. I wonder whether dependencies named core work in a simple workspace? That wouldn't quite explain why core isn't part of the crate graph at all though.

It seems to be listed like a normal workspace member, so it probably is us doing something funny, indeed.

dev/rust - [master●] » cargo metadata | jq '.packages | map(select(.name == "core"))'
warning: please specify `--format-version` flag explicitly to avoid compatibility problems
[
  {
    "name": "core",
    "version": "0.0.0",
    "id": "core 0.0.0 (path+file:///home/jade/dev/rust/library/core)",
    "license": "MIT OR Apache-2.0",
    "license_file": null,
    "description": "The Rust Core Library",
    "source": null,
    "dependencies": [
      {
        "name": "rand",
        "source": "registry+https://github.com/rust-lang/crates.io-index",
        "req": "^0.7",
        "kind": "dev",
        "rename": null,
        "optional": false,
        "uses_default_features": true,
        "features": [],
        "target": null,
        "registry": null
      }
    ],
    "targets": [
      {
        "kind": [
          "lib"
        ],
        "crate_types": [
          "lib"
        ],
        "name": "core",
        "src_path": "/home/jade/dev/rust/library/core/src/lib.rs",
        "edition": "2018",
        "doc": true,
        "doctest": true,
        "test": false
      },
      {
        "kind": [
          "test"
        ],
        "crate_types": [
          "bin"
        ],
        "name": "coretests",
        "src_path": "/home/jade/dev/rust/library/core/tests/lib.rs",
        "edition": "2018",
        "doc": false,
        "doctest": false,
        "test": true
      },
      {
        "kind": [
          "bench"
        ],
        "crate_types": [
          "bin"
        ],
        "name": "corebenches",
        "src_path": "/home/jade/dev/rust/library/core/benches/lib.rs",
        "edition": "2018",
        "doc": false,
        "doctest": false,
        "test": true
      }
    ],
    "features": {
      "debug_refcell": [],
      "panic_immediate_abort": []
    },
    "manifest_path": "/home/jade/dev/rust/library/core/Cargo.toml",
    "metadata": null,
    "publish": null,
    "authors": [
      "The Rust Project Developers"
    ],
    "categories": [],
    "keywords": [],
    "readme": null,
    "repository": "https://github.com/rust-lang/rust.git",
    "homepage": null,
    "documentation": null,
    "edition": "2018",
    "links": null
  }
]

Re: putting something named core into a workspace:

/tmp/f - [main●] » cargo metadata | jq .
warning: please specify `--format-version` flag explicitly to avoid compatibility problems
{
  "packages": [
    {
      "name": "core",
      "version": "0.1.0",
      "id": "core 0.1.0 (path+file:///tmp/f/core)",
      "license": null,
      "license_file": null,
      "description": null,
      "source": null,
      "dependencies": [],
      "targets": [
        {
          "kind": [
            "bin"
          ],
          "crate_types": [
            "bin"
          ],
          "name": "core",
          "src_path": "/tmp/f/core/src/main.rs",
          "edition": "2018",
          "doc": true,
          "doctest": false,
          "test": true
        }
      ],
      "features": {},
      "manifest_path": "/tmp/f/core/Cargo.toml",
      "metadata": null,
      "publish": null,
      "authors": [],
      "categories": [],
      "keywords": [],
      "readme": null,
      "repository": null,
      "homepage": null,
      "documentation": null,
      "edition": "2018",
      "links": null
    },
    {
      "name": "f",
      "version": "0.1.0",
      "id": "f 0.1.0 (path+file:///tmp/f)",
      "license": null,
      "license_file": null,
      "description": null,
      "source": null,
      "dependencies": [],
      "targets": [
        {
          "kind": [
            "bin"
          ],
          "crate_types": [
            "bin"
          ],
          "name": "f",
          "src_path": "/tmp/f/src/main.rs",
          "edition": "2018",
          "doc": true,
          "doctest": false,
          "test": true
        }
      ],
      "features": {},
      "manifest_path": "/tmp/f/Cargo.toml",
      "metadata": null,
      "publish": null,
      "authors": [],
      "categories": [],
      "keywords": [],
      "readme": null,
      "repository": null,
      "homepage": null,
      "documentation": null,
      "edition": "2018",
      "links": null
    },
    {
      "name": "f2",
      "version": "0.1.0",
      "id": "f2 0.1.0 (path+file:///tmp/f/f2)",
      "license": null,
      "license_file": null,
      "description": null,
      "source": null,
      "dependencies": [
        {
          "name": "core",
          "source": null,
          "req": "*",
          "kind": null,
          "rename": null,
          "optional": false,
          "uses_default_features": true,
          "features": [],
          "target": null,
          "registry": null,
          "path": "/tmp/f/core"
        }
      ],
      "targets": [
        {
          "kind": [
            "bin"
          ],
          "crate_types": [
            "bin"
          ],
          "name": "f2",
          "src_path": "/tmp/f/f2/src/main.rs",
          "edition": "2018",
          "doc": true,
          "doctest": false,
          "test": true
        }
      ],
      "features": {},
      "manifest_path": "/tmp/f/f2/Cargo.toml",
      "metadata": null,
      "publish": null,
      "authors": [],
      "categories": [],
      "keywords": [],
      "readme": null,
      "repository": null,
      "homepage": null,
      "documentation": null,
      "edition": "2018",
      "links": null
    }
  ],
  "workspace_members": [
    "f2 0.1.0 (path+file:///tmp/f/f2)",
    "core 0.1.0 (path+file:///tmp/f/core)",
    "f 0.1.0 (path+file:///tmp/f)"
  ],
  "resolve": {
    "nodes": [
      {
        "id": "core 0.1.0 (path+file:///tmp/f/core)",
        "dependencies": [],
        "deps": [],
        "features": []
      },
      {
        "id": "f 0.1.0 (path+file:///tmp/f)",
        "dependencies": [],
        "deps": [],
        "features": []
      },
      {
        "id": "f2 0.1.0 (path+file:///tmp/f/f2)",
        "dependencies": [],
        "deps": [],
        "features": []
      }
    ],
    "root": "f 0.1.0 (path+file:///tmp/f)"
  },
  "target_directory": "/tmp/f/target",
  "version": 1,
  "workspace_root": "/tmp/f",
  "metadata": null
}

@flodiebold
Copy link
Member

Re: putting something named core into a workspace:

So does this setup work with RA?

@lf-
Copy link
Contributor Author

lf- commented Jun 12, 2021

Re: putting something named core into a workspace:

So does this setup work with RA?

Appears so, core/src/main.rs is not getting the error about not being part of a crate graph in spite of being transitively put into the workspace as a dep of f2 as would be the setup in r-l/r. (workspace members are written as just f2 in the workspace manifest)

@flodiebold
Copy link
Member

Oh, actually I think it's simply this.

@lf-
Copy link
Contributor Author

lf- commented Jun 12, 2021

That's the same thing as #7243 but on a more common project. Not sure what we should do about it though, other than detecting it and deciding to not be in the test cfg i guess.

@flodiebold
Copy link
Member

Well, I think the 'correct' way to go about it is to analyze the crate in both configurations, use non-test for dependencies, and while editing the crate itself detect whether to use non-test or test based on the cursor position (i.e. choose the crate configuration where the current cursor position corresponds to something in the HIR). (Though we could be even smarter about it and e.g. base completions on all analyzed configurations...)

@lf-
Copy link
Contributor Author

lf- commented Jun 12, 2021

Well, I think the 'correct' way to go about it is to analyze the crate in both configurations, use non-test for dependencies, and while editing the crate itself detect whether to use non-test or test based on the cursor position (i.e. choose the crate configuration where the current cursor position corresponds to something in the HIR). (Though we could be even smarter about it and e.g. base completions on all analyzed configurations...)

In the specific case for core, we just need to not set #[cfg(test)] for it and this will not break anything as the tests are in another crate. Would you be ok with a change that just checks if the crate name is core and deactivates it in the cfg, to fix the rust-lang/rust problem for now?

I'm mildly concerned about the perf impact of double analyzing things and unsure what changes would be required to make it happen. Also, I remember having frustrations with not being able to set the cfgs while working on a crate that used them for features without changing the default set, so having some kind of UI/command to set them would be another way to accomplish this, though of course not always as slick (also, state 😱 )

@flodiebold
Copy link
Member

We do want a UI for toggling features (and maybe targets as well), but I'm not sure toggling test or other non-feature configs fits in with that. We have to analyze the crate without test for any crate that depends on it anyway to be correct.

Hard-coding the crate name seems a bit too specific for my taste. I could imagine adding a setting for this, or something like that.

lf- added a commit to lf-/rust-analyzer that referenced this issue Jun 14, 2021
Fixes crates which vanish when the 'test' cfg atom is set.

Fix rust-lang#7243.
Fix rust-lang#9203.
Fix rust-lang#7225.
@FrankC01

This comment has been minimized.

@flodiebold

This comment has been minimized.

@FrankC01

This comment has been minimized.

bors bot added a commit that referenced this issue Jun 21, 2021
9227: Add a config setting to disable the 'test' cfg in specified crates r=matklad a=lf-

If you are opening libcore from rust-lang/rust as opposed to e.g.
goto definition from some other crate which would use the sysroot
instance of libcore, a `#![cfg(not(test))]` would previously have made
all the code excluded from the module tree, breaking the editor
experience.

Core does not need to ever be edited with `#[cfg(test)]` enabled,
as the tests are in another crate.

This PR puts in a slight hack that checks for the crate name "core" and
turns off `#[cfg(test)]` for that crate.

Fixes #9203 
Fixes #9226 

Co-authored-by: Jade <software@lfcode.ca>
@bors bors bot closed this as completed in 8b77e26 Jun 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants