mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
fix HirDisplay inserting anonymous lifetimes and update tests
This commit is contained in:
parent
0669ae7faf
commit
490391f576
10 changed files with 25 additions and 28 deletions
|
@ -1316,8 +1316,7 @@ fn hir_fmt_generics(
|
|||
generic_def: Option<hir_def::GenericDefId>,
|
||||
) -> Result<(), HirDisplayError> {
|
||||
let db = f.db;
|
||||
let lifetime_args_count = generic_def.map_or(0, |g| db.generic_params(g).lifetimes.len());
|
||||
if parameters.len(Interner) + lifetime_args_count > 0 {
|
||||
if parameters.len(Interner) > 0 {
|
||||
let parameters_to_write = if f.display_target.is_source_code() || f.omit_verbose_types() {
|
||||
match generic_def
|
||||
.map(|generic_def_id| db.generic_defaults(generic_def_id))
|
||||
|
@ -1343,6 +1342,11 @@ fn hir_fmt_generics(
|
|||
return true;
|
||||
}
|
||||
}
|
||||
if parameter.lifetime(Interner).map(|it| it.data(Interner))
|
||||
== Some(&crate::LifetimeData::Static)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
let default_parameter = match default_parameters.get(i) {
|
||||
Some(it) => it,
|
||||
None => return true,
|
||||
|
@ -1363,16 +1367,9 @@ fn hir_fmt_generics(
|
|||
} else {
|
||||
parameters.as_slice(Interner)
|
||||
};
|
||||
if !parameters_to_write.is_empty() || lifetime_args_count != 0 {
|
||||
if !parameters_to_write.is_empty() {
|
||||
write!(f, "<")?;
|
||||
let mut first = true;
|
||||
for _ in 0..lifetime_args_count {
|
||||
if !first {
|
||||
write!(f, ", ")?;
|
||||
}
|
||||
first = false;
|
||||
write!(f, "'_")?;
|
||||
}
|
||||
for generic_arg in parameters_to_write {
|
||||
if !first {
|
||||
write!(f, ", ")?;
|
||||
|
|
|
@ -915,10 +915,10 @@ impl<'a> TyLoweringContext<'a> {
|
|||
|_, lifetime_ref| self.lower_lifetime(lifetime_ref),
|
||||
) {
|
||||
had_explicit_args = true;
|
||||
substs.push(dbg!(x));
|
||||
substs.push(x);
|
||||
} else {
|
||||
// Never return a None explictly
|
||||
never!("Unexpectd None by generic_arg_to_chalk");
|
||||
// Never return a None explicitly
|
||||
never!("Unexpected None by generic_arg_to_chalk");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ fn render_dyn_for_ty() {
|
|||
trait Foo<'a> {}
|
||||
|
||||
fn foo(foo: &dyn for<'a> Foo<'a>) {}
|
||||
// ^^^ &dyn Foo
|
||||
// ^^^ &dyn Foo<'static>
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1109,7 +1109,7 @@ fn var_args() {
|
|||
#[lang = "va_list"]
|
||||
pub struct VaListImpl<'f>;
|
||||
fn my_fn(foo: ...) {}
|
||||
//^^^ VaListImpl<'_>
|
||||
//^^^ VaListImpl<'static>
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -896,13 +896,13 @@ fn flush(&self) {
|
|||
"#,
|
||||
expect![[r#"
|
||||
123..127 'self': &Mutex<T>
|
||||
150..152 '{}': MutexGuard<'_, T>
|
||||
150..152 '{}': MutexGuard<T, 'static>
|
||||
234..238 'self': &{unknown}
|
||||
240..290 '{ ...()); }': ()
|
||||
250..251 'w': &Mutex<BufWriter>
|
||||
276..287 '*(w.lock())': BufWriter
|
||||
278..279 'w': &Mutex<BufWriter>
|
||||
278..286 'w.lock()': MutexGuard<'_, BufWriter>
|
||||
278..286 'w.lock()': MutexGuard<BufWriter, 'static>
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
|
|
@ -3092,7 +3092,7 @@ fn main() {
|
|||
389..394 'boxed': Box<Foo<i32>>
|
||||
389..406 'boxed....nner()': &i32
|
||||
416..421 'good1': &i32
|
||||
424..438 'Foo::get_inner': fn get_inner<i32>(&Box<Foo<i32>>) -> &i32
|
||||
424..438 'Foo::get_inner': fn get_inner<i32, 'static>(&Box<Foo<i32>>) -> &i32
|
||||
424..446 'Foo::g...boxed)': &i32
|
||||
439..445 '&boxed': &Box<Foo<i32>>
|
||||
440..445 'boxed': Box<Foo<i32>>
|
||||
|
@ -3100,7 +3100,7 @@ fn main() {
|
|||
464..469 'boxed': Box<Foo<i32>>
|
||||
464..480 'boxed....self()': &Foo<i32>
|
||||
490..495 'good2': &Foo<i32>
|
||||
498..511 'Foo::get_self': fn get_self<i32>(&Box<Foo<i32>>) -> &Foo<i32>
|
||||
498..511 'Foo::get_self': fn get_self<i32, 'static>(&Box<Foo<i32>>) -> &Foo<i32>
|
||||
498..519 'Foo::g...boxed)': &Foo<i32>
|
||||
512..518 '&boxed': &Box<Foo<i32>>
|
||||
513..518 'boxed': Box<Foo<i32>>
|
||||
|
@ -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<'_>
|
||||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type: Arguments<'static>
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
|
|
@ -5617,7 +5617,7 @@ fn func<T: Debug>(i: Struct<'_, T>) {
|
|||
fun_name(i);
|
||||
}
|
||||
|
||||
fn $0fun_name(i: Struct<'_, T>) {
|
||||
fn $0fun_name(i: Struct<T, 'static>) {
|
||||
foo(i);
|
||||
}
|
||||
"#,
|
||||
|
|
|
@ -614,7 +614,7 @@ struct Foo<'a, T> {
|
|||
}
|
||||
|
||||
impl<'a, T> Foo<'a, T> {
|
||||
$0fn bar(self, mut b: Vec<&'a Bar<'_, T>>) -> &'a Bar<'_, T> {
|
||||
$0fn bar(self, mut b: Vec<&'a Bar<T, 'a>>) -> &'a Bar<T, 'a> {
|
||||
self.field.bar(b)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<'_, {unknown}, _>
|
||||
st Foo<…> Foo<{unknown}, _, 'static>
|
||||
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<'_, {unknown}, _>
|
||||
st Foo<…> Foo<{unknown}, _, 'static>
|
||||
st Record Record
|
||||
st Tuple Tuple
|
||||
st Unit Unit
|
||||
|
|
|
@ -20,8 +20,8 @@ struct Foo<'lt, T, const C: usize> {
|
|||
en Enum Enum
|
||||
ma makro!(…) macro_rules! makro
|
||||
md module
|
||||
sp Self Foo<'_, {unknown}, _>
|
||||
st Foo<…> Foo<'_, {unknown}, _>
|
||||
sp Self Foo<{unknown}, _, 'static>
|
||||
st Foo<…> Foo<{unknown}, _, 'static>
|
||||
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<'_, {unknown}, _>
|
||||
st Foo<…> Foo<'_, {unknown}, _>
|
||||
sp Self Foo<{unknown}, _, 'static>
|
||||
st Foo<…> Foo<{unknown}, _, 'static>
|
||||
st Record Record
|
||||
st Tuple Tuple
|
||||
st Unit Unit
|
||||
|
|
Loading…
Reference in a new issue