mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Adjust an expr span to account for macros
This commit is contained in:
parent
9de7474830
commit
dec29b1582
@ -39,8 +39,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
let scrut_diverges = self.diverges.replace(Diverges::Maybe);
|
let scrut_diverges = self.diverges.replace(Diverges::Maybe);
|
||||||
|
|
||||||
// #55810: Type check patterns first so we get types for all bindings.
|
// #55810: Type check patterns first so we get types for all bindings.
|
||||||
|
let scrut_span = scrut.span.find_ancestor_inside(expr.span).unwrap_or(scrut.span);
|
||||||
for arm in arms {
|
for arm in arms {
|
||||||
self.check_pat_top(&arm.pat, scrutinee_ty, Some(scrut.span), true);
|
self.check_pat_top(&arm.pat, scrutinee_ty, Some(scrut_span), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now typecheck the blocks.
|
// Now typecheck the blocks.
|
||||||
|
@ -1234,7 +1234,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// Does the expected pattern type originate from an expression and what is the span?
|
// Does the expected pattern type originate from an expression and what is the span?
|
||||||
let (origin_expr, ty_span) = match (decl.ty, decl.init) {
|
let (origin_expr, ty_span) = match (decl.ty, decl.init) {
|
||||||
(Some(ty), _) => (false, Some(ty.span)), // Bias towards the explicit user type.
|
(Some(ty), _) => (false, Some(ty.span)), // Bias towards the explicit user type.
|
||||||
(_, Some(init)) => (true, Some(init.span)), // No explicit type; so use the scrutinee.
|
(_, Some(init)) => {
|
||||||
|
(true, Some(init.span.find_ancestor_inside(decl.span).unwrap_or(init.span)))
|
||||||
|
} // No explicit type; so use the scrutinee.
|
||||||
_ => (false, None), // We have `let $pat;`, so the expected type is unconstrained.
|
_ => (false, None), // We have `let $pat;`, so the expected type is unconstrained.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -24,4 +24,8 @@ fn main() {
|
|||||||
//~^ ERROR: expected an array or slice
|
//~^ ERROR: expected an array or slice
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let [..] = vec![1, 2, 3][..];
|
||||||
|
//~^ ERROR: expected an array or slice
|
||||||
|
//~| HELP: consider slicing here
|
||||||
}
|
}
|
||||||
|
@ -24,4 +24,8 @@ fn main() {
|
|||||||
//~^ ERROR: expected an array or slice
|
//~^ ERROR: expected an array or slice
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let [..] = vec![1, 2, 3];
|
||||||
|
//~^ ERROR: expected an array or slice
|
||||||
|
//~| HELP: consider slicing here
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,14 @@ LL |
|
|||||||
LL | [5] => {}
|
LL | [5] => {}
|
||||||
| ^^^ pattern cannot match with input type `Vec<_>`
|
| ^^^ pattern cannot match with input type `Vec<_>`
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error[E0529]: expected an array or slice, found `Vec<{integer}>`
|
||||||
|
--> $DIR/pattern-slice-vec.rs:28:9
|
||||||
|
|
|
||||||
|
LL | let [..] = vec![1, 2, 3];
|
||||||
|
| ^^^^ ------------- help: consider slicing here: `vec![1, 2, 3][..]`
|
||||||
|
| |
|
||||||
|
| pattern cannot match with input type `Vec<{integer}>`
|
||||||
|
|
||||||
|
error: aborting due to 5 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0529`.
|
For more information about this error, try `rustc --explain E0529`.
|
||||||
|
Loading…
Reference in New Issue
Block a user