Skip to content

Commit 36e530c

Browse files
committed
Auto merge of rust-lang#100793 - matthiaskrgr:rollup-dy7rfdh, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - rust-lang#100186 (Mention `as_mut` alongside `as_ref` in borrowck error message) - rust-lang#100383 (Mitigate stale data reads on SGX platform) - rust-lang#100507 (suggest `once_cell::Lazy` for non-const statics) - rust-lang#100617 (Suggest the right help message for as_ref) - rust-lang#100667 (Migrate "invalid variable declaration" errors to SessionDiagnostic) - rust-lang#100709 (Migrate typeck's `used` expected symbol diagnostic to `SessionDiagnostic`) - rust-lang#100723 (Add the diagnostic translation lints to crates that don't emit them) - rust-lang#100729 (Avoid zeroing a 1kb stack buffer on every call to `std::sys::windows::fill_utf16_buf`) - rust-lang#100750 (improved diagnostic for function defined with `def`, `fun`, `func`, or `function` instead of `fn`) - rust-lang#100763 (triagebot: Autolabel `A-rustdoc-json`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents e1b28cd + 60edec9 commit 36e530c

File tree

63 files changed

+476
-138
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+476
-138
lines changed

Diff for: compiler/rustc_apfloat/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
3434
#![no_std]
3535
#![forbid(unsafe_code)]
36+
#![deny(rustc::untranslatable_diagnostic)]
37+
#![deny(rustc::diagnostic_outside_of_impl)]
3638

3739
#[macro_use]
3840
extern crate alloc;

Diff for: compiler/rustc_arena/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#![feature(rustc_attrs)]
2020
#![cfg_attr(test, feature(test))]
2121
#![feature(strict_provenance)]
22+
#![deny(rustc::untranslatable_diagnostic)]
23+
#![deny(rustc::diagnostic_outside_of_impl)]
2224

2325
use smallvec::SmallVec;
2426

Diff for: compiler/rustc_ast/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#![feature(slice_internals)]
2020
#![feature(stmt_expr_attributes)]
2121
#![recursion_limit = "256"]
22+
#![deny(rustc::untranslatable_diagnostic)]
23+
#![deny(rustc::diagnostic_outside_of_impl)]
2224

2325
#[macro_use]
2426
extern crate rustc_macros;

Diff for: compiler/rustc_ast_pretty/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
13
#![feature(associated_type_bounds)]
24
#![feature(box_patterns)]
35
#![feature(with_negative_coherence)]

Diff for: compiler/rustc_borrowck/src/diagnostics/mod.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1086,14 +1086,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10861086
),
10871087
);
10881088
}
1089-
if is_option_or_result && maybe_reinitialized_locations_is_empty {
1090-
err.span_suggestion_verbose(
1091-
fn_call_span.shrink_to_lo(),
1092-
"consider calling `.as_ref()` to borrow the type's contents",
1093-
"as_ref().",
1094-
Applicability::MachineApplicable,
1095-
);
1096-
}
10971089
// Avoid pointing to the same function in multiple different
10981090
// error messages.
10991091
if span != DUMMY_SP && self.fn_self_span_reported.insert(self_arg.span) {
@@ -1102,6 +1094,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11021094
&format!("this function takes ownership of the receiver `self`, which moves {}", place_name)
11031095
);
11041096
}
1097+
if is_option_or_result && maybe_reinitialized_locations_is_empty {
1098+
err.span_label(
1099+
var_span,
1100+
"help: consider calling `.as_ref()` or `.as_mut()` to borrow the type's contents",
1101+
);
1102+
}
11051103
}
11061104
// Other desugarings takes &self, which cannot cause a move
11071105
_ => {}

Diff for: compiler/rustc_const_eval/src/transform/check_consts/ops.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Concrete error types for all operations which may be invalid in a certain const context.
22
33
use hir::def_id::LocalDefId;
4+
use hir::ConstContext;
45
use rustc_errors::{
56
error_code, struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed,
67
};
@@ -331,6 +332,10 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
331332
ccx.const_kind(),
332333
));
333334

335+
if let ConstContext::Static(_) = ccx.const_kind() {
336+
err.note("consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell");
337+
}
338+
334339
err
335340
}
336341
}

Diff for: compiler/rustc_data_structures/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#![feature(vec_into_raw_parts)]
2929
#![allow(rustc::default_hash_types)]
3030
#![allow(rustc::potential_query_instability)]
31+
#![deny(rustc::untranslatable_diagnostic)]
32+
#![deny(rustc::diagnostic_outside_of_impl)]
3133

3234
#[macro_use]
3335
extern crate tracing;

