Skip to content

Order of type paramerter decleration effects type checking #18240

Closed
@Ericson2314

Description

@Ericson2314

init_hack type checks, but init_hack2 doesn't, and the type error referes to a type parameter not bound in this module. I think there is some larger problem involving associated functions, as I really shouldn't need init_hack at all.

Unfortunately for the time being I cannot release my whole program because it is used in a school assignment. Reducing the program (e.g. making a new trait with just init, unused by other code) make the problem go away, so this code sample is the best I can do.

use std::io::net::ip::{Ipv4Addr, IpAddr};
use std::option::Option;
use std::sync::Arc;

use super::IpState;

pub trait RoutingTable: Send + Sync {

  // initialized with the neighbor IPs
  fn init<I>(i: I) -> Self where I: Iterator<IpAddr>;

  fn lookup(&self, IpAddr) -> Option<IpAddr>;

  fn monitor(state: Arc<IpState<Self>>) -> ();

  fn dump(&self);

}

pub fn init_hack<RT, I>(i: I) -> RT
  where RT: RoutingTable, I: Iterator<IpAddr>
{
  RoutingTable::init::<I>(i)
}

pub fn init_hack2<I, RT>(i: I) -> RT
  where RT: RoutingTable, I: Iterator<IpAddr>
{
  RoutingTable::init::<I>(i)
}

pub fn monitor_hack<RT>(s: Arc<IpState<RT>>) where RT: RoutingTable
{
  RoutingTable::monitor(s);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions