Skip to content

Commit 6358dcc

Browse files
committed
test: add regression test for fuzzy_provenance_casts lint ICE
1 parent ba15679 commit 6358dcc

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Regression test for #137588.
2+
// The compiler used to ICE when emitting a `fuzzy_provenance_casts` lint
3+
// diagnostic for code with an inner attribute spanning the entire file,
4+
// causing `draw_code_line` to panic on an empty `file_lines` from a dummy span.
5+
6+
//@ edition:2024
7+
//@ compile-flags: -Wfuzzy-provenance-casts
8+
9+
#![feature(strict_provenance_lints)]
10+
//~^ ERROR too many leading `super` keywords [E0433]
11+
//~| ERROR cannot find type `Ts` in this scope [E0425]
12+
//~| ERROR `#[prelude_import]` is for use by rustc only [E0658]
13+
//~| WARN strict provenance disallows casting integer `usize` to pointer `*const u32`
14+
#![core::contracts::ensures(|ret| ret.is_none_or(Stars::is_valid))]
15+
//~^ ERROR use of unstable library feature `contracts` [E0658]
16+
//~| ERROR inner macro attributes are unstable [E0658]
17+
//~| ERROR cannot find type `Stars` in this scope [E0433]
18+
19+
pub(super) fn foo() -> *const Ts {
20+
unsafe {
21+
let p2 = 0x52 as *const u32;
22+
}
23+
}
24+
//~^ ERROR `main` function not found in crate
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
error[E0658]: use of unstable library feature `contracts`
2+
--> $DIR/ice-fuzzy-provenance-casts-with-inner-attr.rs:14:4
3+
|
4+
LL | #![core::contracts::ensures(|ret| ret.is_none_or(Stars::is_valid))]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #128044 <https://github.com/rust-lang/rust/issues/128044> for more information
8+
= help: add `#![feature(contracts)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error[E0658]: inner macro attributes are unstable
12+
--> $DIR/ice-fuzzy-provenance-casts-with-inner-attr.rs:14:4
13+
|
14+
LL | #![core::contracts::ensures(|ret| ret.is_none_or(Stars::is_valid))]
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^
16+
|
17+
= note: see issue #54726 <https://github.com/rust-lang/rust/issues/54726> for more information
18+
= help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable
19+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
20+
21+
error[E0433]: too many leading `super` keywords
22+
--> $DIR/ice-fuzzy-provenance-casts-with-inner-attr.rs:9:1
23+
|
24+
LL | / #![feature(strict_provenance_lints)]
25+
... |
26+
LL | | }
27+
| |_^ there are too many leading `super` keywords
28+
29+
error[E0425]: cannot find type `Ts` in this scope
30+
--> $DIR/ice-fuzzy-provenance-casts-with-inner-attr.rs:9:1
31+
|
32+
LL | / #![feature(strict_provenance_lints)]
33+
... |
34+
LL | | }
35+
| |_^ not found in this scope
36+
37+
error[E0658]: `#[prelude_import]` is for use by rustc only
38+
--> $DIR/ice-fuzzy-provenance-casts-with-inner-attr.rs:9:1
39+
|
40+
LL | / #![feature(strict_provenance_lints)]
41+
... |
42+
LL | | }
43+
| |_^
44+
|
45+
= help: add `#![feature(prelude_import)]` to the crate attributes to enable
46+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
47+
48+
error[E0601]: `main` function not found in crate `ice_fuzzy_provenance_casts_with_inner_attr`
49+
--> $DIR/ice-fuzzy-provenance-casts-with-inner-attr.rs:23:2
50+
|
51+
LL | }
52+
| ^ consider adding a `main` function to `$DIR/ice-fuzzy-provenance-casts-with-inner-attr.rs`
53+
54+
error[E0433]: cannot find type `Stars` in this scope
55+
--> $DIR/ice-fuzzy-provenance-casts-with-inner-attr.rs:14:50
56+
|
57+
LL | #![core::contracts::ensures(|ret| ret.is_none_or(Stars::is_valid))]
58+
| ^^^^^ use of undeclared type `Stars`
59+
60+
warning: strict provenance disallows casting integer `usize` to pointer `*const u32`
61+
--> $DIR/ice-fuzzy-provenance-casts-with-inner-attr.rs:9:1
62+
|
63+
LL | / #![feature(strict_provenance_lints)]
64+
... |
65+
LL | | }
66+
| |_^
67+
|
68+
= help: if you can't comply with strict provenance and don't have a pointer with the correct provenance you can use `std::ptr::with_exposed_provenance()` instead
69+
= note: requested on the command line with `-W fuzzy-provenance-casts`
70+
help: use `.with_addr()` to adjust a valid pointer in the same allocation, to this address
71+
|
72+
LL - #![feature(strict_provenance_lints)]
73+
LL -
74+
LL -
75+
LL -
76+
LL -
77+
LL - #![core::contracts::ensures(|ret| ret.is_none_or(Stars::is_valid))]
78+
LL -
79+
LL -
80+
LL -
81+
LL -
82+
LL - pub(super) fn foo() -> *const Ts {
83+
LL - unsafe {
84+
LL - let p2 = 0x52 as *const u32;
85+
LL - }
86+
LL - }
87+
LL + (...).with_addr()
88+
|
89+
90+
error: aborting due to 7 previous errors; 1 warning emitted
91+
92+
Some errors have detailed explanations: E0425, E0433, E0601, E0658.
93+
For more information about an error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)