Skip to content

Commit c97ac34

Browse files
committed
Fix impl trait params not being counted properly
1 parent 8241d8a commit c97ac34

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

crates/hir-ty/src/lower.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,9 @@ impl<'a> TyLoweringContext<'a> {
345345
}
346346
ImplTraitLoweringState::Param(counter) => {
347347
let idx = counter.get();
348-
counter.set(idx + 1);
348+
// Count the number of `impl Trait` things that appear within our bounds.
349+
// Since t hose have been emitted as implicit type args already.
350+
counter.set(idx + count_impl_traits(type_ref) as u16);
349351
let kind = self
350352
.generics()
351353
.expect("param impl trait lowering must be in a generic def")
@@ -367,7 +369,9 @@ impl<'a> TyLoweringContext<'a> {
367369
}
368370
ImplTraitLoweringState::Variable(counter) => {
369371
let idx = counter.get();
370-
counter.set(idx + 1);
372+
// Count the number of `impl Trait` things that appear within our bounds.
373+
// Since t hose have been emitted as implicit type args already.
374+
counter.set(idx + count_impl_traits(type_ref) as u16);
371375
let (
372376
_parent_params,
373377
self_params,
@@ -1397,6 +1401,17 @@ pub fn associated_type_shorthand_candidates<R>(
13971401
named_associated_type_shorthand_candidates(db, def, res, None, |name, _, id| cb(name, id))
13981402
}
13991403

1404+
// FIXME: This does not handle macros!
1405+
fn count_impl_traits(type_ref: &TypeRef) -> usize {
1406+
let mut count = 0;
1407+
type_ref.walk(&mut |type_ref| {
1408+
if matches!(type_ref, TypeRef::ImplTrait(_)) {
1409+
count += 1;
1410+
}
1411+
});
1412+
count
1413+
}
1414+
14001415
fn named_associated_type_shorthand_candidates<R>(
14011416
db: &dyn HirDatabase,
14021417
// If the type parameter is defined in an impl and we're in a method, there

crates/hir-ty/src/tests/regression.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1980,16 +1980,19 @@ impl<#[cfg(feature = "a-feature")] A> Bar for (){}
19801980
fn nested_anon_generics_and_where_bounds_17173() {
19811981
check_types(
19821982
r#"
1983-
//- minicore: sized
1983+
//- minicore: sized, fn
19841984
pub trait Lookup {
19851985
type Data;
19861986
fn lookup(&self) -> Self::Data;
19871987
}
19881988
pub trait ItemTreeLoc {
19891989
type Id;
19901990
}
1991-
fn id_to_generics(id: impl Lookup<Data = impl ItemTreeLoc<Id = ()>>)
1991+
fn id_to_generics(id: impl Lookup<Data = impl ItemTreeLoc<Id = ()>>,
19921992
//^^ impl Lookup<Data = impl ItemTreeLoc<Id = ()>>
1993+
enabled_params: impl Fn(),
1994+
//^^^^^^^^^^^^^^ impl Fn()
1995+
)
19931996
where
19941997
(): Sized,
19951998
{}

crates/rust-analyzer/src/cli/diagnostics.rs

+11
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ use crate::cli::flags;
1313

1414
impl flags::Diagnostics {
1515
pub fn run(self) -> anyhow::Result<()> {
16+
const STACK_SIZE: usize = 1024 * 1024 * 8;
17+
18+
let handle = stdx::thread::Builder::new(stdx::thread::ThreadIntent::LatencySensitive)
19+
.name("BIG_STACK_THREAD".into())
20+
.stack_size(STACK_SIZE)
21+
.spawn(|| self.run_())
22+
.unwrap();
23+
24+
handle.join()
25+
}
26+
fn run_(self) -> anyhow::Result<()> {
1627
let cargo_config =
1728
CargoConfig { sysroot: Some(RustLibSource::Discover), ..Default::default() };
1829
let with_proc_macro_server = if let Some(p) = &self.proc_macro_srv {

0 commit comments

Comments
 (0)