Skip to content

Commit f16a03f

Browse files
committed
Auto merge of rust-lang#18067 - Veykril:prevent-mir-building, r=Veykril
fix: Properly prevent mir building with unknown types present
2 parents 835972b + bdc9da9 commit f16a03f

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/tools/rust-analyzer/crates/hir-ty/src/infer.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,6 @@ impl<'a> InferenceContext<'a> {
708708
tuple_field_access_types: _,
709709
coercion_casts,
710710
} = &mut result;
711-
712711
table.fallback_if_possible();
713712

714713
// Comment from rustc:
@@ -754,7 +753,7 @@ impl<'a> InferenceContext<'a> {
754753
*has_errors = *has_errors || ty.contains_unknown();
755754
}
756755

757-
*has_errors = !type_mismatches.is_empty();
756+
*has_errors |= !type_mismatches.is_empty();
758757

759758
type_mismatches.retain(|_, mismatch| {
760759
mismatch.expected = table.resolve_completely(mismatch.expected.clone());
@@ -797,20 +796,30 @@ impl<'a> InferenceContext<'a> {
797796
});
798797
for (_, subst) in method_resolutions.values_mut() {
799798
*subst = table.resolve_completely(subst.clone());
799+
*has_errors =
800+
*has_errors || subst.type_parameters(Interner).any(|ty| ty.contains_unknown());
800801
}
801802
for (_, subst) in assoc_resolutions.values_mut() {
802803
*subst = table.resolve_completely(subst.clone());
804+
*has_errors =
805+
*has_errors || subst.type_parameters(Interner).any(|ty| ty.contains_unknown());
803806
}
804807
for adjustment in expr_adjustments.values_mut().flatten() {
805808
adjustment.target = table.resolve_completely(adjustment.target.clone());
809+
*has_errors = *has_errors || adjustment.target.contains_unknown();
806810
}
807811
for adjustment in pat_adjustments.values_mut().flatten() {
808812
*adjustment = table.resolve_completely(adjustment.clone());
813+
*has_errors = *has_errors || adjustment.contains_unknown();
809814
}
810815
result.tuple_field_access_types = tuple_field_accesses_rev
811816
.into_iter()
812817
.enumerate()
813818
.map(|(idx, subst)| (TupleId(idx as u32), table.resolve_completely(subst)))
819+
.inspect(|(_, subst)| {
820+
*has_errors =
821+
*has_errors || subst.type_parameters(Interner).any(|ty| ty.contains_unknown());
822+
})
814823
.collect();
815824
result
816825
}

src/tools/rust-analyzer/crates/hir-ty/src/mir.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ impl<V, T> ProjectionElem<V, T> {
185185
never!("Out of bound tuple field");
186186
TyKind::Error.intern(Interner)
187187
}),
188-
_ => {
189-
never!("Only tuple has tuple field");
188+
ty => {
189+
never!("Only tuple has tuple field: {:?}", ty);
190190
TyKind::Error.intern(Interner)
191191
}
192192
},

src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -824,13 +824,13 @@ fn f() {
824824

825825
#[test]
826826
fn or_pattern() {
827+
// FIXME: `None` is inferred as unknown here for some reason
827828
check_diagnostics(
828829
r#"
829830
//- minicore: option
830831
fn f(_: i32) {}
831832
fn main() {
832833
let ((Some(mut x), None) | (_, Some(mut x))) = (None, Some(7)) else { return };
833-
//^^^^^ 💡 warn: variable does not need to be mutable
834834
f(x);
835835
}
836836
"#,

0 commit comments

Comments
 (0)