Skip to content
Myr

Make private module more clearly private

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Tolnay · committed by David Tolnay · parent 6be2da9 · Browse files · 5 files+29 added−29 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+29 added−29 removed

  • tests:+1 added−1 removed
  • other:+28 added−28 removed

5 files+29 added−29 removed

modified:src/ensure.rs+10 added-10 removed
786 unmodified lines
787 match (&$lhs, &$rhs) {788 (lhs, rhs) => {789 if !(lhs $op rhs) {790 #[allow(unused_imports)]791 use $crate::private::{BothDebug, NotBothDebug};791 use $crate::__private::{BothDebug, NotBothDebug};792 return Err((lhs, rhs).__dispatch_ensure(793 $crate::private::concat!(793 $crate::__private::concat!(794 "Condition failed: `",795 $crate::private::stringify!($lhs),795 $crate::__private::stringify!($lhs),796 " ",797 $crate::private::stringify!($op),797 $crate::__private::stringify!($op),798 " ",799 $crate::private::stringify!($rhs),799 $crate::__private::stringify!($rhs),800 "`",801 ),802 ));803 }
6 unmodified lines
810#[macro_export]811macro_rules! __fallback_ensure {812 ($cond:expr $(,)?) => {813 if !$cond {814 return $crate::private::Err($crate::Error::msg(815 $crate::private::concat!("Condition failed: `", $crate::private::stringify!($cond), "`")814 return $crate::__private::Err($crate::Error::msg(815 $crate::__private::concat!("Condition failed: `", $crate::__private::stringify!($cond), "`")816 ));817 }818 };819 ($cond:expr, $msg:literal $(,)?) => {820 if !$cond {821 return $crate::private::Err($crate::__anyhow!($msg));821 return $crate::__private::Err($crate::__anyhow!($msg));822 }823 };824 ($cond:expr, $err:expr $(,)?) => {825 if !$cond {826 return $crate::private::Err($crate::__anyhow!($err));826 return $crate::__private::Err($crate::__anyhow!($err));827 }828 };829 ($cond:expr, $fmt:expr, $($arg:tt)*) => {830 if !$cond {831 return $crate::private::Err($crate::__anyhow!($fmt, $($arg)*));831 return $crate::__private::Err($crate::__anyhow!($fmt, $($arg)*));832 }833 };834}
modified:src/kind.rs+1 added-1 removed
38 unmodified lines
39//40// The anyhow! macro will set up the call in this form:41//42// #[allow(unused_imports)]43// use $crate::private::{AdhocKind, TraitKind};43// use $crate::__private::{AdhocKind, TraitKind};44// let error = $msg;45// (&error).anyhow_kind().new(error)4647use crate::Error;
69 unmodified lines
modified:src/lib.rs+1 added-1 removed
632 unmodified lines
633}634635// Not public API. Referenced by macro-generated code.636#[doc(hidden)]637pub mod private {637pub mod __private {638 use crate::Error;639 use alloc::fmt;640 use core::fmt::Arguments;641
39 unmodified lines
modified:src/macros.rs+16 added-16 removed
53 unmodified lines
54/// ```55#[macro_export]56macro_rules! bail {57 ($msg:literal $(,)?) => {58 return $crate::private::Err($crate::__anyhow!($msg))58 return $crate::__private::Err($crate::__anyhow!($msg))59 };60 ($err:expr $(,)?) => {61 return $crate::private::Err($crate::__anyhow!($err))61 return $crate::__private::Err($crate::__anyhow!($err))62 };63 ($fmt:expr, $($arg:tt)*) => {64 return $crate::private::Err($crate::__anyhow!($fmt, $($arg)*))64 return $crate::__private::Err($crate::__anyhow!($fmt, $($arg)*))65 };66}6768/// Return early with an error if a condition is not satisfied.
50 unmodified lines
119#[macro_export]120macro_rules! ensure {121 ($cond:expr $(,)?) => {122 if !$cond {123 return $crate::private::Err($crate::Error::msg(124 $crate::private::concat!("Condition failed: `", $crate::private::stringify!($cond), "`")123 return $crate::__private::Err($crate::Error::msg(124 $crate::__private::concat!("Condition failed: `", $crate::__private::stringify!($cond), "`")125 ));126 }127 };128 ($cond:expr, $msg:literal $(,)?) => {129 if !$cond {130 return $crate::private::Err($crate::__anyhow!($msg));130 return $crate::__private::Err($crate::__anyhow!($msg));131 }132 };133 ($cond:expr, $err:expr $(,)?) => {134 if !$cond {135 return $crate::private::Err($crate::__anyhow!($err));135 return $crate::__private::Err($crate::__anyhow!($err));136 }137 };138 ($cond:expr, $fmt:expr, $($arg:tt)*) => {139 if !$cond {140 return $crate::private::Err($crate::__anyhow!($fmt, $($arg)*));140 return $crate::__private::Err($crate::__anyhow!($fmt, $($arg)*));141 }142 };143}144
43 unmodified lines
188/// ```189#[macro_export]190macro_rules! anyhow {191 ($msg:literal $(,)?) => {192 $crate::private::must_use({193 let error = $crate::private::format_err($crate::private::format_args!($msg));192 $crate::__private::must_use({193 let error = $crate::__private::format_err($crate::__private::format_args!($msg));194 error195 })196 };197 ($err:expr $(,)?) => {198 $crate::private::must_use({199 use $crate::private::kind::*;198 $crate::__private::must_use({199 use $crate::__private::kind::*;200 let error = match $err {201 error => (&error).anyhow_kind().new(error),202 };203 error204 })205 };206 ($fmt:expr, $($arg:tt)*) => {207 $crate::Error::msg($crate::private::format!($fmt, $($arg)*))207 $crate::Error::msg($crate::__private::format!($fmt, $($arg)*))208 };209}210211// Not public API. This is used in the implementation of some of the other
2 unmodified lines
214#[doc(hidden)]215#[macro_export]216macro_rules! __anyhow {217 ($msg:literal $(,)?) => ({218 let error = $crate::private::format_err($crate::private::format_args!($msg));218 let error = $crate::__private::format_err($crate::__private::format_args!($msg));219 error220 });221 ($err:expr $(,)?) => ({222 use $crate::private::kind::*;222 use $crate::__private::kind::*;223 let error = match $err {224 error => (&error).anyhow_kind().new(error),225 };226 error227 });228 ($fmt:expr, $($arg:tt)*) => {229 $crate::Error::msg($crate::private::format!($fmt, $($arg)*))229 $crate::Error::msg($crate::__private::format!($fmt, $($arg)*))230 };231}
modified:tests/ui/must-use.stderr+1 added-1 removed
1error: unused return value of `anyhow::private::must_use` that must be used1error: unused return value of `anyhow::__private::must_use` that must be used2 --> tests/ui/must-use.rs:8:93 |48 | anyhow!("it failed");5 | ^^^^^^^^^^^^^^^^^^^^
7 unmodified lines