Rollup merge of #116215 - estebank:parse-type-angle-bracket-tweak, r=compiler-errors

Tweak wording of missing angle backets in qualified path
This commit is contained in:
Matthias Krüger 2023-09-28 09:14:07 +02:00 committed by GitHub
commit 86d5939aba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 =
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 =
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)]
pub(crate) struct BadQPathStage2 {
#[primary_span]
#[suggestion(code = "", applicability = "maybe-incorrect")]
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)]

View File

@ -16,7 +16,7 @@ use crate::errors::{
StructLiteralBodyWithoutPath, StructLiteralBodyWithoutPathSugg, StructLiteralNeedingParens,
StructLiteralNeedingParensSugg, SuggAddMissingLetStmt, SuggEscapeIdentifier, SuggRemoveComma,
TernaryOperator, UnexpectedConstInGenericParam, UnexpectedConstParamDeclaration,
UnexpectedConstParamDeclarationSugg, UnmatchedAngleBrackets, UseEqInstead,
UnexpectedConstParamDeclarationSugg, UnmatchedAngleBrackets, UseEqInstead, WrapType,
};
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)?;
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 {
span: path.span,
ty: format!("<{}>::{}", ty_str, pprust::path_to_string(&path)),
span: ty_span,
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`.

View File

@ -2,60 +2,104 @@ error: missing angle brackets in associated item path
--> $DIR/bad-assoc-expr.rs:3:5
|
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
--> $DIR/bad-assoc-expr.rs:6:5
|
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
--> $DIR/bad-assoc-expr.rs:9:5
|
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
--> $DIR/bad-assoc-expr.rs:12:5
|
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
--> $DIR/bad-assoc-expr.rs:15:6
|
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
--> $DIR/bad-assoc-expr.rs:18:10
|
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
--> $DIR/bad-assoc-expr.rs:32:13
|
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
--> $DIR/bad-assoc-expr.rs:34:5
|
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
--> $DIR/bad-assoc-expr.rs:23:19
|
LL | ($ty: ty) => ($ty::clone(&0))
| ^^^^^^^^^^ help: try: `<$ty>::clone`
| ^^^
...
LL | expr!(u8);
| --------- in this macro invocation
|
= 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

View File

@ -2,42 +2,71 @@ error: missing angle brackets in associated item path
--> $DIR/bad-assoc-pat.rs:3:9
|
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
--> $DIR/bad-assoc-pat.rs:6:9
|
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
--> $DIR/bad-assoc-pat.rs:9:9
|
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
--> $DIR/bad-assoc-pat.rs:14:10
|
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
--> $DIR/bad-assoc-pat.rs:32:9
|
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
--> $DIR/bad-assoc-pat.rs:21:19
|
LL | ($ty: ty) => ($ty::AssocItem)
| ^^^^^^^^^^^^^^ help: try: `<$ty>::AssocItem`
| ^^^
...
LL | pat!(u8) => {}
| -------- in this macro invocation
|
= 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
--> $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
|
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
--> $DIR/bad-assoc-ty.rs:5:10
|
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
--> $DIR/bad-assoc-ty.rs:9:10
|
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
--> $DIR/bad-assoc-ty.rs:13:10
|
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
--> $DIR/bad-assoc-ty.rs:17:10
|
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
--> $DIR/bad-assoc-ty.rs:21:19
|
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
--> $DIR/bad-assoc-ty.rs:27:10
|
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
--> $DIR/bad-assoc-ty.rs:46:10
|
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
--> $DIR/bad-assoc-ty.rs:39:19
|
LL | ($ty: ty) => ($ty::AssocTy);
| ^^^^^^^^^^^^ help: try: `<$ty>::AssocTy`
| ^^^
...
LL | type J = ty!(u8);
| ------- in this macro invocation
|
= 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
--> $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
|
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