Skip to content

Commit 147371f

Browse files
authored
Auto merge of #34982 - arielb1:bad-tuples-and-objects, r=nikomatsakis
Turn the RFC1592 warnings into hard errors The warnings have already reached stable, and I want to improve the trait error reporting code. Turning warnings into errors, this is obviously a [breaking-change]. r? @nikomatsakis cc @rust-lang/compiler
2 parents b2799a5 + 7b92d05 commit 147371f

File tree

28 files changed

+50
-314
lines changed

28 files changed

+50
-314
lines changed

src/librustc/lint/builtin.rs

-14
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,6 @@ declare_lint! {
186186
"detects super or self keywords at the beginning of global path"
187187
}
188188

189-
declare_lint! {
190-
pub UNSIZED_IN_TUPLE,
191-
Warn,
192-
"unsized types in the interior of a tuple were erroneously allowed"
193-
}
194-
195-
declare_lint! {
196-
pub OBJECT_UNSAFE_FRAGMENT,
197-
Warn,
198-
"object-unsafe non-principal fragments in object types were erroneously allowed"
199-
}
200-
201189
declare_lint! {
202190
pub LIFETIME_UNDERSCORE,
203191
Warn,
@@ -239,8 +227,6 @@ impl LintPass for HardwiredLints {
239227
OVERLAPPING_INHERENT_IMPLS,
240228
RENAMED_AND_REMOVED_LINTS,
241229
SUPER_OR_SELF_IN_GLOBAL_PATH,
242-
UNSIZED_IN_TUPLE,
243-
OBJECT_UNSAFE_FRAGMENT,
244230
HR_LIFETIME_IN_ASSOC_TYPE,
245231
LIFETIME_UNDERSCORE
246232
)

src/librustc/middle/free_region.rs

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ impl FreeRegionMap {
5555
match *predicate {
5656
ty::Predicate::Projection(..) |
5757
ty::Predicate::Trait(..) |
58-
ty::Predicate::Rfc1592(..) |
5958
ty::Predicate::Equate(..) |
6059
ty::Predicate::WellFormed(..) |
6160
ty::Predicate::ObjectSafe(..) |

src/librustc/traits/error_reporting.rs

+25-97
Original file line numberDiff line numberDiff line change
@@ -36,50 +36,37 @@ use util::nodemap::{FnvHashMap, FnvHashSet};
3636

3737
use std::cmp;
3838
use std::fmt;
39-
use syntax::ast;
4039
use syntax_pos::Span;
4140
use errors::DiagnosticBuilder;
4241

4342
#[derive(Debug, PartialEq, Eq, Hash)]
4443
pub struct TraitErrorKey<'tcx> {
4544
span: Span,
46-
warning_node_id: Option<ast::NodeId>,
4745
predicate: ty::Predicate<'tcx>
4846
}
4947

5048
impl<'a, 'gcx, 'tcx> TraitErrorKey<'tcx> {
5149
fn from_error(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
52-
e: &FulfillmentError<'tcx>,
53-
warning_node_id: Option<ast::NodeId>) -> Self {
50+
e: &FulfillmentError<'tcx>) -> Self {
5451
let predicate =
5552
infcx.resolve_type_vars_if_possible(&e.obligation.predicate);
5653
TraitErrorKey {
5754
span: e.obligation.cause.span,
58-
predicate: infcx.tcx.erase_regions(&predicate),
59-
warning_node_id: warning_node_id
55+
predicate: infcx.tcx.erase_regions(&predicate)
6056
}
6157
}
6258
}
6359

6460
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
6561
pub fn report_fulfillment_errors(&self, errors: &Vec<FulfillmentError<'tcx>>) {
6662
for error in errors {
67-
self.report_fulfillment_error(error, None);
68-
}
69-
}
70-
71-
pub fn report_fulfillment_errors_as_warnings(&self,
72-
errors: &Vec<FulfillmentError<'tcx>>,
73-
node_id: ast::NodeId) {
74-
for error in errors {
75-
self.report_fulfillment_error(error, Some(node_id));
63+
self.report_fulfillment_error(error);
7664
}
7765
}
7866

7967
fn report_fulfillment_error(&self,
80-
error: &FulfillmentError<'tcx>,
81-
warning_node_id: Option<ast::NodeId>) {
82-
let error_key = TraitErrorKey::from_error(self, error, warning_node_id);
68+
error: &FulfillmentError<'tcx>) {
69+
let error_key = TraitErrorKey::from_error(self, error);
8370
debug!("report_fulfillment_errors({:?}) - key={:?}",
8471
error, error_key);
8572
if !self.reported_trait_errors.borrow_mut().insert(error_key) {
@@ -88,10 +75,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
8875
}
8976
match error.code {
9077
FulfillmentErrorCode::CodeSelectionError(ref e) => {
91-
self.report_selection_error(&error.obligation, e, warning_node_id);
78+
self.report_selection_error(&error.obligation, e);
9279
}
9380
FulfillmentErrorCode::CodeProjectionError(ref e) => {
94-
self.report_projection_error(&error.obligation, e, warning_node_id);
81+
self.report_projection_error(&error.obligation, e);
9582
}
9683
FulfillmentErrorCode::CodeAmbiguity => {
9784
self.maybe_report_ambiguity(&error.obligation);
@@ -101,25 +88,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10188

10289
fn report_projection_error(&self,
10390
obligation: &PredicateObligation<'tcx>,
104-
error: &MismatchedProjectionTypes<'tcx>,
105-
warning_node_id: Option<ast::NodeId>)
91+
error: &MismatchedProjectionTypes<'tcx>)
10692
{
10793
let predicate =
10894
self.resolve_type_vars_if_possible(&obligation.predicate);
10995

11096
if predicate.references_error() {
11197
return
11298
}
113-
if let Some(warning_node_id) = warning_node_id {
114-
self.tcx.sess.add_lint(
115-
::lint::builtin::UNSIZED_IN_TUPLE,
116-
warning_node_id,
117-
obligation.cause.span,
118-
format!("type mismatch resolving `{}`: {}",
119-
predicate,
120-
error.err));
121-
return
122-
}
99+
123100
self.probe(|_| {
124101
let origin = TypeOrigin::Misc(obligation.cause.span);
125102
let err_buf;
@@ -442,8 +419,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
442419

443420
pub fn report_selection_error(&self,
444421
obligation: &PredicateObligation<'tcx>,
445-
error: &SelectionError<'tcx>,
446-
warning_node_id: Option<ast::NodeId>)
422+
error: &SelectionError<'tcx>)
447423
{
448424
let span = obligation.cause.span;
449425
let mut err = match *error {
@@ -466,16 +442,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
466442
} else {
467443
let trait_ref = trait_predicate.to_poly_trait_ref();
468444

469-
if let Some(warning_node_id) = warning_node_id {
470-
self.tcx.sess.add_lint(
471-
::lint::builtin::UNSIZED_IN_TUPLE,
472-
warning_node_id,
473-
obligation.cause.span,
474-
format!("the trait bound `{}` is not satisfied",
475-
trait_ref.to_predicate()));
476-
return;
477-
}
478-
479445
let mut err = struct_span_err!(self.tcx.sess, span, E0277,
480446
"the trait bound `{}` is not satisfied",
481447
trait_ref.to_predicate());
@@ -541,15 +507,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
541507

542508
ty::Predicate::ObjectSafe(trait_def_id) => {
543509
let violations = self.tcx.object_safety_violations(trait_def_id);
544-
let err = self.tcx.report_object_safety_error(span,
545-
trait_def_id,
546-
warning_node_id,
547-
violations);
548-
if let Some(err) = err {
549-
err
550-
} else {
551-
return;
552-
}
510+
self.tcx.report_object_safety_error(span,
511+
trait_def_id,
512+
violations)
553513
}
554514

555515
ty::Predicate::ClosureKind(closure_def_id, kind) => {
@@ -577,13 +537,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
577537
// (which may fail).
578538
span_bug!(span, "WF predicate not satisfied for {:?}", ty);
579539
}
580-
581-
ty::Predicate::Rfc1592(ref data) => {
582-
span_bug!(
583-
obligation.cause.span,
584-
"RFC1592 predicate not satisfied for {:?}",
585-
data);
586-
}
587540
}
588541
}
589542
}
@@ -605,14 +558,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
605558

606559
TraitNotObjectSafe(did) => {
607560
let violations = self.tcx.object_safety_violations(did);
608-
let err = self.tcx.report_object_safety_error(span, did,
609-
warning_node_id,
610-
violations);
611-
if let Some(err) = err {
612-
err
613-
} else {
614-
return;
615-
}
561+
self.tcx.report_object_safety_error(span, did,
562+
violations)
616563
}
617564
};
618565
self.note_obligation_cause(&mut err, obligation);
@@ -640,24 +587,17 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
640587
pub fn report_object_safety_error(self,
641588
span: Span,
642589
trait_def_id: DefId,
643-
warning_node_id: Option<ast::NodeId>,
644590
violations: Vec<ObjectSafetyViolation>)
645-
-> Option<DiagnosticBuilder<'tcx>>
591+
-> DiagnosticBuilder<'tcx>
646592
{
647-
let mut err = match warning_node_id {
648-
Some(_) => None,
649-
None => {
650-
let trait_str = self.item_path_str(trait_def_id);
651-
let mut db = struct_span_err!(
652-
self.sess, span, E0038,
653-
"the trait `{}` cannot be made into an object",
654-
trait_str);
655-
db.span_label(span,
656-
&format!("the trait `{}` cannot be made \
657-
into an object", trait_str));
658-
Some(db)
659-
}
660-
};
593+
let trait_str = self.item_path_str(trait_def_id);
594+
let mut err = struct_span_err!(
595+
self.sess, span, E0038,
596+
"the trait `{}` cannot be made into an object",
597+
trait_str);
598+
err.span_label(span, &format!(
599+
"the trait `{}` cannot be made into an object", trait_str
600+
));
661601

662602
let mut reported_violations = FnvHashSet();
663603
for violation in violations {
@@ -697,19 +637,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
697637
&buf
698638
}
699639
};
700-
match (warning_node_id, &mut err) {
701-
(Some(node_id), &mut None) => {
702-
self.sess.add_lint(
703-
::lint::builtin::OBJECT_UNSAFE_FRAGMENT,
704-
node_id,
705-
span,
706-
note.to_string());
707-
}
708-
(None, &mut Some(ref mut err)) => {
709-
err.note(note);
710-
}
711-
_ => unreachable!()
712-
}
640+
err.note(note);
713641
}
714642
err
715643
}

src/librustc/traits/fulfill.rs

-38
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ pub struct FulfillmentContext<'tcx> {
5757
// fulfillment context.
5858
predicates: ObligationForest<PendingPredicateObligation<'tcx>>,
5959

60-
// A list of new obligations due to RFC1592.
61-
rfc1592_obligations: Vec<PredicateObligation<'tcx>>,
62-
6360
// A set of constraints that regionck must validate. Each
6461
// constraint has the form `T:'a`, meaning "some type `T` must
6562
// outlive the lifetime 'a". These constraints derive from
@@ -192,7 +189,6 @@ impl<'a, 'gcx, 'tcx> FulfillmentContext<'tcx> {
192189
pub fn new() -> FulfillmentContext<'tcx> {
193190
FulfillmentContext {
194191
predicates: ObligationForest::new(),
195-
rfc1592_obligations: Vec::new(),
196192
region_obligations: NodeMap(),
197193
deferred_obligations: vec![],
198194
}
@@ -275,13 +271,6 @@ impl<'a, 'gcx, 'tcx> FulfillmentContext<'tcx> {
275271
});
276272
}
277273

278-
pub fn register_rfc1592_obligation(&mut self,
279-
_infcx: &InferCtxt<'a, 'gcx, 'tcx>,
280-
obligation: PredicateObligation<'tcx>)
281-
{
282-
self.rfc1592_obligations.push(obligation);
283-
}
284-
285274
pub fn region_obligations(&self,
286275
body_id: ast::NodeId)
287276
-> &[RegionObligation<'tcx>]
@@ -292,21 +281,6 @@ impl<'a, 'gcx, 'tcx> FulfillmentContext<'tcx> {
292281
}
293282
}
294283

295-
pub fn select_rfc1592_obligations(&mut self,
296-
infcx: &InferCtxt<'a, 'gcx, 'tcx>)
297-
-> Result<(),Vec<FulfillmentError<'tcx>>>
298-
{
299-
while !self.rfc1592_obligations.is_empty() {
300-
for obligation in mem::replace(&mut self.rfc1592_obligations, Vec::new()) {
301-
self.register_predicate_obligation(infcx, obligation);
302-
}
303-
304-
self.select_all_or_error(infcx)?;
305-
}
306-
307-
Ok(())
308-
}
309-
310284
pub fn select_all_or_error(&mut self,
311285
infcx: &InferCtxt<'a, 'gcx, 'tcx>)
312286
-> Result<(),Vec<FulfillmentError<'tcx>>>
@@ -362,7 +336,6 @@ impl<'a, 'gcx, 'tcx> FulfillmentContext<'tcx> {
362336
let outcome = self.predicates.process_obligations(&mut FulfillProcessor {
363337
selcx: selcx,
364338
region_obligations: &mut self.region_obligations,
365-
rfc1592_obligations: &mut self.rfc1592_obligations,
366339
deferred_obligations: &mut self.deferred_obligations
367340
});
368341
debug!("select: outcome={:?}", outcome);
@@ -398,7 +371,6 @@ impl<'a, 'gcx, 'tcx> FulfillmentContext<'tcx> {
398371
struct FulfillProcessor<'a, 'b: 'a, 'gcx: 'tcx, 'tcx: 'b> {
399372
selcx: &'a mut SelectionContext<'b, 'gcx, 'tcx>,
400373
region_obligations: &'a mut NodeMap<Vec<RegionObligation<'tcx>>>,
401-
rfc1592_obligations: &'a mut Vec<PredicateObligation<'tcx>>,
402374
deferred_obligations: &'a mut Vec<DeferredObligation<'tcx>>
403375
}
404376

@@ -413,7 +385,6 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
413385
process_predicate(self.selcx,
414386
obligation,
415387
self.region_obligations,
416-
self.rfc1592_obligations,
417388
self.deferred_obligations)
418389
.map(|os| os.map(|os| os.into_iter().map(|o| PendingPredicateObligation {
419390
obligation: o,
@@ -455,7 +426,6 @@ fn process_predicate<'a, 'gcx, 'tcx>(
455426
selcx: &mut SelectionContext<'a, 'gcx, 'tcx>,
456427
pending_obligation: &mut PendingPredicateObligation<'tcx>,
457428
region_obligations: &mut NodeMap<Vec<RegionObligation<'tcx>>>,
458-
rfc1592_obligations: &mut Vec<PredicateObligation<'tcx>>,
459429
deferred_obligations: &mut Vec<DeferredObligation<'tcx>>)
460430
-> Result<Option<Vec<PredicateObligation<'tcx>>>,
461431
FulfillmentErrorCode<'tcx>>
@@ -644,14 +614,6 @@ fn process_predicate<'a, 'gcx, 'tcx>(
644614
s => Ok(s)
645615
}
646616
}
647-
648-
ty::Predicate::Rfc1592(ref inner) => {
649-
rfc1592_obligations.push(PredicateObligation {
650-
predicate: ty::Predicate::clone(inner),
651-
..obligation.clone()
652-
});
653-
Ok(Some(vec![]))
654-
}
655617
}
656618
}
657619

src/librustc/traits/object_safety.rs

-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
153153
ty::Predicate::TypeOutlives(..) |
154154
ty::Predicate::RegionOutlives(..) |
155155
ty::Predicate::ClosureKind(..) |
156-
ty::Predicate::Rfc1592(..) |
157156
ty::Predicate::Equate(..) => {
158157
false
159158
}
@@ -184,7 +183,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
184183
}
185184
ty::Predicate::Projection(..) |
186185
ty::Predicate::Trait(..) |
187-
ty::Predicate::Rfc1592(..) |
188186
ty::Predicate::Equate(..) |
189187
ty::Predicate::RegionOutlives(..) |
190188
ty::Predicate::WellFormed(..) |

0 commit comments

Comments
 (0)