Skip to content

Commit efe8594

Browse files
committed
account for DUMMY_SP and correct wording
1 parent bb99fc3 commit efe8594

10 files changed

+16
-14
lines changed

src/librustc/error_codes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Generally, `Self: Sized` is used to indicate that the trait should not be used
3939
as a trait object. If the trait comes from your own crate, consider removing
4040
this restriction.
4141
42-
### Method references the `Self` type in its arguments or return type
42+
### Method references the `Self` type in its parameters or return type
4343
4444
This happens when a trait has a method like the following:
4545

src/librustc/traits/object_safety.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::borrow::Cow;
2020
use std::iter::{self};
2121
use syntax::ast::{self};
2222
use syntax::symbol::InternedString;
23-
use syntax_pos::Span;
23+
use syntax_pos::{Span, DUMMY_SP};
2424

2525
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
2626
pub enum ObjectSafetyViolation {
@@ -49,7 +49,7 @@ impl ObjectSafetyViolation {
4949
ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod, _) =>
5050
format!("associated function `{}` has no `self` parameter", name).into(),
5151
ObjectSafetyViolation::Method(name, MethodViolationCode::ReferencesSelf, _) => format!(
52-
"method `{}` references the `Self` type in its arguments or return type",
52+
"method `{}` references the `Self` type in its parameters or return type",
5353
name,
5454
).into(),
5555
ObjectSafetyViolation::Method(
@@ -67,9 +67,9 @@ impl ObjectSafetyViolation {
6767
}
6868

6969
pub fn span(&self) -> Option<Span> {
70-
match self {
70+
match *self {
7171
ObjectSafetyViolation::AssocConst(_, span) |
72-
ObjectSafetyViolation::Method(_, _, span) => Some(*span),
72+
ObjectSafetyViolation::Method(_, _, span) if span != DUMMY_SP => Some(span),
7373
_ => None,
7474
}
7575
}

src/test/ui/coherence/coherence-impl-trait-for-trait-object-safe.old.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0038]: the trait `NotObjectSafe` cannot be made into an object
22
--> $DIR/coherence-impl-trait-for-trait-object-safe.rs:11:6
33
|
44
LL | trait NotObjectSafe { fn eq(&self, other: Self); }
5-
| -- method `eq` references the `Self` type in its arguments or return type
5+
| -- method `eq` references the `Self` type in its parameters or return type
66
LL | impl NotObjectSafe for dyn NotObjectSafe { }
77
| ^^^^^^^^^^^^^ the trait `NotObjectSafe` cannot be made into an object
88

src/test/ui/coherence/coherence-impl-trait-for-trait-object-safe.re.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0038]: the trait `NotObjectSafe` cannot be made into an object
22
--> $DIR/coherence-impl-trait-for-trait-object-safe.rs:11:6
33
|
44
LL | trait NotObjectSafe { fn eq(&self, other: Self); }
5-
| -- method `eq` references the `Self` type in its arguments or return type
5+
| -- method `eq` references the `Self` type in its parameters or return type
66
LL | impl NotObjectSafe for dyn NotObjectSafe { }
77
| ^^^^^^^^^^^^^ the trait `NotObjectSafe` cannot be made into an object
88

src/test/ui/error-codes/E0038.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0038]: the trait `Trait` cannot be made into an object
22
--> $DIR/E0038.rs:5:1
33
|
44
LL | fn foo(&self) -> Self;
5-
| --- method `foo` references the `Self` type in its arguments or return type
5+
| --- method `foo` references the `Self` type in its parameters or return type
66
...
77
LL | fn call_foo(x: Box<dyn Trait>) {
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` cannot be made into an object

src/test/ui/object-safety/object-safety-mentions-Self.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0038]: the trait `Bar` cannot be made into an object
22
--> $DIR/object-safety-mentions-Self.rs:17:1
33
|
44
LL | fn bar(&self, x: &Self);
5-
| --- method `bar` references the `Self` type in its arguments or return type
5+
| --- method `bar` references the `Self` type in its parameters or return type
66
...
77
LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` cannot be made into an object
@@ -11,7 +11,7 @@ error[E0038]: the trait `Baz` cannot be made into an object
1111
--> $DIR/object-safety-mentions-Self.rs:22:1
1212
|
1313
LL | fn bar(&self) -> Self;
14-
| --- method `bar` references the `Self` type in its arguments or return type
14+
| --- method `bar` references the `Self` type in its parameters or return type
1515
...
1616
LL | fn make_baz<T:Baz>(t: &T) -> &dyn Baz {
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Baz` cannot be made into an object

src/test/ui/resolve/issue-3907-2.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0038]: the trait `issue_3907::Foo` cannot be made into an object
33
|
44
LL | fn bar(_x: Foo) {}
55
| ^^^^^^^^^^^^^^^ the trait `issue_3907::Foo` cannot be made into an object
6+
|
7+
= note: associated function `bar` has no `self` parameter
68

79
error: aborting due to previous error
810

src/test/ui/traits/trait-test-2.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ error[E0038]: the trait `bar` cannot be made into an object
1616
LL | trait bar { fn dup(&self) -> Self; fn blah<X>(&self); }
1717
| --- ---- method `blah` has generic type parameters
1818
| |
19-
| method `dup` references the `Self` type in its arguments or return type
19+
| method `dup` references the `Self` type in its parameters or return type
2020
...
2121
LL | (box 10 as Box<dyn bar>).dup();
2222
| ^^^^^^^^^^^^ the trait `bar` cannot be made into an object
@@ -27,7 +27,7 @@ error[E0038]: the trait `bar` cannot be made into an object
2727
LL | trait bar { fn dup(&self) -> Self; fn blah<X>(&self); }
2828
| --- ---- method `blah` has generic type parameters
2929
| |
30-
| method `dup` references the `Self` type in its arguments or return type
30+
| method `dup` references the `Self` type in its parameters or return type
3131
...
3232
LL | (box 10 as Box<dyn bar>).dup();
3333
| ^^^^^^ the trait `bar` cannot be made into an object

src/test/ui/type/type-parameter-defaults-referencing-Self-ppaux.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ error[E0038]: the trait `MyAdd` cannot be made into an object
1414
--> $DIR/type-parameter-defaults-referencing-Self-ppaux.rs:14:18
1515
|
1616
LL | trait MyAdd<Rhs=Self> { fn add(&self, other: &Rhs) -> Self; }
17-
| --- method `add` references the `Self` type in its arguments or return type
17+
| --- method `add` references the `Self` type in its parameters or return type
1818
...
1919
LL | let y = x as dyn MyAdd<i32>;
2020
| ^^^^^^^^^^^^^^ the trait `MyAdd` cannot be made into an object

src/test/ui/wf/wf-object-safe.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0038]: the trait `A` cannot be made into an object
22
--> $DIR/wf-object-safe.rs:9:13
33
|
44
LL | fn foo(&self, _x: &Self);
5-
| --- method `foo` references the `Self` type in its arguments or return type
5+
| --- method `foo` references the `Self` type in its parameters or return type
66
...
77
LL | let _x: &dyn A;
88
| ^^^^^^ the trait `A` cannot be made into an object

0 commit comments

Comments
 (0)