rust
rust copied to clipboard
1.64 - Unexpected `dead_code` warning from inside macro expansion.
I am getting an unexpected dead_code
warning from inside a procedural macro's output. This warning did not appear in the previous version of the Rust Compiler. This is not present in the changelog for 1.64, so I do not believe it to be an expected change.
Code
I tried this code:
#[pin_project(project = Merge2Proj)]
#[derive(Debug)]
pub struct Merge2
{
// struct contents...
}
// impl that only makes use of Merge2Proj::project...
I expected to see this happen: I expected the code to compile without warnings, as was true for the previous compiler version.
Instead, this happened: I get a dead_code
warning from inside the pin_project
macro expansion, telling me that Merge2Proj::project_ref
is unused. This warning is impossible for me to remove, as I have no need for project_ref
and there is no way to tell pin_project
to not generate it.
Version it worked on
It most recently worked on: 1.63
Version with regression
rustc --version --verbose
:
rustc 1.64.0 (a55dd71d5 2022-09-19)
binary: rustc
commit-hash: a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52
commit-date: 2022-09-19
host: x86_64-pc-windows-msvc
release: 1.64.0
LLVM version: 14.0.6
Thanks for the report!
This should be fixed by pin_project
version 1.0.11. I'm having a lot of trouble reproducing the warning, even on older versions of pin_project
; I think I'd need a complete example of the code that triggers the warning to have a chance of doing so.
This warning came from pin_project
version 1.0.8; I wasn't aware that there were updates available that prevented it. With that in mind, it should be reproducible by the following std::future::Future
custom implementation:
# Cargo.toml
[package]
name = "warn_test"
description = ""
authors = ["Jamie Ridding"]
license = "MIT OR Apache-2.0"
version = "0.0.0"
[dependencies]
pin-project = "=1.0.8"
// main.rs
use pin_project::pin_project;
use std::future::Future;
use std::task::{Context, Poll};
use std::pin::Pin;
#[pin_project(project = PinProjectTestProj)]
#[derive(Debug)]
pub struct PinProjectTest<Fut>
where
Fut: Future<Output = ()>,
{
#[pin]
fut: Fut,
}
impl<Fut> PinProjectTest<Fut>
where
Fut: Future<Output = ()>,
{
pub fn new(fut: Fut) -> Self {
PinProjectTest {
fut,
}
}
}
impl<Fut> Future for PinProjectTest<Fut>
where
Fut: Future<Output = ()>,
{
type Output = Fut::Output;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let PinProjectTestProj { fut } = self.project();
fut.poll(cx)
}
}
#[allow(unused_must_use)]
fn main() {
let fut = async {};
let test = PinProjectTest::new(fut);
async {
test.await;
};
}
cargo check
:
PS C:\Users\jamie\test> cargo clean
PS C:\Users\jamie\test> cargo check
Compiling proc-macro2 v1.0.43
Compiling quote v1.0.21
Compiling unicode-ident v1.0.4
Compiling syn v1.0.100
Compiling pin-project-internal v1.0.8
Checking pin-project v1.0.8
Checking warn_test v0.1.0 (C:\Users\jamie\test)
warning: associated function `project_ref` is never used
--> src\main.rs:7:1
|
7 | #[pin_project(project = PinProjectTestProj)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
warning: `warn_test` (bin "warn_test") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 6.06s
PS C:\Users\jamie\test>
cargo +1.63 check
:
PS C:\Users\jamie\test> cargo clean
PS C:\Users\jamie\test> cargo +1.63 check
Compiling proc-macro2 v1.0.43
Compiling unicode-ident v1.0.4
Compiling quote v1.0.21
Compiling syn v1.0.100
Compiling pin-project-internal v1.0.8
Checking pin-project v1.0.8
Checking warn_test v0.1.0 (C:\Users\jamie\test)
Finished dev [unoptimized + debuginfo] target(s) in 7.54s
PS C:\Users\jamie\test>
(Sorry for the huge amount of edits, I am terrible at remembering to include information. And writing, apparently.)
Thanks! This bisects to #98402. CC @cjgillot.
WG-prioritization assigning priority (Zulip discussion).
@rustbot label -I-prioritize +P-medium -E-needs-mcve
possible dupe of https://github.com/rust-lang/rust/issues/102217
You just said this issue is a possible dupe of this issue...
Damn lol, too many tabs open