Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! Regression test for <https://github.com/rust-lang/rust/issues/102190>

@mu001999 mu001999 Jul 28, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this also covers #102217

View changes since the review


//@ check-pass
//@ proc-macro: generate-inherent-impl-with-input-spans.rs

#![deny(dead_code)]

extern crate generate_inherent_impl_with_input_spans;

use generate_inherent_impl_with_input_spans::Test;

#[allow(dead_code)]

@chenyukang chenyukang Jul 28, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the original test code from #102190 is much different with our new generate-inherent-impl-with-input-spans.rs?

View changes since the review

@mu001999 mu001999 Jul 28, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but we cannot use proc_macro2 directly in our test suite. So we have to construct the test case using proc_macro manually. The core part of the original case is using input span for the beginning and ending of the fn header.

#[derive(Test)]
#[repr(i8)]
pub(crate) enum MyEnum {
MyValue,
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
extern crate proc_macro;

use proc_macro::{Delimiter, Group, Ident, TokenStream, TokenTree};

#[proc_macro_derive(Test)]
pub fn derive(input: TokenStream) -> TokenStream {

@chenyukang chenyukang Jul 28, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how this helper file comes from?
you want to simply the test for #102217 without Cargo.toml, syn etc?

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for #102190, but I found it has the same root case with #102217.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have concern about #102217, I think it's okay to remove the line fixing it from the PR description.

let input = input.into_iter().collect::<Vec<_>>();
let input_span = input[0].span();

let output = "impl MyEnum {
pub(crate) fn false_positive(self) -> i8 {
self as i8
}
}"
.parse::<TokenStream>()
.unwrap()
.into_iter()
.collect::<Vec<_>>();

let TokenTree::Group(body) = &output[2] else { unreachable!() };
let mut body = body.stream().into_iter().collect::<Vec<_>>();

// Preserve the visibility tokens from the input, as `quote!` does when interpolating `#vis`.
body[0] = input[0].clone();
body[1] = input[1].clone();

// Give the return type the input's span, matching `Ident::new("i8", input.span())`.
body[7] = TokenTree::Ident(Ident::new("i8", input_span));

let mut generated_body =
Group::new(Delimiter::Brace, body.into_iter().collect::<TokenStream>());
generated_body.set_span(output[2].span());

vec![output[0].clone(), output[1].clone(), generated_body.into()].into_iter().collect()
}
25 changes: 25 additions & 0 deletions tests/ui/lint/dead-code/expect-on-assoc-fn-issue-148861.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//! Regression test for <https://github.com/rust-lang/rust/issues/148861>

//@ check-pass

#![deny(dead_code)]

use std::any::Any;

pub trait Foo: Any {}

impl Foo for Box<dyn Foo> {}

impl dyn Foo {
#[expect(dead_code)]
fn downcast_ref<T: 'static>(&self) -> Option<&T> {
let this = self as &dyn Any;
if let Some(boxed) = this.downcast_ref::<Box<dyn Foo>>() {
boxed.downcast_ref::<T>()
} else {
this.downcast_ref::<T>()
}
}
}

fn main() {}
17 changes: 17 additions & 0 deletions tests/ui/lint/dead-code/struct-used-as-pattern-issue-56750.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! Regression test for <https://github.com/rust-lang/rust/issues/56750>

//@ check-pass

#![deny(dead_code)]

use std::mem;

fn main() {
struct Value {
a: i32,
b: i32,
}

let Value { a, b } = unsafe { mem::zeroed() };
println!("{a} {b}");
}
Loading