Closed
Description
The following code does not compile:
pub trait ScanCursor {
fn pop_ws(&self) -> Self;
}
pub struct Cursor;
impl ScanCursor for Cursor {
fn pop_ws(&self) -> Cursor { unreachable!() }
}
pub trait Scanner {
fn scan<Cur: ScanCursor>(cursor: &Cur) -> Self;
}
fn main() {
let cur : Cursor = Cursor;
//
let _tmp = &cur.pop_ws(); // removing this still fails
// let _ : Stmt = Scanner::scan(_tmp)
let _ : Stmt = Scanner::scan(&cur.pop_ws());
}
struct Stmt;
// Moving this above main compiles
impl Scanner for Stmt {
fn scan<Cur: ScanCursor>(cur: &Cur) -> Stmt {
// Fails to compile
let _s: Stmt = Scanner::scan(&cur.pop_ws());
loop{}
}
}
// Added 2014-10-21
#[cfg(compiles)]
impl ScanCursor for ((),(()),((),(()))) /* or whatever */ {
fn pop_ws(&self) -> ((),(()),((),(()))) { unreachable!() }
}
With an error in scan:
<anon>:29:38: 29:51 error: mismatched types: expected `&Cursor`, found `&Cur` (expected struct Cursor, found type parameter)
<anon>:29 let _s: Stmt = Scanner::scan(&cur.pop_ws());
^~~~~~~~~~~~~
error: aborting due to previous error
However, doing any of the 2 fixes suggested in the comments fixes this, which is strange, as the fixes don't touch the affected function.
The issue started at commit 590a61f788e058d7ae95806f55258bce3ae45567
(2014-10-13), which fixed issue #18019. The code compiles on older version of rustc.
Metadata
Metadata
Assignees
Labels
No labels