From b817a68391bbd3cfe5285457d61111500afeb158 Mon Sep 17 00:00:00 2001 From: Sebastien Marie Date: Fri, 27 Dec 2019 05:32:11 +0000 Subject: [PATCH 01/18] allow rustfmt key in [build] section --- src/bootstrap/config.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 11bfc7a47cc48..4fdfb744f381c 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -201,6 +201,7 @@ struct Build { target: Vec, cargo: Option, rustc: Option, + rustfmt: Option, /* allow bootstrap.py to use rustfmt key */ docs: Option, compiler_docs: Option, submodules: Option, From 98d8326cfc0b20b20d161fe2830bcfe2072cfdfd Mon Sep 17 00:00:00 2001 From: Sebastien Marie Date: Fri, 27 Dec 2019 05:32:12 +0000 Subject: [PATCH 02/18] add comment for rustfmt in config.toml.example --- config.toml.example | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config.toml.example b/config.toml.example index 5152a6c988582..39be51758068f 100644 --- a/config.toml.example +++ b/config.toml.example @@ -132,6 +132,10 @@ # specified, use this rustc binary instead as the stage0 snapshot compiler. #rustc = "/path/to/bin/rustc" +# Instead of download the src/stage0.txt version of rustfmt specified, +# use this rustfmt binary instead as the stage0 snapshot rustfmt. +#rustfmt = "/path/to/bin/rustfmt" + # Flag to specify whether any documentation is built. If false, rustdoc and # friends will still be compiled but they will not be used to generate any # documentation. From d4fbb55c9c1eba39eca81b0d73fe9edf5e3869fd Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Tue, 24 Dec 2019 19:14:20 +0100 Subject: [PATCH 03/18] Suggest adding a lifetime constraint when opaque type is responsible for "does not live long enough" error --- .../diagnostics/explain_borrow.rs | 43 ++++++++++++++++++- .../impl-trait/does-not-live-long-enough.rs | 11 +++++ .../does-not-live-long-enough.stderr | 21 +++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/impl-trait/does-not-live-long-enough.rs create mode 100644 src/test/ui/impl-trait/does-not-live-long-enough.stderr diff --git a/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs b/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs index 04f025fcbead9..05bec59ad8926 100644 --- a/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs +++ b/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs @@ -9,7 +9,7 @@ use rustc::mir::{ use rustc::ty::adjustment::PointerCast; use rustc::ty::{self, TyCtxt}; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_index::vec::IndexVec; use syntax_pos::symbol::Symbol; use syntax_pos::Span; @@ -206,6 +206,47 @@ impl BorrowExplanation { ), ); }; + + self.add_lifetime_bound_suggestion_to_diagnostic( + tcx, + err, + &category, + span, + region_name, + ); + } + _ => {} + } + } + pub(in crate::borrow_check) fn add_lifetime_bound_suggestion_to_diagnostic<'tcx>( + &self, + tcx: TyCtxt<'tcx>, + err: &mut DiagnosticBuilder<'_>, + category: &ConstraintCategory, + span: Span, + region_name: &RegionName, + ) { + match category { + ConstraintCategory::OpaqueType => { + if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(span) { + let suggestable_name = if region_name.was_named() { + region_name.to_string() + } else { + "'_".to_string() + }; + + err.span_suggestion( + span, + &format!( + "you can add a constraint to the {}to make it last less than \ + `'static` and match `{}`", + category.description(), + region_name, + ), + format!("{} + {}", snippet, suggestable_name), + Applicability::Unspecified, + ); + } } _ => {} } diff --git a/src/test/ui/impl-trait/does-not-live-long-enough.rs b/src/test/ui/impl-trait/does-not-live-long-enough.rs new file mode 100644 index 0000000000000..6179132b3f608 --- /dev/null +++ b/src/test/ui/impl-trait/does-not-live-long-enough.rs @@ -0,0 +1,11 @@ +struct List { + data: Vec, +} +impl List { + fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator { + self.data.iter().filter(|s| s.starts_with(prefix)).map(|s| s.as_ref()) + //~^ ERROR does not live long enough + } +} + +fn main() {} diff --git a/src/test/ui/impl-trait/does-not-live-long-enough.stderr b/src/test/ui/impl-trait/does-not-live-long-enough.stderr new file mode 100644 index 0000000000000..ddf81138dafe7 --- /dev/null +++ b/src/test/ui/impl-trait/does-not-live-long-enough.stderr @@ -0,0 +1,21 @@ +error[E0597]: `prefix` does not live long enough + --> $DIR/does-not-live-long-enough.rs:6:51 + | +LL | fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator { + | -- lifetime `'a` defined here --------------------------- opaque type requires that `prefix` is borrowed for `'a` +LL | self.data.iter().filter(|s| s.starts_with(prefix)).map(|s| s.as_ref()) + | --- ^^^^^^ borrowed value does not live long enough + | | + | value captured here +LL | +LL | } + | - `prefix` dropped here while still borrowed + | +help: you can add a constraint to the opaque type to make it last less than `'static` and match `'a` + | +LL | fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator + 'a { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0597`. From d935a26d9d06eee42a5554af23b55af4fc2008cc Mon Sep 17 00:00:00 2001 From: JP Sugarbroad Date: Mon, 30 Dec 2019 12:17:23 -0800 Subject: [PATCH 04/18] Less-than is asymmetric, not antisymmetric This has bothered me for a while. It's such a small nit, but... --- src/libcore/cmp.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 0d4788dfc570b..06e7e45c7014e 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -495,7 +495,7 @@ impl Ord for Reverse { /// /// An order is a total order if it is (for all `a`, `b` and `c`): /// -/// - total and antisymmetric: exactly one of `a < b`, `a == b` or `a > b` is true; and +/// - total and asymmetric: exactly one of `a < b`, `a == b` or `a > b` is true; and /// - transitive, `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`. /// /// ## Derivable @@ -674,7 +674,7 @@ impl PartialOrd for Ordering { /// /// The comparison must satisfy, for all `a`, `b` and `c`: /// -/// - antisymmetry: if `a < b` then `!(a > b)`, as well as `a > b` implying `!(a < b)`; and +/// - asymmetry: if `a < b` then `!(a > b)`, as well as `a > b` implying `!(a < b)`; and /// - transitivity: `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`. /// /// Note that these requirements mean that the trait itself must be implemented symmetrically and From 1a4f6b85a745e9855bbad4c5fdf0806200133f1d Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Wed, 25 Dec 2019 09:26:25 +0100 Subject: [PATCH 05/18] Change wording for lifetime suggestion for opaque types from `constraint` to `bound` --- .../error_reporting/nice_region_error/static_impl_trait.rs | 2 +- src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs | 2 +- src/librustc_mir/borrow_check/diagnostics/region_errors.rs | 2 +- src/test/ui/impl-trait/does-not-live-long-enough.stderr | 2 +- .../ui/impl-trait/multiple-lifetimes/error-handling.stderr | 2 +- .../must_outlive_least_region_or_bound.nll.stderr | 4 ++-- .../ui/impl-trait/must_outlive_least_region_or_bound.stderr | 6 +++--- .../ui/impl-trait/static-return-lifetime-infered.nll.stderr | 4 ++-- .../ui/impl-trait/static-return-lifetime-infered.stderr | 4 ++-- ...rary_self_types_pin_lifetime_impl_trait-async.nll.stderr | 2 +- .../arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr | 2 +- .../arbitrary_self_types_pin_lifetime_impl_trait.stderr | 2 +- 12 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs b/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs index 8f6fbd27a58af..69ebbe1fd3679 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -54,7 +54,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { err.span_suggestion( fn_return_span, &format!( - "you can add a constraint to the return type to make it last \ + "you can add a bound to the return type to make it last \ less than `'static` and match {}", lifetime, ), diff --git a/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs b/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs index 05bec59ad8926..e66708b173152 100644 --- a/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs +++ b/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs @@ -238,7 +238,7 @@ impl BorrowExplanation { err.span_suggestion( span, &format!( - "you can add a constraint to the {}to make it last less than \ + "you can add a bound to the {}to make it last less than \ `'static` and match `{}`", category.description(), region_name, diff --git a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs index e61581336283c..a30b952bd0adb 100644 --- a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs @@ -840,7 +840,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { span, &format!( "to allow this `impl Trait` to capture borrowed data with lifetime \ - `{}`, add `{}` as a constraint", + `{}`, add `{}` as a bound", fr_name, suggestable_fr_name, ), format!("{} + {}", snippet, suggestable_fr_name), diff --git a/src/test/ui/impl-trait/does-not-live-long-enough.stderr b/src/test/ui/impl-trait/does-not-live-long-enough.stderr index ddf81138dafe7..83d0f87015bf9 100644 --- a/src/test/ui/impl-trait/does-not-live-long-enough.stderr +++ b/src/test/ui/impl-trait/does-not-live-long-enough.stderr @@ -11,7 +11,7 @@ LL | LL | } | - `prefix` dropped here while still borrowed | -help: you can add a constraint to the opaque type to make it last less than `'static` and match `'a` +help: you can add a bound to the opaque type to make it last less than `'static` and match `'a` | LL | fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator + 'a { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr b/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr index 45c5142d93f28..4c38f0a8a914d 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr +++ b/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr @@ -5,7 +5,7 @@ LL | fn foo<'a, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> { | -- lifetime `'a` defined here ^^^^^^^^^ opaque type requires that `'a` must outlive `'static` | = help: consider replacing `'a` with `'static` -help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a constraint +help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound | LL | type E<'a, 'b> = impl Sized; + 'a | diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr index bb5a85aba9709..1806d2607a3ac 100644 --- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr +++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.nll.stderr @@ -6,7 +6,7 @@ LL | fn elided(x: &i32) -> impl Copy { x } | | | let's call the lifetime of this reference `'1` | -help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a constraint +help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound | LL | fn elided(x: &i32) -> impl Copy + '_ { x } | ^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x } | lifetime `'a` defined here | = help: consider replacing `'a` with `'static` -help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a constraint +help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound | LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x } | ^^^^^^^^^^^^^^ diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr index a8341f62e1d14..7f92e709af556 100644 --- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr +++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr @@ -11,7 +11,7 @@ note: ...can't outlive the anonymous lifetime #1 defined on the function body at | LL | fn elided(x: &i32) -> impl Copy { x } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: you can add a constraint to the return type to make it last less than `'static` and match the anonymous lifetime #1 defined on the function body at 3:1 +help: you can add a bound to the return type to make it last less than `'static` and match the anonymous lifetime #1 defined on the function body at 3:1 | LL | fn elided(x: &i32) -> impl Copy + '_ { x } | ^^^^^^^^^^^^^^ @@ -29,7 +29,7 @@ note: ...can't outlive the lifetime `'a` as defined on the function body at 6:13 | LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x } | ^^ -help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime `'a` as defined on the function body at 6:13 +help: you can add a bound to the return type to make it last less than `'static` and match the lifetime `'a` as defined on the function body at 6:13 | LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x } | ^^^^^^^^^^^^^^ @@ -47,7 +47,7 @@ note: ...can't outlive the lifetime `'a` as defined on the function body at 12:1 | LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } | ^^ -help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime `'a` as defined on the function body at 12:15 +help: you can add a bound to the return type to make it last less than `'static` and match the lifetime `'a` as defined on the function body at 12:15 | LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static + 'a { x } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr b/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr index 22f081b79f157..123ea6af6b019 100644 --- a/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr +++ b/src/test/ui/impl-trait/static-return-lifetime-infered.nll.stderr @@ -6,7 +6,7 @@ LL | fn iter_values_anon(&self) -> impl Iterator { | | | let's call the lifetime of this reference `'1` | -help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a constraint +help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound | LL | fn iter_values_anon(&self) -> impl Iterator + '_ { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL | fn iter_values<'a>(&'a self) -> impl Iterator { | lifetime `'a` defined here | = help: consider replacing `'a` with `'static` -help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a constraint +help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound | LL | fn iter_values<'a>(&'a self) -> impl Iterator + 'a { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/impl-trait/static-return-lifetime-infered.stderr b/src/test/ui/impl-trait/static-return-lifetime-infered.stderr index 1d6b5f56aa0cf..e550be1917474 100644 --- a/src/test/ui/impl-trait/static-return-lifetime-infered.stderr +++ b/src/test/ui/impl-trait/static-return-lifetime-infered.stderr @@ -15,7 +15,7 @@ LL | / fn iter_values_anon(&self) -> impl Iterator { LL | | self.x.iter().map(|a| a.0) LL | | } | |_____^ -help: you can add a constraint to the return type to make it last less than `'static` and match the anonymous lifetime #1 defined on the method body at 6:5 +help: you can add a bound to the return type to make it last less than `'static` and match the anonymous lifetime #1 defined on the method body at 6:5 | LL | fn iter_values_anon(&self) -> impl Iterator + '_ { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -35,7 +35,7 @@ note: ...can't outlive the lifetime `'a` as defined on the method body at 10:20 | LL | fn iter_values<'a>(&'a self) -> impl Iterator { | ^^ -help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime `'a` as defined on the method body at 10:20 +help: you can add a bound to the return type to make it last less than `'static` and match the lifetime `'a` as defined on the method body at 10:20 | LL | fn iter_values<'a>(&'a self) -> impl Iterator + 'a { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr index 5a63553adc5c8..f2e556c63cbf3 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.nll.stderr @@ -6,7 +6,7 @@ LL | async fn f(self: Pin<&Self>) -> impl Clone { self } | | | let's call the lifetime of this reference `'1` | -help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a constraint +help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound | LL | async fn f(self: Pin<&Self>) -> impl Clone + '_ { self } | ^^^^^^^^^^^^^^^ diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr index b46c6b9b71309..b76966e8693f2 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.nll.stderr @@ -6,7 +6,7 @@ LL | fn f(self: Pin<&Self>) -> impl Clone { self } | | | let's call the lifetime of this reference `'1` | -help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a constraint +help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound | LL | fn f(self: Pin<&Self>) -> impl Clone + '_ { self } | ^^^^^^^^^^^^^^^ diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr index 5118280e7ec0c..9f5414995151b 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr @@ -11,7 +11,7 @@ note: ...can't outlive the anonymous lifetime #1 defined on the method body at 8 | LL | fn f(self: Pin<&Self>) -> impl Clone { self } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: you can add a constraint to the return type to make it last less than `'static` and match the anonymous lifetime #1 defined on the method body at 8:5 +help: you can add a bound to the return type to make it last less than `'static` and match the anonymous lifetime #1 defined on the method body at 8:5 | LL | fn f(self: Pin<&Self>) -> impl Clone + '_ { self } | ^^^^^^^^^^^^^^^ From 0970f3d01d7e6cac81213167d234d9d23db3a15f Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 31 Dec 2019 17:14:49 +0000 Subject: [PATCH 06/18] Add missing links for insecure_time --- src/libstd/time.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 03f1ef0000a34..0dce8f810eb13 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -153,6 +153,8 @@ pub struct Instant(time::Instant); /// | Windows | [GetSystemTimeAsFileTime] | /// /// [clock_time_get (Realtime Clock)]: https://github.com/NuxiNL/cloudabi/blob/master/cloudabi.txt +/// [`insecure_time` usercall]: https://edp.fortanix.com/docs/api/fortanix_sgx_abi/struct.Usercalls.html#method.insecure_time +/// [timekeeping in SGX]: https://edp.fortanix.com/docs/concepts/rust-std/#codestdtimecode /// [gettimeofday]: http://man7.org/linux/man-pages/man2/gettimeofday.2.html /// [clock_gettime (Realtime Clock)]: https://linux.die.net/man/3/clock_gettime /// [__wasi_clock_time_get (Realtime Clock)]: https://github.com/CraneStation/wasmtime/blob/master/docs/WASI-api.md#clock_time_get From 4f639854121261f55863dbf2a88c626abb07247a Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Wed, 1 Jan 2020 18:40:13 +0100 Subject: [PATCH 07/18] Warn for bindings named same as variants when matching against a borrow --- src/librustc_mir/hair/pattern/check_match.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 12d75033da2cf..bbbad36e4851d 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -284,7 +284,7 @@ fn check_for_bindings_named_same_as_variants(cx: &MatchVisitor<'_, '_>, pat: &Pa if let Some(ty::BindByValue(hir::Mutability::Not)) = cx.tables.extract_binding_mode(cx.tcx.sess, p.hir_id, p.span) { - let pat_ty = cx.tables.pat_ty(p); + let pat_ty = cx.tables.pat_ty(p).peel_refs(); if let ty::Adt(edef, _) = pat_ty.kind { if edef.is_enum() && edef.variants.iter().any(|variant| { From f474c0084a23207f89bd082b441bfb4701c8c2dc Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Thu, 2 Jan 2020 00:48:58 +0100 Subject: [PATCH 08/18] Added test --- .../ui/match/match-same-name-enum-variant.rs | 33 +++++++++++++++++++ .../match/match-same-name-enum-variant.stderr | 24 ++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/test/ui/match/match-same-name-enum-variant.rs create mode 100644 src/test/ui/match/match-same-name-enum-variant.stderr diff --git a/src/test/ui/match/match-same-name-enum-variant.rs b/src/test/ui/match/match-same-name-enum-variant.rs new file mode 100644 index 0000000000000..d106bf713412e --- /dev/null +++ b/src/test/ui/match/match-same-name-enum-variant.rs @@ -0,0 +1,33 @@ +// Test for issue #67776: binding named the same as enum variant +// should report a warning even when matching against a borrow + +// check-pass + +#![allow(unused_variables)] +#![allow(non_snake_case)] + +enum Foo { + Bar, + Baz, +} + + +fn fn2(e: Foo) { + match e { + Bar => println!("A"), + //~^ WARNING named the same as one of the variants of the type `Foo` + Baz => println!("B"), + //~^ WARNING named the same as one of the variants of the type `Foo` + } +} + +fn fn1(e: &Foo) { + match e { + Bar => println!("A"), + //~^ WARNING named the same as one of the variants of the type `Foo` + Baz => println!("B"), + //~^ WARNING named the same as one of the variants of the type `Foo` + } +} + +fn main() {} diff --git a/src/test/ui/match/match-same-name-enum-variant.stderr b/src/test/ui/match/match-same-name-enum-variant.stderr new file mode 100644 index 0000000000000..cadf5e6cdeeab --- /dev/null +++ b/src/test/ui/match/match-same-name-enum-variant.stderr @@ -0,0 +1,24 @@ +warning[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo` + --> $DIR/match-same-name-enum-variant.rs:14:9 + | +LL | Bar => println!("A"), + | ^^^ help: to match on the variant, qualify the path: `Foo::Bar` + +warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo` + --> $DIR/match-same-name-enum-variant.rs:16:9 + | +LL | Baz => println!("B"), + | ^^^ help: to match on the variant, qualify the path: `Foo::Baz` + +warning[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo` + --> $DIR/match-same-name-enum-variant.rs:23:9 + | +LL | Bar => println!("A"), + | ^^^ help: to match on the variant, qualify the path: `Foo::Bar` + +warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo` + --> $DIR/match-same-name-enum-variant.rs:25:9 + | +LL | Baz => println!("B"), + | ^^^ help: to match on the variant, qualify the path: `Foo::Baz` + From e8e53b56dff3cd1f9e6d65ee30d5e0bfc55d9607 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Wed, 1 Jan 2020 20:10:55 -0500 Subject: [PATCH 09/18] Ensure that we process projections during MIR inlining Fixes #67710 Previously, we were not calling `super_place`, which resulted in us failing to update any local references that occur in ProjectionElem::Index. This caused the post-inlining MIR to contain a reference to a local ID from the inlined callee, leading to an ICE due to a type mismatch. --- src/librustc_mir/transform/inline.rs | 12 ++++-------- .../ui/mir/issue-67710-inline-projection.rs | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 src/test/ui/mir/issue-67710-inline-projection.rs diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 98cd341770965..3c9f8542e51d0 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -671,12 +671,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> { *local = self.make_integrate_local(local); } - fn visit_place( - &mut self, - place: &mut Place<'tcx>, - _context: PlaceContext, - _location: Location, - ) { + fn visit_place(&mut self, place: &mut Place<'tcx>, context: PlaceContext, location: Location) { match &mut place.base { PlaceBase::Static(_) => {} PlaceBase::Local(l) => { @@ -689,10 +684,11 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> { place.projection = self.tcx.intern_place_elems(&*projs); } - - *l = self.make_integrate_local(l); } } + // Handles integrating any locals that occur in the base + // or projections + self.super_place(place, context, location) } fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option> { diff --git a/src/test/ui/mir/issue-67710-inline-projection.rs b/src/test/ui/mir/issue-67710-inline-projection.rs new file mode 100644 index 0000000000000..37d8f2eac9be1 --- /dev/null +++ b/src/test/ui/mir/issue-67710-inline-projection.rs @@ -0,0 +1,17 @@ +// compile-flags: -Z mir-opt-level=2 +// build-pass + +// This used to ICE due to the inling pass not examining projections +// for references to locals + +pub fn parse(version: ()) { + p(&b'.', b"0"); +} +#[inline(always)] +fn p(byte: &u8, s: &[u8]) { + !(s[0] == *byte); +} + +fn main() { + parse(()); +} From dd8f07223346b06da723c25a3ac42f874e6c945c Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Thu, 2 Jan 2020 08:56:12 +0000 Subject: [PATCH 10/18] Use drop instead of the toilet closure `|_| ()` --- src/liballoc/tests/arc.rs | 2 +- src/liballoc/tests/rc.rs | 2 +- src/librustc_parse/parser/diagnostics.rs | 4 ++-- src/libstd/io/buffered.rs | 2 +- src/libstd/sys/unix/android.rs | 6 +++--- src/libstd/sys/unix/fs.rs | 2 +- src/libstd/sys/unix/net.rs | 2 +- src/libstd/sys/unix/os.rs | 4 ++-- src/libstd/sys/unix/pipe.rs | 4 ++-- src/libstd/sys/unix/process/process_unix.rs | 2 +- src/libstd/sys/vxworks/fs.rs | 2 +- src/libstd/sys/vxworks/net.rs | 2 +- src/libstd/sys/vxworks/os.rs | 4 ++-- src/libstd/sys/vxworks/pipe.rs | 4 ++-- src/libstd/sys/vxworks/process/process_vxworks.rs | 2 +- src/libstd/sys/wasi/os.rs | 4 ++-- src/libstd/sys/windows/fs.rs | 2 +- src/libstd/sys/windows/handle.rs | 2 +- src/libstd/sys/windows/net.rs | 2 +- src/libstd/sys/windows/os.rs | 6 +++--- src/libstd/sys_common/mod.rs | 2 +- src/libstd/sys_common/net.rs | 2 +- src/test/ui/async-await/issues/issue-64433.rs | 2 +- src/test/ui/nll/issue-50343.rs | 2 +- src/test/ui/paths-containing-nul.rs | 2 +- 25 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/liballoc/tests/arc.rs b/src/liballoc/tests/arc.rs index 2fbb59b0419e0..34384cfcba96b 100644 --- a/src/liballoc/tests/arc.rs +++ b/src/liballoc/tests/arc.rs @@ -142,7 +142,7 @@ fn shared_from_iter_trustedlen_normal() { // Try a ZST to make sure it is handled well. { - let iter = (0..SHARED_ITER_MAX).map(|_| ()); + let iter = (0..SHARED_ITER_MAX).map(drop); let vec = iter.clone().collect::>(); let rc = iter.collect::>(); assert_eq!(&*vec, &*rc); diff --git a/src/liballoc/tests/rc.rs b/src/liballoc/tests/rc.rs index e77c57d9a5a09..884856cd1b4d2 100644 --- a/src/liballoc/tests/rc.rs +++ b/src/liballoc/tests/rc.rs @@ -138,7 +138,7 @@ fn shared_from_iter_trustedlen_normal() { // Try a ZST to make sure it is handled well. { - let iter = (0..SHARED_ITER_MAX).map(|_| ()); + let iter = (0..SHARED_ITER_MAX).map(drop); let vec = iter.clone().collect::>(); let rc = iter.collect::>(); assert_eq!(&*vec, &*rc); diff --git a/src/librustc_parse/parser/diagnostics.rs b/src/librustc_parse/parser/diagnostics.rs index 578f816be58c8..fc8272a68daed 100644 --- a/src/librustc_parse/parser/diagnostics.rs +++ b/src/librustc_parse/parser/diagnostics.rs @@ -866,7 +866,7 @@ impl<'a> Parser<'a> { let appl = Applicability::MachineApplicable; if self.token.span == DUMMY_SP || self.prev_span == DUMMY_SP { // Likely inside a macro, can't provide meaninful suggestions. - return self.expect(&token::Semi).map(|_| ()); + return self.expect(&token::Semi).map(drop); } else if !sm.is_multiline(self.prev_span.until(self.token.span)) { // The current token is in the same line as the prior token, not recoverable. } else if self.look_ahead(1, |t| { @@ -905,7 +905,7 @@ impl<'a> Parser<'a> { .emit(); return Ok(()); } - self.expect(&token::Semi).map(|_| ()) // Error unconditionally + self.expect(&token::Semi).map(drop) // Error unconditionally } pub(super) fn parse_semi_or_incorrect_foreign_fn_body( diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index fee5a4e102be2..9e6849ba5bc39 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -232,7 +232,7 @@ impl BufReader { } } } - self.seek(SeekFrom::Current(offset)).map(|_| ()) + self.seek(SeekFrom::Current(offset)).map(drop) } } diff --git a/src/libstd/sys/unix/android.rs b/src/libstd/sys/unix/android.rs index c5e9d66e85ef9..8fc2599f0d762 100644 --- a/src/libstd/sys/unix/android.rs +++ b/src/libstd/sys/unix/android.rs @@ -93,12 +93,12 @@ pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> { unsafe { match ftruncate64.get() { - Some(f) => cvt_r(|| f(fd, size as i64)).map(|_| ()), + Some(f) => cvt_r(|| f(fd, size as i64)).map(drop), None => { if size > i32::max_value() as u64 { Err(io::Error::new(io::ErrorKind::InvalidInput, "cannot truncate >2GB")) } else { - cvt_r(|| ftruncate(fd, size as i32)).map(|_| ()) + cvt_r(|| ftruncate(fd, size as i32)).map(drop) } } } @@ -107,7 +107,7 @@ pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> { #[cfg(target_pointer_width = "64")] pub fn ftruncate64(fd: c_int, size: u64) -> io::Result<()> { - unsafe { cvt_r(|| ftruncate(fd, size as i64)).map(|_| ()) } + unsafe { cvt_r(|| ftruncate(fd, size as i64)).map(drop) } } #[cfg(target_pointer_width = "32")] diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 26fb0bf10fe3e..2a0519487c7a7 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -814,7 +814,7 @@ impl File { use crate::convert::TryInto; let size: off64_t = size.try_into().map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?; - cvt_r(|| unsafe { ftruncate64(self.0.raw(), size) }).map(|_| ()) + cvt_r(|| unsafe { ftruncate64(self.0.raw(), size) }).map(drop) } } diff --git a/src/libstd/sys/unix/net.rs b/src/libstd/sys/unix/net.rs index 4c23aabf49741..79b0dc02978f3 100644 --- a/src/libstd/sys/unix/net.rs +++ b/src/libstd/sys/unix/net.rs @@ -324,7 +324,7 @@ impl Socket { pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { let mut nonblocking = nonblocking as libc::c_int; - cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(|_| ()) + cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(drop) } pub fn take_error(&self) -> io::Result> { diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index b0b14725344a2..b277b3d5899b8 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -529,7 +529,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { unsafe { let _guard = env_lock(); - cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(|_| ()) + cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(drop) } } @@ -538,7 +538,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> { unsafe { let _guard = env_lock(); - cvt(libc::unsetenv(nbuf.as_ptr())).map(|_| ()) + cvt(libc::unsetenv(nbuf.as_ptr())).map(drop) } } diff --git a/src/libstd/sys/unix/pipe.rs b/src/libstd/sys/unix/pipe.rs index 77fefef8a1802..2a861c878015e 100644 --- a/src/libstd/sys/unix/pipe.rs +++ b/src/libstd/sys/unix/pipe.rs @@ -99,11 +99,11 @@ pub fn read2(p1: AnonPipe, v1: &mut Vec, p2: AnonPipe, v2: &mut Vec) -> if fds[0].revents != 0 && read(&p1, v1)? { p2.set_nonblocking(false)?; - return p2.read_to_end(v2).map(|_| ()); + return p2.read_to_end(v2).map(drop); } if fds[1].revents != 0 && read(&p2, v2)? { p1.set_nonblocking(false)?; - return p1.read_to_end(v1).map(|_| ()); + return p1.read_to_end(v1).map(drop); } } diff --git a/src/libstd/sys/unix/process/process_unix.rs b/src/libstd/sys/unix/process/process_unix.rs index 85c30abe45235..07d0fbf61fe22 100644 --- a/src/libstd/sys/unix/process/process_unix.rs +++ b/src/libstd/sys/unix/process/process_unix.rs @@ -425,7 +425,7 @@ impl Process { "invalid argument: can't kill an exited process", )) } else { - cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(|_| ()) + cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(drop) } } diff --git a/src/libstd/sys/vxworks/fs.rs b/src/libstd/sys/vxworks/fs.rs index 6c2dfb79d6f11..68f2c13317024 100644 --- a/src/libstd/sys/vxworks/fs.rs +++ b/src/libstd/sys/vxworks/fs.rs @@ -340,7 +340,7 @@ impl File { } pub fn truncate(&self, size: u64) -> io::Result<()> { - return cvt_r(|| unsafe { ftruncate(self.0.raw(), size as off_t) }).map(|_| ()); + return cvt_r(|| unsafe { ftruncate(self.0.raw(), size as off_t) }).map(drop); } pub fn read(&self, buf: &mut [u8]) -> io::Result { diff --git a/src/libstd/sys/vxworks/net.rs b/src/libstd/sys/vxworks/net.rs index 74cbd246fe819..7d4e5624f7e39 100644 --- a/src/libstd/sys/vxworks/net.rs +++ b/src/libstd/sys/vxworks/net.rs @@ -261,7 +261,7 @@ impl Socket { pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { let mut nonblocking = nonblocking as libc::c_int; - cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(|_| ()) + cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(drop) } pub fn take_error(&self) -> io::Result> { diff --git a/src/libstd/sys/vxworks/os.rs b/src/libstd/sys/vxworks/os.rs index 3f207cabf97d3..d421915449944 100644 --- a/src/libstd/sys/vxworks/os.rs +++ b/src/libstd/sys/vxworks/os.rs @@ -279,7 +279,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { unsafe { let _guard = env_lock(); - cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(|_| ()) + cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(drop) } } @@ -288,7 +288,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> { unsafe { let _guard = env_lock(); - cvt(libc::unsetenv(nbuf.as_ptr())).map(|_| ()) + cvt(libc::unsetenv(nbuf.as_ptr())).map(drop) } } diff --git a/src/libstd/sys/vxworks/pipe.rs b/src/libstd/sys/vxworks/pipe.rs index b72a655455157..0990cb8e83cf8 100644 --- a/src/libstd/sys/vxworks/pipe.rs +++ b/src/libstd/sys/vxworks/pipe.rs @@ -66,11 +66,11 @@ pub fn read2(p1: AnonPipe, v1: &mut Vec, p2: AnonPipe, v2: &mut Vec) -> if fds[0].revents != 0 && read(&p1, v1)? { p2.set_nonblocking_pipe(false)?; - return p2.read_to_end(v2).map(|_| ()); + return p2.read_to_end(v2).map(drop); } if fds[1].revents != 0 && read(&p2, v2)? { p1.set_nonblocking_pipe(false)?; - return p1.read_to_end(v1).map(|_| ()); + return p1.read_to_end(v1).map(drop); } } diff --git a/src/libstd/sys/vxworks/process/process_vxworks.rs b/src/libstd/sys/vxworks/process/process_vxworks.rs index f926dfeb6d42c..ced70dea27f99 100644 --- a/src/libstd/sys/vxworks/process/process_vxworks.rs +++ b/src/libstd/sys/vxworks/process/process_vxworks.rs @@ -138,7 +138,7 @@ impl Process { "invalid argument: can't kill an exited process", )) } else { - cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(|_| ()) + cvt(unsafe { libc::kill(self.pid, libc::SIGKILL) }).map(drop) } } diff --git a/src/libstd/sys/wasi/os.rs b/src/libstd/sys/wasi/os.rs index 44a08a2f0585d..3baec6bf09924 100644 --- a/src/libstd/sys/wasi/os.rs +++ b/src/libstd/sys/wasi/os.rs @@ -151,7 +151,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { unsafe { let _guard = env_lock(); - cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(|_| ()) + cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(drop) } } @@ -160,7 +160,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> { unsafe { let _guard = env_lock(); - cvt(libc::unsetenv(nbuf.as_ptr())).map(|_| ()) + cvt(libc::unsetenv(nbuf.as_ptr())).map(drop) } } diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs index e9c84c4e7c9cb..427f4b684e14a 100644 --- a/src/libstd/sys/windows/fs.rs +++ b/src/libstd/sys/windows/fs.rs @@ -923,6 +923,6 @@ fn symlink_junction_inner(target: &Path, junction: &Path) -> io::Result<()> { &mut ret, ptr::null_mut(), )) - .map(|_| ()) + .map(drop) } } diff --git a/src/libstd/sys/windows/handle.rs b/src/libstd/sys/windows/handle.rs index fd0c2350cb3ae..f2ad057b6b624 100644 --- a/src/libstd/sys/windows/handle.rs +++ b/src/libstd/sys/windows/handle.rs @@ -156,7 +156,7 @@ impl RawHandle { } pub fn cancel_io(&self) -> io::Result<()> { - unsafe { cvt(c::CancelIo(self.raw())).map(|_| ()) } + unsafe { cvt(c::CancelIo(self.raw())).map(drop) } } pub fn write(&self, buf: &[u8]) -> io::Result { diff --git a/src/libstd/sys/windows/net.rs b/src/libstd/sys/windows/net.rs index 58574f5723bc0..d8d4fdfce2fe4 100644 --- a/src/libstd/sys/windows/net.rs +++ b/src/libstd/sys/windows/net.rs @@ -355,7 +355,7 @@ impl Socket { #[cfg(not(target_vendor = "uwp"))] fn set_no_inherit(&self) -> io::Result<()> { sys::cvt(unsafe { c::SetHandleInformation(self.0 as c::HANDLE, c::HANDLE_FLAG_INHERIT, 0) }) - .map(|_| ()) + .map(drop) } #[cfg(target_vendor = "uwp")] diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index e7fa61dd0f6b9..c5354671c9843 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -247,7 +247,7 @@ pub fn chdir(p: &path::Path) -> io::Result<()> { let mut p = p.encode_wide().collect::>(); p.push(0); - cvt(unsafe { c::SetCurrentDirectoryW(p.as_ptr()) }).map(|_| ()) + cvt(unsafe { c::SetCurrentDirectoryW(p.as_ptr()) }).map(drop) } pub fn getenv(k: &OsStr) -> io::Result> { @@ -272,12 +272,12 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { let k = to_u16s(k)?; let v = to_u16s(v)?; - cvt(unsafe { c::SetEnvironmentVariableW(k.as_ptr(), v.as_ptr()) }).map(|_| ()) + cvt(unsafe { c::SetEnvironmentVariableW(k.as_ptr(), v.as_ptr()) }).map(drop) } pub fn unsetenv(n: &OsStr) -> io::Result<()> { let v = to_u16s(n)?; - cvt(unsafe { c::SetEnvironmentVariableW(v.as_ptr(), ptr::null()) }).map(|_| ()) + cvt(unsafe { c::SetEnvironmentVariableW(v.as_ptr(), ptr::null()) }).map(drop) } pub fn temp_dir() -> PathBuf { diff --git a/src/libstd/sys_common/mod.rs b/src/libstd/sys_common/mod.rs index ca8c63d62a6d6..e03e0fc83454b 100644 --- a/src/libstd/sys_common/mod.rs +++ b/src/libstd/sys_common/mod.rs @@ -36,7 +36,7 @@ macro_rules! rtunwrap { match $e { $ok(v) => v, ref err => { - let err = err.as_ref().map(|_| ()); // map Ok/Some which might not be Debug + let err = err.as_ref().map(drop); // map Ok/Some which might not be Debug rtabort!(concat!("unwrap failed: ", stringify!($e), " = {:?}"), err) } } diff --git a/src/libstd/sys_common/net.rs b/src/libstd/sys_common/net.rs index 9d40d9f0afd5c..c7d4828892c04 100644 --- a/src/libstd/sys_common/net.rs +++ b/src/libstd/sys_common/net.rs @@ -659,7 +659,7 @@ impl UdpSocket { pub fn connect(&self, addr: io::Result<&SocketAddr>) -> io::Result<()> { let (addrp, len) = addr?.into_inner(); - cvt_r(|| unsafe { c::connect(*self.inner.as_inner(), addrp, len) }).map(|_| ()) + cvt_r(|| unsafe { c::connect(*self.inner.as_inner(), addrp, len) }).map(drop) } } diff --git a/src/test/ui/async-await/issues/issue-64433.rs b/src/test/ui/async-await/issues/issue-64433.rs index 802e09c8a1f00..d900f8ed9ba12 100644 --- a/src/test/ui/async-await/issues/issue-64433.rs +++ b/src/test/ui/async-await/issues/issue-64433.rs @@ -23,7 +23,7 @@ impl B { async fn can_error(some_string: &str) -> Result<(), String> { let a = A { inner: vec![some_string, "foo"] }; let mut b = B {}; - Ok(b.something_with_a(a).await.map(|_| ())?) + Ok(b.something_with_a(a).await.map(drop)?) } fn main() { diff --git a/src/test/ui/nll/issue-50343.rs b/src/test/ui/nll/issue-50343.rs index 55a2d231e19ff..dd0afbbdfc6fa 100644 --- a/src/test/ui/nll/issue-50343.rs +++ b/src/test/ui/nll/issue-50343.rs @@ -3,6 +3,6 @@ #![deny(unused_mut)] fn main() { - vec![42].iter().map(|_| ()).count(); + vec![42].iter().map(drop).count(); vec![(42, 22)].iter().map(|(_x, _y)| ()).count(); } diff --git a/src/test/ui/paths-containing-nul.rs b/src/test/ui/paths-containing-nul.rs index c9bf710b8e762..e9510b53feab8 100644 --- a/src/test/ui/paths-containing-nul.rs +++ b/src/test/ui/paths-containing-nul.rs @@ -17,7 +17,7 @@ fn assert_invalid_input(on: &str, result: io::Result) { "{} returned a strange {:?} on a path with NUL", on, e.kind()), } } - inner(on, result.map(|_| ())) + inner(on, result.map(drop)) } fn main() { From 1b7c404d4bf5b28f61da14f84fe73c62862f5963 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Fri, 20 Dec 2019 14:38:28 +0100 Subject: [PATCH 11/18] bootstrap: Allow for setting the ThinLTO import limit used for compiler the compiler. --- config.toml.example | 7 +++++++ src/bootstrap/builder.rs | 15 +++++++++++++++ src/bootstrap/config.rs | 3 +++ 3 files changed, 25 insertions(+) diff --git a/config.toml.example b/config.toml.example index f12ff76284589..f22f4a5a97579 100644 --- a/config.toml.example +++ b/config.toml.example @@ -406,6 +406,13 @@ # Whether to verify generated LLVM IR #verify-llvm-ir = false +# Compile the compiler with a non-default ThinLTO import limit. This import +# limit controls the maximum size of functions imported by ThinLTO. Decreasing +# will make code compile faster at the expense of lower runtime performance. +# If `incremental` is set to true above, the import limit will default to 10 +# instead of LLVM's default of 100. +#thin-lto-import-instr-limit = 100 + # Map all debuginfo paths for libstd and crates to `/rust/$sha/$crate/...`, # generally only set for releases #remap-debuginfo = false diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index a2dca66697d6d..f7d8daa75ecb5 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1183,6 +1183,21 @@ impl<'a> Builder<'a> { rustflags.arg("-Cprefer-dynamic"); } + // When building incrementally we default to a lower ThinLTO import limit + // (unless explicitly specified otherwise). This will produce a somewhat + // slower code but give way better compile times. + { + let limit = match self.config.rust_thin_lto_import_instr_limit { + Some(limit) => Some(limit), + None if self.config.incremental => Some(10), + _ => None, + }; + + if let Some(limit) = limit { + rustflags.arg(&format!("-Cllvm-args=-import-instr-limit={}", limit)); + } + } + Cargo { command: cargo, rustflags } } diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 0970a50bee47a..ed65a606ff525 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -108,6 +108,7 @@ pub struct Config { pub rust_dist_src: bool, pub rust_codegen_backends: Vec>, pub rust_verify_llvm_ir: bool, + pub rust_thin_lto_import_instr_limit: Option, pub rust_remap_debuginfo: bool, pub build: Interned, @@ -325,6 +326,7 @@ struct Rust { deny_warnings: Option, backtrace_on_ice: Option, verify_llvm_ir: Option, + thin_lto_import_instr_limit: Option, remap_debuginfo: Option, jemalloc: Option, test_compare_mode: Option, @@ -569,6 +571,7 @@ impl Config { set(&mut config.deny_warnings, flags.deny_warnings.or(rust.deny_warnings)); set(&mut config.backtrace_on_ice, rust.backtrace_on_ice); set(&mut config.rust_verify_llvm_ir, rust.verify_llvm_ir); + config.rust_thin_lto_import_instr_limit = rust.thin_lto_import_instr_limit; set(&mut config.rust_remap_debuginfo, rust.remap_debuginfo); if let Some(ref backends) = rust.codegen_backends { From 6f57bad3182aa67368948dde1bead475f064160d Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Fri, 20 Dec 2019 14:43:28 +0100 Subject: [PATCH 12/18] Set a lower ThinLTO import limit for PR CI image. --- src/ci/docker/x86_64-gnu-llvm-7/Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ci/docker/x86_64-gnu-llvm-7/Dockerfile b/src/ci/docker/x86_64-gnu-llvm-7/Dockerfile index a1c9c13fc471a..dc90c286f5cd1 100644 --- a/src/ci/docker/x86_64-gnu-llvm-7/Dockerfile +++ b/src/ci/docker/x86_64-gnu-llvm-7/Dockerfile @@ -25,7 +25,9 @@ RUN sh /scripts/sccache.sh ENV RUST_CONFIGURE_ARGS \ --build=x86_64-unknown-linux-gnu \ --llvm-root=/usr/lib/llvm-7 \ - --enable-llvm-link-shared + --enable-llvm-link-shared \ + --set rust.thin-lto-import-instr-limit=10 + ENV SCRIPT python2.7 ../x.py test src/tools/tidy && python2.7 ../x.py test # The purpose of this container isn't to test with debug assertions and From d202b595065b9f20c07d3abc72c47f506f4491f0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 2 Jan 2020 19:57:19 +0100 Subject: [PATCH 13/18] Clean up E0130 error explanation --- src/librustc_error_codes/error_codes/E0130.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0130.md b/src/librustc_error_codes/error_codes/E0130.md index 5273f3ad14f46..539049edb33b7 100644 --- a/src/librustc_error_codes/error_codes/E0130.md +++ b/src/librustc_error_codes/error_codes/E0130.md @@ -1,4 +1,4 @@ -You declared a pattern as an argument in a foreign function declaration. +A pattern was declared as an argument in a foreign function declaration. Erroneous code example: @@ -9,7 +9,7 @@ extern { } ``` -Please replace the pattern argument with a regular one. Example: +To fix this error, replace the pattern argument with a regular one. Example: ``` struct SomeStruct { From 318280519d7a721e36d9508ab185e85bde21e2f5 Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Thu, 2 Jan 2020 20:13:40 +0100 Subject: [PATCH 14/18] Move test Co-authored-by: Centril --- .../issue-67776-match-same-name-enum-variant-refs.rs} | 0 .../issue-67776-match-same-name-enum-variant-refs.stderr} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/test/ui/{match/match-same-name-enum-variant.rs => pattern/issue-67776-match-same-name-enum-variant-refs.rs} (100%) rename src/test/ui/{match/match-same-name-enum-variant.stderr => pattern/issue-67776-match-same-name-enum-variant-refs.stderr} (100%) diff --git a/src/test/ui/match/match-same-name-enum-variant.rs b/src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.rs similarity index 100% rename from src/test/ui/match/match-same-name-enum-variant.rs rename to src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.rs diff --git a/src/test/ui/match/match-same-name-enum-variant.stderr b/src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.stderr similarity index 100% rename from src/test/ui/match/match-same-name-enum-variant.stderr rename to src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.stderr From dc19b4842a2842916bca601b83abfdf1f5ae4395 Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Thu, 2 Jan 2020 21:08:25 +0100 Subject: [PATCH 15/18] Enhance test Co-authored-by: Centril --- ...67776-match-same-name-enum-variant-refs.rs | 21 ++++++++++---- ...6-match-same-name-enum-variant-refs.stderr | 28 +++++++++++++------ 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.rs b/src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.rs index d106bf713412e..5e6a97b3ff7dd 100644 --- a/src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.rs +++ b/src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.rs @@ -12,20 +12,29 @@ enum Foo { } -fn fn2(e: Foo) { +fn fn1(e: Foo) { match e { - Bar => println!("A"), + Bar => {}, //~^ WARNING named the same as one of the variants of the type `Foo` - Baz => println!("B"), + Baz => {}, //~^ WARNING named the same as one of the variants of the type `Foo` } } -fn fn1(e: &Foo) { +fn fn2(e: &Foo) { match e { - Bar => println!("A"), + Bar => {}, //~^ WARNING named the same as one of the variants of the type `Foo` - Baz => println!("B"), + Baz => {}, + //~^ WARNING named the same as one of the variants of the type `Foo` + } +} + +fn fn3(e: &mut &&mut Foo) { + match e { + Bar => {}, + //~^ WARNING named the same as one of the variants of the type `Foo` + Baz => {}, //~^ WARNING named the same as one of the variants of the type `Foo` } } diff --git a/src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.stderr b/src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.stderr index cadf5e6cdeeab..abb8d6907e76d 100644 --- a/src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.stderr +++ b/src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.stderr @@ -1,24 +1,36 @@ warning[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo` - --> $DIR/match-same-name-enum-variant.rs:14:9 + --> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:17:9 | -LL | Bar => println!("A"), +LL | Bar => {}, | ^^^ help: to match on the variant, qualify the path: `Foo::Bar` warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo` - --> $DIR/match-same-name-enum-variant.rs:16:9 + --> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:19:9 | -LL | Baz => println!("B"), +LL | Baz => {}, | ^^^ help: to match on the variant, qualify the path: `Foo::Baz` warning[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo` - --> $DIR/match-same-name-enum-variant.rs:23:9 + --> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:26:9 | -LL | Bar => println!("A"), +LL | Bar => {}, | ^^^ help: to match on the variant, qualify the path: `Foo::Bar` warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo` - --> $DIR/match-same-name-enum-variant.rs:25:9 + --> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:28:9 | -LL | Baz => println!("B"), +LL | Baz => {}, + | ^^^ help: to match on the variant, qualify the path: `Foo::Baz` + +warning[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo` + --> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:35:9 + | +LL | Bar => {}, + | ^^^ help: to match on the variant, qualify the path: `Foo::Bar` + +warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo` + --> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:37:9 + | +LL | Baz => {}, | ^^^ help: to match on the variant, qualify the path: `Foo::Baz` From 5cc9f6b70681617300655561b9ff49cc5e4a2a04 Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Thu, 2 Jan 2020 21:11:43 +0100 Subject: [PATCH 16/18] Reformulate test description Co-authored-by: Centril --- .../ui/pattern/issue-67776-match-same-name-enum-variant-refs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.rs b/src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.rs index 5e6a97b3ff7dd..6fd5768a5a26d 100644 --- a/src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.rs +++ b/src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.rs @@ -1,5 +1,5 @@ // Test for issue #67776: binding named the same as enum variant -// should report a warning even when matching against a borrow +// should report a warning even when matching against a reference type // check-pass From 8341a9a8f770ad2cf4390446c5da1e590acfc14e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 2 Jan 2020 19:57:25 +0100 Subject: [PATCH 17/18] Clean up E0131 error explanation --- src/librustc_error_codes/error_codes/E0131.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0131.md b/src/librustc_error_codes/error_codes/E0131.md index a70a02925b0fb..ed798d4f881a3 100644 --- a/src/librustc_error_codes/error_codes/E0131.md +++ b/src/librustc_error_codes/error_codes/E0131.md @@ -1,8 +1,11 @@ -It is not possible to define `main` with generic parameters. -When `main` is present, it must take no arguments and return `()`. +The `main` function was defined with generic parameters. + Erroneous code example: ```compile_fail,E0131 fn main() { // error: main function is not allowed to have generic parameters } ``` + +It is not possible to define the `main` function with generic parameters. +It must not take any arguments. From 4a4881843313ef620dc528cbec95ba7009b79967 Mon Sep 17 00:00:00 2001 From: Peter Todd Date: Fri, 3 Jan 2020 00:40:04 -0500 Subject: [PATCH 18/18] Minor: change take() docs grammar to match other docs Eg. mem::replace() --- src/libcore/mem/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/mem/mod.rs b/src/libcore/mem/mod.rs index e11072db0dcc6..9eb151cf528a5 100644 --- a/src/libcore/mem/mod.rs +++ b/src/libcore/mem/mod.rs @@ -557,7 +557,7 @@ pub fn swap(x: &mut T, y: &mut T) { } } -/// Replace `dest` with the default value of `T`, and return the previous `dest` value. +/// Replaces `dest` with the default value of `T`, returning the previous `dest` value. /// /// # Examples ///