From 9e5939ad92ae1096e3945bbfdfe81ec515ed0c69 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 20 Aug 2021 16:31:14 +0000 Subject: [PATCH 01/16] Remove a code path that is neither documented nor can I see the reason it existed. Also, no tests fail when turning that arm into an ICE --- compiler/rustc_infer/src/infer/opaque_types.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs index 89c14bcc2ce2b..d9ab4ae1eda29 100644 --- a/compiler/rustc_infer/src/infer/opaque_types.rs +++ b/compiler/rustc_infer/src/infer/opaque_types.rs @@ -461,10 +461,6 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> { if let Some(def_id) = def_id.as_local() { let opaque_hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let parent_def_id = self.infcx.defining_use_anchor; - let def_scope_default = || { - let opaque_parent_hir_id = tcx.hir().get_parent_item(opaque_hir_id); - parent_def_id == tcx.hir().local_def_id(opaque_parent_hir_id) - }; let (in_definition_scope, origin) = match tcx.hir().expect_item(def_id).kind { // Anonymous `impl Trait` @@ -481,7 +477,14 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> { }) => { (may_define_opaque_type(tcx, parent_def_id, opaque_hir_id), origin) } - _ => (def_scope_default(), hir::OpaqueTyOrigin::TyAlias), + ref itemkind => { + span_bug!( + self.value_span, + "weird opaque type: {:#?}, {:#?}", + ty.kind(), + itemkind + ) + } }; if in_definition_scope { let opaque_type_key = From 93564c317ba34b9059197cc4985d32efae147730 Mon Sep 17 00:00:00 2001 From: Esteban Kuber Date: Fri, 3 Dec 2021 23:05:49 +0000 Subject: [PATCH 02/16] Tweak "call this function" suggestion to have smaller span --- compiler/rustc_typeck/src/check/op.rs | 25 ++++++++----------- src/test/ui/fn/fn-compare-mismatch.stderr | 4 +-- src/test/ui/issues/issue-59488.stderr | 16 +++++++++--- ...70724-add_type_neq_err_label-unwrap.stderr | 5 +++- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/compiler/rustc_typeck/src/check/op.rs b/compiler/rustc_typeck/src/check/op.rs index f83209f57a897..4956321eb5cd4 100644 --- a/compiler/rustc_typeck/src/check/op.rs +++ b/compiler/rustc_typeck/src/check/op.rs @@ -492,7 +492,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> bool /* did we suggest to call a function because of missing parentheses? */ { err.span_label(span, ty.to_string()); if let FnDef(def_id, _) = *ty.kind() { - let source_map = self.tcx.sess.source_map(); if !self.tcx.has_typeck_results(def_id) { return false; } @@ -517,20 +516,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .lookup_op_method(fn_sig.output(), &[other_ty], Op::Binary(op, is_assign)) .is_ok() { - if let Ok(snippet) = source_map.span_to_snippet(span) { - let (variable_snippet, applicability) = if !fn_sig.inputs().is_empty() { - (format!("{}( /* arguments */ )", snippet), Applicability::HasPlaceholders) - } else { - (format!("{}()", snippet), Applicability::MaybeIncorrect) - }; + let (variable_snippet, applicability) = if !fn_sig.inputs().is_empty() { + ("( /* arguments */ )".to_string(), Applicability::HasPlaceholders) + } else { + ("()".to_string(), Applicability::MaybeIncorrect) + }; - err.span_suggestion( - span, - "you might have forgotten to call this function", - variable_snippet, - applicability, - ); - } + err.span_suggestion_verbose( + span.shrink_to_hi(), + "you might have forgotten to call this function", + variable_snippet, + applicability, + ); return true; } } diff --git a/src/test/ui/fn/fn-compare-mismatch.stderr b/src/test/ui/fn/fn-compare-mismatch.stderr index 585f556abc8b5..096440225b999 100644 --- a/src/test/ui/fn/fn-compare-mismatch.stderr +++ b/src/test/ui/fn/fn-compare-mismatch.stderr @@ -9,11 +9,11 @@ LL | let x = f == g; help: you might have forgotten to call this function | LL | let x = f() == g; - | ~~~ + | ++ help: you might have forgotten to call this function | LL | let x = f == g(); - | ~~~ + | ++ error[E0308]: mismatched types --> $DIR/fn-compare-mismatch.rs:4:18 diff --git a/src/test/ui/issues/issue-59488.stderr b/src/test/ui/issues/issue-59488.stderr index f739557e001f5..47fd9fdb65472 100644 --- a/src/test/ui/issues/issue-59488.stderr +++ b/src/test/ui/issues/issue-59488.stderr @@ -5,7 +5,11 @@ LL | foo > 12; | --- ^ -- {integer} | | | fn() -> i32 {foo} - | help: you might have forgotten to call this function: `foo()` + | +help: you might have forgotten to call this function + | +LL | foo() > 12; + | ++ error[E0308]: mismatched types --> $DIR/issue-59488.rs:14:11 @@ -23,7 +27,11 @@ LL | bar > 13; | --- ^ -- {integer} | | | fn(i64) -> i64 {bar} - | help: you might have forgotten to call this function: `bar( /* arguments */ )` + | +help: you might have forgotten to call this function + | +LL | bar( /* arguments */ ) > 13; + | +++++++++++++++++++ error[E0308]: mismatched types --> $DIR/issue-59488.rs:18:11 @@ -45,11 +53,11 @@ LL | foo > foo; help: you might have forgotten to call this function | LL | foo() > foo; - | ~~~~~ + | ++ help: you might have forgotten to call this function | LL | foo > foo(); - | ~~~~~ + | ++ error[E0369]: binary operation `>` cannot be applied to type `fn() -> i32 {foo}` --> $DIR/issue-59488.rs:25:9 diff --git a/src/test/ui/issues/issue-70724-add_type_neq_err_label-unwrap.stderr b/src/test/ui/issues/issue-70724-add_type_neq_err_label-unwrap.stderr index cd4cc969200a6..4c11f3544948e 100644 --- a/src/test/ui/issues/issue-70724-add_type_neq_err_label-unwrap.stderr +++ b/src/test/ui/issues/issue-70724-add_type_neq_err_label-unwrap.stderr @@ -6,9 +6,12 @@ LL | assert_eq!(a, 0); | | | fn() -> i32 {a} | {integer} - | help: you might have forgotten to call this function: `*left_val()` | = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: you might have forgotten to call this function + | +LL | if !(*left_val() == *right_val) { + | ++ error[E0308]: mismatched types --> $DIR/issue-70724-add_type_neq_err_label-unwrap.rs:6:5 From 14c619340e4df07c79e60ac051a0796b30fd0acc Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Fri, 19 Nov 2021 18:02:42 -0500 Subject: [PATCH 03/16] Add test for evaluate_obligation: Ok(EvaluatedToOkModuloRegions) ICE Adds the minimial repro test case from #85360. The fix for #85360 was supposed to be #85868 however the repro was resolved in the 2021-07-05 nightly while #85360 didn't land until 2021-09-03. The reason for that is d34a3a401b4e44f289a4d5bf53da83367cbb6aa7 **also** resolves that issue. To test if #85868 actually fixes #85360, I reverted d34a3a401b4e44f289a4d5bf53da83367cbb6aa7 and found that #85868 does indeed resolve #85360. With that question resolved, add a test case to our incremental test suite for the original Ok(EvaluatedToOkModuloRegions) ICE. Thanks to @lqd for helping track this down! --- .../issue-85360-eval-obligation-ice.rs | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 src/test/incremental/issue-85360-eval-obligation-ice.rs diff --git a/src/test/incremental/issue-85360-eval-obligation-ice.rs b/src/test/incremental/issue-85360-eval-obligation-ice.rs new file mode 100644 index 0000000000000..e05da656db603 --- /dev/null +++ b/src/test/incremental/issue-85360-eval-obligation-ice.rs @@ -0,0 +1,117 @@ +// revisions:cfail1 cfail2 +// compile-flags: --crate-type=lib --edition=2021 +// build-pass + +use core::any::Any; +use core::marker::PhantomData; + +struct DerefWrap(T); + +impl core::ops::Deref for DerefWrap { + type Target = T; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +struct Storage { + phantom: PhantomData<(T, D)>, +} + +type ReadStorage = Storage>>; + +pub trait Component { + type Storage; +} + +struct VecStorage; + +struct Pos; + +impl Component for Pos { + type Storage = VecStorage; +} + +struct GenericComp { + _t: T, +} + +impl Component for GenericComp { + type Storage = VecStorage; +} +struct ReadData { + pos_interpdata: ReadStorage>, +} + +trait System { + type SystemData; + + fn run(data: Self::SystemData, any: Box); +} + +struct Sys; + +impl System for Sys { + type SystemData = (ReadData, ReadStorage); + + fn run((data, pos): Self::SystemData, any: Box) { + > as SystemData>::setup(any); + + ParJoin::par_join((&pos, &data.pos_interpdata)); + } +} + +trait ParJoin { + fn par_join(self) + where + Self: Sized, + { + } +} + +impl<'a, T, D> ParJoin for &'a Storage +where + T: Component, + D: core::ops::Deref>, + T::Storage: Sync, +{ +} + +impl ParJoin for (A, B) +where + A: ParJoin, + B: ParJoin, +{ +} + +pub trait SystemData { + fn setup(any: Box); +} + +impl SystemData for ReadStorage +where + T: Component, +{ + fn setup(any: Box) { + let storage: &MaskedStorage = any.downcast_ref().unwrap(); + + >>::cast(&storage); + } +} + +pub struct MaskedStorage { + _inner: T::Storage, +} + +pub unsafe trait CastFrom { + fn cast(t: &T) -> &Self; +} + +unsafe impl CastFrom for dyn Any +where + T: Any + 'static, +{ + fn cast(t: &T) -> &Self { + t + } +} From 98e9b3283e749d278b2ba99f6fb18b2e0e346f82 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Mon, 22 Nov 2021 16:39:32 -0500 Subject: [PATCH 04/16] Add test with `#[rustc_evaluate_where_clauses]` As suggested via reviewer feedback. --- .../issue-85360-eval-obligation-ice.rs | 3 +- .../traits/issue-85360-eval-obligation-ice.rs | 130 ++++++++++++++++++ .../issue-85360-eval-obligation-ice.stderr | 20 +++ 3 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/traits/issue-85360-eval-obligation-ice.rs create mode 100644 src/test/ui/traits/issue-85360-eval-obligation-ice.stderr diff --git a/src/test/incremental/issue-85360-eval-obligation-ice.rs b/src/test/incremental/issue-85360-eval-obligation-ice.rs index e05da656db603..1796c9d197c2b 100644 --- a/src/test/incremental/issue-85360-eval-obligation-ice.rs +++ b/src/test/incremental/issue-85360-eval-obligation-ice.rs @@ -1,5 +1,6 @@ // revisions:cfail1 cfail2 -// compile-flags: --crate-type=lib --edition=2021 +//[cfail1] compile-flags: --crate-type=lib --edition=2021 -Zassert-incr-state=not-loaded +//[cfail2] compile-flags: --crate-type=lib --edition=2021 -Zassert-incr-state=loaded // build-pass use core::any::Any; diff --git a/src/test/ui/traits/issue-85360-eval-obligation-ice.rs b/src/test/ui/traits/issue-85360-eval-obligation-ice.rs new file mode 100644 index 0000000000000..2dbf912d214da --- /dev/null +++ b/src/test/ui/traits/issue-85360-eval-obligation-ice.rs @@ -0,0 +1,130 @@ +// compile-flags: --edition=2021 + +#![feature(rustc_attrs)] + +use core::any::Any; +use core::marker::PhantomData; + +fn main() { + test::>>(make()); + //~^ ERROR evaluate(Binder(TraitPredicate(> as std::marker::Sized>, polarity:Positive), [])) = Ok(EvaluatedToOk) + //~| ERROR evaluate(Binder(TraitPredicate(> as std::marker::Sized>, polarity:Positive), [])) = Ok(EvaluatedToOk) +} + +#[rustc_evaluate_where_clauses] +fn test(_: T) {} + +fn make() -> T { + todo!() +} + +struct DerefWrap(T); + +impl core::ops::Deref for DerefWrap { + type Target = T; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +struct Storage { + phantom: PhantomData<(T, D)>, +} + +type ReadStorage = Storage>>; + +pub trait Component { + type Storage; +} + +struct VecStorage; + +struct Pos; + +impl Component for Pos { + type Storage = VecStorage; +} + +struct GenericComp { + _t: T, +} + +impl Component for GenericComp { + type Storage = VecStorage; +} +struct ReadData { + pos_interpdata: ReadStorage>, +} + +trait System { + type SystemData; + + fn run(data: Self::SystemData, any: Box); +} + +struct Sys; + +impl System for Sys { + type SystemData = (ReadData, ReadStorage); + + fn run((data, pos): Self::SystemData, any: Box) { + > as SystemData>::setup(any); + + ParJoin::par_join((&pos, &data.pos_interpdata)); + } +} + +trait ParJoin { + fn par_join(self) + where + Self: Sized, + { + } +} + +impl<'a, T, D> ParJoin for &'a Storage +where + T: Component, + D: core::ops::Deref>, + T::Storage: Sync, +{ +} + +impl ParJoin for (A, B) +where + A: ParJoin, + B: ParJoin, +{ +} + +pub trait SystemData { + fn setup(any: Box); +} + +impl SystemData for ReadStorage +where + T: Component, +{ + fn setup(any: Box) { + let storage: &MaskedStorage = any.downcast_ref().unwrap(); + + >>::cast(&storage); + } +} + +pub struct MaskedStorage { + _inner: T::Storage, +} + +pub unsafe trait CastFrom { + fn cast(t: &T) -> &Self; +} + +unsafe impl CastFrom for dyn Any +where + T: Any + 'static, +{ + fn cast(t: &T) -> &Self { + t + } +} diff --git a/src/test/ui/traits/issue-85360-eval-obligation-ice.stderr b/src/test/ui/traits/issue-85360-eval-obligation-ice.stderr new file mode 100644 index 0000000000000..c62aba30f05d2 --- /dev/null +++ b/src/test/ui/traits/issue-85360-eval-obligation-ice.stderr @@ -0,0 +1,20 @@ +error: evaluate(Binder(TraitPredicate(> as std::marker::Sized>, polarity:Positive), [])) = Ok(EvaluatedToOk) + --> $DIR/issue-85360-eval-obligation-ice.rs:9:5 + | +LL | test::>>(make()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | fn test(_: T) {} + | - predicate + +error: evaluate(Binder(TraitPredicate(> as std::marker::Sized>, polarity:Positive), [])) = Ok(EvaluatedToOk) + --> $DIR/issue-85360-eval-obligation-ice.rs:9:5 + | +LL | test::>>(make()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | fn test(_: T) {} + | ----- predicate + +error: aborting due to 2 previous errors + From 6fe13f62c1e73e6d102ce3673ad31d7195169560 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Fri, 3 Dec 2021 19:30:10 -0500 Subject: [PATCH 05/16] Add test case that evals to `EvaluatedToOkModuloRegions` --- .../traits/issue-85360-eval-obligation-ice.rs | 13 ++++++++++++ .../issue-85360-eval-obligation-ice.stderr | 20 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/test/ui/traits/issue-85360-eval-obligation-ice.rs b/src/test/ui/traits/issue-85360-eval-obligation-ice.rs index 2dbf912d214da..19131684a481b 100644 --- a/src/test/ui/traits/issue-85360-eval-obligation-ice.rs +++ b/src/test/ui/traits/issue-85360-eval-obligation-ice.rs @@ -9,6 +9,10 @@ fn main() { test::>>(make()); //~^ ERROR evaluate(Binder(TraitPredicate(> as std::marker::Sized>, polarity:Positive), [])) = Ok(EvaluatedToOk) //~| ERROR evaluate(Binder(TraitPredicate(> as std::marker::Sized>, polarity:Positive), [])) = Ok(EvaluatedToOk) + + test::>>(make()); + //~^ ERROR evaluate(Binder(TraitPredicate(> as std::marker::Sized>, polarity:Positive), [])) = Ok(EvaluatedToOkModuloRegions) + //~| ERROR evaluate(Binder(TraitPredicate(> as std::marker::Sized>, polarity:Positive), [])) = Ok(EvaluatedToOkModuloRegions) } #[rustc_evaluate_where_clauses] @@ -52,6 +56,15 @@ struct GenericComp { impl Component for GenericComp { type Storage = VecStorage; } + +struct GenericComp2 { + _t: T, +} + +impl Component for GenericComp2 where for<'a> &'a bool: 'a { + type Storage = VecStorage; +} + struct ReadData { pos_interpdata: ReadStorage>, } diff --git a/src/test/ui/traits/issue-85360-eval-obligation-ice.stderr b/src/test/ui/traits/issue-85360-eval-obligation-ice.stderr index c62aba30f05d2..ebf977dd68051 100644 --- a/src/test/ui/traits/issue-85360-eval-obligation-ice.stderr +++ b/src/test/ui/traits/issue-85360-eval-obligation-ice.stderr @@ -16,5 +16,23 @@ LL | test::>>(make()); LL | fn test(_: T) {} | ----- predicate -error: aborting due to 2 previous errors +error: evaluate(Binder(TraitPredicate(> as std::marker::Sized>, polarity:Positive), [])) = Ok(EvaluatedToOkModuloRegions) + --> $DIR/issue-85360-eval-obligation-ice.rs:13:5 + | +LL | test::>>(make()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | fn test(_: T) {} + | - predicate + +error: evaluate(Binder(TraitPredicate(> as std::marker::Sized>, polarity:Positive), [])) = Ok(EvaluatedToOkModuloRegions) + --> $DIR/issue-85360-eval-obligation-ice.rs:13:5 + | +LL | test::>>(make()); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | fn test(_: T) {} + | ----- predicate + +error: aborting due to 4 previous errors From aa3370c92be12d04db6a99c92044c56d453f94df Mon Sep 17 00:00:00 2001 From: TennyZhuang Date: Sun, 5 Dec 2021 14:19:44 +0800 Subject: [PATCH 06/16] doc: suggest try_reserve in try_reserve_exact Signed-off-by: TennyZhuang --- library/alloc/src/collections/vec_deque/mod.rs | 4 ++-- library/alloc/src/string.rs | 4 ++-- library/alloc/src/vec/mod.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 42eae6a54b531..702d97858eb45 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -720,9 +720,9 @@ impl VecDeque { /// /// Note that the allocator may give the collection more space than it /// requests. Therefore, capacity can not be relied upon to be precisely - /// minimal. Prefer [`reserve`] if future insertions are expected. + /// minimal. Prefer [`try_reserve`] if future insertions are expected. /// - /// [`reserve`]: VecDeque::reserve + /// [`try_reserve`]: VecDeque::try_reserve /// /// # Errors /// diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index 4f926d99c6dbc..b151842458d35 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -1044,9 +1044,9 @@ impl String { /// /// Note that the allocator may give the collection more space than it /// requests. Therefore, capacity can not be relied upon to be precisely - /// minimal. Prefer [`reserve`] if future insertions are expected. + /// minimal. Prefer [`try_reserve`] if future insertions are expected. /// - /// [`reserve`]: String::reserve + /// [`try_reserve`]: String::try_reserve /// /// # Errors /// diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 88bde6e8ce481..f1b70fa280214 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -881,9 +881,9 @@ impl Vec { /// /// Note that the allocator may give the collection more space than it /// requests. Therefore, capacity can not be relied upon to be precisely - /// minimal. Prefer [`reserve`] if future insertions are expected. + /// minimal. Prefer [`try_reserve`] if future insertions are expected. /// - /// [`reserve`]: Vec::reserve + /// [`try_reserve`]: Vec::try_reserve /// /// # Errors /// From a9f14c18fa1fe455aa9ea3efb74335653d51a884 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 5 Dec 2021 11:21:24 -0800 Subject: [PATCH 07/16] Add pretty printer test for async blocks Currently fails with: ---- [pretty] pretty/async.rs stdout ---- error: pretty-printed source does not match expected source expected: ------------------------------------------ // pp-exact // pretty-compare-only // edition:2021 async fn f() { let first = async { 1 }; let second = async move { 2 }; join(first, second).await } ------------------------------------------ actual: ------------------------------------------ // pp-exact // pretty-compare-only // edition:2021 async fn f() { let first = async { 1 }; let second = async move { 2 }; join(first, second).await } ------------------------------------------ diff: ------------------------------------------ 3 // edition:2021 4 5 async fn f() { - let first = async { 1 }; - let second = async move { 2 }; + let first = async { 1 }; + let second = async move { 2 }; 8 join(first, second).await 9 } 10 --- src/test/pretty/async.rs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/test/pretty/async.rs diff --git a/src/test/pretty/async.rs b/src/test/pretty/async.rs new file mode 100644 index 0000000000000..573e79bffd7ef --- /dev/null +++ b/src/test/pretty/async.rs @@ -0,0 +1,9 @@ +// pp-exact +// pretty-compare-only +// edition:2021 + +async fn f() { + let first = async { 1 }; + let second = async move { 2 }; + join(first, second).await +} From 33c29a3ad36621bf812fd8af0adceb16188f3624 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 5 Dec 2021 10:53:21 -0800 Subject: [PATCH 08/16] Pretty print async block without redundant space --- compiler/rustc_ast_pretty/src/pprust/state.rs | 1 - src/test/ui/async-await/issues/issue-54752-async-block.rs | 2 +- .../ui/async-await/issues/issue-54752-async-block.stderr | 8 ++++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 593dca1b405d8..096406ad0e7b2 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -2068,7 +2068,6 @@ impl<'a> State<'a> { ast::ExprKind::Async(capture_clause, _, ref blk) => { self.word_nbsp("async"); self.print_capture_clause(capture_clause); - self.s.space(); // cbox/ibox in analogy to the `ExprKind::Block` arm above self.cbox(INDENT_UNIT); self.ibox(0); diff --git a/src/test/ui/async-await/issues/issue-54752-async-block.rs b/src/test/ui/async-await/issues/issue-54752-async-block.rs index c2840d7386f98..a8165ae6c3269 100644 --- a/src/test/ui/async-await/issues/issue-54752-async-block.rs +++ b/src/test/ui/async-await/issues/issue-54752-async-block.rs @@ -3,5 +3,5 @@ // edition:2018 // pp-exact -fn main() { let _a = (async { }); } +fn main() { let _a = (async { }); } //~^ WARNING unnecessary parentheses around assigned value diff --git a/src/test/ui/async-await/issues/issue-54752-async-block.stderr b/src/test/ui/async-await/issues/issue-54752-async-block.stderr index 0aea56ddb702b..e3ed0b53356d4 100644 --- a/src/test/ui/async-await/issues/issue-54752-async-block.stderr +++ b/src/test/ui/async-await/issues/issue-54752-async-block.stderr @@ -1,14 +1,14 @@ warning: unnecessary parentheses around assigned value --> $DIR/issue-54752-async-block.rs:6:22 | -LL | fn main() { let _a = (async { }); } - | ^ ^ +LL | fn main() { let _a = (async { }); } + | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | -LL - fn main() { let _a = (async { }); } -LL + fn main() { let _a = async { }; } +LL - fn main() { let _a = (async { }); } +LL + fn main() { let _a = async { }; } | warning: 1 warning emitted From a30f96311aa2c0c1614132b1d5dd07bcfa9267fe Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 28 Nov 2021 15:34:53 -0800 Subject: [PATCH 09/16] Add `array::IntoIter::{empty, from_raw_parts}` `array::IntoIter` has a bunch of really handy logic for dealing with partial arrays, but it's currently hamstrung by only being creatable from a fully-initialized array. This PR adds two new constructors: - a safe & const `empty`, since `[].into_iter()` gives ``, not ``. - an unsafe `from_raw_parts`, to allow experimentation with new uses. (Slice & vec iterators don't need `from_raw_parts` because you `from_raw_parts` the slice or vec instead, but there's no useful way to made a `<[T; N]>::from_raw_parts`, so I think this is a reasonable place to have one.) --- library/core/src/array/iter.rs | 129 +++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index fe7b3576e2f5f..bebf9aa28fae3 100644 --- a/library/core/src/array/iter.rs +++ b/library/core/src/array/iter.rs @@ -84,6 +84,135 @@ impl IntoIter { IntoIterator::into_iter(array) } + /// Creates an iterator over the elements in a partially-initialized buffer. + /// + /// If you have a fully-initialized array, then use [`IntoIterator`]. + /// But this is useful for returning partial results from unsafe code. + /// + /// # Safety + /// + /// - The `buffer[initialized]` elements must all be initialized. + /// - The range must be canonical, with `initialized.start <= initialized.end`. + /// - The range must in in-bounds for the buffer, with `initialized.end <= N`. + /// (Like how indexing `[0][100..100]` fails despite the range being empty.) + /// + /// It's sound to have more elements initialized than mentioned, though that + /// will most likely result in them being leaked. + /// + /// # Examples + /// + /// ``` + /// #![feature(array_into_iter_constructors)] + /// + /// #![feature(maybe_uninit_array_assume_init)] + /// #![feature(maybe_uninit_uninit_array)] + /// use std::array::IntoIter; + /// use std::mem::MaybeUninit; + /// + /// # // Hi! Thanks for reading the code. This is restricted to `Copy` because + /// # // otherwise it could leak. A fully-general version this would need a drop + /// # // guard to handle panics from the iterator, but this works for an example. + /// fn next_chunk( + /// it: &mut impl Iterator, + /// ) -> Result<[T; N], IntoIter> { + /// let mut buffer = MaybeUninit::uninit_array(); + /// let mut i = 0; + /// while i < N { + /// match it.next() { + /// Some(x) => { + /// buffer[i].write(x); + /// i += 1; + /// } + /// None => { + /// // SAFETY: We've initialized the first `i` items + /// unsafe { + /// return Err(IntoIter::from_raw_parts(buffer, 0..i)); + /// } + /// } + /// } + /// } + /// + /// // SAFETY: We've initialized all N items + /// unsafe { Ok(MaybeUninit::array_assume_init(buffer)) } + /// } + /// + /// let r: [_; 4] = next_chunk(&mut (10..16)).unwrap(); + /// assert_eq!(r, [10, 11, 12, 13]); + /// let r: IntoIter<_, 40> = next_chunk(&mut (10..16)).unwrap_err(); + /// assert_eq!(r.collect::>(), vec![10, 11, 12, 13, 14, 15]); + /// ``` + #[unstable(feature = "array_into_iter_constructors", issue = "88888888")] + #[rustc_const_unstable(feature = "array_into_iter_constructors_const", issue = "88888888")] + pub const unsafe fn from_raw_parts( + buffer: [MaybeUninit; N], + initialized: Range, + ) -> Self { + Self { data: buffer, alive: initialized } + } + + /// Creates an iterator over `T` which returns no elements. + /// + /// If you just need an empty iterator, then use + /// [`iter::empty()`](crate::iter::empty) instead. + /// And if you need an empty array, use `[]`. + /// + /// But this is useful when you need an `array::IntoIter` *specifically*. + /// + /// # Examples + /// + /// ``` + /// #![feature(array_into_iter_constructors)] + /// use std::array::IntoIter; + /// + /// let empty = IntoIter::::empty(); + /// assert_eq!(empty.len(), 0); + /// assert_eq!(empty.as_slice(), &[]); + /// + /// let empty = IntoIter::::empty(); + /// assert_eq!(empty.len(), 0); + /// ``` + /// + /// `[1, 2].into_iter()` and `[].into_iter()` have different types + /// ```should_fail + /// #![feature(array_into_iter_constructors)] + /// use std::array::IntoIter; + /// + /// # // FIXME: use `.into_iter()` once the doc tests are in edition2021 + /// pub fn get_bytes(b: bool) -> IntoIter { + /// if b { + /// IntoIter::new([1, 2, 3, 4]) + /// } else { + /// IntoIter::new([]) // error[E0308]: mismatched types + /// } + /// } + /// ``` + /// + /// But using this method you can get an empty iterator of appropriate size: + /// ``` + /// #![feature(array_into_iter_constructors)] + /// use std::array::IntoIter; + /// + /// pub fn get_bytes(b: bool) -> IntoIter { + /// if b { + /// IntoIter::new([1, 2, 3, 4]) + /// } else { + /// IntoIter::empty() + /// } + /// } + /// + /// assert_eq!(get_bytes(true).collect::>(), vec![1, 2, 3, 4]); + /// assert_eq!(get_bytes(false).collect::>(), vec![]); + /// ``` + #[unstable(feature = "array_into_iter_constructors", issue = "88888888")] + pub fn empty() -> Self { + let buffer = MaybeUninit::uninit_array(); + let initialized = 0..0; + + // SAFETY: We're telling it that none of the elements are initialized, + // which is trivially true. And ∀N: usize, 0 <= N. + unsafe { Self::from_raw_parts(buffer, initialized) } + } + /// Returns an immutable slice of all elements that have not been yielded /// yet. #[stable(feature = "array_value_iter", since = "1.51.0")] From ef7c833c203e3de3785f8cbea3006da6237f730e Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 28 Nov 2021 19:53:32 -0800 Subject: [PATCH 10/16] Move the doc test to edition2021 --- library/core/src/array/iter.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index bebf9aa28fae3..9d4cb9284a5f4 100644 --- a/library/core/src/array/iter.rs +++ b/library/core/src/array/iter.rs @@ -173,28 +173,27 @@ impl IntoIter { /// ``` /// /// `[1, 2].into_iter()` and `[].into_iter()` have different types - /// ```should_fail + /// ```should_fail,edition2021 /// #![feature(array_into_iter_constructors)] /// use std::array::IntoIter; /// - /// # // FIXME: use `.into_iter()` once the doc tests are in edition2021 /// pub fn get_bytes(b: bool) -> IntoIter { /// if b { - /// IntoIter::new([1, 2, 3, 4]) + /// [1, 2, 3, 4].into_iter() /// } else { - /// IntoIter::new([]) // error[E0308]: mismatched types + /// [].into_iter() // error[E0308]: mismatched types /// } /// } /// ``` /// /// But using this method you can get an empty iterator of appropriate size: - /// ``` + /// ```edition2021 /// #![feature(array_into_iter_constructors)] /// use std::array::IntoIter; /// /// pub fn get_bytes(b: bool) -> IntoIter { /// if b { - /// IntoIter::new([1, 2, 3, 4]) + /// [1, 2, 3, 4].into_iter() /// } else { /// IntoIter::empty() /// } From 0b90204bc820ceafda004a5e4baf9f323b70d790 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Mon, 6 Dec 2021 01:12:59 -0800 Subject: [PATCH 11/16] Add tracking issue; make `empty` const too (unstably) --- library/core/src/array/iter.rs | 9 +++++---- library/core/src/lib.rs | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index 9d4cb9284a5f4..de3b768538527 100644 --- a/library/core/src/array/iter.rs +++ b/library/core/src/array/iter.rs @@ -141,8 +141,8 @@ impl IntoIter { /// let r: IntoIter<_, 40> = next_chunk(&mut (10..16)).unwrap_err(); /// assert_eq!(r.collect::>(), vec![10, 11, 12, 13, 14, 15]); /// ``` - #[unstable(feature = "array_into_iter_constructors", issue = "88888888")] - #[rustc_const_unstable(feature = "array_into_iter_constructors_const", issue = "88888888")] + #[unstable(feature = "array_into_iter_constructors", issue = "91583")] + #[rustc_const_unstable(feature = "const_array_into_iter_constructors", issue = "91583")] pub const unsafe fn from_raw_parts( buffer: [MaybeUninit; N], initialized: Range, @@ -202,8 +202,9 @@ impl IntoIter { /// assert_eq!(get_bytes(true).collect::>(), vec![1, 2, 3, 4]); /// assert_eq!(get_bytes(false).collect::>(), vec![]); /// ``` - #[unstable(feature = "array_into_iter_constructors", issue = "88888888")] - pub fn empty() -> Self { + #[unstable(feature = "array_into_iter_constructors", issue = "91583")] + #[rustc_const_unstable(feature = "const_array_into_iter_constructors", issue = "91583")] + pub const fn empty() -> Self { let buffer = MaybeUninit::uninit_array(); let initialized = 0..0; diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index b0f9368b0c068..78383b54c5d1e 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -101,6 +101,7 @@ #![feature(const_align_of_val)] #![feature(const_alloc_layout)] #![feature(const_arguments_as_str)] +#![feature(const_array_into_iter_constructors)] #![feature(const_bigint_helper_methods)] #![feature(const_caller_location)] #![feature(const_cell_into_inner)] @@ -138,6 +139,7 @@ #![feature(const_type_name)] #![feature(const_default_impls)] #![feature(duration_consts_float)] +#![feature(maybe_uninit_uninit_array)] #![feature(ptr_metadata)] #![feature(slice_ptr_get)] #![feature(str_internals)] From a0fb992433872f2c55c538cdaf7222364a921adb Mon Sep 17 00:00:00 2001 From: threadexception Date: Sun, 28 Nov 2021 10:20:53 +0100 Subject: [PATCH 12/16] Fix AnonConst ICE Add test Apply suggestions Switch to match Apply cargofmt --- compiler/rustc_typeck/src/collect/type_of.rs | 15 ++++++++--- src/test/ui/typeck/issue-91267.rs | 6 +++++ src/test/ui/typeck/issue-91267.stderr | 27 ++++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/typeck/issue-91267.rs create mode 100644 src/test/ui/typeck/issue-91267.stderr diff --git a/compiler/rustc_typeck/src/collect/type_of.rs b/compiler/rustc_typeck/src/collect/type_of.rs index 04a68250ced0c..b684844744de3 100644 --- a/compiler/rustc_typeck/src/collect/type_of.rs +++ b/compiler/rustc_typeck/src/collect/type_of.rs @@ -172,7 +172,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option< // We've encountered an `AnonConst` in some path, so we need to // figure out which generic parameter it corresponds to and return // the relevant type. - let (arg_index, segment) = path + let filtered = path .segments .iter() .filter_map(|seg| seg.args.map(|args| (args.args, seg))) @@ -181,10 +181,17 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option< .filter(|arg| arg.is_const()) .position(|arg| arg.id() == hir_id) .map(|index| (index, seg)) - }) - .unwrap_or_else(|| { - bug!("no arg matching AnonConst in path"); }); + let (arg_index, segment) = match filtered { + None => { + tcx.sess.delay_span_bug( + tcx.def_span(def_id), + "no arg matching AnonConst in path", + ); + return None; + } + Some(inner) => inner, + }; // Try to use the segment resolution if it is valid, otherwise we // default to the path resolution. diff --git a/src/test/ui/typeck/issue-91267.rs b/src/test/ui/typeck/issue-91267.rs new file mode 100644 index 0000000000000..f5a37e9cb86f8 --- /dev/null +++ b/src/test/ui/typeck/issue-91267.rs @@ -0,0 +1,6 @@ +fn main() { + 0: u8=e> + //~^ ERROR: cannot find type `e` in this scope [E0412] + //~| ERROR: associated type bindings are not allowed here [E0229] + //~| ERROR: mismatched types [E0308] +} diff --git a/src/test/ui/typeck/issue-91267.stderr b/src/test/ui/typeck/issue-91267.stderr new file mode 100644 index 0000000000000..aac00b9b6a941 --- /dev/null +++ b/src/test/ui/typeck/issue-91267.stderr @@ -0,0 +1,27 @@ +error[E0412]: cannot find type `e` in this scope + --> $DIR/issue-91267.rs:2:16 + | +LL | 0: u8=e> + | ^ + | | + | not found in this scope + | help: maybe you meant to write an assignment here: `let e` + +error[E0229]: associated type bindings are not allowed here + --> $DIR/issue-91267.rs:2:11 + | +LL | 0: u8=e> + | ^^^^^^ associated type not allowed here + +error[E0308]: mismatched types + --> $DIR/issue-91267.rs:2:5 + | +LL | fn main() { + | - expected `()` because of default return type +LL | 0: u8=e> + | ^^^^^^^^^^^^^ expected `()`, found `u8` + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0229, E0308, E0412. +For more information about an error, try `rustc --explain E0229`. From 6a17ee6d4125c0c35147b16ebcf54e34f0cdc87a Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 29 Jul 2021 23:23:17 -0700 Subject: [PATCH 13/16] Recommend fix `count()` -> `len()` on slices Fixes #87302 --- compiler/rustc_span/src/symbol.rs | 1 + .../rustc_typeck/src/check/method/suggest.rs | 26 ++++++++++++-- src/test/ui/suggestions/count2len.rs | 8 +++++ src/test/ui/suggestions/count2len.stderr | 36 +++++++++++++++++++ 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/suggestions/count2len.rs create mode 100644 src/test/ui/suggestions/count2len.stderr diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 0d556b5eda609..adce8da91a3a8 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -496,6 +496,7 @@ symbols! { core_panic_macro, cosf32, cosf64, + count, cr, crate_id, crate_in_paths, diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index ca174ed5e8497..ad38885dbd8bd 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -67,6 +67,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } + fn is_slice_ty(&self, ty: Ty<'tcx>, span: Span) -> bool { + self.autoderef(span, ty).any(|(ty, _)| matches!(ty.kind(), ty::Slice(..) | ty::Array(..))) + } + pub fn report_method_error( &self, mut span: Span, @@ -691,7 +695,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut restrict_type_params = false; let mut unsatisfied_bounds = false; - if !unsatisfied_predicates.is_empty() { + if item_name.name == sym::count && self.is_slice_ty(actual, span) { + let msg = "consider using `len` instead"; + if let SelfSource::MethodCall(_expr) = source { + err.span_suggestion_short( + span, + msg, + String::from("len"), + Applicability::MachineApplicable, + ); + } else { + err.span_label(span, msg); + } + if let Some(iterator_trait) = self.tcx.get_diagnostic_item(sym::Iterator) { + let iterator_trait = self.tcx.def_path_str(iterator_trait); + err.note(&format!("`count` is defined on `{iterator_trait}`, which `{actual}` does not implement")); + } + } else if !unsatisfied_predicates.is_empty() { let def_span = |def_id| { self.tcx.sess.source_map().guess_head_span(self.tcx.def_span(def_id)) }; @@ -990,9 +1010,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - let mut fallback_span = true; - let msg = "remove this method call"; if item_name.name == sym::as_str && actual.peel_refs().is_str() { + let msg = "remove this method call"; + let mut fallback_span = true; if let SelfSource::MethodCall(expr) = source { let call_expr = self.tcx.hir().expect_expr(self.tcx.hir().get_parent_node(expr.hir_id)); diff --git a/src/test/ui/suggestions/count2len.rs b/src/test/ui/suggestions/count2len.rs new file mode 100644 index 0000000000000..f11a789efbc5b --- /dev/null +++ b/src/test/ui/suggestions/count2len.rs @@ -0,0 +1,8 @@ +fn main() { + let slice = [1,2,3,4]; + let vec = vec![1,2,3,4]; + + slice.count(); //~ERROR: E0599 + vec.count(); //~ERROR: E0599 + vec.as_slice().count(); //~ERROR: E0599 +} diff --git a/src/test/ui/suggestions/count2len.stderr b/src/test/ui/suggestions/count2len.stderr new file mode 100644 index 0000000000000..6394a84dd47e1 --- /dev/null +++ b/src/test/ui/suggestions/count2len.stderr @@ -0,0 +1,36 @@ +error[E0599]: no method named `count` found for array `[{integer}; 4]` in the current scope + --> $DIR/count2len.rs:5:11 + | +LL | slice.count(); + | ^^^^^ + | | + | method cannot be called on `[{integer}; 4]` due to unsatisfied trait bounds + | help: consider using `len` instead + | + = note: `count` is defined on `Iterator`, which `[{integer}; 4]` does not implement + +error[E0599]: no method named `count` found for struct `Vec<{integer}>` in the current scope + --> $DIR/count2len.rs:6:9 + | +LL | vec.count(); + | ^^^^^ + | | + | method cannot be called on `Vec<{integer}>` due to unsatisfied trait bounds + | help: consider using `len` instead + | + = note: `count` is defined on `Iterator`, which `Vec<{integer}>` does not implement + +error[E0599]: no method named `count` found for reference `&[{integer}]` in the current scope + --> $DIR/count2len.rs:7:20 + | +LL | vec.as_slice().count(); + | ^^^^^ + | | + | method cannot be called on `&[{integer}]` due to unsatisfied trait bounds + | help: consider using `len` instead + | + = note: `count` is defined on `Iterator`, which `&[{integer}]` does not implement + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0599`. From 880eb59886eabc32a8c5d4da5e2d039d1839ce86 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 6 Dec 2021 20:45:37 -0800 Subject: [PATCH 14/16] Update books --- src/doc/book | 2 +- src/doc/edition-guide | 2 +- src/doc/nomicon | 2 +- src/doc/reference | 2 +- src/doc/rust-by-example | 2 +- src/doc/rustc-dev-guide | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/doc/book b/src/doc/book index a5e0c5b2c5f90..5f9358faeb1f4 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit a5e0c5b2c5f9054be3b961aea2c7edfeea591de8 +Subproject commit 5f9358faeb1f46e19b8a23a21e79fd7fe150491e diff --git a/src/doc/edition-guide b/src/doc/edition-guide index 8e0ec8c77d8b2..beea0a3cdc388 160000 --- a/src/doc/edition-guide +++ b/src/doc/edition-guide @@ -1 +1 @@ -Subproject commit 8e0ec8c77d8b28b86159fdee9d33a758225ecf9c +Subproject commit beea0a3cdc3885375342fd010f9ad658e6a5e09a diff --git a/src/doc/nomicon b/src/doc/nomicon index c6b4bf831e9a4..49681ea4a9fa8 160000 --- a/src/doc/nomicon +++ b/src/doc/nomicon @@ -1 +1 @@ -Subproject commit c6b4bf831e9a40aec34f53067d20634839a6778b +Subproject commit 49681ea4a9fa81173dbe9ffed74b4d4a35eae9e3 diff --git a/src/doc/reference b/src/doc/reference index c0f222da23568..954f3d441ad88 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit c0f222da23568477155991d391c9ce918e381351 +Subproject commit 954f3d441ad880737a13e241108f791a4d2a38cd diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index 43f82530210b8..1ca6a7bd1d73e 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit 43f82530210b83cf888282b207ed13d5893da9b2 +Subproject commit 1ca6a7bd1d73edc4a3e6c7d6a40f5d4b66c1e517 diff --git a/src/doc/rustc-dev-guide b/src/doc/rustc-dev-guide index a2fc9635029c0..a374e7d8bb6b7 160000 --- a/src/doc/rustc-dev-guide +++ b/src/doc/rustc-dev-guide @@ -1 +1 @@ -Subproject commit a2fc9635029c04e692474965a6606f8e286d539a +Subproject commit a374e7d8bb6b79de45b92295d06b4ac0ef35bc09 From f50070b13a6c4f6c5f72a404793ac4b6be65d0b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Tue, 7 Dec 2021 07:46:50 +0200 Subject: [PATCH 15/16] :arrow_up: rust-analyzer --- src/tools/rust-analyzer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/rust-analyzer b/src/tools/rust-analyzer index d9b2291f546ab..7d6fcbc0be215 160000 --- a/src/tools/rust-analyzer +++ b/src/tools/rust-analyzer @@ -1 +1 @@ -Subproject commit d9b2291f546abc77d24499339a72a89127464b95 +Subproject commit 7d6fcbc0be2151bfa85ec146545b42d8be2fb28c From 9b86c5998c5b5b274b21651334a320aecc516dfc Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Mon, 6 Dec 2021 22:59:04 -0800 Subject: [PATCH 16/16] s/from_raw_parts/new_unchecked/ --- library/core/src/array/iter.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index de3b768538527..0dc277785e825 100644 --- a/library/core/src/array/iter.rs +++ b/library/core/src/array/iter.rs @@ -126,7 +126,7 @@ impl IntoIter { /// None => { /// // SAFETY: We've initialized the first `i` items /// unsafe { - /// return Err(IntoIter::from_raw_parts(buffer, 0..i)); + /// return Err(IntoIter::new_unchecked(buffer, 0..i)); /// } /// } /// } @@ -143,7 +143,7 @@ impl IntoIter { /// ``` #[unstable(feature = "array_into_iter_constructors", issue = "91583")] #[rustc_const_unstable(feature = "const_array_into_iter_constructors", issue = "91583")] - pub const unsafe fn from_raw_parts( + pub const unsafe fn new_unchecked( buffer: [MaybeUninit; N], initialized: Range, ) -> Self { @@ -210,7 +210,7 @@ impl IntoIter { // SAFETY: We're telling it that none of the elements are initialized, // which is trivially true. And ∀N: usize, 0 <= N. - unsafe { Self::from_raw_parts(buffer, initialized) } + unsafe { Self::new_unchecked(buffer, initialized) } } /// Returns an immutable slice of all elements that have not been yielded