turn the RFC1592 warnings into hard errors
The warnings have already reached stable The test rfc1592_deprecated is covered by `bad_sized` and `unsized6`. Fixes #33242 Fixes #33243
This commit is contained in:
parent
7a187c39c7
commit
7b92d05804
@ -186,18 +186,6 @@ declare_lint! {
|
||||
"detects super or self keywords at the beginning of global path"
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
pub UNSIZED_IN_TUPLE,
|
||||
Warn,
|
||||
"unsized types in the interior of a tuple were erroneously allowed"
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
pub OBJECT_UNSAFE_FRAGMENT,
|
||||
Warn,
|
||||
"object-unsafe non-principal fragments in object types were erroneously allowed"
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
pub LIFETIME_UNDERSCORE,
|
||||
Warn,
|
||||
@ -239,8 +227,6 @@ impl LintPass for HardwiredLints {
|
||||
OVERLAPPING_INHERENT_IMPLS,
|
||||
RENAMED_AND_REMOVED_LINTS,
|
||||
SUPER_OR_SELF_IN_GLOBAL_PATH,
|
||||
UNSIZED_IN_TUPLE,
|
||||
OBJECT_UNSAFE_FRAGMENT,
|
||||
HR_LIFETIME_IN_ASSOC_TYPE,
|
||||
LIFETIME_UNDERSCORE
|
||||
)
|
||||
|
@ -55,7 +55,6 @@ impl FreeRegionMap {
|
||||
match *predicate {
|
||||
ty::Predicate::Projection(..) |
|
||||
ty::Predicate::Trait(..) |
|
||||
ty::Predicate::Rfc1592(..) |
|
||||
ty::Predicate::Equate(..) |
|
||||
ty::Predicate::WellFormed(..) |
|
||||
ty::Predicate::ObjectSafe(..) |
|
||||
|
@ -36,27 +36,23 @@ use util::nodemap::{FnvHashMap, FnvHashSet};
|
||||
|
||||
use std::cmp;
|
||||
use std::fmt;
|
||||
use syntax::ast;
|
||||
use syntax_pos::Span;
|
||||
use errors::DiagnosticBuilder;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
pub struct TraitErrorKey<'tcx> {
|
||||
span: Span,
|
||||
warning_node_id: Option<ast::NodeId>,
|
||||
predicate: ty::Predicate<'tcx>
|
||||
}
|
||||
|
||||
impl<'a, 'gcx, 'tcx> TraitErrorKey<'tcx> {
|
||||
fn from_error(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||
e: &FulfillmentError<'tcx>,
|
||||
warning_node_id: Option<ast::NodeId>) -> Self {
|
||||
e: &FulfillmentError<'tcx>) -> Self {
|
||||
let predicate =
|
||||
infcx.resolve_type_vars_if_possible(&e.obligation.predicate);
|
||||
TraitErrorKey {
|
||||
span: e.obligation.cause.span,
|
||||
predicate: infcx.tcx.erase_regions(&predicate),
|
||||
warning_node_id: warning_node_id
|
||||
predicate: infcx.tcx.erase_regions(&predicate)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -64,22 +60,13 @@ impl<'a, 'gcx, 'tcx> TraitErrorKey<'tcx> {
|
||||
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
pub fn report_fulfillment_errors(&self, errors: &Vec<FulfillmentError<'tcx>>) {
|
||||
for error in errors {
|
||||
self.report_fulfillment_error(error, None);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn report_fulfillment_errors_as_warnings(&self,
|
||||
errors: &Vec<FulfillmentError<'tcx>>,
|
||||
node_id: ast::NodeId) {
|
||||
for error in errors {
|
||||
self.report_fulfillment_error(error, Some(node_id));
|
||||
self.report_fulfillment_error(error);
|
||||
}
|
||||
}
|
||||
|
||||
fn report_fulfillment_error(&self,
|
||||
error: &FulfillmentError<'tcx>,
|
||||
warning_node_id: Option<ast::NodeId>) {
|
||||
let error_key = TraitErrorKey::from_error(self, error, warning_node_id);
|
||||
error: &FulfillmentError<'tcx>) {
|
||||
let error_key = TraitErrorKey::from_error(self, error);
|
||||
debug!("report_fulfillment_errors({:?}) - key={:?}",
|
||||
error, error_key);
|
||||
if !self.reported_trait_errors.borrow_mut().insert(error_key) {
|
||||
@ -88,10 +75,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
}
|
||||
match error.code {
|
||||
FulfillmentErrorCode::CodeSelectionError(ref e) => {
|
||||
self.report_selection_error(&error.obligation, e, warning_node_id);
|
||||
self.report_selection_error(&error.obligation, e);
|
||||
}
|
||||
FulfillmentErrorCode::CodeProjectionError(ref e) => {
|
||||
self.report_projection_error(&error.obligation, e, warning_node_id);
|
||||
self.report_projection_error(&error.obligation, e);
|
||||
}
|
||||
FulfillmentErrorCode::CodeAmbiguity => {
|
||||
self.maybe_report_ambiguity(&error.obligation);
|
||||
@ -101,8 +88,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
|
||||
fn report_projection_error(&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
error: &MismatchedProjectionTypes<'tcx>,
|
||||
warning_node_id: Option<ast::NodeId>)
|
||||
error: &MismatchedProjectionTypes<'tcx>)
|
||||
{
|
||||
let predicate =
|
||||
self.resolve_type_vars_if_possible(&obligation.predicate);
|
||||
@ -110,16 +96,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
if predicate.references_error() {
|
||||
return
|
||||
}
|
||||
if let Some(warning_node_id) = warning_node_id {
|
||||
self.tcx.sess.add_lint(
|
||||
::lint::builtin::UNSIZED_IN_TUPLE,
|
||||
warning_node_id,
|
||||
obligation.cause.span,
|
||||
format!("type mismatch resolving `{}`: {}",
|
||||
predicate,
|
||||
error.err));
|
||||
return
|
||||
}
|
||||
|
||||
self.probe(|_| {
|
||||
let origin = TypeOrigin::Misc(obligation.cause.span);
|
||||
let err_buf;
|
||||
@ -442,8 +419,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
|
||||
pub fn report_selection_error(&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
error: &SelectionError<'tcx>,
|
||||
warning_node_id: Option<ast::NodeId>)
|
||||
error: &SelectionError<'tcx>)
|
||||
{
|
||||
let span = obligation.cause.span;
|
||||
let mut err = match *error {
|
||||
@ -466,16 +442,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
} else {
|
||||
let trait_ref = trait_predicate.to_poly_trait_ref();
|
||||
|
||||
if let Some(warning_node_id) = warning_node_id {
|
||||
self.tcx.sess.add_lint(
|
||||
::lint::builtin::UNSIZED_IN_TUPLE,
|
||||
warning_node_id,
|
||||
obligation.cause.span,
|
||||
format!("the trait bound `{}` is not satisfied",
|
||||
trait_ref.to_predicate()));
|
||||
return;
|
||||
}
|
||||
|
||||
let mut err = struct_span_err!(self.tcx.sess, span, E0277,
|
||||
"the trait bound `{}` is not satisfied",
|
||||
trait_ref.to_predicate());
|
||||
@ -541,15 +507,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
|
||||
ty::Predicate::ObjectSafe(trait_def_id) => {
|
||||
let violations = self.tcx.object_safety_violations(trait_def_id);
|
||||
let err = self.tcx.report_object_safety_error(span,
|
||||
trait_def_id,
|
||||
warning_node_id,
|
||||
violations);
|
||||
if let Some(err) = err {
|
||||
err
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
self.tcx.report_object_safety_error(span,
|
||||
trait_def_id,
|
||||
violations)
|
||||
}
|
||||
|
||||
ty::Predicate::ClosureKind(closure_def_id, kind) => {
|
||||
@ -577,13 +537,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
// (which may fail).
|
||||
span_bug!(span, "WF predicate not satisfied for {:?}", ty);
|
||||
}
|
||||
|
||||
ty::Predicate::Rfc1592(ref data) => {
|
||||
span_bug!(
|
||||
obligation.cause.span,
|
||||
"RFC1592 predicate not satisfied for {:?}",
|
||||
data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -605,14 +558,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
|
||||
TraitNotObjectSafe(did) => {
|
||||
let violations = self.tcx.object_safety_violations(did);
|
||||
let err = self.tcx.report_object_safety_error(span, did,
|
||||
warning_node_id,
|
||||
violations);
|
||||
if let Some(err) = err {
|
||||
err
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
self.tcx.report_object_safety_error(span, did,
|
||||
violations)
|
||||
}
|
||||
};
|
||||
self.note_obligation_cause(&mut err, obligation);
|
||||
@ -640,24 +587,17 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
pub fn report_object_safety_error(self,
|
||||
span: Span,
|
||||
trait_def_id: DefId,
|
||||
warning_node_id: Option<ast::NodeId>,
|
||||
violations: Vec<ObjectSafetyViolation>)
|
||||
-> Option<DiagnosticBuilder<'tcx>>
|
||||
-> DiagnosticBuilder<'tcx>
|
||||
{
|
||||
let mut err = match warning_node_id {
|
||||
Some(_) => None,
|
||||
None => {
|
||||
let trait_str = self.item_path_str(trait_def_id);
|
||||
let mut db = struct_span_err!(
|
||||
self.sess, span, E0038,
|
||||
"the trait `{}` cannot be made into an object",
|
||||
trait_str);
|
||||
db.span_label(span,
|
||||
&format!("the trait `{}` cannot be made \
|
||||
into an object", trait_str));
|
||||
Some(db)
|
||||
}
|
||||
};
|
||||
let trait_str = self.item_path_str(trait_def_id);
|
||||
let mut err = struct_span_err!(
|
||||
self.sess, span, E0038,
|
||||
"the trait `{}` cannot be made into an object",
|
||||
trait_str);
|
||||
err.span_label(span, &format!(
|
||||
"the trait `{}` cannot be made into an object", trait_str
|
||||
));
|
||||
|
||||
let mut reported_violations = FnvHashSet();
|
||||
for violation in violations {
|
||||
@ -697,19 +637,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
&buf
|
||||
}
|
||||
};
|
||||
match (warning_node_id, &mut err) {
|
||||
(Some(node_id), &mut None) => {
|
||||
self.sess.add_lint(
|
||||
::lint::builtin::OBJECT_UNSAFE_FRAGMENT,
|
||||
node_id,
|
||||
span,
|
||||
note.to_string());
|
||||
}
|
||||
(None, &mut Some(ref mut err)) => {
|
||||
err.note(note);
|
||||
}
|
||||
_ => unreachable!()
|
||||
}
|
||||
err.note(note);
|
||||
}
|
||||
err
|
||||
}
|
||||
|
@ -57,9 +57,6 @@ pub struct FulfillmentContext<'tcx> {
|
||||
// fulfillment context.
|
||||
predicates: ObligationForest<PendingPredicateObligation<'tcx>>,
|
||||
|
||||
// A list of new obligations due to RFC1592.
|
||||
rfc1592_obligations: Vec<PredicateObligation<'tcx>>,
|
||||
|
||||
// A set of constraints that regionck must validate. Each
|
||||
// constraint has the form `T:'a`, meaning "some type `T` must
|
||||
// outlive the lifetime 'a". These constraints derive from
|
||||
@ -192,7 +189,6 @@ impl<'a, 'gcx, 'tcx> FulfillmentContext<'tcx> {
|
||||
pub fn new() -> FulfillmentContext<'tcx> {
|
||||
FulfillmentContext {
|
||||
predicates: ObligationForest::new(),
|
||||
rfc1592_obligations: Vec::new(),
|
||||
region_obligations: NodeMap(),
|
||||
deferred_obligations: vec![],
|
||||
}
|
||||
@ -275,13 +271,6 @@ impl<'a, 'gcx, 'tcx> FulfillmentContext<'tcx> {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn register_rfc1592_obligation(&mut self,
|
||||
_infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||
obligation: PredicateObligation<'tcx>)
|
||||
{
|
||||
self.rfc1592_obligations.push(obligation);
|
||||
}
|
||||
|
||||
pub fn region_obligations(&self,
|
||||
body_id: ast::NodeId)
|
||||
-> &[RegionObligation<'tcx>]
|
||||
@ -292,21 +281,6 @@ impl<'a, 'gcx, 'tcx> FulfillmentContext<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn select_rfc1592_obligations(&mut self,
|
||||
infcx: &InferCtxt<'a, 'gcx, 'tcx>)
|
||||
-> Result<(),Vec<FulfillmentError<'tcx>>>
|
||||
{
|
||||
while !self.rfc1592_obligations.is_empty() {
|
||||
for obligation in mem::replace(&mut self.rfc1592_obligations, Vec::new()) {
|
||||
self.register_predicate_obligation(infcx, obligation);
|
||||
}
|
||||
|
||||
self.select_all_or_error(infcx)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn select_all_or_error(&mut self,
|
||||
infcx: &InferCtxt<'a, 'gcx, 'tcx>)
|
||||
-> Result<(),Vec<FulfillmentError<'tcx>>>
|
||||
@ -362,7 +336,6 @@ impl<'a, 'gcx, 'tcx> FulfillmentContext<'tcx> {
|
||||
let outcome = self.predicates.process_obligations(&mut FulfillProcessor {
|
||||
selcx: selcx,
|
||||
region_obligations: &mut self.region_obligations,
|
||||
rfc1592_obligations: &mut self.rfc1592_obligations,
|
||||
deferred_obligations: &mut self.deferred_obligations
|
||||
});
|
||||
debug!("select: outcome={:?}", outcome);
|
||||
@ -398,7 +371,6 @@ impl<'a, 'gcx, 'tcx> FulfillmentContext<'tcx> {
|
||||
struct FulfillProcessor<'a, 'b: 'a, 'gcx: 'tcx, 'tcx: 'b> {
|
||||
selcx: &'a mut SelectionContext<'b, 'gcx, 'tcx>,
|
||||
region_obligations: &'a mut NodeMap<Vec<RegionObligation<'tcx>>>,
|
||||
rfc1592_obligations: &'a mut Vec<PredicateObligation<'tcx>>,
|
||||
deferred_obligations: &'a mut Vec<DeferredObligation<'tcx>>
|
||||
}
|
||||
|
||||
@ -413,7 +385,6 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
|
||||
process_predicate(self.selcx,
|
||||
obligation,
|
||||
self.region_obligations,
|
||||
self.rfc1592_obligations,
|
||||
self.deferred_obligations)
|
||||
.map(|os| os.map(|os| os.into_iter().map(|o| PendingPredicateObligation {
|
||||
obligation: o,
|
||||
@ -455,7 +426,6 @@ fn process_predicate<'a, 'gcx, 'tcx>(
|
||||
selcx: &mut SelectionContext<'a, 'gcx, 'tcx>,
|
||||
pending_obligation: &mut PendingPredicateObligation<'tcx>,
|
||||
region_obligations: &mut NodeMap<Vec<RegionObligation<'tcx>>>,
|
||||
rfc1592_obligations: &mut Vec<PredicateObligation<'tcx>>,
|
||||
deferred_obligations: &mut Vec<DeferredObligation<'tcx>>)
|
||||
-> Result<Option<Vec<PredicateObligation<'tcx>>>,
|
||||
FulfillmentErrorCode<'tcx>>
|
||||
@ -644,14 +614,6 @@ fn process_predicate<'a, 'gcx, 'tcx>(
|
||||
s => Ok(s)
|
||||
}
|
||||
}
|
||||
|
||||
ty::Predicate::Rfc1592(ref inner) => {
|
||||
rfc1592_obligations.push(PredicateObligation {
|
||||
predicate: ty::Predicate::clone(inner),
|
||||
..obligation.clone()
|
||||
});
|
||||
Ok(Some(vec![]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
ty::Predicate::TypeOutlives(..) |
|
||||
ty::Predicate::RegionOutlives(..) |
|
||||
ty::Predicate::ClosureKind(..) |
|
||||
ty::Predicate::Rfc1592(..) |
|
||||
ty::Predicate::Equate(..) => {
|
||||
false
|
||||
}
|
||||
@ -184,7 +183,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
}
|
||||
ty::Predicate::Projection(..) |
|
||||
ty::Predicate::Trait(..) |
|
||||
ty::Predicate::Rfc1592(..) |
|
||||
ty::Predicate::Equate(..) |
|
||||
ty::Predicate::RegionOutlives(..) |
|
||||
ty::Predicate::WellFormed(..) |
|
||||
|
@ -513,8 +513,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
|
||||
}
|
||||
|
||||
match obligation.predicate {
|
||||
ty::Predicate::Rfc1592(..) => EvaluatedToOk,
|
||||
|
||||
ty::Predicate::Trait(ref t) => {
|
||||
assert!(!t.has_escaping_regions());
|
||||
let obligation = obligation.with(t.clone());
|
||||
@ -1779,8 +1777,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
|
||||
ty::TyStr | ty::TySlice(_) | ty::TyTrait(..) => Never,
|
||||
|
||||
ty::TyTuple(tys) => {
|
||||
// FIXME(#33242) we only need to constrain the last field
|
||||
Where(ty::Binder(tys.to_vec()))
|
||||
Where(ty::Binder(tys.last().into_iter().cloned().collect()))
|
||||
}
|
||||
|
||||
ty::TyStruct(def, substs) | ty::TyEnum(def, substs) => {
|
||||
@ -2508,12 +2505,11 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
|
||||
|
||||
// T -> Trait.
|
||||
(_, &ty::TyTrait(ref data)) => {
|
||||
let mut object_dids = Some(data.principal.def_id()).into_iter();
|
||||
// FIXME(#33243)
|
||||
// data.builtin_bounds.iter().flat_map(|bound| {
|
||||
// tcx.lang_items.from_builtin_kind(bound).ok()
|
||||
// })
|
||||
// .chain(Some(data.principal.def_id()));
|
||||
let mut object_dids =
|
||||
data.builtin_bounds.iter().flat_map(|bound| {
|
||||
tcx.lang_items.from_builtin_kind(bound).ok()
|
||||
})
|
||||
.chain(Some(data.principal.def_id()));
|
||||
if let Some(did) = object_dids.find(|did| {
|
||||
!tcx.is_object_safe(*did)
|
||||
}) {
|
||||
|
@ -23,9 +23,6 @@ fn anonymize_predicate<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
ty::Predicate::Trait(ref data) =>
|
||||
ty::Predicate::Trait(tcx.anonymize_late_bound_regions(data)),
|
||||
|
||||
ty::Predicate::Rfc1592(ref data) =>
|
||||
ty::Predicate::Rfc1592(Box::new(anonymize_predicate(tcx, data))),
|
||||
|
||||
ty::Predicate::Equate(ref data) =>
|
||||
ty::Predicate::Equate(tcx.anonymize_late_bound_regions(data)),
|
||||
|
||||
@ -150,9 +147,6 @@ impl<'cx, 'gcx, 'tcx> Elaborator<'cx, 'gcx, 'tcx> {
|
||||
|
||||
self.stack.extend(predicates);
|
||||
}
|
||||
ty::Predicate::Rfc1592(..) => {
|
||||
// Nothing to elaborate.
|
||||
}
|
||||
ty::Predicate::WellFormed(..) => {
|
||||
// Currently, we do not elaborate WF predicates,
|
||||
// although we easily could.
|
||||
|
@ -804,9 +804,6 @@ pub enum Predicate<'tcx> {
|
||||
/// would be the type parameters.
|
||||
Trait(PolyTraitPredicate<'tcx>),
|
||||
|
||||
/// A predicate created by RFC1592
|
||||
Rfc1592(Box<Predicate<'tcx>>),
|
||||
|
||||
/// where `T1 == T2`.
|
||||
Equate(PolyEquatePredicate<'tcx>),
|
||||
|
||||
@ -906,8 +903,6 @@ impl<'a, 'gcx, 'tcx> Predicate<'tcx> {
|
||||
match *self {
|
||||
Predicate::Trait(ty::Binder(ref data)) =>
|
||||
Predicate::Trait(ty::Binder(data.subst(tcx, substs))),
|
||||
Predicate::Rfc1592(ref pi) =>
|
||||
Predicate::Rfc1592(Box::new(pi.subst_supertrait(tcx, trait_ref))),
|
||||
Predicate::Equate(ty::Binder(ref data)) =>
|
||||
Predicate::Equate(ty::Binder(data.subst(tcx, substs))),
|
||||
Predicate::RegionOutlives(ty::Binder(ref data)) =>
|
||||
@ -1108,9 +1103,6 @@ impl<'tcx> Predicate<'tcx> {
|
||||
ty::Predicate::Trait(ref data) => {
|
||||
data.skip_binder().input_types().collect()
|
||||
}
|
||||
ty::Predicate::Rfc1592(ref data) => {
|
||||
return data.walk_tys()
|
||||
}
|
||||
ty::Predicate::Equate(ty::Binder(ref data)) => {
|
||||
vec![data.0, data.1]
|
||||
}
|
||||
@ -1148,7 +1140,6 @@ impl<'tcx> Predicate<'tcx> {
|
||||
Predicate::Trait(ref t) => {
|
||||
Some(t.to_poly_trait_ref())
|
||||
}
|
||||
Predicate::Rfc1592(..) |
|
||||
Predicate::Projection(..) |
|
||||
Predicate::Equate(..) |
|
||||
Predicate::RegionOutlives(..) |
|
||||
@ -1820,10 +1811,10 @@ impl<'a, 'tcx> AdtDefData<'tcx, 'tcx> {
|
||||
}
|
||||
|
||||
TyTuple(ref tys) => {
|
||||
// FIXME(#33242) we only need to constrain the last field
|
||||
tys.iter().flat_map(|ty| {
|
||||
self.sized_constraint_for_ty(tcx, stack, ty)
|
||||
}).collect()
|
||||
match tys.last() {
|
||||
None => vec![],
|
||||
Some(ty) => self.sized_constraint_for_ty(tcx, stack, ty)
|
||||
}
|
||||
}
|
||||
|
||||
TyEnum(adt, substs) | TyStruct(adt, substs) => {
|
||||
|
@ -178,9 +178,6 @@ impl<'a, 'tcx> Lift<'tcx> for ty::Predicate<'a> {
|
||||
ty::Predicate::WellFormed(ty) => {
|
||||
tcx.lift(&ty).map(ty::Predicate::WellFormed)
|
||||
}
|
||||
ty::Predicate::Rfc1592(box ref a) => {
|
||||
tcx.lift(a).map(|a| ty::Predicate::Rfc1592(Box::new(a)))
|
||||
}
|
||||
ty::Predicate::ClosureKind(closure_def_id, kind) => {
|
||||
Some(ty::Predicate::ClosureKind(closure_def_id, kind))
|
||||
}
|
||||
@ -790,8 +787,6 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
|
||||
match *self {
|
||||
ty::Predicate::Trait(ref a) =>
|
||||
ty::Predicate::Trait(a.fold_with(folder)),
|
||||
ty::Predicate::Rfc1592(ref a) =>
|
||||
ty::Predicate::Rfc1592(a.fold_with(folder)),
|
||||
ty::Predicate::Equate(ref binder) =>
|
||||
ty::Predicate::Equate(binder.fold_with(folder)),
|
||||
ty::Predicate::RegionOutlives(ref binder) =>
|
||||
@ -812,7 +807,6 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
||||
match *self {
|
||||
ty::Predicate::Trait(ref a) => a.visit_with(visitor),
|
||||
ty::Predicate::Rfc1592(ref a) => a.visit_with(visitor),
|
||||
ty::Predicate::Equate(ref binder) => binder.visit_with(visitor),
|
||||
ty::Predicate::RegionOutlives(ref binder) => binder.visit_with(visitor),
|
||||
ty::Predicate::TypeOutlives(ref binder) => binder.visit_with(visitor),
|
||||
|
@ -318,7 +318,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||
match predicate {
|
||||
ty::Predicate::Projection(..) |
|
||||
ty::Predicate::Trait(..) |
|
||||
ty::Predicate::Rfc1592(..) |
|
||||
ty::Predicate::Equate(..) |
|
||||
ty::Predicate::WellFormed(..) |
|
||||
ty::Predicate::ObjectSafe(..) |
|
||||
|
@ -94,9 +94,6 @@ pub fn predicate_obligations<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
|
||||
}
|
||||
ty::Predicate::ClosureKind(..) => {
|
||||
}
|
||||
ty::Predicate::Rfc1592(ref data) => {
|
||||
bug!("RFC1592 predicate `{:?}` in predicate_obligations", data);
|
||||
}
|
||||
}
|
||||
|
||||
wf.normalize()
|
||||
@ -158,7 +155,6 @@ pub fn implied_bounds<'a, 'gcx, 'tcx>(
|
||||
assert!(!obligation.has_escaping_regions());
|
||||
match obligation.predicate {
|
||||
ty::Predicate::Trait(..) |
|
||||
ty::Predicate::Rfc1592(..) |
|
||||
ty::Predicate::Equate(..) |
|
||||
ty::Predicate::Projection(..) |
|
||||
ty::Predicate::ClosureKind(..) |
|
||||
@ -282,21 +278,14 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn require_sized(&mut self, subty: Ty<'tcx>, cause: traits::ObligationCauseCode<'tcx>,
|
||||
rfc1592: bool) {
|
||||
fn require_sized(&mut self, subty: Ty<'tcx>, cause: traits::ObligationCauseCode<'tcx>) {
|
||||
if !subty.has_escaping_regions() {
|
||||
let cause = self.cause(cause);
|
||||
match self.infcx.tcx.trait_ref_for_builtin_bound(ty::BoundSized, subty) {
|
||||
Ok(trait_ref) => {
|
||||
let predicate = trait_ref.to_predicate();
|
||||
let predicate = if rfc1592 {
|
||||
ty::Predicate::Rfc1592(box predicate)
|
||||
} else {
|
||||
predicate
|
||||
};
|
||||
self.out.push(
|
||||
traits::Obligation::new(cause,
|
||||
predicate));
|
||||
trait_ref.to_predicate()));
|
||||
}
|
||||
Err(ErrorReported) => { }
|
||||
}
|
||||
@ -326,13 +315,13 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> {
|
||||
|
||||
ty::TySlice(subty) |
|
||||
ty::TyArray(subty, _) => {
|
||||
self.require_sized(subty, traits::SliceOrArrayElem, false);
|
||||
self.require_sized(subty, traits::SliceOrArrayElem);
|
||||
}
|
||||
|
||||
ty::TyTuple(ref tys) => {
|
||||
if let Some((_last, rest)) = tys.split_last() {
|
||||
for elem in rest {
|
||||
self.require_sized(elem, traits::TupleElem, true);
|
||||
self.require_sized(elem, traits::TupleElem);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -401,22 +390,15 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> {
|
||||
|
||||
let cause = self.cause(traits::MiscObligation);
|
||||
|
||||
// FIXME(#33243): remove RFC1592
|
||||
self.out.push(traits::Obligation::new(
|
||||
cause.clone(),
|
||||
ty::Predicate::ObjectSafe(data.principal.def_id())
|
||||
));
|
||||
let component_traits =
|
||||
data.builtin_bounds.iter().flat_map(|bound| {
|
||||
tcx.lang_items.from_builtin_kind(bound).ok()
|
||||
});
|
||||
// .chain(Some(data.principal.def_id()));
|
||||
})
|
||||
.chain(Some(data.principal.def_id()));
|
||||
self.out.extend(
|
||||
component_traits.map(|did| { traits::Obligation::new(
|
||||
cause.clone(),
|
||||
ty::Predicate::Rfc1592(
|
||||
box ty::Predicate::ObjectSafe(did)
|
||||
)
|
||||
ty::Predicate::ObjectSafe(did)
|
||||
)})
|
||||
);
|
||||
}
|
||||
|
@ -487,9 +487,6 @@ impl<'tcx> fmt::Debug for ty::Predicate<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
ty::Predicate::Trait(ref a) => write!(f, "{:?}", a),
|
||||
ty::Predicate::Rfc1592(ref a) => {
|
||||
write!(f, "RFC1592({:?})", a)
|
||||
}
|
||||
ty::Predicate::Equate(ref pair) => write!(f, "{:?}", pair),
|
||||
ty::Predicate::RegionOutlives(ref pair) => write!(f, "{:?}", pair),
|
||||
ty::Predicate::TypeOutlives(ref pair) => write!(f, "{:?}", pair),
|
||||
@ -1083,7 +1080,6 @@ impl<'tcx> fmt::Display for ty::Predicate<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
ty::Predicate::Trait(ref data) => write!(f, "{}", data),
|
||||
ty::Predicate::Rfc1592(ref data) => write!(f, "{}", data),
|
||||
ty::Predicate::Equate(ref predicate) => write!(f, "{}", predicate),
|
||||
ty::Predicate::RegionOutlives(ref predicate) => write!(f, "{}", predicate),
|
||||
ty::Predicate::TypeOutlives(ref predicate) => write!(f, "{}", predicate),
|
||||
|
@ -191,14 +191,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
|
||||
id: LintId::of(ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN),
|
||||
reference: "RFC 1445 <https://github.com/rust-lang/rfcs/pull/1445>",
|
||||
},
|
||||
FutureIncompatibleInfo {
|
||||
id: LintId::of(UNSIZED_IN_TUPLE),
|
||||
reference: "issue #33242 <https://github.com/rust-lang/rust/issues/33242>",
|
||||
},
|
||||
FutureIncompatibleInfo {
|
||||
id: LintId::of(OBJECT_UNSAFE_FRAGMENT),
|
||||
reference: "issue #33243 <https://github.com/rust-lang/rust/issues/33243>",
|
||||
},
|
||||
FutureIncompatibleInfo {
|
||||
id: LintId::of(HR_LIFETIME_IN_ASSOC_TYPE),
|
||||
reference: "issue #33685 <https://github.com/rust-lang/rust/issues/33685>",
|
||||
|
@ -479,9 +479,6 @@ pub fn enc_predicate<'a, 'tcx>(w: &mut Cursor<Vec<u8>>,
|
||||
p: &ty::Predicate<'tcx>)
|
||||
{
|
||||
match *p {
|
||||
ty::Predicate::Rfc1592(..) => {
|
||||
bug!("RFC1592 predicate in metadata `{:?}`", p);
|
||||
}
|
||||
ty::Predicate::Trait(ref trait_ref) => {
|
||||
write!(w, "t");
|
||||
enc_trait_ref(w, cx, trait_ref.0.trait_ref);
|
||||
|
@ -1019,10 +1019,6 @@ impl<'tcx> MirMapPass<'tcx> for QualifyAndPromoteConstants {
|
||||
if let Err(err) = fulfillment_cx.select_all_or_error(&infcx) {
|
||||
infcx.report_fulfillment_errors(&err);
|
||||
}
|
||||
|
||||
if let Err(errors) = fulfillment_cx.select_rfc1592_obligations(&infcx) {
|
||||
infcx.report_fulfillment_errors_as_warnings(&errors, id);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1128,8 +1128,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
||||
tcx.astconv_object_safety_violations(principal.def_id());
|
||||
if !object_safety_violations.is_empty() {
|
||||
tcx.report_object_safety_error(
|
||||
span, principal.def_id(), None, object_safety_violations)
|
||||
.unwrap().emit();
|
||||
span, principal.def_id(), object_safety_violations)
|
||||
.emit();
|
||||
return tcx.types.err;
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
ty::Predicate::TypeOutlives(..) => None,
|
||||
ty::Predicate::WellFormed(..) => None,
|
||||
ty::Predicate::ObjectSafe(..) => None,
|
||||
ty::Predicate::Rfc1592(..) => None,
|
||||
|
||||
// NB: This predicate is created by breaking down a
|
||||
// `ClosureType: FnFoo()` predicate, where
|
||||
|
@ -484,7 +484,7 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> {
|
||||
|
||||
// Object safety violations or miscellaneous.
|
||||
Err(err) => {
|
||||
self.report_selection_error(&obligation, &err, None);
|
||||
self.report_selection_error(&obligation, &err);
|
||||
// Treat this like an obligation and follow through
|
||||
// with the unsizing - the lack of a coercion should
|
||||
// be silent, as it causes a type mismatch later.
|
||||
|
@ -111,10 +111,6 @@ fn ensure_drop_params_and_item_params_correspond<'a, 'tcx>(
|
||||
return Err(());
|
||||
}
|
||||
|
||||
if let Err(ref errors) = fulfillment_cx.select_rfc1592_obligations(&infcx) {
|
||||
infcx.report_fulfillment_errors_as_warnings(errors, drop_impl_node_id);
|
||||
}
|
||||
|
||||
let free_regions = FreeRegionMap::new();
|
||||
infcx.resolve_regions_and_report_errors(&free_regions, drop_impl_node_id);
|
||||
Ok(())
|
||||
|
@ -496,7 +496,6 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
|
||||
ty::Predicate::WellFormed(..) |
|
||||
ty::Predicate::ObjectSafe(..) |
|
||||
ty::Predicate::ClosureKind(..) |
|
||||
ty::Predicate::Rfc1592(..) |
|
||||
ty::Predicate::TypeOutlives(..) => {
|
||||
None
|
||||
}
|
||||
|
@ -505,10 +505,6 @@ pub fn check_item_bodies(ccx: &CrateCtxt) -> CompileResult {
|
||||
if let Err(errors) = fulfillment_cx.select_all_or_error(&infcx) {
|
||||
infcx.report_fulfillment_errors(&errors);
|
||||
}
|
||||
|
||||
if let Err(errors) = fulfillment_cx.select_rfc1592_obligations(&infcx) {
|
||||
infcx.report_fulfillment_errors_as_warnings(&errors, item_id);
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
@ -2245,10 +2241,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
Ok(()) => { }
|
||||
Err(errors) => { self.report_fulfillment_errors(&errors); }
|
||||
}
|
||||
|
||||
if let Err(ref errors) = fulfillment_cx.select_rfc1592_obligations(self) {
|
||||
self.report_fulfillment_errors_as_warnings(errors, self.body_id);
|
||||
}
|
||||
}
|
||||
|
||||
/// Select as many obligations as we can at present.
|
||||
|
@ -477,7 +477,6 @@ impl<'tcx> GetTypeParameterBounds<'tcx> for ty::GenericPredicates<'tcx> {
|
||||
ty::Predicate::TypeOutlives(ref data) => {
|
||||
data.skip_binder().0.is_param(def.index)
|
||||
}
|
||||
ty::Predicate::Rfc1592(..) |
|
||||
ty::Predicate::Equate(..) |
|
||||
ty::Predicate::RegionOutlives(..) |
|
||||
ty::Predicate::WellFormed(..) |
|
||||
|
@ -858,7 +858,6 @@ impl<'a> Clean<WherePredicate> for ty::Predicate<'a> {
|
||||
Predicate::WellFormed(_) => panic!("not user writable"),
|
||||
Predicate::ObjectSafe(_) => panic!("not user writable"),
|
||||
Predicate::ClosureKind(..) => panic!("not user writable"),
|
||||
Predicate::Rfc1592(..) => panic!("not user writable"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,5 +13,7 @@ trait Trait {}
|
||||
pub fn main() {
|
||||
let x: Vec<Trait + Sized> = Vec::new();
|
||||
//~^ ERROR `Trait + Sized: std::marker::Sized` is not satisfied
|
||||
//~| ERROR the trait `std::marker::Sized` cannot be made into an object
|
||||
//~| ERROR `Trait + Sized: std::marker::Sized` is not satisfied
|
||||
//~| ERROR the trait `std::marker::Sized` cannot be made into an object
|
||||
}
|
||||
|
@ -17,4 +17,5 @@ fn size_of_copy<T: Copy+?Sized>() -> usize { mem::size_of::<T>() }
|
||||
fn main() {
|
||||
size_of_copy::<Misc+Copy>();
|
||||
//~^ ERROR `Misc + Copy: std::marker::Copy` is not satisfied
|
||||
//~| ERROR the trait `std::marker::Copy` cannot be made into an object
|
||||
}
|
||||
|
@ -1,32 +0,0 @@
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::fmt;
|
||||
|
||||
#[deny(warnings)] trait Foo { fn foo(&self) -> (Self, Self); }
|
||||
//~^ ERROR the trait bound `Self: std::marker::Sized` is not satisfied
|
||||
//~| WARNING hard error
|
||||
|
||||
impl<T: Copy> Foo for T {
|
||||
fn foo(&self) -> (Self, Self) {
|
||||
(*self, *self)
|
||||
}
|
||||
}
|
||||
|
||||
#[deny(warnings)]
|
||||
fn main() {
|
||||
assert_eq!((11).foo(), (11, 11));
|
||||
|
||||
let junk: Box<fmt::Debug+Sized> = Box::new(42);
|
||||
//~^ ERROR the trait cannot require that `Self : Sized`
|
||||
//~| WARNING hard error
|
||||
let f = format!("{:?}", junk);
|
||||
assert_eq!(f, "42");
|
||||
}
|
@ -14,9 +14,9 @@ trait T {}
|
||||
|
||||
fn f1<X: ?Sized>(x: &X) {
|
||||
let _: X; // <-- this is OK, no bindings created, no initializer.
|
||||
let _: (isize, (X, isize));
|
||||
let _: (isize, (X, isize)); //~ERROR `X: std::marker::Sized` is not satisfie
|
||||
let y: X; //~ERROR `X: std::marker::Sized` is not satisfied
|
||||
let y: (isize, (X, usize)); //~ERROR `X: std::marker::Sized` is not satisfied
|
||||
let y: (isize, (X, usize));
|
||||
}
|
||||
fn f2<X: ?Sized + T>(x: &X) {
|
||||
let y: X; //~ERROR `X: std::marker::Sized` is not satisfied
|
||||
|
@ -1,29 +0,0 @@
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::fmt;
|
||||
|
||||
trait Foo {
|
||||
fn foo(&self) -> (Self, Self);
|
||||
}
|
||||
|
||||
impl<T: Copy> Foo for T {
|
||||
fn foo(&self) -> (Self, Self) {
|
||||
(*self, *self)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_eq!((11).foo(), (11, 11));
|
||||
|
||||
let junk: Box<fmt::Debug+Sized> = Box::new(42);
|
||||
let f = format!("{:?}", junk);
|
||||
assert_eq!(f, "42");
|
||||
}
|
Loading…
Reference in New Issue
Block a user