diff --git a/Cargo.lock b/Cargo.lock index c7cf4479b3..1209cee03c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -161,9 +161,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chalk-derive" -version = "0.96.0" +version = "0.97.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5676cea088c32290fe65c82895be9d06dd21e0fa49bb97ca840529e9417ab71a" +checksum = "92a0aedc4ac2adc5c0b7dc9ec38c5c816284ad28da6d4ecd01873b9683f54972" dependencies = [ "proc-macro2", "quote", @@ -173,20 +173,19 @@ dependencies = [ [[package]] name = "chalk-ir" -version = "0.96.0" +version = "0.97.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff550c2cdd63ff74394214dce03d06386928a641c0f08837535f04af573a966d" +checksum = "db18493569b190f7266a04901e520fc3a5c00564475154287906f8a27302c119" dependencies = [ "bitflags 2.4.2", "chalk-derive", - "lazy_static", ] [[package]] name = "chalk-recursive" -version = "0.96.0" +version = "0.97.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c4559e5c9b200240453b07d893f9c3c74413b53b0d33cbe272c68b0b77aa1c3" +checksum = "ae4ba8ce5bd2e1b59f1f79495bc8704db09a8285e51cc5ddf01d9baee1bf447d" dependencies = [ "chalk-derive", "chalk-ir", @@ -197,9 +196,9 @@ dependencies = [ [[package]] name = "chalk-solve" -version = "0.96.0" +version = "0.97.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0882e68ce9eb5a0a2413806538494d19df6ee520ab17d1faf489e952f32e98b8" +checksum = "b2ec1b3b7f7b1ec38f099ef39c2bc3ea29335be1b8316d114baff46d96d131e9" dependencies = [ "chalk-derive", "chalk-ir", diff --git a/Cargo.toml b/Cargo.toml index 99338d9d97..06b092a449 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -106,10 +106,10 @@ arrayvec = "0.7.4" bitflags = "2.4.1" cargo_metadata = "0.18.1" camino = "1.1.6" -chalk-solve = { version = "0.96.0", default-features = false } -chalk-ir = "0.96.0" -chalk-recursive = { version = "0.96.0", default-features = false } -chalk-derive = "0.96.0" +chalk-solve = { version = "0.97.0", default-features = false } +chalk-ir = "0.97.0" +chalk-recursive = { version = "0.97.0", default-features = false } +chalk-derive = "0.97.0" command-group = "2.0.1" crossbeam-channel = "0.5.8" dissimilar = "1.0.7" diff --git a/crates/hir-ty/src/display.rs b/crates/hir-ty/src/display.rs index 22a52e6a23..42e33a9853 100644 --- a/crates/hir-ty/src/display.rs +++ b/crates/hir-ty/src/display.rs @@ -42,9 +42,10 @@ use crate::{ primitive, to_assoc_type_id, utils::{self, detect_variant_from_bytes, generics, ClosureSubst}, AdtId, AliasEq, AliasTy, Binders, CallableDefId, CallableSig, Const, ConstScalar, ConstValue, - DomainGoal, FnAbi, GenericArg, ImplTraitId, Interner, Lifetime, LifetimeData, LifetimeOutlives, - MemoryMap, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt, QuantifiedWhereClause, Scalar, - Substitution, TraitEnvironment, TraitRef, TraitRefExt, Ty, TyExt, WhereClause, + DomainGoal, FnAbi, GenericArg, GenericArgData, ImplTraitId, Interner, Lifetime, LifetimeData, + LifetimeOutlives, MemoryMap, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt, + QuantifiedWhereClause, Scalar, Substitution, TraitEnvironment, TraitRef, TraitRefExt, Ty, + TyExt, WhereClause, }; pub trait HirWrite: fmt::Write { @@ -1367,8 +1368,8 @@ fn hir_fmt_generics( return true; } } - if parameter.lifetime(Interner).map(|it| it.data(Interner)) - == Some(&crate::LifetimeData::Static) + if let Some(crate::LifetimeData::Static | crate::LifetimeData::Error) = + parameter.lifetime(Interner).map(|it| it.data(Interner)) { return true; } @@ -1403,10 +1404,18 @@ fn hir_fmt_generics( write!(f, ", ")?; } first = false; - if f.display_target.is_source_code() - && generic_arg.ty(Interner).map(|ty| ty.kind(Interner)) == Some(&TyKind::Error) - { - write!(f, "_")?; + if f.display_target.is_source_code() { + match generic_arg.data(Interner) { + GenericArgData::Lifetime(l) + if matches!(l.data(Interner), LifetimeData::Error) => + { + write!(f, "'_") + } + GenericArgData::Ty(t) if matches!(t.kind(Interner), TyKind::Error) => { + write!(f, "_") + } + _ => generic_arg.hir_fmt(f), + }? } else { generic_arg.hir_fmt(f)?; } @@ -1729,6 +1738,7 @@ impl HirDisplay for LifetimeData { Ok(()) } LifetimeData::Static => write!(f, "'static"), + LifetimeData::Error => write!(f, "'{{error}}"), LifetimeData::Erased => Ok(()), LifetimeData::Phantom(_, _) => Ok(()), } diff --git a/crates/hir-ty/src/lib.rs b/crates/hir-ty/src/lib.rs index b12ccf7c83..b9f4c57366 100644 --- a/crates/hir-ty/src/lib.rs +++ b/crates/hir-ty/src/lib.rs @@ -612,8 +612,6 @@ has_interner!(ImplTraits); #[derive(PartialEq, Eq, Debug, Hash)] pub struct ImplTrait { - // FIXME: Should be Arc<[QuantifiedWhereClause]>, but the HasInterner impl for Arc is missing a - // ?Sized bound pub(crate) bounds: Binders>, } @@ -624,7 +622,7 @@ pub fn static_lifetime() -> Lifetime { } pub fn error_lifetime() -> Lifetime { - LifetimeData::Static.intern(Interner) + LifetimeData::Error.intern(Interner) } pub(crate) fn fold_free_vars + TypeFoldable>( diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs index bfc84ee5e3..4d0516ead6 100644 --- a/crates/hir-ty/src/lower.rs +++ b/crates/hir-ty/src/lower.rs @@ -67,9 +67,9 @@ use crate::{ }, AliasEq, AliasTy, Binders, BoundVar, CallableSig, Const, ConstScalar, DebruijnIndex, DynTy, FnAbi, FnPointer, FnSig, FnSubst, ImplTrait, ImplTraitId, ImplTraits, Interner, Lifetime, - LifetimeData, LifetimeOutlives, ParamKind, PolyFnSig, ProjectionTy, QuantifiedWhereClause, - QuantifiedWhereClauses, Substitution, TraitEnvironment, TraitRef, TraitRefExt, Ty, TyBuilder, - TyKind, WhereClause, + LifetimeData, LifetimeOutlives, ParamKind, PolyFnSig, ProgramClause, ProjectionTy, + QuantifiedWhereClause, QuantifiedWhereClauses, Substitution, TraitEnvironment, TraitRef, + TraitRefExt, Ty, TyBuilder, TyKind, WhereClause, }; #[derive(Debug)] @@ -1052,11 +1052,11 @@ impl<'a> TyLoweringContext<'a> { self_ty: Ty, ignore_bindings: bool, ) -> impl Iterator + 'a { - let mut bindings = None; - let trait_ref = match bound.as_ref() { + let mut trait_ref = None; + let clause = match bound.as_ref() { TypeBound::Path(path, TraitBoundModifier::None) => { - bindings = self.lower_trait_ref_from_path(path, Some(self_ty)); - bindings + trait_ref = self.lower_trait_ref_from_path(path, Some(self_ty)); + trait_ref .clone() .filter(|tr| { // ignore `T: Drop` or `T: Destruct` bounds. @@ -1092,8 +1092,8 @@ impl<'a> TyLoweringContext<'a> { } TypeBound::ForLifetime(_, path) => { // FIXME Don't silently drop the hrtb lifetimes here - bindings = self.lower_trait_ref_from_path(path, Some(self_ty)); - bindings.clone().map(WhereClause::Implemented).map(crate::wrap_empty_binders) + trait_ref = self.lower_trait_ref_from_path(path, Some(self_ty)); + trait_ref.clone().map(WhereClause::Implemented).map(crate::wrap_empty_binders) } TypeBound::Lifetime(l) => { let lifetime = self.lower_lifetime(l); @@ -1104,8 +1104,8 @@ impl<'a> TyLoweringContext<'a> { } TypeBound::Error => None, }; - trait_ref.into_iter().chain( - bindings + clause.into_iter().chain( + trait_ref .into_iter() .filter(move |_| !ignore_bindings) .flat_map(move |tr| self.assoc_type_bindings_from_type_bound(bound, tr)), @@ -1624,10 +1624,14 @@ pub(crate) fn generic_predicates_for_param_query( let subst = generics.bound_vars_subst(db, DebruijnIndex::INNERMOST); let explicitly_unsized_tys = ctx.unsized_types.into_inner(); - let implicitly_sized_predicates = + if let Some(implicitly_sized_predicates) = implicitly_sized_clauses(db, param_id.parent, &explicitly_unsized_tys, &subst, &resolver) - .map(|p| make_binders(db, &generics, crate::wrap_empty_binders(p))); - predicates.extend(implicitly_sized_predicates); + { + predicates.extend( + implicitly_sized_predicates + .map(|p| make_binders(db, &generics, crate::wrap_empty_binders(p))), + ); + } predicates.into() } @@ -1685,24 +1689,23 @@ pub(crate) fn trait_environment_query( let substs = TyBuilder::placeholder_subst(db, trait_id); let trait_ref = TraitRef { trait_id: to_chalk_trait_id(trait_id), substitution: substs }; let pred = WhereClause::Implemented(trait_ref); - let program_clause: chalk_ir::ProgramClause = pred.cast(Interner); - clauses.push(program_clause.into_from_env_clause(Interner)); + clauses.push(pred.cast::(Interner).into_from_env_clause(Interner)); } let subst = generics(db.upcast(), def).placeholder_subst(db); let explicitly_unsized_tys = ctx.unsized_types.into_inner(); - let implicitly_sized_clauses = - implicitly_sized_clauses(db, def, &explicitly_unsized_tys, &subst, &resolver).map(|pred| { - let program_clause: chalk_ir::ProgramClause = pred.cast(Interner); - program_clause.into_from_env_clause(Interner) - }); - clauses.extend(implicitly_sized_clauses); - - let krate = def.module(db.upcast()).krate(); + if let Some(implicitly_sized_clauses) = + implicitly_sized_clauses(db, def, &explicitly_unsized_tys, &subst, &resolver) + { + clauses.extend( + implicitly_sized_clauses + .map(|pred| pred.cast::(Interner).into_from_env_clause(Interner)), + ); + } let env = chalk_ir::Environment::new(Interner).add_clauses(Interner, clauses); - TraitEnvironment::new(krate, None, traits_in_scope.into_boxed_slice(), env) + TraitEnvironment::new(resolver.krate(), None, traits_in_scope.into_boxed_slice(), env) } /// Resolve the where clause(s) of an item with generics. @@ -1730,10 +1733,14 @@ pub(crate) fn generic_predicates_query( let subst = generics.bound_vars_subst(db, DebruijnIndex::INNERMOST); let explicitly_unsized_tys = ctx.unsized_types.into_inner(); - let implicitly_sized_predicates = + if let Some(implicitly_sized_predicates) = implicitly_sized_clauses(db, def, &explicitly_unsized_tys, &subst, &resolver) - .map(|p| make_binders(db, &generics, crate::wrap_empty_binders(p))); - predicates.extend(implicitly_sized_predicates); + { + predicates.extend( + implicitly_sized_predicates + .map(|p| make_binders(db, &generics, crate::wrap_empty_binders(p))), + ); + } predicates.into() } @@ -1745,24 +1752,24 @@ fn implicitly_sized_clauses<'a>( explicitly_unsized_tys: &'a FxHashSet, substitution: &'a Substitution, resolver: &Resolver, -) -> impl Iterator + 'a { +) -> Option + 'a> { let is_trait_def = matches!(def, GenericDefId::TraitId(..)); let generic_args = &substitution.as_slice(Interner)[is_trait_def as usize..]; let sized_trait = db .lang_item(resolver.krate(), LangItem::Sized) .and_then(|lang_item| lang_item.as_trait().map(to_chalk_trait_id)); - sized_trait.into_iter().flat_map(move |sized_trait| { - let implicitly_sized_tys = generic_args + sized_trait.map(move |sized_trait| { + generic_args .iter() .filter_map(|generic_arg| generic_arg.ty(Interner)) - .filter(move |&self_ty| !explicitly_unsized_tys.contains(self_ty)); - implicitly_sized_tys.map(move |self_ty| { - WhereClause::Implemented(TraitRef { - trait_id: sized_trait, - substitution: Substitution::from1(Interner, self_ty.clone()), + .filter(move |&self_ty| !explicitly_unsized_tys.contains(self_ty)) + .map(move |self_ty| { + WhereClause::Implemented(TraitRef { + trait_id: sized_trait, + substitution: Substitution::from1(Interner, self_ty.clone()), + }) }) - }) }) } diff --git a/crates/hir-ty/src/tests/display_source_code.rs b/crates/hir-ty/src/tests/display_source_code.rs index 5069267499..e4c5d709da 100644 --- a/crates/hir-ty/src/tests/display_source_code.rs +++ b/crates/hir-ty/src/tests/display_source_code.rs @@ -85,7 +85,7 @@ fn render_dyn_for_ty() { trait Foo<'a> {} fn foo(foo: &dyn for<'a> Foo<'a>) {} - // ^^^ &dyn Foo<'static> + // ^^^ &dyn Foo<'{error}> "#, ); } diff --git a/crates/hir-ty/src/tests/patterns.rs b/crates/hir-ty/src/tests/patterns.rs index 80d5a0ae00..4355881d72 100644 --- a/crates/hir-ty/src/tests/patterns.rs +++ b/crates/hir-ty/src/tests/patterns.rs @@ -1109,7 +1109,7 @@ fn var_args() { #[lang = "va_list"] pub struct VaListImpl<'f>; fn my_fn(foo: ...) {} - //^^^ VaListImpl<'static> + //^^^ VaListImpl<'{error}> "#, ); } diff --git a/crates/hir-ty/src/tests/regression.rs b/crates/hir-ty/src/tests/regression.rs index 8565b60210..c2d2047e6f 100644 --- a/crates/hir-ty/src/tests/regression.rs +++ b/crates/hir-ty/src/tests/regression.rs @@ -896,13 +896,13 @@ fn flush(&self) { "#, expect![[r#" 123..127 'self': &Mutex - 150..152 '{}': MutexGuard<'static, T> + 150..152 '{}': MutexGuard<'{error}, T> 234..238 'self': &{unknown} 240..290 '{ ...()); }': () 250..251 'w': &Mutex 276..287 '*(w.lock())': BufWriter 278..279 'w': &Mutex - 278..286 'w.lock()': MutexGuard<'static, BufWriter> + 278..286 'w.lock()': MutexGuard<'{error}, BufWriter> "#]], ); } diff --git a/crates/hir-ty/src/tests/simple.rs b/crates/hir-ty/src/tests/simple.rs index f39404593e..a9d28ebfef 100644 --- a/crates/hir-ty/src/tests/simple.rs +++ b/crates/hir-ty/src/tests/simple.rs @@ -3092,7 +3092,7 @@ fn main() { 389..394 'boxed': Box> 389..406 'boxed....nner()': &i32 416..421 'good1': &i32 - 424..438 'Foo::get_inner': fn get_inner(&Box>) -> &i32 + 424..438 'Foo::get_inner': fn get_inner(&Box>) -> &i32 424..446 'Foo::g...boxed)': &i32 439..445 '&boxed': &Box> 440..445 'boxed': Box> @@ -3100,7 +3100,7 @@ fn main() { 464..469 'boxed': Box> 464..480 'boxed....self()': &Foo 490..495 'good2': &Foo - 498..511 'Foo::get_self': fn get_self(&Box>) -> &Foo + 498..511 'Foo::get_self': fn get_self(&Box>) -> &Foo 498..519 'Foo::g...boxed)': &Foo 512..518 '&boxed': &Box> 513..518 'boxed': Box> @@ -3659,7 +3659,7 @@ fn main() { let are = "are"; let count = 10; builtin#format_args("hello {count:02} {} friends, we {are:?} {0}{last}", "fancy", last = "!"); - // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type: Arguments<'static> + // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type: Arguments<'{error}> } "#, ); diff --git a/crates/hir-ty/src/tests/traits.rs b/crates/hir-ty/src/tests/traits.rs index fac850eeaf..dfcd322a39 100644 --- a/crates/hir-ty/src/tests/traits.rs +++ b/crates/hir-ty/src/tests/traits.rs @@ -1602,7 +1602,7 @@ fn weird_bounds() { r#" //- minicore: sized trait Trait {} -fn test( +fn test<'lifetime>( a: impl Trait + 'lifetime, b: impl 'lifetime, c: impl (Trait), @@ -1612,13 +1612,13 @@ fn test( ) {} "#, expect![[r#" - 28..29 'a': impl Trait + 'static - 59..60 'b': impl 'static - 82..83 'c': impl Trait - 103..104 'd': impl 'static - 128..129 'e': impl ?Sized - 148..149 'f': impl Trait + ?Sized - 173..175 '{}': () + 39..40 'a': impl Trait + 'lifetime + 70..71 'b': impl 'lifetime + 93..94 'c': impl Trait + 114..115 'd': impl 'lifetime + 139..140 'e': impl ?Sized + 159..160 'f': impl Trait + ?Sized + 184..186 '{}': () "#]], ); } diff --git a/crates/ide-assists/src/handlers/extract_function.rs b/crates/ide-assists/src/handlers/extract_function.rs index 65ce3e822c..d111005c2e 100644 --- a/crates/ide-assists/src/handlers/extract_function.rs +++ b/crates/ide-assists/src/handlers/extract_function.rs @@ -5617,7 +5617,7 @@ fn func(i: Struct<'_, T>) { fun_name(i); } -fn $0fun_name(i: Struct<'static, T>) { +fn $0fun_name(i: Struct<'_, T>) { foo(i); } "#, diff --git a/crates/ide-assists/src/handlers/inline_call.rs b/crates/ide-assists/src/handlers/inline_call.rs index a90fe83857..44307ffd75 100644 --- a/crates/ide-assists/src/handlers/inline_call.rs +++ b/crates/ide-assists/src/handlers/inline_call.rs @@ -49,13 +49,13 @@ use crate::{ // // fn bar() { // { -// let word = "안녕하세요"; +// let word: &str = "안녕하세요"; // if !word.is_empty() { // print(word); // } // }; // { -// let word = "여러분"; +// let word: &str = "여러분"; // if !word.is_empty() { // print(word); // } diff --git a/crates/ide-assists/src/tests/generated.rs b/crates/ide-assists/src/tests/generated.rs index a66e199a75..71dae47f5c 100644 --- a/crates/ide-assists/src/tests/generated.rs +++ b/crates/ide-assists/src/tests/generated.rs @@ -1820,13 +1820,13 @@ fn print(_: &str) {} fn bar() { { - let word = "안녕하세요"; + let word: &str = "안녕하세요"; if !word.is_empty() { print(word); } }; { - let word = "여러분"; + let word: &str = "여러분"; if !word.is_empty() { print(word); } diff --git a/crates/ide-completion/src/tests/predicate.rs b/crates/ide-completion/src/tests/predicate.rs index 3718dff56e..64a32dee3d 100644 --- a/crates/ide-completion/src/tests/predicate.rs +++ b/crates/ide-completion/src/tests/predicate.rs @@ -19,7 +19,7 @@ struct Foo<'lt, T, const C: usize> where $0 {} en Enum Enum ma makro!(…) macro_rules! makro md module - st Foo<…> Foo<'static, {unknown}, _> + st Foo<…> Foo<'{error}, {unknown}, _> st Record Record st Tuple Tuple st Unit Unit @@ -92,7 +92,7 @@ struct Foo<'lt, T, const C: usize> where for<'a> $0 {} en Enum Enum ma makro!(…) macro_rules! makro md module - st Foo<…> Foo<'static, {unknown}, _> + st Foo<…> Foo<'{error}, {unknown}, _> st Record Record st Tuple Tuple st Unit Unit diff --git a/crates/ide-completion/src/tests/type_pos.rs b/crates/ide-completion/src/tests/type_pos.rs index 9770972865..66f1bff7c1 100644 --- a/crates/ide-completion/src/tests/type_pos.rs +++ b/crates/ide-completion/src/tests/type_pos.rs @@ -20,8 +20,8 @@ struct Foo<'lt, T, const C: usize> { en Enum Enum ma makro!(…) macro_rules! makro md module - sp Self Foo<'static, {unknown}, _> - st Foo<…> Foo<'static, {unknown}, _> + sp Self Foo<'{error}, {unknown}, _> + st Foo<…> Foo<'{error}, {unknown}, _> st Record Record st Tuple Tuple st Unit Unit @@ -45,8 +45,8 @@ struct Foo<'lt, T, const C: usize>(f$0); en Enum Enum ma makro!(…) macro_rules! makro md module - sp Self Foo<'static, {unknown}, _> - st Foo<…> Foo<'static, {unknown}, _> + sp Self Foo<'{error}, {unknown}, _> + st Foo<…> Foo<'{error}, {unknown}, _> st Record Record st Tuple Tuple st Unit Unit