mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Fix impl trait params not being counted properly
This commit is contained in:
parent
8241d8a0b8
commit
c97ac34caa
3 changed files with 33 additions and 4 deletions
|
@ -345,7 +345,9 @@ impl<'a> TyLoweringContext<'a> {
|
||||||
}
|
}
|
||||||
ImplTraitLoweringState::Param(counter) => {
|
ImplTraitLoweringState::Param(counter) => {
|
||||||
let idx = counter.get();
|
let idx = counter.get();
|
||||||
counter.set(idx + 1);
|
// Count the number of `impl Trait` things that appear within our bounds.
|
||||||
|
// Since t hose have been emitted as implicit type args already.
|
||||||
|
counter.set(idx + count_impl_traits(type_ref) as u16);
|
||||||
let kind = self
|
let kind = self
|
||||||
.generics()
|
.generics()
|
||||||
.expect("param impl trait lowering must be in a generic def")
|
.expect("param impl trait lowering must be in a generic def")
|
||||||
|
@ -367,7 +369,9 @@ impl<'a> TyLoweringContext<'a> {
|
||||||
}
|
}
|
||||||
ImplTraitLoweringState::Variable(counter) => {
|
ImplTraitLoweringState::Variable(counter) => {
|
||||||
let idx = counter.get();
|
let idx = counter.get();
|
||||||
counter.set(idx + 1);
|
// Count the number of `impl Trait` things that appear within our bounds.
|
||||||
|
// Since t hose have been emitted as implicit type args already.
|
||||||
|
counter.set(idx + count_impl_traits(type_ref) as u16);
|
||||||
let (
|
let (
|
||||||
_parent_params,
|
_parent_params,
|
||||||
self_params,
|
self_params,
|
||||||
|
@ -1397,6 +1401,17 @@ pub fn associated_type_shorthand_candidates<R>(
|
||||||
named_associated_type_shorthand_candidates(db, def, res, None, |name, _, id| cb(name, id))
|
named_associated_type_shorthand_candidates(db, def, res, None, |name, _, id| cb(name, id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: This does not handle macros!
|
||||||
|
fn count_impl_traits(type_ref: &TypeRef) -> usize {
|
||||||
|
let mut count = 0;
|
||||||
|
type_ref.walk(&mut |type_ref| {
|
||||||
|
if matches!(type_ref, TypeRef::ImplTrait(_)) {
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
count
|
||||||
|
}
|
||||||
|
|
||||||
fn named_associated_type_shorthand_candidates<R>(
|
fn named_associated_type_shorthand_candidates<R>(
|
||||||
db: &dyn HirDatabase,
|
db: &dyn HirDatabase,
|
||||||
// If the type parameter is defined in an impl and we're in a method, there
|
// If the type parameter is defined in an impl and we're in a method, there
|
||||||
|
|
|
@ -1980,7 +1980,7 @@ impl<#[cfg(feature = "a-feature")] A> Bar for (){}
|
||||||
fn nested_anon_generics_and_where_bounds_17173() {
|
fn nested_anon_generics_and_where_bounds_17173() {
|
||||||
check_types(
|
check_types(
|
||||||
r#"
|
r#"
|
||||||
//- minicore: sized
|
//- minicore: sized, fn
|
||||||
pub trait Lookup {
|
pub trait Lookup {
|
||||||
type Data;
|
type Data;
|
||||||
fn lookup(&self) -> Self::Data;
|
fn lookup(&self) -> Self::Data;
|
||||||
|
@ -1988,8 +1988,11 @@ pub trait Lookup {
|
||||||
pub trait ItemTreeLoc {
|
pub trait ItemTreeLoc {
|
||||||
type Id;
|
type Id;
|
||||||
}
|
}
|
||||||
fn id_to_generics(id: impl Lookup<Data = impl ItemTreeLoc<Id = ()>>)
|
fn id_to_generics(id: impl Lookup<Data = impl ItemTreeLoc<Id = ()>>,
|
||||||
//^^ impl Lookup<Data = impl ItemTreeLoc<Id = ()>>
|
//^^ impl Lookup<Data = impl ItemTreeLoc<Id = ()>>
|
||||||
|
enabled_params: impl Fn(),
|
||||||
|
//^^^^^^^^^^^^^^ impl Fn()
|
||||||
|
)
|
||||||
where
|
where
|
||||||
(): Sized,
|
(): Sized,
|
||||||
{}
|
{}
|
||||||
|
|
|
@ -13,6 +13,17 @@ use crate::cli::flags;
|
||||||
|
|
||||||
impl flags::Diagnostics {
|
impl flags::Diagnostics {
|
||||||
pub fn run(self) -> anyhow::Result<()> {
|
pub fn run(self) -> anyhow::Result<()> {
|
||||||
|
const STACK_SIZE: usize = 1024 * 1024 * 8;
|
||||||
|
|
||||||
|
let handle = stdx::thread::Builder::new(stdx::thread::ThreadIntent::LatencySensitive)
|
||||||
|
.name("BIG_STACK_THREAD".into())
|
||||||
|
.stack_size(STACK_SIZE)
|
||||||
|
.spawn(|| self.run_())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
handle.join()
|
||||||
|
}
|
||||||
|
fn run_(self) -> anyhow::Result<()> {
|
||||||
let cargo_config =
|
let cargo_config =
|
||||||
CargoConfig { sysroot: Some(RustLibSource::Discover), ..Default::default() };
|
CargoConfig { sysroot: Some(RustLibSource::Discover), ..Default::default() };
|
||||||
let with_proc_macro_server = if let Some(p) = &self.proc_macro_srv {
|
let with_proc_macro_server = if let Some(p) = &self.proc_macro_srv {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue