Skip to content

Test signatures for functions that only accept 'static borrows - #21

Merged
tanglearncode merged 1 commit into
mainfrom
tests/static-only-signatures
Sep 13, 2026
Merged

tanglearncode merged 1 commit into
mainfrom
tests/static-only-signatures

Conversation

@tanglearncode

@tanglearncode tanglearncode commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Adds tests for functions that only take 'static borrows.

Since #19, mock! and replace! reject a safe signature like fn(&'static str) for these functions. They need unsafe fn(&'static str).

  • mock! and replace! docs: a compile_fail example for the rejected signature.
  • tests/replacement.rs: replace! works with unsafe fn(&'static str) -> usize.

Both doctests fail with the lifetime error when compiled alone. CI passes.

Since the signature check change, a safe mock! or replace! signature cannot
declare a 'static borrowed input, even for a function that only accepts
'static borrows; such functions use an unsafe fn signature. Only mock! had a
test for that form, and neither macro documented the rejection.

Two compile_fail doctests now show that a safe fn(&'static str) signature is
rejected for such a function, one for mock! and one for replace!.
tests/replacement.rs gains a test that replaces one through
unsafe fn(&'static str) -> usize and checks that the replacement kept its
'static argument.
@tanglearncode
tanglearncode merged commit 6ad89e4 into main Sep 13, 2026
12 checks passed
@tanglearncode
tanglearncode deleted the tests/static-only-signatures branch September 14, 2026 03:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant