From 8462a378f313f7f279fb8f98a7dad703ef9ef897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sat, 17 Jul 2021 01:20:10 +0200 Subject: [PATCH 01/17] avoid temporary vectors Avoid collecting an interator just to re-iterate immediately. Rather reuse the previous iterator. (clippy::needless_collect) --- .../rustc_builtin_macros/src/deriving/generic/ty.rs | 10 +++------- compiler/rustc_infer/src/infer/error_reporting/mod.rs | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs index 6b7d0e1f204b5..00d75be439964 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs @@ -72,13 +72,9 @@ impl Path { ) -> ast::Path { let mut idents = self.path.iter().map(|s| Ident::new(*s, span)).collect(); let lt = mk_lifetimes(cx, span, &self.lifetime); - let tys: Vec> = - self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)).collect(); - let params = lt - .into_iter() - .map(GenericArg::Lifetime) - .chain(tys.into_iter().map(GenericArg::Type)) - .collect(); + let tys = self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)); + let params = + lt.into_iter().map(GenericArg::Lifetime).chain(tys.map(GenericArg::Type)).collect(); match self.kind { PathKind::Global => cx.path_all(span, true, idents, params), diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index e3a79fe265330..a5a804a291643 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -2134,7 +2134,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let new_lt = generics .as_ref() .and_then(|(parent_g, g)| { - let possible: Vec<_> = (b'a'..=b'z').map(|c| format!("'{}", c as char)).collect(); + let mut possible = (b'a'..=b'z').map(|c| format!("'{}", c as char)); let mut lts_names = g .params .iter() @@ -2150,7 +2150,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { ); } let lts = lts_names.iter().map(|s| -> &str { &*s }).collect::>(); - possible.into_iter().find(|candidate| !lts.contains(&candidate.as_str())) + possible.find(|candidate| !lts.contains(&candidate.as_str())) }) .unwrap_or("'lt".to_string()); let add_lt_sugg = generics From 31484c0e19e1a2445b9d6d5f073f8a08a11b696e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 17 Jul 2021 23:39:18 +0200 Subject: [PATCH 02/17] Fix overflow in doc blocks --- src/librustdoc/html/static/css/rustdoc.css | 3 ++- src/librustdoc/html/static/css/themes/ayu.css | 2 +- src/librustdoc/html/static/css/themes/dark.css | 2 +- src/librustdoc/html/static/css/themes/light.css | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index b86f012c0e168..08bcc46689822 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -556,7 +556,8 @@ nav.sub { .docblock table { margin: .5em 0; width: calc(100% - 2px); - border: 1px dashed; + overflow-x: auto; + display: block; } .docblock table td { diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css index 8296c3f91ca3b..354cdd2fb035b 100644 --- a/src/librustdoc/html/static/css/themes/ayu.css +++ b/src/librustdoc/html/static/css/themes/ayu.css @@ -140,7 +140,7 @@ pre, .rustdoc.source .example-wrap { border-bottom-color: #5c6773; } -.docblock table, .docblock table td, .docblock table th { +.docblock table td, .docblock table th { border-color: #5c6773; } diff --git a/src/librustdoc/html/static/css/themes/dark.css b/src/librustdoc/html/static/css/themes/dark.css index 599fb942dbe2a..b4f5a13c81509 100644 --- a/src/librustdoc/html/static/css/themes/dark.css +++ b/src/librustdoc/html/static/css/themes/dark.css @@ -97,7 +97,7 @@ pre, .rustdoc.source .example-wrap { border-bottom-color: #DDD; } -.docblock table, .docblock table td, .docblock table th { +.docblock table td, .docblock table th { border-color: #ddd; } diff --git a/src/librustdoc/html/static/css/themes/light.css b/src/librustdoc/html/static/css/themes/light.css index 0c2799727f3e3..29cbcd65ce81d 100644 --- a/src/librustdoc/html/static/css/themes/light.css +++ b/src/librustdoc/html/static/css/themes/light.css @@ -97,7 +97,7 @@ pre, .rustdoc.source .example-wrap { border-bottom-color: #ddd; } -.docblock table, .docblock table td, .docblock table th { +.docblock table td, .docblock table th { border-color: #ddd; } From b0f8776d11b746ab7dd7098fb225eff34a992d87 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 17 Jul 2021 23:56:24 +0200 Subject: [PATCH 03/17] Remove unused file --- src/test/rustdoc-gui/src/lib2/src/lib.rs | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 src/test/rustdoc-gui/src/lib2/src/lib.rs diff --git a/src/test/rustdoc-gui/src/lib2/src/lib.rs b/src/test/rustdoc-gui/src/lib2/src/lib.rs deleted file mode 100644 index 31e1bb209f98e..0000000000000 --- a/src/test/rustdoc-gui/src/lib2/src/lib.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); - } -} From 3f1a120ba9c5077029ffb2d39d654dd3732314a7 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 18 Jul 2021 00:03:08 +0200 Subject: [PATCH 04/17] Add GUI test for
overflow --- src/test/rustdoc-gui/docblock-table-overflow.goml | 9 +++++++++ src/test/rustdoc-gui/src/lib2/lib.rs | 9 +++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/test/rustdoc-gui/docblock-table-overflow.goml diff --git a/src/test/rustdoc-gui/docblock-table-overflow.goml b/src/test/rustdoc-gui/docblock-table-overflow.goml new file mode 100644 index 0000000000000..9ab7cd0fa07b0 --- /dev/null +++ b/src/test/rustdoc-gui/docblock-table-overflow.goml @@ -0,0 +1,9 @@ +// This test ensures that the type declaration content overflow is handled inside the
 directly.
+goto: file://|DOC_PATH|/lib2/long_table/struct.Foo.html
+// We set a fixed size so there is no chance of "random" resize.
+size: (1100, 800)
+// Logically, the ".docblock" and the "

" should have the same scroll width. +compare-elements-property: (".top-doc .docblock", ".top-doc .docblock > p", ["scrollWidth"]) +assert-property: (".top-doc .docblock", {"scrollWidth": "816"}) +// However, since there is overflow in the

, its scroll width is bigger. +assert-property: (".top-doc .docblock table", {"scrollWidth": "1573"}) diff --git a/src/test/rustdoc-gui/src/lib2/lib.rs b/src/test/rustdoc-gui/src/lib2/lib.rs index 0466909479b67..f724a64e30760 100644 --- a/src/test/rustdoc-gui/src/lib2/lib.rs +++ b/src/test/rustdoc-gui/src/lib2/lib.rs @@ -54,3 +54,12 @@ pub mod long_trait { pub trait ALongNameBecauseItHelpsTestingTheCurrentProblem: DerefMut + From + Send + Sync + AsRef + 'static {} } + +pub mod long_table { + /// | This::is::a::kinda::very::long::header::number::one | This::is::a::kinda::very::long::header::number::two | This::is::a::kinda::very::long::header::number::one | This::is::a::kinda::very::long::header::number::two | + /// | ----------- | ----------- | ----------- | ----------- | + /// | This::is::a::kinda::long::content::number::one | This::is::a::kinda::very::long::content::number::two | This::is::a::kinda::long::content::number::one | This::is::a::kinda::very::long::content::number::two | + /// + /// I wanna sqdkfnqds f dsqf qds f dsqf dsq f dsq f qds f qds f qds f dsqq f dsf sqdf dsq fds f dsq f dq f ds fq sd fqds f dsq f sqd fsq df sd fdsqfqsd fdsq f dsq f dsqfd s dfq + pub struct Foo; +} From d05a286449809cba5043bdac39074198a63cda6d Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Mon, 19 Jul 2021 18:50:06 +0800 Subject: [PATCH 05/17] Iterate through impls only when permitted --- .../src/transform/check_consts/validation.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_mir/src/transform/check_consts/validation.rs b/compiler/rustc_mir/src/transform/check_consts/validation.rs index 646ae8ced7eb4..cfc538ef500a1 100644 --- a/compiler/rustc_mir/src/transform/check_consts/validation.rs +++ b/compiler/rustc_mir/src/transform/check_consts/validation.rs @@ -897,16 +897,19 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> { permitted = true; } } - let mut const_impls = true; - tcx.for_each_relevant_impl(trait_id, substs.type_at(0), |imp| { - if const_impls { - if let hir::Constness::NotConst = tcx.impl_constness(imp) { - const_impls = false; + if !permitted { + // if trait's impls are all const, permit the call. + let mut const_impls = true; + tcx.for_each_relevant_impl(trait_id, substs.type_at(0), |imp| { + if const_impls { + if let hir::Constness::NotConst = tcx.impl_constness(imp) { + const_impls = false; + } } + }); + if const_impls { + permitted = true; } - }); - if const_impls { - permitted = true; } } From 4b82bbeac009c09c55e4a5458ee7338bddb14a44 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Mon, 19 Jul 2021 18:50:47 +0800 Subject: [PATCH 06/17] Recognize bounds on impls as const bounds --- compiler/rustc_hir/src/hir.rs | 21 +++++++++++++++++++ .../rustc_typeck/src/check/fn_ctxt/mod.rs | 9 +------- compiler/rustc_typeck/src/collect.rs | 7 +------ .../call-generic-in-impl.rs | 15 +++++++++++++ 4 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 src/test/ui/rfc-2632-const-trait-impl/call-generic-in-impl.rs diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 4b2679e164aac..213887e26179c 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -3064,6 +3064,27 @@ impl<'hir> Node<'hir> { Node::Crate(_) | Node::Visibility(_) => None, } } + + /// Returns `Constness::Const` when this node is a const fn/impl. + pub fn constness(&self) -> Constness { + match self { + Node::Item(Item { + kind: ItemKind::Fn(FnSig { header: FnHeader { constness, .. }, .. }, ..), + .. + }) + | Node::TraitItem(TraitItem { + kind: TraitItemKind::Fn(FnSig { header: FnHeader { constness, .. }, .. }, ..), + .. + }) + | Node::ImplItem(ImplItem { + kind: ImplItemKind::Fn(FnSig { header: FnHeader { constness, .. }, .. }, ..), + .. + }) + | Node::Item(Item { kind: ItemKind::Impl(Impl { constness, .. }), .. }) => *constness, + + _ => Constness::NotConst, + } + } } // Some nodes are used a lot. Make sure they don't unintentionally get bigger. diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs index 4da4835f7cfbb..13686cfec809a 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs @@ -15,7 +15,6 @@ use rustc_hir::def_id::DefId; use rustc_infer::infer; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; -use rustc_middle::hir::map::blocks::FnLikeNode; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::subst::GenericArgKind; use rustc_middle::ty::{self, Const, Ty, TyCtxt}; @@ -175,13 +174,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { } fn default_constness_for_trait_bounds(&self) -> hir::Constness { - // FIXME: refactor this into a method - let node = self.tcx.hir().get(self.body_id); - if let Some(fn_like) = FnLikeNode::from_node(node) { - fn_like.constness() - } else { - hir::Constness::NotConst - } + self.tcx.hir().get(self.body_id).constness() } fn get_type_parameter_bounds( diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 506ca98b96026..1a4c2eb515584 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -35,7 +35,6 @@ use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE}; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_hir::weak_lang_items; use rustc_hir::{GenericParamKind, HirId, Node}; -use rustc_middle::hir::map::blocks::FnLikeNode; use rustc_middle::hir::map::Map; use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}; use rustc_middle::mir::mono::Linkage; @@ -358,11 +357,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> { } fn default_constness_for_trait_bounds(&self) -> hir::Constness { - if let Some(fn_like) = FnLikeNode::from_node(self.node()) { - fn_like.constness() - } else { - hir::Constness::NotConst - } + self.node().constness() } fn get_type_parameter_bounds( diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-in-impl.rs b/src/test/ui/rfc-2632-const-trait-impl/call-generic-in-impl.rs new file mode 100644 index 0000000000000..536c1d7374023 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-in-impl.rs @@ -0,0 +1,15 @@ +// check-pass +#![feature(const_fn_trait_bound)] +#![feature(const_trait_impl)] + +trait MyPartialEq { + fn eq(&self, other: &Self) -> bool; +} + +impl const MyPartialEq for T { + fn eq(&self, other: &Self) -> bool { + PartialEq::eq(self, other) + } +} + +fn main() {} From 2a56a681c4cfd56822e447a66adccdc32580b46a Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 19 Jul 2021 07:06:42 -0700 Subject: [PATCH 07/17] Add comments explaining the unix command-line argument support. Following up on #87236, add comments to the unix command-line argument support explaining that the code doesn't mutate the system-provided argc/argv, and that this is why the code doesn't need a lock or special memory ordering. --- library/std/src/sys/unix/args.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/library/std/src/sys/unix/args.rs b/library/std/src/sys/unix/args.rs index ad93fa610c481..0bd1ea645779f 100644 --- a/library/std/src/sys/unix/args.rs +++ b/library/std/src/sys/unix/args.rs @@ -77,10 +77,18 @@ mod imp { use crate::ptr; use crate::sync::atomic::{AtomicIsize, AtomicPtr, Ordering}; + // The system-provided argc and argv, which we store in static memory + // here so that we can defer the work of parsing them until its actually + // needed. + // + // Note that we never mutate argv/argc, the argv array, or the argv + // strings, which allows the code in this file to be very simple. static ARGC: AtomicIsize = AtomicIsize::new(0); static ARGV: AtomicPtr<*const u8> = AtomicPtr::new(ptr::null_mut()); unsafe fn really_init(argc: isize, argv: *const *const u8) { + // These don't need to be ordered with each other or other stores, + // because they only hold the unmodified system-provide argv/argc. ARGC.store(argc, Ordering::Relaxed); ARGV.store(argv as *mut _, Ordering::Relaxed); } @@ -122,8 +130,14 @@ mod imp { fn clone() -> Vec { unsafe { - // Load ARGC and ARGV without a lock. If the store to either ARGV or - // ARGC isn't visible yet, we'll return an empty argument list. + // Load ARGC and ARGV, which hold the unmodified system-provided + // argc/argv, so we can read the pointed-to memory without atomics + // or synchronization. + // + // If either ARGC or ARGV is still zero or null, then either there + // really are no arguments, or someone is asking for `args()` + // before initialization has completed, and we return an empty + // list. let argv = ARGV.load(Ordering::Relaxed); let argc = if argv.is_null() { 0 } else { ARGC.load(Ordering::Relaxed) }; (0..argc) From 64f4e34d69a99b00e635a572a0643dd008bb5a3a Mon Sep 17 00:00:00 2001 From: Chinmay Deshpande Date: Mon, 19 Jul 2021 20:03:03 -0700 Subject: [PATCH 08/17] Fix typo in compile.rs --- src/bootstrap/compile.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 1fae4bee732c0..5b9ea97dea59d 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -2,7 +2,7 @@ //! library. //! //! This module contains some of the real meat in the rustbuild build system -//! which is where Cargo is used to compiler the standard library, libtest, and +//! which is where Cargo is used to compile the standard library, libtest, and //! compiler. This module is also responsible for assembling the sysroot as it //! goes along from the output of the previous stage. From b3594f0d1d8190387d37b0f5b30b9688f857b1dd Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 20 Jul 2021 11:36:31 +0000 Subject: [PATCH 09/17] Get back the more precise suggestion spans of old regionck --- .../src/borrow_check/diagnostics/region_errors.rs | 10 ++++++---- .../must_outlive_least_region_or_bound.nll.stderr | 4 ++-- .../static-return-lifetime-infered.nll.stderr | 4 ++-- ...self_types_pin_lifetime_impl_trait-async.nll.stderr | 2 +- ...trary_self_types_pin_lifetime_impl_trait.nll.stderr | 2 +- .../trait-object-nested-in-impl-trait.nll.stderr | 4 ++-- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs index feb7672f650ec..1460c2378d1c9 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs @@ -9,7 +9,7 @@ use rustc_middle::mir::{ConstraintCategory, ReturnConstraint}; use rustc_middle::ty::subst::Subst; use rustc_middle::ty::{self, RegionVid, Ty}; use rustc_span::symbol::{kw, sym}; -use rustc_span::Span; +use rustc_span::{BytePos, Span}; use crate::util::borrowck_errors; @@ -641,12 +641,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } else { "'_".to_string() }; - let suggestion = if snippet.ends_with(';') { + let span = if snippet.ends_with(';') { // `type X = impl Trait;` - format!("{} + {};", &snippet[..snippet.len() - 1], suggestable_fr_name) + span.with_hi(span.hi() - BytePos(1)) } else { - format!("{} + {}", snippet, suggestable_fr_name) + span }; + let suggestion = format!(" + {}", suggestable_fr_name); + let span = span.shrink_to_hi(); diag.span_suggestion( span, &format!( 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 4372de245078f..e9d6208773454 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 @@ -9,7 +9,7 @@ LL | fn elided(x: &i32) -> impl Copy { x } 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 } - | ^^^^^^^^^^^^^^ + | ^^^^ error: lifetime may not live long enough --> $DIR/must_outlive_least_region_or_bound.rs:5:32 @@ -23,7 +23,7 @@ LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x } 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 } - | ^^^^^^^^^^^^^^ + | ^^^^ error: lifetime may not live long enough --> $DIR/must_outlive_least_region_or_bound.rs:7:46 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 65178cc9d24c2..6c5264671a912 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 @@ -9,7 +9,7 @@ LL | fn iter_values_anon(&self) -> impl Iterator { 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 + '_ { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^ error: lifetime may not live long enough --> $DIR/static-return-lifetime-infered.rs:9:37 @@ -23,7 +23,7 @@ LL | fn iter_values<'a>(&'a self) -> impl Iterator { 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 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^ error: aborting due to 2 previous errors 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 f2e556c63cbf3..a678731934f6e 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 @@ -9,7 +9,7 @@ LL | async fn f(self: Pin<&Self>) -> impl Clone { self } 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 } - | ^^^^^^^^^^^^^^^ + | ^^^^ error: aborting due to previous error 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 73766c31b93b6..962593e411e92 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 @@ -9,7 +9,7 @@ LL | fn f(self: Pin<&Self>) -> impl Clone { self } 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 } - | ^^^^^^^^^^^^^^^ + | ^^^^ error: aborting due to previous error diff --git a/src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.nll.stderr b/src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.nll.stderr index 2407d13714a2a..05ba7808600b0 100644 --- a/src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.nll.stderr +++ b/src/test/ui/suggestions/lifetimes/trait-object-nested-in-impl-trait.nll.stderr @@ -9,7 +9,7 @@ LL | fn iter(&self) -> impl Iterator> { help: to allow this `impl Trait` to capture borrowed data with lifetime `'1`, add `'_` as a bound | LL | fn iter(&self) -> impl Iterator> + '_ { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^ error: lifetime may not live long enough --> $DIR/trait-object-nested-in-impl-trait.rs:39:9 @@ -47,7 +47,7 @@ LL | fn iter<'a>(&'a self) -> impl Iterator> { help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound | LL | fn iter<'a>(&'a self) -> impl Iterator> + 'a { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^ error: aborting due to 4 previous errors From 919a8a5028e4b94370e9c3f6b19cda48f9c97f7b Mon Sep 17 00:00:00 2001 From: oxalica Date: Fri, 16 Jul 2021 19:18:50 +0800 Subject: [PATCH 10/17] Fix NixOS detection Use `/etc/os-release` instead of `/etc/NIXOS`. The latter one does not exist on NixOS when using tmpfs as root. --- src/bootstrap/bootstrap.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index f9904cb610d2d..1c5e9d5d83736 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -580,7 +580,13 @@ def fix_bin_or_dylib(self, fname): if ostype != "Linux": return - if not os.path.exists("/etc/NIXOS"): + # Use `/etc/os-release` instead of `/etc/NIXOS`. + # The latter one does not exist on NixOS when using tmpfs as root. + try: + with open("/etc/os-release", "r") as f: + if not any(line.strip() == "ID=nixos" for line in f): + return + except FileNotFoundError: return if os.path.exists("/lib"): return From 320d049e876579cd5c57be17e791a519f9b852a0 Mon Sep 17 00:00:00 2001 From: Chris Midgley Date: Tue, 20 Jul 2021 20:13:08 +0100 Subject: [PATCH 11/17] Add long explanation for E0722 --- compiler/rustc_error_codes/src/error_codes.rs | 2 +- .../src/error_codes/E0722.md | 24 +++++++++++++++++++ .../feature-gate-optimize_attribute.stderr | 3 ++- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 compiler/rustc_error_codes/src/error_codes/E0722.md diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index df162f8dce026..902c7c4787323 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -418,6 +418,7 @@ E0716: include_str!("./error_codes/E0716.md"), E0718: include_str!("./error_codes/E0718.md"), E0719: include_str!("./error_codes/E0719.md"), E0720: include_str!("./error_codes/E0720.md"), +E0722: include_str!("./error_codes/E0722.md"), E0724: include_str!("./error_codes/E0724.md"), E0725: include_str!("./error_codes/E0725.md"), E0727: include_str!("./error_codes/E0727.md"), @@ -634,7 +635,6 @@ E0783: include_str!("./error_codes/E0783.md"), E0711, // a feature has been declared with conflicting stability attributes E0717, // rustc_promotable without stability attribute // E0721, // `await` keyword - E0722, // Malformed `#[optimize]` attribute // E0723, unstable feature in `const` context E0726, // non-explicit (not `'_`) elided lifetime in unsupported position // E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`. diff --git a/compiler/rustc_error_codes/src/error_codes/E0722.md b/compiler/rustc_error_codes/src/error_codes/E0722.md new file mode 100644 index 0000000000000..4a687d7428805 --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0722.md @@ -0,0 +1,24 @@ +The `optimize` attribute was malformed. + +Erroneous code example: + +```compile_fail,E0722 +#![feature(optimize_attribute)] + +#[optimize(something)] // error: invalid argument +pub fn something() {} + +fn main() {} +``` + +The `#[optimize]` attribute should be used as follows: + +- `#[optimize(size)]` -- instructs the optimization pipeline to generate code + that's smaller rather than faster + +- `#[optimize(speed)]` -- instructs the optimization pipeline to generate code + that's faster rather than smaller + +See [RFC 2412] for more details. + +[RFC 2412]: https://rust-lang.github.io/rfcs/2412-optimize-attr.html diff --git a/src/test/ui/feature-gates/feature-gate-optimize_attribute.stderr b/src/test/ui/feature-gates/feature-gate-optimize_attribute.stderr index 50ce6427e8b58..a3ced35155f37 100644 --- a/src/test/ui/feature-gates/feature-gate-optimize_attribute.stderr +++ b/src/test/ui/feature-gates/feature-gate-optimize_attribute.stderr @@ -51,4 +51,5 @@ LL | #[optimize(banana)] error: aborting due to 6 previous errors -For more information about this error, try `rustc --explain E0658`. +Some errors have detailed explanations: E0658, E0722. +For more information about an error, try `rustc --explain E0658`. From e09d78260908436e6bc1691f23cda2ee8382545a Mon Sep 17 00:00:00 2001 From: Chris Midgley Date: Wed, 21 Jul 2021 10:29:20 +0100 Subject: [PATCH 12/17] add working code example --- compiler/rustc_error_codes/src/error_codes/E0722.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/compiler/rustc_error_codes/src/error_codes/E0722.md b/compiler/rustc_error_codes/src/error_codes/E0722.md index 4a687d7428805..1513c4ce0594d 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0722.md +++ b/compiler/rustc_error_codes/src/error_codes/E0722.md @@ -19,6 +19,16 @@ The `#[optimize]` attribute should be used as follows: - `#[optimize(speed)]` -- instructs the optimization pipeline to generate code that's faster rather than smaller +For example: +``` +#![feature(optimize_attribute)] + +#[optimize(size)] +pub fn something() {} + +fn main() {} +``` + See [RFC 2412] for more details. [RFC 2412]: https://rust-lang.github.io/rfcs/2412-optimize-attr.html From adc5de601f9e860f00638f078f3a4d4e6ae4c73d Mon Sep 17 00:00:00 2001 From: Chris Midgley Date: Wed, 21 Jul 2021 10:57:27 +0100 Subject: [PATCH 13/17] docs: remove spurious main functions --- compiler/rustc_error_codes/src/error_codes/E0722.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0722.md b/compiler/rustc_error_codes/src/error_codes/E0722.md index 1513c4ce0594d..fe2b6d27457f5 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0722.md +++ b/compiler/rustc_error_codes/src/error_codes/E0722.md @@ -7,8 +7,6 @@ Erroneous code example: #[optimize(something)] // error: invalid argument pub fn something() {} - -fn main() {} ``` The `#[optimize]` attribute should be used as follows: @@ -25,8 +23,6 @@ For example: #[optimize(size)] pub fn something() {} - -fn main() {} ``` See [RFC 2412] for more details. From b24d4915b895fab1528ee5081edaa94e951b523e Mon Sep 17 00:00:00 2001 From: Chris Midgley Date: Wed, 21 Jul 2021 10:58:35 +0100 Subject: [PATCH 14/17] docs: add newline before example --- compiler/rustc_error_codes/src/error_codes/E0722.md | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_error_codes/src/error_codes/E0722.md b/compiler/rustc_error_codes/src/error_codes/E0722.md index fe2b6d27457f5..570717a92bd79 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0722.md +++ b/compiler/rustc_error_codes/src/error_codes/E0722.md @@ -18,6 +18,7 @@ The `#[optimize]` attribute should be used as follows: that's faster rather than smaller For example: + ``` #![feature(optimize_attribute)] From 27ffc3725a3e8bf5cac28094099250bc2d664ec7 Mon Sep 17 00:00:00 2001 From: Chris Midgley Date: Wed, 21 Jul 2021 13:22:57 +0100 Subject: [PATCH 15/17] Add long explanation for E0757 --- compiler/rustc_error_codes/src/error_codes.rs | 2 +- .../src/error_codes/E0757.md | 25 +++++++++++++++++++ src/test/ui/ffi_const2.stderr | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 compiler/rustc_error_codes/src/error_codes/E0757.md diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index df162f8dce026..2eced1fc0fc3c 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -449,6 +449,7 @@ E0753: include_str!("./error_codes/E0753.md"), E0754: include_str!("./error_codes/E0754.md"), E0755: include_str!("./error_codes/E0755.md"), E0756: include_str!("./error_codes/E0756.md"), +E0757: include_str!("./error_codes/E0757.md"), E0758: include_str!("./error_codes/E0758.md"), E0759: include_str!("./error_codes/E0759.md"), E0760: include_str!("./error_codes/E0760.md"), @@ -638,6 +639,5 @@ E0783: include_str!("./error_codes/E0783.md"), // E0723, unstable feature in `const` context E0726, // non-explicit (not `'_`) elided lifetime in unsupported position // E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`. - E0757, // `#[ffi_const]` functions cannot be `#[ffi_pure]` E0772, // `'static' obligation coming from `impl dyn Trait {}` or `impl Foo for dyn Bar {}`. } diff --git a/compiler/rustc_error_codes/src/error_codes/E0757.md b/compiler/rustc_error_codes/src/error_codes/E0757.md new file mode 100644 index 0000000000000..03ab4e7699dcd --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0757.md @@ -0,0 +1,25 @@ +A function was given both the `ffi_const` and `ffi_pure` attributes. + +Erroneous code example: + +```compile_fail,E0757 +#![feature(ffi_const, ffi_pure)] + +extern "C" { + #[ffi_const] + #[ffi_pure] // error: `#[ffi_const]` function cannot be `#[ffi_pure]` + pub fn square(num: i32) -> i32; +} +``` + +As `const` has a stricter set of requirements than `pure`, remove the `ffi_pure` +attribute: + +``` +#![feature(ffi_const)] + +extern "C" { + #[ffi_const] + pub fn square(num: i32) -> i32; +} +``` diff --git a/src/test/ui/ffi_const2.stderr b/src/test/ui/ffi_const2.stderr index 0b401942c4792..0c30c9dc50c0d 100644 --- a/src/test/ui/ffi_const2.stderr +++ b/src/test/ui/ffi_const2.stderr @@ -6,3 +6,4 @@ LL | #[ffi_pure] error: aborting due to previous error +For more information about this error, try `rustc --explain E0757`. From 3e981e220940c86b57ebab8413d9855af3bbda8c Mon Sep 17 00:00:00 2001 From: Chris Midgley Date: Wed, 21 Jul 2021 14:11:14 +0100 Subject: [PATCH 16/17] docs: add additional links for ffi_pure / ffi_const --- compiler/rustc_error_codes/src/error_codes/E0757.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0757.md b/compiler/rustc_error_codes/src/error_codes/E0757.md index 03ab4e7699dcd..ed7ee1c6fa2cc 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0757.md +++ b/compiler/rustc_error_codes/src/error_codes/E0757.md @@ -12,8 +12,8 @@ extern "C" { } ``` -As `const` has a stricter set of requirements than `pure`, remove the `ffi_pure` -attribute: +As `ffi_const` has a stricter set of requirements than `ffi_pure`, remove the +`ffi_pure` attribute: ``` #![feature(ffi_const)] @@ -23,3 +23,11 @@ extern "C" { pub fn square(num: i32) -> i32; } ``` + +You can get more information about `const` and `pure` in the [GCC documentation +on Common Function Attributes]. The unstable Rust Book has more information +about [`ffi_const`] and [`ffi_pure`]. + +[GCC documentation on Common Function Attributes]: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html +[`ffi_const`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/ffi-const.html +[`ffi_pure`]: https://doc.rust-lang.org/nightly/unstable-book/language-features/ffi-pure.html From 8b75feceddbf4e162524418b72e1f5331de7109b Mon Sep 17 00:00:00 2001 From: Chris Midgley Date: Wed, 21 Jul 2021 14:13:46 +0100 Subject: [PATCH 17/17] docs: normalise wording in line with docs --- compiler/rustc_error_codes/src/error_codes/E0757.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0757.md b/compiler/rustc_error_codes/src/error_codes/E0757.md index ed7ee1c6fa2cc..41b06b23c4f2b 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0757.md +++ b/compiler/rustc_error_codes/src/error_codes/E0757.md @@ -12,7 +12,7 @@ extern "C" { } ``` -As `ffi_const` has a stricter set of requirements than `ffi_pure`, remove the +As `ffi_const` provides stronger guarantees than `ffi_pure`, remove the `ffi_pure` attribute: ```