Skip to content

Commit b50d527

Browse files
authored
Merge pull request #20036 from Veykril/push-yquvoyrxkksx
Do not default to 'static for trait object lifetimes
2 parents 95dce2b + 2b05bd7 commit b50d527

File tree

12 files changed

+70
-70
lines changed

12 files changed

+70
-70
lines changed

crates/hir-ty/src/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ impl<'a> TyLoweringContext<'a> {
711711
.unwrap_or(it),
712712
None => it,
713713
},
714-
None => static_lifetime(),
714+
None => error_lifetime(),
715715
},
716716
})
717717
.intern(Interner)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ trait Foo {}
561561
fn test(f: impl Foo, g: &(impl Foo + ?Sized)) {
562562
let _: &dyn Foo = &f;
563563
let _: &dyn Foo = g;
564-
//^ expected &'? (dyn Foo + 'static), got &'? impl Foo + ?Sized
564+
//^ expected &'? (dyn Foo + '?), got &'? impl Foo + ?Sized
565565
}
566566
"#,
567567
);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ trait B: A {}
6767
6868
fn test<'a>(
6969
_: &(dyn A<Assoc = ()> + Send),
70-
//^ &(dyn A<Assoc = ()> + Send + 'static)
70+
//^ &(dyn A<Assoc = ()> + Send)
7171
_: &'a (dyn Send + A<Assoc = ()>),
72-
//^ &'a (dyn A<Assoc = ()> + Send + 'static)
72+
//^ &'a (dyn A<Assoc = ()> + Send)
7373
_: &dyn B<Assoc = ()>,
74-
//^ &(dyn B<Assoc = ()> + 'static)
74+
//^ &(dyn B<Assoc = ()>)
7575
) {}
7676
"#,
7777
);
@@ -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<'?> + 'static)
88+
// ^^^ &dyn Foo<'?>
8989
"#,
9090
);
9191
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,9 +1153,9 @@ fn dyn_trait_super_trait_not_in_scope() {
11531153
51..55 'self': &'? Self
11541154
64..69 '{ 0 }': u32
11551155
66..67 '0': u32
1156-
176..177 'd': &'? (dyn Trait + 'static)
1156+
176..177 'd': &'? (dyn Trait + '?)
11571157
191..207 '{ ...o(); }': ()
1158-
197..198 'd': &'? (dyn Trait + 'static)
1158+
197..198 'd': &'? (dyn Trait + '?)
11591159
197..204 'd.foo()': u32
11601160
"#]],
11611161
);
@@ -2019,10 +2019,10 @@ impl dyn Error + Send {
20192019
/// Attempts to downcast the box to a concrete type.
20202020
pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<dyn Error + Send>> {
20212021
let err: Box<dyn Error> = self;
2022-
// ^^^^ expected Box<dyn Error + 'static>, got Box<dyn Error + Send + 'static>
2022+
// ^^^^ expected Box<dyn Error + '?>, got Box<dyn Error + Send + '?>
20232023
// FIXME, type mismatch should not occur
20242024
<dyn Error>::downcast(err).map_err(|_| loop {})
2025-
//^^^^^^^^^^^^^^^^^^^^^ type: fn downcast<{unknown}>(Box<dyn Error + 'static>) -> Result<Box<{unknown}>, Box<dyn Error + 'static>>
2025+
//^^^^^^^^^^^^^^^^^^^^^ type: fn downcast<{unknown}>(Box<dyn Error + '?>) -> Result<Box<{unknown}>, Box<dyn Error + '?>>
20262026
}
20272027
}
20282028
"#,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ fn issue_4053_diesel_where_clauses() {
629629
488..522 '{ ... }': ()
630630
498..502 'self': SelectStatement<F, S, D, W, O, LOf, {unknown}, {unknown}>
631631
498..508 'self.order': O
632-
498..515 'self.o...into()': dyn QueryFragment<DB> + 'static
632+
498..515 'self.o...into()': dyn QueryFragment<DB> + '?
633633
"#]],
634634
);
635635
}
@@ -773,7 +773,7 @@ fn issue_4800() {
773773
"#,
774774
expect![[r#"
775775
379..383 'self': &'? mut PeerSet<D>
776-
401..424 '{ ... }': dyn Future<Output = ()> + 'static
776+
401..424 '{ ... }': dyn Future<Output = ()> + '?
777777
411..418 'loop {}': !
778778
416..418 '{}': ()
779779
575..579 'self': &'? mut Self

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2741,11 +2741,11 @@ impl B for Astruct {}
27412741
715..744 '#[rust...1i32])': Box<[i32; 1], Global>
27422742
737..743 '[1i32]': [i32; 1]
27432743
738..742 '1i32': i32
2744-
755..756 'v': Vec<Box<dyn B + 'static, Global>, Global>
2745-
776..793 '<[_]> ...to_vec': fn into_vec<Box<dyn B + 'static, Global>, Global>(Box<[Box<dyn B + 'static, Global>], Global>) -> Vec<Box<dyn B + 'static, Global>, Global>
2746-
776..850 '<[_]> ...ct)]))': Vec<Box<dyn B + 'static, Global>, Global>
2747-
794..849 '#[rust...uct)])': Box<[Box<dyn B + 'static, Global>; 1], Global>
2748-
816..848 '[#[rus...ruct)]': [Box<dyn B + 'static, Global>; 1]
2744+
755..756 'v': Vec<Box<dyn B + '?, Global>, Global>
2745+
776..793 '<[_]> ...to_vec': fn into_vec<Box<dyn B + '?, Global>, Global>(Box<[Box<dyn B + '?, Global>], Global>) -> Vec<Box<dyn B + '?, Global>, Global>
2746+
776..850 '<[_]> ...ct)]))': Vec<Box<dyn B + '?, Global>, Global>
2747+
794..849 '#[rust...uct)])': Box<[Box<dyn B + '?, Global>; 1], Global>
2748+
816..848 '[#[rus...ruct)]': [Box<dyn B + '?, Global>; 1]
27492749
817..847 '#[rust...truct)': Box<Astruct, Global>
27502750
839..846 'Astruct': Astruct
27512751
"#]],

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

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,26 +1475,26 @@ fn test(x: Box<dyn Trait<u64>>, y: &dyn Trait<u64>) {
14751475
expect![[r#"
14761476
29..33 'self': &'? Self
14771477
54..58 'self': &'? Self
1478-
198..200 '{}': Box<dyn Trait<u64> + 'static>
1479-
210..211 'x': Box<dyn Trait<u64> + 'static>
1480-
234..235 'y': &'? (dyn Trait<u64> + 'static)
1478+
198..200 '{}': Box<dyn Trait<u64> + '?>
1479+
210..211 'x': Box<dyn Trait<u64> + '?>
1480+
234..235 'y': &'? (dyn Trait<u64> + '?)
14811481
254..371 '{ ...2(); }': ()
1482-
260..261 'x': Box<dyn Trait<u64> + 'static>
1483-
267..268 'y': &'? (dyn Trait<u64> + 'static)
1484-
278..279 'z': Box<dyn Trait<u64> + 'static>
1485-
282..285 'bar': fn bar() -> Box<dyn Trait<u64> + 'static>
1486-
282..287 'bar()': Box<dyn Trait<u64> + 'static>
1487-
293..294 'x': Box<dyn Trait<u64> + 'static>
1482+
260..261 'x': Box<dyn Trait<u64> + '?>
1483+
267..268 'y': &'? (dyn Trait<u64> + '?)
1484+
278..279 'z': Box<dyn Trait<u64> + '?>
1485+
282..285 'bar': fn bar() -> Box<dyn Trait<u64> + '?>
1486+
282..287 'bar()': Box<dyn Trait<u64> + '?>
1487+
293..294 'x': Box<dyn Trait<u64> + '?>
14881488
293..300 'x.foo()': u64
1489-
306..307 'y': &'? (dyn Trait<u64> + 'static)
1489+
306..307 'y': &'? (dyn Trait<u64> + '?)
14901490
306..313 'y.foo()': u64
1491-
319..320 'z': Box<dyn Trait<u64> + 'static>
1491+
319..320 'z': Box<dyn Trait<u64> + '?>
14921492
319..326 'z.foo()': u64
1493-
332..333 'x': Box<dyn Trait<u64> + 'static>
1493+
332..333 'x': Box<dyn Trait<u64> + '?>
14941494
332..340 'x.foo2()': i64
1495-
346..347 'y': &'? (dyn Trait<u64> + 'static)
1495+
346..347 'y': &'? (dyn Trait<u64> + '?)
14961496
346..354 'y.foo2()': i64
1497-
360..361 'z': Box<dyn Trait<u64> + 'static>
1497+
360..361 'z': Box<dyn Trait<u64> + '?>
14981498
360..368 'z.foo2()': i64
14991499
"#]],
15001500
);
@@ -1523,14 +1523,14 @@ fn test(s: S<u32, i32>) {
15231523
expect![[r#"
15241524
32..36 'self': &'? Self
15251525
102..106 'self': &'? S<T, U>
1526-
128..139 '{ loop {} }': &'? (dyn Trait<T, U> + 'static)
1526+
128..139 '{ loop {} }': &'? (dyn Trait<T, U> + '?)
15271527
130..137 'loop {}': !
15281528
135..137 '{}': ()
15291529
175..179 'self': &'? Self
15301530
251..252 's': S<u32, i32>
15311531
267..289 '{ ...z(); }': ()
15321532
273..274 's': S<u32, i32>
1533-
273..280 's.bar()': &'? (dyn Trait<u32, i32> + 'static)
1533+
273..280 's.bar()': &'? (dyn Trait<u32, i32> + '?)
15341534
273..286 's.bar().baz()': (u32, i32)
15351535
"#]],
15361536
);
@@ -1556,20 +1556,20 @@ fn test(x: Trait, y: &Trait) -> u64 {
15561556
}"#,
15571557
expect![[r#"
15581558
26..30 'self': &'? Self
1559-
60..62 '{}': dyn Trait + 'static
1560-
72..73 'x': dyn Trait + 'static
1561-
82..83 'y': &'? (dyn Trait + 'static)
1559+
60..62 '{}': dyn Trait + '?
1560+
72..73 'x': dyn Trait + '?
1561+
82..83 'y': &'? (dyn Trait + '?)
15621562
100..175 '{ ...o(); }': u64
1563-
106..107 'x': dyn Trait + 'static
1564-
113..114 'y': &'? (dyn Trait + 'static)
1565-
124..125 'z': dyn Trait + 'static
1566-
128..131 'bar': fn bar() -> dyn Trait + 'static
1567-
128..133 'bar()': dyn Trait + 'static
1568-
139..140 'x': dyn Trait + 'static
1563+
106..107 'x': dyn Trait + '?
1564+
113..114 'y': &'? (dyn Trait + '?)
1565+
124..125 'z': dyn Trait + '?
1566+
128..131 'bar': fn bar() -> dyn Trait + '?
1567+
128..133 'bar()': dyn Trait + '?
1568+
139..140 'x': dyn Trait + '?
15691569
139..146 'x.foo()': u64
1570-
152..153 'y': &'? (dyn Trait + 'static)
1570+
152..153 'y': &'? (dyn Trait + '?)
15711571
152..159 'y.foo()': u64
1572-
165..166 'z': dyn Trait + 'static
1572+
165..166 'z': dyn Trait + '?
15731573
165..172 'z.foo()': u64
15741574
"#]],
15751575
);
@@ -1589,10 +1589,10 @@ fn main() {
15891589
expect![[r#"
15901590
31..35 'self': &'? S
15911591
37..39 '{}': ()
1592-
47..48 '_': &'? (dyn Fn(S) + 'static)
1592+
47..48 '_': &'? (dyn Fn(S) + '?)
15931593
58..60 '{}': ()
15941594
71..105 '{ ...()); }': ()
1595-
77..78 'f': fn f(&'? (dyn Fn(S) + 'static))
1595+
77..78 'f': fn f(&'? (dyn Fn(S) + '?))
15961596
77..102 'f(&|nu...foo())': ()
15971597
79..101 '&|numb....foo()': &'? impl Fn(S)
15981598
80..101 '|numbe....foo()': impl Fn(S)
@@ -2927,13 +2927,13 @@ fn test(x: &dyn Foo) {
29272927
foo(x);
29282928
}"#,
29292929
expect![[r#"
2930-
21..22 'x': &'? (dyn Foo + 'static)
2930+
21..22 'x': &'? (dyn Foo + '?)
29312931
34..36 '{}': ()
2932-
46..47 'x': &'? (dyn Foo + 'static)
2932+
46..47 'x': &'? (dyn Foo + '?)
29332933
59..74 '{ foo(x); }': ()
2934-
65..68 'foo': fn foo(&'? (dyn Foo + 'static))
2934+
65..68 'foo': fn foo(&'? (dyn Foo + '?))
29352935
65..71 'foo(x)': ()
2936-
69..70 'x': &'? (dyn Foo + 'static)
2936+
69..70 'x': &'? (dyn Foo + '?)
29372937
"#]],
29382938
);
29392939
}
@@ -3210,13 +3210,13 @@ fn foo() {
32103210
218..324 '{ ...&s); }': ()
32113211
228..229 's': Option<i32>
32123212
232..236 'None': Option<i32>
3213-
246..247 'f': Box<dyn FnOnce(&'? Option<i32>) + 'static>
3214-
281..310 'Box { ... {}) }': Box<dyn FnOnce(&'? Option<i32>) + 'static>
3213+
246..247 'f': Box<dyn FnOnce(&'? Option<i32>) + '?>
3214+
281..310 'Box { ... {}) }': Box<dyn FnOnce(&'? Option<i32>) + '?>
32153215
294..308 '&mut (|ps| {})': &'? mut impl FnOnce(&'? Option<i32>)
32163216
300..307 '|ps| {}': impl FnOnce(&'? Option<i32>)
32173217
301..303 'ps': &'? Option<i32>
32183218
305..307 '{}': ()
3219-
316..317 'f': Box<dyn FnOnce(&'? Option<i32>) + 'static>
3219+
316..317 'f': Box<dyn FnOnce(&'? Option<i32>) + '?>
32203220
316..321 'f(&s)': ()
32213221
318..320 '&s': &'? Option<i32>
32223222
319..320 's': Option<i32>
@@ -4252,9 +4252,9 @@ fn f<'a>(v: &dyn Trait<Assoc<i32> = &'a i32>) {
42524252
"#,
42534253
expect![[r#"
42544254
90..94 'self': &'? Self
4255-
127..128 'v': &'? (dyn Trait<Assoc<i32> = &'a i32> + 'static)
4255+
127..128 'v': &'? (dyn Trait<Assoc<i32> = &'a i32> + '?)
42564256
164..195 '{ ...f(); }': ()
4257-
170..171 'v': &'? (dyn Trait<Assoc<i32> = &'a i32> + 'static)
4257+
170..171 'v': &'? (dyn Trait<Assoc<i32> = &'a i32> + '?)
42584258
170..184 'v.get::<i32>()': &'? i32
42594259
170..192 'v.get:...eref()': &'? i32
42604260
"#]],

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -429,18 +429,18 @@ trait Tr<T> {
429429
impl Tr<$0
430430
"#,
431431
expect![[r#"
432-
en Enum Enum
433-
ma makro!(…) macro_rules! makro
432+
en Enum Enum
433+
ma makro!(…) macro_rules! makro
434434
md module
435-
sp Self dyn Tr<{unknown}> + 'static
436-
st Record Record
437-
st S S
438-
st Tuple Tuple
439-
st Unit Unit
435+
sp Self dyn Tr<{unknown}>
436+
st Record Record
437+
st S S
438+
st Tuple Tuple
439+
st Unit Unit
440440
tt Tr
441441
tt Trait
442-
un Union Union
443-
bt u32 u32
442+
un Union Union
443+
bt u32 u32
444444
kw crate::
445445
kw self::
446446
"#]],

crates/ide-diagnostics/src/handlers/type_mismatch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ trait B {}
11711171
11721172
fn test(a: &dyn A) -> &dyn B {
11731173
a
1174-
//^ error: expected &(dyn B + 'static), found &(dyn A + 'static)
1174+
//^ error: expected &dyn B, found &dyn A
11751175
}
11761176
"#,
11771177
);

crates/ide/src/inlay_hints/bind_pat.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,9 @@ fn main() {
380380
let foo = foo3();
381381
// ^^^ impl Fn(f64, f64) -> u32
382382
let foo = foo4();
383-
// ^^^ &'static (dyn Fn(f64, f64) -> u32 + 'static)
383+
// ^^^ &'static dyn Fn(f64, f64) -> u32
384384
let foo = foo5();
385-
// ^^^ &'static (dyn Fn(&(dyn Fn(f64, f64) -> u32 + 'static), f64) -> u32 + 'static)
385+
// ^^^ &'static dyn Fn(&dyn Fn(f64, f64) -> u32, f64) -> u32
386386
let foo = foo6();
387387
// ^^^ impl Fn(f64, f64) -> u32
388388
let foo = foo7();
@@ -413,7 +413,7 @@ fn main() {
413413
let foo = foo3();
414414
// ^^^ impl Fn(f64, f64) -> u32
415415
let foo = foo4();
416-
// ^^^ &'static (dyn Fn(f64, f64) -> u32 + 'static)
416+
// ^^^ &'static dyn Fn(f64, f64) -> u32
417417
let foo = foo5();
418418
let foo = foo6();
419419
let foo = foo7();

crates/ide/src/inlay_hints/closing_brace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl Tr for () {
193193
//^ impl Tr for ()
194194
impl dyn Tr {
195195
}
196-
//^ impl dyn Tr + 'static
196+
//^ impl dyn Tr
197197
198198
static S0: () = 0;
199199
static S1: () = {};

crates/project-model/src/workspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,7 @@ fn add_target_crate_root(
16301630
None => Err("proc-macro crate build data is missing dylib path".to_owned()),
16311631
}
16321632
}
1633-
None => Err("proc-macro crate is missing its build data".to_owned()),
1633+
None => Err("build scripts have not been built".to_owned()),
16341634
};
16351635
proc_macros.insert(crate_id, proc_macro);
16361636
}

0 commit comments

Comments
 (0)