-
Notifications
You must be signed in to change notification settings - Fork 0
chore: switch to Rust 2024 edition #1269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
b349801
to
eb62183
Compare
@@ -50,7 +50,7 @@ pub struct LoggingConfig { | |||
impl LoggingConfig { | |||
/// Returns the configured filter according to the corresponding fields. The filter will also allow | |||
/// any span whose level doesn't exceed [SPAN_ATTRIBUTES_MAX_LEVEL]. | |||
pub fn filter(&self) -> Result<impl Filter<Registry>, LoggingConfigError> { | |||
pub fn filter(&self) -> Result<impl Filter<Registry> + use<>, LoggingConfigError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference of the use<>
: https://doc.rust-lang.org/stable/reference/types/impl-trait.html#precise-capturing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've read some documentation and blog posts. I'm still a bit puzzled. Was this added by the migrator? Is it extremely necessary or the function would still work if we removed the use
bound, but using it is more correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it was added automatically by the migrator. In Rust 2024 if you remove this the project stops compiling due to borrowed data escaping some functions in the tracing_layers
module. Let me retrieve the exact lints to give more context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't worry, I can do that on my computer and check it out. I was curious if it was automatically done and potentially not required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$ cargo build
# ...
error[E0521]: borrowed data escapes outside of function
--> agent-control/src/instrumentation/tracing_layers/file.rs:29:25
|
18 | config: &LoggingConfig,
| ------ - let's call the lifetime of this reference `'1`
| |
| `config` is a reference that is only valid in the function body
...
29 | let layer = tracing_subscriber::fmt::layer()
| _________________________^
30 | | .with_writer(file_writer)
31 | | .with_ansi(false) // Disable colors for file
32 | | .with_target(target)
... |
35 | | .with_filter(config.filter()?)
36 | | .boxed();
| | ^
| | |
| |________________________`config` escapes the function body here
| argument requires that `'1` must outlive `'static`
error[E0521]: borrowed data escapes outside of function
--> agent-control/src/instrumentation/tracing_layers/stdout.rs:12:17
|
8 | pub fn stdout(config: &LoggingConfig) -> Result<LayerBox, LoggingConfigError> {
| ------ - let's call the lifetime of this reference `'1`
| |
| `config` is a reference that is only valid in the function body
...
12 | let layer = tracing_subscriber::fmt::layer()
| _________________^
13 | | .with_writer(std::io::stdout)
14 | | .with_ansi(config.format.ansi_colors)
15 | | .with_target(target)
... |
18 | | .with_filter(config.filter()?)
19 | | .boxed();
| | ^
| | |
| |________________`config` escapes the function body here
| argument requires that `'1` must outlive `'static`
For more information about this error, try `rustc --explain E0521`.
error: could not compile `newrelic_agent_control` (lib) due to 2 previous errors
So now apparently we have to make explicit that the type impl Filter<Registry>
doesn't capture any lifetimes of the &LoggingConfig
/&self
. I will try to search for more info to better clarify how this changed in Rust 2024.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a stackoverflow link pointing to other three resources
https://blog.rust-lang.org/2024/10/17/Rust-1.82.0/#precise-capturing-use-syntax
https://blog.rust-lang.org/2024/09/05/impl-trait-capture-rules/
https://github.com/rust-lang/rfcs/blob/master/text/3617-precise-capturing.md
Those are helpful, but I never used that so it's confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the exact change related to "impl traits in return position (RPIT)": https://doc.rust-lang.org/nightly/edition-guide/rust-2024/rpit-lifetime-capture.html
In Rust 2024, all in-scope generic parameters, including lifetime parameters, are implicitly captured when the
use<..>
bound is not present.
eb62183
to
02cb7c9
Compare
02cb7c9
to
6ba44fd
Compare
26e7c4d
to
087f008
Compare
087f008
to
11ccbb3
Compare
What this PR does / why we need it
Updates the project to use Rust 2024, which includes some syntax and semantic breaking changes but will allow us to use additional new features such as
let_chains
in Rust 1.88.The codebase was migrated automatically using
cargo fix --edition --all-features
so there might be changes done conservatively, like thematch
expressions replacingif let
s in dafa43c. Where appropriate, I'll try to rework the syntax for it to be more clear before applying the finalcargo fmt
that will change a lot of files.Checklist
[Place an '[x]' (no spaces) in all applicable fields. Please remove unrelated fields.]
docs
is aligned with the change.CONTRIBUTING.md
.log level guidelines
.