1
Fork 0

Rollup merge of #94746 - notriddle:notriddle/method-rustc-on-unimplemented, r=davidtwco

diagnostics: use rustc_on_unimplemented to recommend `[].iter()`

To make this work, the `#[rustc_on_unimplemented]` data needs to be used to
report method resolution errors, which is most of what this commit does.

Fixes #94581
This commit is contained in:
Matthias Krüger 2022-03-10 12:20:53 +01:00 committed by GitHub
commit e7281d08de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 258 additions and 162 deletions

View file

@ -11,7 +11,7 @@ use std::iter;
use super::InferCtxtPrivExt;
crate trait InferCtxtExt<'tcx> {
pub trait InferCtxtExt<'tcx> {
/*private*/
fn impl_similar_to(
&self,
@ -204,6 +204,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
flags.push((sym::_Self, Some("{integral}".to_owned())));
}
if self_ty.is_array_slice() {
flags.push((sym::_Self, Some("&[]".to_owned())));
}
if let ty::Array(aty, len) = self_ty.kind() {
flags.push((sym::_Self, Some("[]".to_owned())));
flags.push((sym::_Self, Some(format!("[{}]", aty))));