message: don't redirect to a yanked version if it's the latest
diff: @@ -259,8 +259,8 @@ fn match_version(conn: &Connection, name: &str, version: Option<&str>) -> Option
  .unwrap_or_else(|| "*".into());
  let mut corrected_name = None;
  - let versions: Vec<(String, i32)> = {
  - let query = "SELECT name, version, releases.id
  + let versions: Vec<(String, i32, bool)> = {
  + let query = "SELECT name, version, releases.id, releases.yanked
  FROM releases INNER JOIN crates ON releases.crate_id = crates.id
  WHERE normalize_crate_name(name) = normalize_crate_name($1) AND yanked = false";
  @@ -275,11 +275,12 @@ fn match_version(conn: &Connection, name: &str, version: Option<&str>) -> Option
  }
  };
  - rows.map(|row| (row.get(1), row.get(2))).collect()
  + rows.map(|row| (row.get(1), row.get(2), row.get(3)))
  + .collect()
  };
  // first check for exact match, we can't expect users to use semver in query
  - if let Some((version, id)) = versions.iter().find(|(vers, _)| vers == &req_version) {
  + if let Some((version, id, _)) = versions.iter().find(|(vers, _, _)| vers == &req_version) {
  return Some(MatchVersion {
  corrected_name,
  version: MatchSemver::Exact((version.to_owned(), *id)),
  @@ -293,7 +294,7 @@ fn match_version(conn: &Connection, name: &str, version: Option<&str>) -> Option
  let versions_sem = {
  let mut versions_sem: Vec<(Version, i32)> = Vec::new();
  - for version in &versions {
  + for version in versions.iter().filter(|(_, _, yanked)| !yanked) {
  // in theory a crate must always have a semver compatible version, but check result just in case
  versions_sem.push((Version::parse(&version.0).ok()?, version.1));
  }
  @@ -314,11 +315,11 @@ fn match_version(conn: &Connection, name: &str, version: Option<&str>) -> Option
  }
  // semver is acting weird for '*' (any) range if a crate only have pre-release versions
  - // return first version if requested version is '*'
  - if req_version == "*" && !versions_sem.is_empty() {
  - return Some(MatchVersion {
  + // return first non-yanked version if requested version is '*'
  + if req_version == "*" {
  + return versions_sem.first().map(|v| MatchVersion {
  corrected_name,
  - version: MatchSemver::Semver((versions_sem[0].0.to_string(), versions_sem[0].1)),
  + version: MatchSemver::Semver((v.0.to_string(), v.1)),
  });
  }
  