mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
Simplify error reporting.
This commit is contained in:
parent
8b2409cd7d
commit
554aceba49
@ -602,6 +602,25 @@ impl<'a> Resolver<'a> {
|
|||||||
|
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
|
ResolutionError::TraitImplMismatch {
|
||||||
|
name,
|
||||||
|
kind,
|
||||||
|
code,
|
||||||
|
trait_item_span,
|
||||||
|
trait_path,
|
||||||
|
} => {
|
||||||
|
let mut err = self.session.struct_span_err_with_code(
|
||||||
|
span,
|
||||||
|
&format!(
|
||||||
|
"item `{}` is an associated {}, which doesn't match its trait `{}`",
|
||||||
|
name, kind, trait_path,
|
||||||
|
),
|
||||||
|
code,
|
||||||
|
);
|
||||||
|
err.span_label(span, "does not match trait");
|
||||||
|
err.span_label(trait_item_span, "item in trait");
|
||||||
|
err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1470,45 +1470,22 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
|||||||
|
|
||||||
// The method kind does not correspond to what appeared in the trait, report.
|
// The method kind does not correspond to what appeared in the trait, report.
|
||||||
let path = &self.current_trait_ref.as_ref().unwrap().1.path;
|
let path = &self.current_trait_ref.as_ref().unwrap().1.path;
|
||||||
let path = &path_names_to_string(path);
|
let (code, kind) = match kind {
|
||||||
let mut err = match kind {
|
AssocItemKind::Const(..) => (rustc_errors::error_code!(E0323), "const"),
|
||||||
AssocItemKind::Const(..) => {
|
AssocItemKind::Fn(..) => (rustc_errors::error_code!(E0324), "method"),
|
||||||
rustc_errors::struct_span_err!(
|
AssocItemKind::TyAlias(..) => (rustc_errors::error_code!(E0325), "type"),
|
||||||
self.r.session,
|
AssocItemKind::MacCall(..) => span_bug!(span, "unexpanded macro"),
|
||||||
span,
|
|
||||||
E0323,
|
|
||||||
"item `{}` is an associated const, which doesn't match its trait `{}`",
|
|
||||||
ident,
|
|
||||||
path,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
AssocItemKind::Fn(..) => {
|
|
||||||
rustc_errors::struct_span_err!(
|
|
||||||
self.r.session,
|
|
||||||
span,
|
|
||||||
E0324,
|
|
||||||
"item `{}` is an associated method, which doesn't match its trait `{}`",
|
|
||||||
ident,
|
|
||||||
path,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
AssocItemKind::TyAlias(..) => {
|
|
||||||
rustc_errors::struct_span_err!(
|
|
||||||
self.r.session,
|
|
||||||
span,
|
|
||||||
E0325,
|
|
||||||
"item `{}` is an associated type, which doesn't match its trait `{}`",
|
|
||||||
ident,
|
|
||||||
path,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
AssocItemKind::MacCall(..) => {
|
|
||||||
span_bug!(span, "macros should have been expanded")
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
err.span_label(span, "does not match trait");
|
self.report_error(
|
||||||
err.span_label(binding.span, "item in trait");
|
span,
|
||||||
err.emit();
|
ResolutionError::TraitImplMismatch {
|
||||||
|
name: ident.name,
|
||||||
|
kind,
|
||||||
|
code,
|
||||||
|
trait_path: path_names_to_string(path),
|
||||||
|
trait_item_span: binding.span,
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_params(&mut self, params: &'ast [Param]) {
|
fn resolve_params(&mut self, params: &'ast [Param]) {
|
||||||
|
@ -258,6 +258,14 @@ enum ResolutionError<'a> {
|
|||||||
SelfInGenericParamDefault,
|
SelfInGenericParamDefault,
|
||||||
/// Error E0767: use of unreachable label
|
/// Error E0767: use of unreachable label
|
||||||
UnreachableLabel { name: Symbol, definition_span: Span, suggestion: Option<LabelSuggestion> },
|
UnreachableLabel { name: Symbol, definition_span: Span, suggestion: Option<LabelSuggestion> },
|
||||||
|
/// Error E0323, E0324, E0325: mismatch between trait item and impl item.
|
||||||
|
TraitImplMismatch {
|
||||||
|
name: Symbol,
|
||||||
|
kind: &'static str,
|
||||||
|
trait_path: String,
|
||||||
|
trait_item_span: Span,
|
||||||
|
code: rustc_errors::DiagnosticId,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
enum VisResolutionError<'a> {
|
enum VisResolutionError<'a> {
|
||||||
|
Loading…
Reference in New Issue
Block a user