Skip to content

Commit

Permalink
Use new functions
Browse files Browse the repository at this point in the history
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  • Loading branch information
ggwpez committed Oct 8, 2023
1 parent 4a7c91a commit abcd6dd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions proc-macro-warning/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -180,13 +180,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.build_or_panic()
}

/// Build the warning or panic if it fails.
#[must_use]
pub fn build_or_panic(self) -> Warning {
self.maybe_build().expect("maybe_build failed")
self.try_build().expect("maybe_build failed")
}
}

Expand Down
4 changes: 2 additions & 2 deletions proc-macro-warning/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion ui-tests/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit abcd6dd

Please sign in to comment.