Diff for: compiler/rustc_error_codes/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#![deny(rustdoc::invalid_codeblock_attributes)]
2+
#![deny(rustc::untranslatable_diagnostic)]
3+
#![deny(rustc::diagnostic_outside_of_impl)]
24
//! This library is used to gather all error codes into one place,
35
//! the goal being to make their maintenance easier.
46

Diff for: compiler/rustc_error_messages/locales/en-US/parser.ftl

+9
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,12 @@ parser_incorrect_use_of_await =
3232
parser_in_in_typo =
3333
expected iterable, found keyword `in`
3434
.suggestion = remove the duplicated `in`
35+
36+
parser_invalid_variable_declaration =
37+
invalid variable declaration
38+
39+
parser_switch_mut_let_order =
40+
switch the order of `mut` and `let`
41+
parser_missing_let_before_mut = missing keyword
42+
parser_use_let_not_auto = write `let` instead of `auto` to introduce a new variable
43+
parser_use_let_not_var = write `let` instead of `var` to introduce a new variable

Diff for: compiler/rustc_error_messages/locales/en-US/typeck.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,5 @@ typeck_unused_extern_crate =
131131
typeck_extern_crate_not_idiomatic =
132132
`extern crate` is not idiomatic in the new edition
133133
.suggestion = convert it to a `{$msg_code}`
134+
135+
typeck_expected_used_symbol = expected `used`, `used(compiler)` or `used(linker)`

Diff for: compiler/rustc_error_messages/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#![feature(once_cell)]
22
#![feature(rustc_attrs)]
33
#![feature(type_alias_impl_trait)]
4+
#![deny(rustc::untranslatable_diagnostic)]
5+
#![deny(rustc::diagnostic_outside_of_impl)]
46

57
use fluent_bundle::FluentResource;
68
use fluent_syntax::parser::ParserError;

Diff for: compiler/rustc_feature/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
//! symbol to the `accepted` or `removed` modules respectively.
1313
1414
#![feature(once_cell)]
15+
#![deny(rustc::untranslatable_diagnostic)]
16+
#![deny(rustc::diagnostic_outside_of_impl)]
1517

1618
mod accepted;
1719
mod active;

Diff for: compiler/rustc_fs_util/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
3+
14
use std::ffi::CString;
25
use std::fs;
36
use std::io;

Diff for: compiler/rustc_graphviz/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@
273273
html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/",
274274
test(attr(allow(unused_variables), deny(warnings)))
275275
)]
276+
#![deny(rustc::untranslatable_diagnostic)]
277+
#![deny(rustc::diagnostic_outside_of_impl)]
276278

277279
use LabelText::*;
278280

Diff for: compiler/rustc_hir/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#![feature(never_type)]
1212
#![feature(rustc_attrs)]
1313
#![recursion_limit = "256"]
14+
#![deny(rustc::untranslatable_diagnostic)]
15+
#![deny(rustc::diagnostic_outside_of_impl)]
1416

1517
#[macro_use]
1618
extern crate rustc_macros;

Diff for: compiler/rustc_hir_pretty/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#![recursion_limit = "256"]
2+
#![deny(rustc::untranslatable_diagnostic)]
3+
#![deny(rustc::diagnostic_outside_of_impl)]
24

35
use rustc_ast as ast;
46
use rustc_ast::util::parser::{self, AssocOp, Fixity};

Diff for: compiler/rustc_index/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
13
#![feature(allow_internal_unstable)]
24
#![feature(bench_black_box)]
35
#![feature(extend_one)]

Diff for: compiler/rustc_infer/src/infer/error_reporting/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2079,7 +2079,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
20792079
diag.span_suggestion(
20802080
span,
20812081
*msg,
2082-
format!("{}.as_ref()", snippet),
2082+
// HACK: fix issue# 100605, suggesting convert from &Option<T> to Option<&T>, remove the extra `&`
2083+
format!("{}.as_ref()", snippet.trim_start_matches('&')),
20832084
Applicability::MachineApplicable,
20842085
);
20852086
}

Diff for: compiler/rustc_lexer/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
//! lexeme types.
1919
//!
2020
//! [`rustc_parse::lexer`]: ../rustc_parse/lexer/index.html
21+
#![deny(rustc::untranslatable_diagnostic)]
22+
#![deny(rustc::diagnostic_outside_of_impl)]
2123
// We want to be able to build this crate with a stable compiler, so no
2224
// `#![feature]` attributes should be added.
2325

Diff for: compiler/rustc_lint_defs/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#![feature(min_specialization)]
2+
#![deny(rustc::untranslatable_diagnostic)]
3+
#![deny(rustc::diagnostic_outside_of_impl)]
24

35
#[macro_use]
46
extern crate rustc_macros;

