-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Add regression tests for fixed dead-code issues #160044
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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> | ||
|
|
||
| //@ 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)] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the original test code from #102190 is much different with our new
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how this helper file comes from?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
| } | ||
| 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() {} |
| 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}"); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
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 believe this also covers #102217
View changes since the review