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

Track caller on methods using assertions #3297

Merged
merged 1 commit into from Jan 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/parse/matches/arg_matches.rs
Expand Up @@ -165,6 +165,7 @@ impl ArgMatches {
/// [`default_value`]: crate::Arg::default_value()
/// [`occurrences_of`]: ArgMatches::occurrences_of()
/// [`Arg::values_of_lossy`]: ArgMatches::values_of_lossy()
#[cfg_attr(debug_assertions, track_caller)]
pub fn value_of_lossy<T: Key>(&self, id: T) -> Option<Cow<'_, str>> {
let id = Id::from(id);
let arg = self.get_arg(&id)?;
Expand Down Expand Up @@ -215,6 +216,7 @@ impl ArgMatches {
/// [`default_value`]: crate::Arg::default_value()
/// [`occurrences_of`]: ArgMatches::occurrences_of()
/// [`ArgMatches::values_of_os`]: ArgMatches::values_of_os()
#[cfg_attr(debug_assertions, track_caller)]
pub fn value_of_os<T: Key>(&self, id: T) -> Option<&OsStr> {
let id = Id::from(id);
let arg = self.get_arg(&id)?;
Expand Down Expand Up @@ -318,6 +320,7 @@ impl ArgMatches {
/// assert_eq!(&itr.next().unwrap()[..], "\u{FFFD}!");
/// assert_eq!(itr.next(), None);
/// ```
#[cfg_attr(debug_assertions, track_caller)]
pub fn values_of_lossy<T: Key>(&self, id: T) -> Option<Vec<String>> {
let id = Id::from(id);
let arg = self.get_arg(&id)?;
Expand Down Expand Up @@ -371,6 +374,7 @@ impl ArgMatches {
/// [`OsSt`]: std::ffi::OsStr
/// [values]: OsValues
/// [`String`]: std::string::String
#[cfg_attr(debug_assertions, track_caller)]
pub fn values_of_os<T: Key>(&self, id: T) -> Option<OsValues> {
let id = Id::from(id);
let arg = self.get_arg(&id)?;
Expand Down Expand Up @@ -1313,7 +1317,7 @@ impl<'a> Default for Indices<'a> {
}
}

#[track_caller]
#[cfg_attr(debug_assertions, track_caller)]
#[inline]
fn assert_utf8_validation(arg: &MatchedArg, id: &Id) {
debug_assert!(
Expand All @@ -1323,7 +1327,7 @@ fn assert_utf8_validation(arg: &MatchedArg, id: &Id) {
);
}

#[track_caller]
#[cfg_attr(debug_assertions, track_caller)]
#[inline]
fn assert_no_utf8_validation(arg: &MatchedArg, id: &Id) {
debug_assert!(
Expand Down