Auto merge of #87640 - JohnTitor:rollup-yq24nq5, r=JohnTitor
Rollup of 9 pull requests Successful merges: - #86072 (Cross compiling rustc_llvm on Darwin requires zlib.) - #87385 (Make `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` warn by default) - #87547 (Add missing examples for NonNull) - #87557 (Fix issue with autofix for ambiguous associated function from Rust 2021 prelude when struct is generic) - #87559 (Tweak borrowing suggestion in `for` loop) - #87596 (Add warning when whitespace is not skipped after an escaped newline) - #87606 (Add some TAIT-related regression tests) - #87609 (Add docs about performance and `Iterator::map` to `[T; N]::map`) - #87616 (Fix missing word in rustdoc book) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
1f0a591b3a
43 changed files with 577 additions and 94 deletions
|
@ -5,7 +5,7 @@ use rustc_ast::Mutability;
|
|||
use rustc_errors::Applicability;
|
||||
use rustc_hir as hir;
|
||||
use rustc_middle::ty::subst::InternalSubsts;
|
||||
use rustc_middle::ty::{Ref, Ty};
|
||||
use rustc_middle::ty::{Adt, Ref, Ty};
|
||||
use rustc_session::lint::builtin::RUST_2021_PRELUDE_COLLISIONS;
|
||||
use rustc_span::symbol::kw::Underscore;
|
||||
use rustc_span::symbol::{sym, Ident};
|
||||
|
@ -255,16 +255,31 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
method_name.name
|
||||
));
|
||||
|
||||
let self_ty = self
|
||||
let self_ty_name = self
|
||||
.sess()
|
||||
.source_map()
|
||||
.span_to_snippet(self_ty_span)
|
||||
.unwrap_or_else(|_| self_ty.to_string());
|
||||
|
||||
let self_ty_generics_count = match self_ty.kind() {
|
||||
// Get the number of generics the self type has (if an Adt) unless we can determine that
|
||||
// the user has written the self type with generics already which we (naively) do by looking
|
||||
// for a "<" in `self_ty_name`.
|
||||
Adt(def, _) if !self_ty_name.contains("<") => self.tcx.generics_of(def.did).count(),
|
||||
_ => 0,
|
||||
};
|
||||
let self_ty_generics = if self_ty_generics_count > 0 {
|
||||
format!("<{}>", vec!["_"; self_ty_generics_count].join(", "))
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
lint.span_suggestion(
|
||||
span,
|
||||
"disambiguate the associated function",
|
||||
format!("<{} as {}>::{}", self_ty, trait_name, method_name.name,),
|
||||
format!(
|
||||
"<{}{} as {}>::{}",
|
||||
self_ty_name, self_ty_generics, trait_name, method_name.name,
|
||||
),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue