Skip to content

Import suggestion breaks code with #[cfg] #516

Closed as not planned
Closed as not planned
@marcospb19

Description

@marcospb19

Sublime Text Version

Build 4155

Rust Enhanced Version

2.25.0

Operating system

Arch Linux

Steps to reproduce

  1. Add this code:
#[cfg(unix)]
use std::os::unix::fs;

fn main() {
    let _ = stdout();

    #[cfg(unix)]
    {
        // Using unix specific stuff here.
        let _function = fs::chroot::<&str>;
    }
}
  1. Save the file.
  2. Click on the suggestion to import the function.
  3. Arrive at this code:
#[cfg(unix)]
use std::io::stdout;
use std::os::unix::fs;

fn main() {
...
  1. Code should now be incompatible with non-unix platforms, because cfg(unix) is not on top of the std::os::unix import.

Should this be thrown to upstream as a compiler diagnostic issue? Or does it belong here, considering that rust-enhanced assumes rustc tips are trustworthy?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions