Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refer to "self type" instead of "receiver type" #64110

Merged
merged 7 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Generally, `Self: Sized` is used to indicate that the trait should not be used
as a trait object. If the trait comes from your own crate, consider removing
this restriction.

### Method references the `Self` type in its arguments or return type
### Method references the `Self` type in its parameters or return type

This happens when a trait has a method like the following:

Expand Down
8 changes: 4 additions & 4 deletions src/librustc/traits/object_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::borrow::Cow;
use std::iter::{self};
use syntax::ast::{self};
use syntax::symbol::InternedString;
use syntax_pos::Span;
use syntax_pos::{Span, DUMMY_SP};

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum ObjectSafetyViolation {
Expand Down Expand Up @@ -49,7 +49,7 @@ impl ObjectSafetyViolation {
ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod, _) =>
format!("associated function `{}` has no `self` parameter", name).into(),
ObjectSafetyViolation::Method(name, MethodViolationCode::ReferencesSelf, _) => format!(
"method `{}` references the `Self` type in its arguments or return type",
"method `{}` references the `Self` type in its parameters or return type",
name,
).into(),
ObjectSafetyViolation::Method(
Expand All @@ -67,9 +67,9 @@ impl ObjectSafetyViolation {
}

pub fn span(&self) -> Option<Span> {
match self {
match *self {
ObjectSafetyViolation::AssocConst(_, span) |
ObjectSafetyViolation::Method(_, _, span) => Some(*span),
ObjectSafetyViolation::Method(_, _, span) if span != DUMMY_SP => Some(span),
estebank marked this conversation as resolved.
Show resolved Hide resolved
_ => None,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0038]: the trait `NotObjectSafe` cannot be made into an object
--> $DIR/coherence-impl-trait-for-trait-object-safe.rs:11:6
|
LL | trait NotObjectSafe { fn eq(&self, other: Self); }
| -- method `eq` references the `Self` type in its arguments or return type
| -- method `eq` references the `Self` type in its parameters or return type
LL | impl NotObjectSafe for dyn NotObjectSafe { }
| ^^^^^^^^^^^^^ the trait `NotObjectSafe` cannot be made into an object

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0038]: the trait `NotObjectSafe` cannot be made into an object
--> $DIR/coherence-impl-trait-for-trait-object-safe.rs:11:6
|
LL | trait NotObjectSafe { fn eq(&self, other: Self); }
| -- method `eq` references the `Self` type in its arguments or return type
| -- method `eq` references the `Self` type in its parameters or return type
LL | impl NotObjectSafe for dyn NotObjectSafe { }
| ^^^^^^^^^^^^^ the trait `NotObjectSafe` cannot be made into an object

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0038.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0038]: the trait `Trait` cannot be made into an object
--> $DIR/E0038.rs:5:1
|
LL | fn foo(&self) -> Self;
| --- method `foo` references the `Self` type in its arguments or return type
| --- method `foo` references the `Self` type in its parameters or return type
...
LL | fn call_foo(x: Box<dyn Trait>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` cannot be made into an object
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/object-safety/object-safety-mentions-Self.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0038]: the trait `Bar` cannot be made into an object
--> $DIR/object-safety-mentions-Self.rs:17:1
|
LL | fn bar(&self, x: &Self);
| --- method `bar` references the `Self` type in its arguments or return type
| --- method `bar` references the `Self` type in its parameters or return type
...
LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` cannot be made into an object
Expand All @@ -11,7 +11,7 @@ error[E0038]: the trait `Baz` cannot be made into an object
--> $DIR/object-safety-mentions-Self.rs:22:1
|
LL | fn bar(&self) -> Self;
| --- method `bar` references the `Self` type in its arguments or return type
| --- method `bar` references the `Self` type in its parameters or return type
...
LL | fn make_baz<T:Baz>(t: &T) -> &dyn Baz {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Baz` cannot be made into an object
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/resolve/issue-3907-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ error[E0038]: the trait `issue_3907::Foo` cannot be made into an object
|
LL | fn bar(_x: Foo) {}
| ^^^^^^^^^^^^^^^ the trait `issue_3907::Foo` cannot be made into an object
|
= note: associated function `bar` has no `self` parameter

error: aborting due to previous error

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/traits/trait-test-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ error[E0038]: the trait `bar` cannot be made into an object
LL | trait bar { fn dup(&self) -> Self; fn blah<X>(&self); }
| --- ---- method `blah` has generic type parameters
| |
| method `dup` references the `Self` type in its arguments or return type
| method `dup` references the `Self` type in its parameters or return type
...
LL | (box 10 as Box<dyn bar>).dup();
| ^^^^^^^^^^^^ the trait `bar` cannot be made into an object
Expand All @@ -27,7 +27,7 @@ error[E0038]: the trait `bar` cannot be made into an object
LL | trait bar { fn dup(&self) -> Self; fn blah<X>(&self); }
| --- ---- method `blah` has generic type parameters
| |
| method `dup` references the `Self` type in its arguments or return type
| method `dup` references the `Self` type in its parameters or return type
...
LL | (box 10 as Box<dyn bar>).dup();
| ^^^^^^ the trait `bar` cannot be made into an object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ error[E0038]: the trait `MyAdd` cannot be made into an object
--> $DIR/type-parameter-defaults-referencing-Self-ppaux.rs:14:18
|
LL | trait MyAdd<Rhs=Self> { fn add(&self, other: &Rhs) -> Self; }
| --- method `add` references the `Self` type in its arguments or return type
| --- method `add` references the `Self` type in its parameters or return type
...
LL | let y = x as dyn MyAdd<i32>;
| ^^^^^^^^^^^^^^ the trait `MyAdd` cannot be made into an object
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/wf/wf-object-safe.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0038]: the trait `A` cannot be made into an object
--> $DIR/wf-object-safe.rs:9:13
|
LL | fn foo(&self, _x: &Self);
| --- method `foo` references the `Self` type in its arguments or return type
| --- method `foo` references the `Self` type in its parameters or return type
...
LL | let _x: &dyn A;
| ^^^^^^ the trait `A` cannot be made into an object
Expand Down