Point at the trait item and tweak wording
This commit is contained in:
parent
ef2a8539aa
commit
6998085c03
6 changed files with 36 additions and 15 deletions
|
|
@ -6,11 +6,13 @@ use crate::infer::{ValuePairs, Subtype};
|
|||
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
|
||||
use crate::infer::lexical_region_resolve::RegionResolutionError;
|
||||
use crate::util::common::ErrorReported;
|
||||
use crate::traits::ObligationCauseCode::CompareImplMethodObligation;
|
||||
|
||||
impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
||||
/// Print the error message for lifetime errors when the `impl` doesn't conform to the `trait`.
|
||||
pub(super) fn try_report_impl_not_conforming_to_trait(&self) -> Option<ErrorReported> {
|
||||
if let Some(ref error) = self.error {
|
||||
debug!("try_report_impl_not_conforming_to_trait {:?}", error);
|
||||
if let RegionResolutionError::SubSupConflict(
|
||||
_,
|
||||
var_origin,
|
||||
|
|
@ -27,10 +29,18 @@ 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 impl_sp = if let CompareImplMethodObligation {
|
||||
trait_item_def_id, ..
|
||||
} = &sub_trace.cause.code {
|
||||
Some(self.tcx().def_span(*trait_item_def_id))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
self.emit_err(
|
||||
sp,
|
||||
sub_expected_found.expected,
|
||||
sub_expected_found.found,
|
||||
impl_sp,
|
||||
);
|
||||
return Some(ErrorReported);
|
||||
}
|
||||
|
|
@ -43,14 +53,16 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
None
|
||||
}
|
||||
|
||||
fn emit_err(&self, sp: Span, expected: Ty<'tcx>, found: Ty<'tcx>) {
|
||||
fn emit_err(&self, sp: Span, expected: Ty<'tcx>, found: Ty<'tcx>, impl_sp: Option<Span>) {
|
||||
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.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.
|
||||
if let Some(span) = impl_sp {
|
||||
err.span_label(span, &format!("expected {:?}", expected));
|
||||
}
|
||||
err.emit();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ struct Struct;
|
|||
impl Deref for Struct {
|
||||
type Target = dyn Trait;
|
||||
fn deref(&self) -> &dyn Trait {
|
||||
//~^ ERROR `impl` item signature doesn't match `trait` item signature
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
||||
//~^^^^ ERROR `impl` item signature doesn't match `trait` item signature
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,14 @@ error: `impl` item signature doesn't match `trait` item signature
|
|||
|
|
||||
LL | fn deref(&self) -> &dyn Trait {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found fn(&Struct) -> &dyn Trait
|
||||
|
|
||||
::: $SRC_DIR/libcore/ops/deref.rs:LL:COL
|
||||
|
|
||||
= note: expected: fn(&Struct) -> &(dyn Trait + 'static)
|
||||
found: fn(&Struct) -> &dyn Trait
|
||||
LL | fn deref(&self) -> &Self::Target;
|
||||
| --------------------------------- expected fn(&Struct) -> &(dyn Trait + 'static)
|
||||
|
|
||||
= note: expected `fn(&Struct) -> &(dyn Trait + 'static)`
|
||||
found `fn(&Struct) -> &dyn Trait`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0495`.
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
error: `impl` item signature doesn't match `trait` item signature
|
||||
--> $DIR/mismatched_trait_impl.rs:9:5
|
||||
|
|
||||
LL | fn foo(&self, x: &'a u32, y: &u32) -> &'a u32;
|
||||
| ---------------------------------------------- expected fn(&i32, &'a u32, &u32) -> &'a u32
|
||||
...
|
||||
LL | fn foo(&self, x: &u32, y: &'a u32) -> &'a u32 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found fn(&i32, &u32, &u32) -> &u32
|
||||
|
|
||||
= note: expected: fn(&i32, &'a u32, &u32) -> &'a u32
|
||||
found: fn(&i32, &u32, &u32) -> &u32
|
||||
= note: expected `fn(&i32, &'a u32, &u32) -> &'a u32`
|
||||
found `fn(&i32, &u32, &u32) -> &u32`
|
||||
|
||||
error[E0623]: lifetime mismatch
|
||||
--> $DIR/mismatched_trait_impl.rs:10:9
|
||||
|
|
@ -19,4 +22,3 @@ LL | x
|
|||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0495`.
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
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: &i32, y: &'a i32) -> &'a i32;
|
||||
| ------------------------------------------- expected fn(&i32, &'a i32) -> &'a i32
|
||||
...
|
||||
LL | fn foo<'a>(x: &'a i32, y: &'a i32) -> &'a i32 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found fn(&i32, &i32) -> &i32
|
||||
|
|
||||
= note: expected: fn(&i32, &'a i32) -> &'a i32
|
||||
found: fn(&i32, &i32) -> &i32
|
||||
= note: expected `fn(&i32, &'a i32) -> &'a i32`
|
||||
found `fn(&i32, &i32) -> &i32`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -95,10 +95,10 @@ error: `impl` item signature doesn't match `trait` item signature
|
|||
LL | impl<'lw> Drop for W<'lw,'lw> { fn drop(&mut self) { } } // REJECT
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found W<'_, '_>
|
||||
|
|
||||
= note: expected: W<'l1, 'l2>
|
||||
found: W<'_, '_>
|
||||
= note: expected `W<'l1, 'l2>`
|
||||
found `W<'_, '_>`
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0308, E0366, E0367, E0495.
|
||||
Some errors have detailed explanations: E0308, E0366, E0367.
|
||||
For more information about an error, try `rustc --explain E0308`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue