-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inference replaces bounded type parameter with sole implementer (was: action-at-a-distance regression) #18187
Comments
Perhaps related to this other action-at-a-distance problem that I recently reported: |
@pfalabella encountered a similar issue on IRC, with the code: use std::num::{One, one};
#[cfg(not(test))]
fn main() {
let _: Hamming<int> = Hamming::new(0);
}
/// representation of a Hamming number, allows to abstract on how the hamming number is stored
pub trait HammingNumber: Eq + Ord + Mul<Self, Self> + One {
fn multipliers() -> Self;
}
#[cfg(compiles)]
impl HammingNumber for i64 {
// returns the multipliers 2, 3 and 5 in the representation for the HammingNumber
fn multipliers() -> i64 {
0
}
}
impl HammingNumber for int {
// returns the multipliers 2, 3 and 5 in the representation for the HammingNumber
fn multipliers() -> int {
0
}
}
pub struct Hamming<T> {
// Using a RingBuf as a queue, push to the back, pop from the front
q2: Vec<T>,
}
impl <T: HammingNumber> Hamming<T> {
/// Static constructor method
/// `n` initializes the capacity of the queues
pub fn new(n: uint) -> Hamming<T> {
let mut h =
Hamming{q2: Vec::with_capacity(n),};
h.q2.push(one());
h
}
/// Pushes the next multiple of `n` (x2, x3, x5) to the queues
pub fn enqueue(&mut self, n: &T) {
let two : T = HammingNumber::multipliers();
self.q2.push(*n * two);
}
} Which gives the error
But compiles with |
I added a similar The issue seems that when a trait |
See #18209 for a much reduced test case |
Fix: Handle block exprs as modules when finding their parents Fixes rust-lang#18187
The following code does not compile:
With an error in scan:
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.The text was updated successfully, but these errors were encountered: