Skip to content

Commit 37c21d6

Browse files
committed
Do not suggest "wrapping the expression in std::num::NonZeroU64"
1 parent c2ecd3a commit 37c21d6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

compiler/rustc_typeck/src/check/demand.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_span::{BytePos, Span};
1919
use super::method::probe;
2020

2121
use std::iter;
22+
use std::ops::Bound;
2223

2324
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2425
pub fn emit_coerce_suggestions(
@@ -347,6 +348,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
347348
}
348349
}
349350

351+
// Avoid suggesting wrapping in `NonZeroU64` and alike
352+
if self.tcx.layout_scalar_valid_range(expected_adt.did())
353+
!= (Bound::Unbounded, Bound::Unbounded)
354+
{
355+
return;
356+
}
357+
350358
let compatible_variants: Vec<String> = expected_adt
351359
.variants()
352360
.iter()

0 commit comments

Comments
 (0)