Skip to content

Commit 3afaa01

Browse files
committed
improve span on use items
1 parent 3b60981 commit 3afaa01

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
<!-- ## [Unreleased] -->
7+
## [Unreleased]
8+
### Fixed
9+
- adjusted spans for `#[manyhow]` on `use` items to make go-to-definition work better.
10+
811
## [0.11.1] - 2024-03-16
912
### Fixed
1013
- fix `item_as_dummy` for attribute macros

macros/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use std::{fmt::{Display, Write}, mem};
1+
use std::fmt::{Display, Write};
2+
use std::mem;
23

34
use proc_macro2::{Group, Ident, Span, TokenStream, TokenTree};
45
use proc_macro_utils::{Delimited, TokenStream2Ext, TokenStreamExt, TokenTree2Ext, TokenTreePunct};
@@ -82,7 +83,7 @@ impl Display for Param {
8283
}
8384
}
8485

85-
/// Attribute macro to remove boiler plate from proc macro entry points.
86+
/// Attribute macro to remove boilerplate from proc macro entry points.
8687
///
8788
/// See [the documentation at the crate root for more
8889
/// details](https://docs.rs/manyhow#using-the-manyhow-macro).
@@ -193,7 +194,7 @@ pub fn manyhow(
193194
let flags_replace = |i: usize, replacement: Option<&str>| {
194195
let mut flags = flags.iter().map(ToString::to_string).collect::<Vec<_>>();
195196
if let Some(replacement) = replacement {
196-
flags[i] = replacement.to_owned();
197+
replacement.clone_into(&mut flags[i]);
197198
} else {
198199
flags.remove(i);
199200
}
@@ -292,7 +293,7 @@ pub fn manyhow(
292293
.last()
293294
.expect("use statement should contain at least on item");
294295

295-
let Some(fn_name) = fn_name.ident() else {
296+
let Some(mut fn_name) = fn_name.ident().cloned() else {
296297
return with_helpful_error(
297298
item,
298299
fn_name.span(),
@@ -302,6 +303,8 @@ pub fn manyhow(
302303
);
303304
};
304305

306+
fn_name.set_span(Span::call_site());
307+
305308
quote!(fn #fn_name).to_tokens(&mut output);
306309
impl_fn_path = path.into_iter().collect();
307310

0 commit comments

Comments
 (0)