This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
compiler/rustc_mir_transform/src Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 1
1
use crate :: MirPass ;
2
2
use rustc_hir:: def_id:: DefId ;
3
+ use rustc_hir:: lang_items:: LangItem ;
3
4
use rustc_index:: vec:: IndexVec ;
4
5
use rustc_middle:: mir:: * ;
5
6
use rustc_middle:: mir:: {
@@ -17,6 +18,12 @@ impl<'tcx> MirPass<'tcx> for CheckAlignment {
17
18
}
18
19
19
20
fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
21
+ // This pass emits new panics. If for whatever reason we do not have a panic
22
+ // implementation, running this pass may cause otherwise-valid code to not compile.
23
+ if tcx. lang_items ( ) . get ( LangItem :: PanicImpl ) . is_none ( ) {
24
+ return ;
25
+ }
26
+
20
27
let basic_blocks = body. basic_blocks . as_mut ( ) ;
21
28
let local_decls = & mut body. local_decls ;
22
29
Original file line number Diff line number Diff line change
1
+ // Ensures that the alignment check we insert for raw pointer dereferences
2
+ // does not prevent crates without a panic_impl from compiling.
3
+ // See rust-lang/rust#109996
4
+
5
+ // build-pass
6
+ // compile-flags: -Cdebug-assertions=yes
7
+
8
+ #![ crate_type = "lib" ]
9
+
10
+ #![ feature( lang_items) ]
11
+ #![ feature( no_core) ]
12
+ #![ no_core]
13
+
14
+ #[ lang = "sized" ]
15
+ trait Foo { }
16
+
17
+ pub unsafe fn foo ( x : * const i32 ) -> & ' static i32 { unsafe { & * x } }
You can’t perform that action at this time.
0 commit comments