Diff for: compiler/rustc_llvm/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(rustc::untranslatable_diagnostic)]
2+
#![deny(rustc::diagnostic_outside_of_impl)]
13
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
24

35
// NOTE: This crate only exists to allow linking on mingw targets.

Diff for: compiler/rustc_log/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
//! debugging, you can make changes inside those crates and quickly run main.rs
3939
//! to read the debug logs.
4040
41+
#![deny(rustc::untranslatable_diagnostic)]
42+
#![deny(rustc::diagnostic_outside_of_impl)]
43+
4144
use std::env::{self, VarError};
4245
use std::fmt::{self, Display};
4346
use std::io;

Diff for: compiler/rustc_macros/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#![feature(proc_macro_diagnostic)]
55
#![feature(proc_macro_span)]
66
#![allow(rustc::default_hash_types)]
7+
#![deny(rustc::untranslatable_diagnostic)]
8+
#![deny(rustc::diagnostic_outside_of_impl)]
79
#![recursion_limit = "128"]
810

911
use synstructure::decl_derive;

Diff for: compiler/rustc_parse/src/parser/diagnostics.rs

+38
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,35 @@ struct InInTypo {
334334
sugg_span: Span,
335335
}
336336

337+
#[derive(SessionDiagnostic)]
338+
#[error(parser::invalid_variable_declaration)]
339+
pub struct InvalidVariableDeclaration {
340+
#[primary_span]
341+
pub span: Span,
342+
#[subdiagnostic]
343+
pub sub: InvalidVariableDeclarationSub,
344+
}
345+
346+
#[derive(SessionSubdiagnostic)]
347+
pub enum InvalidVariableDeclarationSub {
348+
#[suggestion(
349+
parser::switch_mut_let_order,
350+
applicability = "maybe-incorrect",
351+
code = "let mut"
352+
)]
353+
SwitchMutLetOrder(#[primary_span] Span),
354+
#[suggestion(
355+
parser::missing_let_before_mut,
356+
applicability = "machine-applicable",
357+
code = "let mut"
358+
)]
359+
MissingLet(#[primary_span] Span),
360+
#[suggestion(parser::use_let_not_auto, applicability = "machine-applicable", code = "let")]
361+
UseLetNotAuto(#[primary_span] Span),
362+
#[suggestion(parser::use_let_not_var, applicability = "machine-applicable", code = "let")]
363+
UseLetNotVar(#[primary_span] Span),
364+
}
365+
337366
// SnapshotParser is used to create a snapshot of the parser
338367
// without causing duplicate errors being emitted when the `Parser`
339368
// is dropped.
@@ -611,6 +640,15 @@ impl<'a> Parser<'a> {
611640
appl,
612641
);
613642
}
643+
644+
if ["def", "fun", "func", "function"].contains(&symbol.as_str()) {
645+
err.span_suggestion_short(
646+
self.prev_token.span,
647+
&format!("write `fn` instead of `{symbol}` to declare a function"),
648+
"fn",
649+
appl,
650+
);
651+
}
614652
}
615653

616654
// Add suggestion for a missing closing angle bracket if '>' is included in expected_tokens

Diff for: compiler/rustc_parse/src/parser/stmt.rs

