Skip to content

Commit

Permalink
Make private module more clearly private
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Aug 13, 2022
1 parent 6be2da9 commit b88a699
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
20 changes: 10 additions & 10 deletions src/ensure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,15 +788,15 @@ macro_rules! __fancy_ensure {
(lhs, rhs) => {
if !(lhs $op rhs) {
#[allow(unused_imports)]
use $crate::private::{BothDebug, NotBothDebug};
use $crate::__private::{BothDebug, NotBothDebug};
return Err((lhs, rhs).__dispatch_ensure(
$crate::private::concat!(
$crate::__private::concat!(
"Condition failed: `",
$crate::private::stringify!($lhs),
$crate::__private::stringify!($lhs),
" ",
$crate::private::stringify!($op),
$crate::__private::stringify!($op),
" ",
$crate::private::stringify!($rhs),
$crate::__private::stringify!($rhs),
"`",
),
));
Expand All @@ -811,24 +811,24 @@ macro_rules! __fancy_ensure {
macro_rules! __fallback_ensure {
($cond:expr $(,)?) => {
if !$cond {
return $crate::private::Err($crate::Error::msg(
$crate::private::concat!("Condition failed: `", $crate::private::stringify!($cond), "`")
return $crate::__private::Err($crate::Error::msg(
$crate::__private::concat!("Condition failed: `", $crate::__private::stringify!($cond), "`")
));
}
};
($cond:expr, $msg:literal $(,)?) => {
if !$cond {
return $crate::private::Err($crate::__anyhow!($msg));
return $crate::__private::Err($crate::__anyhow!($msg));
}
};
($cond:expr, $err:expr $(,)?) => {
if !$cond {
return $crate::private::Err($crate::__anyhow!($err));
return $crate::__private::Err($crate::__anyhow!($err));
}
};
($cond:expr, $fmt:expr, $($arg:tt)*) => {
if !$cond {
return $crate::private::Err($crate::__anyhow!($fmt, $($arg)*));
return $crate::__private::Err($crate::__anyhow!($fmt, $($arg)*));
}
};
}
2 changes: 1 addition & 1 deletion src/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
// The anyhow! macro will set up the call in this form:
//
// #[allow(unused_imports)]
// use $crate::private::{AdhocKind, TraitKind};
// use $crate::__private::{AdhocKind, TraitKind};
// let error = $msg;
// (&error).anyhow_kind().new(error)

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ pub fn Ok<T>(t: T) -> Result<T> {

// Not public API. Referenced by macro-generated code.
#[doc(hidden)]
pub mod private {
pub mod __private {
use crate::Error;
use alloc::fmt;
use core::fmt::Arguments;
Expand Down
32 changes: 16 additions & 16 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
#[macro_export]
macro_rules! bail {
($msg:literal $(,)?) => {
return $crate::private::Err($crate::__anyhow!($msg))
return $crate::__private::Err($crate::__anyhow!($msg))
};
($err:expr $(,)?) => {
return $crate::private::Err($crate::__anyhow!($err))
return $crate::__private::Err($crate::__anyhow!($err))
};
($fmt:expr, $($arg:tt)*) => {
return $crate::private::Err($crate::__anyhow!($fmt, $($arg)*))
return $crate::__private::Err($crate::__anyhow!($fmt, $($arg)*))
};
}

Expand Down Expand Up @@ -120,24 +120,24 @@ macro_rules! bail {
macro_rules! ensure {
($cond:expr $(,)?) => {
if !$cond {
return $crate::private::Err($crate::Error::msg(
$crate::private::concat!("Condition failed: `", $crate::private::stringify!($cond), "`")
return $crate::__private::Err($crate::Error::msg(
$crate::__private::concat!("Condition failed: `", $crate::__private::stringify!($cond), "`")
));
}
};
($cond:expr, $msg:literal $(,)?) => {
if !$cond {
return $crate::private::Err($crate::__anyhow!($msg));
return $crate::__private::Err($crate::__anyhow!($msg));
}
};
($cond:expr, $err:expr $(,)?) => {
if !$cond {
return $crate::private::Err($crate::__anyhow!($err));
return $crate::__private::Err($crate::__anyhow!($err));
}
};
($cond:expr, $fmt:expr, $($arg:tt)*) => {
if !$cond {
return $crate::private::Err($crate::__anyhow!($fmt, $($arg)*));
return $crate::__private::Err($crate::__anyhow!($fmt, $($arg)*));
}
};
}
Expand Down Expand Up @@ -189,22 +189,22 @@ macro_rules! ensure {
#[macro_export]
macro_rules! anyhow {
($msg:literal $(,)?) => {
$crate::private::must_use({
let error = $crate::private::format_err($crate::private::format_args!($msg));
$crate::__private::must_use({
let error = $crate::__private::format_err($crate::__private::format_args!($msg));
error
})
};
($err:expr $(,)?) => {
$crate::private::must_use({
use $crate::private::kind::*;
$crate::__private::must_use({
use $crate::__private::kind::*;
let error = match $err {
error => (&error).anyhow_kind().new(error),
};
error
})
};
($fmt:expr, $($arg:tt)*) => {
$crate::Error::msg($crate::private::format!($fmt, $($arg)*))
$crate::Error::msg($crate::__private::format!($fmt, $($arg)*))
};
}

Expand All @@ -215,17 +215,17 @@ macro_rules! anyhow {
#[macro_export]
macro_rules! __anyhow {
($msg:literal $(,)?) => ({
let error = $crate::private::format_err($crate::private::format_args!($msg));
let error = $crate::__private::format_err($crate::__private::format_args!($msg));
error
});
($err:expr $(,)?) => ({
use $crate::private::kind::*;
use $crate::__private::kind::*;
let error = match $err {
error => (&error).anyhow_kind().new(error),
};
error
});
($fmt:expr, $($arg:tt)*) => {
$crate::Error::msg($crate::private::format!($fmt, $($arg)*))
$crate::Error::msg($crate::__private::format!($fmt, $($arg)*))
};
}
2 changes: 1 addition & 1 deletion tests/ui/must-use.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: unused return value of `anyhow::private::must_use` that must be used
error: unused return value of `anyhow::__private::must_use` that must be used
--> tests/ui/must-use.rs:8:9
|
8 | anyhow!("it failed");
Expand Down

0 comments on commit b88a699

Please sign in to comment.