review comments
This commit is contained in:
parent
ae0e3d0511
commit
88f5e110db
55 changed files with 133 additions and 132 deletions
|
@ -100,51 +100,7 @@ fn object_safety_violations_for_trait(
|
|||
span,
|
||||
) = violation
|
||||
{
|
||||
// Using `CRATE_NODE_ID` is wrong, but it's hard to get a more precise id.
|
||||
// It's also hard to get a use site span, so we use the method definition span.
|
||||
tcx.struct_span_lint_hir(
|
||||
WHERE_CLAUSES_OBJECT_SAFETY,
|
||||
hir::CRATE_HIR_ID,
|
||||
*span,
|
||||
|lint| {
|
||||
let mut err = lint.build(&format!(
|
||||
"the trait `{}` cannot be made into an object",
|
||||
tcx.def_path_str(trait_def_id)
|
||||
));
|
||||
let node = tcx.hir().get_if_local(trait_def_id);
|
||||
let mut spans = MultiSpan::from_span(*span);
|
||||
if let Some(hir::Node::Item(item)) = node {
|
||||
spans.push_span_label(
|
||||
item.ident.span,
|
||||
"this trait cannot be made into an object...".into(),
|
||||
);
|
||||
spans.push_span_label(
|
||||
*span,
|
||||
format!("...because {}", violation.error_msg()),
|
||||
);
|
||||
} else {
|
||||
spans.push_span_label(
|
||||
*span,
|
||||
format!(
|
||||
"the trait cannot be made into an object because {}",
|
||||
violation.error_msg()
|
||||
),
|
||||
);
|
||||
};
|
||||
err.span_note(
|
||||
spans,
|
||||
"for a trait to be \"object safe\" it needs to allow building a vtable \
|
||||
to allow the call to be resolvable dynamically; for more information \
|
||||
visit <https://doc.rust-lang.org/reference/items/traits.html\
|
||||
#object-safety>",
|
||||
);
|
||||
if node.is_some() {
|
||||
// Only provide the help if its a local trait, otherwise it's not
|
||||
violation.solution(&mut err);
|
||||
}
|
||||
err.emit();
|
||||
},
|
||||
);
|
||||
lint_object_unsafe_trait(tcx, *span, trait_def_id, violation);
|
||||
false
|
||||
} else {
|
||||
true
|
||||
|
@ -182,6 +138,51 @@ fn object_safety_violations_for_trait(
|
|||
violations
|
||||
}
|
||||
|
||||
/// Lint object-unsafe trait.
|
||||
fn lint_object_unsafe_trait(
|
||||
tcx: TyCtxt<'_>,
|
||||
span: Span,
|
||||
trait_def_id: DefId,
|
||||
violation: &ObjectSafetyViolation,
|
||||
) {
|
||||
// Using `CRATE_NODE_ID` is wrong, but it's hard to get a more precise id.
|
||||
// It's also hard to get a use site span, so we use the method definition span.
|
||||
tcx.struct_span_lint_hir(WHERE_CLAUSES_OBJECT_SAFETY, hir::CRATE_HIR_ID, span, |lint| {
|
||||
let mut err = lint.build(&format!(
|
||||
"the trait `{}` cannot be made into an object",
|
||||
tcx.def_path_str(trait_def_id)
|
||||
));
|
||||
let node = tcx.hir().get_if_local(trait_def_id);
|
||||
let mut spans = MultiSpan::from_span(span);
|
||||
if let Some(hir::Node::Item(item)) = node {
|
||||
spans.push_span_label(
|
||||
item.ident.span,
|
||||
"this trait cannot be made into an object...".into(),
|
||||
);
|
||||
spans.push_span_label(span, format!("...because {}", violation.error_msg()));
|
||||
} else {
|
||||
spans.push_span_label(
|
||||
span,
|
||||
format!(
|
||||
"the trait cannot be made into an object because {}",
|
||||
violation.error_msg()
|
||||
),
|
||||
);
|
||||
};
|
||||
err.span_note(
|
||||
spans,
|
||||
"for a trait to be \"object safe\" it needs to allow building a vtable to allow the \
|
||||
call to be resolvable dynamically; for more information visit \
|
||||
<https://doc.rust-lang.org/reference/items/traits.html#object-safety>",
|
||||
);
|
||||
if node.is_some() {
|
||||
// Only provide the help if its a local trait, otherwise it's not
|
||||
violation.solution(&mut err);
|
||||
}
|
||||
err.emit();
|
||||
});
|
||||
}
|
||||
|
||||
fn sized_trait_bound_spans<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
bounds: hir::GenericBounds<'tcx>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue