Fix static string lints
This commit is contained in:
parent
eeb527602a
commit
0138513635
32 changed files with 491 additions and 200 deletions
|
@ -742,3 +742,33 @@ parse_bad_return_type_notation_output =
|
|||
parse_bad_return_type_notation_dotdot =
|
||||
return type notation uses `()` instead of `(..)` for elided arguments
|
||||
.suggestion = remove the `..`
|
||||
|
||||
parse_bad_assoc_type_bounds = bounds on associated types do not belong here
|
||||
.label = belongs in `where` clause
|
||||
|
||||
parse_attr_after_generic = trailing attribute after generic parameter
|
||||
.label = attributes must go before parameters
|
||||
|
||||
parse_attr_without_generics = attribute without generic parameters
|
||||
.label = attributes are only permitted when preceding parameters
|
||||
|
||||
parse_where_generics = generic parameters on `where` clauses are reserved for future use
|
||||
.label = currently unsupported
|
||||
|
||||
parse_generics_in_path = unexpected generic arguments in path
|
||||
|
||||
parse_assoc_lifetime = associated lifetimes are not supported
|
||||
.label = the lifetime is given here
|
||||
.help = if you meant to specify a trait object, write `dyn Trait + 'lifetime`
|
||||
|
||||
parse_tilde_const_lifetime = `~const` may only modify trait bounds, not lifetime bounds
|
||||
|
||||
parse_maybe_lifetime = `?` may only modify trait bounds, not lifetime bounds
|
||||
|
||||
parse_parenthesized_lifetime = parenthesized lifetime bounds are not supported
|
||||
.suggestion = remove the parentheses
|
||||
|
||||
parse_const_bounds_missing_tilde = const bounds must start with `~`
|
||||
.suggestion = add `~`
|
||||
|
||||
parse_underscore_literal_suffix = underscore literal suffix is not allowed
|
||||
|
|
|
@ -2332,3 +2332,92 @@ pub(crate) struct BadReturnTypeNotationDotDot {
|
|||
#[suggestion(code = "", applicability = "maybe-incorrect")]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(parse_bad_assoc_type_bounds)]
|
||||
pub(crate) struct BadAssocTypeBounds {
|
||||
#[primary_span]
|
||||
#[label]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(parse_attr_after_generic)]
|
||||
pub(crate) struct AttrAfterGeneric {
|
||||
#[primary_span]
|
||||
#[label]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(parse_attr_without_generics)]
|
||||
pub(crate) struct AttrWithoutGenerics {
|
||||
#[primary_span]
|
||||
#[label]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(parse_where_generics)]
|
||||
pub(crate) struct WhereOnGenerics {
|
||||
#[primary_span]
|
||||
#[label]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(parse_generics_in_path)]
|
||||
pub(crate) struct GenericsInPath {
|
||||
#[primary_span]
|
||||
pub span: Vec<Span>,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(parse_assoc_lifetime)]
|
||||
#[help]
|
||||
pub(crate) struct AssocLifetime {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
#[label]
|
||||
pub lifetime: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(parse_tilde_const_lifetime)]
|
||||
pub(crate) struct TildeConstLifetime {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(parse_maybe_lifetime)]
|
||||
pub(crate) struct MaybeLifetime {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(parse_parenthesized_lifetime)]
|
||||
pub(crate) struct ParenthesizedLifetime {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
#[suggestion(style = "short", applicability = "machine-applicable", code = "{snippet}")]
|
||||
pub sugg: Option<Span>,
|
||||
pub snippet: String,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(parse_const_bounds_missing_tilde)]
|
||||
pub(crate) struct ConstMissingTilde {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
#[suggestion(code = "~", applicability = "machine-applicable")]
|
||||
pub start: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(parse_underscore_literal_suffix)]
|
||||
pub(crate) struct UnderscoreLiteralSuffix {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
}
|
||||
|
|
|
@ -209,11 +209,7 @@ impl<'a> StringReader<'a> {
|
|||
if string == "_" {
|
||||
self.sess
|
||||
.span_diagnostic
|
||||
.struct_span_err(
|
||||
self.mk_sp(suffix_start, self.pos),
|
||||
"underscore literal suffix is not allowed",
|
||||
)
|
||||
.emit();
|
||||
.emit_err(errors::UnderscoreLiteralSuffix { span: self.mk_sp(suffix_start, self.pos) });
|
||||
None
|
||||
} else {
|
||||
Some(Symbol::intern(string))
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::errors::{
|
||||
MultipleWhereClauses, UnexpectedDefaultValueForLifetimeInGenericParameters,
|
||||
self, MultipleWhereClauses, UnexpectedDefaultValueForLifetimeInGenericParameters,
|
||||
UnexpectedSelfInGenericParameters, WhereClauseBeforeTupleStructBody,
|
||||
WhereClauseBeforeTupleStructBodySugg,
|
||||
};
|
||||
|
@ -181,12 +181,9 @@ impl<'a> Parser<'a> {
|
|||
let snapshot = this.create_snapshot_for_diagnostic();
|
||||
match this.parse_ty_where_predicate() {
|
||||
Ok(where_predicate) => {
|
||||
this.struct_span_err(
|
||||
where_predicate.span(),
|
||||
"bounds on associated types do not belong here",
|
||||
)
|
||||
.span_label(where_predicate.span(), "belongs in `where` clause")
|
||||
.emit();
|
||||
this.sess.emit_err(errors::BadAssocTypeBounds {
|
||||
span: where_predicate.span(),
|
||||
});
|
||||
// FIXME - try to continue parsing other generics?
|
||||
return Ok((None, TrailingToken::None));
|
||||
}
|
||||
|
@ -201,22 +198,11 @@ impl<'a> Parser<'a> {
|
|||
// Check for trailing attributes and stop parsing.
|
||||
if !attrs.is_empty() {
|
||||
if !params.is_empty() {
|
||||
this.struct_span_err(
|
||||
attrs[0].span,
|
||||
"trailing attribute after generic parameter",
|
||||
)
|
||||
.span_label(attrs[0].span, "attributes must go before parameters")
|
||||
.emit();
|
||||
this.sess
|
||||
.emit_err(errors::AttrAfterGeneric { span: attrs[0].span });
|
||||
} else {
|
||||
this.struct_span_err(
|
||||
attrs[0].span,
|
||||
"attribute without generic parameters",
|
||||
)
|
||||
.span_label(
|
||||
attrs[0].span,
|
||||
"attributes are only permitted when preceding parameters",
|
||||
)
|
||||
.emit();
|
||||
this.sess
|
||||
.emit_err(errors::AttrWithoutGenerics { span: attrs[0].span });
|
||||
}
|
||||
}
|
||||
return Ok((None, TrailingToken::None));
|
||||
|
@ -304,12 +290,7 @@ impl<'a> Parser<'a> {
|
|||
// change we parse those generics now, but report an error.
|
||||
if self.choose_generics_over_qpath(0) {
|
||||
let generics = self.parse_generics()?;
|
||||
self.struct_span_err(
|
||||
generics.span,
|
||||
"generic parameters on `where` clauses are reserved for future use",
|
||||
)
|
||||
.span_label(generics.span, "currently unsupported")
|
||||
.emit();
|
||||
self.sess.emit_err(errors::WhereOnGenerics { span: generics.span });
|
||||
}
|
||||
|
||||
loop {
|
||||
|
|
|
@ -150,16 +150,13 @@ impl<'a> Parser<'a> {
|
|||
//
|
||||
if style == PathStyle::Mod && path.segments.iter().any(|segment| segment.args.is_some())
|
||||
{
|
||||
parser
|
||||
.struct_span_err(
|
||||
path.segments
|
||||
.iter()
|
||||
.filter_map(|segment| segment.args.as_ref())
|
||||
.map(|arg| arg.span())
|
||||
.collect::<Vec<_>>(),
|
||||
"unexpected generic arguments in path",
|
||||
)
|
||||
.emit();
|
||||
let span = path
|
||||
.segments
|
||||
.iter()
|
||||
.filter_map(|segment| segment.args.as_ref())
|
||||
.map(|arg| arg.span())
|
||||
.collect::<Vec<_>>();
|
||||
parser.sess.emit_err(errors::GenericsInPath { span });
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -620,10 +617,7 @@ impl<'a> Parser<'a> {
|
|||
c.into()
|
||||
}
|
||||
Some(GenericArg::Lifetime(lt)) => {
|
||||
self.struct_span_err(span, "associated lifetimes are not supported")
|
||||
.span_label(lt.ident.span, "the lifetime is given here")
|
||||
.help("if you meant to specify a trait object, write `dyn Trait + 'lifetime`")
|
||||
.emit();
|
||||
self.sess.emit_err(errors::AssocLifetime { span, lifetime: lt.ident.span });
|
||||
self.mk_ty(span, ast::TyKind::Err).into()
|
||||
}
|
||||
None => {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use super::{Parser, PathStyle, TokenType};
|
||||
|
||||
use crate::errors::{
|
||||
DynAfterMut, ExpectedFnPathFoundFnKeyword, ExpectedMutOrConstInRawPointerType,
|
||||
self, DynAfterMut, ExpectedFnPathFoundFnKeyword, ExpectedMutOrConstInRawPointerType,
|
||||
FnPointerCannotBeAsync, FnPointerCannotBeConst, FnPtrWithGenerics, FnPtrWithGenericsSugg,
|
||||
InvalidDynKeyword, LifetimeAfterMut, NeedPlusAfterTraitObjectLifetime,
|
||||
NegativeBoundsNotSupported, NegativeBoundsNotSupportedSugg, NestedCVariadicType,
|
||||
|
@ -807,16 +807,11 @@ impl<'a> Parser<'a> {
|
|||
/// Emits an error if any trait bound modifiers were present.
|
||||
fn error_lt_bound_with_modifiers(&self, modifiers: BoundModifiers) {
|
||||
if let Some(span) = modifiers.maybe_const {
|
||||
self.struct_span_err(
|
||||
span,
|
||||
"`~const` may only modify trait bounds, not lifetime bounds",
|
||||
)
|
||||
.emit();
|
||||
self.sess.emit_err(errors::TildeConstLifetime { span });
|
||||
}
|
||||
|
||||
if let Some(span) = modifiers.maybe {
|
||||
self.struct_span_err(span, "`?` may only modify trait bounds, not lifetime bounds")
|
||||
.emit();
|
||||
self.sess.emit_err(errors::MaybeLifetime { span });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -824,19 +819,14 @@ impl<'a> Parser<'a> {
|
|||
fn recover_paren_lifetime(&mut self, lo: Span, inner_lo: Span) -> PResult<'a, ()> {
|
||||
let inner_span = inner_lo.to(self.prev_token.span);
|
||||
self.expect(&token::CloseDelim(Delimiter::Parenthesis))?;
|
||||
let mut err = self.struct_span_err(
|
||||
lo.to(self.prev_token.span),
|
||||
"parenthesized lifetime bounds are not supported",
|
||||
);
|
||||
if let Ok(snippet) = self.span_to_snippet(inner_span) {
|
||||
err.span_suggestion_short(
|
||||
lo.to(self.prev_token.span),
|
||||
"remove the parentheses",
|
||||
snippet,
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
err.emit();
|
||||
let span = lo.to(self.prev_token.span);
|
||||
let (sugg, snippet) = if let Ok(snippet) = self.span_to_snippet(inner_span) {
|
||||
(Some(span), snippet)
|
||||
} else {
|
||||
(None, String::new())
|
||||
};
|
||||
|
||||
self.sess.emit_err(errors::ParenthesizedLifetime { span, sugg, snippet });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -857,15 +847,7 @@ impl<'a> Parser<'a> {
|
|||
} else if self.eat_keyword(kw::Const) {
|
||||
let span = self.prev_token.span;
|
||||
self.sess.gated_spans.gate(sym::const_trait_impl, span);
|
||||
|
||||
self.struct_span_err(span, "const bounds must start with `~`")
|
||||
.span_suggestion(
|
||||
span.shrink_to_lo(),
|
||||
"add `~`",
|
||||
"~",
|
||||
Applicability::MachineApplicable,
|
||||
)
|
||||
.emit();
|
||||
self.sess.emit_err(errors::ConstMissingTilde { span, start: span.shrink_to_lo() });
|
||||
|
||||
Some(span)
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue