]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #63612 - estebank:macro-sugg-try-into, r=Centril
authorMazdak Farrokhzad <twingoow@gmail.com>
Fri, 16 Aug 2019 06:26:40 +0000 (08:26 +0200)
committerGitHub <noreply@github.com>
Fri, 16 Aug 2019 06:26:40 +0000 (08:26 +0200)
Do not suggest `try_into` for base types inside of macro expansions

1  2 
src/librustc_typeck/check/demand.rs

index c72966edc5ae8847fb7199143f47c9b9658cf46f,f3b56b31b775d360116087d33923b96fe668870d..de5ba8bc8eb42418d181cfebfd457809460b99e1
@@@ -347,9 -347,9 +347,9 @@@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> 
              sp,
          );
  
 -        // Check the `expn_info()` to see if this is a macro; if so, it's hard to
 -        // extract the text and make a good suggestion, so don't bother.
 -        let is_macro = sp.ctxt().outer_expn_info().is_some();
 +        // If the span is from a macro, then it's hard to extract the text
 +        // and make a good suggestion, so don't bother.
 +        let is_macro = sp.from_expansion();
  
          match (&expr.node, &expected.sty, &checked_ty.sty) {
              (_, &ty::Ref(_, exp, _), &ty::Ref(_, check, _)) => match (&exp.sty, &check.sty) {
              // FIXME(estebank): modify once we decide to suggest `as` casts
              return false;
          }
+         if !self.tcx.sess.source_map().span_to_filename(expr.span).is_real() {
+             // Ignore if span is from within a macro.
+             return false;
+         }
  
          // If casting this expression to a given numeric type would be appropriate in case of a type
          // mismatch.