about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-06-10 22:36:28 +0000
committerMichael Goulet <michael@errs.io>2023-06-28 17:51:01 +0000
commit0f7ef1a202b32f783b3e0e05d318208c0c83b8d0 (patch)
treea38a4a22f7355449881dde4717653ec6b3fc188d
parent8621285e3beb8e7e4a80b7d369e62b12084f9bcc (diff)
downloadrust-0f7ef1a202b32f783b3e0e05d318208c0c83b8d0.tar.gz
rust-0f7ef1a202b32f783b3e0e05d318208c0c83b8d0.zip
Adjust inner span of implicit self ref argument
-rw-r--r--compiler/rustc_ast/src/ast.rs7
-rw-r--r--tests/ui/dropck/explicit-drop-bounds.bad1.stderr4
-rw-r--r--tests/ui/dropck/explicit-drop-bounds.bad2.stderr4
-rw-r--r--tests/ui/specialization/min_specialization/issue-79224.stderr4
-rw-r--r--tests/ui/typeck/mismatched-map-under-self.rs17
-rw-r--r--tests/ui/typeck/mismatched-map-under-self.stderr42
6 files changed, 71 insertions, 7 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs
index a398fd80119..cd4373e6d33 100644
--- a/compiler/rustc_ast/src/ast.rs
+++ b/compiler/rustc_ast/src/ast.rs
@@ -2353,7 +2353,12 @@ impl Param {
     /// Builds a `Param` object from `ExplicitSelf`.
     pub fn from_self(attrs: AttrVec, eself: ExplicitSelf, eself_ident: Ident) -> Param {
         let span = eself.span.to(eself_ident.span);
-        let infer_ty = P(Ty { id: DUMMY_NODE_ID, kind: TyKind::ImplicitSelf, span, tokens: None });
+        let infer_ty = P(Ty {
+            id: DUMMY_NODE_ID,
+            kind: TyKind::ImplicitSelf,
+            span: eself_ident.span,
+            tokens: None,
+        });
         let (mutbl, ty) = match eself.node {
             SelfKind::Explicit(ty, mutbl) => (mutbl, ty),
             SelfKind::Value(mutbl) => (mutbl, infer_ty),
diff --git a/tests/ui/dropck/explicit-drop-bounds.bad1.stderr b/tests/ui/dropck/explicit-drop-bounds.bad1.stderr
index 3b506c7e7ec..3ef11e2c0bb 100644
--- a/tests/ui/dropck/explicit-drop-bounds.bad1.stderr
+++ b/tests/ui/dropck/explicit-drop-bounds.bad1.stderr
@@ -15,10 +15,10 @@ LL |     [T; 1]: Copy, T: std::marker::Copy // But `[T; 1]: Copy` does not imply
    |                 ~~~~~~~~~~~~~~~~~~~~~~
 
 error[E0277]: the trait bound `T: Copy` is not satisfied
-  --> $DIR/explicit-drop-bounds.rs:32:13
+  --> $DIR/explicit-drop-bounds.rs:32:18
    |
 LL |     fn drop(&mut self) {}
-   |             ^^^^^^^^^ the trait `Copy` is not implemented for `T`
+   |                  ^^^^ the trait `Copy` is not implemented for `T`
    |
 note: required by a bound in `DropMe`
   --> $DIR/explicit-drop-bounds.rs:7:18
diff --git a/tests/ui/dropck/explicit-drop-bounds.bad2.stderr b/tests/ui/dropck/explicit-drop-bounds.bad2.stderr
index 832af3e521a..8138b86ddea 100644
--- a/tests/ui/dropck/explicit-drop-bounds.bad2.stderr
+++ b/tests/ui/dropck/explicit-drop-bounds.bad2.stderr
@@ -15,10 +15,10 @@ LL | impl<T: std::marker::Copy> Drop for DropMe<T>
    |       +++++++++++++++++++
 
 error[E0277]: the trait bound `T: Copy` is not satisfied
-  --> $DIR/explicit-drop-bounds.rs:40:13
+  --> $DIR/explicit-drop-bounds.rs:40:18
    |
 LL |     fn drop(&mut self) {}
-   |             ^^^^^^^^^ the trait `Copy` is not implemented for `T`
+   |                  ^^^^ the trait `Copy` is not implemented for `T`
    |
 note: required by a bound in `DropMe`
   --> $DIR/explicit-drop-bounds.rs:7:18
diff --git a/tests/ui/specialization/min_specialization/issue-79224.stderr b/tests/ui/specialization/min_specialization/issue-79224.stderr
index 505baa23ca3..9a4d557a152 100644
--- a/tests/ui/specialization/min_specialization/issue-79224.stderr
+++ b/tests/ui/specialization/min_specialization/issue-79224.stderr
@@ -11,10 +11,10 @@ LL | impl<B: ?Sized + std::clone::Clone> Display for Cow<'_, B> {
    |                +++++++++++++++++++
 
 error[E0277]: the trait bound `B: Clone` is not satisfied
-  --> $DIR/issue-79224.rs:20:12
+  --> $DIR/issue-79224.rs:20:13
    |
 LL |     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-   |            ^^^^^ the trait `Clone` is not implemented for `B`
+   |             ^^^^ the trait `Clone` is not implemented for `B`
    |
    = note: required for `B` to implement `ToOwned`
 help: consider further restricting this bound
diff --git a/tests/ui/typeck/mismatched-map-under-self.rs b/tests/ui/typeck/mismatched-map-under-self.rs
new file mode 100644
index 00000000000..bedb7a1907d
--- /dev/null
+++ b/tests/ui/typeck/mismatched-map-under-self.rs
@@ -0,0 +1,17 @@
+pub trait Insertable {
+    type Values;
+
+    fn values(&self) -> Self::Values;
+}
+
+impl<T> Insertable for Option<T> {
+    type Values = ();
+
+    fn values(self) -> Self::Values {
+        //~^ ERROR method `values` has an incompatible type for trait
+        self.map(Insertable::values).unwrap_or_default()
+        //~^ ERROR type mismatch in function arguments
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/typeck/mismatched-map-under-self.stderr b/tests/ui/typeck/mismatched-map-under-self.stderr
new file mode 100644
index 00000000000..65ef5456268
--- /dev/null
+++ b/tests/ui/typeck/mismatched-map-under-self.stderr
@@ -0,0 +1,42 @@
+error[E0053]: method `values` has an incompatible type for trait
+  --> $DIR/mismatched-map-under-self.rs:10:15
+   |
+LL |     fn values(self) -> Self::Values {
+   |               ^^^^
+   |               |
+   |               expected `&Option<T>`, found `Option<T>`
+   |               help: change the self-receiver type to match the trait: `&self`
+   |
+note: type in trait
+  --> $DIR/mismatched-map-under-self.rs:4:15
+   |
+LL |     fn values(&self) -> Self::Values;
+   |               ^^^^^
+   = note: expected signature `fn(&Option<T>)`
+              found signature `fn(Option<T>)`
+
+error[E0631]: type mismatch in function arguments
+  --> $DIR/mismatched-map-under-self.rs:12:18
+   |
+LL |     fn values(&self) -> Self::Values;
+   |     --------------------------------- found signature defined here
+...
+LL |         self.map(Insertable::values).unwrap_or_default()
+   |              --- ^^^^^^^^^^^^^^^^^^ expected due to this
+   |              |
+   |              required by a bound introduced by this call
+   |
+   = note: expected function signature `fn(T) -> _`
+              found function signature `for<'a> fn(&'a _) -> _`
+note: required by a bound in `Option::<T>::map`
+  --> $SRC_DIR/core/src/option.rs:LL:COL
+help: consider adjusting the signature so it does not borrow its argument
+   |
+LL -     fn values(&self) -> Self::Values;
+LL +     fn values(self) -> Self::Values;
+   |
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0053, E0631.
+For more information about an error, try `rustc --explain E0053`.