Skip to content
This repository has been archived by the owner on Jul 9, 2023. It is now read-only.

Modules defined by combining multiple files. #47

Closed
crlf0710 opened this issue Feb 23, 2020 · 4 comments
Closed

Modules defined by combining multiple files. #47

crlf0710 opened this issue Feb 23, 2020 · 4 comments

Comments

@crlf0710
Copy link

Define a proc macro that collects and combines multiple sources into a single module.

// lib.rs

#[paths("a.rs", "b.rs")]
mod foo;

// a.rs
//! inner docstring comment 1
struct Part1;

// b.rs
//! inner docstring comment 2

struct Part2;

got expanded into (with proper Spans if possible):

// lib.rs
mod foo {
    //! inner docstring comment 1
    //! inner docstring comment 2

    struct Part1;
    struct Part2;
}
@CreepySkeleton
Copy link

What it would be useful for?

@dtolnay
Copy link
Owner

dtolnay commented Feb 23, 2020

I think any implementation of this would destroy all the spans, so I am skeptical that a macro would be worthwhile.

@dtolnay dtolnay closed this as completed Feb 23, 2020
@dtolnay
Copy link
Owner

dtolnay commented Feb 23, 2020

A workaround would be to write:

mod foo {
    //! inner docstring comment 1
    //! inner docstring comment 2

    mod a;
    mod b;

    pub use a::*;
    pub use b::*;
}

@crlf0710
Copy link
Author

that's a little different, with the current visibility rules, some arrangement needs to be done in a.rs and b.rs to make them work together. (Additional uses, for example.) But it will mostly work.

Too bad Span referring to external files cannot be created. I left a ticket in rust-lang/rfcs#2869 .

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants