Skip to content

Commit 9ce2662

Browse files
authored
Rollup merge of rust-lang#63612 - estebank:macro-sugg-try-into, r=Centril
Do not suggest `try_into` for base types inside of macro expansions
2 parents e771421 + fbf1efb commit 9ce2662

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/librustc_typeck/check/demand.rs

+4
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
554554
// FIXME(estebank): modify once we decide to suggest `as` casts
555555
return false;
556556
}
557+
if !self.tcx.sess.source_map().span_to_filename(expr.span).is_real() {
558+
// Ignore if span is from within a macro.
559+
return false;
560+
}
557561

558562
// If casting this expression to a given numeric type would be appropriate in case of a type
559563
// mismatch.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
assert_eq!(10u64, 10usize); //~ ERROR mismatched types
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/dont-suggest-try_into-in-macros.rs:2:5
3+
|
4+
LL | assert_eq!(10u64, 10usize);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected u64, found usize
6+
|
7+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)