Skip to content

Commit 0abe6e5

Browse files
authored
fix overly strict lifetime bound in Default impl (#111)
* fix overly strict lifetime bound in Default impl
1 parent f3c23b9 commit 0abe6e5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## Unreleased
9+
10+
### Changed
11+
12+
- Implementation of the `Default` trait for `Pointer` now doesn't constrain the lifetime.
13+
814
## [0.7.1] 2025-02-16
915

1016
### Changed

src/pointer.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ mod slice;
3636
#[cfg_attr(not(doc), repr(transparent))]
3737
pub struct Pointer(str);
3838

39-
impl Default for &'static Pointer {
39+
impl Default for &Pointer {
4040
fn default() -> Self {
4141
Pointer::root()
4242
}
@@ -2342,4 +2342,14 @@ mod tests {
23422342
let unboxed = boxed.into_buf();
23432343
assert_eq!(subjectal, unboxed);
23442344
}
2345+
2346+
#[test]
2347+
fn default_lifetime_is_correct() {
2348+
// if this compiles, we're good
2349+
fn or_default(ptr: &Pointer) -> &Pointer {
2350+
Some(ptr).unwrap_or_default()
2351+
}
2352+
// just to satisfy codecov and clippy
2353+
or_default(Pointer::root());
2354+
}
23452355
}

0 commit comments

Comments
 (0)