review comments

This commit is contained in:
Esteban Küber 2019-10-03 20:14:48 -07:00
parent c3521fe940
commit ef2a8539aa
9 changed files with 23 additions and 20 deletions

View File

@ -1,5 +1,7 @@
//! Error Reporting for `impl` items that do not match the obligations from their `trait`.
use syntax_pos::Span;
use crate::ty::Ty;
use crate::infer::{ValuePairs, Subtype};
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
use crate::infer::lexical_region_resolve::RegionResolutionError;
@ -25,21 +27,11 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
) = (&sub_trace.values, &sup_trace.values) {
if sup_expected_found == sub_expected_found {
let sp = var_origin.span();
let mut err = self.tcx().sess.struct_span_err(
self.emit_err(
sp,
"`impl` item doesn't match `trait` item"
);
err.note(&format!(
"expected: {:?}\n found: {:?}",
sub_expected_found.expected,
sub_expected_found.found,
));
err.span_label(sp, &format!(
"found {:?}",
sub_expected_found.found,
));
// FIXME: recover the `FnPtr`'s `HirId`/`Node` to point to it.
err.emit();
);
return Some(ErrorReported);
}
}
@ -50,4 +42,15 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
}
None
}
fn emit_err(&self, sp: Span, expected: Ty<'tcx>, found: Ty<'tcx>) {
let mut err = self.tcx().sess.struct_span_err(
sp,
"`impl` item signature doesn't match `trait` item signature",
);
err.note(&format!("expected: {:?}\n found: {:?}", expected, found));
err.span_label(sp, &format!("found {:?}", found));
// FIXME: recover the `FnPtr`'s `HirId`/`Node` to point to it.
err.emit();
}
}

View File

@ -9,6 +9,6 @@ impl Deref for Struct {
unimplemented!();
}
}
//~^^^^ ERROR `impl` item doesn't match `trait` item
//~^^^^ ERROR `impl` item signature doesn't match `trait` item signature
fn main() {}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -52,6 +52,6 @@ impl<One> Drop for V<One,One> { fn drop(&mut self) { } } // REJECT
//~^ ERROR Implementations of Drop cannot be specialized
impl<'lw> Drop for W<'lw,'lw> { fn drop(&mut self) { } } // REJECT
//~^ ERROR `impl` item doesn't match `trait` item
//~^ ERROR `impl` item signature doesn't match `trait` item signature
pub fn main() { }

View File

@ -89,7 +89,7 @@ note: Use same sequence of generic type and region parameters that is on the str
LL | struct V<Tva, Tvb> { x: *const Tva, y: *const Tvb }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: `impl` item doesn't match `trait` item
error: `impl` item signature doesn't match `trait` item signature
--> $DIR/reject-specialized-drops-8142.rs:54:1
|
LL | impl<'lw> Drop for W<'lw,'lw> { fn drop(&mut self) { } } // REJECT