Skip to content

Commit ee8c31e

Browse files
committed
Auto merge of rust-lang#100868 - Dylan-DPC:rollup-a1hfi1r, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#93162 (Std module docs improvements) - rust-lang#99386 (Add tests that check `Vec::retain` predicate execution order.) - rust-lang#99915 (Recover keywords in trait bounds) - rust-lang#100694 (Migrate rustc_ast_passes diagnostics to `SessionDiagnostic` and translatable messages (first part)) - rust-lang#100757 (Catch overflow early) Failed merges: - rust-lang#99917 (Move Error trait into core) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a9bb589 + 88e39b2 commit ee8c31e

File tree

40 files changed

+957
-342
lines changed

40 files changed

+957
-342
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3595,6 +3595,7 @@ dependencies = [
35953595
"rustc_data_structures",
35963596
"rustc_errors",
35973597
"rustc_feature",
3598+
"rustc_macros",
35983599
"rustc_parse",
35993600
"rustc_session",
36003601
"rustc_span",

compiler/rustc_ast_passes/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ rustc_attr = { path = "../rustc_attr" }
1111
rustc_data_structures = { path = "../rustc_data_structures" }
1212
rustc_errors = { path = "../rustc_errors" }
1313
rustc_feature = { path = "../rustc_feature" }
14+
rustc_macros = { path = "../rustc_macros" }
1415
rustc_parse = { path = "../rustc_parse" }
1516
rustc_session = { path = "../rustc_session" }
1617
rustc_span = { path = "../rustc_span" }

compiler/rustc_ast_passes/src/ast_validation.rs

+80-168
Large diffs are not rendered by default.
+248
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
//! Errors emitted by ast_passes.
2+
3+
use rustc_errors::{fluent, AddSubdiagnostic, Applicability, Diagnostic};
4+
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
5+
use rustc_span::{Span, Symbol};
6+
7+
use crate::ast_validation::ForbiddenLetReason;
8+
9+
#[derive(SessionDiagnostic)]
10+
#[diag(ast_passes::forbidden_let)]
11+
#[note]
12+
pub struct ForbiddenLet {
13+
#[primary_span]
14+
pub span: Span,
15+
#[subdiagnostic]
16+
pub(crate) reason: ForbiddenLetReason,
17+
}
18+
19+
impl AddSubdiagnostic for ForbiddenLetReason {
20+
fn add_to_diagnostic(self, diag: &mut Diagnostic) {
21+
match self {
22+
Self::GenericForbidden => {}
23+
Self::NotSupportedOr(span) => {
24+
diag.span_note(span, fluent::ast_passes::not_supported_or);
25+
}
26+
Self::NotSupportedParentheses(span) => {
27+
diag.span_note(span, fluent::ast_passes::not_supported_parentheses);
28+
}
29+
}
30+
}
31+
}
32+
33+
#[derive(SessionDiagnostic)]
34+
#[diag(ast_passes::forbidden_assoc_constraint)]
35+
pub struct ForbiddenAssocConstraint {
36+
#[primary_span]
37+
pub span: Span,
38+
}
39+
40+
#[derive(SessionDiagnostic)]
41+
#[diag(ast_passes::keyword_lifetime)]
42+
pub struct KeywordLifetime {
43+
#[primary_span]
44+
pub span: Span,
45+
}
46+
47+
#[derive(SessionDiagnostic)]
48+
#[diag(ast_passes::invalid_label)]
49+
pub struct InvalidLabel {
50+
#[primary_span]
51+
pub span: Span,
52+
pub name: Symbol,
53+
}
54+
55+
#[derive(SessionDiagnostic)]
56+
#[diag(ast_passes::invalid_visibility, code = "E0449")]
57+
pub struct InvalidVisibility {
58+
#[primary_span]
59+
pub span: Span,
60+
#[label(ast_passes::implied)]
61+
pub implied: Option<Span>,
62+
#[subdiagnostic]
63+
pub note: Option<InvalidVisibilityNote>,
64+
}
65+
66+
#[derive(SessionSubdiagnostic)]
67+
pub enum InvalidVisibilityNote {
68+
#[note(ast_passes::individual_impl_items)]
69+
IndividualImplItems,
70+
#[note(ast_passes::individual_foreign_items)]
71+
IndividualForeignItems,
72+
}
73+
74+
#[derive(SessionDiagnostic)]
75+
#[diag(ast_passes::trait_fn_async, code = "E0706")]
76+
#[note]
77+
#[note(ast_passes::note2)]
78+
pub struct TraitFnAsync {
79+
#[primary_span]
80+
pub fn_span: Span,
81+
#[label]
82+
pub span: Span,
83+
}
84+
85+
#[derive(SessionDiagnostic)]
86+
#[diag(ast_passes::trait_fn_const, code = "E0379")]
87+
pub struct TraitFnConst {
88+
#[primary_span]
89+
#[label]
90+
pub span: Span,
91+
}
92+
93+
#[derive(SessionDiagnostic)]
94+
#[diag(ast_passes::forbidden_lifetime_bound)]
95+
pub struct ForbiddenLifetimeBound {
96+
#[primary_span]
97+
pub spans: Vec<Span>,
98+
}
99+
100+
#[derive(SessionDiagnostic)]
101+
#[diag(ast_passes::forbidden_non_lifetime_param)]
102+
pub struct ForbiddenNonLifetimeParam {
103+
#[primary_span]
104+
pub spans: Vec<Span>,
105+
}
106+
107+
#[derive(SessionDiagnostic)]
108+
#[diag(ast_passes::fn_param_too_many)]
109+
pub struct FnParamTooMany {
110+
#[primary_span]
111+
pub span: Span,
112+
pub max_num_args: usize,
113+
}
114+
115+
#[derive(SessionDiagnostic)]
116+
#[diag(ast_passes::fn_param_c_var_args_only)]
117+
pub struct FnParamCVarArgsOnly {
118+
#[primary_span]
119+
pub span: Span,
120+
}
121+
122+
#[derive(SessionDiagnostic)]
123+
#[diag(ast_passes::fn_param_c_var_args_not_last)]
124+
pub struct FnParamCVarArgsNotLast {
125+
#[primary_span]
126+
pub span: Span,
127+
}
128+
129+
#[derive(SessionDiagnostic)]
130+
#[diag(ast_passes::fn_param_doc_comment)]
131+
pub struct FnParamDocComment {
132+
#[primary_span]
133+
#[label]
134+
pub span: Span,
135+
}
136+
137+
#[derive(SessionDiagnostic)]
138+
#[diag(ast_passes::fn_param_forbidden_attr)]
139+
pub struct FnParamForbiddenAttr {
140+
#[primary_span]
141+
pub span: Span,
142+
}
143+
144+
#[derive(SessionDiagnostic)]
145+
#[diag(ast_passes::fn_param_forbidden_self)]
146+
#[note]
147+
pub struct FnParamForbiddenSelf {
148+
#[primary_span]
149+
#[label]
150+
pub span: Span,
151+
}
152+
153+
#[derive(SessionDiagnostic)]
154+
#[diag(ast_passes::forbidden_default)]
155+
pub struct ForbiddenDefault {
156+
#[primary_span]
157+
pub span: Span,
158+
#[label]
159+
pub def_span: Span,
160+
}
161+
162+
#[derive(SessionDiagnostic)]
163+
#[diag(ast_passes::assoc_const_without_body)]
164+
pub struct AssocConstWithoutBody {
165+
#[primary_span]
166+
pub span: Span,
167+
#[suggestion(code = " = <expr>;", applicability = "has-placeholders")]
168+
pub replace_span: Span,
169+
}
170+
171+
#[derive(SessionDiagnostic)]
172+
#[diag(ast_passes::assoc_fn_without_body)]
173+
pub struct AssocFnWithoutBody {
174+
#[primary_span]
175+
pub span: Span,
176+
#[suggestion(code = " {{ <body> }}", applicability = "has-placeholders")]
177+
pub replace_span: Span,
178+
}
179+
180+
#[derive(SessionDiagnostic)]
181+
#[diag(ast_passes::assoc_type_without_body)]
182+
pub struct AssocTypeWithoutBody {
183+
#[primary_span]
184+
pub span: Span,
185+
#[suggestion(code = " = <type>;", applicability = "has-placeholders")]
186+
pub replace_span: Span,
187+
}
188+
189+
#[derive(SessionDiagnostic)]
190+
#[diag(ast_passes::const_without_body)]
191+
pub struct ConstWithoutBody {
192+
#[primary_span]
193+
pub span: Span,
194+
#[suggestion(code = " = <expr>;", applicability = "has-placeholders")]
195+
pub replace_span: Span,
196+
}
197+
198+
#[derive(SessionDiagnostic)]
199+
#[diag(ast_passes::static_without_body)]
200+
pub struct StaticWithoutBody {
201+
#[primary_span]
202+
pub span: Span,
203+
#[suggestion(code = " = <expr>;", applicability = "has-placeholders")]
204+
pub replace_span: Span,
205+
}
206+
207+
#[derive(SessionDiagnostic)]
208+
#[diag(ast_passes::ty_alias_without_body)]
209+
pub struct TyAliasWithoutBody {
210+
#[primary_span]
211+
pub span: Span,
212+
#[suggestion(code = " = <type>;", applicability = "has-placeholders")]
213+
pub replace_span: Span,
214+
}
215+
216+
#[derive(SessionDiagnostic)]
217+
#[diag(ast_passes::fn_without_body)]
218+
pub struct FnWithoutBody {
219+
#[primary_span]
220+
pub span: Span,
221+
#[suggestion(code = " {{ <body> }}", applicability = "has-placeholders")]
222+
pub replace_span: Span,
223+
#[subdiagnostic]
224+
pub extern_block_suggestion: Option<ExternBlockSuggestion>,
225+
}
226+
227+
pub struct ExternBlockSuggestion {
228+
pub start_span: Span,
229+
pub end_span: Span,
230+
pub abi: Option<Symbol>,
231+
}
232+
233+
impl AddSubdiagnostic for ExternBlockSuggestion {
234+
fn add_to_diagnostic(self, diag: &mut Diagnostic) {
235+
let start_suggestion = if let Some(abi) = self.abi {
236+
format!("extern \"{}\" {{", abi)
237+
} else {
238+
"extern {".to_owned()
239+
};
240+
let end_suggestion = " }".to_owned();
241+
242+
diag.multipart_suggestion(
243+
fluent::ast_passes::extern_block_suggestion,
244+
vec![(self.start_span, start_suggestion), (self.end_span, end_suggestion)],
245+
Applicability::MaybeIncorrect,
246+
);
247+
}
248+
}

compiler/rustc_ast_passes/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#![recursion_limit = "256"]
1313

1414
pub mod ast_validation;
15+
mod errors;
1516
pub mod feature_gate;
1617
pub mod node_count;
1718
pub mod show_span;

compiler/rustc_builtin_macros/src/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ fn create_lints_for_named_arguments_used_positionally(cx: &mut Context<'_, '_>)
11761176

11771177
cx.ecx.buffered_early_lint.push(BufferedEarlyLint {
11781178
span: MultiSpan::from_span(named_arg.positional_named_arg_span),
1179-
msg: msg.clone(),
1179+
msg: msg.into(),
11801180
node_id: ast::CRATE_NODE_ID,
11811181
lint_id: LintId::of(&NAMED_ARGUMENTS_USED_POSITIONALLY),
11821182
diagnostic: BuiltinLintDiagnostics::NamedArgumentUsedPositionally {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
ast_passes_forbidden_let =
2+
`let` expressions are not supported here
3+
.note = only supported directly in conditions of `if` and `while` expressions
4+
.not_supported_or = `||` operators are not supported in let chain expressions
5+
.not_supported_parentheses = `let`s wrapped in parentheses are not supported in a context with let chains
6+
7+
ast_passes_deprecated_where_clause_location =
8+
where clause not allowed here
9+
10+
ast_passes_forbidden_assoc_constraint =
11+
associated type bounds are not allowed within structs, enums, or unions
12+
13+
ast_passes_keyword_lifetime =
14+
lifetimes cannot use keyword names
15+
16+
ast_passes_invalid_label =
17+
invalid label name `{$name}`
18+
19+
ast_passes_invalid_visibility =
20+
unnecessary visibility qualifier
21+
.implied = `pub` not permitted here because it's implied
22+
.individual_impl_items = place qualifiers on individual impl items instead
23+
.individual_foreign_items = place qualifiers on individual foreign items instead
24+
25+
ast_passes_trait_fn_async =
26+
functions in traits cannot be declared `async`
27+
.label = `async` because of this
28+
.note = `async` trait functions are not currently supported
29+
.note2 = consider using the `async-trait` crate: https://crates.io/crates/async-trait
30+
31+
ast_passes_trait_fn_const =
32+
functions in traits cannot be declared const
33+
.label = functions in traits cannot be const
34+
35+
ast_passes_forbidden_lifetime_bound =
36+
lifetime bounds cannot be used in this context
37+
38+
ast_passes_forbidden_non_lifetime_param =
39+
only lifetime parameters can be used in this context
40+
41+
ast_passes_fn_param_too_many =
42+
function can not have more than {$max_num_args} arguments
43+
44+
ast_passes_fn_param_c_var_args_only =
45+
C-variadic function must be declared with at least one named argument
46+
47+
ast_passes_fn_param_c_var_args_not_last =
48+
`...` must be the last argument of a C-variadic function
49+
50+
ast_passes_fn_param_doc_comment =
51+
documentation comments cannot be applied to function parameters
52+
.label = doc comments are not allowed here
53+
54+
ast_passes_fn_param_forbidden_attr =
55+
allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
56+
57+
ast_passes_fn_param_forbidden_self =
58+
`self` parameter is only allowed in associated functions
59+
.label = not semantically valid as function parameter
60+
.note = associated functions are those in `impl` or `trait` definitions
61+
62+
ast_passes_forbidden_default =
63+
`default` is only allowed on items in trait impls
64+
.label = `default` because of this
65+
66+
ast_passes_assoc_const_without_body =
67+
associated constant in `impl` without body
68+
.suggestion = provide a definition for the constant
69+
70+
ast_passes_assoc_fn_without_body =
71+
associated function in `impl` without body
72+
.suggestion = provide a definition for the function
73+
74+
ast_passes_assoc_type_without_body =
75+
associated type in `impl` without body
76+
.suggestion = provide a definition for the type
77+
78+
ast_passes_const_without_body =
79+
free constant item without body
80+
.suggestion = provide a definition for the constant
81+
82+
ast_passes_static_without_body =
83+
free static item without body
84+
.suggestion = provide a definition for the static
85+
86+
ast_passes_ty_alias_without_body =
87+
free type alias without body
88+
.suggestion = provide a definition for the type
89+
90+
ast_passes_fn_without_body =
91+
free function without a body
92+
.suggestion = provide a definition for the function
93+
.extern_block_suggestion = if you meant to declare an externally defined function, use an `extern` block

compiler/rustc_error_messages/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub use unic_langid::{langid, LanguageIdentifier};
3232

3333
// Generates `DEFAULT_LOCALE_RESOURCES` static and `fluent_generated` module.
3434
fluent_messages! {
35+
ast_passes => "../locales/en-US/ast_passes.ftl",
3536
borrowck => "../locales/en-US/borrowck.ftl",
3637
builtin_macros => "../locales/en-US/builtin_macros.ftl",
3738
const_eval => "../locales/en-US/const_eval.ftl",

compiler/rustc_lint/src/early.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
4545
lint_id.lint,
4646
Some(span),
4747
|lint| {
48-
lint.build(&msg).emit();
48+
lint.build(msg).emit();
4949
},
5050
diagnostic,
5151
);

0 commit comments

Comments
 (0)