Skip to content

Commit 0d78e40

Browse files
committed
convert EXTRA_REQUIREMENT_IN_IMPL into a hard error
cc rust-lang#37166
1 parent 64206b4 commit 0d78e40

File tree

11 files changed

+21
-93
lines changed

11 files changed

+21
-93
lines changed

src/librustc/infer/error_reporting/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -880,14 +880,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
880880
};
881881

882882
if let SubregionOrigin::CompareImplMethodObligation {
883-
span, item_name, impl_item_def_id, trait_item_def_id, lint_id
883+
span, item_name, impl_item_def_id, trait_item_def_id,
884884
} = origin {
885885
self.report_extra_impl_obligation(span,
886886
item_name,
887887
impl_item_def_id,
888888
trait_item_def_id,
889-
&format!("`{}: {}`", bound_kind, sub),
890-
lint_id)
889+
&format!("`{}: {}`", bound_kind, sub))
891890
.emit();
892891
return;
893892
}

src/librustc/infer/error_reporting/note.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -445,14 +445,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
445445
infer::CompareImplMethodObligation { span,
446446
item_name,
447447
impl_item_def_id,
448-
trait_item_def_id,
449-
lint_id } => {
448+
trait_item_def_id } => {
450449
self.report_extra_impl_obligation(span,
451450
item_name,
452451
impl_item_def_id,
453452
trait_item_def_id,
454-
&format!("`{}: {}`", sup, sub),
455-
lint_id)
453+
&format!("`{}: {}`", sup, sub))
456454
}
457455
}
458456
}

src/librustc/infer/mod.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,6 @@ pub enum SubregionOrigin<'tcx> {
274274
item_name: ast::Name,
275275
impl_item_def_id: DefId,
276276
trait_item_def_id: DefId,
277-
278-
// this is `Some(_)` if this error arises from the bug fix for
279-
// #18937. This is a temporary measure.
280-
lint_id: Option<ast::NodeId>,
281277
},
282278
}
283279

@@ -1532,14 +1528,12 @@ impl<'tcx> SubregionOrigin<'tcx> {
15321528

15331529
traits::ObligationCauseCode::CompareImplMethodObligation { item_name,
15341530
impl_item_def_id,
1535-
trait_item_def_id,
1536-
lint_id } =>
1531+
trait_item_def_id, } =>
15371532
SubregionOrigin::CompareImplMethodObligation {
15381533
span: cause.span,
15391534
item_name,
15401535
impl_item_def_id,
15411536
trait_item_def_id,
1542-
lint_id,
15431537
},
15441538

15451539
_ => default(),

src/librustc/lint/builtin.rs

-7
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,6 @@ declare_lint! {
161161
"patterns in functions without body were erroneously allowed"
162162
}
163163

164-
declare_lint! {
165-
pub EXTRA_REQUIREMENT_IN_IMPL,
166-
Deny,
167-
"detects extra requirements in impls that were erroneously allowed"
168-
}
169-
170164
declare_lint! {
171165
pub LEGACY_DIRECTORY_OWNERSHIP,
172166
Deny,
@@ -254,7 +248,6 @@ impl LintPass for HardwiredLints {
254248
RESOLVE_TRAIT_ON_DEFAULTED_UNIT,
255249
SAFE_EXTERN_STATICS,
256250
PATTERNS_IN_FNS_WITHOUT_BODY,
257-
EXTRA_REQUIREMENT_IN_IMPL,
258251
LEGACY_DIRECTORY_OWNERSHIP,
259252
LEGACY_IMPORTS,
260253
LEGACY_CONSTRUCTOR_VISIBILITY,

src/librustc/traits/error_reporting.rs

+7-25
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use hir::def_id::DefId;
3333
use infer::{self, InferCtxt};
3434
use infer::type_variable::TypeVariableOrigin;
3535
use middle::const_val;
36-
use rustc::lint::builtin::EXTRA_REQUIREMENT_IN_IMPL;
3736
use std::fmt;
3837
use syntax::ast;
3938
use session::DiagnosticMessageId;
@@ -481,30 +480,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
481480
item_name: ast::Name,
482481
_impl_item_def_id: DefId,
483482
trait_item_def_id: DefId,
484-
requirement: &fmt::Display,
485-
lint_id: Option<ast::NodeId>) // (*)
483+
requirement: &fmt::Display)
486484
-> DiagnosticBuilder<'tcx>
487485
{
488-
// (*) This parameter is temporary and used only for phasing
489-
// in the bug fix to #18937. If it is `Some`, it has a kind of
490-
// weird effect -- the diagnostic is reported as a lint, and
491-
// the builder which is returned is marked as canceled.
492-
493486
let msg = "impl has stricter requirements than trait";
494-
let mut err = match lint_id {
495-
Some(node_id) => {
496-
self.tcx.struct_span_lint_node(EXTRA_REQUIREMENT_IN_IMPL,
497-
node_id,
498-
error_span,
499-
msg)
500-
}
501-
None => {
502-
struct_span_err!(self.tcx.sess,
503-
error_span,
504-
E0276,
505-
"{}", msg)
506-
}
507-
};
487+
let mut err = struct_span_err!(self.tcx.sess,
488+
error_span,
489+
E0276,
490+
"{}", msg);
508491

509492
if let Some(trait_item_span) = self.tcx.hir.span_if_local(trait_item_def_id) {
510493
let span = self.tcx.sess.codemap().def_span(trait_item_span);
@@ -543,15 +526,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
543526
let mut err = match *error {
544527
SelectionError::Unimplemented => {
545528
if let ObligationCauseCode::CompareImplMethodObligation {
546-
item_name, impl_item_def_id, trait_item_def_id, lint_id
529+
item_name, impl_item_def_id, trait_item_def_id,
547530
} = obligation.cause.code {
548531
self.report_extra_impl_obligation(
549532
span,
550533
item_name,
551534
impl_item_def_id,
552535
trait_item_def_id,
553-
&format!("`{}`", obligation.predicate),
554-
lint_id)
536+
&format!("`{}`", obligation.predicate))
555537
.emit();
556538
return;
557539
}

src/librustc/traits/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ pub enum ObligationCauseCode<'tcx> {
152152
item_name: ast::Name,
153153
impl_item_def_id: DefId,
154154
trait_item_def_id: DefId,
155-
lint_id: Option<ast::NodeId>,
156155
},
157156

158157
/// Checking that this expression can be assigned where it needs to be

src/librustc/traits/structural_impls.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,11 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
214214
}
215215
super::CompareImplMethodObligation { item_name,
216216
impl_item_def_id,
217-
trait_item_def_id,
218-
lint_id } => {
217+
trait_item_def_id } => {
219218
Some(super::CompareImplMethodObligation {
220219
item_name,
221220
impl_item_def_id,
222221
trait_item_def_id,
223-
lint_id,
224222
})
225223
}
226224
super::ExprAssignable => Some(super::ExprAssignable),

src/librustc_lint/lib.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
207207
id: LintId::of(INVALID_TYPE_PARAM_DEFAULT),
208208
reference: "issue #36887 <https://github.com/rust-lang/rust/issues/36887>",
209209
},
210-
FutureIncompatibleInfo {
211-
id: LintId::of(EXTRA_REQUIREMENT_IN_IMPL),
212-
reference: "issue #37166 <https://github.com/rust-lang/rust/issues/37166>",
213-
},
214210
FutureIncompatibleInfo {
215211
id: LintId::of(LEGACY_DIRECTORY_OWNERSHIP),
216212
reference: "issue #37872 <https://github.com/rust-lang/rust/issues/37872>",
@@ -276,4 +272,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
276272
"converted into hard error, see https://github.com/rust-lang/rust/issues/36891");
277273
store.register_removed("lifetime_underscore",
278274
"converted into hard error, see https://github.com/rust-lang/rust/issues/36892");
275+
store.register_removed("extra_requirement_in_impl",
276+
"converted into hard error, see https://github.com/rust-lang/rust/issues/37166");
279277
}

src/librustc_typeck/check/compare_method.rs

+5-25
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
use rustc::hir::{self, ImplItemKind, TraitItemKind};
1212
use rustc::infer::{self, InferOk};
13-
use rustc::middle::free_region::FreeRegionMap;
14-
use rustc::middle::region;
1513
use rustc::ty::{self, TyCtxt};
1614
use rustc::ty::util::ExplicitSelf;
1715
use rustc::traits::{self, ObligationCause, ObligationCauseCode, Reveal};
@@ -38,8 +36,7 @@ pub fn compare_impl_method<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
3836
impl_m_span: Span,
3937
trait_m: &ty::AssociatedItem,
4038
impl_trait_ref: ty::TraitRef<'tcx>,
41-
trait_item_span: Option<Span>,
42-
old_broken_mode: bool) {
39+
trait_item_span: Option<Span>) {
4340
debug!("compare_impl_method(impl_trait_ref={:?})",
4441
impl_trait_ref);
4542

@@ -71,8 +68,7 @@ pub fn compare_impl_method<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
7168
impl_m,
7269
impl_m_span,
7370
trait_m,
74-
impl_trait_ref,
75-
old_broken_mode) {
71+
impl_trait_ref) {
7672
return;
7773
}
7874
}
@@ -81,8 +77,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
8177
impl_m: &ty::AssociatedItem,
8278
impl_m_span: Span,
8379
trait_m: &ty::AssociatedItem,
84-
impl_trait_ref: ty::TraitRef<'tcx>,
85-
old_broken_mode: bool)
80+
impl_trait_ref: ty::TraitRef<'tcx>)
8681
-> Result<(), ErrorReported> {
8782
let trait_to_impl_substs = impl_trait_ref.substs;
8883

@@ -98,7 +93,6 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
9893
item_name: impl_m.name,
9994
impl_item_def_id: impl_m.def_id,
10095
trait_item_def_id: trait_m.def_id,
101-
lint_id: if !old_broken_mode { Some(impl_m_node_id) } else { None },
10296
},
10397
};
10498

@@ -334,22 +328,8 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
334328

335329
// Finally, resolve all regions. This catches wily misuses of
336330
// lifetime parameters.
337-
if old_broken_mode {
338-
// FIXME(#18937) -- this is how the code used to
339-
// work. This is buggy because the fulfillment cx creates
340-
// region obligations that get overlooked. The right
341-
// thing to do is the code below. But we keep this old
342-
// pass around temporarily.
343-
let region_scope_tree = region::ScopeTree::default();
344-
let mut free_regions = FreeRegionMap::new();
345-
free_regions.relate_free_regions_from_predicates(&param_env.caller_bounds);
346-
infcx.resolve_regions_and_report_errors(impl_m.def_id,
347-
&region_scope_tree,
348-
&free_regions);
349-
} else {
350-
let fcx = FnCtxt::new(&inh, param_env, impl_m_node_id);
351-
fcx.regionck_item(impl_m_node_id, impl_m_span, &[]);
352-
}
331+
let fcx = FnCtxt::new(&inh, param_env, impl_m_node_id);
332+
fcx.regionck_item(impl_m_node_id, impl_m_span, &[]);
353333

354334
Ok(())
355335
})

src/librustc_typeck/check/mod.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -1339,24 +1339,12 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
13391339
hir::ImplItemKind::Method(..) => {
13401340
let trait_span = tcx.hir.span_if_local(ty_trait_item.def_id);
13411341
if ty_trait_item.kind == ty::AssociatedKind::Method {
1342-
let err_count = tcx.sess.err_count();
13431342
compare_impl_method(tcx,
13441343
&ty_impl_item,
13451344
impl_item.span,
13461345
&ty_trait_item,
13471346
impl_trait_ref,
1348-
trait_span,
1349-
true); // start with old-broken-mode
1350-
if err_count == tcx.sess.err_count() {
1351-
// old broken mode did not report an error. Try with the new mode.
1352-
compare_impl_method(tcx,
1353-
&ty_impl_item,
1354-
impl_item.span,
1355-
&ty_trait_item,
1356-
impl_trait_ref,
1357-
trait_span,
1358-
false); // use the new mode
1359-
}
1347+
trait_span);
13601348
} else {
13611349
let mut err = struct_span_err!(tcx.sess, impl_item.span, E0324,
13621350
"item `{}` is an associated method, \

src/test/compile-fail/issue-18937.rs

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ trait A<'a> {
2727

2828
impl<'a> A<'a> for B {
2929
fn foo<F>(&mut self, f: F) //~ ERROR impl has stricter
30-
//~^ WARNING future release
3130
where F: fmt::Debug + 'static,
3231
{
3332
self.list.push(Box::new(f));

0 commit comments

Comments
 (0)