Do not suggest "wrapping the expression in std::num::NonZeroU64"

This commit is contained in:
Maybe Waffle 2022-07-18 21:55:47 +04:00
parent c2ecd3af87
commit 37c21d6fc7

View File

@ -19,6 +19,7 @@ use rustc_span::{BytePos, Span};
use super::method::probe;
use std::iter;
use std::ops::Bound;
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub fn emit_coerce_suggestions(
@ -347,6 +348,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
// Avoid suggesting wrapping in `NonZeroU64` and alike
if self.tcx.layout_scalar_valid_range(expected_adt.did())
!= (Bound::Unbounded, Bound::Unbounded)
{
return;
}
let compatible_variants: Vec<String> = expected_adt
.variants()
.iter()