diff --git a/Cargo.lock b/Cargo.lock index 100626e..f169ce6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -40,7 +40,7 @@ checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "proc-macro-warning" -version = "1.0.0-rc.1" +version = "1.0.0" dependencies = [ "derive", "proc-macro2", diff --git a/README.md b/README.md index 9ff956f..1ee2dde 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ let warning = Warning::new_deprecated("OldStuffUsed") .new("my_macro::new()") .help_link("https:://example.com") .span(proc_macro2::Span::call_site()) - .build(); + .build_or_panic(); // Use the warning in a proc macro let tokens = quote::quote!(#warning); diff --git a/proc-macro-warning/Cargo.toml b/proc-macro-warning/Cargo.toml index 1acd318..1b00958 100644 --- a/proc-macro-warning/Cargo.toml +++ b/proc-macro-warning/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "proc-macro-warning" -version = "1.0.0-rc.1" +version = "1.0.0" edition = "2021" license = "GPL-3.0 OR Apache-2.0" authors = ["Oliver Tale-Yazdi "] diff --git a/proc-macro-warning/src/lib.rs b/proc-macro-warning/src/lib.rs index 950c1a5..41822dd 100644 --- a/proc-macro-warning/src/lib.rs +++ b/proc-macro-warning/src/lib.rs @@ -84,7 +84,7 @@ impl FormattedWarning { /// .help_link("https:://example.com") /// // Normally you use the input span, but this is an example: /// .span(proc_macro2::Span::call_site()) -/// .build(); +/// .build_or_panic(); /// /// let mut warnings = vec![warning]; /// // When adding more, you will need to build each with `.index`. @@ -161,7 +161,13 @@ impl DeprecatedWarningBuilder { } /// Fallibly build a warning. + #[deprecated(note = "Use `try_build` instead; Will be removed after Q1 2024")] pub fn maybe_build(self) -> Result { + self.try_build() + } + + /// Try to build the warning. + pub fn try_build(self) -> Result { let span = self.span.unwrap_or_else(Span::call_site); let title = self.title; let old = self.old.ok_or("Missing old")?; @@ -173,8 +179,15 @@ impl DeprecatedWarningBuilder { /// Unwraps [`Self::maybe_build`] for convenience. #[must_use] + #[deprecated(note = "Use `build_or_panic` instead; Will be removed after Q1 2024")] pub fn build(self) -> Warning { - self.maybe_build().expect("maybe_build failed") + self.build_or_panic() + } + + /// Build the warning or panic if it fails. + #[must_use] + pub fn build_or_panic(self) -> Warning { + self.try_build().expect("maybe_build failed") } } diff --git a/proc-macro-warning/src/test.rs b/proc-macro-warning/src/test.rs index f9614fa..b86149c 100644 --- a/proc-macro-warning/src/test.rs +++ b/proc-macro-warning/src/test.rs @@ -16,7 +16,7 @@ fn example_works() { .new("my_macro::new()") .help_link("https:://example.com") .span(proc_macro2::Span::call_site()) - .build(); + .build_or_panic(); let got_tokens = quote!(#warning); let want_tokens = quote!( @@ -77,7 +77,7 @@ fn warning_debug_works() { .new("my_macro::new()") .help_link("https:://example.com") .span(proc_macro2::Span::call_site()) - .build(); + .build_or_panic(); let _ = format!("{:?}", warning); } diff --git a/ui-tests/derive/src/lib.rs b/ui-tests/derive/src/lib.rs index 525c619..3dc6f92 100644 --- a/ui-tests/derive/src/lib.rs +++ b/ui-tests/derive/src/lib.rs @@ -18,7 +18,7 @@ fn impl_dep(input: TokenStream, span: bool) -> TokenStream { let input = syn::parse_macro_input!(input as syn::DeriveInput); let warning = proc_macro_warning::Warning::new_deprecated("test").old("foo").new("bar"); - let warning = if span { warning.span(input.span()) } else { warning }.build(); + let warning = if span { warning.span(input.span()) } else { warning }.build_or_panic(); warning.into_token_stream().into() }