Skip to content

Commit b9f405b

Browse files
committed
fix: swap Span::source_file -> Span::file
rust-lang/rust#54725 rust-lang/rust#139903
1 parent 18fcd64 commit b9f405b

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/lib.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
//! A simple proc macro to generate a const list of filenames and optionally apply a macro to each.
2-
//!
2+
//!
33
//! ```rust
44
//! use std::fs::canonicalize;
5-
//!
5+
//!
66
//! use list_files_macro::list_files;
7-
//!
7+
//!
88
//! fn get_full_path(path: &str) -> String {
99
//! canonicalize(path).unwrap().into_os_string().into_string().unwrap()
1010
//! }
11-
//!
11+
//!
1212
//! const FILENAMES: [&'static str; 3] = list_files!("../tests/files/*.rs");
13-
//!
13+
//!
1414
//! assert_eq!(FILENAMES, [
1515
//! "tests/files/a.rs",
1616
//! "tests/files/b.rs",
1717
//! "tests/files/c.rs",
1818
//! ].map(get_full_path));
19-
//!
19+
//!
2020
//! const CONTENTS: [&'static str; 3] = list_files!(include_str, "../tests/files/*.rs");
21-
//!
21+
//!
2222
//! assert_eq!(CONTENTS[0], r#"
2323
//! pub fn run() -> &'static str {
2424
//! "A"
2525
//! }
2626
//! "#);
27-
//!
27+
//!
2828
//! macro_rules! run_file {
2929
//! ($x:expr) => {
3030
//! {
@@ -34,23 +34,22 @@
3434
//! }
3535
//! };
3636
//! }
37-
//!
37+
//!
3838
//! let results = list_files!(run_file, "../tests/files/*.rs");
39-
//!
39+
//!
4040
//! assert_eq!(results, [
4141
//! "A",
4242
//! "B",
4343
//! "C",
4444
//! ]);
4545
//! ```
46-
//!
46+
//!
4747
//! To use this, add it as a dependency to your Cargo.toml:
4848
//! ```toml
4949
//! [dependencies]
5050
//! list_files_macro = "^0.1.0"
5151
//! ```
5252
53-
#![feature(let_else)]
5453
#![feature(proc_macro_span)]
5554

5655
#![doc(html_root_url = "https://docs.rs/list_files_macro/0.1.0")]
@@ -73,23 +72,23 @@ pub fn list_files(input: TokenStream) -> TokenStream {
7372
[Expr::Lit(ExprLit { lit: Lit::Str(path), .. })] => (path.value(), None),
7473
_ => panic!("Usage: list_files!(\"path/to/dir\") | list_files!(handler_macro, \"path/to/dir\")"),
7574
};
76-
75+
7776
// Resolve directory
7877
let absolute_path =
7978
if path.starts_with(".") {
80-
let source_path = Span::call_site().source_file().path();
79+
let source_path: std::path::PathBuf = Span::call_site().file().into();
8180
source_path.parent().unwrap().join(&path).into_os_string().into_string().unwrap()
8281
} else {
8382
path
8483
};
85-
84+
8685
// Generate list of literal string paths
8786
let files = glob(&absolute_path).unwrap();
8887
let file_literals = files.map(|file| {
8988
let file = file.unwrap().canonicalize().unwrap().into_os_string().into_string().unwrap();
9089
quote!(#file)
9190
});
92-
91+
9392
// Run handlers if required
9493
if let Some(handler) = handler {
9594
quote!([#(#handler!(#file_literals)),*])

0 commit comments

Comments
 (0)