Skip to content

Commit 3e2bc19

Browse files
committed
review comments
1 parent 893ab67 commit 3e2bc19

9 files changed

+23
-20
lines changed

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

+15-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Error Reporting for `impl` items that do not match the obligations from their `trait`.
22
3+
use syntax_pos::Span;
4+
use crate::ty::Ty;
35
use crate::infer::{ValuePairs, Subtype};
46
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
57
use crate::infer::lexical_region_resolve::RegionResolutionError;
@@ -25,21 +27,11 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
2527
) = (&sub_trace.values, &sup_trace.values) {
2628
if sup_expected_found == sub_expected_found {
2729
let sp = var_origin.span();
28-
let mut err = self.tcx().sess.struct_span_err(
30+
self.emit_err(
2931
sp,
30-
"`impl` item doesn't match `trait` item"
31-
);
32-
err.note(&format!(
33-
"expected: {:?}\n found: {:?}",
3432
sub_expected_found.expected,
3533
sub_expected_found.found,
36-
));
37-
err.span_label(sp, &format!(
38-
"found {:?}",
39-
sub_expected_found.found,
40-
));
41-
// FIXME: recover the `FnPtr`'s `HirId`/`Node` to point to it.
42-
err.emit();
34+
);
4335
return Some(ErrorReported);
4436
}
4537
}
@@ -50,4 +42,15 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
5042
}
5143
None
5244
}
45+
46+
fn emit_err(&self, sp: Span, expected: Ty<'tcx>, found: Ty<'tcx>) {
47+
let mut err = self.tcx().sess.struct_span_err(
48+
sp,
49+
"`impl` item signature doesn't match `trait` item signature",
50+
);
51+
err.note(&format!("expected: {:?}\n found: {:?}", expected, found));
52+
err.span_label(sp, &format!("found {:?}", found));
53+
// FIXME: recover the `FnPtr`'s `HirId`/`Node` to point to it.
54+
err.emit();
55+
}
5356
}

src/test/ui/in-band-lifetimes/mismatched_trait_impl-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ impl Deref for Struct {
99
unimplemented!();
1010
}
1111
}
12-
//~^^^^ ERROR `impl` item doesn't match `trait` item
12+
//~^^^^ ERROR `impl` item signature doesn't match `trait` item signature
1313

1414
fn main() {}

src/test/ui/in-band-lifetimes/mismatched_trait_impl-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `impl` item doesn't match `trait` item
1+
error: `impl` item signature doesn't match `trait` item signature
22
--> $DIR/mismatched_trait_impl-2.rs:8:5
33
|
44
LL | fn deref(&self) -> &dyn Trait {

src/test/ui/in-band-lifetimes/mismatched_trait_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ trait Get {
66
}
77

88
impl Get for i32 {
9-
fn foo(&self, x: &u32, y: &'a u32) -> &'a u32 { //~ ERROR `impl` item doesn't match `trait`
9+
fn foo(&self, x: &u32, y: &'a u32) -> &'a u32 { //~ ERROR `impl` item signature doesn't match
1010
x //~ ERROR lifetime mismatch
1111
}
1212
}

src/test/ui/in-band-lifetimes/mismatched_trait_impl.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `impl` item doesn't match `trait` item
1+
error: `impl` item signature doesn't match `trait` item signature
22
--> $DIR/mismatched_trait_impl.rs:9:5
33
|
44
LL | fn foo(&self, x: &u32, y: &'a u32) -> &'a u32 {

src/test/ui/lifetimes/lifetime-mismatch-between-trait-and-impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ trait Foo {
44

55
impl Foo for () {
66
fn foo<'a>(x: &'a i32, y: &'a i32) -> &'a i32 {
7-
//~^ ERROR `impl` item doesn't match `trait` item
7+
//~^ ERROR `impl` item signature doesn't match `trait` item signature
88
if x > y { x } else { y }
99
}
1010
}

src/test/ui/lifetimes/lifetime-mismatch-between-trait-and-impl.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `impl` item doesn't match `trait` item
1+
error: `impl` item signature doesn't match `trait` item signature
22
--> $DIR/lifetime-mismatch-between-trait-and-impl.rs:6:5
33
|
44
LL | fn foo<'a>(x: &'a i32, y: &'a i32) -> &'a i32 {

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

+1-1
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 doesn't match `trait` item
55+
//~^ ERROR `impl` item signature doesn't match `trait` item signature
5656

5757
pub fn main() { }

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ 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 doesn't match `trait` item
92+
error: `impl` item signature doesn't match `trait` item signature
9393
--> $DIR/reject-specialized-drops-8142.rs:54:1
9494
|
9595
LL | impl<'lw> Drop for W<'lw,'lw> { fn drop(&mut self) { } } // REJECT

0 commit comments

Comments
 (0)