]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #49117 - nivkner:fixme_fixup3, r=estebank
authorkennytm <kennytm@gmail.com>
Thu, 22 Mar 2018 09:51:25 +0000 (17:51 +0800)
committerkennytm <kennytm@gmail.com>
Thu, 22 Mar 2018 14:43:37 +0000 (22:43 +0800)
address some FIXME whose associated issues were marked as closed

part of #44366

1  2 
src/librustc_resolve/resolve_imports.rs
src/librustc_typeck/check/mod.rs
src/libsyntax/parse/mod.rs
src/libsyntax/test.rs

index 4cbebdc3c1c39f9458fb732e4e0da80bf471d2f7,a73f660c4059aaff3fd600af0dd81644876805e1..644a2ffe3c379bfc9c7864bfe8e7c51502c0132e
@@@ -667,10 -667,11 +667,10 @@@ impl<'a, 'b:'a> ImportResolver<'a, 'b> 
              }
              PathResult::Failed(span, msg, true) => {
                  let (mut self_path, mut self_result) = (module_path.clone(), None);
 -                if !self_path.is_empty() &&
 -                    !token::Ident(self_path[0].node).is_path_segment_keyword() &&
 -                    !(self_path.len() > 1 &&
 -                      token::Ident(self_path[1].node).is_path_segment_keyword())
 -                {
 +                let is_special = |ident| token::Ident(ident).is_path_segment_keyword() &&
 +                                         ident.name != keywords::CrateRoot.name();
 +                if !self_path.is_empty() && !is_special(self_path[0].node) &&
 +                   !(self_path.len() > 1 && is_special(self_path[1].node)) {
                      self_path[0].node.name = keywords::SelfValue.name();
                      self_result = Some(self.resolve_path(&self_path, None, false, span));
                  }
@@@ -1025,28 -1026,9 +1025,9 @@@ fn import_path_to_string(names: &[Spann
          if names.is_empty() {
              import_directive_subclass_to_string(subclass)
          } else {
-             // FIXME: Remove this entire logic after #48116 is fixed.
-             //
-             // Note that this code looks a little wonky, it's currently here to
-             // hopefully help debug #48116, but otherwise isn't intended to
-             // cause any problems.
-             let x = format!(
-                 "{}::{}",
-                 names_to_string(names),
-                 import_directive_subclass_to_string(subclass),
-             );
-             if names.is_empty() || x.starts_with("::") {
-                 span_bug!(
-                     span,
-                     "invalid name `{}` at {:?}; global = {}, names = {:?}, subclass = {:?}",
-                     x,
-                     span,
-                     global,
-                     names,
-                     subclass
-                 );
-             }
-             return x
+             format!("{}::{}",
+                     names_to_string(names),
+                     import_directive_subclass_to_string(subclass))
          }
      }
  }
index eb61aa94cd76fbf571d153fd7bd00fa8c85ea451,c99e49256faa048080ad22372d17d1294094c1d4..69879bbe85d6e4e50d22af815d071c08be95a4f2
@@@ -718,18 -718,6 +718,18 @@@ fn typeck_item_bodies<'a, 'tcx>(tcx: Ty
      })?)
  }
  
 +fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
 +    wfcheck::check_item_well_formed(tcx, def_id);
 +}
 +
 +fn check_trait_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
 +    wfcheck::check_trait_item(tcx, def_id);
 +}
 +
 +fn check_impl_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
 +    wfcheck::check_impl_item(tcx, def_id);
 +}
 +
  pub fn provide(providers: &mut Providers) {
      *providers = Providers {
          typeck_item_bodies,
          has_typeck_tables,
          adt_destructor,
          used_trait_imports,
 +        check_item_well_formed,
 +        check_trait_item_well_formed,
 +        check_impl_item_well_formed,
          ..*providers
      };
  }
@@@ -2535,7 -2520,7 +2535,7 @@@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, '
              if sugg_unit {
                  let sugg_span = sess.codemap().end_point(expr_sp);
                  // remove closing `)` from the span
 -                let sugg_span = sugg_span.with_hi(sugg_span.lo());
 +                let sugg_span = sugg_span.shrink_to_lo();
                  err.span_suggestion(
                      sugg_span,
                      "expected the unit value `()`; create it with empty parentheses",
                  let origin = self.misc(call_span);
                  let ures = self.at(&origin, self.param_env).sup(ret_ty, formal_ret);
  
-                 // FIXME(#15760) can't use try! here, FromError doesn't default
+                 // FIXME(#27336) can't use ? here, Try::from_error doesn't default
                  // to identity so the resulting type is not constrained.
                  match ures {
                      Ok(ok) => {
                          // we can.  We don't care if some things turn
                          // out unconstrained or ambiguous, as we're
                          // just trying to get hints here.
-                         let result = self.save_and_restore_in_snapshot_flag(|_| {
+                         self.save_and_restore_in_snapshot_flag(|_| {
                              let mut fulfill = FulfillmentContext::new();
-                             let ok = ok; // FIXME(#30046)
                              for obligation in ok.obligations {
                                  fulfill.register_predicate_obligation(self, obligation);
                              }
                              fulfill.select_where_possible(self)
-                         });
-                         match result {
-                             Ok(()) => { }
-                             Err(_) => return Err(()),
-                         }
+                         }).map_err(|_| ())?;
                      }
                      Err(_) => return Err(()),
                  }
index f7e5d40b52468821e79a28e324a01cdd866fdb1f,fdb3b91fbbf04bd18bc2412bd895d0843e76af19..202dc03eaa41d511452cb28880e194460d610dc9
@@@ -298,7 -298,6 +298,6 @@@ pub fn str_lit(lit: &str, diag: Option<
      debug!("parse_str_lit: given {}", escape_default(lit));
      let mut res = String::with_capacity(lit.len());
  
-     // FIXME #8372: This could be a for-loop if it didn't borrow the iterator
      let error = |i| format!("lexer should have rejected {} at {}", lit, i);
  
      /// Eat everything up to a non-whitespace
@@@ -503,7 -502,6 +502,6 @@@ pub fn byte_lit(lit: &str) -> (u8, usiz
  pub fn byte_str_lit(lit: &str) -> Lrc<Vec<u8>> {
      let mut res = Vec::with_capacity(lit.len());
  
-     // FIXME #8372: This could be a for-loop if it didn't borrow the iterator
      let error = |i| format!("lexer should have rejected {} at {}", lit, i);
  
      /// Eat everything up to a non-whitespace
@@@ -713,7 -711,7 +711,7 @@@ mod tests 
                          id: ast::DUMMY_NODE_ID,
                          node: ast::ExprKind::Path(None, ast::Path {
                              span: sp(0, 6),
 -                            segments: vec![ast::PathSegment::crate_root(sp(0, 2)),
 +                            segments: vec![ast::PathSegment::crate_root(sp(0, 0)),
                                          str2seg("a", 2, 3),
                                          str2seg("b", 5, 6)]
                          }),
diff --combined src/libsyntax/test.rs
index 9edfa767d31958df8c0ff07e7850c49708c072b0,69213f236e1dd07fcce6839f41a2f871e3e4b17f..5264b627e96137b0b933adce4c3bdcab30115ae5
@@@ -78,7 -78,7 +78,7 @@@ pub fn modify_for_testing(sess: &ParseS
                            span_diagnostic: &errors::Handler,
                            features: &Features) -> ast::Crate {
      // Check for #[reexport_test_harness_main = "some_name"] which
 -    // creates a `use some_name = __test::main;`. This needs to be
 +    // creates a `use __test::main as some_name;`. This needs to be
      // unconditional, so that the attribute is still marked as used in
      // non-test builds.
      let reexport_test_harness_main =
@@@ -240,8 -240,7 +240,8 @@@ fn mk_reexport_mod(cx: &mut TestCtxt
                                    cx.ext_cx.path(DUMMY_SP, vec![super_, r]))
      }).chain(tested_submods.into_iter().map(|(r, sym)| {
          let path = cx.ext_cx.path(DUMMY_SP, vec![super_, r, sym]);
 -        cx.ext_cx.item_use_simple_(DUMMY_SP, dummy_spanned(ast::VisibilityKind::Public), r, path)
 +        cx.ext_cx.item_use_simple_(DUMMY_SP, dummy_spanned(ast::VisibilityKind::Public),
 +                                   Some(r), path)
      })).collect();
  
      let reexport_mod = ast::Mod {
@@@ -503,7 -502,7 +503,7 @@@ fn mk_std(cx: &TestCtxt) -> P<ast::Item
          (ast::ItemKind::Use(P(ast::UseTree {
              span: DUMMY_SP,
              prefix: path_node(vec![id_test]),
 -            kind: ast::UseTreeKind::Simple(id_test),
 +            kind: ast::UseTreeKind::Simple(None),
          })),
           ast::VisibilityKind::Public, keywords::Invalid.ident())
      } else {
@@@ -591,13 -590,13 +591,13 @@@ fn mk_test_module(cx: &mut TestCtxt) -
          tokens: None,
      })).pop().unwrap();
      let reexport = cx.reexport_test_harness_main.map(|s| {
 -        // building `use <ident> = __test::main`
 -        let reexport_ident = Ident::with_empty_ctxt(s);
 +        // building `use __test::main as <ident>;`
 +        let rename = Ident::with_empty_ctxt(s);
  
          let use_path = ast::UseTree {
              span: DUMMY_SP,
              prefix: path_node(vec![mod_ident, Ident::from_str("main")]),
 -            kind: ast::UseTreeKind::Simple(reexport_ident),
 +            kind: ast::UseTreeKind::Simple(Some(rename)),
          };
  
          expander.fold_item(P(ast::Item {
@@@ -628,8 -627,15 +628,15 @@@ fn path_node(ids: Vec<Ident>) -> ast::P
  }
  
  fn path_name_i(idents: &[Ident]) -> String {
-     // FIXME: Bad copies (#2543 -- same for everything else that says "bad")
-     idents.iter().map(|i| i.to_string()).collect::<Vec<String>>().join("::")
+     let mut path_name = "".to_string();
+     let mut idents_iter = idents.iter().peekable();
+     while let Some(ident) = idents_iter.next() {
+         path_name.push_str(&ident.name.as_str());
+         if let Some(_) = idents_iter.peek() {
+             path_name.push_str("::")
+         }
+     }
+     path_name
  }
  
  fn mk_tests(cx: &TestCtxt) -> P<ast::Item> {
@@@ -682,7 -688,6 +689,6 @@@ fn mk_test_desc_and_fn_rec(cx: &TestCtx
      // gensym information.
  
      let span = ignored_span(cx, test.span);
-     let path = test.path.clone();
      let ecx = &cx.ext_cx;
      let self_id = ecx.ident_of("self");
      let test_id = ecx.ident_of("test");
      // creates $name: $expr
      let field = |name, expr| ecx.field_imm(span, ecx.ident_of(name), expr);
  
-     debug!("encoding {}", path_name_i(&path[..]));
      // path to the #[test] function: "foo::bar::baz"
-     let path_string = path_name_i(&path[..]);
+     let path_string = path_name_i(&test.path[..]);
+     debug!("encoding {}", path_string);
      let name_expr = ecx.expr_str(span, Symbol::intern(&path_string));
  
      // self::test::StaticTestName($name_expr)
              diag.bug("expected to find top-level re-export name, but found None");
          }
      };
-     visible_path.extend(path);
+     visible_path.extend_from_slice(&test.path[..]);
  
      // Rather than directly give the test function to the test
      // harness, we create a wrapper like one of the following: