question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Handle `cfg` blocks in resolve

See original GitHub issue

When there are two items with different cfgs, like

#[cfg(test)]
fn foo() {}

#[cfg(not(test))]
fn foo() {}

#[cfg(unix)]
fn bar() {}

#[cfg(not(unix))]
fn bar() {}

we should pick the non-test one matching the current platform.

This should solve this problem in a principle way. Then this can be extended to fix https://github.com/intellij-rust/intellij-rust/issues/1189.

  • support compiler options like unix, target_os, etc - fixed by #4488
  • support cargo features:
    • in libraries - fixed by #4635
    • in stdlib
    • in workspace (#4693)
  • support cfg_attr (#6497)

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:7
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
Undincommented, Aug 16, 2020

@Kobzol I don’t know about any ongoing work on cfg_attr but let’s ask @ortem as well Be careful with org.rust.lang.core.stubs.RsAttributeOwnerStubBase#hasCfg/org.rust.lang.core.stubs.RsAttributeOwnerStubBase#hasMacroUse properties. Currently, our stubs keep info only about direct usages of cfg, macro_use and other code relies on that. But with cfg_attr things become more complex because we can have cfg under cfg_attr (or even under several cfg_attr). Also, it’s impossible to precisely calculate if element has cfg after unfolding all cfg_attrs while stub creation since we have info only about single file. We discussed it with @vlad20012 some time ago and decided that the best solution is to keep only approximate info if an item has cfg/macro_use/etc. attributes in stubs and calculate precise value when needed. Since these properties in stubs were introduced only for performance reasons, it should be ok. For example, the simplest implementation is to return true by the corresponding properties if an element has cfg_attr without any additional unfolding of attributes themselves while stub creation. I don’t know it’s ok or not from performance point of view, it should be investigated.

1reaction
nazar-pccommented, Sep 26, 2020

Here is another one that is currently not handled nicely:

#[cfg(not(doc))]
pub use router::consumer;
#[cfg(doc)]
#[path = "router/consumer.rs"]
pub mod consumer;

I’m doing this because of https://github.com/rust-lang/rust/issues/59368, but now IDE is confused and thinks those are 2 modules and doesn’t know which one to use, so uses neither.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why resolve is not triggered in config? - Stack Overflow
Your issue is that your resolve block does not map to the correct data type. The purpose of the resolve block is to...
Read more >
Merge conflicts - GitLab Docs
Resolve conflicts from the command line · Open the terminal and check out your feature branch. · Rebase your branch against the target...
Read more >
Configuration options for isort
WARNING: this overrides the behavior of future handling and therefore can ... isort will look at all sub-folders in this config root to...
Read more >
Understanding Nginx Server and Location Block Selection ...
How Nginx Decides Which Server Block Will Handle a Request ... to build a list of the server blocks that can possibly resolve...
Read more >
Handling Errors | Axios Docs
Using the validateStatus config option, you can define HTTP code(s) that should ... status < 500; // Resolve only if the status code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found