use rustc_session::lint::builtin::WHERE_CLAUSES_OBJECT_SAFETY;
use rustc_span::symbol::Symbol;
use rustc_span::{Span, DUMMY_SP};
-use smallvec::SmallVec;
+use smallvec::{smallvec, SmallVec};
use syntax::ast;
use std::borrow::Cow;
| ObjectSafetyViolation::Method(_, _, span)
if *span != DUMMY_SP =>
{
- vec![*span].into()
+ smallvec![*span]
}
- _ => vec![].into(),
+ _ => smallvec![],
}
}
}
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
use rustc_hir::def_id::DefId;
use rustc_hir::ItemKind;
-use rustc_span::symbol::{sym, Ident};
+use rustc_span::symbol::sym;
use rustc_span::Span;
use syntax::ast;
check_associated_item(tcx, trait_item.hir_id, trait_item.span, method_sig);
}
-fn could_be_self(trait_name: Ident, ty: &hir::Ty<'_>) -> bool {
+fn could_be_self(trait_def_id: DefId, ty: &hir::Ty<'_>) -> bool {
match ty.kind {
- hir::TyKind::TraitObject([trait_ref], ..) => {
- let mut p = trait_ref.trait_ref.path.segments.iter().map(|s| s.ident);
- match (p.next(), p.next()) {
- (Some(ident), None) => ident == trait_name,
- _ => false,
- }
- }
+ hir::TyKind::TraitObject([trait_ref], ..) => match trait_ref.trait_ref.path.segments {
+ [s] => s.res.and_then(|r| r.opt_def_id()) == Some(trait_def_id),
+ _ => false,
+ },
_ => false,
}
}
let mut trait_should_be_self = vec![];
match &item.kind {
hir::TraitItemKind::Const(ty, _) | hir::TraitItemKind::Type(_, Some(ty))
- if could_be_self(trait_name, ty) =>
+ if could_be_self(trait_def_id, ty) =>
{
trait_should_be_self.push(ty.span)
}
hir::TraitItemKind::Method(sig, _) => {
for ty in sig.decl.inputs {
- if could_be_self(trait_name, ty) {
+ if could_be_self(trait_def_id, ty) {
trait_should_be_self.push(ty.span);
}
}
match sig.decl.output {
- hir::FunctionRetTy::Return(ty) if could_be_self(trait_name, ty) => {
+ hir::FunctionRetTy::Return(ty) if could_be_self(trait_def_id, ty) => {
trait_should_be_self.push(ty.span);
}
_ => {}