Skip to content

Commit 075f1c3

Browse files
authored
Rollup merge of #121025 - oli-obk:taint_after_errors, r=petrochenkov
add known-bug tests for derive failure to detect packed repr We only taint if it was a normal item. Modules and imports are untouched. Tainting them needs to be done differently, and it's unclear if that would be useful or desirable. If we just taint them into `Res::Err`, we end up losing some duplicate name messages *in the presence of other resolution errors*. r? `@petrochenkov`
2 parents 1b2c53a + bed9d1f commit 075f1c3

5 files changed

+108
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//@ force-host
2+
//@ no-prefer-dynamic
3+
//@ compile-flags: --crate-type proc-macro
4+
5+
extern crate proc_macro;
6+
7+
use proc_macro::*;
8+
9+
#[proc_macro_attribute]
10+
pub fn proc_macro_attribute_that_generates_repr_packed(
11+
_attr: TokenStream,
12+
item: TokenStream,
13+
) -> TokenStream {
14+
let repr = vec![TokenTree::Ident(Ident::new("packed", Span::call_site()))].into_iter();
15+
let attr = vec![
16+
TokenTree::Ident(Ident::new("repr", Span::call_site())),
17+
TokenTree::Group(Group::new(Delimiter::Parenthesis, repr.collect())),
18+
]
19+
.into_iter();
20+
vec![
21+
TokenTree::Punct(Punct::new('#', Spacing::Alone)),
22+
TokenTree::Group(Group::new(Delimiter::Bracket, attr.collect())),
23+
]
24+
.into_iter()
25+
.chain(item)
26+
.collect()
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! This test ICEs because the `repr(packed)` attributes
2+
//! end up on the `Dealigned` struct's attribute list, but the
3+
//! derive didn't see that.
4+
5+
//@known-bug: #120873
6+
//@ failure-status: 101
7+
//@ normalize-stderr-test "note: .*\n\n" -> ""
8+
//@ normalize-stderr-test "thread 'rustc' panicked.*\n" -> ""
9+
//@ normalize-stderr-test "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: "
10+
//@ rustc-env:RUST_BACKTRACE=0
11+
12+
#[repr(packed)]
13+
struct Dealigned<T>(u8, T);
14+
15+
#[derive(PartialEq)]
16+
#[repr(C)]
17+
struct Dealigned<T>(u8, T);
18+
19+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0428]: the name `Dealigned` is defined multiple times
2+
--> $DIR/multiple_definitions_attribute_merging.rs:17:1
3+
|
4+
LL | struct Dealigned<T>(u8, T);
5+
| --------------------------- previous definition of the type `Dealigned` here
6+
...
7+
LL | struct Dealigned<T>(u8, T);
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Dealigned` redefined here
9+
|
10+
= error: internal compiler error: compiler/rustc_mir_transform/src/check_packed_ref.rs:LL:CC: builtin derive created an unaligned reference
11+
--> $DIR/multiple_definitions_attribute_merging.rs:17:25
12+
|
13+
LL | #[derive(PartialEq)]
14+
| --------- in this derive macro expansion
15+
LL | #[repr(C)]
16+
LL | struct Dealigned<T>(u8, T);
17+
| ^
18+
|
19+
= Box<dyn Any>
20+
query stack during panic:
21+
#0 [mir_const] preparing `<impl at $DIR/multiple_definitions_attribute_merging.rs:15:10: 15:19>::eq` for borrow checking
22+
#1 [mir_promoted] promoting constants in MIR for `<impl at $DIR/multiple_definitions_attribute_merging.rs:15:10: 15:19>::eq`
23+
end of query stack
24+
error: aborting due to 2 previous errors
25+
26+
For more information about this error, try `rustc --explain E0428`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! This test ICEs because the `repr(packed)` attribute
2+
//! was generated by a proc macro, so `#[derive]` didn't see it.
3+
4+
//@aux-build: proc_macro_generate_packed.rs
5+
//@known-bug: #120873
6+
//@ failure-status: 101
7+
//@ normalize-stderr-test "note: .*\n\n" -> ""
8+
//@ normalize-stderr-test "thread 'rustc' panicked.*\n" -> ""
9+
//@ normalize-stderr-test "(error: internal compiler error: [^:]+):\d+:\d+: " -> "$1:LL:CC: "
10+
//@ rustc-env:RUST_BACKTRACE=0
11+
12+
extern crate proc_macro_generate_packed;
13+
use proc_macro_generate_packed::proc_macro_attribute_that_generates_repr_packed;
14+
15+
#[derive(PartialEq)]
16+
#[repr(C)]
17+
#[proc_macro_attribute_that_generates_repr_packed]
18+
struct Dealigned<T>(u8, T);
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: internal compiler error: compiler/rustc_mir_transform/src/check_packed_ref.rs:LL:CC: builtin derive created an unaligned reference
2+
--> $DIR/proc_macro_generated_packed.rs:18:25
3+
|
4+
LL | #[derive(PartialEq)]
5+
| --------- in this derive macro expansion
6+
...
7+
LL | struct Dealigned<T>(u8, T);
8+
| ^
9+
|
10+
= Box<dyn Any>
11+
query stack during panic:
12+
#0 [mir_const] preparing `<impl at $DIR/proc_macro_generated_packed.rs:15:10: 15:19>::eq` for borrow checking
13+
#1 [mir_promoted] promoting constants in MIR for `<impl at $DIR/proc_macro_generated_packed.rs:15:10: 15:19>::eq`
14+
end of query stack
15+
error: aborting due to 1 previous error
16+

0 commit comments

Comments
 (0)