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

Allow calling `const unsafe fn` in `const fn` behind a feature gate #55635

Merged
merged 23 commits into from Dec 6, 2018

Conversation

@oli-obk
Copy link
Contributor

oli-obk commented Nov 2, 2018

@Centril
Copy link
Contributor

Centril left a comment

Tests look mostly good :)

}
// not ok
const unsafe fn foo8_2() -> i32 {
foo4() //~ ERROR not allowed in const fn

This comment has been minimized.

@Centril

Centril Nov 3, 2018

Contributor

The error message doesn't seem great here; the user isn't made aware that it can be fixed by wrapping in unsafe { ... } so knowing how to fix it sort of depends on having been introduced to the tracking issue / PR.

This comment has been minimized.

@nikomatsakis

nikomatsakis Nov 29, 2018

Contributor

It may indeed be worth having an extra note like:

= note: unsafe actions within a `const unsafe fn` still require an `unsafe` block
Show resolved Hide resolved src/test/ui/consts/min_const_fn/min_const_fn_unsafe.stderr Outdated
Show resolved Hide resolved src/test/ui/consts/min_const_fn/min_const_fn_unsafe_feature_gate.rs
@Centril

This comment has been minimized.

Copy link
Contributor

Centril commented Nov 3, 2018

Passing the review over to Ralf;

r? @RalfJung

@rust-highfive rust-highfive assigned RalfJung and unassigned Centril Nov 3, 2018

Show resolved Hide resolved src/librustc/ty/constness.rs Outdated
@RalfJung

This comment has been minimized.

Copy link
Member

RalfJung commented Nov 3, 2018

This doesn't actually allow any new operations in unsafe const fn, right? It just allows marking them as unsafe?

Unfortunately most of this is code that I am not at all familiar with, so I cannot judge the side-effects this may have. @Centril does that mean you would r+ and just want to get my opinion as well?

@oli-obk I am a bit confused why there are two places where it makes the body of an unsafe fn not behave like an unsafe block: In librustc_mir/build/mod.rs and in librustc_mir/transform/check_unsafety.rs. Why is that?

@oli-obk

This comment has been minimized.

Copy link
Contributor

oli-obk commented Nov 3, 2018

check_unsafety can actually bug! out for const fn where the body is treated as unsafe, I'll fix that.

@Centril

This comment has been minimized.

Copy link
Contributor

Centril commented Nov 3, 2018

@RalfJung

This doesn't actually allow any new operations in unsafe const fn, right? It just allows marking them as unsafe?

The intention is that calling const unsafe fns should now be allowed in unsafe { ... } in const unsafe? fn.

Unfortunately most of this is code that I am not at all familiar with, so I cannot judge the side-effects this may have. @Centril does that mean you would r+ and just want to get my opinion as well?

I mainly want someone who is more familiar with the compiler internals than me (e.g. you) to review the code and see that it is correct and such; but if you are not familiar with the code maybe let's pass it to a third person (e.g. eddyb) to also check it?

@oli-obk

This comment has been minimized.

Copy link
Contributor

oli-obk commented Nov 3, 2018

cc @arielb1 who wrote the original unsafety checker for MIR

@RalfJung

This comment has been minimized.

Copy link
Member

RalfJung commented Nov 3, 2018

if you are not familiar with the code maybe let's pass it to a third person (e.g. eddyb) to also check it?

The unsafety checker I can at least read because it works on MIR (but I wouldn't call that familiarity); the is_min_const_fn etc. stuff and the HIR things I have no idea about at all.

@rust-highfive

This comment was marked as outdated.

Copy link
Collaborator

rust-highfive commented Nov 3, 2018

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:05fad40f:start=1541284876858100045,finish=1541284930131123479,duration=53273023434
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-5.0
---
[00:04:41]    Compiling rustc_tsan v0.0.0 (/checkout/src/librustc_tsan)
[00:04:41]    Compiling rustc_asan v0.0.0 (/checkout/src/librustc_asan)
[00:04:42]    Compiling rustc_msan v0.0.0 (/checkout/src/librustc_msan)
[00:04:42]    Compiling rustc_lsan v0.0.0 (/checkout/src/librustc_lsan)
[00:04:50] warning: unnecessary `unsafe` block
[00:04:50]     |
[00:04:50]     |
[00:04:50] 73  |                       $Ty(unsafe { NonZero(n) })
[00:04:50]     |                           ^^^^^^ unnecessary `unsafe` block
[00:04:50] ...
[00:04:50] 110 | / nonzero_integers! {
[00:04:50] 111 | |     NonZeroU8(u8);
[00:04:50] 112 | |     NonZeroU16(u16);
[00:04:50] 113 | |     NonZeroU32(u32);
[00:04:50] 116 | |     NonZeroUsize(usize);
[00:04:50] 117 | | }
[00:04:50]     | |_- in this macro invocation
[00:04:50]     |
[00:04:50]     |
[00:04:50]     = note: #[warn(unused_unsafe)] on by default
[00:04:50] 
[00:04:50] warning: unnecessary `unsafe` block
[00:04:50]     |
[00:04:50]     |
[00:04:50] 73  |                       $Ty(unsafe { NonZero(n) })
[00:04:50]     |                           ^^^^^^ unnecessary `unsafe` block
[00:04:50] ...
[00:04:50] 110 | / nonzero_integers! {
[00:04:50] 111 | |     NonZeroU8(u8);
[00:04:50] 112 | |     NonZeroU16(u16);
[00:04:50] 113 | |     NonZeroU32(u32);
[00:04:50] 116 | |     NonZeroUsize(usize);
[00:04:50] 117 | | }
[00:04:50]     | |_- in this macro invocation
[00:04:50] 
[00:04:50] 
[00:04:50] warning: unnecessary `unsafe` block
[00:04:50]     |
[00:04:50]     |
[00:04:50] 81  |                           Some($Ty(unsafe { NonZero(n) }))
[00:04:50]     |                                    ^^^^^^ unnecessary `unsafe` block
[00:04:50] ...
[00:04:50] 110 | / nonzero_integers! {
[00:04:50] 111 | |     NonZeroU8(u8);
[00:04:50] 112 | |     NonZeroU16(u16);
[00:04:50] 113 | |     NonZeroU32(u32);
[00:04:50] 116 | |     NonZeroUsize(usize);
[00:04:50] 117 | | }
[00:04:50]     | |_- in this macro invocation
[00:04:50] 
[00:04:50] 
[00:04:50] warning: unnecessary `unsafe` block
[00:04:50]     --> libcore/ptr.rs:2755:36
[00:04:50]      |
[00:04:50] 2755 |             Some(Unique { pointer: unsafe { NonZero(ptr as _) }, _marker: PhantomData })
[00:04:50]      |                                    ^^^^^^ unnecessary `unsafe` block
[00:04:50] 
[00:04:50] warning: unnecessary `unsafe` block
[00:04:50]     --> libcore/ptr.rs:2811:27
[00:04:50]      |
[00:04:50] 2811 |         Unique { pointer: unsafe { NonZero(reference as _) }, _marker: PhantomData }
[00:04:50]      |                           ^^^^^^ unnecessary `unsafe` block
[00:04:50] 
[00:04:50] warning: unnecessary `unsafe` block
[00:04:50]     --> libcore/ptr.rs:2818:27
[00:04:50]      |
[00:04:50] 2818 |         Unique { pointer: unsafe { NonZero(reference as _) }, _marker: PhantomData }
[00:04:50]      |                           ^^^^^^ unnecessary `unsafe` block
[00:04:50] 
[00:04:50] warning: unnecessary `unsafe` block
[00:04:50]     --> libcore/ptr.rs:2891:28
[00:04:50]      |
[00:04:50] 2891 |         NonNull { pointer: unsafe { NonZero(ptr as _) } }
[00:04:50]      |                            ^^^^^^ unnecessary `unsafe` block
[00:04:50] 
[00:04:50] warning: unnecessary `unsafe` block
[00:04:50]     --> libcore/ptr.rs:2899:37
[00:04:50]      |
[00:04:50] 2899 |             Some(NonNull { pointer: unsafe { NonZero(ptr as _) } })
[00:04:50]      |                                     ^^^^^^ unnecessary `unsafe` block
[00:04:50] 
[00:04:50] warning: unnecessary `unsafe` block
[00:04:50]     --> libcore/ptr.rs:3021:28
[00:04:50]      |
[00:04:50] 3021 |         NonNull { pointer: unsafe { NonZero(reference as _) } }
[00:04:50]      |                            ^^^^^^ unnecessary `unsafe` block
[00:04:50] 
[00:04:50] warning: unnecessary `unsafe` block
[00:04:50]     --> libcore/ptr.rs:3029:28
[00:04:50]      |
[00:04:50] 3029 |         NonNull { pointer: unsafe { NonZero(reference as _) } }
[00:04:50]      |                            ^^^^^^ unnecessary `unsafe` block
[00:04:50] 
[00:04:50] warning: unnecessary `unsafe` block
[00:04:50]    |
[00:04:50]    |
[00:04:50] 26 |         unsafe { NonZero(self.0) }
[00:04:50]    |         ^^^^^^ unnecessary `unsafe` block
[00:04:57]    Compiling libc v0.0.0 (/checkout/src/rustc/libc_shim)
[00:04:57]    Compiling alloc v0.0.0 (/checkout/src/liballoc)
[00:04:58]    Compiling alloc_system v0.0.0 (/checkout/src/liballoc_system)
[00:04:58]    Compiling panic_abort v0.0.0 (/checkout/src/libpanic_abort)
---
[00:50:03] .................................................................................................... 100/4992
[00:50:06] .................................................................................................... 200/4992
[00:50:08] ...........................................................................................ii....... 300/4992
[00:50:11] .........................................................................................iii........ 400/4992
[00:50:14] iiiiiiii.iii...........................iii...........................................i...........i.. 500/4992
[00:50:21] .................................................................................................... 700/4992
[00:50:27] .....................................................................i...........i.................. 800/4992
[00:50:30] ........................................................................................iiiii....... 900/4992
[00:50:33] .................................................................................................... 1000/4992
---
[00:51:08] .................................................................................................... 2200/4992
[00:51:12] .................................................................................................... 2300/4992
[00:51:16] .................................................................................................... 2400/4992
[00:51:20] .................................................................................................... 2500/4992
[00:51:23] .........................................................................iiiiiiiii.................. 2600/4992
[00:51:30] ........................ii.......................................................................... 2800/4992
[00:51:33] .................................................................................................... 2900/4992
[00:51:36] .................................................................................................... 3000/4992
[00:51:39] ...................i................................................................................ 3100/4992
---
travis_time:start:test_codegen
Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:05:02] 
[01:05:02] running 115 tests
[01:05:05] i..ii...iii..iii.....i...i.........i..iii...........i.....i.....ii...i..i.ii..............i...ii..ii 100/115
[01:05:06] .i....iiii.....
[01:05:06] 
[01:05:06]  finished in 3.417
[01:05:06] travis_fold:end:test_codegen

---
travis_time:start:test_debuginfo
Check compiletest suite=debuginfo mode=debuginfo-both (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:05:20] 
[01:05:20] running 118 tests
[01:05:44] .iiiii...i.....i..i...i..i.i..i.i..i.....i..i....i..........iiii.........i.i....i...i.......ii.i.i.i 100/118
[01:05:48] ......iii.i.....ii
[01:05:48] 
[01:05:48]  finished in 28.294
[01:05:48] travis_fold:end:test_debuginfo

---
travis_time:start:test_run-pass-fulldeps
Check compiletest suite=run-pass-fulldeps mode=run-pass (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:06:26] 
[01:06:26] running 97 tests
[01:08:27] ........................................F..............test [run-pass] run-pass-fulldeps/myriad-closures.rs has been running for over 60 seconds
e used\" ] [ ! ( value <= $ max ) as usize ] ;","highlight_start":1,"highlight_end":74},{"text":"unsafe { $ type { private : value } } } # [ inline ] $ v const unsafe fn","highlight_start":1,"highlight_end":73},{"text":"from_u32_unchecked ( value : u32 ) -> Self {","highlight_start":1,"highlight_end":45},{"text":"unsafe { $ type { private : value } } }","highlight_start":1,"highlight_end":40},{"text":"/// Extract value of this index as an integer.","highlight_start":1,"highlight_end":47},{"text":" # [ inline ] $ v fn index ( self ) -> usize { self . as_usize (  ) }","highlight_start":1,"highlight_end":70},{"text":"/// Extract value of this index as a usize.","highlight_start":1,"highlight_end":44},{"text":" # [ inline ] $ v fn as_u32 ( self ) -> u32 { self . private }","highlight_start":1,"highlight_end":63},{"text":"/// Extract value of this index as a u32.","highlight_start":1,"highlight_end":42},{"text":" # [ inline ] $ v fn as_usize ( self ) -> usize { self . as_u32 (  ) as usize","highlight_start":1,"highlight_end":78},{"text":"} } impl Idx for $ type {","highlight_start":1,"highlight_end":26},{"text":"# [ inline ] fn new ( value : usize ) -> Self { Self :: from ( value ) } # [","highlight_start":1,"highlight_end":77},{"text":"inline ] fn index ( self ) -> usize { usize :: from ( self ) } } impl :: std","highlight_start":1,"highlight_end":77},{"text":":: iter :: Step for $ type {","highlight_start":1,"highlight_end":29},{"text":"# [ inline ] fn steps_between ( start : & Self , end : & Self ) -> Option <","highlight_start":1,"highlight_end":76},{"text":"usize > {","highlight_start":1,"highlight_end":10},{"text":"< usize as :: std :: iter :: Step > :: steps_between (","highlight_start":1,"highlight_end":55},{"text":"& Idx :: index ( * start ) , & Idx :: index ( * end ) , ) } # [ inline ] fn","highlight_start":1,"highlight_end":76},{"text":"replace_one ( & mut self ) -> Self {","highlight_start":1,"highlight_end":37},{"text":":: std :: mem :: replace ( self , Self :: new ( 1 ) ) } # [ inline ] fn","highlight_start":1,"highlight_end":72},{"text":"replace_zero ( & mut self ) -> Self {","highlight_start":1,"highlight_end":38},{"text":":: std :: mem :: replace ( self , Self :: new ( 0 ) ) } # [ inline ] fn","highlight_start":1,"highlight_end":72},{"text":"add_one ( & self ) -> Self { Self :: new ( Idx :: index ( * self ) + 1 ) } # [","highlight_start":1,"highlight_end":79},{"text":"inline ] fn sub_one ( & self ) -> Self {","highlight_start":1,"highlight_end":41},{"text":"Self :: new ( Idx :: index ( * self ) - 1 ) } # [ inline ] fn add_usize (","highlight_start":1,"highlight_end":74},{"text":"& self , u : usize ) -> Option < Self > {","highlight_start":1,"highlight_end":42},{"text":"Idx :: index ( * self ) . checked_add ( u ) . map ( Self :: new ) } } impl","highlight_start":1,"highlight_end":75},{"text":"From < $ type > for u32 {","highlight_start":1,"highlight_end":26},{"text":"# [ inline ] fn from ( v : $ type ) -> u32 { v . as_u32 (  ) } } impl From < $","highlight_start":1,"highlight_end":79},{"text":"type > for usize {","highlight_start":1,"highlight_end":19},{"text":"# [ inline ] fn from ( v : $ type ) -> usize { v . as_usize (  ) } } impl From","highlight_start":1,"highlight_end":79},{"text":"< usize > for $ type {","highlight_start":1,"highlight_end":23},{"text":"# [ inline ] fn from ( value : usize ) -> Self {","highlight_start":1,"highlight_end":49},{"text":"$ type :: from_usize ( value ) } } impl From < u32 > for $ type {","highlight_start":1,"highlight_end":66},{"text":"# [ inline ] fn from ( value : u32 ) -> Self { $ type :: from_u32 ( value ) }","highlight_start":1,"highlight_end":78},{"text":"} newtype_index ! (","highlight_start":1,"highlight_end":20},{"text":"@ handle_debug @ derives [ $ ( $ derives , ) * ] @ type [ $ type ] @","highlight_start":1,"highlight_end":69},{"text":"debug_format [ $ debug_format ] ) ; ) ; (","highlight_start":1,"highlight_end":42},{"text":"@ handle_debug @ derives [ $ ( $ _derives : ident , ) * ] @ type [","highlight_start":1,"highlight_end":67},{"text":"$ type : ident ] @ debug_format [ custom ] ) => (  ) ; (","highlight_start":1,"highlight_end":57},{"text":"@ handle_debug @ derives [  ] @ type [ $ type : ident ] @ debug_format [","highlight_start":1,"highlight_end":73},{"text":"$ debug_format : tt ] ) => (","highlight_start":1,"highlight_end":29},{"text":"impl :: std :: fmt :: Debug for $ type {","highlight_start":1,"highlight_end":41},{"text":"fn fmt ( & self , fmt : & mut :: std :: fmt :: Formatter ) -> :: std :: fmt ::","highlight_start":1,"highlight_end":79},{"text":"Result { write ! ( fmt , $ debug_format , self . as_u32 (  ) ) } } ) ; (","highlight_start":1,"highlight_end":73},{"text":"@ handle_debug @ derives [ Debug , $ ( $ derives : ident , ) * ] @ type [","highlight_start":1,"highlight_end":74},{"text":"$ type : ident ] @ debug_format [ $ debug_format : tt ] ) => (  ) ; (","highlight_start":1,"highlight_end":70},{"text":"@ handle_debug @ derives [ $ _derive : ident , $ ( $ derives : ident , ) * ] @","highlight_start":1,"highlight_end":79},{"text":"type [ $ type : ident ] @ debug_format [ $ debug_format : tt ] ) => (","highlight_start":1,"highlight_end":70},{"text":"newtype_index ! (","highlight_start":1,"highlight_end":18},{"text":"@ handle_debug @ derives [ $ ( $ derives , ) * ] @ type [ $ type ] @","highlight_start":1,"highlight_end":69},{"text":"debug_format [ $ debug_format ] ) ; ) ; (","highlight_start":1,"highlight_end":42},{"text":"@ type [ $ type : ident ] @ max [ $ max : expr ] @ vis [ $ v : vis ] @","highlight_start":1,"highlight_end":71},{"text":"debug_format [ $ debug_format : tt ] derive [ $ ( $ derives : ident ) , * ] $","highlight_start":1,"highlight_end":78},{"text":"( $ tokens : tt ) * ) => (","highlight_start":1,"highlight_end":27},{"text":"newtype_index ! (","highlight_start":1,"highlight_end":18},{"text":"@ type [ $ type ] @ max [ $ max ] @ vis [ $ v ] @ debug_format [","highlight_start":1,"highlight_end":65},{"text":"$ debug_format ] derive [ $ ( $ derives , ) * ] $ ( $ tokens ) * ) ; ) ; (","highlight_start":1,"highlight_end":75},{"text":"@ type [ $ type : ident ] @ max [ $ max : expr ] @ vis [ $ v : vis ] @","highlight_start":1,"highlight_end":71},{"text":"debug_format [ $ debug_format : tt ] derive [ $ ( $ derives : ident , ) + ]","highlight_start":1,"highlight_end":76},{"text":"ENCODABLE = custom $ ( $ tokens : tt ) * ) => (","highlight_start":1,"highlight_end":48},{"text":"newtype_index ! (","highlight_start":1,"highlight_end":18},{"text":"@ derives [ $ ( $ derives , ) + ] @ type [ $ type ] @ max [ $ max ] @) ; ) ; (","highlight_start":1,"highlight_end":46},{"text":"@ type [ $ type : ident ] @ max [ $ max : expr ] @ vis [ $ v : vis ] @","highlight_start":1,"highlight_end":71},{"text":"debug_format [ $ debug_format : tt ] $ ( $ tokens : tt ) * ) => (","highlight_start":1,"highlight_end":66},{"text":"newtype_index ! (","highlight_start":1,"highlight_end":18},{"text":"@ derives [ RustcEncodable , ] @ type [ $ type ] @ max [ $ max ] @ vis [ $ v ]","highlight_start":1,"highlight_end":79},{"text":"@ debug_format [ $ debug_format ] $ ( $ tokens ) * ) ; impl Decodable for $","highlight_start":1,"highlight_end":76},{"text":"type {","highlight_start":1,"highlight_end":7},{"text":"fn decode < D : Decoder > ( d : & mut D ) -> Result < Self , D :: Error > {","highlight_start":1,"highlight_end":76},{"text":"d . read_u32 (  ) . map ( Self :: from ) } } ) ; (","highlight_start":1,"highlight_end":51},{"text":"@ derives [ $ ( $ derives : ident , ) * ] @ type [ $ type : ident ] @ max [","highlight_start":1,"highlight_end":76},{"text":"$ max : expr ] @ vis [ $ v : vis ] @ debug_format [ $ debug_format : tt ] $","highlight_start":1,"highlight_end":76},{"text":"name : ident = $ constant : expr ) => (","highlight_start":1,"highlight_end":40},{"text":"newtype_index ! (","highlight_start":1,"highlight_end":18},{"text":"@ derives [ $ ( $ derives , ) * ] @ type [ $ type ] @ max [ $ max ] @ vis [","highlight_start":1,"highlight_end":76},{"text":"$ v ] @ debug_format [ $ debug_format ] $ name = $ constant , ) ; ) ; (","highlight_start":1,"highlight_end":72},{"text":"@ derives [ $ ( $ derives : ident , ) * ] @ type [ $ type : ident ] @ max [","highlight_startt ) * ) => (","highlight_start":1,"highlight_end":66},{"text":"newtype_index ! (","highlight_start":1,"highlight_end":18},{"text":"@ derives [ $ ( $ derives , ) * ] @ type [ $ type ] @ max [ $ max ] @ vis [","highlight_start":1,"highlight_end":76},{"text":"$ v ] @ debug_format [ $ debug_format ] $ ( $ tokens ) * ) ; ) ; (","highlight_start":1,"highlight_end":67},{"text":"@ derives [ $ ( $ derives : ident , ) * ] @ type [ $ type : ident ] @ max [","highlight_start":1,"highlight_end":76},{"text":"$ max : expr ] @ vis [ $ v : vis ] @ debug_format [ $ debug_format : tt ] $ (","highlight_start":1,"highlight_end":78},{"text":"# [ doc = $ doc : expr ] ) * const $ name : ident = $ constant : expr , $ (","highlight_start":1,"highlight_end":76},{"text":"$ tokens : tt ) * ) => (","highlight_start":1,"highlight_end":25},{"text":"$ ( # [ doc = $ doc ] ) * pub const $ name : $ type = $ type :: from_u32_const","highlight_start":1,"highlight_end":79},{"text":"( $ constant ) ; newtype_index ! (","highlight_start":1,"highlight_end":35},{"text":"@ derives [ $ ( $ derives , ) * ] @ type [ $ type ] @ max [ $ max ] @ vis [","highlight_start":1,"highlight_end":76},{"text":"$ v ] @ debug_format [ $ debug_format ] $ ( $ tokens ) * ) ; ) ;","highlight_start":1,"highlight_end":65}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}},"macro_decl_name":"newtype_index!","def_site_span":{"file_name":"<::rustc_data_structures::indexed_vec::newtype_index macros>","byte_start":0,"byte_end":8246,"line_start":1,"line_end":146,"column_start":1,"column_end":65,"is_primary":false,"text":[{"text":"( $ v : vis struct $ name@ max [","highlight_start":1,"highlight_end":77},{"text":"$ max ] @ vis [ $ v ] @ debug_format [ $ debug_format ] $ ( $ tokens ) * ) ;","highlight_start":1,"highlight_end":77},{"text":"impl Decodable for $ type {","highlight_start":1,"highlight_end":28},{"text":"fn decode < D : Decoder > ( d : & mut D ) -> Result < Self , D :: Error > {","highlight_start":1,"highlight_end":76},{"text":"d . read_u32 (  ) . into (  ) } } ) ; (","highlight_start":1,"highlight_end":40},{"text":"@ type [ $ type : ident ] @ max [ $ max : expr ] @ vis [ $ v : vis ] @","highlight_start":1,"highlight_end":71},{"text":"debug_format [ $ debug_format : tt ] ENCODABLE = custom $ ( $ tokens : tt ) *","highlight_start":1,"highlight_end":78},{"text":") => (","highlight_start":1,"highlight_end":7},{"text":"newtype_index ! (","highlight_start":1,"highlight_end":18},{"text":"@ derives [  ] @ type [ $ type ] @ max [ $ max ] @ vis [ $ v ] @ debug_format","highlight_start":1,"highlight_end":78},{"text":"[ $ debug_format ] $ ( $ tokens ) * ) ; ) ; (","highlight_start":1,"highlight_end":46},{"text":"@ type [ $ type : ident ] @ max [ $ max : expr ] @ vis [ $ v : vis ] @","highlight_start":1,"highlight_end":71},{"text":"debug_format [ $ debug_format : tt ] $ ( $ tokens : tt ) * ) => (","highlight_start":1,"highlight_end":66},{"text":"newtype_index ! (","highlight_start":1,"highlight_end":18},{"text":"@ derives [ RustcEncodable , ] @ type [ $ type ] @ max [ $ max ] @ vis [ $ v ]","highlight_start":1,"highlight_end":79},{"text":"@ debug_format [ $ debug_format ] $ ( $ tokens ) * ) ; impl Decodable for $","highlight_start":1,"highlight_end":76},{"text":"type {","highlight_start":1,"highlight_end":7},{"text":"fn decode < D : Decoder > ( d : & mut D ) -> Result < Self , D :: Error > {","highlight_start":1,"highlight_end":76},{"text":"d . read_u32 (  ) . map ( Self :: from ) } } ) ; (","highlight_start":1,"highlight_end":51},{"text":"@ derives [ $ ( $ derives : ident , ) * ] @ type [ $ type : ident ] @ max [","highlight_start":1,"highlight_end":76},{"text":"$ max : expr ] @ vis [ $ v : vis ] @ debug_format [ $ debug_format : tt ] $","highlight_start":1,"highlight_end":76},{"text":"name : ident = $ constant : expr ) => (","highlight_start":1,"highlight_end":40},{"text":"newtype_index ! (","highlight_start":1,"highlight_end":18},{"text":"@ derives [ $ ( $ derives , ) * ] @ type [ $ type ] @ max [ $ max ] @ vis [","highlight_start":1,"highlight_end":76},{"text":"$ v ] @ debug_format [ $ debug_format ] $ name = $ constant , ) ; ) ; (","highlight_start":1,"highlight_end":72},{"text":"@ derives [ $ ( $ derives : ident , ) * ] @ type [ $ type : ident ] @ max [","highlight_start":1,"highlight_end":76},{"text":"$ _max : expr ] @ vis [ $ v : vis ] @ debug_format [ $ debug_format : tt ] $ (","highlight_start":1,"highlight_end":79},{"text":"# [ doc = $ doc : expr ] ) * const $ name : ident = $ constant : expr ) => (","highlight_start":1,"highlight_end":77},{"text":"newtype_index ! (","highlight_start":1,"highlight_end":18},{"text":"@ derives [ $ ( $ derives , ) * ] @ type [ $ type ] @ max [ $ max ] @ vis [","highlight_start":1,"highlight_end":76},{"text":"$ v ] @ debug_format [ $ debug_format ] $ ( # [ doc = $ doc ] ) * const $ name","highlight_start":1,"highlight_end":79},{"text":"= $ constant , ) ; ) ; (tside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)\nhelp: possible candidate is found in another module, you can import it into scope\n   |\nLL | use rustc_serialize::Decodable;\n   |\n\n"}
[01:11:10] {"message":"cannot find trait `Decoder` in this scope","code":{"code":"E0405","explanation":"\nThe code refers to a trait that is not in scope.\n\nErroneous code example:\n\n```compile_fail,E0405\nstruct Foo;\n\nimpl SomeTrait for Foo {} // error: trait `SomeTrait` is not in scope\n```\n\nPlease verify that the name of the trait wasn't misspelled and ensure that it\nwas imported. Example:\n\n```\n# #[cfg(for_demonstration_only)]\n// solution 1:\nuse some_file::SomeTrait;\n\n// solution 2:\ntrait SomeTrait {\n    // some functions\n}\n\nstruct Foo;\n\nimpl SomeTrait for Foo { // ok!\n    // implements functions\n}\n```\n"},"level":"error","spans":[{"file_name":"<::rustc_data_structures::indexed_vec::newtype_index macros>","byte_start":6098,"byte_end":6105,"line_start":112,"line_end":112,"column_start":17,"column_end":24,"is_primary":true,"text":[{"text":"fn decode < D : Decoder > ( d : & mut D ) -> Result < Self , D :: Error > {","highlight_start":17,"highlight_end":24}],"label":"not found in this scope","suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"<::rustc_data_structures::indexed_vec::newtype_index macros>","byte_start":219,"byte_end":335,"line_start":5,"line_end":7,"column_start":1,"column_end":21,"is_primary":false,"text":[{"text":"newtype_index ! (","highlight_start":1,"highlight_end":18},{"text":"@ type [ $ name ] @ max [ 0xFFFF_FF00 ] @ vis [ $ v ] @ debug_format [ \"{}\" ]","highlight_start":1,"highlight_end":78},{"text":"$ ( $ tokens ) + ) ; ) ; (","highlight_start":1,"highlight_end":21}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"/checkout/src/test/run-pass-fulldeps/newtype_index.rs","byte_start":179,"byte_end":230,"line_start":8,"line_end":8,"column_start":1,"column_end":52,"is_primary":false,"text":[{"text":"newtype_index!(struct MyIdx { MAX = 0xFFFF_FFFA });","highlight_start":1,"highlight_end":52}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},"macro_decl_name":"newtype_index!","def_site_span":{"file_name":"<::rustc_data_structures::indexed_vec::newtype_index macros>","byte_start":0,"byte_end":8246,"line_start":1,"line_end":146,"column_start":1,"column_end":65,"is_primary":false,"text":[{"text":"( $ v : vis struct $ name : ident { .. } ) => (","highlight_start":1,"highlight_end":48},{"text":"newtype_index ! (","highlight_start":1,"highlight_end":18},{"text":"@ type [ $ name ] @ max [ 0xFFFF_FF00 ] @ vis [ $ v ] @ debug_format [ \"{}\" ]","highlight_start":1,"highlight_end":78},{"text":") ; ) ; ( $ v : vis struct $ name : ident { $ ( $ tokens : tt ) + } ) => (","highlight_start":1,"highlight_end":75},{"text":"newtype_index ! (","highlight_start":1,"highlight_end":18},{"text":"@ type [ $ name ] @ max [ 0xFFFF_FF00 ] @ vis [ $ v ] @ debug_format [ \"{}\" ]","highlight_start":1,"highlight_end":78},{"text":"$ ( $ tokens ) + ) ; ) ; (","highlight_start":1,"highlight_end":27},{"text":"@ derives [ $ ( $ derives : ident , ) * ] @ type [ $ type : ident ] @ max [","highlight_start":1,"highlight_end":76},{"text":"$ max : expr ] @ vis [ $ v : vis ] @ debug_format [ $ debug_format : tt ] ) =>","highlight_start":1,"highlight_end":79},{"text":"(","highlight_start":1,"highlight_end":2},{"text":"# [","highlight_start":1,"highlight_end":4},{"text":"derive ( Copy , PartialEq , Eq , Hash , PartialOrd , Ord , $ ( $ derives ) , *","highlight_start":1,"highlight_end":79},{"text":") ] # [ rustc_layout_scalar_valid_range_end ( $ max ) ] $ v struct $ type {","highlight_start":1,"highlight_end":76},{"text":"private : u32 } impl Clone for $ type { fn clone ( & self ) -> Self { * self }","highlight_start":1,"highlight_end":79},{"text":"} impl $ type {","highlight_start":1,"highlight_end":16},{"text":"$ v const MAX_AS_U32 : u32 = $ max ; $ v const MAX : $ type = $ type ::","highlight_start":1,"highlight_end":72},{"text":"from_u32_const ( $ max ) ; # [ inline ] $ v fn from_usize ( value : usize ) ->","highlight_start":1,"highlight_end":79},{"text":"Self {","highlight_start":1,"highlight_end":7},{"text":"assert ! ( value <= ( $ max as usize ) ) ; unsafe {","highlight_start":1,"highlight_end":52},{"text":"$ type :: from_u32_unchecked ( value as u32 ) } } # [ inline ] $ v fn from_u32","highlight_start":1,"highlight_end":79},{"text":"( value : u32 ) -> Self {","highlight_start":1,"highlight_end":26},{"text":"assert ! ( value <= $ max ) ; unsafe { $ type :: from_u32_unchecked ( value )","highlight_start":1,"highlight_end":78},{"text":"} } /// Hacky variant of `from_u32` for use in constants.","highlight_start":1,"highlight_end":58},{"text":" /// This version checks the \"max\" constraint by using an","highlight_start":1,"highlight_end":58},{"text":" /// invalid array dereference.","highlight_start":1,"highlight_end":32},{"text":" # [ inline ] $ v const fn from_u32_const ( value : u32 ) -> Self {","highlight_start":1,"highlight_end":68},{"text":"let _ = [ \"out of range value used\" ] [ ! ( value <= $ max ) as usize ] ;","highlight_start":1,"highlight_end":74},{"text":"unsafe { $ type { private : value } } } # [ inline ] $ v const unsafe fn","highlight_start":1,"highlight_end":73},{"text":"from_u32_unchecked ( value : u32 ) -> Self {","highlight_start":1,"highlight_end":45},{"text":"unsafe { $ type { private : value } } }","highlight_start":1,"highlight_end":40},{"text":"/// Extract value of this index as an integer.","highlight_start":1,"highlight_end":47},{"text":" # [ inline ] $ v fn index ( self ) -> usize { self . as_usize (  ) }","highlight_start":1,"highlight_end":70},{"text":"/// Extract value of this index as a usize.","highlight_start":1,"highlight_end":44},{"text":" # [ inline ] $ v fn as_u32 ( self ) -> u32 { self . private }","highlight_start":1,"highlight_end":63},{"text":"/// Extract value of this index as a u32.","highlight_start":1,"highlight_end":42},{"text":" # [ inline ] $ v fn as_usize ( self ) -> usize { self . as_u32 (  ) as usize","highlight_start":1,"highlight_end":78},{"text":"} } impl Idx for $ type {","highlight_start":1,"highlight_end":26},{"text":"# [ inline ] fn new ( value : usize ) -> Self { Self :: from ( value ) } # [","highlight_start":1,"highlight_end":77},{"text":"inline ] fn index ( self ) -> usize { usize :: from ( self ) } } impl :: std","highlight_start":1,"highlight_ghlight_start":1,"highlight_end":79},{"text":"type > for usize {","highlight_start":1,"highlight_end":19},{"text":"# [ inline ] fn from ( v : $ type ) -> usize { v . as_usize (  ) } } impl From","highlight_start":1,"highlight_end":79},{"text":"< usize > for $ type {","highlight_start":1,"highlight_end":23},{"text":"# [ inline ] fn from ( value : usize ) -> Self {","highlight_start":1,"highlight_end":49},{"text":"$ type :: from_usize ( value ) } } impl From < u32 > for $ type {","highlight_start":1,"highlight_end":66},{"text":"# [ inline ] fn from ( value : u32 ) -> Self { $ type :: from_u32 ( value ) }","highlight_start":1,"highlight_end":78},{"text":"} newtype_index ! (","highlight_start":1,"highlight_end":20},{"text":"@ handle_debug @ derives [ $ ( $ derives , ) * ] @ type [ $ type ] @","highlight_start":1,"highlight_end":69},{"text":"debug_format [ $ debug_format ] ) ; ) ; (","highlight_start":1,"highlight_end":42},{"text":"@ handle_debug @ derives [ $ ( $ _derives : ident , ) * ] @ type [","highlight_start":1,"highlight_end":67},{"text":"$ type : ident ] @ debug_format [ custom ] ) => (  ) ; (","highlight_start":1,"highlight_end":57},{"text":"@ handle_debug @ derives [  ] @ type [ $ type : ident ] @ debug_format [","highlight_start":1,"highlight_end":73},{"text":"$ debug_format : tt ] ) => (","highlight_start":1,"highlight_end":29},{"text":"impl :: std :: fmt :: Debug for $ type {","highlight_start":1,"highlight_end":41},{"text":"fn fmt ( & self , fmt : & mut :: std :: fmt :: Formatter ) -> :: std :: fmt ::","highlight_start":1,"highlight_end":79},{"text":"Result { write ! ( fmt , $ debug_format , self . as_u32 (  ) ) } } ) + ]","highlight_start":1,"highlight_end":76},{"text":"ENCODABLE = custom $ ( $ tokens : tt ) * ) => (","highlight_start":1,"highlight_end":48},{"text":"newtype_index ! (","highlight_start":1,"highlight_end":18},{"text":"@ derives [ $ ( $ derives , ) + ] @ type [ $ type ] @ max [ $ max ] @ vis [","highlight_start":1,"highlight_end":76},{"text":"$ v ] @ debug_format [ $ debug_format ] $ ( $ tokens ) * ) ; ) ; (","highlight_start":1,"highlight_end":67},{"text":"@ type [ $ type : ident ] @ max [ $ max : expr ] @ vis [ $ v : vis ] @","highlight_start":1,"highlight_end":71},{"text":"debug_format [ $ debug_format : tt ] derive [ $ ( $ derives : ident , ) + ] $","highlight_start":1,"highlight_end":78},{"text":"( $ tokens : tt ) * ) => (","highlight_start":1,"highlight_end":27},{"text":"newtype_index ! (","highlight_start":1,"highlight_end":18},{"text":"@ derives [ $ ( $ derives , ) + RustcEncodable , ] @ type [ $ type ] @ max [","highlight_start":1,"highlight_end":77},{"text":"$ max ] @ vis [ $ v ] @ debug_format [ $ debug_format ] $ ( $ tokens ) * ) ;","highlight_start":1,"highlight_end":77},{"text":"impl Decodable for $ type {","highlight_start":1,"highlight_end":28},{"text":"fn decode < D : Decoder > ( d : & mut D ) -> Result < Self , D :: Error > {","highlight_start":1,"highlight_end":76},{"text":"d . read_u32 (  ) . into (  ) } } ) ; (","highlight_start":1,"highlight_end":40},{"text":"@ type [ $ type : ident ] @ max [ $ max : expr ] @ vis [ $ v : vis ] @","highlight_start":1,"highlight_end":71},{"text":"debug_format [ $ debug_format : tt ] ENCODABLE = custom $ ( $ tokens : tt ) *","highlight_start":1,"highlight_end":78},{"tex18},{"text":"@ derives [ $ ( $ derives , ) * ] @ type [ $ type ] @ max [ $ max ] @ vis [","highlight_start":1,"highlight_end":76},{"text":"$ v ] @ debug_format [ $ debug_format ] $ ( # [ doc = $ doc ] ) * const $ name","highlight_start":1,"highlight_end":79},{"text":"= $ constant , ) ; ) ; (","highlight_start":1,"highlight_end":25},{"text":"@ derives [ $ ( $ derives : ident , ) * ] @ type [ $ type : ident ] @ max [","highlight_start":1,"highlight_end":76},{"text":"$ _max : expr ] @ vis [ $ v : vis ] @ debug_format [ $ debug_format : tt ] MAX","highlight_start":1,"highlight_end":79},{"text":"= $ max : expr , $ ( $ tokens : tt ) * ) => (","highlight_start":1,"highlight_end":46},{"text":"newtype_index ! (","highlight_start":1,"highlight_end":18},{"text":"@ derives [ $ ( $ derives , ) * ] @ type [ $ type ] @ max [ $ max ] @ vis [","highlight_start":1,"highlight_end":76},{"text":"$ v ] @ debug_format [ $ debug_format ] $ ( $ tokens ) * ) ; ) ; (","highlight_start":1,"highlight_end":67},{"text":"@ derives [ $ ( $ derives : ident , ) * ] @ type [ $ type : ident ] @ max [","highlight_start":1,"highlight_end":76},{"text":"$ max : expr ] @ vis [ $ v : vis ] @ debug_format [ $ _debug_format : tt ]","highlight_start":1,"highlight_end":75},{"text":"DEBUG_FORMAT = $ debug_format : tt , $ ( $ tokens : tt ) * ) => (","highlight_start":1,"highlight_end":66},{"text":"newtype_index ! (","highlight_start":1,"highlight_end":18},{"text":"@ derives [ $ ( $ derives , ) * ] @ type [ $ type ] @ max [ $ max ] @ vis [","highlight_start":1,"highlight_end":76},{"text":"$ v ] @ debug_format [ $ debug_format ] $ ( $ tokens ) * ) ; ) ; (","highlight_start":1`Decoder` in this scope\n  --> /checkout/src/test/run-pass-fulldeps/newtype_index.rs:8:1\n   |\nLL | newtype_index!(struct MyIdx { MAX = 0xFFFF_FFFA });\n   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope\n   |\n   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)\nhelp: possible candidate is found in another module, you can import it into scope\n   |\nLL | use rustc_serialize::Decoder;\n   |\n\n"}
[01:11:10] {"message":"aborting due to 2 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to 2 previous errors\n\n"}
[01:11:10] {"message":"For more information about this error, try `rustc --explain E0405`.","code":null,"level":"","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0405`.\n"}
[01:11:10] ------------------------------------------
[01:11:10] 
[01:11:10] thread '[run-pass] run-pass-fulldeps/newtype_index.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:3284:9
[01:11:10] note: Run with `RUST_BACKTRACE=1` for a backtrace.
---
[01:11:10] test result: FAILED. 96 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
[01:11:10] 
[01:11:10] 
[01:11:10] 
[01:11:10] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/run-pass-fulldeps" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass-fulldeps" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "run-pass" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-5.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options " "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "5.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[01:11:10] 
[01:11:10] 
[01:11:10] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:11:10] Build completed unsuccessfully in 0:24:46
[01:11:10] Build completed unsuccessfully in 0:24:46
[01:11:10] make: *** [check] Error 1
[01:11:10] Makefile:58: recipe for target 'check' failed

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:14156274
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@rust-lang rust-lang deleted a comment from rust-highfive Nov 4, 2018

@rust-lang rust-lang deleted a comment from rust-highfive Nov 4, 2018

@oli-obk oli-obk force-pushed the oli-obk:min_const_unsafe_fn branch from 411ceea to 3844277 Nov 4, 2018

#[repr(transparent)]
pub(crate) struct NonZero<T>(pub(crate) T);
pub(crate) struct NonZero<T: Freeze>(pub(crate) T);

This comment has been minimized.

@eddyb

eddyb Nov 4, 2018

Member

Glad this is not exported anymore!

@oli-obk oli-obk force-pushed the oli-obk:min_const_unsafe_fn branch from 5102c82 to 9604080 Nov 5, 2018

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 4, 2018

⌛️ Testing commit cb71752 with merge 2ba23a2...

bors added a commit that referenced this pull request Dec 4, 2018

Auto merge of #55635 - oli-obk:min_const_unsafe_fn, r=nikomatsakis
Allow calling `const unsafe fn` in `const fn` behind a feature gate

cc #55607

r? @Centril
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 4, 2018

💔 Test failed - status-travis

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Dec 4, 2018

The job x86_64-gnu-tools of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:02:24]    Compiling rustc_tsan v0.0.0 (/checkout/src/librustc_tsan)
[00:02:24]    Compiling rustc_lsan v0.0.0 (/checkout/src/librustc_lsan)
[00:02:25]    Compiling rustc_asan v0.0.0 (/checkout/src/librustc_asan)
[00:02:25]    Compiling rustc_msan v0.0.0 (/checkout/src/librustc_msan)
[00:02:34] warning: unnecessary `unsafe` block
[00:02:34]     |
[00:02:34]     |
[00:02:34] 73  |                       $Ty(unsafe { NonZero(n) })
[00:02:34]     |                           ^^^^^^ unnecessary `unsafe` block
[00:02:34] ...
[00:02:34] 110 | / nonzero_integers! {
[00:02:34] 111 | |     NonZeroU8(u8);
[00:02:34] 112 | |     NonZeroU16(u16);
[00:02:34] 113 | |     NonZeroU32(u32);
[00:02:34] 116 | |     NonZeroUsize(usize);
[00:02:34] 117 | | }
[00:02:34]     | |_- in this macro invocation
[00:02:34]     |
[00:02:34]     |
[00:02:34]     = note: #[warn(unused_unsafe)] on by default
[00:02:34] 
[00:02:34] warning: unnecessary `unsafe` block
[00:02:34]     |
[00:02:34]     |
[00:02:34] 73  |                       $Ty(unsafe { NonZero(n) })
[00:02:34]     |                           ^^^^^^ unnecessary `unsafe` block
[00:02:34] ...
[00:02:34] 110 | / nonzero_integers! {
[00:02:34] 111 | |     NonZeroU8(u8);
[00:02:34] 112 | |     NonZeroU16(u16);
[00:02:34] 113 | |     NonZeroU32(u32);
[00:02:34] 116 | |     NonZeroUsize(usize);
[00:02:34] 117 | | }
[00:02:34]     | |_- in this macro invocation
[00:02:34] 
[00:02:34] 
[00:02:34] warning: unnecessary `unsafe` block
[00:02:34]     |
[00:02:34]     |
[00:02:34] 81  |                           Some($Ty(unsafe { NonZero(n) }))
[00:02:34]     |                                    ^^^^^^ unnecessary `unsafe` block
[00:02:34] ...
[00:02:34] 110 | / nonzero_integers! {
[00:02:34] 111 | |     NonZeroU8(u8);
[00:02:34] 112 | |     NonZeroU16(u16);
[00:02:34] 113 | |     NonZeroU32(u32);
[00:02:34] 116 | |     NonZeroUsize(usize);
[00:02:34] 117 | | }
[00:02:34]     | |_- in this macro invocation
[00:02:34] 
[00:02:34] 
[00:02:34] warning: unnecessary `unsafe` block
[00:02:34]     --> src/libcore/ptr.rs:2762:36
[00:02:34]      |
[00:02:34] 2762 |             Some(Unique { pointer: unsafe { NonZero(ptr as _) }, _marker: PhantomData })
[00:02:34]      |                                    ^^^^^^ unnecessary `unsafe` block
[00:02:34] 
[00:02:34] warning: unnecessary `unsafe` block
[00:02:34]     --> src/libcore/ptr.rs:2818:27
[00:02:34]      |
[00:02:34] 2818 |         Unique { pointer: unsafe { NonZero(reference as _) }, _marker: PhantomData }
[00:02:34]      |                           ^^^^^^ unnecessary `unsafe` block
[00:02:34] 
[00:02:34] warning: unnecessary `unsafe` block
[00:02:34]     --> src/libcore/ptr.rs:2825:27
[00:02:34]      |
[00:02:34] 2825 |         Unique { pointer: unsafe { NonZero(reference as _) }, _marker: PhantomData }
[00:02:34]      |                           ^^^^^^ unnecessary `unsafe` block
[00:02:34] 
[00:02:34] warning: unnecessary `unsafe` block
[00:02:34]     --> src/libcore/ptr.rs:2898:28
[00:02:34]      |
[00:02:34] 2898 |         NonNull { pointer: unsafe { NonZero(ptr as _) } }
[00:02:34]      |                            ^^^^^^ unnecessary `unsafe` block
[00:02:34] 
[00:02:34] warning: unnecessary `unsafe` block
[00:02:34]     --> src/libcore/ptr.rs:3028:28
[00:02:34]      |
[00:02:34] 3028 |         NonNull { pointer: unsafe { NonZero(reference as _) } }
[00:02:34]      |                            ^^^^^^ unnecessary `unsafe` block
[00:02:34] 
[00:02:34] warning: unnecessary `unsafe` block
[00:02:34]     --> src/libcore/ptr.rs:3036:28
[00:02:34]      |
[00:02:34] 3036 |         NonNull { pointer: unsafe { NonZero(reference as _) } }
[00:02:34]      |                            ^^^^^^ unnecessary `unsafe` block
[00:02:34] 
[00:02:34] warning: unnecessary `unsafe` block
[00:02:34]    |
[00:02:34]    |
[00:02:34] 27 |         unsafe { NonZero(self.0) }
[00:02:34]    |         ^^^^^^ unnecessary `unsafe` block
[00:02:39] [RUSTC-TIMING] core test:false 24.101
[00:02:41] [RUSTC-TIMING] compiler_builtins test:false 1.844
[00:02:41]    Compiling libc v0.0.0 (/checkout/src/rustc/libc_shim)
[00:02:41]    Compiling alloc v0.0.0 (/checkout/src/liballoc)
---
[01:09:42] [RUSTC-TIMING] arena test:false 0.926
[01:09:42]    Compiling rustc-ap-syntax_pos v297.0.0
[01:09:44] [RUSTC-TIMING] git2_curl test:false 2.904
[01:09:44]    Compiling cargo v0.33.0 (/checkout/src/tools/cargo)
[01:09:45] error[E0133]: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block
[01:09:45]    --> /cargo/registry/src/github.com-1ecc6299db9ec823/rustc-ap-rustc_target-297.0.0/abi/mod.rs:830:1
[01:09:45]     |
[01:09:45] 830 | / newtype_index! {
[01:09:45] 831 | |     pub struct VariantIdx { .. }
[01:09:45] 832 | | }
[01:09:45]     | |_^ initializing type with `rustc_layout_scalar_valid_range` attr
[01:09:45]     |
[01:09:45]     = note: initializing a layout restricted type's field with a value outside the valid range is undefined behavior
[01:09:45] 
[01:09:45] 
[01:09:45] error[E0133]: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block
[01:09:45]    --> /cargo/registry/src/github.com-1ecc6299db9ec823/rustc-ap-rustc_target-297.0.0/abi/mod.rs:830:1
[01:09:45]     |
[01:09:45] 830 | / newtype_index! {
[01:09:45] 831 | |     pub struct VariantIdx { .. }
[01:09:45] 832 | | }
[01:09:45]     | |_^ initializing type with `rustc_layout_scalar_valid_range` attr
[01:09:45]     |
[01:09:45]     = note: initializing a layout restricted type's field with a value outside the valid range is undefined behavior
[01:09:45] 
[01:09:45] error: aborting due to 2 previous errors
[01:09:45] 
[01:09:45] For more information about this error, try `rustc --explain E0133`.
---
[01:12:59]    Compiling rustc-ap-arena v297.0.0
[01:12:59]    Compiling rustc-ap-rustc_target v297.0.0
[01:12:59] [RUSTC-TIMING] arena test:false 0.528
[01:12:59]    Compiling rustc-ap-syntax_pos v297.0.0
[01:13:02] error[E0133]: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block
[01:13:02]    --> /cargo/registry/src/github.com-1ecc6299db9ec823/rustc-ap-rustc_target-297.0.0/abi/mod.rs:830:1
[01:13:02]     |
[01:13:02] 830 | / newtype_index! {
[01:13:02] 831 | |     pub struct VariantIdx { .. }
[01:13:02] 832 | | }
[01:13:02]     | |_^ initializing type with `rustc_layout_scalar_valid_range` attr
[01:13:02]     |
[01:13:02]     = note: initializing a layout restricted type's field with a value outside the valid range is undefined behavior
[01:13:02] 
[01:13:02] 
[01:13:02] error[E0133]: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block
[01:13:02]    --> /cargo/registry/src/github.com-1ecc6299db9ec823/rustc-ap-rustc_target-297.0.0/abi/mod.rs:830:1
[01:13:02]     |
[01:13:02] 830 | / newtype_index! {
[01:13:02] 831 | |     pub struct VariantIdx { .. }
[01:13:02] 832 | | }
[01:13:02]     | |_^ initializing type with `rustc_layout_scalar_valid_range` attr
[01:13:02]     |
[01:13:02]     = note: initializing a layout restricted type's field with a value outside the valid range is undefined behavior
[01:13:02] 
[01:13:02] error: aborting due to 2 previous errors
[01:13:02] 
[01:13:02] For more information about this error, try `rustc --explain E0133`.
---
[01:16:14] failures:
[01:16:14] 
[01:16:14] ---- [compile-fail] compile-fail/validity/nonzero.rs stdout ----
[01:16:14] 
[01:16:14] error: tests/compile-fail/validity/nonzero.rs:10: unexpected error: '10:19: 10:29: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block [E0133]'
[01:16:14] 
[01:16:14] error: tests/compile-fail/validity/nonzero.rs:10: expected error not found: encountered 0, but expected something greater or equal to 1
[01:16:14] error: 1 unexpected errors found, 1 expected errors not found
[01:16:14] status: exit code: 1
[01:16:14] status: exit code: 1
[01:16:14] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools-bin/miri" "tests/compile-fail/validity/nonzero.rs" "-L" "/tmp/compiletestvu0kh1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-C" "prefer-dynamic" "-o" "/tmp/compiletestvu0kh1/validity/nonzero.stage-id" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "-Dwarnings" "-Dunused" "--edition" "2018" "-L" "/tmp/compiletestvu0kh1/validity/nonzero.stage-id.aux" "-A" "unused"
[01:16:14] unexpected errors (from JSON output): [
[01:16:14]     Error {
[01:16:14]         line_num: 10,
[01:16:14]         kind: Some(
[01:16:14]         kind: Some(
[01:16:14]             Error
[01:16:14]         ),
[01:16:14]         msg: "10:19: 10:29: initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block [E0133]"
[01:16:14] ]
[01:16:14] 
[01:16:14] not found errors (from test file): [
[01:16:14]     Error {
[01:16:14]     Error {
[01:16:14]         line_num: 10,
[01:16:14]         kind: Some(
[01:16:14]             Error
[01:16:14]         ),
[01:16:14]         msg: "encountered 0, but expected something greater or equal to 1"
[01:16:14] ]
[01:16:14] 
[01:16:14] thread '[compile-fail] compile-fail/validity/nonzero.rs' panicked at 'explicit panic', /cargo/registry/src/github.com-1ecc6299db9ec823/compiletest_rs-0.3.17/src/runtest.rs:1098:13
[01:16:14] note: Run with `RUST_BACKTRACE=1` for a backtrace.
---
travis_time:end:094631be:start=1543937712944865554,finish=1543937712951008419,duration=6142865
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:00efd01b
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:00a40e95
travis_time:start:00a40e95
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:075b2172
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@oli-obk

This comment has been minimized.

Copy link
Contributor

oli-obk commented Dec 4, 2018

Uh... @alexcrichton @nrc what is the correct procedure for landing something that breaks a rustc-ap-* crate needed for cargo?

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Dec 4, 2018

@oli-obk in theory there's no procedure as we just publish a new version of rustc-ap-syntax every night, whatever the nightly happened to be released with. I've just fixed a bug where it stopped running for a week or so, so maybe that's all that was needed?

Does that help? I fear I may be missing context about what's actually needed here

@oli-obk

This comment has been minimized.

Copy link
Contributor

oli-obk commented Dec 4, 2018

I made a breaking change to librustc_data_structures, which in turn broke rustc-ap-syntax_pos.

From your statement it sounds like that's normally fine, so it might be that that in turn would have broken rls, and since we're in publishing week, we can't break tools.

I am currently investigating if I can work around it by a targeted application of #[allow_internal_unstable].

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Dec 4, 2018

Hm that's odd because that breakage should be impossible, the rustc-ap-syntax_pos crate depend on rustc-ap-rustc_data_structures, not the in-tree copy. Is the breakage in the logs above or elsewhere?

@oli-obk

This comment has been minimized.

Copy link
Contributor

oli-obk commented Dec 4, 2018

Is the breakage in the logs above or elsewhere?

It's in the logs above.... But I think I know the issue: I changed language semantics for the forever-unstable feature rustc_layout_scalar_valid_range attributes. Using them requires unsafe now.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Dec 4, 2018

Ah yes indeed! If that breaks crates on crates.io that's fine, it just means that until the release happens (where we require the RLS compiles) this won't be able to land. After the release though this can land, it'll break the RLS, and then the RLS will update to a newer version of the crate on crates.io as it's naturally published.

@kennytm

This comment has been minimized.

Copy link
Member

kennytm commented Dec 6, 2018

@bors retry

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 6, 2018

⌛️ Testing commit cb71752 with merge 128a1fa...

bors added a commit that referenced this pull request Dec 6, 2018

Auto merge of #55635 - oli-obk:min_const_unsafe_fn, r=nikomatsakis
Allow calling `const unsafe fn` in `const fn` behind a feature gate

cc #55607

r? @Centril
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 6, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing 128a1fa to master...

@bors bors merged commit cb71752 into rust-lang:master Dec 6, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Dec 6, 2018

📣 Toolstate changed by #55635!

Tested on commit 128a1fa.
Direct link to PR: #55635

💔 miri on windows: test-pass → test-fail (cc @oli-obk @RalfJung @eddyb, @rust-lang/infra).
💔 miri on linux: test-pass → test-fail (cc @oli-obk @RalfJung @eddyb, @rust-lang/infra).
💔 rls on windows: test-pass → build-fail (cc @nrc @Xanewok, @rust-lang/infra).
💔 rls on linux: test-pass → build-fail (cc @nrc @Xanewok, @rust-lang/infra).
💔 rustfmt on windows: test-pass → build-fail (cc @nrc, @rust-lang/infra).
💔 rustfmt on linux: test-pass → build-fail (cc @nrc, @rust-lang/infra).

rust-highfive added a commit to rust-lang-nursery/rust-toolstate that referenced this pull request Dec 6, 2018

📣 Toolstate changed by rust-lang/rust#55635!
Tested on commit rust-lang/rust@128a1fa.
Direct link to PR: <rust-lang/rust#55635>

💔 miri on windows: test-pass → test-fail (cc @oli-obk @RalfJung @eddyb, @rust-lang/infra).
💔 miri on linux: test-pass → test-fail (cc @oli-obk @RalfJung @eddyb, @rust-lang/infra).
💔 rls on windows: test-pass → build-fail (cc @nrc @Xanewok, @rust-lang/infra).
💔 rls on linux: test-pass → build-fail (cc @nrc @Xanewok, @rust-lang/infra).
💔 rustfmt on windows: test-pass → build-fail (cc @nrc, @rust-lang/infra).
💔 rustfmt on linux: test-pass → build-fail (cc @nrc, @rust-lang/infra).

@oli-obk oli-obk deleted the oli-obk:min_const_unsafe_fn branch Dec 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment