Skip to content

Commit 0f7ef1a

Browse files
Adjust inner span of implicit self ref argument
1 parent 8621285 commit 0f7ef1a

File tree

6 files changed

+71
-7
lines changed

6 files changed

+71
-7
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2353,7 +2353,12 @@ impl Param {
23532353
/// Builds a `Param` object from `ExplicitSelf`.
23542354
pub fn from_self(attrs: AttrVec, eself: ExplicitSelf, eself_ident: Ident) -> Param {
23552355
let span = eself.span.to(eself_ident.span);
2356-
let infer_ty = P(Ty { id: DUMMY_NODE_ID, kind: TyKind::ImplicitSelf, span, tokens: None });
2356+
let infer_ty = P(Ty {
2357+
id: DUMMY_NODE_ID,
2358+
kind: TyKind::ImplicitSelf,
2359+
span: eself_ident.span,
2360+
tokens: None,
2361+
});
23572362
let (mutbl, ty) = match eself.node {
23582363
SelfKind::Explicit(ty, mutbl) => (mutbl, ty),
23592364
SelfKind::Value(mutbl) => (mutbl, infer_ty),

tests/ui/dropck/explicit-drop-bounds.bad1.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ LL | [T; 1]: Copy, T: std::marker::Copy // But `[T; 1]: Copy` does not imply
1515
| ~~~~~~~~~~~~~~~~~~~~~~
1616

1717
error[E0277]: the trait bound `T: Copy` is not satisfied
18-
--> $DIR/explicit-drop-bounds.rs:32:13
18+
--> $DIR/explicit-drop-bounds.rs:32:18
1919
|
2020
LL | fn drop(&mut self) {}
21-
| ^^^^^^^^^ the trait `Copy` is not implemented for `T`
21+
| ^^^^ the trait `Copy` is not implemented for `T`
2222
|
2323
note: required by a bound in `DropMe`
2424
--> $DIR/explicit-drop-bounds.rs:7:18

tests/ui/dropck/explicit-drop-bounds.bad2.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ LL | impl<T: std::marker::Copy> Drop for DropMe<T>
1515
| +++++++++++++++++++
1616

1717
error[E0277]: the trait bound `T: Copy` is not satisfied
18-
--> $DIR/explicit-drop-bounds.rs:40:13
18+
--> $DIR/explicit-drop-bounds.rs:40:18
1919
|
2020
LL | fn drop(&mut self) {}
21-
| ^^^^^^^^^ the trait `Copy` is not implemented for `T`
21+
| ^^^^ the trait `Copy` is not implemented for `T`
2222
|
2323
note: required by a bound in `DropMe`
2424
--> $DIR/explicit-drop-bounds.rs:7:18

tests/ui/specialization/min_specialization/issue-79224.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ LL | impl<B: ?Sized + std::clone::Clone> Display for Cow<'_, B> {
1111
| +++++++++++++++++++
1212

1313
error[E0277]: the trait bound `B: Clone` is not satisfied
14-
--> $DIR/issue-79224.rs:20:12
14+
--> $DIR/issue-79224.rs:20:13
1515
|
1616
LL | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17-
| ^^^^^ the trait `Clone` is not implemented for `B`
17+
| ^^^^ the trait `Clone` is not implemented for `B`
1818
|
1919
= note: required for `B` to implement `ToOwned`
2020
help: consider further restricting this bound
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pub trait Insertable {
2+
type Values;
3+
4+
fn values(&self) -> Self::Values;
5+
}
6+
7+
impl<T> Insertable for Option<T> {
8+
type Values = ();
9+
10+
fn values(self) -> Self::Values {
11+
//~^ ERROR method `values` has an incompatible type for trait
12+
self.map(Insertable::values).unwrap_or_default()
13+
//~^ ERROR type mismatch in function arguments
14+
}
15+
}
16+
17+
fn main() {}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
error[E0053]: method `values` has an incompatible type for trait
2+
--> $DIR/mismatched-map-under-self.rs:10:15
3+
|
4+
LL | fn values(self) -> Self::Values {
5+
| ^^^^
6+
| |
7+
| expected `&Option<T>`, found `Option<T>`
8+
| help: change the self-receiver type to match the trait: `&self`
9+
|
10+
note: type in trait
11+
--> $DIR/mismatched-map-under-self.rs:4:15
12+
|
13+
LL | fn values(&self) -> Self::Values;
14+
| ^^^^^
15+
= note: expected signature `fn(&Option<T>)`
16+
found signature `fn(Option<T>)`
17+
18+
error[E0631]: type mismatch in function arguments
19+
--> $DIR/mismatched-map-under-self.rs:12:18
20+
|
21+
LL | fn values(&self) -> Self::Values;
22+
| --------------------------------- found signature defined here
23+
...
24+
LL | self.map(Insertable::values).unwrap_or_default()
25+
| --- ^^^^^^^^^^^^^^^^^^ expected due to this
26+
| |
27+
| required by a bound introduced by this call
28+
|
29+
= note: expected function signature `fn(T) -> _`
30+
found function signature `for<'a> fn(&'a _) -> _`
31+
note: required by a bound in `Option::<T>::map`
32+
--> $SRC_DIR/core/src/option.rs:LL:COL
33+
help: consider adjusting the signature so it does not borrow its argument
34+
|
35+
LL - fn values(&self) -> Self::Values;
36+
LL + fn values(self) -> Self::Values;
37+
|
38+
39+
error: aborting due to 2 previous errors
40+
41+
Some errors have detailed explanations: E0053, E0631.
42+
For more information about an error, try `rustc --explain E0053`.

0 commit comments

Comments
 (0)