diff options
| author | Michael Goulet <michael@errs.io> | 2023-05-11 17:43:09 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-11 17:43:09 -0700 |
| commit | 6641b49cddbde1462d20c0f222444ec5f4ee0400 (patch) | |
| tree | 018de79b1614629cf63ce09f0a71fc017c8166c3 /compiler/rustc_resolve/src | |
| parent | eead6f4703c17882cdd77044ca4a60a7eb2f5ea0 (diff) | |
| parent | 3851a4bb914f74fb3f1d7394479ad810deb653cd (diff) | |
| download | rust-6641b49cddbde1462d20c0f222444ec5f4ee0400.tar.gz rust-6641b49cddbde1462d20c0f222444ec5f4ee0400.zip | |
Rollup merge of #111460 - clubby789:lowercase-box-self, r=compiler-errors
Improve suggestion for `self: Box<self>` Fixes #110642
Diffstat (limited to 'compiler/rustc_resolve/src')
| -rw-r--r-- | compiler/rustc_resolve/src/diagnostics.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/errors.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/ident.rs | 44 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/late.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/lib.rs | 2 |
5 files changed, 42 insertions, 24 deletions
diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 72cdce5c8f0..6675b8ed59b 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -948,6 +948,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { ResolutionError::InvalidAsmSym => { self.tcx.sess.create_err(errs::InvalidAsmSym { span }) } + ResolutionError::LowercaseSelf => { + self.tcx.sess.create_err(errs::LowercaseSelf { span }) + } } } diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index f6d7e8b4c87..2ab55f12637 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -443,6 +443,14 @@ pub(crate) struct InvalidAsmSym { } #[derive(Diagnostic)] +#[diag(resolve_lowercase_self)] +pub(crate) struct LowercaseSelf { + #[primary_span] + #[suggestion(code = "Self", applicability = "maybe-incorrect", style = "short")] + pub(crate) span: Span, +} + +#[derive(Diagnostic)] #[diag(resolve_trait_impl_duplicate, code = "E0201")] pub(crate) struct TraitImplDuplicate { #[primary_span] diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 5a3ae656ad4..755acdd81fe 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -15,8 +15,7 @@ use std::ptr; use crate::errors::{ParamKindInEnumDiscriminant, ParamKindInNonTrivialAnonConst}; use crate::late::{ - ConstantHasGenerics, ConstantItemKind, HasGenericParams, NoConstantGenericsReason, PathSource, - Rib, RibKind, + ConstantHasGenerics, HasGenericParams, NoConstantGenericsReason, PathSource, Rib, RibKind, }; use crate::macros::{sub_namespace_match, MacroRulesScope}; use crate::{errors, AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, Determinacy, Finalize}; @@ -1127,28 +1126,25 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { RibKind::ConstantItem(_, item) => { // Still doesn't deal with upvars if let Some(span) = finalize { - let (span, resolution_error) = - if let Some((ident, constant_item_kind)) = item { - let kind_str = match constant_item_kind { - ConstantItemKind::Const => "const", - ConstantItemKind::Static => "static", - }; - ( - span, - AttemptToUseNonConstantValueInConstant( - ident, "let", kind_str, - ), - ) - } else { - ( - rib_ident.span, - AttemptToUseNonConstantValueInConstant( - original_rib_ident_def, - "const", - "let", - ), - ) - }; + let (span, resolution_error) = match item { + None if rib_ident.as_str() == "self" => (span, LowercaseSelf), + None => ( + rib_ident.span, + AttemptToUseNonConstantValueInConstant( + original_rib_ident_def, + "const", + "let", + ), + ), + Some((ident, kind)) => ( + span, + AttemptToUseNonConstantValueInConstant( + ident, + "let", + kind.as_str(), + ), + ), + }; self.report_error(span, resolution_error); } return Res::Err; diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index d7509cbf10e..44e277c99b9 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -150,6 +150,15 @@ pub(crate) enum ConstantItemKind { Static, } +impl ConstantItemKind { + pub(crate) fn as_str(&self) -> &'static str { + match self { + Self::Const => "const", + Self::Static => "static", + } + } +} + #[derive(Debug, Copy, Clone, PartialEq, Eq)] enum RecordPartialRes { Yes, diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 590609f9ed3..c12dc2f5d92 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -251,6 +251,8 @@ enum ResolutionError<'a> { TraitImplDuplicate { name: Symbol, trait_item_span: Span, old_span: Span }, /// Inline asm `sym` operand must refer to a `fn` or `static`. InvalidAsmSym, + /// `self` used instead of `Self` in a generic parameter + LowercaseSelf, } enum VisResolutionError<'a> { |
