mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
⬆️ rust-analyzer
This commit is contained in:
parent
61c744d4fd
commit
a2a1d99545
126 changed files with 2098 additions and 904 deletions
|
@ -53,7 +53,7 @@ pub use builder::{ParamKind, TyBuilder};
|
|||
pub use chalk_ext::*;
|
||||
pub use infer::{
|
||||
could_coerce, could_unify, Adjust, Adjustment, AutoBorrow, BindingMode, InferenceDiagnostic,
|
||||
InferenceResult,
|
||||
InferenceResult, OverloadedDeref, PointerCast,
|
||||
};
|
||||
pub use interner::Interner;
|
||||
pub use lower::{
|
||||
|
@ -523,7 +523,7 @@ where
|
|||
}
|
||||
|
||||
pub fn callable_sig_from_fnonce(
|
||||
self_ty: &Canonical<Ty>,
|
||||
self_ty: &Ty,
|
||||
env: Arc<TraitEnvironment>,
|
||||
db: &dyn HirDatabase,
|
||||
) -> Option<CallableSig> {
|
||||
|
@ -531,27 +531,28 @@ pub fn callable_sig_from_fnonce(
|
|||
let fn_once_trait = FnTrait::FnOnce.get_id(db, krate)?;
|
||||
let output_assoc_type = db.trait_data(fn_once_trait).associated_type_by_name(&name![Output])?;
|
||||
|
||||
let mut kinds = self_ty.binders.interned().to_vec();
|
||||
let b = TyBuilder::trait_ref(db, fn_once_trait);
|
||||
if b.remaining() != 2 {
|
||||
return None;
|
||||
}
|
||||
let fn_once = b
|
||||
.push(self_ty.value.clone())
|
||||
.fill_with_bound_vars(DebruijnIndex::INNERMOST, kinds.len())
|
||||
.build();
|
||||
kinds.extend(fn_once.substitution.iter(Interner).skip(1).map(|x| {
|
||||
let vk = match x.data(Interner) {
|
||||
chalk_ir::GenericArgData::Ty(_) => {
|
||||
chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General)
|
||||
}
|
||||
chalk_ir::GenericArgData::Lifetime(_) => chalk_ir::VariableKind::Lifetime,
|
||||
chalk_ir::GenericArgData::Const(c) => {
|
||||
chalk_ir::VariableKind::Const(c.data(Interner).ty.clone())
|
||||
}
|
||||
};
|
||||
chalk_ir::WithKind::new(vk, UniverseIndex::ROOT)
|
||||
}));
|
||||
let fn_once = b.push(self_ty.clone()).fill_with_bound_vars(DebruijnIndex::INNERMOST, 0).build();
|
||||
let kinds = fn_once
|
||||
.substitution
|
||||
.iter(Interner)
|
||||
.skip(1)
|
||||
.map(|x| {
|
||||
let vk = match x.data(Interner) {
|
||||
chalk_ir::GenericArgData::Ty(_) => {
|
||||
chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General)
|
||||
}
|
||||
chalk_ir::GenericArgData::Lifetime(_) => chalk_ir::VariableKind::Lifetime,
|
||||
chalk_ir::GenericArgData::Const(c) => {
|
||||
chalk_ir::VariableKind::Const(c.data(Interner).ty.clone())
|
||||
}
|
||||
};
|
||||
chalk_ir::WithKind::new(vk, UniverseIndex::ROOT)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// FIXME: chalk refuses to solve `<Self as FnOnce<^0.0>>::Output == ^0.1`, so we first solve
|
||||
// `<Self as FnOnce<^0.0>>` and then replace `^0.0` with the concrete argument tuple.
|
||||
|
@ -563,21 +564,16 @@ pub fn callable_sig_from_fnonce(
|
|||
Some(Solution::Unique(vars)) => vars.value.subst,
|
||||
_ => return None,
|
||||
};
|
||||
let args = subst.at(Interner, self_ty.binders.interned().len()).ty(Interner)?;
|
||||
let args = subst.at(Interner, 0).ty(Interner)?;
|
||||
let params = match args.kind(Interner) {
|
||||
chalk_ir::TyKind::Tuple(_, subst) => {
|
||||
subst.iter(Interner).filter_map(|arg| arg.ty(Interner).cloned()).collect::<Vec<_>>()
|
||||
}
|
||||
_ => return None,
|
||||
};
|
||||
if params.iter().any(|ty| ty.is_unknown()) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let fn_once = TyBuilder::trait_ref(db, fn_once_trait)
|
||||
.push(self_ty.value.clone())
|
||||
.push(args.clone())
|
||||
.build();
|
||||
let fn_once =
|
||||
TyBuilder::trait_ref(db, fn_once_trait).push(self_ty.clone()).push(args.clone()).build();
|
||||
let projection =
|
||||
TyBuilder::assoc_type_projection(db, output_assoc_type, Some(fn_once.substitution.clone()))
|
||||
.build();
|
||||
|
|
|
@ -541,7 +541,7 @@ pub struct ReceiverAdjustments {
|
|||
|
||||
impl ReceiverAdjustments {
|
||||
pub(crate) fn apply(&self, table: &mut InferenceTable<'_>, ty: Ty) -> (Ty, Vec<Adjustment>) {
|
||||
let mut ty = ty;
|
||||
let mut ty = table.resolve_ty_shallow(&ty);
|
||||
let mut adjust = Vec::new();
|
||||
for _ in 0..self.autoderefs {
|
||||
match autoderef::autoderef_step(table, ty.clone()) {
|
||||
|
|
|
@ -164,16 +164,16 @@ fn infer_associated_method_with_modules() {
|
|||
check_infer(
|
||||
r#"
|
||||
mod a {
|
||||
struct A;
|
||||
pub struct A;
|
||||
impl A { pub fn thing() -> A { A {} }}
|
||||
}
|
||||
|
||||
mod b {
|
||||
struct B;
|
||||
pub struct B;
|
||||
impl B { pub fn thing() -> u32 { 99 }}
|
||||
|
||||
mod c {
|
||||
struct C;
|
||||
pub mod c {
|
||||
pub struct C;
|
||||
impl C { pub fn thing() -> C { C {} }}
|
||||
}
|
||||
}
|
||||
|
@ -186,22 +186,22 @@ fn infer_associated_method_with_modules() {
|
|||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
55..63 '{ A {} }': A
|
||||
57..61 'A {}': A
|
||||
125..131 '{ 99 }': u32
|
||||
127..129 '99': u32
|
||||
201..209 '{ C {} }': C
|
||||
203..207 'C {}': C
|
||||
240..324 '{ ...g(); }': ()
|
||||
250..251 'x': A
|
||||
254..265 'a::A::thing': fn thing() -> A
|
||||
254..267 'a::A::thing()': A
|
||||
277..278 'y': u32
|
||||
281..292 'b::B::thing': fn thing() -> u32
|
||||
281..294 'b::B::thing()': u32
|
||||
304..305 'z': C
|
||||
308..319 'c::C::thing': fn thing() -> C
|
||||
308..321 'c::C::thing()': C
|
||||
59..67 '{ A {} }': A
|
||||
61..65 'A {}': A
|
||||
133..139 '{ 99 }': u32
|
||||
135..137 '99': u32
|
||||
217..225 '{ C {} }': C
|
||||
219..223 'C {}': C
|
||||
256..340 '{ ...g(); }': ()
|
||||
266..267 'x': A
|
||||
270..281 'a::A::thing': fn thing() -> A
|
||||
270..283 'a::A::thing()': A
|
||||
293..294 'y': u32
|
||||
297..308 'b::B::thing': fn thing() -> u32
|
||||
297..310 'b::B::thing()': u32
|
||||
320..321 'z': C
|
||||
324..335 'c::C::thing': fn thing() -> C
|
||||
324..337 'c::C::thing()': C
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1707,3 +1707,19 @@ impl<T, const N: usize> Trait for [T; N] {
|
|||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsize_array_with_inference_variable() {
|
||||
check_types(
|
||||
r#"
|
||||
//- minicore: try, slice
|
||||
use core::ops::ControlFlow;
|
||||
fn foo() -> ControlFlow<(), [usize; 1]> { loop {} }
|
||||
fn bar() -> ControlFlow<(), ()> {
|
||||
let a = foo()?.len();
|
||||
//^ usize
|
||||
ControlFlow::Continue(())
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -214,7 +214,7 @@ fn infer_paths() {
|
|||
fn a() -> u32 { 1 }
|
||||
|
||||
mod b {
|
||||
fn c() -> u32 { 1 }
|
||||
pub fn c() -> u32 { 1 }
|
||||
}
|
||||
|
||||
fn test() {
|
||||
|
@ -225,13 +225,13 @@ fn test() {
|
|||
expect![[r#"
|
||||
14..19 '{ 1 }': u32
|
||||
16..17 '1': u32
|
||||
47..52 '{ 1 }': u32
|
||||
49..50 '1': u32
|
||||
66..90 '{ ...c(); }': ()
|
||||
72..73 'a': fn a() -> u32
|
||||
72..75 'a()': u32
|
||||
81..85 'b::c': fn c() -> u32
|
||||
81..87 'b::c()': u32
|
||||
51..56 '{ 1 }': u32
|
||||
53..54 '1': u32
|
||||
70..94 '{ ...c(); }': ()
|
||||
76..77 'a': fn a() -> u32
|
||||
76..79 'a()': u32
|
||||
85..89 'b::c': fn c() -> u32
|
||||
85..91 'b::c()': u32
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -1856,7 +1856,7 @@ fn not_shadowing_module_by_primitive() {
|
|||
check_types(
|
||||
r#"
|
||||
//- /str.rs
|
||||
fn foo() -> u32 {0}
|
||||
pub fn foo() -> u32 {0}
|
||||
|
||||
//- /main.rs
|
||||
mod str;
|
||||
|
|
|
@ -1706,7 +1706,7 @@ fn where_clause_trait_in_scope_for_method_resolution() {
|
|||
check_types(
|
||||
r#"
|
||||
mod foo {
|
||||
trait Trait {
|
||||
pub trait Trait {
|
||||
fn foo(&self) -> u32 { 0 }
|
||||
}
|
||||
}
|
||||
|
@ -1723,7 +1723,7 @@ fn super_trait_method_resolution() {
|
|||
check_infer(
|
||||
r#"
|
||||
mod foo {
|
||||
trait SuperTrait {
|
||||
pub trait SuperTrait {
|
||||
fn foo(&self) -> u32 {}
|
||||
}
|
||||
}
|
||||
|
@ -1735,15 +1735,15 @@ fn test<T: Trait1, U: Trait2>(x: T, y: U) {
|
|||
y.foo();
|
||||
}"#,
|
||||
expect![[r#"
|
||||
49..53 'self': &Self
|
||||
62..64 '{}': u32
|
||||
181..182 'x': T
|
||||
187..188 'y': U
|
||||
193..222 '{ ...o(); }': ()
|
||||
199..200 'x': T
|
||||
199..206 'x.foo()': u32
|
||||
212..213 'y': U
|
||||
212..219 'y.foo()': u32
|
||||
53..57 'self': &Self
|
||||
66..68 '{}': u32
|
||||
185..186 'x': T
|
||||
191..192 'y': U
|
||||
197..226 '{ ...o(); }': ()
|
||||
203..204 'x': T
|
||||
203..210 'x.foo()': u32
|
||||
216..217 'y': U
|
||||
216..223 'y.foo()': u32
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -1754,7 +1754,7 @@ fn super_trait_impl_trait_method_resolution() {
|
|||
r#"
|
||||
//- minicore: sized
|
||||
mod foo {
|
||||
trait SuperTrait {
|
||||
pub trait SuperTrait {
|
||||
fn foo(&self) -> u32 {}
|
||||
}
|
||||
}
|
||||
|
@ -1764,12 +1764,12 @@ fn test(x: &impl Trait1) {
|
|||
x.foo();
|
||||
}"#,
|
||||
expect![[r#"
|
||||
49..53 'self': &Self
|
||||
62..64 '{}': u32
|
||||
115..116 'x': &impl Trait1
|
||||
132..148 '{ ...o(); }': ()
|
||||
138..139 'x': &impl Trait1
|
||||
138..145 'x.foo()': u32
|
||||
53..57 'self': &Self
|
||||
66..68 '{}': u32
|
||||
119..120 'x': &impl Trait1
|
||||
136..152 '{ ...o(); }': ()
|
||||
142..143 'x': &impl Trait1
|
||||
142..149 'x.foo()': u32
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue