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

add a std macro_rules path! #12904

Closed
electricface opened this issue Mar 15, 2014 · 3 comments
Closed

add a std macro_rules path! #12904

electricface opened this issue Mar 15, 2014 · 3 comments
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@electricface
Copy link

can add a std macro_rules path to mod "std::macros" ,like

path!("/fmt/path-{}/abc/{}", "foo", "bar")

=>

&Path::new("/fmt/path-foo/abc/bar")
@sfackler
Copy link
Member

I'm not sure if there's enough of a use case for this to be added to libstd. You can always define it yourself:

macro_rules! path(
    ($($t:tt),+) => (&Path::new(format!($($t),+)))
)

@electricface
Copy link
Author

This is convenient

#[crate_id="abc"];
#[crate_type="bin"];
#[feature(macro_rules)];

#[macro_export]
macro_rules! path(
    ($e:expr) => (&Path::new($e));
    ($($arg:tt),+) => (
        &Path::new(format_args!(::std::fmt::format, $($arg),+ ))
    )
)

fn main(){
    use std::io::{File,Open,ReadWrite};

    for num in range(0,10){
        let p = path!("message{}.txt",num);
        println!("write file {}", "message" + num.to_str() + ".txt" );
        let mut file = match File::open_mode( p, Open,ReadWrite ){
            Ok(o) => o,
            Err(e) => fail!("can't open file")
        };
        file.write_line( "one line" );
    }
}

@alexcrichton
Copy link
Member

Closing for reasons found here: #12915 (comment)

matthiaskrgr pushed a commit to matthiaskrgr/rust that referenced this issue Aug 2, 2022
…lnicola

internal: Be more explicit when filtering built-in completions

We return every built-in type here, but only have `u32` in the tests, so let's look for that one to make tests more reliable across platforms.
flip1995 pushed a commit to flip1995/rust that referenced this issue Jun 13, 2024
Normalize type aliases when checking significant drops.

fixes rust-lang#10750

No test as I'm not sure exactly how the type alias caused a stack overflow here. Also removes an unnecessary `HashSet`.

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

4 participants