Skip to content

Commit f9cff63

Browse files
committed
Auto merge of #2905 - saethlin:rustup, r=saethlin
rustup
2 parents 7bef7b7 + 55df622 commit f9cff63

File tree

82 files changed

+693
-428
lines changed

Some content is hidden

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

82 files changed

+693
-428
lines changed

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
4444
| asm::InlineAsmArch::AArch64
4545
| asm::InlineAsmArch::RiscV32
4646
| asm::InlineAsmArch::RiscV64
47+
| asm::InlineAsmArch::LoongArch64
4748
);
4849
if !is_stable && !self.tcx.features().asm_experimental_arch {
4950
feature_err(

compiler/rustc_builtin_macros/src/compile_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn expand_compile_error<'cx>(
1818
reason = "diagnostic message is specified by user"
1919
)]
2020
#[expect(rustc::untranslatable_diagnostic, reason = "diagnostic message is specified by user")]
21-
cx.span_err(sp, var.as_str());
21+
cx.span_err(sp, var.to_string());
2222

2323
DummyResult::any(sp)
2424
}

compiler/rustc_builtin_macros/src/deriving/clone.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ pub fn expand_deriving_clone(
6868
_ => cx.span_bug(span, "`#[derive(Clone)]` on trait item or impl item"),
6969
}
7070

71-
let attrs = thin_vec![cx.attr_word(sym::inline, span)];
7271
let trait_def = TraitDef {
7372
span,
7473
path: path_std!(clone::Clone),
@@ -82,7 +81,7 @@ pub fn expand_deriving_clone(
8281
explicit_self: true,
8382
nonself_args: Vec::new(),
8483
ret_ty: Self_,
85-
attributes: attrs,
84+
attributes: thin_vec![cx.attr_word(sym::inline, span)],
8685
fieldless_variants_strategy: FieldlessVariantsStrategy::Default,
8786
combine_substructure: substructure,
8887
}],

compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ pub fn expand_deriving_eq(
1818
is_const: bool,
1919
) {
2020
let span = cx.with_def_site_ctxt(span);
21-
let attrs = thin_vec![
22-
cx.attr_word(sym::inline, span),
23-
cx.attr_nested_word(sym::doc, sym::hidden, span),
24-
cx.attr_word(sym::no_coverage, span)
25-
];
2621
let trait_def = TraitDef {
2722
span,
2823
path: path_std!(cmp::Eq),
@@ -36,7 +31,11 @@ pub fn expand_deriving_eq(
3631
explicit_self: true,
3732
nonself_args: vec![],
3833
ret_ty: Unit,
39-
attributes: attrs,
34+
attributes: thin_vec![
35+
cx.attr_word(sym::inline, span),
36+
cx.attr_nested_word(sym::doc, sym::hidden, span),
37+
cx.attr_word(sym::no_coverage, span)
38+
],
4039
fieldless_variants_strategy: FieldlessVariantsStrategy::Unify,
4140
combine_substructure: combine_substructure(Box::new(|a, b, c| {
4241
cs_total_eq_assert(a, b, c)

compiler/rustc_builtin_macros/src/deriving/cmp/ord.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ pub fn expand_deriving_ord(
1515
push: &mut dyn FnMut(Annotatable),
1616
is_const: bool,
1717
) {
18-
let attrs = thin_vec![cx.attr_word(sym::inline, span)];
1918
let trait_def = TraitDef {
2019
span,
2120
path: path_std!(cmp::Ord),
@@ -29,7 +28,7 @@ pub fn expand_deriving_ord(
2928
explicit_self: true,
3029
nonself_args: vec![(self_ref(), sym::other)],
3130
ret_ty: Path(path_std!(cmp::Ordering)),
32-
attributes: attrs,
31+
attributes: thin_vec![cx.attr_word(sym::inline, span)],
3332
fieldless_variants_strategy: FieldlessVariantsStrategy::Unify,
3433
combine_substructure: combine_substructure(Box::new(|a, b, c| cs_cmp(a, b, c))),
3534
}],

compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,13 @@ pub fn expand_deriving_partial_eq(
8282

8383
// No need to generate `ne`, the default suffices, and not generating it is
8484
// faster.
85-
let attrs = thin_vec![cx.attr_word(sym::inline, span)];
8685
let methods = vec![MethodDef {
8786
name: sym::eq,
8887
generics: Bounds::empty(),
8988
explicit_self: true,
9089
nonself_args: vec![(self_ref(), sym::other)],
9190
ret_ty: Path(path_local!(bool)),
92-
attributes: attrs,
91+
attributes: thin_vec![cx.attr_word(sym::inline, span)],
9392
fieldless_variants_strategy: FieldlessVariantsStrategy::Unify,
9493
combine_substructure: combine_substructure(Box::new(|a, b, c| cs_eq(a, b, c))),
9594
}];

compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ pub fn expand_deriving_partial_ord(
1919
let ret_ty =
2020
Path(Path::new_(pathvec_std!(option::Option), vec![Box::new(ordering_ty)], PathKind::Std));
2121

22-
let attrs = thin_vec![cx.attr_word(sym::inline, span)];
23-
2422
// Order in which to perform matching
2523
let tag_then_data = if let Annotatable::Item(item) = item
2624
&& let ItemKind::Enum(def, _) = &item.kind {
@@ -48,7 +46,7 @@ pub fn expand_deriving_partial_ord(
4846
explicit_self: true,
4947
nonself_args: vec![(self_ref(), sym::other)],
5048
ret_ty,
51-
attributes: attrs,
49+
attributes: thin_vec![cx.attr_word(sym::inline, span)],
5250
fieldless_variants_strategy: FieldlessVariantsStrategy::Unify,
5351
combine_substructure: combine_substructure(Box::new(|cx, span, substr| {
5452
cs_partial_cmp(cx, span, substr, tag_then_data)

compiler/rustc_builtin_macros/src/deriving/default.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub fn expand_deriving_default(
2020
) {
2121
item.visit_with(&mut DetectNonVariantDefaultAttr { cx });
2222

23-
let attrs = thin_vec![cx.attr_word(sym::inline, span)];
2423
let trait_def = TraitDef {
2524
span,
2625
path: Path::new(vec![kw::Default, sym::Default]),
@@ -34,7 +33,7 @@ pub fn expand_deriving_default(
3433
explicit_self: false,
3534
nonself_args: Vec::new(),
3635
ret_ty: Self_,
37-
attributes: attrs,
36+
attributes: thin_vec![cx.attr_word(sym::inline, span)],
3837
fieldless_variants_strategy: FieldlessVariantsStrategy::Default,
3938
combine_substructure: combine_substructure(Box::new(|cx, trait_span, substr| {
4039
match substr.fields {

compiler/rustc_builtin_macros/src/deriving/hash.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::deriving::generic::ty::*;
22
use crate::deriving::generic::*;
33
use crate::deriving::{path_std, pathvec_std};
4-
use rustc_ast::{AttrVec, MetaItem, Mutability};
4+
use rustc_ast::{MetaItem, Mutability};
55
use rustc_expand::base::{Annotatable, ExtCtxt};
66
use rustc_span::symbol::sym;
77
use rustc_span::Span;
@@ -33,7 +33,7 @@ pub fn expand_deriving_hash(
3333
explicit_self: true,
3434
nonself_args: vec![(Ref(Box::new(Path(arg)), Mutability::Mut), sym::state)],
3535
ret_ty: Unit,
36-
attributes: AttrVec::new(),
36+
attributes: thin_vec![cx.attr_word(sym::inline, span)],
3737
fieldless_variants_strategy: FieldlessVariantsStrategy::Unify,
3838
combine_substructure: combine_substructure(Box::new(|a, b, c| {
3939
hash_substructure(a, b, c)

compiler/rustc_builtin_macros/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for EnvNotDefined {
377377
rustc::untranslatable_diagnostic,
378378
reason = "cannot translate user-provided messages"
379379
)]
380-
handler.struct_diagnostic(msg.as_str())
380+
handler.struct_diagnostic(msg.to_string())
381381
} else {
382382
handler.struct_diagnostic(crate::fluent_generated::builtin_macros_env_not_defined)
383383
};

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_session::utils::NativeLibKind;
2323
use rustc_session::{filesearch, Session};
2424
use rustc_span::symbol::Symbol;
2525
use rustc_target::spec::crt_objects::{CrtObjects, LinkSelfContainedDefault};
26-
use rustc_target::spec::{Cc, LinkOutputKind, LinkerFlavor, LinkerFlavorCli, Lld, PanicStrategy};
26+
use rustc_target::spec::{Cc, LinkOutputKind, LinkerFlavor, Lld, PanicStrategy};
2727
use rustc_target::spec::{RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo};
2828

2929
use super::archive::{ArchiveBuilder, ArchiveBuilderBuilder};
@@ -893,7 +893,7 @@ fn link_natively<'a>(
893893
linker_path: &linker_path,
894894
exit_status: prog.status,
895895
command: &cmd,
896-
escaped_output: &escaped_output,
896+
escaped_output,
897897
};
898898
sess.diagnostic().emit_err(err);
899899
// If MSVC's `link.exe` was expected but the return code
@@ -1302,44 +1302,7 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
13021302
let stem = linker.file_stem().and_then(|stem| stem.to_str()).unwrap_or_else(|| {
13031303
sess.emit_fatal(errors::LinkerFileStem);
13041304
});
1305-
1306-
// Remove any version postfix.
1307-
let stem = stem
1308-
.rsplit_once('-')
1309-
.and_then(|(lhs, rhs)| rhs.chars().all(char::is_numeric).then_some(lhs))
1310-
.unwrap_or(stem);
1311-
1312-
// GCC/Clang can have an optional target prefix.
1313-
let flavor = if stem == "emcc" {
1314-
LinkerFlavor::EmCc
1315-
} else if stem == "gcc"
1316-
|| stem.ends_with("-gcc")
1317-
|| stem == "g++"
1318-
|| stem.ends_with("-g++")
1319-
|| stem == "clang"
1320-
|| stem.ends_with("-clang")
1321-
|| stem == "clang++"
1322-
|| stem.ends_with("-clang++")
1323-
{
1324-
LinkerFlavor::from_cli(LinkerFlavorCli::Gcc, &sess.target)
1325-
} else if stem == "wasm-ld" || stem.ends_with("-wasm-ld") {
1326-
LinkerFlavor::WasmLld(Cc::No)
1327-
} else if stem == "ld" || stem.ends_with("-ld") {
1328-
LinkerFlavor::from_cli(LinkerFlavorCli::Ld, &sess.target)
1329-
} else if stem == "ld.lld" {
1330-
LinkerFlavor::Gnu(Cc::No, Lld::Yes)
1331-
} else if stem == "link" {
1332-
LinkerFlavor::Msvc(Lld::No)
1333-
} else if stem == "lld-link" {
1334-
LinkerFlavor::Msvc(Lld::Yes)
1335-
} else if stem == "lld" || stem == "rust-lld" {
1336-
let lld_flavor = sess.target.linker_flavor.lld_flavor();
1337-
LinkerFlavor::from_cli(LinkerFlavorCli::Lld(lld_flavor), &sess.target)
1338-
} else {
1339-
// fall back to the value in the target spec
1340-
sess.target.linker_flavor
1341-
};
1342-
1305+
let flavor = sess.target.linker_flavor.with_linker_hints(stem);
13431306
Some((linker, flavor))
13441307
}
13451308
(None, None) => None,
@@ -1349,7 +1312,7 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
13491312
// linker and linker flavor specified via command line have precedence over what the target
13501313
// specification specifies
13511314
let linker_flavor =
1352-
sess.opts.cg.linker_flavor.map(|flavor| LinkerFlavor::from_cli(flavor, &sess.target));
1315+
sess.opts.cg.linker_flavor.map(|flavor| sess.target.linker_flavor.with_cli_hints(flavor));
13531316
if let Some(ret) = infer_from(sess, sess.opts.cg.linker.clone(), linker_flavor) {
13541317
return ret;
13551318
}

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1800,7 +1800,7 @@ impl SharedEmitterMain {
18001800
handler.emit_diagnostic(&mut d);
18011801
}
18021802
Ok(SharedEmitterMessage::InlineAsmError(cookie, msg, level, source)) => {
1803-
let msg = msg.strip_prefix("error: ").unwrap_or(&msg);
1803+
let msg = msg.strip_prefix("error: ").unwrap_or(&msg).to_string();
18041804

18051805
let mut err = match level {
18061806
Level::Error { lint: false } => sess.struct_err(msg).forget_guarantee(),

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ pub struct LinkingFailed<'a> {
336336
pub linker_path: &'a PathBuf,
337337
pub exit_status: ExitStatus,
338338
pub command: &'a Command,
339-
pub escaped_output: &'a str,
339+
pub escaped_output: String,
340340
}
341341

342342
impl IntoDiagnostic<'_> for LinkingFailed<'_> {
@@ -345,11 +345,13 @@ impl IntoDiagnostic<'_> for LinkingFailed<'_> {
345345
diag.set_arg("linker_path", format!("{}", self.linker_path.display()));
346346
diag.set_arg("exit_status", format!("{}", self.exit_status));
347347

348-
diag.note(format!("{:?}", self.command)).note(self.escaped_output);
348+
let contains_undefined_ref = self.escaped_output.contains("undefined reference to");
349+
350+
diag.note(format!("{:?}", self.command)).note(self.escaped_output.to_string());
349351

350352
// Trying to match an error from OS linkers
351353
// which by now we have no way to translate.
352-
if self.escaped_output.contains("undefined reference to") {
354+
if contains_undefined_ref {
353355
diag.note(fluent::codegen_ssa_extern_funcs_not_found)
354356
.note(fluent::codegen_ssa_specify_libraries_to_link)
355357
.note(fluent::codegen_ssa_use_cargo_directive);

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ pub fn install_ice_hook(bug_report_url: &'static str, extra_info: fn(&Handler))
12581258
if let Some(msg) = info.payload().downcast_ref::<String>() {
12591259
if msg.starts_with("failed printing to stdout: ") && msg.ends_with("(os error 232)") {
12601260
// the error code is already going to be reported when the panic unwinds up the stack
1261-
let _ = early_error_no_abort(ErrorOutputType::default(), msg.as_str());
1261+
let _ = early_error_no_abort(ErrorOutputType::default(), msg.clone());
12621262
return;
12631263
}
12641264
};

compiler/rustc_error_codes/src/error_codes/E0133.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Unsafe code was used outside of an unsafe function or block.
1+
Unsafe code was used outside of an unsafe block.
22

33
Erroneous code example:
44

@@ -30,4 +30,21 @@ fn main() {
3030

3131
See the [unsafe section][unsafe-section] of the Book for more details.
3232

33+
#### Unsafe code in functions
34+
35+
Unsafe code is currently accepted in unsafe functions, but that is being phased
36+
out in favor of requiring unsafe blocks here too.
37+
38+
```
39+
unsafe fn f() { return; }
40+
41+
unsafe fn g() {
42+
f(); // Is accepted, but no longer recommended
43+
unsafe { f(); } // Recommended way to write this
44+
}
45+
```
46+
47+
Linting against this is controlled via the `unsafe_op_in_unsafe_fn` lint, which
48+
is `allow` by default but will be upgraded to `warn` in a future edition.
49+
3350
[unsafe-section]: https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html

compiler/rustc_error_messages/src/lib.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ type FluentId = Cow<'static, str>;
263263
#[rustc_diagnostic_item = "SubdiagnosticMessage"]
264264
pub enum SubdiagnosticMessage {
265265
/// Non-translatable diagnostic message.
266-
// FIXME(davidtwco): can a `Cow<'static, str>` be used here?
267-
Str(String),
266+
Str(Cow<'static, str>),
268267
/// Translatable message which has already been translated eagerly.
269268
///
270269
/// Some diagnostics have repeated subdiagnostics where the same interpolated variables would
@@ -275,8 +274,7 @@ pub enum SubdiagnosticMessage {
275274
/// incorrect diagnostics. Eager translation results in translation for a subdiagnostic
276275
/// happening immediately after the subdiagnostic derive's logic has been run. This variant
277276
/// stores messages which have been translated eagerly.
278-
// FIXME(#100717): can a `Cow<'static, str>` be used here?
279-
Eager(String),
277+
Eager(Cow<'static, str>),
280278
/// Identifier of a Fluent message. Instances of this variant are generated by the
281279
/// `Subdiagnostic` derive.
282280
FluentIdentifier(FluentId),
@@ -290,17 +288,17 @@ pub enum SubdiagnosticMessage {
290288

291289
impl From<String> for SubdiagnosticMessage {
292290
fn from(s: String) -> Self {
293-
SubdiagnosticMessage::Str(s)
291+
SubdiagnosticMessage::Str(Cow::Owned(s))
294292
}
295293
}
296-
impl<'a> From<&'a str> for SubdiagnosticMessage {
297-
fn from(s: &'a str) -> Self {
298-
SubdiagnosticMessage::Str(s.to_string())
294+
impl From<&'static str> for SubdiagnosticMessage {
295+
fn from(s: &'static str) -> Self {
296+
SubdiagnosticMessage::Str(Cow::Borrowed(s))
299297
}
300298
}
301299
impl From<Cow<'static, str>> for SubdiagnosticMessage {
302300
fn from(s: Cow<'static, str>) -> Self {
303-
SubdiagnosticMessage::Str(s.to_string())
301+
SubdiagnosticMessage::Str(s)
304302
}
305303
}
306304

@@ -312,8 +310,7 @@ impl From<Cow<'static, str>> for SubdiagnosticMessage {
312310
#[rustc_diagnostic_item = "DiagnosticMessage"]
313311
pub enum DiagnosticMessage {
314312
/// Non-translatable diagnostic message.
315-
// FIXME(#100717): can a `Cow<'static, str>` be used here?
316-
Str(String),
313+
Str(Cow<'static, str>),
317314
/// Translatable message which has already been translated eagerly.
318315
///
319316
/// Some diagnostics have repeated subdiagnostics where the same interpolated variables would
@@ -324,8 +321,7 @@ pub enum DiagnosticMessage {
324321
/// incorrect diagnostics. Eager translation results in translation for a subdiagnostic
325322
/// happening immediately after the subdiagnostic derive's logic has been run. This variant
326323
/// stores messages which have been translated eagerly.
327-
// FIXME(#100717): can a `Cow<'static, str>` be used here?
328-
Eager(String),
324+
Eager(Cow<'static, str>),
329325
/// Identifier for a Fluent message (with optional attribute) corresponding to the diagnostic
330326
/// message.
331327
///
@@ -363,17 +359,17 @@ impl DiagnosticMessage {
363359

364360
impl From<String> for DiagnosticMessage {
365361
fn from(s: String) -> Self {
366-
DiagnosticMessage::Str(s)
362+
DiagnosticMessage::Str(Cow::Owned(s))
367363
}
368364
}
369-
impl<'a> From<&'a str> for DiagnosticMessage {
370-
fn from(s: &'a str) -> Self {
371-
DiagnosticMessage::Str(s.to_string())
365+
impl From<&'static str> for DiagnosticMessage {
366+
fn from(s: &'static str) -> Self {
367+
DiagnosticMessage::Str(Cow::Borrowed(s))
372368
}
373369
}
374370
impl From<Cow<'static, str>> for DiagnosticMessage {
375371
fn from(s: Cow<'static, str>) -> Self {
376-
DiagnosticMessage::Str(s.to_string())
372+
DiagnosticMessage::Str(s)
377373
}
378374
}
379375

0 commit comments

Comments
 (0)