Skip to content

Commit 9ae0c1d

Browse files
committed
Make error apply only to impl/trait mismatch
1 parent 6998085 commit 9ae0c1d

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

src/librustc/infer/error_reporting/nice_region_error/trait_impl_difference.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,14 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
2626
if let (
2727
ValuePairs::Types(sub_expected_found),
2828
ValuePairs::Types(sup_expected_found),
29-
) = (&sub_trace.values, &sup_trace.values) {
29+
CompareImplMethodObligation { trait_item_def_id, .. },
30+
) = (&sub_trace.values, &sup_trace.values, &sub_trace.cause.code) {
3031
if sup_expected_found == sub_expected_found {
31-
let sp = var_origin.span();
32-
let impl_sp = if let CompareImplMethodObligation {
33-
trait_item_def_id, ..
34-
} = &sub_trace.cause.code {
35-
Some(self.tcx().def_span(*trait_item_def_id))
36-
} else {
37-
None
38-
};
3932
self.emit_err(
40-
sp,
33+
var_origin.span(),
4134
sub_expected_found.expected,
4235
sub_expected_found.found,
43-
impl_sp,
36+
self.tcx().def_span(*trait_item_def_id),
4437
);
4538
return Some(ErrorReported);
4639
}
@@ -53,16 +46,14 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
5346
None
5447
}
5548

56-
fn emit_err(&self, sp: Span, expected: Ty<'tcx>, found: Ty<'tcx>, impl_sp: Option<Span>) {
49+
fn emit_err(&self, sp: Span, expected: Ty<'tcx>, found: Ty<'tcx>, impl_sp: Span) {
5750
let mut err = self.tcx().sess.struct_span_err(
5851
sp,
5952
"`impl` item signature doesn't match `trait` item signature",
6053
);
6154
err.note(&format!("expected `{:?}`\n found `{:?}`", expected, found));
6255
err.span_label(sp, &format!("found {:?}", found));
63-
if let Some(span) = impl_sp {
64-
err.span_label(span, &format!("expected {:?}", expected));
65-
}
56+
err.span_label(impl_sp, &format!("expected {:?}", expected));
6657
err.emit();
6758
}
6859
}

src/test/ui/reject-specialized-drops-8142.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ impl<One> Drop for V<One,One> { fn drop(&mut self) { } } // REJECT
5252
//~^ ERROR Implementations of Drop cannot be specialized
5353

5454
impl<'lw> Drop for W<'lw,'lw> { fn drop(&mut self) { } } // REJECT
55-
//~^ ERROR `impl` item signature doesn't match `trait` item signature
55+
//~^ ERROR cannot infer an appropriate lifetime for lifetime parameter `'lw`
5656

5757
pub fn main() { }

src/test/ui/reject-specialized-drops-8142.stderr

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,27 @@ note: Use same sequence of generic type and region parameters that is on the str
8989
LL | struct V<Tva, Tvb> { x: *const Tva, y: *const Tvb }
9090
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9191

92-
error: `impl` item signature doesn't match `trait` item signature
92+
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'lw` due to conflicting requirements
9393
--> $DIR/reject-specialized-drops-8142.rs:54:1
9494
|
9595
LL | impl<'lw> Drop for W<'lw,'lw> { fn drop(&mut self) { } } // REJECT
96-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found W<'_, '_>
96+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
97+
|
98+
note: first, the lifetime cannot outlive the lifetime `'l1` as defined on the struct at 17:10...
99+
--> $DIR/reject-specialized-drops-8142.rs:17:10
100+
|
101+
LL | struct W<'l1, 'l2> { x: &'l1 i8, y: &'l2 u8 }
102+
| ^^^
103+
note: ...but the lifetime must also be valid for the lifetime `'l2` as defined on the struct at 17:15...
104+
--> $DIR/reject-specialized-drops-8142.rs:17:15
97105
|
98-
= note: expected `W<'l1, 'l2>`
99-
found `W<'_, '_>`
106+
LL | struct W<'l1, 'l2> { x: &'l1 i8, y: &'l2 u8 }
107+
| ^^^
108+
= note: ...so that the types are compatible:
109+
expected W<'l1, 'l2>
110+
found W<'_, '_>
100111

101112
error: aborting due to 8 previous errors
102113

103-
Some errors have detailed explanations: E0308, E0366, E0367.
114+
Some errors have detailed explanations: E0308, E0366, E0367, E0495.
104115
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)