From 65e366064f222502c96d0d39102ea6cea9d4bafa Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Mon, 23 Dec 2019 11:56:08 -0500 Subject: [PATCH 01/19] docs: Iterator adapters have unspecified results after a panic --- src/libcore/iter/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs index 80294de714d25..0d5af3986fbff 100644 --- a/src/libcore/iter/mod.rs +++ b/src/libcore/iter/mod.rs @@ -216,6 +216,11 @@ //! Common iterator adapters include [`map`], [`take`], and [`filter`]. //! For more, see their documentation. //! +//! If an iterator adapter panics, the iterator will be in an unspecified (but +//! memory safe) state. This state is also not guaranteed to stay the same +//! across versions of Rust, so you should avoid relying on the exact values +//! returned by an iterator which panicked. +//! //! [`map`]: trait.Iterator.html#method.map //! [`take`]: trait.Iterator.html#method.take //! [`filter`]: trait.Iterator.html#method.filter From f6faf0b2e725b2ba638acc61501df2b88597b271 Mon Sep 17 00:00:00 2001 From: jumbatm <30644300+jumbatm@users.noreply.github.com> Date: Fri, 27 Dec 2019 11:59:55 +1000 Subject: [PATCH 02/19] Clean up const-hack from #63810 --- src/libcore/lib.rs | 2 ++ src/libcore/ptr/const_ptr.rs | 5 +---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 7d11dd2800fd4..590f4e46c1d2f 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -71,6 +71,8 @@ #![feature(cfg_target_has_atomic)] #![feature(concat_idents)] #![feature(const_fn)] +#![feature(const_if_match)] +#![feature(const_panic)] #![feature(const_fn_union)] #![feature(const_generics)] #![feature(const_ptr_offset_from)] diff --git a/src/libcore/ptr/const_ptr.rs b/src/libcore/ptr/const_ptr.rs index e5297a0c1e094..fc3c02e1f066d 100644 --- a/src/libcore/ptr/const_ptr.rs +++ b/src/libcore/ptr/const_ptr.rs @@ -288,10 +288,7 @@ impl *const T { T: Sized, { let pointee_size = mem::size_of::(); - let ok = 0 < pointee_size && pointee_size <= isize::max_value() as usize; - // assert that the pointee size is valid in a const eval compatible way - // FIXME: do this with a real assert at some point - [()][(!ok) as usize]; + assert!(0 < pointee_size && pointee_size <= isize::max_value() as usize); intrinsics::ptr_offset_from(self, origin) } From 8c494866bebd24e71bff64063f24a5c0dc8db851 Mon Sep 17 00:00:00 2001 From: jumbatm Date: Fri, 27 Dec 2019 20:09:07 +1000 Subject: [PATCH 03/19] Clean up const-hack from #63786 --- src/libcore/num/mod.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 8a32479b2ff7d..39e2c7ca60cbf 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -1416,18 +1416,14 @@ $EndFeature, " ```"), #[stable(feature = "no_panic_abs", since = "1.13.0")] #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] + #[allow_internal_unstable(const_if_match)] #[inline] pub const fn wrapping_abs(self) -> Self { - // sign is -1 (all ones) for negative numbers, 0 otherwise. - let sign = self >> ($BITS - 1); - // For positive self, sign == 0 so the expression is simply - // (self ^ 0).wrapping_sub(0) == self == abs(self). - // - // For negative self, self ^ sign == self ^ all_ones. - // But all_ones ^ self == all_ones - self == -1 - self. - // So for negative numbers, (self ^ sign).wrapping_sub(sign) is - // (-1 - self).wrapping_sub(-1) == -self == abs(self). - (self ^ sign).wrapping_sub(sign) + if self.is_negative() { + self.wrapping_neg() + } else { + self + } } } From 282635f2db06096f1d7f0a986cf39da4c39da449 Mon Sep 17 00:00:00 2001 From: jumbatm Date: Fri, 27 Dec 2019 20:17:17 +1000 Subject: [PATCH 04/19] Clean up const-hack from #61635 --- src/libcore/num/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 39e2c7ca60cbf..2148b6c2b415b 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -2037,7 +2037,11 @@ $EndFeature, " #[rustc_const_unstable(feature = "const_int_sign", issue = "53718")] #[inline] pub const fn signum(self) -> Self { - (self > 0) as Self - (self < 0) as Self + match self { + n if n > 0 => 1, + 0 => 0, + _ => -1, + } } } From 91c2f78b504e60e5c82ff3944d6663785bf47eee Mon Sep 17 00:00:00 2001 From: jumbatm Date: Fri, 27 Dec 2019 20:29:39 +1000 Subject: [PATCH 05/19] Clean up const-hack from #58044 --- src/libcore/num/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 2148b6c2b415b..14540394caba1 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -1709,8 +1709,13 @@ assert_eq!(", stringify!($SelfT), "::MIN.overflowing_neg(), (", stringify!($Self #[inline] #[stable(feature = "wrapping", since = "1.7.0")] #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")] + #[allow_internal_unstable(const_if_match)] pub const fn overflowing_neg(self) -> (Self, bool) { - ((!self).wrapping_add(1), self == Self::min_value()) + if self == Self::min_value() { + (Self::min_value(), true) + } else { + (-self, false) + } } } From e3155abd2efd5d07a8bc323b1ea0a915616c7ae0 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 8 Sep 2019 01:42:12 +0300 Subject: [PATCH 06/19] Stabilize attribute macros on inline modules --- src/libsyntax_expand/expand.rs | 11 ++--- .../proc-macro/attributes-on-modules-fail.rs | 21 ++++++++- .../attributes-on-modules-fail.stderr | 26 +++++------ .../ui/proc-macro/attributes-on-modules.rs | 8 +++- .../proc-macro/attributes-on-modules.stderr | 12 ----- src/test/ui/proc-macro/proc-macro-gates.rs | 6 +-- .../ui/proc-macro/proc-macro-gates.stderr | 46 ++++++------------- 7 files changed, 58 insertions(+), 72 deletions(-) delete mode 100644 src/test/ui/proc-macro/attributes-on-modules.stderr diff --git a/src/libsyntax_expand/expand.rs b/src/libsyntax_expand/expand.rs index b9b449d177915..4f6f88a753b2b 100644 --- a/src/libsyntax_expand/expand.rs +++ b/src/libsyntax_expand/expand.rs @@ -717,13 +717,10 @@ impl<'a, 'b> MacroExpander<'a, 'b> { fn gate_proc_macro_attr_item(&self, span: Span, item: &Annotatable) { let kind = match item { - Annotatable::Item(item) => match &item.kind { - ItemKind::Mod(m) if m.inline => "modules", - _ => return, - }, - Annotatable::TraitItem(_) | Annotatable::ImplItem(_) | Annotatable::ForeignItem(_) => { - return; - } + Annotatable::Item(_) + | Annotatable::TraitItem(_) + | Annotatable::ImplItem(_) + | Annotatable::ForeignItem(_) => return, Annotatable::Stmt(_) => "statements", Annotatable::Expr(_) => "expressions", Annotatable::Arm(..) diff --git a/src/test/ui/proc-macro/attributes-on-modules-fail.rs b/src/test/ui/proc-macro/attributes-on-modules-fail.rs index c8bc0b3437436..c506e903e7f89 100644 --- a/src/test/ui/proc-macro/attributes-on-modules-fail.rs +++ b/src/test/ui/proc-macro/attributes-on-modules-fail.rs @@ -3,7 +3,7 @@ #[macro_use] extern crate test_macros; -#[identity_attr] //~ ERROR custom attributes cannot be applied to modules +#[identity_attr] mod m { pub struct X; @@ -19,11 +19,28 @@ mod n {} #[empty_attr] mod module; //~ ERROR non-inline modules in proc macro input are unstable -#[empty_attr] //~ ERROR custom attributes cannot be applied to modules +#[empty_attr] mod outer { mod inner; //~ ERROR non-inline modules in proc macro input are unstable mod inner_inline {} // OK } +#[derive(Empty)] +struct S { + field: [u8; { + #[path = "outer/inner.rs"] + mod inner; //~ ERROR non-inline modules in proc macro input are unstable + mod inner_inline {} // OK + 0 + }] +} + +#[identity_attr] +fn f() { + #[path = "outer/inner.rs"] + mod inner; //~ ERROR non-inline modules in proc macro input are unstable + mod inner_inline {} // OK +} + fn main() {} diff --git a/src/test/ui/proc-macro/attributes-on-modules-fail.stderr b/src/test/ui/proc-macro/attributes-on-modules-fail.stderr index 34a5a5aaa54fb..74b9932a916c9 100644 --- a/src/test/ui/proc-macro/attributes-on-modules-fail.stderr +++ b/src/test/ui/proc-macro/attributes-on-modules-fail.stderr @@ -1,12 +1,3 @@ -error[E0658]: custom attributes cannot be applied to modules - --> $DIR/attributes-on-modules-fail.rs:6:1 - | -LL | #[identity_attr] - | ^^^^^^^^^^^^^^^^ - | - = note: for more information, see https://github.com/rust-lang/rust/issues/54727 - = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable - error: `derive` may only be applied to structs, enums and unions --> $DIR/attributes-on-modules-fail.rs:16:1 | @@ -31,11 +22,20 @@ LL | mod inner; = note: for more information, see https://github.com/rust-lang/rust/issues/54727 = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable -error[E0658]: custom attributes cannot be applied to modules - --> $DIR/attributes-on-modules-fail.rs:22:1 +error[E0658]: non-inline modules in proc macro input are unstable + --> $DIR/attributes-on-modules-fail.rs:33:9 + | +LL | mod inner; + | ^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/54727 + = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable + +error[E0658]: non-inline modules in proc macro input are unstable + --> $DIR/attributes-on-modules-fail.rs:42:5 | -LL | #[empty_attr] - | ^^^^^^^^^^^^^ +LL | mod inner; + | ^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/54727 = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable diff --git a/src/test/ui/proc-macro/attributes-on-modules.rs b/src/test/ui/proc-macro/attributes-on-modules.rs index 12c3ac6d9475b..6c73b0bf19c7f 100644 --- a/src/test/ui/proc-macro/attributes-on-modules.rs +++ b/src/test/ui/proc-macro/attributes-on-modules.rs @@ -1,13 +1,19 @@ +// check-pass // aux-build:test-macros.rs #[macro_use] extern crate test_macros; -#[identity_attr] //~ ERROR custom attributes cannot be applied to modules +#[identity_attr] mod m { pub struct S; } +#[identity_attr] +fn f() { + mod m {} +} + fn main() { let s = m::S; } diff --git a/src/test/ui/proc-macro/attributes-on-modules.stderr b/src/test/ui/proc-macro/attributes-on-modules.stderr deleted file mode 100644 index df75f0bf4b149..0000000000000 --- a/src/test/ui/proc-macro/attributes-on-modules.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0658]: custom attributes cannot be applied to modules - --> $DIR/attributes-on-modules.rs:6:1 - | -LL | #[identity_attr] - | ^^^^^^^^^^^^^^^^ - | - = note: for more information, see https://github.com/rust-lang/rust/issues/54727 - = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/proc-macro/proc-macro-gates.rs b/src/test/ui/proc-macro/proc-macro-gates.rs index 591c1e039bd75..5df6ac422ac4b 100644 --- a/src/test/ui/proc-macro/proc-macro-gates.rs +++ b/src/test/ui/proc-macro/proc-macro-gates.rs @@ -10,12 +10,8 @@ fn _test_inner() { #![empty_attr] //~ ERROR: non-builtin inner attributes are unstable } -#[empty_attr] //~ ERROR: custom attributes cannot be applied to modules -mod _test2 {} - mod _test2_inner { - #![empty_attr] //~ ERROR: custom attributes cannot be applied to modules - //~| ERROR: non-builtin inner attributes are unstable + #![empty_attr] //~ ERROR: non-builtin inner attributes are unstable } #[empty_attr = "y"] //~ ERROR: key-value macro attributes are not supported diff --git a/src/test/ui/proc-macro/proc-macro-gates.stderr b/src/test/ui/proc-macro/proc-macro-gates.stderr index e939434243b6a..fff96572e340f 100644 --- a/src/test/ui/proc-macro/proc-macro-gates.stderr +++ b/src/test/ui/proc-macro/proc-macro-gates.stderr @@ -8,7 +8,7 @@ LL | #![empty_attr] = help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable error[E0658]: non-builtin inner attributes are unstable - --> $DIR/proc-macro-gates.rs:17:5 + --> $DIR/proc-macro-gates.rs:14:5 | LL | #![empty_attr] | ^^^^^^^^^^^^^^ @@ -16,32 +16,14 @@ LL | #![empty_attr] = note: for more information, see https://github.com/rust-lang/rust/issues/54726 = help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable -error[E0658]: custom attributes cannot be applied to modules - --> $DIR/proc-macro-gates.rs:13:1 - | -LL | #[empty_attr] - | ^^^^^^^^^^^^^ - | - = note: for more information, see https://github.com/rust-lang/rust/issues/54727 - = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable - -error[E0658]: custom attributes cannot be applied to modules - --> $DIR/proc-macro-gates.rs:17:5 - | -LL | #![empty_attr] - | ^^^^^^^^^^^^^^ - | - = note: for more information, see https://github.com/rust-lang/rust/issues/54727 - = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable - error: key-value macro attributes are not supported - --> $DIR/proc-macro-gates.rs:21:1 + --> $DIR/proc-macro-gates.rs:17:1 | LL | #[empty_attr = "y"] | ^^^^^^^^^^^^^^^^^^^ error[E0658]: custom attributes cannot be applied to statements - --> $DIR/proc-macro-gates.rs:30:5 + --> $DIR/proc-macro-gates.rs:26:5 | LL | #[empty_attr] | ^^^^^^^^^^^^^ @@ -50,7 +32,7 @@ LL | #[empty_attr] = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable error[E0658]: custom attributes cannot be applied to statements - --> $DIR/proc-macro-gates.rs:34:5 + --> $DIR/proc-macro-gates.rs:30:5 | LL | #[empty_attr] | ^^^^^^^^^^^^^ @@ -59,7 +41,7 @@ LL | #[empty_attr] = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable error[E0658]: custom attributes cannot be applied to statements - --> $DIR/proc-macro-gates.rs:38:5 + --> $DIR/proc-macro-gates.rs:34:5 | LL | #[empty_attr] | ^^^^^^^^^^^^^ @@ -68,7 +50,7 @@ LL | #[empty_attr] = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable error[E0658]: custom attributes cannot be applied to expressions - --> $DIR/proc-macro-gates.rs:42:14 + --> $DIR/proc-macro-gates.rs:38:14 | LL | let _x = #[identity_attr] 2; | ^^^^^^^^^^^^^^^^ @@ -77,7 +59,7 @@ LL | let _x = #[identity_attr] 2; = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable error[E0658]: custom attributes cannot be applied to expressions - --> $DIR/proc-macro-gates.rs:45:15 + --> $DIR/proc-macro-gates.rs:41:15 | LL | let _x = [#[identity_attr] 2]; | ^^^^^^^^^^^^^^^^ @@ -86,7 +68,7 @@ LL | let _x = [#[identity_attr] 2]; = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable error[E0658]: custom attributes cannot be applied to expressions - --> $DIR/proc-macro-gates.rs:48:14 + --> $DIR/proc-macro-gates.rs:44:14 | LL | let _x = #[identity_attr] println!(); | ^^^^^^^^^^^^^^^^ @@ -95,7 +77,7 @@ LL | let _x = #[identity_attr] println!(); = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable error[E0658]: procedural macros cannot be expanded to patterns - --> $DIR/proc-macro-gates.rs:53:12 + --> $DIR/proc-macro-gates.rs:49:12 | LL | if let identity!(Some(_x)) = Some(3) {} | ^^^^^^^^^^^^^^^^^^^ @@ -104,7 +86,7 @@ LL | if let identity!(Some(_x)) = Some(3) {} = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable error[E0658]: procedural macros cannot be expanded to statements - --> $DIR/proc-macro-gates.rs:56:5 + --> $DIR/proc-macro-gates.rs:52:5 | LL | empty!(struct S;); | ^^^^^^^^^^^^^^^^^^ @@ -113,7 +95,7 @@ LL | empty!(struct S;); = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable error[E0658]: procedural macros cannot be expanded to statements - --> $DIR/proc-macro-gates.rs:57:5 + --> $DIR/proc-macro-gates.rs:53:5 | LL | empty!(let _x = 3;); | ^^^^^^^^^^^^^^^^^^^^ @@ -122,7 +104,7 @@ LL | empty!(let _x = 3;); = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable error[E0658]: procedural macros cannot be expanded to expressions - --> $DIR/proc-macro-gates.rs:59:14 + --> $DIR/proc-macro-gates.rs:55:14 | LL | let _x = identity!(3); | ^^^^^^^^^^^^ @@ -131,7 +113,7 @@ LL | let _x = identity!(3); = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable error[E0658]: procedural macros cannot be expanded to expressions - --> $DIR/proc-macro-gates.rs:60:15 + --> $DIR/proc-macro-gates.rs:56:15 | LL | let _x = [empty!(3)]; | ^^^^^^^^^ @@ -139,6 +121,6 @@ LL | let _x = [empty!(3)]; = note: for more information, see https://github.com/rust-lang/rust/issues/54727 = help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable -error: aborting due to 16 previous errors +error: aborting due to 14 previous errors For more information about this error, try `rustc --explain E0658`. From a0d8b794d61098693f53f5e6e7da29e1ea1a1c94 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 28 Dec 2019 17:37:22 +0300 Subject: [PATCH 07/19] resolve: Minor cleanup of duplicate macro reexports --- src/librustc_resolve/resolve_imports.rs | 26 +------------------------ src/test/ui/issues/issue-38715.rs | 2 +- src/test/ui/issues/issue-38715.stderr | 14 ++++++------- 3 files changed, 9 insertions(+), 33 deletions(-) diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 800c40ffdb173..afbfb647b3cac 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -528,31 +528,7 @@ impl<'a> Resolver<'a> { resolution.shadowed_glob = Some(glob_binding); } (false, false) => { - if let (&NameBindingKind::Res(_, true), &NameBindingKind::Res(_, true)) = - (&old_binding.kind, &binding.kind) - { - this.session - .struct_span_err( - binding.span, - &format!( - "a macro named `{}` has already been exported", - key.ident - ), - ) - .span_label( - binding.span, - format!("`{}` already exported", key.ident), - ) - .span_note( - old_binding.span, - "previous macro export is now shadowed", - ) - .emit(); - - resolution.binding = Some(binding); - } else { - return Err(old_binding); - } + return Err(old_binding); } } } else { diff --git a/src/test/ui/issues/issue-38715.rs b/src/test/ui/issues/issue-38715.rs index 7e9defab58864..9a9a501cae157 100644 --- a/src/test/ui/issues/issue-38715.rs +++ b/src/test/ui/issues/issue-38715.rs @@ -2,6 +2,6 @@ macro_rules! foo { ($i:ident) => {} } #[macro_export] -macro_rules! foo { () => {} } //~ ERROR a macro named `foo` has already been exported +macro_rules! foo { () => {} } //~ ERROR the name `foo` is defined multiple times fn main() {} diff --git a/src/test/ui/issues/issue-38715.stderr b/src/test/ui/issues/issue-38715.stderr index d7c4f88ff5079..c87d9f7360b98 100644 --- a/src/test/ui/issues/issue-38715.stderr +++ b/src/test/ui/issues/issue-38715.stderr @@ -1,14 +1,14 @@ -error: a macro named `foo` has already been exported +error[E0428]: the name `foo` is defined multiple times --> $DIR/issue-38715.rs:5:1 | +LL | macro_rules! foo { ($i:ident) => {} } + | ---------------- previous definition of the macro `foo` here +... LL | macro_rules! foo { () => {} } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `foo` already exported - | -note: previous macro export is now shadowed - --> $DIR/issue-38715.rs:2:1 + | ^^^^^^^^^^^^^^^^ `foo` redefined here | -LL | macro_rules! foo { ($i:ident) => {} } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `foo` must be defined only once in the macro namespace of this module error: aborting due to previous error +For more information about this error, try `rustc --explain E0428`. From 5e1b366fb6c7bb11f08a085a07f7c11666fdf80a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 28 Dec 2019 13:51:29 -0800 Subject: [PATCH 08/19] Do not ICE on lifetime error involving closures --- .../diagnostics/conflict_errors.rs | 22 +++++++++++++++++-- ...ure-doesnt-life-long-enough-issue-67634.rs | 3 +++ ...doesnt-life-long-enough-issue-67634.stderr | 15 +++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/lifetimes/unnamed-closure-doesnt-life-long-enough-issue-67634.rs create mode 100644 src/test/ui/lifetimes/unnamed-closure-doesnt-life-long-enough-issue-67634.stderr diff --git a/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs b/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs index 79221329ead48..af6fcb6922a8b 100644 --- a/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs @@ -882,9 +882,27 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { err.span_label( drop_span, format!( - "...but `{}` will be dropped here, when the function `{}` returns", + "...but `{}` will be dropped here, when the {} returns", name, - self.infcx.tcx.hir().name(fn_hir_id), + self.infcx + .tcx + .hir() + .opt_name(fn_hir_id) + .map(|name| format!("function `{}`", name)) + .unwrap_or_else(|| { + match &self + .infcx + .tcx + .typeck_tables_of(self.mir_def_id) + .node_type(fn_hir_id) + .kind + { + ty::Closure(..) => "enclosing closure", + ty::Generator(..) => "enclosing generator", + kind => bug!("expected closure or generator, found {:?}", kind), + } + .to_string() + }) ), ); diff --git a/src/test/ui/lifetimes/unnamed-closure-doesnt-life-long-enough-issue-67634.rs b/src/test/ui/lifetimes/unnamed-closure-doesnt-life-long-enough-issue-67634.rs new file mode 100644 index 0000000000000..19d7f0190479e --- /dev/null +++ b/src/test/ui/lifetimes/unnamed-closure-doesnt-life-long-enough-issue-67634.rs @@ -0,0 +1,3 @@ +fn main() { + [0].iter().flat_map(|a| [0].iter().map(|_| &a)); //~ ERROR `a` does not live long enough +} diff --git a/src/test/ui/lifetimes/unnamed-closure-doesnt-life-long-enough-issue-67634.stderr b/src/test/ui/lifetimes/unnamed-closure-doesnt-life-long-enough-issue-67634.stderr new file mode 100644 index 0000000000000..cb0b481e74876 --- /dev/null +++ b/src/test/ui/lifetimes/unnamed-closure-doesnt-life-long-enough-issue-67634.stderr @@ -0,0 +1,15 @@ +error[E0597]: `a` does not live long enough + --> $DIR/unnamed-closure-doesnt-life-long-enough-issue-67634.rs:2:49 + | +LL | [0].iter().flat_map(|a| [0].iter().map(|_| &a)); + | - ^- ...but `a` will be dropped here, when the enclosing closure returns + | | | + | | `a` would have to be valid for `'_`... + | has type `&i32` + | + = note: functions cannot return a borrow to data owned within the function's scope, functions can only return borrows to data passed as arguments + = note: to learn more, visit + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0597`. From bc1b2d5017fd99ac0814167473d00e236a5ebbac Mon Sep 17 00:00:00 2001 From: Giles Cope Date: Wed, 25 Dec 2019 22:59:26 +0000 Subject: [PATCH 09/19] Some keyword documentation. --- src/libstd/keyword_docs.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/libstd/keyword_docs.rs b/src/libstd/keyword_docs.rs index 7901c8197b587..5c7ee9bded9dc 100644 --- a/src/libstd/keyword_docs.rs +++ b/src/libstd/keyword_docs.rs @@ -1149,20 +1149,39 @@ mod where_keyword {} // /// Return a [`Future`] instead of blocking the current thread. /// -/// The documentation for this keyword is [not yet complete]. Pull requests welcome! +/// Use `async` in front of `fn`, `closure`, or a `block` to turn the marked code into a `Future`. +/// As such the code will not be run immediately, but will only be evaluated when the returned +/// future is `.await`ed. +/// +/// We have written an [async book] detailing async/await and trade-offs compared to using threads. +/// +/// ## Editions +/// +/// `async` is a keyword from the 2018 edition onwards. +/// +/// It is available for use in stable rust from version 1.39 onwards. /// /// [`Future`]: ./future/trait.Future.html -/// [not yet complete]: https://github.com/rust-lang/rust/issues/34601 +/// [async book]: https://rust-lang.github.io/async-book/ mod async_keyword {} #[doc(keyword = "await")] // /// Suspend execution until the result of a [`Future`] is ready. /// -/// The documentation for this keyword is [not yet complete]. Pull requests welcome! +/// `.await`ing a future will suspend the current function's execution until the `executor` +/// has run the future to completion. +/// +/// Read the [async book] for details on how async/await and executors work. +/// +/// ## Editions +/// +/// `await` is a keyword from the 2018 edition onwards. +/// +/// It is available for use in stable rust from version 1.39 onwards. /// /// [`Future`]: ./future/trait.Future.html -/// [not yet complete]: https://github.com/rust-lang/rust/issues/34601 +/// [async book]: https://rust-lang.github.io/async-book/ mod await_keyword {} #[doc(keyword = "dyn")] From 2e7dbb42c7f343daa22f4b4e21db4c77e834a458 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 26 Dec 2019 20:03:45 +0100 Subject: [PATCH 10/19] Move reachable.rs to librustc_passes. --- src/{librustc/middle => librustc_passes}/reachable.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{librustc/middle => librustc_passes}/reachable.rs (100%) diff --git a/src/librustc/middle/reachable.rs b/src/librustc_passes/reachable.rs similarity index 100% rename from src/librustc/middle/reachable.rs rename to src/librustc_passes/reachable.rs From 4922310a3bcc36adc21e7db11acb038918b9a2a7 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 26 Dec 2019 23:24:36 +0100 Subject: [PATCH 11/19] Move reachable_set query in librustc_passes. --- src/librustc/lib.rs | 1 - src/librustc/query/mod.rs | 2 +- src/librustc/ty/query/mod.rs | 3 +- .../back/symbol_export.rs | 3 +- src/librustc_interface/passes.rs | 4 +- src/librustc_passes/lib.rs | 2 + src/librustc_passes/reachable.rs | 38 ++++++++----------- 7 files changed, 22 insertions(+), 31 deletions(-) diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 55713aedbcb67..22bd333b6dded 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -105,7 +105,6 @@ pub mod middle { pub mod lang_items; pub mod lib_features; pub mod privacy; - pub mod reachable; pub mod recursion_limit; pub mod region; pub mod resolve_lifetime; diff --git a/src/librustc/query/mod.rs b/src/librustc/query/mod.rs index 24841a1ccf456..9b7ae0993357b 100644 --- a/src/librustc/query/mod.rs +++ b/src/librustc/query/mod.rs @@ -510,7 +510,7 @@ rustc_queries! { } Other { - query reachable_set(_: CrateNum) -> ReachableSet { + query reachable_set(_: CrateNum) -> Lrc { desc { "reachability" } } diff --git a/src/librustc/ty/query/mod.rs b/src/librustc/ty/query/mod.rs index 8be0536a18ec6..f523cee49ec63 100644 --- a/src/librustc/ty/query/mod.rs +++ b/src/librustc/ty/query/mod.rs @@ -10,7 +10,6 @@ use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; use crate::middle::lang_items::{LangItem, LanguageItems}; use crate::middle::lib_features::LibFeatures; use crate::middle::privacy::AccessLevels; -use crate::middle::reachable::ReachableSet; use crate::middle::region; use crate::middle::resolve_lifetime::{ObjectLifetimeDefault, Region, ResolveLifetimes}; use crate::middle::stability::{self, DeprecationEntry}; @@ -37,7 +36,7 @@ use crate::ty::subst::SubstsRef; use crate::ty::util::NeedsDrop; use crate::ty::{self, AdtSizedConstraint, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt}; use crate::util::common::ErrorReported; -use crate::util::nodemap::{DefIdMap, DefIdSet}; +use crate::util::nodemap::{DefIdMap, DefIdSet, HirIdSet}; use rustc_data_structures::profiling::ProfileCategory::*; use rustc_data_structures::fingerprint::Fingerprint; diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs index 07ff5c362ebbf..5bdb310f9b546 100644 --- a/src/librustc_codegen_ssa/back/symbol_export.rs +++ b/src/librustc_codegen_ssa/back/symbol_export.rs @@ -65,7 +65,6 @@ fn reachable_non_generics_provider( let mut reachable_non_generics: DefIdMap<_> = tcx .reachable_set(LOCAL_CRATE) - .0 .iter() .filter_map(|&hir_id| { // We want to ignore some FFI functions that are not exposed from @@ -313,7 +312,7 @@ fn upstream_monomorphizations_for_provider( fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: DefId) -> bool { if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) { - !tcx.reachable_set(LOCAL_CRATE).0.contains(&hir_id) + !tcx.reachable_set(LOCAL_CRATE).contains(&hir_id) } else { bug!("is_unreachable_local_definition called with non-local DefId: {:?}", def_id) } diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index 9d0ec585c203b..b4522f4c66531 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -10,7 +10,7 @@ use rustc::hir::def_id::{CrateNum, LOCAL_CRATE}; use rustc::hir::lowering::lower_crate; use rustc::lint; use rustc::middle::cstore::{CrateStore, MetadataLoader, MetadataLoaderDyn}; -use rustc::middle::{self, reachable, resolve_lifetime, stability}; +use rustc::middle::{self, resolve_lifetime, stability}; use rustc::session::config::{self, CrateType, Input, OutputFilenames, OutputType}; use rustc::session::config::{PpMode, PpSourceMode}; use rustc::session::search_paths::PathKind; @@ -678,14 +678,12 @@ pub fn default_provide(providers: &mut ty::query::Providers<'_>) { plugin::build::provide(providers); hir::provide(providers); mir::provide(providers); - reachable::provide(providers); resolve_lifetime::provide(providers); rustc_privacy::provide(providers); typeck::provide(providers); ty::provide(providers); traits::provide(providers); stability::provide(providers); - reachable::provide(providers); rustc_passes::provide(providers); rustc_traits::provide(providers); middle::region::provide(providers); diff --git a/src/librustc_passes/lib.rs b/src/librustc_passes/lib.rs index 5c2ccd28383b3..fd34b6e6f47b8 100644 --- a/src/librustc_passes/lib.rs +++ b/src/librustc_passes/lib.rs @@ -28,6 +28,7 @@ mod intrinsicck; pub mod layout_test; mod liveness; pub mod loops; +mod reachable; pub fn provide(providers: &mut Providers<'_>) { check_const::provide(providers); @@ -35,4 +36,5 @@ pub fn provide(providers: &mut Providers<'_>) { loops::provide(providers); liveness::provide(providers); intrinsicck::provide(providers); + reachable::provide(providers); } diff --git a/src/librustc_passes/reachable.rs b/src/librustc_passes/reachable.rs index c6598f2d328bf..5241d9ea43f13 100644 --- a/src/librustc_passes/reachable.rs +++ b/src/librustc_passes/reachable.rs @@ -5,23 +5,22 @@ // makes all other generics or inline functions that it references // reachable as well. -use crate::hir::def::{DefKind, Res}; -use crate::hir::def_id::{CrateNum, DefId}; -use crate::hir::Node; -use crate::hir::{CodegenFnAttrFlags, CodegenFnAttrs}; -use crate::middle::privacy; -use crate::session::config; -use crate::ty::query::Providers; -use crate::ty::{self, TyCtxt}; -use crate::util::nodemap::{FxHashSet, HirIdSet}; +use rustc::hir::def::{DefKind, Res}; +use rustc::hir::def_id::{CrateNum, DefId}; +use rustc::hir::Node; +use rustc::hir::{CodegenFnAttrFlags, CodegenFnAttrs}; +use rustc::middle::privacy; +use rustc::session::config; +use rustc::ty::query::Providers; +use rustc::ty::{self, TyCtxt}; +use rustc::util::nodemap::{FxHashSet, HirIdSet}; use rustc_data_structures::sync::Lrc; -use crate::hir; -use crate::hir::def_id::LOCAL_CRATE; -use crate::hir::intravisit; -use crate::hir::intravisit::{NestedVisitorMap, Visitor}; -use crate::hir::itemlikevisit::ItemLikeVisitor; -use rustc_macros::HashStable; +use rustc::hir; +use rustc::hir::def_id::LOCAL_CRATE; +use rustc::hir::intravisit; +use rustc::hir::intravisit::{NestedVisitorMap, Visitor}; +use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc_target::spec::abi::Abi; // Returns true if the given item must be inlined because it may be @@ -378,12 +377,7 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx } } -// We introduce a new-type here, so we can have a specialized HashStable -// implementation for it. -#[derive(Clone, HashStable)] -pub struct ReachableSet(pub Lrc); - -fn reachable_set(tcx: TyCtxt<'_>, crate_num: CrateNum) -> ReachableSet { +fn reachable_set(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Lrc { debug_assert!(crate_num == LOCAL_CRATE); let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE); @@ -429,7 +423,7 @@ fn reachable_set(tcx: TyCtxt<'_>, crate_num: CrateNum) -> ReachableSet { debug!("Inline reachability shows: {:?}", reachable_context.reachable_symbols); // Return the set of reachable symbols. - ReachableSet(Lrc::new(reachable_context.reachable_symbols)) + Lrc::new(reachable_context.reachable_symbols) } pub fn provide(providers: &mut Providers<'_>) { From 2a14d1658367ecb9e465d1b45d4f4258982dd372 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 26 Dec 2019 23:26:24 +0100 Subject: [PATCH 12/19] Move diagnostic_items.rs to librustc_passes. --- src/{librustc/middle => librustc_passes}/diagnostic_items.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{librustc/middle => librustc_passes}/diagnostic_items.rs (100%) diff --git a/src/librustc/middle/diagnostic_items.rs b/src/librustc_passes/diagnostic_items.rs similarity index 100% rename from src/librustc/middle/diagnostic_items.rs rename to src/librustc_passes/diagnostic_items.rs From fd4d50d4429f16edbc61d509bd3a31e28180b851 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 26 Dec 2019 23:33:40 +0100 Subject: [PATCH 13/19] Move diagnostic_items queries to librustc_passes. --- src/librustc/lib.rs | 1 - src/librustc/ty/context.rs | 8 -------- src/librustc_passes/diagnostic_items.rs | 26 ++++++++++++++++++------- src/librustc_passes/lib.rs | 2 ++ 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 22bd333b6dded..38dcbc8e3fbb5 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -99,7 +99,6 @@ pub mod lint; pub mod middle { pub mod cstore; pub mod dependency_format; - pub mod diagnostic_items; pub mod exported_symbols; pub mod free_region; pub mod lang_items; diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 0fb294bb9da60..566c814f947f3 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -2759,14 +2759,6 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) { assert_eq!(id, LOCAL_CRATE); tcx.arena.alloc(middle::lang_items::collect(tcx)) }; - providers.diagnostic_items = |tcx, id| { - assert_eq!(id, LOCAL_CRATE); - middle::diagnostic_items::collect(tcx) - }; - providers.all_diagnostic_items = |tcx, id| { - assert_eq!(id, LOCAL_CRATE); - middle::diagnostic_items::collect_all(tcx) - }; providers.maybe_unused_trait_import = |tcx, id| tcx.maybe_unused_trait_imports.contains(&id); providers.maybe_unused_extern_crates = |tcx, cnum| { assert_eq!(cnum, LOCAL_CRATE); diff --git a/src/librustc_passes/diagnostic_items.rs b/src/librustc_passes/diagnostic_items.rs index 32ef1338712bb..65138fad43bd8 100644 --- a/src/librustc_passes/diagnostic_items.rs +++ b/src/librustc_passes/diagnostic_items.rs @@ -9,12 +9,13 @@ //! //! * Compiler internal types like `Ty` and `TyCtxt` -use crate::hir::def_id::{DefId, LOCAL_CRATE}; -use crate::ty::TyCtxt; -use crate::util::nodemap::FxHashMap; +use rustc::hir::def_id::{DefId, LOCAL_CRATE}; +use rustc::ty::query::Providers; +use rustc::ty::TyCtxt; +use rustc::util::nodemap::FxHashMap; -use crate::hir; -use crate::hir::itemlikevisit::ItemLikeVisitor; +use rustc::hir; +use rustc::hir::itemlikevisit::ItemLikeVisitor; use syntax::ast; use syntax::symbol::{sym, Symbol}; @@ -93,7 +94,7 @@ fn extract(attrs: &[ast::Attribute]) -> Option { } /// Traverse and collect the diagnostic items in the current -pub fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap { +fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap { // Initialize the collector. let mut collector = DiagnosticItemCollector::new(tcx); @@ -104,7 +105,7 @@ pub fn collect<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap { } /// Traverse and collect all the diagnostic items in all crates. -pub fn collect_all<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap { +fn collect_all<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap { // Initialize the collector. let mut collector = FxHashMap::default(); @@ -117,3 +118,14 @@ pub fn collect_all<'tcx>(tcx: TyCtxt<'tcx>) -> &'tcx FxHashMap { tcx.arena.alloc(collector) } + +pub fn provide(providers: &mut Providers<'_>) { + providers.diagnostic_items = |tcx, id| { + assert_eq!(id, LOCAL_CRATE); + collect(tcx) + }; + providers.all_diagnostic_items = |tcx, id| { + assert_eq!(id, LOCAL_CRATE); + collect_all(tcx) + }; +} diff --git a/src/librustc_passes/lib.rs b/src/librustc_passes/lib.rs index fd34b6e6f47b8..1ac03122c4a3e 100644 --- a/src/librustc_passes/lib.rs +++ b/src/librustc_passes/lib.rs @@ -22,6 +22,7 @@ use rustc::ty::query::Providers; pub mod ast_validation; mod check_const; pub mod dead; +mod diagnostic_items; pub mod entry; pub mod hir_stats; mod intrinsicck; @@ -32,6 +33,7 @@ mod reachable; pub fn provide(providers: &mut Providers<'_>) { check_const::provide(providers); + diagnostic_items::provide(providers); entry::provide(providers); loops::provide(providers); liveness::provide(providers); From 5b80a99a9f72d0f95641b9ab9358fa3801d68be0 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 29 Dec 2019 14:31:54 +0300 Subject: [PATCH 14/19] tidy: Enforce formatting rather than just check it if `--bless` is specified --- src/bootstrap/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index f2a7d1d00cf28..b5c8de057d017 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -736,7 +736,7 @@ impl Step for Tidy { if builder.config.channel == "dev" || builder.config.channel == "nightly" { builder.info("fmt check"); - crate::format::format(&builder.build, true); + crate::format::format(&builder.build, !builder.config.cmd.bless()); } } From ec3a9f64f1e08520a486c2a1dfffca7bb7332d26 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 27 Dec 2019 18:43:22 +0100 Subject: [PATCH 15/19] Move lib_features.rs in librustc_passes. --- src/{librustc/middle => librustc_passes}/lib_features.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{librustc/middle => librustc_passes}/lib_features.rs (100%) diff --git a/src/librustc/middle/lib_features.rs b/src/librustc_passes/lib_features.rs similarity index 100% rename from src/librustc/middle/lib_features.rs rename to src/librustc_passes/lib_features.rs From 57681628f9138a76302d0eb41cac69c44b00f75a Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 27 Dec 2019 18:52:36 +0100 Subject: [PATCH 16/19] Move get_lib_features query in librustc_passes. --- src/librustc/lib.rs | 25 +++++++++++++++- src/librustc/ty/context.rs | 4 --- src/librustc_passes/lib.rs | 2 ++ src/librustc_passes/lib_features.rs | 44 +++++++++++------------------ 4 files changed, 42 insertions(+), 33 deletions(-) diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 38dcbc8e3fbb5..35c20cdbaf591 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -102,7 +102,30 @@ pub mod middle { pub mod exported_symbols; pub mod free_region; pub mod lang_items; - pub mod lib_features; + pub mod lib_features { + use rustc_data_structures::fx::{FxHashMap, FxHashSet}; + use syntax::symbol::Symbol; + + #[derive(HashStable)] + pub struct LibFeatures { + // A map from feature to stabilisation version. + pub stable: FxHashMap, + pub unstable: FxHashSet, + } + + impl LibFeatures { + pub fn to_vec(&self) -> Vec<(Symbol, Option)> { + let mut all_features: Vec<_> = self + .stable + .iter() + .map(|(f, s)| (*f, Some(*s))) + .chain(self.unstable.iter().map(|f| (*f, None))) + .collect(); + all_features.sort_unstable_by_key(|f| f.0.as_str()); + all_features + } + } + } pub mod privacy; pub mod recursion_limit; pub mod region; diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 566c814f947f3..69e3358d6f65e 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -2751,10 +2751,6 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) { assert_eq!(id, LOCAL_CRATE); tcx.crate_name }; - providers.get_lib_features = |tcx, id| { - assert_eq!(id, LOCAL_CRATE); - tcx.arena.alloc(middle::lib_features::collect(tcx)) - }; providers.get_lang_items = |tcx, id| { assert_eq!(id, LOCAL_CRATE); tcx.arena.alloc(middle::lang_items::collect(tcx)) diff --git a/src/librustc_passes/lib.rs b/src/librustc_passes/lib.rs index 1ac03122c4a3e..da781f2bae528 100644 --- a/src/librustc_passes/lib.rs +++ b/src/librustc_passes/lib.rs @@ -27,6 +27,7 @@ pub mod entry; pub mod hir_stats; mod intrinsicck; pub mod layout_test; +mod lib_features; mod liveness; pub mod loops; mod reachable; @@ -35,6 +36,7 @@ pub fn provide(providers: &mut Providers<'_>) { check_const::provide(providers); diagnostic_items::provide(providers); entry::provide(providers); + lib_features::provide(providers); loops::provide(providers); liveness::provide(providers); intrinsicck::provide(providers); diff --git a/src/librustc_passes/lib_features.rs b/src/librustc_passes/lib_features.rs index b4ddb09861df5..0b0183f3cce04 100644 --- a/src/librustc_passes/lib_features.rs +++ b/src/librustc_passes/lib_features.rs @@ -4,38 +4,19 @@ // and `#[unstable (..)]`), but are not declared in one single location // (unlike lang features), which means we need to collect them instead. -use crate::hir::intravisit::{self, NestedVisitorMap, Visitor}; -use crate::ty::TyCtxt; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; -use rustc_macros::HashStable; +use rustc::hir::def_id::LOCAL_CRATE; +use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; +use rustc::middle::lib_features::LibFeatures; +use rustc::ty::query::Providers; +use rustc::ty::TyCtxt; use syntax::ast::{Attribute, MetaItem, MetaItemKind}; use syntax::symbol::Symbol; use syntax_pos::{sym, Span}; use rustc_error_codes::*; -#[derive(HashStable)] -pub struct LibFeatures { - // A map from feature to stabilisation version. - pub stable: FxHashMap, - pub unstable: FxHashSet, -} - -impl LibFeatures { - fn new() -> LibFeatures { - LibFeatures { stable: Default::default(), unstable: Default::default() } - } - - pub fn to_vec(&self) -> Vec<(Symbol, Option)> { - let mut all_features: Vec<_> = self - .stable - .iter() - .map(|(f, s)| (*f, Some(*s))) - .chain(self.unstable.iter().map(|f| (*f, None))) - .collect(); - all_features.sort_unstable_by_key(|f| f.0.as_str()); - all_features - } +fn new_lib_features() -> LibFeatures { + LibFeatures { stable: Default::default(), unstable: Default::default() } } pub struct LibFeatureCollector<'tcx> { @@ -45,7 +26,7 @@ pub struct LibFeatureCollector<'tcx> { impl LibFeatureCollector<'tcx> { fn new(tcx: TyCtxt<'tcx>) -> LibFeatureCollector<'tcx> { - LibFeatureCollector { tcx, lib_features: LibFeatures::new() } + LibFeatureCollector { tcx, lib_features: new_lib_features() } } fn extract(&self, attr: &Attribute) -> Option<(Symbol, Option, Span)> { @@ -142,7 +123,7 @@ impl Visitor<'tcx> for LibFeatureCollector<'tcx> { } } -pub fn collect(tcx: TyCtxt<'_>) -> LibFeatures { +fn collect(tcx: TyCtxt<'_>) -> LibFeatures { let mut collector = LibFeatureCollector::new(tcx); let krate = tcx.hir().krate(); for attr in krate.non_exported_macro_attrs { @@ -151,3 +132,10 @@ pub fn collect(tcx: TyCtxt<'_>) -> LibFeatures { intravisit::walk_crate(&mut collector, krate); collector.lib_features } + +pub fn provide(providers: &mut Providers<'_>) { + providers.get_lib_features = |tcx, id| { + assert_eq!(id, LOCAL_CRATE); + tcx.arena.alloc(collect(tcx)) + }; +} From f5c63e7b27cfb94cbc0b78ab109616c7c4706779 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 29 Dec 2019 11:57:30 +0100 Subject: [PATCH 17/19] Introduce librustc/middle/mod.rs --- src/librustc/lib.rs | 40 +------------------------------------- src/librustc/middle/mod.rs | 35 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 39 deletions(-) create mode 100644 src/librustc/middle/mod.rs diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 35c20cdbaf591..76588dfa5e25e 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -95,45 +95,7 @@ pub mod hir; pub mod ich; pub mod infer; pub mod lint; - -pub mod middle { - pub mod cstore; - pub mod dependency_format; - pub mod exported_symbols; - pub mod free_region; - pub mod lang_items; - pub mod lib_features { - use rustc_data_structures::fx::{FxHashMap, FxHashSet}; - use syntax::symbol::Symbol; - - #[derive(HashStable)] - pub struct LibFeatures { - // A map from feature to stabilisation version. - pub stable: FxHashMap, - pub unstable: FxHashSet, - } - - impl LibFeatures { - pub fn to_vec(&self) -> Vec<(Symbol, Option)> { - let mut all_features: Vec<_> = self - .stable - .iter() - .map(|(f, s)| (*f, Some(*s))) - .chain(self.unstable.iter().map(|f| (*f, None))) - .collect(); - all_features.sort_unstable_by_key(|f| f.0.as_str()); - all_features - } - } - } - pub mod privacy; - pub mod recursion_limit; - pub mod region; - pub mod resolve_lifetime; - pub mod stability; - pub mod weak_lang_items; -} - +pub mod middle; pub mod mir; pub use rustc_session as session; pub mod traits; diff --git a/src/librustc/middle/mod.rs b/src/librustc/middle/mod.rs new file mode 100644 index 0000000000000..030bcf3bf4231 --- /dev/null +++ b/src/librustc/middle/mod.rs @@ -0,0 +1,35 @@ +pub mod cstore; +pub mod dependency_format; +pub mod exported_symbols; +pub mod free_region; +pub mod lang_items; +pub mod lib_features { + use rustc_data_structures::fx::{FxHashMap, FxHashSet}; + use syntax::symbol::Symbol; + + #[derive(HashStable)] + pub struct LibFeatures { + // A map from feature to stabilisation version. + pub stable: FxHashMap, + pub unstable: FxHashSet, + } + + impl LibFeatures { + pub fn to_vec(&self) -> Vec<(Symbol, Option)> { + let mut all_features: Vec<_> = self + .stable + .iter() + .map(|(f, s)| (*f, Some(*s))) + .chain(self.unstable.iter().map(|f| (*f, None))) + .collect(); + all_features.sort_unstable_by_key(|f| f.0.as_str()); + all_features + } + } +} +pub mod privacy; +pub mod recursion_limit; +pub mod region; +pub mod resolve_lifetime; +pub mod stability; +pub mod weak_lang_items; From c4b6de2d6a67440e3718512b21f37157c9e1cd3e Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Fri, 13 Dec 2019 23:33:58 +0100 Subject: [PATCH 18/19] note other end-point when typeck range pats --- src/librustc_typeck/check/pat.rs | 31 ++++++++---- src/test/ui/error-codes/E0308-4.stderr | 6 ++- ...sive_range_pattern_syntax_collision.stderr | 2 +- ...ive_range_pattern_syntax_collision2.stderr | 2 +- ...clusive_range_pattern_syntax_collision3.rs | 1 + ...ive_range_pattern_syntax_collision3.stderr | 23 +++++++-- src/test/ui/match/match-range-fail.stderr | 4 +- src/test/ui/parser/pat-tuple-5.stderr | 2 +- src/test/ui/parser/recover-range-pats.stderr | 48 ++++++++++++------- 9 files changed, 81 insertions(+), 38 deletions(-) diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs index 3fb6d5227f77b..c6378ac2d0b1b 100644 --- a/src/librustc_typeck/check/pat.rs +++ b/src/librustc_typeck/check/pat.rs @@ -353,13 +353,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn check_pat_range( &self, span: Span, - begin: &'tcx hir::Expr<'tcx>, - end: &'tcx hir::Expr<'tcx>, + lhs: &'tcx hir::Expr<'tcx>, + rhs: &'tcx hir::Expr<'tcx>, expected: Ty<'tcx>, discrim_span: Option, ) -> Option> { - let lhs_ty = self.check_expr(begin); - let rhs_ty = self.check_expr(end); + let lhs_ty = self.check_expr(lhs); + let rhs_ty = self.check_expr(rhs); // Check that both end-points are of numeric or char type. let numeric_or_char = |ty: Ty<'_>| ty.is_numeric() || ty.is_char() || ty.references_error(); @@ -367,7 +367,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let rhs_fail = !numeric_or_char(rhs_ty); if lhs_fail || rhs_fail { - self.emit_err_pat_range(span, begin.span, end.span, lhs_fail, rhs_fail, lhs_ty, rhs_ty); + self.emit_err_pat_range(span, lhs.span, rhs.span, lhs_fail, rhs_fail, lhs_ty, rhs_ty); return None; } @@ -376,11 +376,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let common_type = self.resolve_vars_if_possible(&lhs_ty); // Subtyping doesn't matter here, as the value is some kind of scalar. - self.demand_eqtype_pat(span, expected, lhs_ty, discrim_span); - self.demand_eqtype_pat(span, expected, rhs_ty, discrim_span); + let demand_eqtype = |x_span, y_span, x_ty, y_ty| { + self.demand_eqtype_pat_diag(x_span, expected, x_ty, discrim_span).map(|mut err| { + self.endpoint_has_type(&mut err, y_span, y_ty); + err.emit(); + }); + }; + demand_eqtype(lhs.span, rhs.span, lhs_ty, rhs_ty); + demand_eqtype(rhs.span, lhs.span, rhs_ty, lhs_ty); + Some(common_type) } + fn endpoint_has_type(&self, err: &mut DiagnosticBuilder<'_>, span: Span, ty: Ty<'_>) { + if !ty.references_error() { + err.span_label(span, &format!("this is of type `{}`", ty)); + } + } + fn emit_err_pat_range( &self, span: Span, @@ -408,9 +421,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let msg = |ty| format!("this is of type `{}` but it should be `char` or numeric", ty); let mut one_side_err = |first_span, first_ty, second_span, second_ty: Ty<'_>| { err.span_label(first_span, &msg(first_ty)); - if !second_ty.references_error() { - err.span_label(second_span, &format!("this is of type `{}`", second_ty)); - } + self.endpoint_has_type(&mut err, second_span, second_ty); }; if lhs_fail && rhs_fail { err.span_label(begin_span, &msg(lhs_ty)); diff --git a/src/test/ui/error-codes/E0308-4.stderr b/src/test/ui/error-codes/E0308-4.stderr index 127fdaadbc5dd..46805d6e13b7c 100644 --- a/src/test/ui/error-codes/E0308-4.stderr +++ b/src/test/ui/error-codes/E0308-4.stderr @@ -1,10 +1,12 @@ error[E0308]: mismatched types - --> $DIR/E0308-4.rs:4:9 + --> $DIR/E0308-4.rs:4:15 | LL | match x { | - this match expression has type `u8` LL | 0u8..=3i8 => (), - | ^^^^^^^^^ expected `u8`, found `i8` + | --- ^^^ expected `u8`, found `i8` + | | + | this is of type `u8` error: aborting due to previous error diff --git a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision.stderr b/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision.stderr index 2029cfaf75dfe..04538cd74b195 100644 --- a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision.stderr +++ b/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision.stderr @@ -10,7 +10,7 @@ error[E0308]: mismatched types LL | match [5..4, 99..105, 43..44] { | ----------------------- this match expression has type `std::ops::Range<{integer}>` LL | [_, 99.., _] => {}, - | ^^^^ expected struct `std::ops::Range`, found integer + | ^^ expected struct `std::ops::Range`, found integer | = note: expected struct `std::ops::Range<{integer}>` found type `{integer}` diff --git a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision2.stderr b/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision2.stderr index 6a88d05837a87..c918d0a385c75 100644 --- a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision2.stderr +++ b/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision2.stderr @@ -16,7 +16,7 @@ error[E0308]: mismatched types LL | match [5..4, 99..105, 43..44] { | ----------------------- this match expression has type `std::ops::Range<{integer}>` LL | [_, 99..] => {}, - | ^^^^ expected struct `std::ops::Range`, found integer + | ^^ expected struct `std::ops::Range`, found integer | = note: expected struct `std::ops::Range<{integer}>` found type `{integer}` diff --git a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.rs b/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.rs index 95e58b1d48c88..1557f592b2a9b 100644 --- a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.rs +++ b/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.rs @@ -6,6 +6,7 @@ fn main() { //~^ ERROR `..X` range patterns are not supported //~| ERROR mismatched types //~| ERROR mismatched types + //~| ERROR mismatched types _ => {}, } } diff --git a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.stderr b/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.stderr index 5c49fbe4c5c94..e6ee3817b3558 100644 --- a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.stderr +++ b/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.stderr @@ -5,12 +5,12 @@ LL | [..9, 99..100, _] => {}, | ^^^ help: try using the minimum value for the type: `MIN..9` error[E0308]: mismatched types - --> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:10 + --> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:12 | LL | match [5..4, 99..105, 43..44] { | ----------------------- this match expression has type `std::ops::Range<{integer}>` LL | [..9, 99..100, _] => {}, - | ^^^ expected struct `std::ops::Range`, found integer + | ^ expected struct `std::ops::Range`, found integer | = note: expected struct `std::ops::Range<{integer}>` found type `{integer}` @@ -21,11 +21,26 @@ error[E0308]: mismatched types LL | match [5..4, 99..105, 43..44] { | ----------------------- this match expression has type `std::ops::Range<{integer}>` LL | [..9, 99..100, _] => {}, - | ^^^^^^^ expected struct `std::ops::Range`, found integer + | ^^ --- this is of type `{integer}` + | | + | expected struct `std::ops::Range`, found integer + | + = note: expected struct `std::ops::Range<{integer}>` + found type `{integer}` + +error[E0308]: mismatched types + --> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:19 + | +LL | match [5..4, 99..105, 43..44] { + | ----------------------- this match expression has type `std::ops::Range<{integer}>` +LL | [..9, 99..100, _] => {}, + | -- ^^^ expected struct `std::ops::Range`, found integer + | | + | this is of type `{integer}` | = note: expected struct `std::ops::Range<{integer}>` found type `{integer}` -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/match/match-range-fail.stderr b/src/test/ui/match/match-range-fail.stderr index adaaf29aae4c8..64105dc73d3f5 100644 --- a/src/test/ui/match/match-range-fail.stderr +++ b/src/test/ui/match/match-range-fail.stderr @@ -28,7 +28,9 @@ error[E0308]: mismatched types --> $DIR/match-range-fail.rs:18:9 | LL | 'c' ..= 100 => { } - | ^^^^^^^^^^^ expected integer, found `char` + | ^^^ --- this is of type `{integer}` + | | + | expected integer, found `char` error: aborting due to 4 previous errors diff --git a/src/test/ui/parser/pat-tuple-5.stderr b/src/test/ui/parser/pat-tuple-5.stderr index 3579a2c4e0951..5b0253cd2738a 100644 --- a/src/test/ui/parser/pat-tuple-5.stderr +++ b/src/test/ui/parser/pat-tuple-5.stderr @@ -19,7 +19,7 @@ error[E0308]: mismatched types LL | match (0, 1) { | ------ this match expression has type `({integer}, {integer})` LL | (PAT ..) => {} - | ^^^^^^ expected tuple, found `u8` + | ^^^ expected tuple, found `u8` | = note: expected tuple `({integer}, {integer})` found type `u8` diff --git a/src/test/ui/parser/recover-range-pats.stderr b/src/test/ui/parser/recover-range-pats.stderr index af03b577548f7..50a44192707f0 100644 --- a/src/test/ui/parser/recover-range-pats.stderr +++ b/src/test/ui/parser/recover-range-pats.stderr @@ -417,13 +417,17 @@ error[E0308]: mismatched types --> $DIR/recover-range-pats.rs:21:12 | LL | if let .0..Y = 0 {} - | ^^^^^ expected integer, found floating-point number + | ^^ - this is of type `u8` + | | + | expected integer, found floating-point number error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:23:12 + --> $DIR/recover-range-pats.rs:23:16 | LL | if let X.. .0 = 0 {} - | ^^^^^^ expected integer, found floating-point number + | - ^^ expected integer, found floating-point number + | | + | this is of type `u8` error[E0029]: only char and numeric types are allowed in range patterns --> $DIR/recover-range-pats.rs:32:12 @@ -445,13 +449,17 @@ error[E0308]: mismatched types --> $DIR/recover-range-pats.rs:34:12 | LL | if let .0..=Y = 0 {} - | ^^^^^^ expected integer, found floating-point number + | ^^ - this is of type `u8` + | | + | expected integer, found floating-point number error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:36:12 + --> $DIR/recover-range-pats.rs:36:16 | LL | if let X..=.0 = 0 {} - | ^^^^^^ expected integer, found floating-point number + | - ^^ expected integer, found floating-point number + | | + | this is of type `u8` error[E0029]: only char and numeric types are allowed in range patterns --> $DIR/recover-range-pats.rs:45:12 @@ -473,13 +481,17 @@ error[E0308]: mismatched types --> $DIR/recover-range-pats.rs:49:12 | LL | if let .0...Y = 0 {} - | ^^^^^^ expected integer, found floating-point number + | ^^ - this is of type `u8` + | | + | expected integer, found floating-point number error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:52:12 + --> $DIR/recover-range-pats.rs:52:17 | LL | if let X... .0 = 0 {} - | ^^^^^^^ expected integer, found floating-point number + | - ^^ expected integer, found floating-point number + | | + | this is of type `u8` error[E0029]: only char and numeric types are allowed in range patterns --> $DIR/recover-range-pats.rs:60:12 @@ -491,7 +503,7 @@ error[E0308]: mismatched types --> $DIR/recover-range-pats.rs:62:12 | LL | if let .0.. = 0 {} - | ^^^^ expected integer, found floating-point number + | ^^ expected integer, found floating-point number error[E0029]: only char and numeric types are allowed in range patterns --> $DIR/recover-range-pats.rs:70:12 @@ -503,7 +515,7 @@ error[E0308]: mismatched types --> $DIR/recover-range-pats.rs:72:12 | LL | if let .0..= = 0 {} - | ^^^^^ expected integer, found floating-point number + | ^^ expected integer, found floating-point number error[E0029]: only char and numeric types are allowed in range patterns --> $DIR/recover-range-pats.rs:82:12 @@ -515,7 +527,7 @@ error[E0308]: mismatched types --> $DIR/recover-range-pats.rs:85:12 | LL | if let .0... = 0 {} - | ^^^^^ expected integer, found floating-point number + | ^^ expected integer, found floating-point number error[E0029]: only char and numeric types are allowed in range patterns --> $DIR/recover-range-pats.rs:94:14 @@ -524,10 +536,10 @@ LL | if let ..true = 0 {} | ^^^^ this is of type `bool` but it should be `char` or numeric error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:96:12 + --> $DIR/recover-range-pats.rs:96:15 | LL | if let .. .0 = 0 {} - | ^^^^^ expected integer, found floating-point number + | ^^ expected integer, found floating-point number error[E0029]: only char and numeric types are allowed in range patterns --> $DIR/recover-range-pats.rs:104:15 @@ -536,10 +548,10 @@ LL | if let ..=true = 0 {} | ^^^^ this is of type `bool` but it should be `char` or numeric error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:106:12 + --> $DIR/recover-range-pats.rs:106:15 | LL | if let ..=.0 = 0 {} - | ^^^^^ expected integer, found floating-point number + | ^^ expected integer, found floating-point number error[E0029]: only char and numeric types are allowed in range patterns --> $DIR/recover-range-pats.rs:116:15 @@ -548,10 +560,10 @@ LL | if let ...true = 0 {} | ^^^^ this is of type `bool` but it should be `char` or numeric error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:119:12 + --> $DIR/recover-range-pats.rs:119:15 | LL | if let ....3 = 0 {} - | ^^^^^ expected integer, found floating-point number + | ^^ expected integer, found floating-point number error: aborting due to 85 previous errors From e4c0eddbdb9eff62a994c76f518d8204c08b4941 Mon Sep 17 00:00:00 2001 From: Peter Todd Date: Sun, 29 Dec 2019 20:50:01 -0500 Subject: [PATCH 19/19] Typo fix --- src/libcore/mem/manually_drop.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/mem/manually_drop.rs b/src/libcore/mem/manually_drop.rs index af4635f89f61e..36064488eb249 100644 --- a/src/libcore/mem/manually_drop.rs +++ b/src/libcore/mem/manually_drop.rs @@ -121,7 +121,7 @@ impl ManuallyDrop { /// This function runs the destructor of the contained value and thus the wrapped value /// now represents uninitialized data. It is up to the user of this method to ensure the /// uninitialized data is not actually used. - /// In particular, this function can only be called called at most once + /// In particular, this function can only be called at most once /// for a given instance of `ManuallyDrop`. /// /// [`ManuallyDrop::into_inner`]: #method.into_inner