/// Allows `async || body` closures.
(active, async_closure, "1.37.0", Some(62290), None),
- /// Allows `[x; N]` where `x` is a constant (RFC 2203).
- (active, const_in_array_repeat_expressions, "1.37.0", Some(49147), None),
-
/// Allows `impl Trait` to be used inside type aliases (RFC 2515).
(active, type_alias_impl_trait, "1.38.0", Some(63063), None),
(removed, extern_in_paths, "1.33.0", Some(55600), None,
Some("subsumed by `::foo::bar` paths")),
(removed, quote, "1.33.0", Some(29601), None, None),
+ /// Allows `[x; N]` where `x` is a constant (RFC 2203).
+ (removed, const_in_array_repeat_expressions, "1.37.0", Some(49147), None,
+ Some("removed due to causing promotable bugs")),
/// Allows using `#[unsafe_destructor_blind_to_params]` (RFC 1238).
(removed, dropck_parametricity, "1.38.0", Some(28498), None, None),
(removed, await_macro, "1.38.0", Some(50547), None,
/// Inline asm operand type must be `Sized`.
InlineAsmSized,
/// `[T, ..n]` implies that `T` must be `Copy`.
- /// If `true`, suggest `const_in_array_repeat_expressions` feature flag.
- RepeatVec(bool),
+ RepeatVec,
/// Types of fields (other than the last, except for packed structs) in a struct must be sized.
FieldSized {
use crate::dataflow::impls::MaybeInitializedPlaces;
use crate::dataflow::move_paths::MoveData;
use crate::dataflow::ResultsCursor;
-use crate::transform::{
- check_consts::ConstCx,
- promote_consts::should_suggest_const_in_array_repeat_expressions_attribute,
-};
use crate::borrow_check::{
borrow_set::BorrowSet,
let span = body.source_info(location).span;
let ty = operand.ty(body, tcx);
if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span) {
- let ccx = ConstCx::new_with_param_env(tcx, body, self.param_env);
- // To determine if `const_in_array_repeat_expressions` feature gate should
- // be mentioned, need to check if the rvalue is promotable.
- let should_suggest =
- should_suggest_const_in_array_repeat_expressions_attribute(
- &ccx, operand,
- );
- debug!("check_rvalue: should_suggest={:?}", should_suggest);
-
let def_id = body.source.def_id().expect_local();
self.infcx.report_selection_error(
&traits::Obligation::new(
ObligationCause::new(
span,
self.tcx().hir().local_def_id_to_hir_id(def_id),
- traits::ObligationCauseCode::RepeatVec(should_suggest),
+ traits::ObligationCauseCode::RepeatVec,
),
self.param_env,
ty::Binder::bind(ty::TraitRef::new(
};
// Check the qualifs of the value of `const` items.
- if let ty::ConstKind::Unevaluated(def, _, None) = constant.literal.val {
+ if let ty::ConstKind::Unevaluated(def, _, promoted) = constant.literal.val {
+ assert!(promoted.is_none());
// Don't peek inside trait associated constants.
if cx.tcx.trait_of_item(def.did).is_none() {
let qualifs = if let Some((did, param_did)) = def.as_const_arg() {
/// Borrow of a constant temporary, candidate for lifetime extension.
Ref(Location),
- /// Promotion of the `x` in `[x; 32]`.
- Repeat(Location),
-
/// Currently applied to function calls where the callee has the unstable
/// `#[rustc_args_required_const]` attribute as well as the SIMD shuffle
/// intrinsic. The intrinsic requires the arguments are indeed constant and
/// Returns `true` if we should use the "explicit" rules for promotability for this `Candidate`.
fn forces_explicit_promotion(&self) -> bool {
match self {
- Candidate::Ref(_) | Candidate::Repeat(_) => false,
+ Candidate::Ref(_) => false,
Candidate::Argument { .. } | Candidate::InlineAsm { .. } => true,
}
}
fn source_info(&self, body: &Body<'_>) -> SourceInfo {
match self {
- Candidate::Ref(location) | Candidate::Repeat(location) => *body.source_info(*location),
+ Candidate::Ref(location) => *body.source_info(*location),
Candidate::Argument { bb, .. } | Candidate::InlineAsm { bb, .. } => {
*body.source_info(body.terminator_loc(*bb))
}
Rvalue::Ref(..) => {
self.candidates.push(Candidate::Ref(location));
}
- Rvalue::Repeat(..) if self.ccx.tcx.features().const_in_array_repeat_expressions => {
- // FIXME(#49147) only promote the element when it isn't `Copy`
- // (so that code that can copy it at runtime is unaffected).
- self.candidates.push(Candidate::Repeat(location));
- }
_ => {}
}
}
_ => bug!(),
}
}
- Candidate::Repeat(loc) => {
- assert!(!self.explicit);
-
- let statement = &self.body[loc.block].statements[loc.statement_index];
- match &statement.kind {
- StatementKind::Assign(box (_, Rvalue::Repeat(ref operand, _))) => {
- if !self.tcx.features().const_in_array_repeat_expressions {
- return Err(Unpromotable);
- }
-
- self.validate_operand(operand)
- }
- _ => bug!(),
- }
- }
Candidate::Argument { bb, index } => {
assert!(self.explicit);
_ => bug!(),
}
}
- Candidate::Repeat(loc) => {
- let statement = &mut blocks[loc.block].statements[loc.statement_index];
- match statement.kind {
- StatementKind::Assign(box (_, Rvalue::Repeat(ref mut operand, _))) => {
- let ty = operand.ty(local_decls, self.tcx);
- let span = statement.source_info.span;
-
- Rvalue::Use(mem::replace(operand, promoted_operand(ty, span)))
- }
- _ => bug!(),
- }
- }
Candidate::Argument { bb, index } => {
let terminator = blocks[bb].terminator_mut();
match terminator.kind {
let mut extra_statements = vec![];
for candidate in candidates.into_iter().rev() {
match candidate {
- Candidate::Repeat(Location { block, statement_index })
- | Candidate::Ref(Location { block, statement_index }) => {
+ Candidate::Ref(Location { block, statement_index }) => {
if let StatementKind::Assign(box (place, _)) =
&body[block].statements[statement_index].kind
{
promotions
}
-
-/// This function returns `true` if the `const_in_array_repeat_expressions` feature attribute should
-/// be suggested. This function is probably quite expensive, it shouldn't be run in the happy path.
-/// Feature attribute should be suggested if `operand` can be promoted and the feature is not
-/// enabled.
-crate fn should_suggest_const_in_array_repeat_expressions_attribute<'tcx>(
- ccx: &ConstCx<'_, 'tcx>,
- operand: &Operand<'tcx>,
-) -> bool {
- let mut rpo = traversal::reverse_postorder(&ccx.body);
- let (temps, _) = collect_temps_and_candidates(&ccx, &mut rpo);
- let validator = Validator { ccx, temps: &temps, explicit: false };
-
- let should_promote = validator.validate_operand(operand).is_ok();
- let feature_flag = validator.ccx.tcx.features().const_in_array_repeat_expressions;
- debug!(
- "should_suggest_const_in_array_repeat_expressions_flag: def_id={:?} \
- should_promote={:?} feature_flag={:?}",
- validator.ccx.def_id(),
- should_promote,
- feature_flag
- );
- should_promote && !feature_flag
-}
ObligationCauseCode::Coercion { source: _, target } => {
err.note(&format!("required by cast to type `{}`", self.ty_to_string(target)));
}
- ObligationCauseCode::RepeatVec(suggest_const_in_array_repeat_expressions) => {
+ ObligationCauseCode::RepeatVec => {
err.note(
"the `Copy` trait is required because the repeated element will be copied",
);
- if suggest_const_in_array_repeat_expressions {
- err.note(
- "this array initializer can be evaluated at compile-time, see issue \
- #49147 <https://github.com/rust-lang/rust/issues/49147> \
- for more information",
- );
- if tcx.sess.opts.unstable_features.is_nightly_build() {
- err.help(
- "add `#![feature(const_in_array_repeat_expressions)]` to the \
- crate attributes to enable",
- );
- }
- }
}
ObligationCauseCode::VariableType(hir_id) => {
let parent_node = self.tcx.hir().get_parent_node(hir_id);
#![feature(coerce_unsized)]
#![feature(const_btree_new)]
#![feature(const_fn)]
-#![feature(const_in_array_repeat_expressions)]
#![feature(cow_is_borrowed)]
#![feature(const_cow_is_borrowed)]
#![feature(dispatch_from_dyn)]
+++ /dev/null
-# `const_in_array_repeat_expressions`
-
-The tracking issue for this feature is: [#49147]
-
-[#49147]: https://github.com/rust-lang/rust/issues/49147
-
-------------------------
-
-Relaxes the rules for repeat expressions, `[x; N]` such that `x` may also be `const` (strictly
-speaking rvalue promotable), in addition to `typeof(x): Copy`. The result of `[x; N]` where `x` is
-`const` is itself also `const`.
--- /dev/null
+#![crate_type = "lib"]
+
+pub struct Header<'a> {
+ pub value: &'a [u8],
+}
+
+pub fn test() {
+ let headers = [Header{value: &[]}; 128];
+ //~^ ERROR the trait bound
+}
+
+pub fn test2() {
+ let headers = [Header{value: &[0]}; 128];
+ //~^ ERROR the trait bound
+}
--- /dev/null
+error[E0277]: the trait bound `Header<'_>: Copy` is not satisfied
+ --> $DIR/repeat_empty_ok.rs:8:19
+ |
+LL | let headers = [Header{value: &[]}; 128];
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Header<'_>`
+ |
+ = note: the `Copy` trait is required because the repeated element will be copied
+
+error[E0277]: the trait bound `Header<'_>: Copy` is not satisfied
+ --> $DIR/repeat_empty_ok.rs:13:19
+ |
+LL | let headers = [Header{value: &[0]}; 128];
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Header<'_>`
+ |
+ = note: the `Copy` trait is required because the repeated element will be copied
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+// run-pass
+
+// Repeating a *constant* of non-Copy type (not just a constant expression) is already stable.
+
+const EMPTY: Vec<i32> = Vec::new();
+
+pub fn bar() -> [Vec<i32>; 2] {
+ [EMPTY; 2]
+}
+
+struct Bomb;
+
+impl Drop for Bomb {
+ fn drop(&mut self) {
+ panic!("BOOM!");
+ }
+}
+
+const BOOM: Bomb = Bomb;
+
+fn main() {
+ let _x = bar();
+
+ // Make sure the destructor does not get called for empty arrays. `[CONST; N]` should
+ // instantiate (and then later drop) the const exactly `N` times.
+ let _x = [BOOM; 0];
+}
--- /dev/null
+// run-pass
+
+#![feature(inline_const)]
+#![allow(unused, incomplete_features)]
+
+// Some type that is not copyable.
+struct Bar;
+
+const fn type_no_copy() -> Option<Bar> {
+ None
+}
+
+const fn type_copy() -> u32 {
+ 3
+}
+
+const _: [u32; 2] = [type_copy(); 2];
+
+// This is allowed because all promotion contexts use the explicit rules for promotability when
+// inside an explicit const context.
+const _: [Option<Bar>; 2] = [const { type_no_copy() }; 2];
+
+fn main() {}
--- /dev/null
+// Some type that is not copyable.
+struct Bar;
+
+const fn no_copy() -> Option<Bar> {
+ None
+}
+
+const fn copy() -> u32 {
+ 3
+}
+
+fn main() {
+ let _: [u32; 2] = [copy(); 2];
+ let _: [Option<Bar>; 2] = [no_copy(); 2];
+ //~^ ERROR the trait bound `Option<Bar>: Copy` is not satisfied
+}
--- /dev/null
+error[E0277]: the trait bound `Option<Bar>: Copy` is not satisfied
+ --> $DIR/fn-call-in-non-const.rs:14:31
+ |
+LL | let _: [Option<Bar>; 2] = [no_copy(); 2];
+ | ^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Option<Bar>`
+ |
+ = help: the following implementations were found:
+ <Option<T> as Copy>
+ = note: the `Copy` trait is required because the repeated element will be copied
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+// ignore-compare-mode-nll
+// compile-flags: -Z borrowck=migrate
+#![allow(warnings)]
+
+// Some type that is not copyable.
+struct Bar;
+
+mod non_constants {
+ use Bar;
+
+ fn no_impl_copy_empty_value_multiple_elements() {
+ let x = None;
+ let arr: [Option<Bar>; 2] = [x; 2];
+ //~^ ERROR the trait bound `Option<Bar>: Copy` is not satisfied [E0277]
+ }
+
+ fn no_impl_copy_value_multiple_elements() {
+ let x = Some(Bar);
+ let arr: [Option<Bar>; 2] = [x; 2];
+ //~^ ERROR the trait bound `Option<Bar>: Copy` is not satisfied [E0277]
+ }
+}
+
+fn main() {}
--- /dev/null
+error[E0277]: the trait bound `Option<Bar>: Copy` is not satisfied
+ --> $DIR/migrate-fail.rs:13:37
+ |
+LL | let arr: [Option<Bar>; 2] = [x; 2];
+ | ^^^^^^ the trait `Copy` is not implemented for `Option<Bar>`
+ |
+ = help: the following implementations were found:
+ <Option<T> as Copy>
+ = note: the `Copy` trait is required because the repeated element will be copied
+
+error[E0277]: the trait bound `Option<Bar>: Copy` is not satisfied
+ --> $DIR/migrate-fail.rs:19:37
+ |
+LL | let arr: [Option<Bar>; 2] = [x; 2];
+ | ^^^^^^ the trait `Copy` is not implemented for `Option<Bar>`
+ |
+ = help: the following implementations were found:
+ <Option<T> as Copy>
+ = note: the `Copy` trait is required because the repeated element will be copied
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+// check-pass
+// compile-flags: -Z borrowck=migrate
+// ignore-compare-mode-nll
+#![allow(warnings)]
+
+// Some type that is not copyable.
+struct Bar;
+
+mod constants {
+ use Bar;
+
+ fn no_impl_copy_empty_value_no_elements() {
+ const FOO: Option<Bar> = None;
+ const ARR: [Option<Bar>; 0] = [FOO; 0];
+ }
+
+ fn no_impl_copy_empty_value_single_element() {
+ const FOO: Option<Bar> = None;
+ const ARR: [Option<Bar>; 1] = [FOO; 1];
+ }
+
+ fn no_impl_copy_empty_value_multiple_elements() {
+ const FOO: Option<Bar> = None;
+ const ARR: [Option<Bar>; 2] = [FOO; 2];
+ }
+
+ fn no_impl_copy_value_no_elements() {
+ const FOO: Option<Bar> = Some(Bar);
+ const ARR: [Option<Bar>; 0] = [FOO; 0];
+ }
+
+ fn no_impl_copy_value_single_element() {
+ const FOO: Option<Bar> = Some(Bar);
+ const ARR: [Option<Bar>; 1] = [FOO; 1];
+ }
+
+ fn no_impl_copy_value_multiple_elements() {
+ const FOO: Option<Bar> = Some(Bar);
+ const ARR: [Option<Bar>; 2] = [FOO; 2];
+ }
+
+ fn impl_copy_empty_value_no_elements() {
+ const FOO: Option<u32> = None;
+ const ARR: [Option<u32>; 0] = [FOO; 0];
+ }
+
+ fn impl_copy_empty_value_one_element() {
+ const FOO: Option<u32> = None;
+ const ARR: [Option<u32>; 1] = [FOO; 1];
+ }
+
+ fn impl_copy_empty_value_multiple_elements() {
+ const FOO: Option<u32> = None;
+ const ARR: [Option<u32>; 2] = [FOO; 2];
+ }
+
+ fn impl_copy_value_no_elements() {
+ const FOO: Option<u32> = Some(4);
+ const ARR: [Option<u32>; 0] = [FOO; 0];
+ }
+
+ fn impl_copy_value_one_element() {
+ const FOO: Option<u32> = Some(4);
+ const ARR: [Option<u32>; 1] = [FOO; 1];
+ }
+
+ fn impl_copy_value_multiple_elements() {
+ const FOO: Option<u32> = Some(4);
+ const ARR: [Option<u32>; 2] = [FOO; 2];
+ }
+}
+
+mod non_constants {
+ use Bar;
+
+ fn no_impl_copy_empty_value_no_elements() {
+ let x = None;
+ let arr: [Option<Bar>; 0] = [x; 0];
+ }
+
+ fn no_impl_copy_empty_value_single_element() {
+ let x = None;
+ let arr: [Option<Bar>; 1] = [x; 1];
+ }
+
+ fn no_impl_copy_value_no_elements() {
+ let x = Some(Bar);
+ let arr: [Option<Bar>; 0] = [x; 0];
+ }
+
+ fn no_impl_copy_value_single_element() {
+ let x = Some(Bar);
+ let arr: [Option<Bar>; 1] = [x; 1];
+ }
+
+ fn impl_copy_empty_value_no_elements() {
+ let x: Option<u32> = None;
+ let arr: [Option<u32>; 0] = [x; 0];
+ }
+
+ fn impl_copy_empty_value_one_element() {
+ let x: Option<u32> = None;
+ let arr: [Option<u32>; 1] = [x; 1];
+ }
+
+ fn impl_copy_empty_value_multiple_elements() {
+ let x: Option<u32> = None;
+ let arr: [Option<u32>; 2] = [x; 2];
+ }
+
+ fn impl_copy_value_no_elements() {
+ let x: Option<u32> = Some(4);
+ let arr: [Option<u32>; 0] = [x; 0];
+ }
+
+ fn impl_copy_value_one_element() {
+ let x: Option<u32> = Some(4);
+ let arr: [Option<u32>; 1] = [x; 1];
+ }
+
+ fn impl_copy_value_multiple_elements() {
+ let x: Option<u32> = Some(4);
+ let arr: [Option<u32>; 2] = [x; 2];
+ }
+}
+
+fn main() {}
--- /dev/null
+// ignore-compare-mode-nll
+#![allow(warnings)]
+
+// Some type that is not copyable.
+struct Bar;
+
+mod non_constants {
+ use Bar;
+
+ fn no_impl_copy_empty_value_multiple_elements() {
+ let x = None;
+ let arr: [Option<Bar>; 2] = [x; 2];
+ //~^ ERROR the trait bound `Option<Bar>: Copy` is not satisfied [E0277]
+ }
+
+ fn no_impl_copy_value_multiple_elements() {
+ let x = Some(Bar);
+ let arr: [Option<Bar>; 2] = [x; 2];
+ //~^ ERROR the trait bound `Option<Bar>: Copy` is not satisfied [E0277]
+ }
+}
+
+fn main() {}
--- /dev/null
+error[E0277]: the trait bound `Option<Bar>: Copy` is not satisfied
+ --> $DIR/nll-fail.rs:12:37
+ |
+LL | let arr: [Option<Bar>; 2] = [x; 2];
+ | ^^^^^^ the trait `Copy` is not implemented for `Option<Bar>`
+ |
+ = help: the following implementations were found:
+ <Option<T> as Copy>
+ = note: the `Copy` trait is required because the repeated element will be copied
+
+error[E0277]: the trait bound `Option<Bar>: Copy` is not satisfied
+ --> $DIR/nll-fail.rs:18:37
+ |
+LL | let arr: [Option<Bar>; 2] = [x; 2];
+ | ^^^^^^ the trait `Copy` is not implemented for `Option<Bar>`
+ |
+ = help: the following implementations were found:
+ <Option<T> as Copy>
+ = note: the `Copy` trait is required because the repeated element will be copied
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+// check-pass
+// ignore-compare-mode-nll
+#![allow(warnings)]
+
+// Some type that is not copyable.
+struct Bar;
+
+mod constants {
+ use Bar;
+
+ fn no_impl_copy_empty_value_no_elements() {
+ const FOO: Option<Bar> = None;
+ const ARR: [Option<Bar>; 0] = [FOO; 0];
+ }
+
+ fn no_impl_copy_empty_value_single_element() {
+ const FOO: Option<Bar> = None;
+ const ARR: [Option<Bar>; 1] = [FOO; 1];
+ }
+
+ fn no_impl_copy_empty_value_multiple_elements() {
+ const FOO: Option<Bar> = None;
+ const ARR: [Option<Bar>; 2] = [FOO; 2];
+ }
+
+ fn no_impl_copy_value_no_elements() {
+ const FOO: Option<Bar> = Some(Bar);
+ const ARR: [Option<Bar>; 0] = [FOO; 0];
+ }
+
+ fn no_impl_copy_value_single_element() {
+ const FOO: Option<Bar> = Some(Bar);
+ const ARR: [Option<Bar>; 1] = [FOO; 1];
+ }
+
+ fn no_impl_copy_value_multiple_elements() {
+ const FOO: Option<Bar> = Some(Bar);
+ const ARR: [Option<Bar>; 2] = [FOO; 2];
+ }
+
+ fn impl_copy_empty_value_no_elements() {
+ const FOO: Option<u32> = None;
+ const ARR: [Option<u32>; 0] = [FOO; 0];
+ }
+
+ fn impl_copy_empty_value_one_element() {
+ const FOO: Option<u32> = None;
+ const ARR: [Option<u32>; 1] = [FOO; 1];
+ }
+
+ fn impl_copy_empty_value_multiple_elements() {
+ const FOO: Option<u32> = None;
+ const ARR: [Option<u32>; 2] = [FOO; 2];
+ }
+
+ fn impl_copy_value_no_elements() {
+ const FOO: Option<u32> = Some(4);
+ const ARR: [Option<u32>; 0] = [FOO; 0];
+ }
+
+ fn impl_copy_value_one_element() {
+ const FOO: Option<u32> = Some(4);
+ const ARR: [Option<u32>; 1] = [FOO; 1];
+ }
+
+ fn impl_copy_value_multiple_elements() {
+ const FOO: Option<u32> = Some(4);
+ const ARR: [Option<u32>; 2] = [FOO; 2];
+ }
+}
+
+mod non_constants {
+ use Bar;
+
+ fn no_impl_copy_empty_value_no_elements() {
+ let x = None;
+ let arr: [Option<Bar>; 0] = [x; 0];
+ }
+
+ fn no_impl_copy_empty_value_single_element() {
+ let x = None;
+ let arr: [Option<Bar>; 1] = [x; 1];
+ }
+
+ fn no_impl_copy_value_no_elements() {
+ let x = Some(Bar);
+ let arr: [Option<Bar>; 0] = [x; 0];
+ }
+
+ fn no_impl_copy_value_single_element() {
+ let x = Some(Bar);
+ let arr: [Option<Bar>; 1] = [x; 1];
+ }
+
+ fn impl_copy_empty_value_no_elements() {
+ let x: Option<u32> = None;
+ let arr: [Option<u32>; 0] = [x; 0];
+ }
+
+ fn impl_copy_empty_value_one_element() {
+ let x: Option<u32> = None;
+ let arr: [Option<u32>; 1] = [x; 1];
+ }
+
+ fn impl_copy_empty_value_multiple_elements() {
+ let x: Option<u32> = None;
+ let arr: [Option<u32>; 2] = [x; 2];
+ }
+
+ fn impl_copy_value_no_elements() {
+ let x: Option<u32> = Some(4);
+ let arr: [Option<u32>; 0] = [x; 0];
+ }
+
+ fn impl_copy_value_one_element() {
+ let x: Option<u32> = Some(4);
+ let arr: [Option<u32>; 1] = [x; 1];
+ }
+
+ fn impl_copy_value_multiple_elements() {
+ let x: Option<u32> = Some(4);
+ let arr: [Option<u32>; 2] = [x; 2];
+ }
+}
+
+fn main() {}
--- /dev/null
+// run-pass
+
+#[derive(Debug, Eq, PartialEq)]
+struct Bar;
+
+fn main() {
+ const FOO: Option<Bar> = None;
+ const ARR: [Option<Bar>; 2] = [FOO; 2];
+
+ assert_eq!(ARR, [None::<Bar>, None::<Bar>]);
+}
--- /dev/null
+#[derive(Copy, Clone)]
+struct Foo<T>(T);
+
+fn main() {
+ [Foo(String::new()); 4];
+ //~^ ERROR the trait bound `Foo<String>: Copy` is not satisfied [E0277]
+}
--- /dev/null
+error[E0277]: the trait bound `Foo<String>: Copy` is not satisfied
+ --> $DIR/trait-error.rs:5:5
+ |
+LL | [Foo(String::new()); 4];
+ | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Foo<String>`
+ |
+ = help: the following implementations were found:
+ <Foo<T> as Copy>
+ = note: the `Copy` trait is required because the repeated element will be copied
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-// run-pass
-
-// Repeating a *constant* of non-Copy type (not just a constant expression) is already stable.
-
-const EMPTY: Vec<i32> = Vec::new();
-
-pub fn bar() -> [Vec<i32>; 2] {
- [EMPTY; 2]
-}
-
-struct Bomb;
-
-impl Drop for Bomb {
- fn drop(&mut self) {
- panic!("BOOM!");
- }
-}
-
-const BOOM: Bomb = Bomb;
-
-fn main() {
- let _x = bar();
-
- // Make sure the destructor does not get called for empty arrays. `[CONST; N]` should
- // instantiate (and then later drop) the const exactly `N` times.
- let _x = [BOOM; 0];
-}
+++ /dev/null
-// run-pass
-
-#![allow(unused)]
-#![feature(const_in_array_repeat_expressions)]
-
-// Some type that is not copyable.
-struct Bar;
-
-const fn type_no_copy() -> Option<Bar> {
- None
-}
-
-const fn type_copy() -> u32 {
- 3
-}
-
-const _: [u32; 2] = [type_copy(); 2];
-
-// This is allowed because all promotion contexts use the explicit rules for promotability when
-// inside an explicit const context.
-const _: [Option<Bar>; 2] = [type_no_copy(); 2];
-
-fn main() {}
+++ /dev/null
-#![feature(const_in_array_repeat_expressions)]
-
-// Some type that is not copyable.
-struct Bar;
-
-const fn no_copy() -> Option<Bar> {
- None
-}
-
-const fn copy() -> u32 {
- 3
-}
-
-fn main() {
- let _: [u32; 2] = [copy(); 2];
- let _: [Option<Bar>; 2] = [no_copy(); 2];
- //~^ ERROR the trait bound `Option<Bar>: Copy` is not satisfied
-}
+++ /dev/null
-error[E0277]: the trait bound `Option<Bar>: Copy` is not satisfied
- --> $DIR/fn-call-in-non-const.rs:16:31
- |
-LL | let _: [Option<Bar>; 2] = [no_copy(); 2];
- | ^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Option<Bar>`
- |
- = help: the following implementations were found:
- <Option<T> as Copy>
- = note: the `Copy` trait is required because the repeated element will be copied
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-// ignore-compare-mode-nll
-// compile-flags: -Z borrowck=migrate
-#![feature(const_in_array_repeat_expressions)]
-#![allow(warnings)]
-
-// Some type that is not copyable.
-struct Bar;
-
-mod non_constants {
- use Bar;
-
- fn no_impl_copy_empty_value_multiple_elements() {
- let x = None;
- let arr: [Option<Bar>; 2] = [x; 2];
- //~^ ERROR the trait bound `Option<Bar>: Copy` is not satisfied [E0277]
- }
-
- fn no_impl_copy_value_multiple_elements() {
- let x = Some(Bar);
- let arr: [Option<Bar>; 2] = [x; 2];
- //~^ ERROR the trait bound `Option<Bar>: Copy` is not satisfied [E0277]
- }
-}
-
-fn main() {}
+++ /dev/null
-error[E0277]: the trait bound `Option<Bar>: Copy` is not satisfied
- --> $DIR/migrate-fail.rs:14:37
- |
-LL | let arr: [Option<Bar>; 2] = [x; 2];
- | ^^^^^^ the trait `Copy` is not implemented for `Option<Bar>`
- |
- = help: the following implementations were found:
- <Option<T> as Copy>
- = note: the `Copy` trait is required because the repeated element will be copied
-
-error[E0277]: the trait bound `Option<Bar>: Copy` is not satisfied
- --> $DIR/migrate-fail.rs:20:37
- |
-LL | let arr: [Option<Bar>; 2] = [x; 2];
- | ^^^^^^ the trait `Copy` is not implemented for `Option<Bar>`
- |
- = help: the following implementations were found:
- <Option<T> as Copy>
- = note: the `Copy` trait is required because the repeated element will be copied
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-// check-pass
-// compile-flags: -Z borrowck=migrate
-// ignore-compare-mode-nll
-#![feature(const_in_array_repeat_expressions)]
-#![allow(warnings)]
-
-// Some type that is not copyable.
-struct Bar;
-
-mod constants {
- use Bar;
-
- fn no_impl_copy_empty_value_no_elements() {
- const FOO: Option<Bar> = None;
- const ARR: [Option<Bar>; 0] = [FOO; 0];
- }
-
- fn no_impl_copy_empty_value_single_element() {
- const FOO: Option<Bar> = None;
- const ARR: [Option<Bar>; 1] = [FOO; 1];
- }
-
- fn no_impl_copy_empty_value_multiple_elements() {
- const FOO: Option<Bar> = None;
- const ARR: [Option<Bar>; 2] = [FOO; 2];
- }
-
- fn no_impl_copy_value_no_elements() {
- const FOO: Option<Bar> = Some(Bar);
- const ARR: [Option<Bar>; 0] = [FOO; 0];
- }
-
- fn no_impl_copy_value_single_element() {
- const FOO: Option<Bar> = Some(Bar);
- const ARR: [Option<Bar>; 1] = [FOO; 1];
- }
-
- fn no_impl_copy_value_multiple_elements() {
- const FOO: Option<Bar> = Some(Bar);
- const ARR: [Option<Bar>; 2] = [FOO; 2];
- }
-
- fn impl_copy_empty_value_no_elements() {
- const FOO: Option<u32> = None;
- const ARR: [Option<u32>; 0] = [FOO; 0];
- }
-
- fn impl_copy_empty_value_one_element() {
- const FOO: Option<u32> = None;
- const ARR: [Option<u32>; 1] = [FOO; 1];
- }
-
- fn impl_copy_empty_value_multiple_elements() {
- const FOO: Option<u32> = None;
- const ARR: [Option<u32>; 2] = [FOO; 2];
- }
-
- fn impl_copy_value_no_elements() {
- const FOO: Option<u32> = Some(4);
- const ARR: [Option<u32>; 0] = [FOO; 0];
- }
-
- fn impl_copy_value_one_element() {
- const FOO: Option<u32> = Some(4);
- const ARR: [Option<u32>; 1] = [FOO; 1];
- }
-
- fn impl_copy_value_multiple_elements() {
- const FOO: Option<u32> = Some(4);
- const ARR: [Option<u32>; 2] = [FOO; 2];
- }
-}
-
-mod non_constants {
- use Bar;
-
- fn no_impl_copy_empty_value_no_elements() {
- let x = None;
- let arr: [Option<Bar>; 0] = [x; 0];
- }
-
- fn no_impl_copy_empty_value_single_element() {
- let x = None;
- let arr: [Option<Bar>; 1] = [x; 1];
- }
-
- fn no_impl_copy_value_no_elements() {
- let x = Some(Bar);
- let arr: [Option<Bar>; 0] = [x; 0];
- }
-
- fn no_impl_copy_value_single_element() {
- let x = Some(Bar);
- let arr: [Option<Bar>; 1] = [x; 1];
- }
-
- fn impl_copy_empty_value_no_elements() {
- let x: Option<u32> = None;
- let arr: [Option<u32>; 0] = [x; 0];
- }
-
- fn impl_copy_empty_value_one_element() {
- let x: Option<u32> = None;
- let arr: [Option<u32>; 1] = [x; 1];
- }
-
- fn impl_copy_empty_value_multiple_elements() {
- let x: Option<u32> = None;
- let arr: [Option<u32>; 2] = [x; 2];
- }
-
- fn impl_copy_value_no_elements() {
- let x: Option<u32> = Some(4);
- let arr: [Option<u32>; 0] = [x; 0];
- }
-
- fn impl_copy_value_one_element() {
- let x: Option<u32> = Some(4);
- let arr: [Option<u32>; 1] = [x; 1];
- }
-
- fn impl_copy_value_multiple_elements() {
- let x: Option<u32> = Some(4);
- let arr: [Option<u32>; 2] = [x; 2];
- }
-}
-
-fn main() {}
+++ /dev/null
-// ignore-compare-mode-nll
-#![feature(const_in_array_repeat_expressions, nll)]
-#![allow(warnings)]
-
-// Some type that is not copyable.
-struct Bar;
-
-mod non_constants {
- use Bar;
-
- fn no_impl_copy_empty_value_multiple_elements() {
- let x = None;
- let arr: [Option<Bar>; 2] = [x; 2];
- //~^ ERROR the trait bound `Option<Bar>: Copy` is not satisfied [E0277]
- }
-
- fn no_impl_copy_value_multiple_elements() {
- let x = Some(Bar);
- let arr: [Option<Bar>; 2] = [x; 2];
- //~^ ERROR the trait bound `Option<Bar>: Copy` is not satisfied [E0277]
- }
-}
-
-fn main() {}
+++ /dev/null
-error[E0277]: the trait bound `Option<Bar>: Copy` is not satisfied
- --> $DIR/nll-fail.rs:13:37
- |
-LL | let arr: [Option<Bar>; 2] = [x; 2];
- | ^^^^^^ the trait `Copy` is not implemented for `Option<Bar>`
- |
- = help: the following implementations were found:
- <Option<T> as Copy>
- = note: the `Copy` trait is required because the repeated element will be copied
-
-error[E0277]: the trait bound `Option<Bar>: Copy` is not satisfied
- --> $DIR/nll-fail.rs:19:37
- |
-LL | let arr: [Option<Bar>; 2] = [x; 2];
- | ^^^^^^ the trait `Copy` is not implemented for `Option<Bar>`
- |
- = help: the following implementations were found:
- <Option<T> as Copy>
- = note: the `Copy` trait is required because the repeated element will be copied
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-// check-pass
-// ignore-compare-mode-nll
-#![allow(warnings)]
-#![feature(const_in_array_repeat_expressions, nll)]
-
-// Some type that is not copyable.
-struct Bar;
-
-mod constants {
- use Bar;
-
- fn no_impl_copy_empty_value_no_elements() {
- const FOO: Option<Bar> = None;
- const ARR: [Option<Bar>; 0] = [FOO; 0];
- }
-
- fn no_impl_copy_empty_value_single_element() {
- const FOO: Option<Bar> = None;
- const ARR: [Option<Bar>; 1] = [FOO; 1];
- }
-
- fn no_impl_copy_empty_value_multiple_elements() {
- const FOO: Option<Bar> = None;
- const ARR: [Option<Bar>; 2] = [FOO; 2];
- }
-
- fn no_impl_copy_value_no_elements() {
- const FOO: Option<Bar> = Some(Bar);
- const ARR: [Option<Bar>; 0] = [FOO; 0];
- }
-
- fn no_impl_copy_value_single_element() {
- const FOO: Option<Bar> = Some(Bar);
- const ARR: [Option<Bar>; 1] = [FOO; 1];
- }
-
- fn no_impl_copy_value_multiple_elements() {
- const FOO: Option<Bar> = Some(Bar);
- const ARR: [Option<Bar>; 2] = [FOO; 2];
- }
-
- fn impl_copy_empty_value_no_elements() {
- const FOO: Option<u32> = None;
- const ARR: [Option<u32>; 0] = [FOO; 0];
- }
-
- fn impl_copy_empty_value_one_element() {
- const FOO: Option<u32> = None;
- const ARR: [Option<u32>; 1] = [FOO; 1];
- }
-
- fn impl_copy_empty_value_multiple_elements() {
- const FOO: Option<u32> = None;
- const ARR: [Option<u32>; 2] = [FOO; 2];
- }
-
- fn impl_copy_value_no_elements() {
- const FOO: Option<u32> = Some(4);
- const ARR: [Option<u32>; 0] = [FOO; 0];
- }
-
- fn impl_copy_value_one_element() {
- const FOO: Option<u32> = Some(4);
- const ARR: [Option<u32>; 1] = [FOO; 1];
- }
-
- fn impl_copy_value_multiple_elements() {
- const FOO: Option<u32> = Some(4);
- const ARR: [Option<u32>; 2] = [FOO; 2];
- }
-}
-
-mod non_constants {
- use Bar;
-
- fn no_impl_copy_empty_value_no_elements() {
- let x = None;
- let arr: [Option<Bar>; 0] = [x; 0];
- }
-
- fn no_impl_copy_empty_value_single_element() {
- let x = None;
- let arr: [Option<Bar>; 1] = [x; 1];
- }
-
- fn no_impl_copy_value_no_elements() {
- let x = Some(Bar);
- let arr: [Option<Bar>; 0] = [x; 0];
- }
-
- fn no_impl_copy_value_single_element() {
- let x = Some(Bar);
- let arr: [Option<Bar>; 1] = [x; 1];
- }
-
- fn impl_copy_empty_value_no_elements() {
- let x: Option<u32> = None;
- let arr: [Option<u32>; 0] = [x; 0];
- }
-
- fn impl_copy_empty_value_one_element() {
- let x: Option<u32> = None;
- let arr: [Option<u32>; 1] = [x; 1];
- }
-
- fn impl_copy_empty_value_multiple_elements() {
- let x: Option<u32> = None;
- let arr: [Option<u32>; 2] = [x; 2];
- }
-
- fn impl_copy_value_no_elements() {
- let x: Option<u32> = Some(4);
- let arr: [Option<u32>; 0] = [x; 0];
- }
-
- fn impl_copy_value_one_element() {
- let x: Option<u32> = Some(4);
- let arr: [Option<u32>; 1] = [x; 1];
- }
-
- fn impl_copy_value_multiple_elements() {
- let x: Option<u32> = Some(4);
- let arr: [Option<u32>; 2] = [x; 2];
- }
-}
-
-fn main() {}
+++ /dev/null
-// run-pass
-#![feature(const_in_array_repeat_expressions)]
-
-#[derive(Debug, Eq, PartialEq)]
-struct Bar;
-
-fn main() {
- const FOO: Option<Bar> = None;
- const ARR: [Option<Bar>; 2] = [FOO; 2];
-
- assert_eq!(ARR, [None::<Bar>, None::<Bar>]);
-}
+++ /dev/null
-#![feature(const_in_array_repeat_expressions)]
-
-#[derive(Copy, Clone)]
-struct Foo<T>(T);
-
-fn main() {
- [Foo(String::new()); 4];
- //~^ ERROR the trait bound `Foo<String>: Copy` is not satisfied [E0277]
-}
+++ /dev/null
-error[E0277]: the trait bound `Foo<String>: Copy` is not satisfied
- --> $DIR/trait-error.rs:7:5
- |
-LL | [Foo(String::new()); 4];
- | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Foo<String>`
- |
- = help: the following implementations were found:
- <Foo<T> as Copy>
- = note: the `Copy` trait is required because the repeated element will be copied
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-#![allow(warnings)]
-
-struct Bar;
-
-// This function would compile with the feature gate, and tests that it is suggested.
-fn foo() {
- let arr: [Option<String>; 2] = [None::<String>; 2];
- //~^ ERROR the trait bound `Option<String>: Copy` is not satisfied [E0277]
-}
-
-// This function would not compile with the feature gate, and tests that it is not suggested.
-fn bar() {
- let arr: [Option<String>; 2] = [Some("foo".to_string()); 2];
- //~^ ERROR the trait bound `Option<String>: Copy` is not satisfied [E0277]
-}
-
-fn main() {}
+++ /dev/null
-error[E0277]: the trait bound `Option<String>: Copy` is not satisfied
- --> $DIR/feature-gate-const_in_array_repeat_expressions.rs:7:36
- |
-LL | let arr: [Option<String>; 2] = [None::<String>; 2];
- | ^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Option<String>`
- |
- = help: the following implementations were found:
- <Option<T> as Copy>
- = note: the `Copy` trait is required because the repeated element will be copied
- = note: this array initializer can be evaluated at compile-time, see issue #49147 <https://github.com/rust-lang/rust/issues/49147> for more information
- = help: add `#![feature(const_in_array_repeat_expressions)]` to the crate attributes to enable
-
-error[E0277]: the trait bound `Option<String>: Copy` is not satisfied
- --> $DIR/feature-gate-const_in_array_repeat_expressions.rs:13:36
- |
-LL | let arr: [Option<String>; 2] = [Some("foo".to_string()); 2];
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Option<String>`
- |
- = help: the following implementations were found:
- <Option<T> as Copy>
- = note: the `Copy` trait is required because the repeated element will be copied
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-#![crate_type = "lib"]
-
-pub struct Header<'a> {
- pub value: &'a [u8],
-}
-
-pub fn test() {
- let headers = [Header{value: &[]}; 128];
- //~^ ERROR the trait bound
-}
-
-pub fn test2() {
- let headers = [Header{value: &[0]}; 128];
- //~^ ERROR the trait bound
-}
+++ /dev/null
-error[E0277]: the trait bound `Header<'_>: Copy` is not satisfied
- --> $DIR/issue-80371.rs:8:19
- |
-LL | let headers = [Header{value: &[]}; 128];
- | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Header<'_>`
- |
- = note: the `Copy` trait is required because the repeated element will be copied
- = note: this array initializer can be evaluated at compile-time, see issue #49147 <https://github.com/rust-lang/rust/issues/49147> for more information
- = help: add `#![feature(const_in_array_repeat_expressions)]` to the crate attributes to enable
-
-error[E0277]: the trait bound `Header<'_>: Copy` is not satisfied
- --> $DIR/issue-80371.rs:13:19
- |
-LL | let headers = [Header{value: &[0]}; 128];
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Header<'_>`
- |
- = note: the `Copy` trait is required because the repeated element will be copied
- = note: this array initializer can be evaluated at compile-time, see issue #49147 <https://github.com/rust-lang/rust/issues/49147> for more information
- = help: add `#![feature(const_in_array_repeat_expressions)]` to the crate attributes to enable
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0277`.
// edition:2018
#![feature(async_closure)]
-#![feature(const_in_array_repeat_expressions)]
#![feature(generators)]
#![deny(unused_must_use)]
[Box::new([|| {}; 10]); 1]; //~ ERROR unused array of boxed arrays of closures that must be used
- [|| { //~ ERROR unused array of generators that must be used
- yield 42u32;
- }; 42];
-
vec![|| "a"].pop().unwrap(); //~ ERROR unused closure that must be used
let b = false;
error: unused closure that must be used
- --> $DIR/unused-closure.rs:10:5
+ --> $DIR/unused-closure.rs:9:5
|
LL | / || {
LL | | println!("Hello!");
| |______^
|
note: the lint level is defined here
- --> $DIR/unused-closure.rs:7:9
+ --> $DIR/unused-closure.rs:6:9
|
LL | #![deny(unused_must_use)]
| ^^^^^^^^^^^^^^^
= note: closures are lazy and do nothing unless called
error: unused implementer of `Future` that must be used
- --> $DIR/unused-closure.rs:14:5
+ --> $DIR/unused-closure.rs:13:5
|
LL | async {};
| ^^^^^^^^^
= note: futures do nothing unless you `.await` or poll them
error: unused closure that must be used
- --> $DIR/unused-closure.rs:15:5
+ --> $DIR/unused-closure.rs:14:5
|
LL | || async {};
| ^^^^^^^^^^^^
= note: closures are lazy and do nothing unless called
error: unused closure that must be used
- --> $DIR/unused-closure.rs:16:5
+ --> $DIR/unused-closure.rs:15:5
|
LL | async || {};
| ^^^^^^^^^^^^
= note: closures are lazy and do nothing unless called
error: unused array of boxed arrays of closures that must be used
- --> $DIR/unused-closure.rs:19:5
+ --> $DIR/unused-closure.rs:18:5
|
LL | [Box::new([|| {}; 10]); 1];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: closures are lazy and do nothing unless called
-error: unused array of generators that must be used
- --> $DIR/unused-closure.rs:21:5
- |
-LL | / [|| {
-LL | | yield 42u32;
-LL | | }; 42];
- | |___________^
- |
- = note: generators are lazy and do nothing unless resumed
-
error: unused closure that must be used
- --> $DIR/unused-closure.rs:25:5
+ --> $DIR/unused-closure.rs:20:5
|
LL | vec![|| "a"].pop().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: closures are lazy and do nothing unless called
error: unused closure that must be used
- --> $DIR/unused-closure.rs:28:9
+ --> $DIR/unused-closure.rs:23:9
|
LL | || true;
| ^^^^^^^^
|
= note: closures are lazy and do nothing unless called
-error: aborting due to 8 previous errors
+error: aborting due to 7 previous errors