Skip to content

1.64 - Unexpected dead_code warning from inside macro expansion. #102217

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

Open
Themayu opened this issue Sep 24, 2022 · 7 comments
Open

1.64 - Unexpected dead_code warning from inside macro expansion. #102217

Themayu opened this issue Sep 24, 2022 · 7 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. L-dead_code Lint: dead_code P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Themayu
Copy link

Themayu commented Sep 24, 2022

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
@Themayu Themayu added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Sep 24, 2022
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Sep 24, 2022
@inquisitivecrystal
Copy link
Contributor

inquisitivecrystal commented Sep 24, 2022

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.

@apiraino apiraino added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Sep 24, 2022
@Themayu
Copy link
Author

Themayu commented Sep 24, 2022

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.)

@inquisitivecrystal
Copy link
Contributor

Thanks! This bisects to #98402. CC @cjgillot.

@inquisitivecrystal inquisitivecrystal added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-untriaged Untriaged performance or correctness regression. labels Sep 25, 2022
@cjgillot cjgillot self-assigned this Sep 25, 2022
@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium -E-needs-mcve

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Sep 25, 2022
@inquisitivecrystal inquisitivecrystal added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 25, 2022
tdyas pushed a commit to tdyas/pants that referenced this issue Sep 27, 2022
Needed due to rust-lang/rust#102217 (comment)

[ci skip-build-wheels]
tdyas pushed a commit to pantsbuild/pants that referenced this issue Sep 28, 2022
@fee1-dead fee1-dead added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 2, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Oct 2, 2022
Give `def_span` the same SyntaxContext as `span_with_body`.

rust-lang#102217

I'm not sure how to add a test, since the erroneous span was crafted using a proc macro.
The debug assertion in `def_span` will ensure we have the correct behaviour.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Oct 2, 2022
Give `def_span` the same SyntaxContext as `span_with_body`.

rust-lang#102217

I'm not sure how to add a test, since the erroneous span was crafted using a proc macro.
The debug assertion in `def_span` will ensure we have the correct behaviour.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Oct 2, 2022
Give `def_span` the same SyntaxContext as `span_with_body`.

rust-lang#102217

I'm not sure how to add a test, since the erroneous span was crafted using a proc macro.
The debug assertion in `def_span` will ensure we have the correct behaviour.
RalfJung pushed a commit to RalfJung/miri that referenced this issue Oct 4, 2022
Give `def_span` the same SyntaxContext as `span_with_body`.

rust-lang/rust#102217

I'm not sure how to add a test, since the erroneous span was crafted using a proc macro.
The debug assertion in `def_span` will ensure we have the correct behaviour.
@cjgillot cjgillot removed their assignment Oct 9, 2022
@BGR360
Copy link
Contributor

BGR360 commented Nov 11, 2022

possible dupe of #102217

@Themayu
Copy link
Author

Themayu commented Nov 11, 2022

You just said this issue is a possible dupe of this issue...

@BGR360
Copy link
Contributor

BGR360 commented Nov 11, 2022

Damn lol, too many tabs open

@JohnTitor JohnTitor added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Dec 14, 2022
jneem added a commit to standard-ai/ya-gcp that referenced this issue Dec 23, 2022
This fixes a spurious dead-code warning that was causing tests to fail.
See rust-lang/rust#102217
jneem added a commit to standard-ai/ya-gcp that referenced this issue Dec 23, 2022
This fixes a spurious dead-code warning that was causing tests to fail.
See rust-lang/rust#102217
jneem added a commit to standard-ai/ya-gcp that referenced this issue Feb 17, 2023
This fixes a spurious dead-code warning that was causing tests to fail.
See rust-lang/rust#102217
rnarubin pushed a commit to standard-ai/ya-gcp that referenced this issue Mar 21, 2023
This fixes a spurious dead-code warning that was causing tests to fail.
See rust-lang/rust#102217
@jieyouxu jieyouxu added the L-dead_code Lint: dead_code label May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. L-dead_code Lint: dead_code P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

9 participants