Rollup merge of #111612 - ChayimFriedman2:collect-into-slice-ref, r=petrochenkov
Give better error when collecting into `&[T]` The detection of slice reference of `{integral}` in `rustc_on_unimplemented` is hacky, but a proper solution requires changing `FmtPrinter` to add a parameter to print integers as `{integral}` and I didn't want to change it just for `rustc_on_unimplemented`. I can do that if requested, though. I'm open to better wording; this is the best I could come up with.
This commit is contained in:
commit
df8b0dfc27
4 changed files with 35 additions and 1 deletions
|
@ -306,6 +306,14 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// `&[{integral}]` - `FromIterator` needs that.
|
||||
if let ty::Ref(_, ref_ty, rustc_ast::Mutability::Not) = self_ty.kind()
|
||||
&& let ty::Slice(sty) = ref_ty.kind()
|
||||
&& sty.is_integral()
|
||||
{
|
||||
flags.push((sym::_Self, Some("&[{integral}]".to_owned())));
|
||||
}
|
||||
});
|
||||
|
||||
if let Ok(Some(command)) = OnUnimplementedDirective::of_item(self.tcx, def_id) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue