Skip to content

Commit d137b7a

Browse files
committed
review comments
1 parent 0eb29d1 commit d137b7a

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

src/librustc_typeck/check/wfcheck.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: DefId) {
176176
hir::TraitItemKind::Method(ref sig, _) => Some(sig),
177177
_ => None,
178178
};
179-
check_bare_self_trait_by_name(tcx, &trait_item);
179+
check_object_unsafe_self_trait_by_name(tcx, &trait_item);
180180
check_associated_item(tcx, trait_item.hir_id, trait_item.span, method_sig);
181181
}
182182

@@ -195,7 +195,7 @@ fn could_be_self(trait_name: Ident, ty: &hir::Ty<'_>) -> bool {
195195

196196
/// Detect when an object unsafe trait is referring to itself in one of its associated items.
197197
/// When this is done, suggest using `Self` instead.
198-
fn check_bare_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem<'_>) {
198+
fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem<'_>) {
199199
let (trait_name, trait_def_id) = match tcx.hir().get(tcx.hir().get_parent_item(item.hir_id)) {
200200
hir::Node::Item(item) => match item.kind {
201201
hir::ItemKind::Trait(..) => (item.ident, tcx.hir().local_def_id(item.hir_id)),
@@ -230,17 +230,18 @@ fn check_bare_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem<'_>) {
230230
return;
231231
}
232232
let sugg = trait_should_be_self.iter().map(|span| (*span, "Self".to_string())).collect();
233-
let mut err = tcx.sess.struct_span_err(
234-
trait_should_be_self,
235-
"associated item referring to unboxed trait object for its own trait",
236-
);
237-
err.span_label(trait_name.span, "in this trait");
238-
err.multipart_suggestion(
239-
"you might have meant to use `Self` to refer to the materialized type",
240-
sugg,
241-
Applicability::MachineApplicable,
242-
);
243-
err.emit();
233+
tcx.sess
234+
.struct_span_err(
235+
trait_should_be_self,
236+
"associated item referring to unboxed trait object for its own trait",
237+
)
238+
.span_label(trait_name.span, "in this trait")
239+
.multipart_suggestion(
240+
"you might have meant to use `Self` to refer to the implementing type",
241+
sugg,
242+
Applicability::MachineApplicable,
243+
)
244+
.emit();
244245
}
245246
}
246247

src/test/ui/suggestions/object-unsafe-trait-should-use-self.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | trait A: Sized {
66
LL | fn f(a: A) -> A;
77
| ^ ^
88
|
9-
help: you might have meant to use `Self` to refer to the materialized type
9+
help: you might have meant to use `Self` to refer to the implementing type
1010
|
1111
LL | fn f(a: Self) -> Self;
1212
| ^^^^ ^^^^
@@ -29,7 +29,7 @@ LL | trait B {
2929
LL | fn f(a: B) -> B;
3030
| ^ ^
3131
|
32-
help: you might have meant to use `Self` to refer to the materialized type
32+
help: you might have meant to use `Self` to refer to the implementing type
3333
|
3434
LL | fn f(a: Self) -> Self;
3535
| ^^^^ ^^^^

0 commit comments

Comments
 (0)