-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Description
With a static function sf
on a trait implemented on struct S
, then calling S::sf(&value)
with value being (&str, …)
, the borrow checker will report that the string within the tuple doesn't live long enough. It behaves like it expects &str
to be static, and indeed works only with &'static strings. However, if S::sf
is made into a standalone function sf
, it works as expected with non-static strings.
I tried to run cargo check
on this code, which caused these error messages:
Instead I expected the check to pass.
When commenting in this line and commenting out this line sf
is used instead, and cargo check
passes as expected.
How to reproduce
The following snippet takes 1min 10s to execute on a 12core laptop.
git clone https://github.com/crates-io/criner && \
cd criner && \
git checkout 2c6314397b347d4b3ddd4dcf6e3f0278bcaa447b && \
cargo check
Observations
The error message provided by the borrow checker is sparse compared to how helpful it usually is. Also I do suspect it is related to interactions of using references in static trait functions.
Meta
rustc --version --verbose
:
rustc 1.41.0 (5e1a79984 2020-01-27)
binary: rustc
commit-hash: 5e1a799842ba6ed4a57e91f7ab9435947482f7d8
commit-date: 2020-01-27
host: x86_64-apple-darwin
release: 1.41.0
LLVM version: 9.0
Also tested on nightly - the issue persists:
rustc +nightly --version --verbose
rustc 1.43.0-nightly (834bc5650 2020-02-24)
binary: rustc
commit-hash: 834bc5650acf7019a53b409db68986857822812c
commit-date: 2020-02-24
host: x86_64-apple-darwin
release: 1.43.0-nightly
LLVM version: 9.0