rustc_mir: Re-use report_selection_error
.
This commit replaces the new error that was being emitted in NLL type check with a call to `report_selection_error` so that the same trait error as before this PR is emitted.
This commit is contained in:
parent
3cca4ceed8
commit
813c994a75
@ -1564,6 +1564,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
err.note(&format!("required for the cast to the object type `{}`",
|
||||
self.ty_to_string(object_ty)));
|
||||
}
|
||||
ObligationCauseCode::RepeatVec => {
|
||||
err.note("the `Copy` trait is required because the \
|
||||
repeated element will be copied");
|
||||
}
|
||||
ObligationCauseCode::VariableType(_) => {
|
||||
err.note("all local variables must have a statically known size");
|
||||
if !self.tcx.features().unsized_locals {
|
||||
|
@ -195,6 +195,8 @@ pub enum ObligationCauseCode<'tcx> {
|
||||
SizedReturnType,
|
||||
/// Yield type must be Sized
|
||||
SizedYieldType,
|
||||
/// [T,..n] --> T must be Copy
|
||||
RepeatVec,
|
||||
|
||||
/// Types of fields (other than the last, except for packed structs) in a struct must be sized.
|
||||
FieldSized { adt_kind: AdtKind, last: bool },
|
||||
|
@ -488,6 +488,7 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
|
||||
super::SizedArgumentType => Some(super::SizedArgumentType),
|
||||
super::SizedReturnType => Some(super::SizedReturnType),
|
||||
super::SizedYieldType => Some(super::SizedYieldType),
|
||||
super::RepeatVec => Some(super::RepeatVec),
|
||||
super::FieldSized { adt_kind, last } => Some(super::FieldSized { adt_kind, last }),
|
||||
super::ConstSized => Some(super::ConstSized),
|
||||
super::SharedStatic => Some(super::SharedStatic),
|
||||
|
@ -35,7 +35,7 @@ use rustc::mir::*;
|
||||
use rustc::traits::query::type_op;
|
||||
use rustc::traits::query::type_op::custom::CustomTypeOp;
|
||||
use rustc::traits::query::{Fallible, NoSolution};
|
||||
use rustc::traits::{ObligationCause, PredicateObligations};
|
||||
use rustc::traits::{self, ObligationCause, PredicateObligations};
|
||||
use rustc::ty::adjustment::{PointerCast};
|
||||
use rustc::ty::fold::TypeFoldable;
|
||||
use rustc::ty::subst::{Subst, SubstsRef, UnpackedKind, UserSubsts};
|
||||
@ -1968,25 +1968,25 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
||||
// a required check to make sure that repeated elements implement `Copy`.
|
||||
let span = body.source_info(location).span;
|
||||
let ty = operand.ty(body, tcx);
|
||||
let is_copy = self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span);
|
||||
if !is_copy {
|
||||
let copy_path = self.tcx().def_path_str(
|
||||
self.tcx().lang_items().copy_trait().unwrap());
|
||||
self.tcx().sess
|
||||
.struct_span_err(
|
||||
span,
|
||||
&format!("repeated expression does not implement `{}`", copy_path),
|
||||
)
|
||||
.span_label(span, &format!(
|
||||
"the trait `{}` is not implemented for `{}`",
|
||||
copy_path, ty,
|
||||
))
|
||||
.note(&format!(
|
||||
"the `{}` trait is required because the repeated element will be \
|
||||
copied",
|
||||
copy_path,
|
||||
))
|
||||
.emit();
|
||||
if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span) {
|
||||
self.infcx.report_selection_error(
|
||||
&traits::Obligation::new(
|
||||
ObligationCause::new(
|
||||
span,
|
||||
self.tcx().hir().def_index_to_hir_id(self.mir_def_id.index),
|
||||
traits::ObligationCauseCode::RepeatVec,
|
||||
),
|
||||
self.param_env,
|
||||
ty::Predicate::Trait(ty::Binder::bind(ty::TraitPredicate {
|
||||
trait_ref: ty::TraitRef::new(
|
||||
self.tcx().lang_items().copy_trait().unwrap(),
|
||||
tcx.mk_substs_trait(ty, &[]),
|
||||
),
|
||||
})),
|
||||
),
|
||||
&traits::SelectionError::Unimplemented,
|
||||
false,
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -86,7 +86,7 @@ mod non_constants {
|
||||
fn no_impl_copy_empty_value_multiple_elements() {
|
||||
let x = None;
|
||||
let arr: [Option<Bar>; 2] = [x; 2];
|
||||
//~^ ERROR repeated expression does not implement `std::marker::Copy`
|
||||
//~^ ERROR the trait bound `std::option::Option<Bar>: std::marker::Copy` is not satisfied [E0277]
|
||||
}
|
||||
|
||||
fn no_impl_copy_value_no_elements() {
|
||||
@ -102,7 +102,7 @@ mod non_constants {
|
||||
fn no_impl_copy_value_multiple_elements() {
|
||||
let x = Some(Bar);
|
||||
let arr: [Option<Bar>; 2] = [x; 2];
|
||||
//~^ ERROR repeated expression does not implement `std::marker::Copy`
|
||||
//~^ ERROR the trait bound `std::option::Option<Bar>: std::marker::Copy` is not satisfied [E0277]
|
||||
}
|
||||
|
||||
fn impl_copy_empty_value_no_elements() {
|
||||
|
@ -1,18 +1,23 @@
|
||||
error: repeated expression does not implement `std::marker::Copy`
|
||||
error[E0277]: the trait bound `std::option::Option<Bar>: std::marker::Copy` is not satisfied
|
||||
--> $DIR/migrate-borrowck.rs:88:37
|
||||
|
|
||||
LL | let arr: [Option<Bar>; 2] = [x; 2];
|
||||
| ^^^^^^ the trait `std::marker::Copy` is not implemented for `std::option::Option<Bar>`
|
||||
|
|
||||
= note: the `std::marker::Copy` trait is required because the repeated element will be copied
|
||||
= help: the following implementations were found:
|
||||
<std::option::Option<T> as std::marker::Copy>
|
||||
= note: the `Copy` trait is required because the repeated element will be copied
|
||||
|
||||
error: repeated expression does not implement `std::marker::Copy`
|
||||
error[E0277]: the trait bound `std::option::Option<Bar>: std::marker::Copy` is not satisfied
|
||||
--> $DIR/migrate-borrowck.rs:104:37
|
||||
|
|
||||
LL | let arr: [Option<Bar>; 2] = [x; 2];
|
||||
| ^^^^^^ the trait `std::marker::Copy` is not implemented for `std::option::Option<Bar>`
|
||||
|
|
||||
= note: the `std::marker::Copy` trait is required because the repeated element will be copied
|
||||
= help: the following implementations were found:
|
||||
<std::option::Option<T> as std::marker::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`.
|
||||
|
@ -85,7 +85,7 @@ mod non_constants {
|
||||
fn no_impl_copy_empty_value_multiple_elements() {
|
||||
let x = None;
|
||||
let arr: [Option<Bar>; 2] = [x; 2];
|
||||
//~^ ERROR repeated expression does not implement `std::marker::Copy`
|
||||
//~^ ERROR the trait bound `std::option::Option<Bar>: std::marker::Copy` is not satisfied [E0277]
|
||||
}
|
||||
|
||||
fn no_impl_copy_value_no_elements() {
|
||||
@ -101,7 +101,7 @@ mod non_constants {
|
||||
fn no_impl_copy_value_multiple_elements() {
|
||||
let x = Some(Bar);
|
||||
let arr: [Option<Bar>; 2] = [x; 2];
|
||||
//~^ ERROR repeated expression does not implement `std::marker::Copy`
|
||||
//~^ ERROR the trait bound `std::option::Option<Bar>: std::marker::Copy` is not satisfied [E0277]
|
||||
}
|
||||
|
||||
fn impl_copy_empty_value_no_elements() {
|
||||
|
@ -1,18 +1,23 @@
|
||||
error: repeated expression does not implement `std::marker::Copy`
|
||||
error[E0277]: the trait bound `std::option::Option<Bar>: std::marker::Copy` is not satisfied
|
||||
--> $DIR/nll-borrowck.rs:87:37
|
||||
|
|
||||
LL | let arr: [Option<Bar>; 2] = [x; 2];
|
||||
| ^^^^^^ the trait `std::marker::Copy` is not implemented for `std::option::Option<Bar>`
|
||||
|
|
||||
= note: the `std::marker::Copy` trait is required because the repeated element will be copied
|
||||
= help: the following implementations were found:
|
||||
<std::option::Option<T> as std::marker::Copy>
|
||||
= note: the `Copy` trait is required because the repeated element will be copied
|
||||
|
||||
error: repeated expression does not implement `std::marker::Copy`
|
||||
error[E0277]: the trait bound `std::option::Option<Bar>: std::marker::Copy` is not satisfied
|
||||
--> $DIR/nll-borrowck.rs:103:37
|
||||
|
|
||||
LL | let arr: [Option<Bar>; 2] = [x; 2];
|
||||
| ^^^^^^ the trait `std::marker::Copy` is not implemented for `std::option::Option<Bar>`
|
||||
|
|
||||
= note: the `std::marker::Copy` trait is required because the repeated element will be copied
|
||||
= help: the following implementations were found:
|
||||
<std::option::Option<T> as std::marker::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`.
|
||||
|
@ -15,5 +15,5 @@ impl Drop for Foo {
|
||||
fn main() {
|
||||
let a = Foo { x: 3 };
|
||||
let _ = [ a; 5 ];
|
||||
//~^ ERROR repeated expression does not implement `std::marker::Copy`
|
||||
//~^ ERROR the trait bound `Foo: std::marker::Copy` is not satisfied [E0277]
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
error: repeated expression does not implement `std::marker::Copy`
|
||||
error[E0277]: the trait bound `Foo: std::marker::Copy` is not satisfied
|
||||
--> $DIR/repeat-to-run-dtor-twice.rs:17:13
|
||||
|
|
||||
LL | let _ = [ a; 5 ];
|
||||
| ^^^^^^^^ the trait `std::marker::Copy` is not implemented for `Foo`
|
||||
|
|
||||
= note: the `std::marker::Copy` trait is required because the repeated element will be copied
|
||||
= 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`.
|
||||
|
Loading…
x
Reference in New Issue
Block a user