mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Adjust inner span of implicit self ref argument
This commit is contained in:
parent
8621285e3b
commit
0f7ef1a202
@ -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),
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
17
tests/ui/typeck/mismatched-map-under-self.rs
Normal file
17
tests/ui/typeck/mismatched-map-under-self.rs
Normal file
@ -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() {}
|
42
tests/ui/typeck/mismatched-map-under-self.stderr
Normal file
42
tests/ui/typeck/mismatched-map-under-self.stderr
Normal file
@ -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`.
|
Loading…
Reference in New Issue
Block a user