Clean up some things in the name resolver
* Get rid of a typo in a function name * Rename `currently_processing_generics`: The old name confused me at first since I assumed it referred to generic *parameters* when it was in fact referring to generic *arguments*. Generics are typically short for generic params. * Get rid of a few unwraps by properly leveraging slice patterns
This commit is contained in:
parent
cb4d9a1902
commit
3f7b1a5f49
@ -594,9 +594,9 @@ struct DiagnosticMetadata<'ast> {
|
|||||||
/// The current trait (used to suggest).
|
/// The current trait (used to suggest).
|
||||||
current_item: Option<&'ast Item>,
|
current_item: Option<&'ast Item>,
|
||||||
|
|
||||||
/// When processing generics and encountering a type not found, suggest introducing a type
|
/// When processing generic arguments and encountering an unresolved ident not found,
|
||||||
/// param.
|
/// suggest introducing a type or const param depending on the context.
|
||||||
currently_processing_generics: bool,
|
currently_processing_generic_args: bool,
|
||||||
|
|
||||||
/// The current enclosing (non-closure) function (used for better errors).
|
/// The current enclosing (non-closure) function (used for better errors).
|
||||||
current_function: Option<(FnKind<'ast>, Span)>,
|
current_function: Option<(FnKind<'ast>, Span)>,
|
||||||
@ -1069,7 +1069,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
|||||||
|
|
||||||
fn visit_generic_arg(&mut self, arg: &'ast GenericArg) {
|
fn visit_generic_arg(&mut self, arg: &'ast GenericArg) {
|
||||||
debug!("visit_generic_arg({:?})", arg);
|
debug!("visit_generic_arg({:?})", arg);
|
||||||
let prev = replace(&mut self.diagnostic_metadata.currently_processing_generics, true);
|
let prev = replace(&mut self.diagnostic_metadata.currently_processing_generic_args, true);
|
||||||
match arg {
|
match arg {
|
||||||
GenericArg::Type(ref ty) => {
|
GenericArg::Type(ref ty) => {
|
||||||
// We parse const arguments as path types as we cannot distinguish them during
|
// We parse const arguments as path types as we cannot distinguish them during
|
||||||
@ -1100,7 +1100,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
self.diagnostic_metadata.currently_processing_generics = prev;
|
self.diagnostic_metadata.currently_processing_generic_args = prev;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1113,7 +1113,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
|||||||
self.resolve_anon_const(ct, AnonConstKind::ConstArg(IsRepeatExpr::No))
|
self.resolve_anon_const(ct, AnonConstKind::ConstArg(IsRepeatExpr::No))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.diagnostic_metadata.currently_processing_generics = prev;
|
self.diagnostic_metadata.currently_processing_generic_args = prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_assoc_constraint(&mut self, constraint: &'ast AssocConstraint) {
|
fn visit_assoc_constraint(&mut self, constraint: &'ast AssocConstraint) {
|
||||||
|
@ -452,7 +452,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.suggest_self_or_self_ref(&mut err, path, span);
|
self.suggest_self_or_self_ref(&mut err, path, span);
|
||||||
self.detect_assoct_type_constraint_meant_as_path(&mut err, &base_error);
|
self.detect_assoc_type_constraint_meant_as_path(&mut err, &base_error);
|
||||||
if self.suggest_self_ty(&mut err, source, path, span)
|
if self.suggest_self_ty(&mut err, source, path, span)
|
||||||
|| self.suggest_self_value(&mut err, source, path, span)
|
|| self.suggest_self_value(&mut err, source, path, span)
|
||||||
{
|
{
|
||||||
@ -491,7 +491,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||||||
(err, candidates)
|
(err, candidates)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn detect_assoct_type_constraint_meant_as_path(
|
fn detect_assoc_type_constraint_meant_as_path(
|
||||||
&self,
|
&self,
|
||||||
err: &mut Diagnostic,
|
err: &mut Diagnostic,
|
||||||
base_error: &BaseError,
|
base_error: &BaseError,
|
||||||
@ -799,7 +799,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||||||
false,
|
false,
|
||||||
) = (source, res, is_macro)
|
) = (source, res, is_macro)
|
||||||
{
|
{
|
||||||
if let Some(bounds @ [_, .., _]) = self.diagnostic_metadata.current_trait_object {
|
if let Some(bounds @ [first_bound, .., last_bound]) =
|
||||||
|
self.diagnostic_metadata.current_trait_object
|
||||||
|
{
|
||||||
fallback = true;
|
fallback = true;
|
||||||
let spans: Vec<Span> = bounds
|
let spans: Vec<Span> = bounds
|
||||||
.iter()
|
.iter()
|
||||||
@ -807,9 +809,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||||||
.filter(|&sp| sp != base_error.span)
|
.filter(|&sp| sp != base_error.span)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let start_span = bounds[0].span();
|
let start_span = first_bound.span();
|
||||||
// `end_span` is the end of the poly trait ref (Foo + 'baz + Bar><)
|
// `end_span` is the end of the poly trait ref (Foo + 'baz + Bar><)
|
||||||
let end_span = bounds.last().unwrap().span();
|
let end_span = last_bound.span();
|
||||||
// `last_bound_span` is the last bound of the poly trait ref (Foo + >'baz< + Bar)
|
// `last_bound_span` is the last bound of the poly trait ref (Foo + >'baz< + Bar)
|
||||||
let last_bound_span = spans.last().cloned().unwrap();
|
let last_bound_span = spans.last().cloned().unwrap();
|
||||||
let mut multi_span: MultiSpan = spans.clone().into();
|
let mut multi_span: MultiSpan = spans.clone().into();
|
||||||
@ -2419,10 +2421,10 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
|||||||
let mut iter = ident.chars().map(|c| c.is_uppercase());
|
let mut iter = ident.chars().map(|c| c.is_uppercase());
|
||||||
let single_uppercase_char =
|
let single_uppercase_char =
|
||||||
matches!(iter.next(), Some(true)) && matches!(iter.next(), None);
|
matches!(iter.next(), Some(true)) && matches!(iter.next(), None);
|
||||||
if !self.diagnostic_metadata.currently_processing_generics && !single_uppercase_char {
|
if !self.diagnostic_metadata.currently_processing_generic_args && !single_uppercase_char {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
match (self.diagnostic_metadata.current_item, single_uppercase_char, self.diagnostic_metadata.currently_processing_generics) {
|
match (self.diagnostic_metadata.current_item, single_uppercase_char, self.diagnostic_metadata.currently_processing_generic_args) {
|
||||||
(Some(Item { kind: ItemKind::Fn(..), ident, .. }), _, _) if ident.name == sym::main => {
|
(Some(Item { kind: ItemKind::Fn(..), ident, .. }), _, _) if ident.name == sym::main => {
|
||||||
// Ignore `fn main()` as we don't want to suggest `fn main<T>()`
|
// Ignore `fn main()` as we don't want to suggest `fn main<T>()`
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user