Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 490391f

Browse files
committed
fix HirDisplay inserting anonymous lifetimes and update tests
1 parent 0669ae7 commit 490391f

File tree

10 files changed

+25
-28
lines changed

10 files changed

+25
-28
lines changed

crates/hir-ty/src/display.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,8 +1316,7 @@ fn hir_fmt_generics(
13161316
generic_def: Option<hir_def::GenericDefId>,
13171317
) -> Result<(), HirDisplayError> {
13181318
let db = f.db;
1319-
let lifetime_args_count = generic_def.map_or(0, |g| db.generic_params(g).lifetimes.len());
1320-
if parameters.len(Interner) + lifetime_args_count > 0 {
1319+
if parameters.len(Interner) > 0 {
13211320
let parameters_to_write = if f.display_target.is_source_code() || f.omit_verbose_types() {
13221321
match generic_def
13231322
.map(|generic_def_id| db.generic_defaults(generic_def_id))
@@ -1343,6 +1342,11 @@ fn hir_fmt_generics(
13431342
return true;
13441343
}
13451344
}
1345+
if parameter.lifetime(Interner).map(|it| it.data(Interner))
1346+
== Some(&crate::LifetimeData::Static)
1347+
{
1348+
return true;
1349+
}
13461350
let default_parameter = match default_parameters.get(i) {
13471351
Some(it) => it,
13481352
None => return true,
@@ -1363,16 +1367,9 @@ fn hir_fmt_generics(
13631367
} else {
13641368
parameters.as_slice(Interner)
13651369
};
1366-
if !parameters_to_write.is_empty() || lifetime_args_count != 0 {
1370+
if !parameters_to_write.is_empty() {
13671371
write!(f, "<")?;
13681372
let mut first = true;
1369-
for _ in 0..lifetime_args_count {
1370-
if !first {
1371-
write!(f, ", ")?;
1372-
}
1373-
first = false;
1374-
write!(f, "'_")?;
1375-
}
13761373
for generic_arg in parameters_to_write {
13771374
if !first {
13781375
write!(f, ", ")?;

crates/hir-ty/src/lower.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -915,10 +915,10 @@ impl<'a> TyLoweringContext<'a> {
915915
|_, lifetime_ref| self.lower_lifetime(lifetime_ref),
916916
) {
917917
had_explicit_args = true;
918-
substs.push(dbg!(x));
918+
substs.push(x);
919919
} else {
920-
// Never return a None explictly
921-
never!("Unexpectd None by generic_arg_to_chalk");
920+
// Never return a None explicitly
921+
never!("Unexpected None by generic_arg_to_chalk");
922922
}
923923
}
924924
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn render_dyn_for_ty() {
8585
trait Foo<'a> {}
8686
8787
fn foo(foo: &dyn for<'a> Foo<'a>) {}
88-
// ^^^ &dyn Foo
88+
// ^^^ &dyn Foo<'static>
8989
"#,
9090
);
9191
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ fn var_args() {
11091109
#[lang = "va_list"]
11101110
pub struct VaListImpl<'f>;
11111111
fn my_fn(foo: ...) {}
1112-
//^^^ VaListImpl<'_>
1112+
//^^^ VaListImpl<'static>
11131113
"#,
11141114
);
11151115
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,13 +896,13 @@ fn flush(&self) {
896896
"#,
897897
expect![[r#"
898898
123..127 'self': &Mutex<T>
899-
150..152 '{}': MutexGuard<'_, T>
899+
150..152 '{}': MutexGuard<T, 'static>
900900
234..238 'self': &{unknown}
901901
240..290 '{ ...()); }': ()
902902
250..251 'w': &Mutex<BufWriter>
903903
276..287 '*(w.lock())': BufWriter
904904
278..279 'w': &Mutex<BufWriter>
905-
278..286 'w.lock()': MutexGuard<'_, BufWriter>
905+
278..286 'w.lock()': MutexGuard<BufWriter, 'static>
906906
"#]],
907907
);
908908
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3092,15 +3092,15 @@ fn main() {
30923092
389..394 'boxed': Box<Foo<i32>>
30933093
389..406 'boxed....nner()': &i32
30943094
416..421 'good1': &i32
3095-
424..438 'Foo::get_inner': fn get_inner<i32>(&Box<Foo<i32>>) -> &i32
3095+
424..438 'Foo::get_inner': fn get_inner<i32, 'static>(&Box<Foo<i32>>) -> &i32
30963096
424..446 'Foo::g...boxed)': &i32
30973097
439..445 '&boxed': &Box<Foo<i32>>
30983098
440..445 'boxed': Box<Foo<i32>>
30993099
457..461 'bad2': &Foo<i32>
31003100
464..469 'boxed': Box<Foo<i32>>
31013101
464..480 'boxed....self()': &Foo<i32>
31023102
490..495 'good2': &Foo<i32>
3103-
498..511 'Foo::get_self': fn get_self<i32>(&Box<Foo<i32>>) -> &Foo<i32>
3103+
498..511 'Foo::get_self': fn get_self<i32, 'static>(&Box<Foo<i32>>) -> &Foo<i32>
31043104
498..519 'Foo::g...boxed)': &Foo<i32>
31053105
512..518 '&boxed': &Box<Foo<i32>>
31063106
513..518 'boxed': Box<Foo<i32>>
@@ -3659,7 +3659,7 @@ fn main() {
36593659
let are = "are";
36603660
let count = 10;
36613661
builtin#format_args("hello {count:02} {} friends, we {are:?} {0}{last}", "fancy", last = "!");
3662-
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type: Arguments<'_>
3662+
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type: Arguments<'static>
36633663
}
36643664
"#,
36653665
);

crates/ide-assists/src/handlers/extract_function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5617,7 +5617,7 @@ fn func<T: Debug>(i: Struct<'_, T>) {
56175617
fun_name(i);
56185618
}
56195619
5620-
fn $0fun_name(i: Struct<'_, T>) {
5620+
fn $0fun_name(i: Struct<T, 'static>) {
56215621
foo(i);
56225622
}
56235623
"#,

crates/ide-assists/src/handlers/generate_delegate_methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ struct Foo<'a, T> {
614614
}
615615
616616
impl<'a, T> Foo<'a, T> {
617-
$0fn bar(self, mut b: Vec<&'a Bar<'_, T>>) -> &'a Bar<'_, T> {
617+
$0fn bar(self, mut b: Vec<&'a Bar<T, 'a>>) -> &'a Bar<T, 'a> {
618618
self.field.bar(b)
619619
}
620620
}

crates/ide-completion/src/tests/predicate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct Foo<'lt, T, const C: usize> where $0 {}
1919
en Enum Enum
2020
ma makro!(…) macro_rules! makro
2121
md module
22-
st Foo<…> Foo<'_, {unknown}, _>
22+
st Foo<…> Foo<{unknown}, _, 'static>
2323
st Record Record
2424
st Tuple Tuple
2525
st Unit Unit
@@ -92,7 +92,7 @@ struct Foo<'lt, T, const C: usize> where for<'a> $0 {}
9292
en Enum Enum
9393
ma makro!(…) macro_rules! makro
9494
md module
95-
st Foo<…> Foo<'_, {unknown}, _>
95+
st Foo<…> Foo<{unknown}, _, 'static>
9696
st Record Record
9797
st Tuple Tuple
9898
st Unit Unit

crates/ide-completion/src/tests/type_pos.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ struct Foo<'lt, T, const C: usize> {
2020
en Enum Enum
2121
ma makro!(…) macro_rules! makro
2222
md module
23-
sp Self Foo<'_, {unknown}, _>
24-
st Foo<…> Foo<'_, {unknown}, _>
23+
sp Self Foo<{unknown}, _, 'static>
24+
st Foo<…> Foo<{unknown}, _, 'static>
2525
st Record Record
2626
st Tuple Tuple
2727
st Unit Unit
@@ -45,8 +45,8 @@ struct Foo<'lt, T, const C: usize>(f$0);
4545
en Enum Enum
4646
ma makro!(…) macro_rules! makro
4747
md module
48-
sp Self Foo<'_, {unknown}, _>
49-
st Foo<…> Foo<'_, {unknown}, _>
48+
sp Self Foo<{unknown}, _, 'static>
49+
st Foo<…> Foo<{unknown}, _, 'static>
5050
st Record Record
5151
st Tuple Tuple
5252
st Unit Unit

0 commit comments

Comments
 (0)