mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 17:24:06 +00:00
Fix for issue 91058
This commit is contained in:
parent
3ba27e7dfa
commit
01b24045fa
@ -1695,11 +1695,23 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
_ => exp_found,
|
_ => exp_found,
|
||||||
};
|
};
|
||||||
debug!("exp_found {:?} terr {:?}", exp_found, terr);
|
debug!("exp_found {:?} terr {:?} cause.code {:?}", exp_found, terr, cause.code);
|
||||||
if let Some(exp_found) = exp_found {
|
if let Some(exp_found) = exp_found {
|
||||||
self.suggest_as_ref_where_appropriate(span, &exp_found, diag);
|
let should_suggest_fixes = if let ObligationCauseCode::Pattern { root_ty, .. } =
|
||||||
self.suggest_accessing_field_where_appropriate(cause, &exp_found, diag);
|
&cause.code
|
||||||
self.suggest_await_on_expect_found(cause, span, &exp_found, diag);
|
{
|
||||||
|
// Skip if the root_ty of the pattern is not the same as the expected_ty.
|
||||||
|
// If these types aren't equal then we've probably peeled off a layer of arrays.
|
||||||
|
same_type_modulo_infer(self.resolve_vars_if_possible(*root_ty), exp_found.expected)
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
};
|
||||||
|
|
||||||
|
if should_suggest_fixes {
|
||||||
|
self.suggest_as_ref_where_appropriate(span, &exp_found, diag);
|
||||||
|
self.suggest_accessing_field_where_appropriate(cause, &exp_found, diag);
|
||||||
|
self.suggest_await_on_expect_found(cause, span, &exp_found, diag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// In some (most?) cases cause.body_id points to actual body, but in some cases
|
// In some (most?) cases cause.body_id points to actual body, but in some cases
|
||||||
|
@ -8,10 +8,6 @@ LL | [_, 99.., _] => {},
|
|||||||
|
|
|
|
||||||
= note: expected struct `std::ops::Range<{integer}>`
|
= note: expected struct `std::ops::Range<{integer}>`
|
||||||
found type `{integer}`
|
found type `{integer}`
|
||||||
help: you might have meant to use field `start` whose type is `{integer}`
|
|
||||||
|
|
|
||||||
LL | match [5..4, 99..105, 43..44].start {
|
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
@ -14,10 +14,6 @@ LL | [_, 99..] => {},
|
|||||||
|
|
|
|
||||||
= note: expected struct `std::ops::Range<{integer}>`
|
= note: expected struct `std::ops::Range<{integer}>`
|
||||||
found type `{integer}`
|
found type `{integer}`
|
||||||
help: you might have meant to use field `start` whose type is `{integer}`
|
|
||||||
|
|
|
||||||
LL | match [5..4, 99..105, 43..44].start {
|
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
@ -8,10 +8,6 @@ LL | [..9, 99..100, _] => {},
|
|||||||
|
|
|
|
||||||
= note: expected struct `std::ops::Range<{integer}>`
|
= note: expected struct `std::ops::Range<{integer}>`
|
||||||
found type `{integer}`
|
found type `{integer}`
|
||||||
help: you might have meant to use field `start` whose type is `{integer}`
|
|
||||||
|
|
|
||||||
LL | match [5..4, 99..105, 43..44].start {
|
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:15
|
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:15
|
||||||
@ -25,10 +21,6 @@ LL | [..9, 99..100, _] => {},
|
|||||||
|
|
|
|
||||||
= note: expected struct `std::ops::Range<{integer}>`
|
= note: expected struct `std::ops::Range<{integer}>`
|
||||||
found type `{integer}`
|
found type `{integer}`
|
||||||
help: you might have meant to use field `start` whose type is `{integer}`
|
|
||||||
|
|
|
||||||
LL | match [5..4, 99..105, 43..44].start {
|
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:19
|
--> $DIR/exclusive_range_pattern_syntax_collision3.rs:6:19
|
||||||
@ -42,10 +34,6 @@ LL | [..9, 99..100, _] => {},
|
|||||||
|
|
|
|
||||||
= note: expected struct `std::ops::Range<{integer}>`
|
= note: expected struct `std::ops::Range<{integer}>`
|
||||||
found type `{integer}`
|
found type `{integer}`
|
||||||
help: you might have meant to use field `start` whose type is `{integer}`
|
|
||||||
|
|
|
||||||
LL | match [5..4, 99..105, 43..44].start {
|
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
11
src/test/ui/match/issue-91058.rs
Normal file
11
src/test/ui/match/issue-91058.rs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
struct S(());
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let array = [S(())];
|
||||||
|
|
||||||
|
match array {
|
||||||
|
[()] => {}
|
||||||
|
//~^ ERROR mismatched types [E0308]
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
11
src/test/ui/match/issue-91058.stderr
Normal file
11
src/test/ui/match/issue-91058.stderr
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/issue-91058.rs:7:10
|
||||||
|
|
|
||||||
|
LL | match array {
|
||||||
|
| ----- this expression has type `[S; 1]`
|
||||||
|
LL | [()] => {}
|
||||||
|
| ^^ expected struct `S`, found `()`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0308`.
|
Loading…
Reference in New Issue
Block a user