Rollup merge of #149058 - amb-trait-lint, r=petrochenkov
FCW Lint when using an ambiguously glob imported trait Related to rust-lang/rust#147992. Report a lint when using an ambiguously glob import trait, this is a FCW because this should not be allowed. r? @petrochenkov
This commit is contained in:
commit
b5fa7495fe
9 changed files with 473 additions and 19 deletions
|
|
@ -622,7 +622,18 @@ struct ModuleData<'ra> {
|
|||
globs: CmRefCell<Vec<Import<'ra>>>,
|
||||
|
||||
/// Used to memoize the traits in this module for faster searches through all traits in scope.
|
||||
traits: CmRefCell<Option<Box<[(Macros20NormalizedIdent, Decl<'ra>, Option<Module<'ra>>)]>>>,
|
||||
traits: CmRefCell<
|
||||
Option<
|
||||
Box<
|
||||
[(
|
||||
Macros20NormalizedIdent,
|
||||
Decl<'ra>,
|
||||
Option<Module<'ra>>,
|
||||
bool, /* lint ambiguous */
|
||||
)],
|
||||
>,
|
||||
>,
|
||||
>,
|
||||
|
||||
/// Span of the module itself. Used for error reporting.
|
||||
span: Span,
|
||||
|
|
@ -719,7 +730,12 @@ impl<'ra> Module<'ra> {
|
|||
return;
|
||||
}
|
||||
if let Res::Def(DefKind::Trait | DefKind::TraitAlias, def_id) = binding.res() {
|
||||
collected_traits.push((name, binding, r.as_ref().get_module(def_id)))
|
||||
collected_traits.push((
|
||||
name,
|
||||
binding,
|
||||
r.as_ref().get_module(def_id),
|
||||
binding.is_ambiguity_recursive(),
|
||||
));
|
||||
}
|
||||
});
|
||||
*traits = Some(collected_traits.into_boxed_slice());
|
||||
|
|
@ -1877,7 +1893,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
if let Some(module) = current_trait {
|
||||
if self.trait_may_have_item(Some(module), assoc_item) {
|
||||
let def_id = module.def_id();
|
||||
found_traits.push(TraitCandidate { def_id, import_ids: smallvec![] });
|
||||
found_traits.push(TraitCandidate {
|
||||
def_id,
|
||||
import_ids: smallvec![],
|
||||
lint_ambiguous: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1915,11 +1935,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
|||
) {
|
||||
module.ensure_traits(self);
|
||||
let traits = module.traits.borrow();
|
||||
for &(trait_name, trait_binding, trait_module) in traits.as_ref().unwrap().iter() {
|
||||
for &(trait_name, trait_binding, trait_module, lint_ambiguous) in
|
||||
traits.as_ref().unwrap().iter()
|
||||
{
|
||||
if self.trait_may_have_item(trait_module, assoc_item) {
|
||||
let def_id = trait_binding.res().def_id();
|
||||
let import_ids = self.find_transitive_imports(&trait_binding.kind, trait_name.0);
|
||||
found_traits.push(TraitCandidate { def_id, import_ids });
|
||||
found_traits.push(TraitCandidate { def_id, import_ids, lint_ambiguous });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue