]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #50257 - estebank:fix-49560, r=nikomatsakis
authorkennytm <kennytm@gmail.com>
Fri, 27 Apr 2018 20:51:00 +0000 (04:51 +0800)
committerkennytm <kennytm@gmail.com>
Fri, 27 Apr 2018 20:51:00 +0000 (04:51 +0800)
Don't ICE on tuple struct ctor with incorrect arg count

Fix #49560.

1  2 
src/librustc/traits/error_reporting.rs

index 285d530a38a69cab5e6eda57c2f29f9f5470d651,3eb45439001cd16298fd037056b8b5819fb5d536..047d4bb893096103d38a4f6c3a6af6132ea3133d
@@@ -24,7 -24,6 +24,7 @@@ use super::
      SelectionContext,
      SelectionError,
      ObjectSafetyViolation,
 +    Overflow,
  };
  
  use errors::DiagnosticBuilder;
@@@ -660,7 -659,8 +660,7 @@@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx
                                  predicate: ty::Predicate::Trait(predicate),
                                  .. obligation.clone()
                              };
 -                            let mut selcx = SelectionContext::new(self);
 -                            if selcx.evaluate_obligation(&unit_obligation) {
 +                            if self.predicate_may_hold(&unit_obligation) {
                                  err.note("the trait is implemented for `()`. \
                                           Possibly this error has been caused by changes to \
                                           Rust's type-inference algorithm \
                  }
                  err.struct_error(self.tcx, span, "constant expression")
              }
 +
 +            Overflow => {
 +                bug!("overflow should be handled before the `report_selection_error` path");
 +            }
          };
          self.note_obligation_cause(&mut err, obligation);
          err.emit();
                  .count();
  
              let mut trait_type = trait_ref.self_ty();
 -            let mut selcx = SelectionContext::new(self);
  
              for refs_remaining in 0..refs_number {
                  if let ty::TypeVariants::TyRef(_, ty::TypeAndMut{ ty: t_type, mutbl: _ }) =
                                                           obligation.param_env,
                                                           new_trait_ref.to_predicate());
  
 -                    if selcx.evaluate_obligation(&new_obligation) {
 +                    if self.predicate_may_hold(&new_obligation) {
                          let sp = self.tcx.sess.codemap()
                              .span_take_while(span, |c| c.is_whitespace() || *c == '&');
  
                       ArgKind::Arg(format!("{}", field.name), "_".to_string())
                   }).collect::<Vec<_>>())
              }
+             hir::map::NodeStructCtor(ref variant_data) => {
+                 (self.tcx.sess.codemap().def_span(self.tcx.hir.span(variant_data.id())),
+                  variant_data.fields()
+                     .iter().map(|_| ArgKind::Arg("_".to_owned(), "_".to_owned()))
+                     .collect())
+             }
              _ => panic!("non-FnLike node found: {:?}", node),
          }
      }
@@@ -1325,7 -1328,7 +1331,7 @@@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx
                  cleaned_pred.to_predicate()
              );
  
 -            selcx.evaluate_obligation(&obligation)
 +            self.predicate_may_hold(&obligation)
          })
      }