+12-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use super::attr::DEFAULT_INNER_ATTR_FORBIDDEN;
2-
use super::diagnostics::{AttemptLocalParseRecovery, Error};
2+
use super::diagnostics::{
3+
AttemptLocalParseRecovery, Error, InvalidVariableDeclaration, InvalidVariableDeclarationSub,
4+
};
35
use super::expr::LhsExpr;
46
use super::pat::RecoverComma;
57
use super::path::PathStyle;
@@ -58,28 +60,22 @@ impl<'a> Parser<'a> {
5860
if self.token.is_keyword(kw::Mut) && self.is_keyword_ahead(1, &[kw::Let]) {
5961
self.bump();
6062
let mut_let_span = lo.to(self.token.span);
61-
self.struct_span_err(mut_let_span, "invalid variable declaration")
62-
.span_suggestion(
63-
mut_let_span,
64-
"switch the order of `mut` and `let`",
65-
"let mut",
66-
Applicability::MaybeIncorrect,
67-
)
68-
.emit();
63+
self.sess.emit_err(InvalidVariableDeclaration {
64+
span: mut_let_span,
65+
sub: InvalidVariableDeclarationSub::SwitchMutLetOrder(mut_let_span),
66+
});
6967
}
7068

7169
Ok(Some(if self.token.is_keyword(kw::Let) {
7270
self.parse_local_mk(lo, attrs, capture_semi, force_collect)?
7371
} else if self.is_kw_followed_by_ident(kw::Mut) {
74-
self.recover_stmt_local(lo, attrs, "missing keyword", "let mut")?
72+
self.recover_stmt_local(lo, attrs, InvalidVariableDeclarationSub::MissingLet)?
7573
} else if self.is_kw_followed_by_ident(kw::Auto) {
7674
self.bump(); // `auto`
77-
let msg = "write `let` instead of `auto` to introduce a new variable";
78-
self.recover_stmt_local(lo, attrs, msg, "let")?
75+
self.recover_stmt_local(lo, attrs, InvalidVariableDeclarationSub::UseLetNotAuto)?
7976
} else if self.is_kw_followed_by_ident(sym::var) {
8077
self.bump(); // `var`
81-
let msg = "write `let` instead of `var` to introduce a new variable";
82-
self.recover_stmt_local(lo, attrs, msg, "let")?
78+
self.recover_stmt_local(lo, attrs, InvalidVariableDeclarationSub::UseLetNotVar)?
8379
} else if self.check_path() && !self.token.is_qpath_start() && !self.is_path_start_item() {
8480
// We have avoided contextual keywords like `union`, items with `crate` visibility,
8581
// or `auto trait` items. We aim to parse an arbitrary path `a::b` but not something
@@ -217,13 +213,10 @@ impl<'a> Parser<'a> {
217213
&mut self,
218214
lo: Span,
219215
attrs: AttrWrapper,
220-
msg: &str,
221-
sugg: &str,
216+
subdiagnostic: fn(Span) -> InvalidVariableDeclarationSub,
222217
) -> PResult<'a, Stmt> {
223218
let stmt = self.recover_local_after_let(lo, attrs)?;
224-
self.struct_span_err(lo, "invalid variable declaration")
225-
.span_suggestion(lo, msg, sugg, Applicability::MachineApplicable)
226-
.emit();
219+
self.sess.emit_err(InvalidVariableDeclaration { span: lo, sub: subdiagnostic(lo) });
227220
Ok(stmt)
228221
}
229222

Diff for: compiler/rustc_parse_format/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
html_playground_url = "https://play.rust-lang.org/",
1010
test(attr(deny(warnings)))
1111
)]
12+
#![deny(rustc::untranslatable_diagnostic)]
13+
#![deny(rustc::diagnostic_outside_of_impl)]
1214
// We want to be able to build this crate with a stable compiler, so no
1315
// `#![feature]` attributes should be added.
1416

Diff for: compiler/rustc_query_impl/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#![feature(rustc_attrs)]
88
#![recursion_limit = "256"]
99
#![allow(rustc::potential_query_instability)]
10+
#![deny(rustc::untranslatable_diagnostic)]
11+
#![deny(rustc::diagnostic_outside_of_impl)]
1012

1113
#[macro_use]
1214
extern crate rustc_macros;

Diff for: compiler/rustc_serialize/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Core encoding and decoding interfaces.
1818
#![feature(new_uninit)]
1919
#![cfg_attr(test, feature(test))]
2020
#![allow(rustc::internal)]
21+
#![deny(rustc::untranslatable_diagnostic)]
22+
#![deny(rustc::diagnostic_outside_of_impl)]
2123

2224
pub use self::serialize::{Decodable, Decoder, Encodable, Encoder};
2325

Diff for: compiler/rustc_smir/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
test(attr(allow(unused_variables), deny(warnings)))
1212
)]
1313
#![cfg_attr(not(feature = "default"), feature(rustc_private))]
14+
#![deny(rustc::untranslatable_diagnostic)]
15+
#![deny(rustc::diagnostic_outside_of_impl)]
1416

1517
pub mod mir;
1618

Diff for: compiler/rustc_span/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#![feature(negative_impls)]
2121
#![feature(min_specialization)]
2222
#![feature(rustc_attrs)]
23+
#![deny(rustc::untranslatable_diagnostic)]
24+
#![deny(rustc::diagnostic_outside_of_impl)]
2325

2426
#[macro_use]
2527
extern crate rustc_macros;

Diff for: compiler/rustc_target/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#![feature(never_type)]
1717
#![feature(rustc_attrs)]
1818
#![feature(step_trait)]
19+
#![deny(rustc::untranslatable_diagnostic)]
20+
#![deny(rustc::diagnostic_outside_of_impl)]
1921

2022
use std::iter::FromIterator;
2123
use std::path::{Path, PathBuf};

Diff for: compiler/rustc_traits/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! New recursive solver modeled on Chalk's recursive solver. Most of
22
//! the guts are broken up into modules; see the comments in those modules.
33
4+
#![deny(rustc::untranslatable_diagnostic)]
5+
#![deny(rustc::diagnostic_outside_of_impl)]
46
#![feature(let_else)]
57
#![recursion_limit = "256"]
68

0 commit comments

Comments
 (0)