Skip to content

Commit 7b094ba

Browse files
author
Lukas Markeffsky
committed
add another test
1 parent e5c98fd commit 7b094ba

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

tests/ui/cast/ptr-to-trait-obj-different-regions-misc.rs

+5
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,10 @@ fn change_assoc_1<'a, 'b>(
3333
//~| error: lifetime may not live long enough
3434
}
3535

36+
// This tests the default borrow check error, without the special casing for return values.
37+
fn require_static(_: *const dyn Trait<'static>) {}
38+
fn extend_to_static<'a>(ptr: *const dyn Trait<'a>) {
39+
require_static(ptr as _) //~ error: lifetime may not live long enough
40+
}
3641

3742
fn main() {}

tests/ui/cast/ptr-to-trait-obj-different-regions-misc.stderr

+9-1
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,13 @@ help: `'b` and `'a` must be the same: replace one with the other
132132
|
133133
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
134134

135-
error: aborting due to 8 previous errors
135+
error: lifetime may not live long enough
136+
--> $DIR/ptr-to-trait-obj-different-regions-misc.rs:39:20
137+
|
138+
LL | fn extend_to_static<'a>(ptr: *const dyn Trait<'a>) {
139+
| -- lifetime `'a` defined here
140+
LL | require_static(ptr as _)
141+
| ^^^ cast requires that `'a` must outlive `'static`
142+
143+
error: aborting due to 9 previous errors
136144

0 commit comments

Comments
 (0)