mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-28 10:39:45 +00:00
fix: Binding wrong assoc ty when lowering trait ref bound
This commit is contained in:
parent
9691da7707
commit
9d459e8de7
2 changed files with 45 additions and 10 deletions
|
|
@ -837,15 +837,16 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
|
||||||
}
|
}
|
||||||
(_, ImplTraitLoweringMode::Param | ImplTraitLoweringMode::Variable) => {
|
(_, ImplTraitLoweringMode::Param | ImplTraitLoweringMode::Variable) => {
|
||||||
// Find the generic index for the target of our `bound`
|
// Find the generic index for the target of our `bound`
|
||||||
let target_param_idx =
|
let target_param_idx = self
|
||||||
self.ctx.resolver.where_predicates_in_scope().find_map(|(p, _)| {
|
.ctx
|
||||||
match p {
|
.resolver
|
||||||
WherePredicate::TypeBound {
|
.where_predicates_in_scope()
|
||||||
target: WherePredicateTypeTarget::TypeOrConstParam(idx),
|
.find_map(|(p, (_, types_map))| match p {
|
||||||
bound: b,
|
WherePredicate::TypeBound {
|
||||||
} if b == bound => Some(idx),
|
target: WherePredicateTypeTarget::TypeOrConstParam(idx),
|
||||||
_ => None,
|
bound: b,
|
||||||
}
|
} if b == bound && self.ctx.types_map == types_map => Some(idx),
|
||||||
|
_ => None,
|
||||||
});
|
});
|
||||||
let ty = if let Some(target_param_idx) = target_param_idx {
|
let ty = if let Some(target_param_idx) = target_param_idx {
|
||||||
let mut counter = 0;
|
let mut counter = 0;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use span::{Edition, EditionedFileId};
|
||||||
use syntax::{TextRange, TextSize};
|
use syntax::{TextRange, TextSize};
|
||||||
use test_fixture::WithFixture;
|
use test_fixture::WithFixture;
|
||||||
|
|
||||||
use crate::{db::HirDatabase, test_db::TestDB, Interner, Substitution};
|
use crate::{db::HirDatabase, mir::MirLowerError, test_db::TestDB, Interner, Substitution};
|
||||||
|
|
||||||
use super::{interpret_mir, MirEvalError};
|
use super::{interpret_mir, MirEvalError};
|
||||||
|
|
||||||
|
|
@ -84,6 +84,16 @@ fn check_panic(#[rust_analyzer::rust_fixture] ra_fixture: &str, expected_panic:
|
||||||
assert_eq!(e.is_panic().unwrap_or_else(|| panic!("unexpected error: {e:?}")), expected_panic);
|
assert_eq!(e.is_panic().unwrap_or_else(|| panic!("unexpected error: {e:?}")), expected_panic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check_error_with(
|
||||||
|
#[rust_analyzer::rust_fixture] ra_fixture: &str,
|
||||||
|
expect_err: impl FnOnce(MirEvalError) -> bool,
|
||||||
|
) {
|
||||||
|
let (db, file_ids) = TestDB::with_many_files(ra_fixture);
|
||||||
|
let file_id = *file_ids.last().unwrap();
|
||||||
|
let e = eval_main(&db, file_id).unwrap_err();
|
||||||
|
assert!(expect_err(e));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn function_with_extern_c_abi() {
|
fn function_with_extern_c_abi() {
|
||||||
check_pass(
|
check_pass(
|
||||||
|
|
@ -945,3 +955,27 @@ fn main() {
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn regression_19177() {
|
||||||
|
check_error_with(
|
||||||
|
r#"
|
||||||
|
//- minicore: copy
|
||||||
|
trait Foo {}
|
||||||
|
trait Bar {}
|
||||||
|
trait Baz {}
|
||||||
|
trait Qux {
|
||||||
|
type Assoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main<'a, T: Foo + Bar + Baz>(
|
||||||
|
x: &T,
|
||||||
|
y: (),
|
||||||
|
z: &'a dyn Qux<Assoc = T>,
|
||||||
|
w: impl Foo + Bar,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
|e| matches!(e, MirEvalError::MirLowerError(_, MirLowerError::GenericArgNotProvided(..))),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue