Skip to content

Commit 06fea92

Browse files
committed
review comments
1 parent 132921b commit 06fea92

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

src/librustc/traits/object_safety.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_hir::def_id::DefId;
1818
use rustc_session::lint::builtin::WHERE_CLAUSES_OBJECT_SAFETY;
1919
use rustc_span::symbol::Symbol;
2020
use rustc_span::{Span, DUMMY_SP};
21-
use smallvec::SmallVec;
21+
use smallvec::{smallvec, SmallVec};
2222
use syntax::ast;
2323

2424
use std::borrow::Cow;
@@ -85,9 +85,9 @@ impl ObjectSafetyViolation {
8585
| ObjectSafetyViolation::Method(_, _, span)
8686
if *span != DUMMY_SP =>
8787
{
88-
vec![*span].into()
88+
smallvec![*span]
8989
}
90-
_ => vec![].into(),
90+
_ => smallvec![],
9191
}
9292
}
9393
}

src/librustc_typeck/check/wfcheck.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1313
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
1414
use rustc_hir::def_id::DefId;
1515
use rustc_hir::ItemKind;
16-
use rustc_span::symbol::{sym, Ident};
16+
use rustc_span::symbol::sym;
1717
use rustc_span::Span;
1818
use syntax::ast;
1919

@@ -180,15 +180,12 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: DefId) {
180180
check_associated_item(tcx, trait_item.hir_id, trait_item.span, method_sig);
181181
}
182182

183-
fn could_be_self(trait_name: Ident, ty: &hir::Ty<'_>) -> bool {
183+
fn could_be_self(trait_def_id: DefId, ty: &hir::Ty<'_>) -> bool {
184184
match ty.kind {
185-
hir::TyKind::TraitObject([trait_ref], ..) => {
186-
let mut p = trait_ref.trait_ref.path.segments.iter().map(|s| s.ident);
187-
match (p.next(), p.next()) {
188-
(Some(ident), None) => ident == trait_name,
189-
_ => false,
190-
}
191-
}
185+
hir::TyKind::TraitObject([trait_ref], ..) => match trait_ref.trait_ref.path.segments {
186+
[s] => s.res.and_then(|r| r.opt_def_id()) == Some(trait_def_id),
187+
_ => false,
188+
},
192189
_ => false,
193190
}
194191
}
@@ -206,18 +203,18 @@ fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem
206203
let mut trait_should_be_self = vec![];
207204
match &item.kind {
208205
hir::TraitItemKind::Const(ty, _) | hir::TraitItemKind::Type(_, Some(ty))
209-
if could_be_self(trait_name, ty) =>
206+
if could_be_self(trait_def_id, ty) =>
210207
{
211208
trait_should_be_self.push(ty.span)
212209
}
213210
hir::TraitItemKind::Method(sig, _) => {
214211
for ty in sig.decl.inputs {
215-
if could_be_self(trait_name, ty) {
212+
if could_be_self(trait_def_id, ty) {
216213
trait_should_be_self.push(ty.span);
217214
}
218215
}
219216
match sig.decl.output {
220-
hir::FunctionRetTy::Return(ty) if could_be_self(trait_name, ty) => {
217+
hir::FunctionRetTy::Return(ty) if could_be_self(trait_def_id, ty) => {
221218
trait_should_be_self.push(ty.span);
222219
}
223220
_ => {}

0 commit comments

Comments
 (0)