You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT// file at the top-level directory of this distribution and at// http://rust-lang.org/COPYRIGHT.//// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your// option. This file may not be copied, modified, or distributed// except according to those terms.// xfail-fastuse std::int;traitto_str{fnto_str(&self) -> ~str;}implto_strforint{fnto_str(&self) -> ~str{ int::to_str(*self)}}implto_strfor ~str{fnto_str(&self) -> ~str{self.clone()}}implto_strfor(){fnto_str(&self) -> ~str{ ~"()" }}traitmap<T>{fnmap<U:Copy>(&self,f:&fn(&T) -> U) -> ~[U];}impl<T>map<T>for ~[T]{fn map<U:Copy>(&self,f:&fn(&T) -> U) -> ~[U]{letmut r = ~[];/*for std::vec::each(*self) |x| { r += ~[f(x)]; }*/forself.iter().advance |x| { r += ~[f(x)];}
r
}}fnfoo<U,T:map<U>>(x:T) -> ~[~str]{
x.map(|_e| ~"hi" )}fnbar<U:to_str,T:map<U>>(x:T) -> ~[~str]{
x.map(|_e| _e.to_str())}pubfn main(){assert_eq!(foo(~[1]), ~[~"hi"]); assert_eq!(bar::<int, ~[int]>(~[4, 5]), ~[~"4", ~"5"]); assert_eq!(bar::<~str, ~[~str]>(~[~"x", ~"y"]), ~[~"x", ~"y"]); assert_eq!(bar::<(), ~[()]>(~[()]), ~[~"()"]);}
With the each line changed to iter().advance, this generates bad code. It's definitely a bug in codegen and not the libraries/test.
The text was updated successfully, but these errors were encountered:
Trying to modernize this for the new for syntax; cannot reproduce. I do, however, find an ICE.
The line marked "works fine" solves the compiler error (+ICE) but appears to generate correct code.
trait map<T> {
fn map<U>(&self, f: &fn(&T) -> U) -> ~[U];
}
impl<T> map<T> for ~[T] {
fn map<U>(&self, f: &fn(&T) -> U) -> ~[U] {
let mut r: ~[U] = ~[];
// for x in self.iter() { r.push(f(x)); } // works fine
for x in self.iter() { r += ~[f(x)]; }
r
}
}
pub fn main() { }
emits:
foo.rs:8:31: 8:43 error: binary operation + cannot be applied to type `~[U]`
foo.rs:8 for x in self.iter() { r += ~[f(x)]; }
^~~~~~~~~~~~
error: internal compiler error: no type for node 61: expr [f(x)] (id=61) in fcx 7fa3c8c584d0
With the
each
line changed toiter().advance
, this generates bad code. It's definitely a bug in codegen and not the libraries/test.The text was updated successfully, but these errors were encountered: