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 11use crate :: MirPass ;
22use rustc_hir:: def_id:: DefId ;
3+ use rustc_hir:: lang_items:: LangItem ;
34use rustc_index:: vec:: IndexVec ;
45use rustc_middle:: mir:: * ;
56use rustc_middle:: mir:: {
@@ -17,6 +18,12 @@ impl<'tcx> MirPass<'tcx> for CheckAlignment {
1718 }
1819
1920 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+
2027 let basic_blocks = body. basic_blocks . as_mut ( ) ;
2128 let local_decls = & mut body. local_decls ;
2229
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