1
Fork 0

Tweak wording of missing angle backets in qualified path

This commit is contained in:
Esteban Küber 2023-09-28 00:37:20 +00:00
parent 5899a80ae6
commit 3848ffcee7
7 changed files with 162 additions and 32 deletions

View file

@ -509,7 +509,7 @@ parse_maybe_fn_typo_with_impl = you might have meant to write `impl` instead of
parse_maybe_recover_from_bad_qpath_stage_2 = parse_maybe_recover_from_bad_qpath_stage_2 =
missing angle brackets in associated item path missing angle brackets in associated item path
.suggestion = try: `{$ty}` .suggestion = types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
parse_maybe_recover_from_bad_type_plus = parse_maybe_recover_from_bad_type_plus =
expected a path on the left-hand side of `+`, not `{$ty}` expected a path on the left-hand side of `+`, not `{$ty}`

View file

@ -59,9 +59,18 @@ pub(crate) enum BadTypePlusSub {
#[diag(parse_maybe_recover_from_bad_qpath_stage_2)] #[diag(parse_maybe_recover_from_bad_qpath_stage_2)]
pub(crate) struct BadQPathStage2 { pub(crate) struct BadQPathStage2 {
#[primary_span] #[primary_span]
#[suggestion(code = "", applicability = "maybe-incorrect")]
pub span: Span, pub span: Span,
pub ty: String, #[subdiagnostic]
pub wrap: WrapType,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")]
pub(crate) struct WrapType {
#[suggestion_part(code = "<")]
pub lo: Span,
#[suggestion_part(code = ">")]
pub hi: Span,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]

View file

@ -16,7 +16,7 @@ use crate::errors::{
StructLiteralBodyWithoutPath, StructLiteralBodyWithoutPathSugg, StructLiteralNeedingParens, StructLiteralBodyWithoutPath, StructLiteralBodyWithoutPathSugg, StructLiteralNeedingParens,
StructLiteralNeedingParensSugg, SuggAddMissingLetStmt, SuggEscapeIdentifier, SuggRemoveComma, StructLiteralNeedingParensSugg, SuggAddMissingLetStmt, SuggEscapeIdentifier, SuggRemoveComma,
TernaryOperator, UnexpectedConstInGenericParam, UnexpectedConstParamDeclaration, TernaryOperator, UnexpectedConstInGenericParam, UnexpectedConstParamDeclaration,
UnexpectedConstParamDeclarationSugg, UnmatchedAngleBrackets, UseEqInstead, UnexpectedConstParamDeclarationSugg, UnmatchedAngleBrackets, UseEqInstead, WrapType,
}; };
use crate::fluent_generated as fluent; use crate::fluent_generated as fluent;
@ -1589,10 +1589,9 @@ impl<'a> Parser<'a> {
self.parse_path_segments(&mut path.segments, T::PATH_STYLE, None)?; self.parse_path_segments(&mut path.segments, T::PATH_STYLE, None)?;
path.span = ty_span.to(self.prev_token.span); path.span = ty_span.to(self.prev_token.span);
let ty_str = self.span_to_snippet(ty_span).unwrap_or_else(|_| pprust::ty_to_string(&ty));
self.sess.emit_err(BadQPathStage2 { self.sess.emit_err(BadQPathStage2 {
span: path.span, span: ty_span,
ty: format!("<{}>::{}", ty_str, pprust::path_to_string(&path)), wrap: WrapType { lo: ty_span.shrink_to_lo(), hi: ty_span.shrink_to_hi() },
}); });
let path_span = ty_span.shrink_to_hi(); // Use an empty path since `position == 0`. let path_span = ty_span.shrink_to_hi(); // Use an empty path since `position == 0`.

View file

@ -2,60 +2,104 @@ error: missing angle brackets in associated item path
--> $DIR/bad-assoc-expr.rs:3:5 --> $DIR/bad-assoc-expr.rs:3:5
| |
LL | [i32; 4]::clone(&a); LL | [i32; 4]::clone(&a);
| ^^^^^^^^^^^^^^^ help: try: `<[i32; 4]>::clone` | ^^^^^^^^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | <[i32; 4]>::clone(&a);
| + +
error: missing angle brackets in associated item path error: missing angle brackets in associated item path
--> $DIR/bad-assoc-expr.rs:6:5 --> $DIR/bad-assoc-expr.rs:6:5
| |
LL | [i32]::as_ref(&a); LL | [i32]::as_ref(&a);
| ^^^^^^^^^^^^^ help: try: `<[i32]>::as_ref` | ^^^^^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | <[i32]>::as_ref(&a);
| + +
error: missing angle brackets in associated item path error: missing angle brackets in associated item path
--> $DIR/bad-assoc-expr.rs:9:5 --> $DIR/bad-assoc-expr.rs:9:5
| |
LL | (u8)::clone(&0); LL | (u8)::clone(&0);
| ^^^^^^^^^^^ help: try: `<(u8)>::clone` | ^^^^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | <(u8)>::clone(&0);
| + +
error: missing angle brackets in associated item path error: missing angle brackets in associated item path
--> $DIR/bad-assoc-expr.rs:12:5 --> $DIR/bad-assoc-expr.rs:12:5
| |
LL | (u8, u8)::clone(&(0, 0)); LL | (u8, u8)::clone(&(0, 0));
| ^^^^^^^^^^^^^^^ help: try: `<(u8, u8)>::clone` | ^^^^^^^^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | <(u8, u8)>::clone(&(0, 0));
| + +
error: missing angle brackets in associated item path error: missing angle brackets in associated item path
--> $DIR/bad-assoc-expr.rs:15:6 --> $DIR/bad-assoc-expr.rs:15:6
| |
LL | &(u8)::clone(&0); LL | &(u8)::clone(&0);
| ^^^^^^^^^^^ help: try: `<(u8)>::clone` | ^^^^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | &<(u8)>::clone(&0);
| + +
error: missing angle brackets in associated item path error: missing angle brackets in associated item path
--> $DIR/bad-assoc-expr.rs:18:10 --> $DIR/bad-assoc-expr.rs:18:10
| |
LL | 10 + (u8)::clone(&0); LL | 10 + (u8)::clone(&0);
| ^^^^^^^^^^^ help: try: `<(u8)>::clone` | ^^^^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | 10 + <(u8)>::clone(&0);
| + +
error: missing angle brackets in associated item path error: missing angle brackets in associated item path
--> $DIR/bad-assoc-expr.rs:32:13 --> $DIR/bad-assoc-expr.rs:32:13
| |
LL | let _ = ty!()::clone(&0); LL | let _ = ty!()::clone(&0);
| ^^^^^^^^^^^^ help: try: `<ty!()>::clone` | ^^^^^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | let _ = <ty!()>::clone(&0);
| + +
error: missing angle brackets in associated item path error: missing angle brackets in associated item path
--> $DIR/bad-assoc-expr.rs:34:5 --> $DIR/bad-assoc-expr.rs:34:5
| |
LL | ty!()::clone(&0); LL | ty!()::clone(&0);
| ^^^^^^^^^^^^ help: try: `<ty!()>::clone` | ^^^^^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | <ty!()>::clone(&0);
| + +
error: missing angle brackets in associated item path error: missing angle brackets in associated item path
--> $DIR/bad-assoc-expr.rs:23:19 --> $DIR/bad-assoc-expr.rs:23:19
| |
LL | ($ty: ty) => ($ty::clone(&0)) LL | ($ty: ty) => ($ty::clone(&0))
| ^^^^^^^^^^ help: try: `<$ty>::clone` | ^^^
... ...
LL | expr!(u8); LL | expr!(u8);
| --------- in this macro invocation | --------- in this macro invocation
| |
= note: this error originates in the macro `expr` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `expr` (in Nightly builds, run with -Z macro-backtrace for more info)
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | ($ty: ty) => (<$ty>::clone(&0))
| + +
error: aborting due to 9 previous errors error: aborting due to 9 previous errors

View file

@ -2,42 +2,71 @@ error: missing angle brackets in associated item path
--> $DIR/bad-assoc-pat.rs:3:9 --> $DIR/bad-assoc-pat.rs:3:9
| |
LL | [u8]::AssocItem => {} LL | [u8]::AssocItem => {}
| ^^^^^^^^^^^^^^^ help: try: `<[u8]>::AssocItem` | ^^^^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | <[u8]>::AssocItem => {}
| + +
error: missing angle brackets in associated item path error: missing angle brackets in associated item path
--> $DIR/bad-assoc-pat.rs:6:9 --> $DIR/bad-assoc-pat.rs:6:9
| |
LL | (u8, u8)::AssocItem => {} LL | (u8, u8)::AssocItem => {}
| ^^^^^^^^^^^^^^^^^^^ help: try: `<(u8, u8)>::AssocItem` | ^^^^^^^^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | <(u8, u8)>::AssocItem => {}
| + +
error: missing angle brackets in associated item path error: missing angle brackets in associated item path
--> $DIR/bad-assoc-pat.rs:9:9 --> $DIR/bad-assoc-pat.rs:9:9
| |
LL | _::AssocItem => {} LL | _::AssocItem => {}
| ^^^^^^^^^^^^ help: try: `<_>::AssocItem` | ^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | <_>::AssocItem => {}
| + +
error: missing angle brackets in associated item path error: missing angle brackets in associated item path
--> $DIR/bad-assoc-pat.rs:14:10 --> $DIR/bad-assoc-pat.rs:14:10
| |
LL | &(u8,)::AssocItem => {} LL | &(u8,)::AssocItem => {}
| ^^^^^^^^^^^^^^^^ help: try: `<(u8,)>::AssocItem` | ^^^^^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | &<(u8,)>::AssocItem => {}
| + +
error: missing angle brackets in associated item path error: missing angle brackets in associated item path
--> $DIR/bad-assoc-pat.rs:32:9 --> $DIR/bad-assoc-pat.rs:32:9
| |
LL | ty!()::AssocItem => {} LL | ty!()::AssocItem => {}
| ^^^^^^^^^^^^^^^^ help: try: `<ty!()>::AssocItem` | ^^^^^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | <ty!()>::AssocItem => {}
| + +
error: missing angle brackets in associated item path error: missing angle brackets in associated item path
--> $DIR/bad-assoc-pat.rs:21:19 --> $DIR/bad-assoc-pat.rs:21:19
| |
LL | ($ty: ty) => ($ty::AssocItem) LL | ($ty: ty) => ($ty::AssocItem)
| ^^^^^^^^^^^^^^ help: try: `<$ty>::AssocItem` | ^^^
... ...
LL | pat!(u8) => {} LL | pat!(u8) => {}
| -------- in this macro invocation | -------- in this macro invocation
| |
= note: this error originates in the macro `pat` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `pat` (in Nightly builds, run with -Z macro-backtrace for more info)
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | ($ty: ty) => (<$ty>::AssocItem)
| + +
error[E0599]: no associated item named `AssocItem` found for slice `[u8]` in the current scope error[E0599]: no associated item named `AssocItem` found for slice `[u8]` in the current scope
--> $DIR/bad-assoc-pat.rs:3:15 --> $DIR/bad-assoc-pat.rs:3:15

View file

@ -2,60 +2,104 @@ error: missing angle brackets in associated item path
--> $DIR/bad-assoc-ty.rs:1:10 --> $DIR/bad-assoc-ty.rs:1:10
| |
LL | type A = [u8; 4]::AssocTy; LL | type A = [u8; 4]::AssocTy;
| ^^^^^^^^^^^^^^^^ help: try: `<[u8; 4]>::AssocTy` | ^^^^^^^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | type A = <[u8; 4]>::AssocTy;
| + +
error: missing angle brackets in associated item path error: missing angle brackets in associated item path
--> $DIR/bad-assoc-ty.rs:5:10 --> $DIR/bad-assoc-ty.rs:5:10
| |
LL | type B = [u8]::AssocTy; LL | type B = [u8]::AssocTy;
| ^^^^^^^^^^^^^ help: try: `<[u8]>::AssocTy` | ^^^^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | type B = <[u8]>::AssocTy;
| + +
error: missing angle brackets in associated item path error: missing angle brackets in associated item path
--> $DIR/bad-assoc-ty.rs:9:10 --> $DIR/bad-assoc-ty.rs:9:10
| |
LL | type C = (u8)::AssocTy; LL | type C = (u8)::AssocTy;
| ^^^^^^^^^^^^^ help: try: `<(u8)>::AssocTy` | ^^^^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | type C = <(u8)>::AssocTy;
| + +
error: missing angle brackets in associated item path error: missing angle brackets in associated item path
--> $DIR/bad-assoc-ty.rs:13:10 --> $DIR/bad-assoc-ty.rs:13:10
| |
LL | type D = (u8, u8)::AssocTy; LL | type D = (u8, u8)::AssocTy;
| ^^^^^^^^^^^^^^^^^ help: try: `<(u8, u8)>::AssocTy` | ^^^^^^^^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | type D = <(u8, u8)>::AssocTy;
| + +
error: missing angle brackets in associated item path error: missing angle brackets in associated item path
--> $DIR/bad-assoc-ty.rs:17:10 --> $DIR/bad-assoc-ty.rs:17:10
| |
LL | type E = _::AssocTy; LL | type E = _::AssocTy;
| ^^^^^^^^^^ help: try: `<_>::AssocTy` | ^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | type E = <_>::AssocTy;
| + +
error: missing angle brackets in associated item path error: missing angle brackets in associated item path
--> $DIR/bad-assoc-ty.rs:21:19 --> $DIR/bad-assoc-ty.rs:21:19
| |
LL | type F = &'static (u8)::AssocTy; LL | type F = &'static (u8)::AssocTy;
| ^^^^^^^^^^^^^ help: try: `<(u8)>::AssocTy` | ^^^^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | type F = &'static <(u8)>::AssocTy;
| + +
error: missing angle brackets in associated item path error: missing angle brackets in associated item path
--> $DIR/bad-assoc-ty.rs:27:10 --> $DIR/bad-assoc-ty.rs:27:10
| |
LL | type G = dyn 'static + (Send)::AssocTy; LL | type G = dyn 'static + (Send)::AssocTy;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `<dyn 'static + (Send)>::AssocTy` | ^^^^^^^^^^^^^^^^^^^^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | type G = <dyn 'static + (Send)>::AssocTy;
| + +
error: missing angle brackets in associated item path error: missing angle brackets in associated item path
--> $DIR/bad-assoc-ty.rs:46:10 --> $DIR/bad-assoc-ty.rs:46:10
| |
LL | type I = ty!()::AssocTy; LL | type I = ty!()::AssocTy;
| ^^^^^^^^^^^^^^ help: try: `<ty!()>::AssocTy` | ^^^^^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | type I = <ty!()>::AssocTy;
| + +
error: missing angle brackets in associated item path error: missing angle brackets in associated item path
--> $DIR/bad-assoc-ty.rs:39:19 --> $DIR/bad-assoc-ty.rs:39:19
| |
LL | ($ty: ty) => ($ty::AssocTy); LL | ($ty: ty) => ($ty::AssocTy);
| ^^^^^^^^^^^^ help: try: `<$ty>::AssocTy` | ^^^
... ...
LL | type J = ty!(u8); LL | type J = ty!(u8);
| ------- in this macro invocation | ------- in this macro invocation
| |
= note: this error originates in the macro `ty` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `ty` (in Nightly builds, run with -Z macro-backtrace for more info)
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | ($ty: ty) => (<$ty>::AssocTy);
| + +
error[E0223]: ambiguous associated type error[E0223]: ambiguous associated type
--> $DIR/bad-assoc-ty.rs:1:10 --> $DIR/bad-assoc-ty.rs:1:10

View file

@ -2,7 +2,12 @@ error: missing angle brackets in associated item path
--> $DIR/issue-89388.rs:5:24 --> $DIR/issue-89388.rs:5:24
| |
LL | let _ = option.map([_]::to_vec); LL | let _ = option.map([_]::to_vec);
| ^^^^^^^^^^^ help: try: `<[_]>::to_vec` | ^^^
|
help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths
|
LL | let _ = option.map(<[_]>::to_vec);
| + +
error: aborting due to previous error error: aborting due to previous error