Skip to content

Commit 9c981b7

Browse files
authored
Merge pull request rust-lang#19085 from Veykril/push-sknwykqmlott
Do not use make use of `InferenceResult::has_errors` flag for mir building
2 parents 3c83458 + 5acbff8 commit 9c981b7

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@ pub struct InferenceResult {
466466
pub type_of_for_iterator: FxHashMap<ExprId, Ty>,
467467
type_mismatches: FxHashMap<ExprOrPatId, TypeMismatch>,
468468
/// Whether there are any type-mismatching errors in the result.
469+
// FIXME: This isn't as useful as initially thought due to us falling back placeholders to
470+
// `TyKind::Error`.
471+
// Which will then mark this field.
469472
pub(crate) has_errors: bool,
470473
/// Interned common types to return references to.
471474
// FIXME: Move this into `InferenceContext`

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

+17-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! and the corresponding code mostly in rustc_hir_analysis/check/method/probe.rs.
55
use std::ops::ControlFlow;
66

7+
use arrayvec::ArrayVec;
78
use base_db::CrateId;
89
use chalk_ir::{cast::Cast, UniverseIndex, WithKind};
910
use hir_def::{
@@ -732,15 +733,27 @@ fn lookup_impl_assoc_item_for_trait_ref(
732733
let self_ty = trait_ref.self_type_parameter(Interner);
733734
let self_ty_fp = TyFingerprint::for_trait_impl(&self_ty)?;
734735
let impls = db.trait_impls_in_deps(env.krate);
735-
let self_impls = match self_ty.kind(Interner) {
736-
TyKind::Adt(id, _) => {
737-
id.0.module(db.upcast()).containing_block().and_then(|it| db.trait_impls_in_block(it))
736+
737+
let trait_module = hir_trait_id.module(db.upcast());
738+
let type_module = match self_ty_fp {
739+
TyFingerprint::Adt(adt_id) => Some(adt_id.module(db.upcast())),
740+
TyFingerprint::ForeignType(type_id) => {
741+
Some(from_foreign_def_id(type_id).module(db.upcast()))
738742
}
743+
TyFingerprint::Dyn(trait_id) => Some(trait_id.module(db.upcast())),
739744
_ => None,
740745
};
746+
747+
let def_blocks: ArrayVec<_, 2> =
748+
[trait_module.containing_block(), type_module.and_then(|it| it.containing_block())]
749+
.into_iter()
750+
.flatten()
751+
.filter_map(|block_id| db.trait_impls_in_block(block_id))
752+
.collect();
753+
741754
let impls = impls
742755
.iter()
743-
.chain(self_impls.as_ref())
756+
.chain(&def_blocks)
744757
.flat_map(|impls| impls.for_trait_and_self_ty(hir_trait_id, self_ty_fp));
745758

746759
let table = InferenceTable::new(db, env);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2156,7 +2156,7 @@ pub fn lower_to_mir(
21562156
// need to take this input explicitly.
21572157
root_expr: ExprId,
21582158
) -> Result<MirBody> {
2159-
if infer.has_errors {
2159+
if infer.type_mismatches().next().is_some() {
21602160
return Err(MirLowerError::HasErrors);
21612161
}
21622162
let mut ctx = MirLowerCtx::new(db, owner, body, infer);

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

+2
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,7 @@ fn func() {
936936
fn override_lint_level() {
937937
check_diagnostics(
938938
r#"
939+
#![allow(unused_variables)]
939940
#[warn(nonstandard_style)]
940941
fn foo() {
941942
let BAR;
@@ -992,6 +993,7 @@ struct QUX;
992993
const foo: i32 = 0;
993994
fn BAR() {
994995
let BAZ;
996+
_ = BAZ;
995997
}
996998
"#,
997999
);

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -831,13 +831,14 @@ fn f() {
831831

832832
#[test]
833833
fn or_pattern() {
834-
// FIXME: `None` is inferred as unknown here for some reason
835834
check_diagnostics(
836835
r#"
837836
//- minicore: option
838837
fn f(_: i32) {}
839838
fn main() {
840839
let ((Some(mut x), None) | (_, Some(mut x))) = (None, Some(7)) else { return };
840+
//^^^^^ 💡 warn: variable does not need to be mutable
841+
841842
f(x);
842843
}
843844
"#,

0 commit comments

Comments
 (0)