Skip to content

Commit 4482662

Browse files
authored
Merge pull request #423 from dtolnay/trackcaller
Track caller for Ident validation panics
2 parents f15383f + 690ab11 commit 4482662

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

src/fallback.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ pub(crate) struct Ident {
755755
}
756756

757757
impl Ident {
758+
#[track_caller]
758759
pub fn new_checked(string: &str, span: Span) -> Self {
759760
validate_ident(string);
760761
Ident::new_unchecked(string, span)
@@ -768,6 +769,7 @@ impl Ident {
768769
}
769770
}
770771

772+
#[track_caller]
771773
pub fn new_raw_checked(string: &str, span: Span) -> Self {
772774
validate_ident_raw(string);
773775
Ident::new_raw_unchecked(string, span)
@@ -798,6 +800,7 @@ pub(crate) fn is_ident_continue(c: char) -> bool {
798800
unicode_ident::is_xid_continue(c)
799801
}
800802

803+
#[track_caller]
801804
fn validate_ident(string: &str) {
802805
if string.is_empty() {
803806
panic!("Ident is not allowed to be empty; use Option<Ident>");
@@ -826,6 +829,7 @@ fn validate_ident(string: &str) {
826829
}
827830
}
828831

832+
#[track_caller]
829833
fn validate_ident_raw(string: &str) {
830834
validate_ident(string);
831835

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,7 @@ impl Ident {
950950
/// style="padding-right:0;">syn::parse_str</code></a><code
951951
/// style="padding-left:0;">::&lt;Ident&gt;</code>
952952
/// rather than `Ident::new`.
953+
#[track_caller]
953954
pub fn new(string: &str, span: Span) -> Self {
954955
Ident::_new(imp::Ident::new_checked(string, span.inner))
955956
}
@@ -959,6 +960,7 @@ impl Ident {
959960
/// (including keywords, e.g. `fn`). Keywords which are usable in path
960961
/// segments (e.g. `self`, `super`) are not supported, and will cause a
961962
/// panic.
963+
#[track_caller]
962964
pub fn new_raw(string: &str, span: Span) -> Self {
963965
Ident::_new(imp::Ident::new_raw_checked(string, span.inner))
964966
}

src/wrapper.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ pub(crate) enum Ident {
639639
}
640640

641641
impl Ident {
642+
#[track_caller]
642643
pub fn new_checked(string: &str, span: Span) -> Self {
643644
match span {
644645
Span::Compiler(s) => Ident::Compiler(proc_macro::Ident::new(string, s)),
@@ -650,6 +651,7 @@ impl Ident {
650651
Ident::Fallback(fallback::Ident::new_unchecked(string, span))
651652
}
652653

654+
#[track_caller]
653655
pub fn new_raw_checked(string: &str, span: Span) -> Self {
654656
match span {
655657
Span::Compiler(s) => Ident::Compiler(proc_macro::Ident::new_raw(string, s)),

0 commit comments

Comments
 (0)