Check if E0530 is rustc_resolve::late::PatternSource::Match
to emit suggestion
This commit is contained in:
parent
ea46e7a47e
commit
c2436d54d0
3 changed files with 14 additions and 11 deletions
|
@ -28,7 +28,7 @@ use rustc_span::{BytePos, Span};
|
|||
use tracing::debug;
|
||||
|
||||
use crate::imports::{Import, ImportKind, ImportResolver};
|
||||
use crate::late::Rib;
|
||||
use crate::late::{PatternSource, Rib};
|
||||
use crate::path_names_to_string;
|
||||
use crate::{AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, BindingError, Finalize};
|
||||
use crate::{HasGenericParams, MacroRulesScope, Module, ModuleKind, ModuleOrUniformRoot};
|
||||
|
@ -896,7 +896,7 @@ impl<'a> Resolver<'a> {
|
|||
err
|
||||
}
|
||||
ResolutionError::BindingShadowsSomethingUnacceptable {
|
||||
shadowing_binding_descr,
|
||||
shadowing_binding,
|
||||
name,
|
||||
participle,
|
||||
article,
|
||||
|
@ -909,15 +909,18 @@ impl<'a> Resolver<'a> {
|
|||
span,
|
||||
E0530,
|
||||
"{}s cannot shadow {}s",
|
||||
shadowing_binding_descr,
|
||||
shadowing_binding.descr(),
|
||||
shadowed_binding_descr,
|
||||
);
|
||||
err.span_label(
|
||||
span,
|
||||
format!("cannot be named the same as {} {}", article, shadowed_binding_descr),
|
||||
);
|
||||
match shadowed_binding {
|
||||
Res::Def(DefKind::Ctor(CtorOf::Variant | CtorOf::Struct, CtorKind::Fn), _) => {
|
||||
match (shadowing_binding, shadowed_binding) {
|
||||
(
|
||||
PatternSource::Match,
|
||||
Res::Def(DefKind::Ctor(CtorOf::Variant | CtorOf::Struct, CtorKind::Fn), _),
|
||||
) => {
|
||||
err.span_suggestion(
|
||||
span,
|
||||
"try specify the pattern arguments",
|
||||
|
|
|
@ -50,7 +50,7 @@ struct BindingInfo {
|
|||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
enum PatternSource {
|
||||
pub enum PatternSource {
|
||||
Match,
|
||||
Let,
|
||||
For,
|
||||
|
@ -64,7 +64,7 @@ enum IsRepeatExpr {
|
|||
}
|
||||
|
||||
impl PatternSource {
|
||||
fn descr(self) -> &'static str {
|
||||
pub fn descr(self) -> &'static str {
|
||||
match self {
|
||||
PatternSource::Match => "match binding",
|
||||
PatternSource::Let => "let binding",
|
||||
|
@ -2845,7 +2845,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
|||
self.report_error(
|
||||
ident.span,
|
||||
ResolutionError::BindingShadowsSomethingUnacceptable {
|
||||
shadowing_binding_descr: pat_src.descr(),
|
||||
shadowing_binding: pat_src,
|
||||
name: ident.name,
|
||||
participle: if binding.is_import() { "imported" } else { "defined" },
|
||||
article: binding.res().article(),
|
||||
|
@ -2861,7 +2861,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
|||
self.report_error(
|
||||
ident.span,
|
||||
ResolutionError::BindingShadowsSomethingUnacceptable {
|
||||
shadowing_binding_descr: pat_src.descr(),
|
||||
shadowing_binding: pat_src,
|
||||
name: ident.name,
|
||||
participle: "defined",
|
||||
article: res.article(),
|
||||
|
|
|
@ -61,7 +61,7 @@ use tracing::debug;
|
|||
|
||||
use diagnostics::{ImportSuggestion, LabelSuggestion, Suggestion};
|
||||
use imports::{Import, ImportKind, ImportResolver, NameResolution};
|
||||
use late::{HasGenericParams, PathSource};
|
||||
use late::{HasGenericParams, PathSource, PatternSource};
|
||||
use macros::{MacroRulesBinding, MacroRulesScope, MacroRulesScopeRef};
|
||||
|
||||
use crate::access_levels::AccessLevelsVisitor;
|
||||
|
@ -230,7 +230,7 @@ enum ResolutionError<'a> {
|
|||
),
|
||||
/// Error E0530: `X` bindings cannot shadow `Y`s.
|
||||
BindingShadowsSomethingUnacceptable {
|
||||
shadowing_binding_descr: &'static str,
|
||||
shadowing_binding: PatternSource,
|
||||
name: Symbol,
|
||||
participle: &'static str,
|
||||
article: &'static str,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue