From a1a0aea9e3830f4351f45f3a56c1adbca49be481 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 15 Jan 2020 13:36:54 +0100 Subject: [PATCH 1/6] clean up E0195 explanation --- src/librustc_error_codes/error_codes/E0195.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0195.md b/src/librustc_error_codes/error_codes/E0195.md index 3606521020a11..b8c313d412eba 100644 --- a/src/librustc_error_codes/error_codes/E0195.md +++ b/src/librustc_error_codes/error_codes/E0195.md @@ -1,4 +1,5 @@ -Your method's lifetime parameters do not match the trait declaration. +The lifetime parameters of the method do not match the trait declaration. + Erroneous code example: ```compile_fail,E0195 @@ -16,7 +17,7 @@ impl Trait for Foo { } ``` -The lifetime constraint `'b` for bar() implementation does not match the +The lifetime constraint `'b` for `bar()` implementation does not match the trait declaration. Ensure lifetime declarations match exactly in both trait declaration and implementation. Example: From 6f1bdb47f2a3bb24f60f8f27683991ddd2058b03 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 15 Jan 2020 13:37:01 +0100 Subject: [PATCH 2/6] clean up E0197 explanation --- src/librustc_error_codes/error_codes/E0197.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0197.md b/src/librustc_error_codes/error_codes/E0197.md index 0d91157e572cc..c142b8f3664c5 100644 --- a/src/librustc_error_codes/error_codes/E0197.md +++ b/src/librustc_error_codes/error_codes/E0197.md @@ -1,13 +1,20 @@ +An inherent implementation was marked unsafe. + +Erroneous code example: + +```compile_fail,E0197 +struct Foo; + +unsafe impl Foo { } // error! +``` + Inherent implementations (one that do not implement a trait but provide methods associated with a type) are always safe because they are not implementing an unsafe trait. Removing the `unsafe` keyword from the inherent implementation will resolve this error. -```compile_fail,E0197 +``` struct Foo; -// this will cause this error -unsafe impl Foo { } -// converting it to this will fix it -impl Foo { } +impl Foo { } // ok! ``` From a70b24018936fe59f0a037adfa13f2255d8aa5d2 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Sat, 18 Jan 2020 18:35:36 +0100 Subject: [PATCH 3/6] Make iter::Empty implement Send and Sync for any T --- src/libcore/iter/sources.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libcore/iter/sources.rs b/src/libcore/iter/sources.rs index a65d47cc2c1f0..25dfc573e416a 100644 --- a/src/libcore/iter/sources.rs +++ b/src/libcore/iter/sources.rs @@ -208,6 +208,11 @@ pub fn repeat_with A>(repeater: F) -> RepeatWith { #[stable(feature = "iter_empty", since = "1.2.0")] pub struct Empty(marker::PhantomData); +#[stable(feature = "iter_empty_send_sync", since = "1.42.0")] +unsafe impl Send for Empty {} +#[stable(feature = "iter_empty_send_sync", since = "1.42.0")] +unsafe impl Sync for Empty {} + #[stable(feature = "core_impl_debug", since = "1.9.0")] impl fmt::Debug for Empty { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { From d7a18f89864a4360230e3cbbdcbf22d9864a86e0 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Thu, 17 Jan 2019 00:07:22 +0100 Subject: [PATCH 4/6] Add a test for iter::empty::<*mut i32> being Sync and Send --- src/test/ui/threads-sendsync/sync-send-iterators-in-libcore.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/ui/threads-sendsync/sync-send-iterators-in-libcore.rs b/src/test/ui/threads-sendsync/sync-send-iterators-in-libcore.rs index 44beb9dc1e534..2f6d35f01be62 100644 --- a/src/test/ui/threads-sendsync/sync-send-iterators-in-libcore.rs +++ b/src/test/ui/threads-sendsync/sync-send-iterators-in-libcore.rs @@ -88,6 +88,7 @@ fn main() { is_sync_send!((1..)); is_sync_send!(repeat(1)); is_sync_send!(empty::()); + is_sync_send!(empty::<*mut i32>()); is_sync_send!(once(1)); // for option.rs From e1f70f77bf7aae099453d54a1175d8453ce4f5cb Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Sat, 18 Jan 2020 18:44:05 -0500 Subject: [PATCH 5/6] [const-prop] Remove useless typedef It's confusing because it conflicts with ty::Const and just isn't generally useful. --- src/librustc_mir/transform/const_prop.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 3afc7290ca9c8..2fd59f3ee1944 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -288,8 +288,6 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine { } } -type Const<'tcx> = OpTy<'tcx>; - /// Finds optimization opportunities on the MIR. struct ConstPropagator<'mir, 'tcx> { ecx: InterpCx<'mir, 'tcx, ConstPropMachine>, @@ -387,7 +385,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { } } - fn get_const(&self, local: Local) -> Option> { + fn get_const(&self, local: Local) -> Option> { if local == RETURN_PLACE { // Try to read the return place as an immediate so that if it is representable as a // scalar, we can handle it as such, but otherwise, just return the value as is. @@ -470,7 +468,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { &mut self, c: &Constant<'tcx>, source_info: SourceInfo, - ) -> Option> { + ) -> Option> { self.ecx.tcx.span = c.span; // FIXME we need to revisit this for #67176 @@ -510,12 +508,12 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { } } - fn eval_place(&mut self, place: &Place<'tcx>, source_info: SourceInfo) -> Option> { + fn eval_place(&mut self, place: &Place<'tcx>, source_info: SourceInfo) -> Option> { trace!("eval_place(place={:?})", place); self.use_ecx(source_info, |this| this.ecx.eval_place_to_op(place, None)) } - fn eval_operand(&mut self, op: &Operand<'tcx>, source_info: SourceInfo) -> Option> { + fn eval_operand(&mut self, op: &Operand<'tcx>, source_info: SourceInfo) -> Option> { match *op { Operand::Constant(ref c) => self.eval_constant(c, source_info), Operand::Move(ref place) | Operand::Copy(ref place) => { @@ -664,7 +662,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { fn replace_with_const( &mut self, rval: &mut Rvalue<'tcx>, - value: Const<'tcx>, + value: OpTy<'tcx>, source_info: SourceInfo, ) { trace!("attepting to replace {:?} with {:?}", rval, value); From a957f0d7ff2c6389ec94f921d9ba4e9fade26a72 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Sat, 18 Jan 2020 18:44:22 -0500 Subject: [PATCH 6/6] [const-prop] Run `x.py fmt` --- src/librustc_mir/transform/const_prop.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 2fd59f3ee1944..bd398c6e5b449 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -464,11 +464,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { r } - fn eval_constant( - &mut self, - c: &Constant<'tcx>, - source_info: SourceInfo, - ) -> Option> { + fn eval_constant(&mut self, c: &Constant<'tcx>, source_info: SourceInfo) -> Option> { self.ecx.tcx.span = c.span; // FIXME we need to revisit this for #67176