Skip to content

Commit cbd0d89

Browse files
committed
Add test for issue rust-lang#70304
1 parent 1ef760d commit cbd0d89

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#![allow(incomplete_features)]
2+
#![feature(generic_associated_types)]
3+
4+
trait Document {
5+
type Cursor<'a>: DocCursor<'a>;
6+
7+
fn cursor(&self) -> Self::Cursor<'_>;
8+
}
9+
10+
struct DocumentImpl {}
11+
12+
impl Document for DocumentImpl {
13+
type Cursor<'a> = DocCursorImpl<'a>;
14+
15+
fn cursor(&self) -> Self::Cursor<'_> {
16+
DocCursorImpl {
17+
document: &self,
18+
}
19+
}
20+
}
21+
22+
23+
trait DocCursor<'a> {}
24+
25+
struct DocCursorImpl<'a> {
26+
document: &'a DocumentImpl,
27+
}
28+
29+
impl<'a> DocCursor<'a> for DocCursorImpl<'a> {}
30+
31+
struct Lexer<'d, Cursor>
32+
where
33+
Cursor: DocCursor<'d>,
34+
{
35+
cursor: Cursor,
36+
_phantom: std::marker::PhantomData<&'d ()>,
37+
}
38+
39+
40+
impl<'d, Cursor> Lexer<'d, Cursor>
41+
where
42+
Cursor: DocCursor<'d>,
43+
{
44+
pub fn from<Doc>(document: &'d Doc) -> Lexer<'d, Cursor>
45+
where
46+
Doc: Document<Cursor<'d> = Cursor>,
47+
{
48+
Lexer {
49+
cursor: document.cursor(),
50+
_phantom: std::marker::PhantomData,
51+
}
52+
}
53+
}
54+
55+
fn create_doc() -> impl Document<Cursor<'_> = DocCursorImpl<'_>> {
56+
//~^ ERROR: missing lifetime specifier
57+
DocumentImpl {}
58+
}
59+
60+
pub fn main() {
61+
let doc = create_doc();
62+
let lexer: Lexer<'_, DocCursorImpl<'_>> = Lexer::from(&doc);
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0106]: missing lifetime specifier
2+
--> $DIR/issue-70304.rs:55:41
3+
|
4+
LL | fn create_doc() -> impl Document<Cursor<'_> = DocCursorImpl<'_>> {
5+
| ^^ expected named lifetime parameter
6+
|
7+
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
8+
help: consider using the `'static` lifetime
9+
|
10+
LL | fn create_doc() -> impl Document<Cursor<'static> = DocCursorImpl<'_>> {
11+
| ^^^^^^^
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0106`.

0 commit comments

Comments
 (0)