-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Closed
Description
Hey folks,
I had a contributor track down a bug that slipped through in one of my crates. It took them a few hours, and turned out to be caused by an ambiguity in next method calls. Here's the example of the bug that they gave:
pub trait Window {}
pub struct PistonWindow {}
impl Window for PistonWindow {}
struct WindowEvents {}
impl WindowEvents {
fn next<W: Window>(self, arg: &W) {
println!("WindowEvents::next");
}
}
trait EventWindow {
fn next(self, arg: &PistonWindow);
}
impl EventWindow for WindowEvents {
fn next(self, arg: &PistonWindow) {
println!("EventWindow::next");
}
}
fn main() {
let struct1 = PistonWindow {};
let struct2 = WindowEvents {};
struct2.next(&struct1);
}Here, I would normally assume rustc to throw an error about an ambiguity between the next method call, something like:
multiple possible sources of next method:
1. inherent method `WindowEvents::next`
2. trait method `EventWindow::next`
Instead, the program compiles and the WindowEvents inherent method is called.
Perhaps this is expected behaviour and I'm missing something, but just thought I'd report in case.
Metadata
Metadata
Assignees
Labels
No labels