From 532c15eb2a7fb9f1aae3f83bd083327fa2dde825 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 8 Mar 2024 00:02:11 +0000 Subject: [PATCH] Fix suggestion when shorthand self has erroneous type --- compiler/rustc_ast/src/ast.rs | 13 ++ compiler/rustc_parse/messages.ftl | 3 + compiler/rustc_parse/src/errors.rs | 19 +++ compiler/rustc_parse/src/parser/item.rs | 32 +++- src/tools/tidy/src/issues.txt | 194 ++++++++++++------------ tests/ui/parser/typed-self-param.rs | 14 ++ tests/ui/parser/typed-self-param.stderr | 50 ++++++ 7 files changed, 227 insertions(+), 98 deletions(-) create mode 100644 tests/ui/parser/typed-self-param.rs create mode 100644 tests/ui/parser/typed-self-param.stderr diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 13b1a589d9ba9..8e63702b62f27 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2355,6 +2355,19 @@ pub enum SelfKind { Explicit(P, Mutability), } +impl SelfKind { + pub fn as_suggestion(&self) -> String { + match self { + SelfKind::Value(mutbl) => mutbl.prefix_str().to_string(), + SelfKind::Region(None, mutbl) => mutbl.ref_prefix_str().to_string(), + SelfKind::Region(Some(lt), mutbl) => format!("&{lt} {}", mutbl.prefix_str()), + SelfKind::Explicit(_, _) => { + unreachable!("if we had an explicit self, we wouldn't be here") + } + } + } +} + pub type ExplicitSelf = Spanned; impl Param { diff --git a/compiler/rustc_parse/messages.ftl b/compiler/rustc_parse/messages.ftl index 60cc138fd7bc2..2256449b1528c 100644 --- a/compiler/rustc_parse/messages.ftl +++ b/compiler/rustc_parse/messages.ftl @@ -329,6 +329,9 @@ parse_incorrect_semicolon = .suggestion = remove this semicolon .help = {$name} declarations are not followed by a semicolon +parse_incorrect_type_on_self = type not allowed for shorthand `self` parameter + .suggestion = move the modifiers on `self` to the type + parse_incorrect_use_of_await = incorrect use of `await` .parentheses_suggestion = `await` is not a method call, remove the parentheses diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index c72b7e2cfa727..b31b343060ede 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -2974,3 +2974,22 @@ pub(crate) struct AsyncImpl { #[primary_span] pub span: Span, } + +#[derive(Diagnostic)] +#[diag(parse_incorrect_type_on_self)] +pub(crate) struct IncorrectTypeOnSelf { + #[primary_span] + pub span: Span, + #[subdiagnostic] + pub move_self_modifier: MoveSelfModifier, +} + +#[derive(Subdiagnostic)] +#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")] +pub(crate) struct MoveSelfModifier { + #[suggestion_part(code = "")] + pub removal_span: Span, + #[suggestion_part(code = "{modifier}")] + pub insertion_span: Span, + pub modifier: String, +} diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 79492fe62ed97..c43127d7b163c 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -2774,6 +2774,33 @@ impl<'a> Parser<'a> { }; Ok((eself, eself_ident, eself_hi)) }; + let expect_self_ident_not_typed = + |this: &mut Self, modifier: &SelfKind, modifier_span: Span| { + let eself_ident = expect_self_ident(this); + + // Recover `: Type` after a qualified self + if this.may_recover() && this.check_noexpect(&token::Colon) { + this.bump(); + let snap = this.create_snapshot_for_diagnostic(); + match this.parse_ty() { + Ok(ty) => { + this.dcx().emit_err(errors::IncorrectTypeOnSelf { + span: ty.span, + move_self_modifier: errors::MoveSelfModifier { + removal_span: modifier_span, + insertion_span: ty.span.shrink_to_lo(), + modifier: modifier.as_suggestion(), + }, + }); + } + Err(diag) => { + diag.cancel(); + this.restore_snapshot(snap); + } + } + } + eself_ident + }; // Recover for the grammar `*self`, `*const self`, and `*mut self`. let recover_self_ptr = |this: &mut Self| { this.dcx().emit_err(errors::SelfArgumentPointer { span: this.token.span }); @@ -2787,6 +2814,7 @@ impl<'a> Parser<'a> { let eself_lo = self.token.span; let (eself, eself_ident, eself_hi) = match self.token.uninterpolate().kind { token::BinOp(token::And) => { + let lo = self.token.span; let eself = if is_isolated_self(self, 1) { // `&self` self.bump(); @@ -2811,7 +2839,9 @@ impl<'a> Parser<'a> { // `¬_self` return Ok(None); }; - (eself, expect_self_ident(self), self.prev_token.span) + let hi = self.token.span; + let self_ident = expect_self_ident_not_typed(self, &eself, lo.until(hi)); + (eself, self_ident, hi) } // `*self` token::BinOp(token::Star) if is_isolated_self(self, 1) => { diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt index cd3976ea6575d..91bbf5041ff58 100644 --- a/src/tools/tidy/src/issues.txt +++ b/src/tools/tidy/src/issues.txt @@ -183,8 +183,8 @@ "ui/async-await/issue-67651.rs", "ui/async-await/issue-67765-async-diagnostic.rs", "ui/async-await/issue-68112.rs", -"ui/async-await/issue-68523.rs", "ui/async-await/issue-68523-start.rs", +"ui/async-await/issue-68523.rs", "ui/async-await/issue-69446-fnmut-capture.rs", "ui/async-await/issue-70594.rs", "ui/async-await/issue-70818.rs", @@ -342,8 +342,8 @@ "ui/borrowck/issue-52967-edition-2018-needs-two-phase-borrows.rs", "ui/borrowck/issue-53432-nested-closure-outlives-borrowed-value.rs", "ui/borrowck/issue-54499-field-mutation-marks-mut-as-used.rs", -"ui/borrowck/issue-54499-field-mutation-of-moved-out.rs", "ui/borrowck/issue-54499-field-mutation-of-moved-out-with-mut.rs", +"ui/borrowck/issue-54499-field-mutation-of-moved-out.rs", "ui/borrowck/issue-54499-field-mutation-of-never-init.rs", "ui/borrowck/issue-54597-reject-move-out-of-borrow-via-pat.rs", "ui/borrowck/issue-55492-borrowck-migrate-scans-parents.rs", @@ -360,9 +360,9 @@ "ui/borrowck/issue-71546.rs", "ui/borrowck/issue-7573.rs", "ui/borrowck/issue-80772.rs", +"ui/borrowck/issue-81365-1.rs", "ui/borrowck/issue-81365-10.rs", "ui/borrowck/issue-81365-11.rs", -"ui/borrowck/issue-81365-1.rs", "ui/borrowck/issue-81365-2.rs", "ui/borrowck/issue-81365-3.rs", "ui/borrowck/issue-81365-4.rs", @@ -392,6 +392,9 @@ "ui/borrowck/issue-95079-missing-move-in-nested-closure.rs", "ui/box/issue-82446.rs", "ui/box/issue-95036.rs", +"ui/c-variadic/issue-32201.rs", +"ui/c-variadic/issue-86053-1.rs", +"ui/c-variadic/issue-86053-2.rs", "ui/cast/issue-106883-is-empty.rs", "ui/cast/issue-10991.rs", "ui/cast/issue-17444.rs", @@ -399,19 +402,19 @@ "ui/cast/issue-85586.rs", "ui/cast/issue-88621.rs", "ui/cast/issue-89497.rs", +"ui/closure-expected-type/issue-24421.rs", "ui/closure_context/issue-26046-fn-mut.rs", "ui/closure_context/issue-26046-fn-once.rs", "ui/closure_context/issue-42065.rs", -"ui/closure-expected-type/issue-24421.rs", "ui/closures/2229_closure_analysis/issue-118144.rs", "ui/closures/2229_closure_analysis/issue-87378.rs", "ui/closures/2229_closure_analysis/issue-87987.rs", "ui/closures/2229_closure_analysis/issue-88118-2.rs", -"ui/closures/2229_closure_analysis/issue_88118.rs", "ui/closures/2229_closure_analysis/issue-88476.rs", "ui/closures/2229_closure_analysis/issue-89606.rs", "ui/closures/2229_closure_analysis/issue-90465.rs", "ui/closures/2229_closure_analysis/issue-92724-needsdrop-query-cycle.rs", +"ui/closures/2229_closure_analysis/issue_88118.rs", "ui/closures/2229_closure_analysis/match/issue-87097.rs", "ui/closures/2229_closure_analysis/match/issue-87426.rs", "ui/closures/2229_closure_analysis/match/issue-87988.rs", @@ -644,8 +647,8 @@ "ui/const-generics/issues/issue-99641.rs", "ui/const-generics/parser-error-recovery/issue-89013-no-assoc.rs", "ui/const-generics/parser-error-recovery/issue-89013-no-kw.rs", -"ui/const-generics/parser-error-recovery/issue-89013.rs", "ui/const-generics/parser-error-recovery/issue-89013-type.rs", +"ui/const-generics/parser-error-recovery/issue-89013.rs", "ui/const-generics/type-dependent/issue-61936.rs", "ui/const-generics/type-dependent/issue-63695.rs", "ui/const-generics/type-dependent/issue-67144-1.rs", @@ -689,13 +692,13 @@ "ui/consts/const-eval/issue-91827-extern-types-field-offset.rs", "ui/consts/const-extern-fn/issue-68062-const-extern-fns-dont-need-fn-specifier-2.rs", "ui/consts/const-extern-fn/issue-68062-const-extern-fns-dont-need-fn-specifier.rs", +"ui/consts/const-mut-refs/issue-76510.rs", "ui/consts/const_in_pattern/issue-34784-match-on-non-int-raw-ptr.rs", "ui/consts/const_in_pattern/issue-44333.rs", "ui/consts/const_in_pattern/issue-53708.rs", "ui/consts/const_in_pattern/issue-62614.rs", "ui/consts/const_in_pattern/issue-65466.rs", "ui/consts/const_in_pattern/issue-73431.rs", -"ui/consts/const-mut-refs/issue-76510.rs", "ui/consts/control-flow/issue-46843.rs", "ui/consts/control-flow/issue-50577.rs", "ui/consts/extra-const-ub/issue-100771.rs", @@ -714,9 +717,9 @@ "ui/consts/issue-17074.rs", "ui/consts/issue-17458.rs", "ui/consts/issue-17718-borrow-interior.rs", -"ui/consts/issue-17718-constants-not-static.rs", "ui/consts/issue-17718-const-bad-values.rs", "ui/consts/issue-17718-const-borrow.rs", +"ui/consts/issue-17718-constants-not-static.rs", "ui/consts/issue-17718-references.rs", "ui/consts/issue-17718.rs", "ui/consts/issue-17756.rs", @@ -841,9 +844,6 @@ "ui/coroutine/issue-91477.rs", "ui/coroutine/issue-93161.rs", "ui/cross-crate/issue-64872/issue-64872.rs", -"ui/c-variadic/issue-32201.rs", -"ui/c-variadic/issue-86053-1.rs", -"ui/c-variadic/issue-86053-2.rs", "ui/cycle-trait/issue-12511.rs", "ui/debuginfo/issue-105386-debuginfo-ub.rs", "ui/deprecation/issue-66340-deprecated-attr-non-meta-grammar.rs", @@ -902,15 +902,6 @@ "ui/did_you_mean/issue-56028-there-is-an-enum-variant.rs", "ui/did_you_mean/issue-87830-try-brackets-for-arrays.rs", "ui/drop/auxiliary/issue-10028.rs", -"ui/dropck/issue-24805-dropck-itemless.rs", -"ui/dropck/issue-28498-ugeh-with-lifetime-param.rs", -"ui/dropck/issue-28498-ugeh-with-passed-to-fn.rs", -"ui/dropck/issue-28498-ugeh-with-trait-bound.rs", -"ui/dropck/issue-29844.rs", -"ui/dropck/issue-34053.rs", -"ui/dropck/issue-38868.rs", -"ui/dropck/issue-54943-1.rs", -"ui/dropck/issue-54943-2.rs", "ui/drop/issue-100276.rs", "ui/drop/issue-10028.rs", "ui/drop/issue-103107.rs", @@ -929,6 +920,15 @@ "ui/drop/issue-90752-raw-ptr-shenanigans.rs", "ui/drop/issue-90752.rs", "ui/drop/issue-979.rs", +"ui/dropck/issue-24805-dropck-itemless.rs", +"ui/dropck/issue-28498-ugeh-with-lifetime-param.rs", +"ui/dropck/issue-28498-ugeh-with-passed-to-fn.rs", +"ui/dropck/issue-28498-ugeh-with-trait-bound.rs", +"ui/dropck/issue-29844.rs", +"ui/dropck/issue-34053.rs", +"ui/dropck/issue-38868.rs", +"ui/dropck/issue-54943-1.rs", +"ui/dropck/issue-54943-2.rs", "ui/dst/issue-113447.rs", "ui/dst/issue-90528-unsizing-not-suggestion-110063.rs", "ui/dst/issue-90528-unsizing-suggestion-1.rs", @@ -1014,14 +1014,14 @@ "ui/fn/issue-3904.rs", "ui/fn/issue-39259.rs", "ui/fn/issue-80179.rs", -"ui/foreign/issue-74120-lowering-of-ffi-block-bodies.rs", -"ui/foreign/issue-91370-foreign-fn-block-impl.rs", -"ui/foreign/issue-99276-same-type-lifetimes.rs", -"ui/for/issue-20605.rs", "ui/for-loop-while/issue-1257.rs", "ui/for-loop-while/issue-2216.rs", "ui/for-loop-while/issue-51345.rs", "ui/for-loop-while/issue-69841.rs", +"ui/for/issue-20605.rs", +"ui/foreign/issue-74120-lowering-of-ffi-block-bodies.rs", +"ui/foreign/issue-91370-foreign-fn-block-impl.rs", +"ui/foreign/issue-99276-same-type-lifetimes.rs", "ui/function-pointer/issue-102289.rs", "ui/functions-closures/closure-expected-type/issue-38714.rs", "ui/generic-associated-types/bugs/issue-100013.rs", @@ -1084,8 +1084,8 @@ "ui/generic-associated-types/issue-87258_b.rs", "ui/generic-associated-types/issue-87429-2.rs", "ui/generic-associated-types/issue-87429-associated-type-default.rs", -"ui/generic-associated-types/issue-87429.rs", "ui/generic-associated-types/issue-87429-specialization.rs", +"ui/generic-associated-types/issue-87429.rs", "ui/generic-associated-types/issue-87748.rs", "ui/generic-associated-types/issue-87750.rs", "ui/generic-associated-types/issue-88287.rs", @@ -1095,9 +1095,9 @@ "ui/generic-associated-types/issue-88595.rs", "ui/generic-associated-types/issue-89008.rs", "ui/generic-associated-types/issue-89352.rs", -"ui/generic-associated-types/issue-90014.rs", -"ui/generic-associated-types/issue-90014-tait2.rs", "ui/generic-associated-types/issue-90014-tait.rs", +"ui/generic-associated-types/issue-90014-tait2.rs", +"ui/generic-associated-types/issue-90014.rs", "ui/generic-associated-types/issue-90729.rs", "ui/generic-associated-types/issue-91139.rs", "ui/generic-associated-types/issue-91883.rs", @@ -1119,8 +1119,8 @@ "ui/generics/issue-333.rs", "ui/generics/issue-59508-1.rs", "ui/generics/issue-59508.rs", -"ui/generics/issue-61631-default-type-param-cannot-reference-self.rs", "ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.rs", +"ui/generics/issue-61631-default-type-param-cannot-reference-self.rs", "ui/generics/issue-65285-incorrect-explicit-lifetime-name-needed.rs", "ui/generics/issue-79605.rs", "ui/generics/issue-80512-param-reordering-with-defaults.rs", @@ -1179,9 +1179,6 @@ "ui/hygiene/issue-47312.rs", "ui/hygiene/issue-61574-const-parameters.rs", "ui/hygiene/issue-77523-def-site-async-await.rs", -"ui/implied-bounds/issue-100690.rs", -"ui/implied-bounds/issue-101951.rs", -"ui/implied-bounds/issue-110161.rs", "ui/impl-trait/explicit-generic-args-with-impl-trait/issue-87718.rs", "ui/impl-trait/in-trait/issue-102140.rs", "ui/impl-trait/in-trait/issue-102301.rs", @@ -1261,6 +1258,9 @@ "ui/impl-trait/issues/issue-92305.rs", "ui/impl-trait/issues/issue-93788.rs", "ui/impl-trait/issues/issue-99348-impl-compatibility.rs", +"ui/implied-bounds/issue-100690.rs", +"ui/implied-bounds/issue-101951.rs", +"ui/implied-bounds/issue-110161.rs", "ui/imports/auxiliary/issue-114682-2-extern.rs", "ui/imports/auxiliary/issue-114682-3-extern.rs", "ui/imports/auxiliary/issue-114682-4-extern.rs", @@ -1368,8 +1368,8 @@ "ui/inference/need_type_info/issue-107745-avoid-expr-from-macro-expansion.rs", "ui/inference/need_type_info/issue-109905.rs", "ui/inference/need_type_info/issue-113264-incorrect-impl-trait-in-path-suggestion.rs", -"ui/infinite/issue-41731-infinite-macro-println.rs", "ui/infinite/issue-41731-infinite-macro-print.rs", +"ui/infinite/issue-41731-infinite-macro-println.rs", "ui/intrinsics/issue-28575.rs", "ui/intrinsics/issue-84297-reifying-copy.rs", "ui/invalid/issue-114435-layout-type-err.rs", @@ -1386,8 +1386,8 @@ "ui/issues/auxiliary/issue-11508.rs", "ui/issues/auxiliary/issue-11529.rs", "ui/issues/auxiliary/issue-11680.rs", -"ui/issues/auxiliary/issue-12133-dylib2.rs", "ui/issues/auxiliary/issue-12133-dylib.rs", +"ui/issues/auxiliary/issue-12133-dylib2.rs", "ui/issues/auxiliary/issue-12133-rlib.rs", "ui/issues/auxiliary/issue-12612-1.rs", "ui/issues/auxiliary/issue-12612-2.rs", @@ -1554,8 +1554,8 @@ "ui/issues/issue-13497-2.rs", "ui/issues/issue-13497.rs", "ui/issues/issue-13507-2.rs", -"ui/issues/issue-13620.rs", "ui/issues/issue-1362.rs", +"ui/issues/issue-13620.rs", "ui/issues/issue-13665.rs", "ui/issues/issue-13703.rs", "ui/issues/issue-13763.rs", @@ -1649,8 +1649,8 @@ "ui/issues/issue-16819.rs", "ui/issues/issue-16922-rpass.rs", "ui/issues/issue-16939.rs", -"ui/issues/issue-16966.rs", "ui/issues/issue-1696.rs", +"ui/issues/issue-16966.rs", "ui/issues/issue-16994.rs", "ui/issues/issue-17001.rs", "ui/issues/issue-17033.rs", @@ -1729,8 +1729,8 @@ "ui/issues/issue-18952.rs", "ui/issues/issue-18959.rs", "ui/issues/issue-18988.rs", -"ui/issues/issue-19001.rs", "ui/issues/issue-1900.rs", +"ui/issues/issue-19001.rs", "ui/issues/issue-19037.rs", "ui/issues/issue-19086.rs", "ui/issues/issue-19097.rs", @@ -1826,8 +1826,8 @@ "ui/issues/issue-21622.rs", "ui/issues/issue-21634.rs", "ui/issues/issue-21655.rs", -"ui/issues/issue-21701.rs", "ui/issues/issue-2170-exe.rs", +"ui/issues/issue-21701.rs", "ui/issues/issue-21763.rs", "ui/issues/issue-21891.rs", "ui/issues/issue-2190-1.rs", @@ -1863,15 +1863,15 @@ "ui/issues/issue-22777.rs", "ui/issues/issue-22781.rs", "ui/issues/issue-22789.rs", -"ui/issues/issue-22814.rs", "ui/issues/issue-2281-part1.rs", +"ui/issues/issue-22814.rs", "ui/issues/issue-2284.rs", "ui/issues/issue-22864-1.rs", "ui/issues/issue-22864-2.rs", "ui/issues/issue-22872.rs", "ui/issues/issue-22874.rs", -"ui/issues/issue-22886.rs", "ui/issues/issue-2288.rs", +"ui/issues/issue-22886.rs", "ui/issues/issue-22894.rs", "ui/issues/issue-22933-1.rs", "ui/issues/issue-22933-2.rs", @@ -1884,9 +1884,9 @@ "ui/issues/issue-23073.rs", "ui/issues/issue-2311-2.rs", "ui/issues/issue-2311.rs", +"ui/issues/issue-2312.rs", "ui/issues/issue-23122-1.rs", "ui/issues/issue-23122-2.rs", -"ui/issues/issue-2312.rs", "ui/issues/issue-2316-c.rs", "ui/issues/issue-23173.rs", "ui/issues/issue-23189.rs", @@ -1917,8 +1917,8 @@ "ui/issues/issue-23649-2.rs", "ui/issues/issue-23649-3.rs", "ui/issues/issue-23699.rs", -"ui/issues/issue-23808.rs", "ui/issues/issue-2380-b.rs", +"ui/issues/issue-23808.rs", "ui/issues/issue-2383.rs", "ui/issues/issue-23891.rs", "ui/issues/issue-23898.rs", @@ -1981,8 +1981,8 @@ "ui/issues/issue-25746-bool-transmute.rs", "ui/issues/issue-25757.rs", "ui/issues/issue-25810.rs", -"ui/issues/issue-25901.rs", "ui/issues/issue-2590.rs", +"ui/issues/issue-25901.rs", "ui/issues/issue-26056.rs", "ui/issues/issue-26093.rs", "ui/issues/issue-26095.rs", @@ -2041,10 +2041,10 @@ "ui/issues/issue-28433.rs", "ui/issues/issue-28472.rs", "ui/issues/issue-2848.rs", +"ui/issues/issue-2849.rs", "ui/issues/issue-28498-must-work-ex1.rs", "ui/issues/issue-28498-must-work-ex2.rs", "ui/issues/issue-28498-ugeh-ex1.rs", -"ui/issues/issue-2849.rs", "ui/issues/issue-28550.rs", "ui/issues/issue-28561.rs", "ui/issues/issue-28568.rs", @@ -2062,8 +2062,8 @@ "ui/issues/issue-28999.rs", "ui/issues/issue-29030.rs", "ui/issues/issue-29037.rs", -"ui/issues/issue-29048.rs", "ui/issues/issue-2904.rs", +"ui/issues/issue-29048.rs", "ui/issues/issue-29053.rs", "ui/issues/issue-29071-2.rs", "ui/issues/issue-29071.rs", @@ -2075,8 +2075,8 @@ "ui/issues/issue-2935.rs", "ui/issues/issue-29466.rs", "ui/issues/issue-29485.rs", -"ui/issues/issue-29516.rs", "ui/issues/issue-2951.rs", +"ui/issues/issue-29516.rs", "ui/issues/issue-29522.rs", "ui/issues/issue-29540.rs", "ui/issues/issue-29663.rs", @@ -2101,10 +2101,10 @@ "ui/issues/issue-30255.rs", "ui/issues/issue-3026.rs", "ui/issues/issue-3029.rs", -"ui/issues/issue-30371.rs", "ui/issues/issue-3037.rs", -"ui/issues/issue-30380.rs", +"ui/issues/issue-30371.rs", "ui/issues/issue-3038.rs", +"ui/issues/issue-30380.rs", "ui/issues/issue-3052.rs", "ui/issues/issue-30530.rs", "ui/issues/issue-30589.rs", @@ -2226,8 +2226,8 @@ "ui/issues/issue-37131.rs", "ui/issues/issue-37311-type-length-limit/issue-37311.rs", "ui/issues/issue-37510.rs", -"ui/issues/issue-37534.rs", "ui/issues/issue-3753.rs", +"ui/issues/issue-37534.rs", "ui/issues/issue-37576.rs", "ui/issues/issue-3763.rs", "ui/issues/issue-37665.rs", @@ -2254,8 +2254,8 @@ "ui/issues/issue-3888-2.rs", "ui/issues/issue-38919.rs", "ui/issues/issue-38942.rs", -"ui/issues/issue-38954.rs", "ui/issues/issue-3895.rs", +"ui/issues/issue-38954.rs", "ui/issues/issue-38987.rs", "ui/issues/issue-39089.rs", "ui/issues/issue-39175.rs", @@ -2265,8 +2265,8 @@ "ui/issues/issue-39687.rs", "ui/issues/issue-39709.rs", "ui/issues/issue-3979-2.rs", -"ui/issues/issue-3979.rs", "ui/issues/issue-3979-xcrate.rs", +"ui/issues/issue-3979.rs", "ui/issues/issue-39808.rs", "ui/issues/issue-39827.rs", "ui/issues/issue-39848.rs", @@ -2341,9 +2341,9 @@ "ui/issues/issue-43250.rs", "ui/issues/issue-43291.rs", "ui/issues/issue-4333.rs", +"ui/issues/issue-4335.rs", "ui/issues/issue-43355.rs", "ui/issues/issue-43357.rs", -"ui/issues/issue-4335.rs", "ui/issues/issue-43420-no-over-suggest.rs", "ui/issues/issue-43424.rs", "ui/issues/issue-43431.rs", @@ -2372,8 +2372,8 @@ "ui/issues/issue-44851.rs", "ui/issues/issue-4517.rs", "ui/issues/issue-4541.rs", -"ui/issues/issue-45425.rs", "ui/issues/issue-4542.rs", +"ui/issues/issue-45425.rs", "ui/issues/issue-4545.rs", "ui/issues/issue-45510.rs", "ui/issues/issue-45562.rs", @@ -2402,8 +2402,8 @@ "ui/issues/issue-47309.rs", "ui/issues/issue-4734.rs", "ui/issues/issue-4735.rs", -"ui/issues/issue-47364.rs", "ui/issues/issue-4736.rs", +"ui/issues/issue-47364.rs", "ui/issues/issue-47377.rs", "ui/issues/issue-47380.rs", "ui/issues/issue-47486.rs", @@ -2412,8 +2412,8 @@ "ui/issues/issue-47638.rs", "ui/issues/issue-47673.rs", "ui/issues/issue-47703-1.rs", -"ui/issues/issue-47703.rs", "ui/issues/issue-47703-tuple.rs", +"ui/issues/issue-47703.rs", "ui/issues/issue-47715.rs", "ui/issues/issue-47722.rs", "ui/issues/issue-48006.rs", @@ -2561,8 +2561,8 @@ "ui/issues/issue-59756.rs", "ui/issues/issue-5988.rs", "ui/issues/issue-5997-outer-generic-parameter/issue-5997-enum.rs", -"ui/issues/issue-5997-outer-generic-parameter/issue-5997.rs", "ui/issues/issue-5997-outer-generic-parameter/issue-5997-struct.rs", +"ui/issues/issue-5997-outer-generic-parameter/issue-5997.rs", "ui/issues/issue-60218.rs", "ui/issues/issue-60622.rs", "ui/issues/issue-60989.rs", @@ -2837,8 +2837,8 @@ "ui/lint/unused/issue-103320-must-use-ops.rs", "ui/lint/unused/issue-104397.rs", "ui/lint/unused/issue-105061-array-lint.rs", -"ui/lint/unused/issue-105061.rs", "ui/lint/unused/issue-105061-should-lint.rs", +"ui/lint/unused/issue-105061.rs", "ui/lint/unused/issue-117142-invalid-remove-parens.rs", "ui/lint/unused/issue-117284-arg-in-macro.rs", "ui/lint/unused/issue-119383-if-let-guard.rs", @@ -2862,8 +2862,8 @@ "ui/lint/use-redundant/issue-92904.rs", "ui/loops/issue-43162.rs", "ui/loops/issue-50576.rs", -"ui/loops/issue-69225-layout-repeated-checked-add.rs", "ui/loops/issue-69225-SCEVAddExpr-wrap-flag.rs", +"ui/loops/issue-69225-layout-repeated-checked-add.rs", "ui/loops/issue-82916.rs", "ui/lowering/issue-121108.rs", "ui/lowering/issue-96847.rs", @@ -3016,7 +3016,6 @@ "ui/mir/issue-29227.rs", "ui/mir/issue-46845.rs", "ui/mir/issue-60390.rs", -"ui/mir/issue66339.rs", "ui/mir/issue-66851.rs", "ui/mir/issue-66930.rs", "ui/mir/issue-67639-normalization-ice.rs", @@ -3043,6 +3042,7 @@ "ui/mir/issue-92893.rs", "ui/mir/issue-99852.rs", "ui/mir/issue-99866.rs", +"ui/mir/issue66339.rs", "ui/mir/validate/issue-95978-validator-lifetime-comparison.rs", "ui/mismatched_types/issue-106182.rs", "ui/mismatched_types/issue-112036.rs", @@ -3053,10 +3053,10 @@ "ui/mismatched_types/issue-26480.rs", "ui/mismatched_types/issue-35030.rs", "ui/mismatched_types/issue-36053-2.rs", -"ui/mismatched_types/issue-38371.rs", "ui/mismatched_types/issue-38371-unfixable.rs", -"ui/mismatched_types/issue-47706.rs", +"ui/mismatched_types/issue-38371.rs", "ui/mismatched_types/issue-47706-trait.rs", +"ui/mismatched_types/issue-47706.rs", "ui/mismatched_types/issue-74918-missing-lifetime.rs", "ui/mismatched_types/issue-75361-mismatched-impl.rs", "ui/mismatched_types/issue-84976.rs", @@ -3414,8 +3414,8 @@ "ui/parser/issues/issue-73568-lifetime-after-mut.rs", "ui/parser/issues/issue-75599.rs", "ui/parser/issues/issue-76437-async.rs", -"ui/parser/issues/issue-76437-const-async.rs", "ui/parser/issues/issue-76437-const-async-unsafe.rs", +"ui/parser/issues/issue-76437-const-async.rs", "ui/parser/issues/issue-76437-const.rs", "ui/parser/issues/issue-76437-pub-crate-unsafe.rs", "ui/parser/issues/issue-76437-unsafe.rs", @@ -3561,16 +3561,10 @@ "ui/privacy/issue-57264-2.rs", "ui/privacy/issue-75062-fieldless-tuple-struct.rs", "ui/privacy/issue-75906.rs", -"ui/privacy/issue-75907_b.rs", "ui/privacy/issue-75907.rs", +"ui/privacy/issue-75907_b.rs", "ui/privacy/issue-79593.rs", "ui/privacy/issue-92755.rs", -"ui/process/issue-13304.rs", -"ui/process/issue-14456.rs", -"ui/process/issue-14940.rs", -"ui/process/issue-16272.rs", -"ui/process/issue-20091.rs", -"ui/process/issue-30490.rs", "ui/proc-macro/auxiliary/issue-104884.rs", "ui/proc-macro/auxiliary/issue-107113.rs", "ui/proc-macro/auxiliary/issue-118809.rs", @@ -3619,8 +3613,14 @@ "ui/proc-macro/issue-86781-bad-inner-doc.rs", "ui/proc-macro/issue-89566-suggest-fix-invalid-top-level-macro-attr.rs", "ui/proc-macro/issue-91800.rs", -"ui/ptr_ops/issue-80309.rs", +"ui/process/issue-13304.rs", +"ui/process/issue-14456.rs", +"ui/process/issue-14940.rs", +"ui/process/issue-16272.rs", +"ui/process/issue-20091.rs", +"ui/process/issue-30490.rs", "ui/ptr_ops/issue-80309-safe.rs", +"ui/ptr_ops/issue-80309.rs", "ui/pub/issue-33174-restricted-type-in-public-interface.rs", "ui/query-system/issue-83479.rs", "ui/range/issue-54505-no-literals.rs", @@ -3698,8 +3698,8 @@ "ui/resolve/issue-21221-3.rs", "ui/resolve/issue-21221-4.rs", "ui/resolve/issue-22692.rs", -"ui/resolve/issue-23305.rs", "ui/resolve/issue-2330.rs", +"ui/resolve/issue-23305.rs", "ui/resolve/issue-2356.rs", "ui/resolve/issue-23716.rs", "ui/resolve/issue-24968.rs", @@ -3820,10 +3820,6 @@ "ui/span/issue-25199.rs", "ui/span/issue-26656.rs", "ui/span/issue-27522.rs", -"ui/span/issue28498-reject-ex1.rs", -"ui/span/issue28498-reject-lifetime-param.rs", -"ui/span/issue28498-reject-passed-to-fn.rs", -"ui/span/issue28498-reject-trait-bound.rs", "ui/span/issue-29106.rs", "ui/span/issue-29595.rs", "ui/span/issue-33884.rs", @@ -3838,6 +3834,10 @@ "ui/span/issue-43927-non-ADT-derive.rs", "ui/span/issue-71363.rs", "ui/span/issue-81800.rs", +"ui/span/issue28498-reject-ex1.rs", +"ui/span/issue28498-reject-lifetime-param.rs", +"ui/span/issue28498-reject-passed-to-fn.rs", +"ui/span/issue28498-reject-trait-bound.rs", "ui/specialization/issue-111232.rs", "ui/specialization/issue-33017.rs", "ui/specialization/issue-35376.rs", @@ -4124,8 +4124,8 @@ "ui/traits/object/issue-44454-3.rs", "ui/traits/suggest-dereferences/issue-39029.rs", "ui/traits/suggest-dereferences/issue-62530.rs", -"ui/traits/trait-upcasting/issue-11515.rs", "ui/traits/trait-upcasting/issue-11515-upcast-fn_mut-fn.rs", +"ui/traits/trait-upcasting/issue-11515.rs", "ui/traits/vtable/issue-91807.rs", "ui/traits/vtable/issue-97381.rs", "ui/transmutability/arrays/issue-103783-array-length.rs", @@ -4163,8 +4163,8 @@ "ui/type-alias-impl-trait/issue-58951.rs", "ui/type-alias-impl-trait/issue-60371.rs", "ui/type-alias-impl-trait/issue-60407.rs", -"ui/type-alias-impl-trait/issue-60564.rs", "ui/type-alias-impl-trait/issue-60564-working.rs", +"ui/type-alias-impl-trait/issue-60564.rs", "ui/type-alias-impl-trait/issue-60662.rs", "ui/type-alias-impl-trait/issue-62000-associate-impl-trait-lifetimes.rs", "ui/type-alias-impl-trait/issue-63263-closure-return.rs", @@ -4208,10 +4208,26 @@ "ui/type-alias/issue-62263-self-in-atb.rs", "ui/type-alias/issue-62305-self-assoc-ty.rs", "ui/type-alias/issue-62364-self-ty-arg.rs", +"ui/type-inference/issue-113283-alllocator-trait-eq.rs", +"ui/type-inference/issue-30225.rs", "ui/type/ascription/issue-34255-1.rs", "ui/type/ascription/issue-47666.rs", "ui/type/ascription/issue-54516.rs", "ui/type/ascription/issue-60933.rs", +"ui/type/issue-100584.rs", +"ui/type/issue-101866.rs", +"ui/type/issue-102598.rs", +"ui/type/issue-103271.rs", +"ui/type/issue-58355.rs", +"ui/type/issue-67690-type-alias-bound-diagnostic-crash.rs", +"ui/type/issue-91268.rs", +"ui/type/issue-94187-verbose-type-name.rs", +"ui/type/type-check/issue-116967-cannot-coerce-returned-result.rs", +"ui/type/type-check/issue-22897.rs", +"ui/type/type-check/issue-40294.rs", +"ui/type/type-check/issue-41314.rs", +"ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.rs", +"ui/type/type-check/issue-88577-check-fn-with-more-than-65535-arguments.rs", "ui/typeck/auxiliary/issue-29181.rs", "ui/typeck/auxiliary/issue-36708.rs", "ui/typeck/auxiliary/issue-81943-lib.rs", @@ -4316,25 +4332,9 @@ "ui/typeck/issue-96738.rs", "ui/typeck/issue-98260.rs", "ui/typeck/issue-98982.rs", -"ui/type-inference/issue-113283-alllocator-trait-eq.rs", -"ui/type-inference/issue-30225.rs", -"ui/type/issue-100584.rs", -"ui/type/issue-101866.rs", -"ui/type/issue-102598.rs", -"ui/type/issue-103271.rs", -"ui/type/issue-58355.rs", -"ui/type/issue-67690-type-alias-bound-diagnostic-crash.rs", -"ui/type/issue-91268.rs", -"ui/type/issue-94187-verbose-type-name.rs", "ui/typeof/issue-100183.rs", "ui/typeof/issue-29184.rs", "ui/typeof/issue-42060.rs", -"ui/type/type-check/issue-116967-cannot-coerce-returned-result.rs", -"ui/type/type-check/issue-22897.rs", -"ui/type/type-check/issue-40294.rs", -"ui/type/type-check/issue-41314.rs", -"ui/type/type-check/issue-67273-assignment-match-prior-arm-bool-expected-unit.rs", -"ui/type/type-check/issue-88577-check-fn-with-more-than-65535-arguments.rs", "ui/unboxed-closures/issue-18652.rs", "ui/unboxed-closures/issue-18661.rs", "ui/unboxed-closures/issue-30906.rs", @@ -4355,6 +4355,11 @@ "ui/unsafe/issue-47412.rs", "ui/unsafe/issue-85435-unsafe-op-in-let-under-unsafe-under-closure.rs", "ui/unsafe/issue-87414-query-cycle.rs", +"ui/unsized-locals/issue-30276-feature-flagged.rs", +"ui/unsized-locals/issue-30276.rs", +"ui/unsized-locals/issue-50940-with-feature.rs", +"ui/unsized-locals/issue-50940.rs", +"ui/unsized-locals/issue-67981.rs", "ui/unsized/issue-115203.rs", "ui/unsized/issue-115809.rs", "ui/unsized/issue-30355.rs", @@ -4367,11 +4372,6 @@ "ui/unsized/issue-91801.rs", "ui/unsized/issue-91803.rs", "ui/unsized/issue-97732.rs", -"ui/unsized-locals/issue-30276-feature-flagged.rs", -"ui/unsized-locals/issue-30276.rs", -"ui/unsized-locals/issue-50940.rs", -"ui/unsized-locals/issue-50940-with-feature.rs", -"ui/unsized-locals/issue-67981.rs", "ui/use/issue-18986.rs", "ui/use/issue-60976-extern-use-primitive-type.rs", "ui/wf/issue-103573.rs", diff --git a/tests/ui/parser/typed-self-param.rs b/tests/ui/parser/typed-self-param.rs new file mode 100644 index 0000000000000..e3d85ab891b5b --- /dev/null +++ b/tests/ui/parser/typed-self-param.rs @@ -0,0 +1,14 @@ +struct S; + +impl S { + fn a(&self: Self) {} + //~^ ERROR type not allowed for shorthand `self` parameter + fn b(&mut self: Self) {} + //~^ ERROR type not allowed for shorthand `self` parameter + fn c<'c>(&'c mut self: Self) {} + //~^ ERROR type not allowed for shorthand `self` parameter + fn d<'d>(&'d self: Self) {} + //~^ ERROR type not allowed for shorthand `self` parameter +} + +fn main() {} diff --git a/tests/ui/parser/typed-self-param.stderr b/tests/ui/parser/typed-self-param.stderr new file mode 100644 index 0000000000000..c1ecd3b7fef43 --- /dev/null +++ b/tests/ui/parser/typed-self-param.stderr @@ -0,0 +1,50 @@ +error: type not allowed for shorthand `self` parameter + --> $DIR/typed-self-param.rs:4:17 + | +LL | fn a(&self: Self) {} + | ^^^^ + | +help: move the modifiers on `self` to the type + | +LL - fn a(&self: Self) {} +LL + fn a(self: &Self) {} + | + +error: type not allowed for shorthand `self` parameter + --> $DIR/typed-self-param.rs:6:21 + | +LL | fn b(&mut self: Self) {} + | ^^^^ + | +help: move the modifiers on `self` to the type + | +LL - fn b(&mut self: Self) {} +LL + fn b(self: &mut Self) {} + | + +error: type not allowed for shorthand `self` parameter + --> $DIR/typed-self-param.rs:8:28 + | +LL | fn c<'c>(&'c mut self: Self) {} + | ^^^^ + | +help: move the modifiers on `self` to the type + | +LL - fn c<'c>(&'c mut self: Self) {} +LL + fn c<'c>(self: &'c mut Self) {} + | + +error: type not allowed for shorthand `self` parameter + --> $DIR/typed-self-param.rs:10:24 + | +LL | fn d<'d>(&'d self: Self) {} + | ^^^^ + | +help: move the modifiers on `self` to the type + | +LL - fn d<'d>(&'d self: Self) {} +LL + fn d<'d>(self: &'d Self) {} + | + +error: aborting due to 4 previous errors +