Skip to content

Commit 01b5c40

Browse files
committed
Auto merge of rust-lang#113483 - Mark-Simulacrum:beta-backport, r=Mark-Simulacrum
[beta] backport This PR backports: - rust-lang#113334: Revert the lexing of `c"…"` string literals - rust-lang#113231: Fix `dropping_copy_types` lint from linting in match-arm with side-effects - rust-lang#112794: Fix linker failures when #[global_allocator] is used in a dependency r? `@Mark-Simulacrum`
2 parents f06c1b8 + df2ddb7 commit 01b5c40

File tree

20 files changed

+217
-39
lines changed

20 files changed

+217
-39
lines changed

Cargo.lock

+17-10
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@ version = 3
44

55
[[package]]
66
name = "addr2line"
7-
version = "0.19.0"
7+
version = "0.18.0"
88
source = "registry+https://github.com/rust-lang/crates.io-index"
9-
checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97"
9+
checksum = "6ca9b76e919fd83ccfb509f51b28c333c0e03f2221616e347a129215cec4e4a9"
1010
dependencies = [
1111
"compiler_builtins",
12-
"gimli 0.27.2",
12+
"gimli 0.26.2",
1313
"rustc-std-workspace-alloc",
1414
"rustc-std-workspace-core",
1515
]
1616

17+
[[package]]
18+
name = "addr2line"
19+
version = "0.19.0"
20+
source = "registry+https://github.com/rust-lang/crates.io-index"
21+
checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97"
22+
dependencies = [
23+
"gimli 0.27.2",
24+
]
25+
1726
[[package]]
1827
name = "adler"
1928
version = "1.0.2"
@@ -228,7 +237,7 @@ version = "0.3.67"
228237
source = "registry+https://github.com/rust-lang/crates.io-index"
229238
checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca"
230239
dependencies = [
231-
"addr2line",
240+
"addr2line 0.19.0",
232241
"cc",
233242
"cfg-if",
234243
"libc",
@@ -1524,8 +1533,11 @@ version = "0.26.2"
15241533
source = "registry+https://github.com/rust-lang/crates.io-index"
15251534
checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d"
15261535
dependencies = [
1536+
"compiler_builtins",
15271537
"fallible-iterator",
15281538
"indexmap",
1539+
"rustc-std-workspace-alloc",
1540+
"rustc-std-workspace-core",
15291541
"stable_deref_trait",
15301542
]
15311543

@@ -1534,11 +1546,6 @@ name = "gimli"
15341546
version = "0.27.2"
15351547
source = "registry+https://github.com/rust-lang/crates.io-index"
15361548
checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4"
1537-
dependencies = [
1538-
"compiler_builtins",
1539-
"rustc-std-workspace-alloc",
1540-
"rustc-std-workspace-core",
1541-
]
15421549

15431550
[[package]]
15441551
name = "glob"
@@ -4718,7 +4725,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
47184725
name = "std"
47194726
version = "0.0.0"
47204727
dependencies = [
4721-
"addr2line",
4728+
"addr2line 0.18.0",
47224729
"alloc",
47234730
"cfg-if",
47244731
"compiler_builtins",

compiler/rustc_codegen_ssa/src/base.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::mir::place::PlaceRef;
1313
use crate::traits::*;
1414
use crate::{CachedModuleCodegen, CompiledModule, CrateInfo, MemFlags, ModuleCodegen, ModuleKind};
1515

16-
use rustc_ast::expand::allocator::AllocatorKind;
16+
use rustc_ast::expand::allocator::{global_fn_name, AllocatorKind, ALLOCATOR_METHODS};
1717
use rustc_attr as attr;
1818
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1919
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
@@ -909,7 +909,21 @@ impl CrateInfo {
909909
missing_weak_lang_items
910910
.iter()
911911
.map(|item| (format!("{prefix}{item}"), SymbolExportKind::Text)),
912-
)
912+
);
913+
if tcx.allocator_kind(()).is_some() {
914+
// At least one crate needs a global allocator. This crate may be placed
915+
// after the crate that defines it in the linker order, in which case some
916+
// linkers return an error. By adding the global allocator shim methods to
917+
// the linked_symbols list, linking the generated symbols.o will ensure that
918+
// circular dependencies involving the global allocator don't lead to linker
919+
// errors.
920+
linked_symbols.extend(ALLOCATOR_METHODS.iter().map(|method| {
921+
(
922+
format!("{prefix}{}", global_fn_name(method.name).as_str()),
923+
SymbolExportKind::Text,
924+
)
925+
}));
926+
}
913927
});
914928
}
915929

compiler/rustc_lexer/src/lib.rs

-7
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,6 @@ impl Cursor<'_> {
367367
Some(|terminated| Byte { terminated }),
368368
),
369369

370-
// c-string literal, raw c-string literal or identifier.
371-
'c' => self.c_or_byte_string(
372-
|terminated| CStr { terminated },
373-
|n_hashes| RawCStr { n_hashes },
374-
None,
375-
),
376-
377370
// Identifier (this should be checked after other variant that can
378371
// start as identifier).
379372
c if is_id_start(c) => self.ident_or_unknown_prefix(),

compiler/rustc_lint/src/drop_forget_useless.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ fn is_single_call_in_arm<'tcx>(
154154
arg: &'tcx Expr<'_>,
155155
drop_expr: &'tcx Expr<'_>,
156156
) -> bool {
157-
if matches!(arg.kind, ExprKind::Call(..) | ExprKind::MethodCall(..)) {
157+
if arg.can_have_side_effects() {
158158
let parent_node = cx.tcx.hir().find_parent(drop_expr.hir_id);
159159
if let Some(Node::Arm(Arm { body, .. })) = &parent_node {
160160
return body.hir_id == drop_expr.hir_id;

library/std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ hashbrown = { version = "0.13", default-features = false, features = ['rustc-dep
2323
std_detect = { path = "../stdarch/crates/std_detect", default-features = false, features = ['rustc-dep-of-std'] }
2424

2525
# Dependencies of the `backtrace` crate
26-
addr2line = { version = "0.19.0", optional = true, default-features = false }
26+
addr2line = { version = "0.18.0", optional = true, default-features = false }
2727
rustc-demangle = { version = "0.1.21", features = ['rustc-dep-of-std'] }
2828
miniz_oxide = { version = "0.6.0", optional = true, default-features = false }
2929
[dependencies.object]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# ignore-cross-compile
2+
include ../tools.mk
3+
4+
all:
5+
rm -rf $(TMPDIR) && mkdir $(TMPDIR)
6+
$(RUSTC) my_lib.rs
7+
$(RUSTC) main.rs --test --extern my_lib=$(TMPDIR)/libmy_lib.rlib
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#![crate_type = "bin"]
2+
3+
fn main() {
4+
my_lib::do_something();
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![crate_type = "lib"]
2+
3+
use std::alloc::System;
4+
5+
#[global_allocator]
6+
static ALLOCATOR: System = System;
7+
8+
pub fn do_something() {
9+
format!("allocating a string!");
10+
}

tests/ui/lint/dropping_copy_types.rs

+19
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,22 @@ fn issue9482(x: u8) {
7777
_ => (),
7878
}
7979
}
80+
81+
fn issue112653() {
82+
fn foo() -> Result<u8, ()> {
83+
println!("doing foo");
84+
Ok(0) // result is not always useful, the side-effect matters
85+
}
86+
fn bar() {
87+
println!("doing bar");
88+
}
89+
90+
fn stuff() -> Result<(), ()> {
91+
match 42 {
92+
0 => drop(foo()?), // drop is needed because we only care about side-effects
93+
1 => bar(),
94+
_ => (), // doing nothing (no side-effects needed here)
95+
}
96+
Ok(())
97+
}
98+
}

tests/ui/lint/dropping_references.rs

+19
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,22 @@ fn issue10122(x: u8) {
9797
_ => (),
9898
}
9999
}
100+
101+
fn issue112653() {
102+
fn foo() -> Result<&'static u8, ()> {
103+
println!("doing foo");
104+
Ok(&0) // result is not always useful, the side-effect matters
105+
}
106+
fn bar() {
107+
println!("doing bar");
108+
}
109+
110+
fn stuff() -> Result<(), ()> {
111+
match 42 {
112+
0 => drop(foo()?), // drop is needed because we only care about side-effects
113+
1 => bar(),
114+
_ => (), // doing nothing (no side-effects needed here)
115+
}
116+
Ok(())
117+
}
118+
}

tests/ui/rfcs/rfc-3348-c-string-literals/basic.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// run-pass
1+
// FIXME(c_str_literals): This should be `run-pass`
2+
// known-bug: #113333
3+
// edition: 2021
24

35
#![feature(c_str_literals)]
46

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error: prefix `c` is unknown
2+
--> $DIR/basic.rs:8:27
3+
|
4+
LL | assert_eq!(b"test\0", c"test".to_bytes_with_nul());
5+
| ^ unknown prefix
6+
|
7+
= note: prefixed identifiers and literals are reserved since Rust 2021
8+
help: consider inserting whitespace here
9+
|
10+
LL | assert_eq!(b"test\0", c "test".to_bytes_with_nul());
11+
| +
12+
13+
error: no rules expected the token `"test"`
14+
--> $DIR/basic.rs:8:28
15+
|
16+
LL | assert_eq!(b"test\0", c"test".to_bytes_with_nul());
17+
| -^^^^^
18+
| |
19+
| no rules expected this token in macro call
20+
| help: missing comma here
21+
|
22+
= note: while trying to match sequence start
23+
24+
error: aborting due to 2 previous errors
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Regression test for issue #113235.
2+
3+
// check-pass
4+
// revisions: edition2015 edition2018
5+
//[edition2015] edition: 2015
6+
//[edition2018] edition: 2018
7+
8+
// Make sure that in pre-2021 editions we continue to parse the snippet
9+
// `c"hello"` as an identifier followed by a (normal) string literal and
10+
// allow the code below to compile.
11+
// Prefixes including `c` as used by C string literals are only reserved
12+
// in edition 2021 and onward.
13+
//
14+
// Consider checking out rust-2021/reserved-prefixes-migration.rs as well.
15+
16+
macro_rules! parse {
17+
(c $e:expr) => {
18+
$e
19+
};
20+
}
21+
22+
fn main() {
23+
let _: &'static str = parse!(c"hello");
24+
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// gate-test-c_str_literals
2+
// known-bug: #113333
3+
// edition: 2021
24

35
macro_rules! m {
46
($t:tt) => {}
57
}
68

79
fn main() {
810
c"foo";
9-
//~^ ERROR: `c".."` literals are experimental
11+
// FIXME(c_str_literals): This should be ``c".."` literals are experimental`
1012

1113
m!(c"test");
12-
//~^ ERROR: `c".."` literals are experimental
14+
// FIXME(c_str_literals): This should be ``c".."` literals are experimental`
1315
}

tests/ui/rfcs/rfc-3348-c-string-literals/gate.stderr

+23-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1-
error[E0658]: `c".."` literals are experimental
2-
--> $DIR/gate.rs:8:5
1+
error: prefix `c` is unknown
2+
--> $DIR/gate.rs:10:5
33
|
44
LL | c"foo";
5-
| ^^^^^^
5+
| ^ unknown prefix
66
|
7-
= note: see issue #105723 <https://github.com/rust-lang/rust/issues/105723> for more information
8-
= help: add `#![feature(c_str_literals)]` to the crate attributes to enable
7+
= note: prefixed identifiers and literals are reserved since Rust 2021
8+
help: consider inserting whitespace here
9+
|
10+
LL | c "foo";
11+
| +
912

10-
error[E0658]: `c".."` literals are experimental
11-
--> $DIR/gate.rs:11:8
13+
error: prefix `c` is unknown
14+
--> $DIR/gate.rs:13:8
1215
|
1316
LL | m!(c"test");
14-
| ^^^^^^^
17+
| ^ unknown prefix
18+
|
19+
= note: prefixed identifiers and literals are reserved since Rust 2021
20+
help: consider inserting whitespace here
1521
|
16-
= note: see issue #105723 <https://github.com/rust-lang/rust/issues/105723> for more information
17-
= help: add `#![feature(c_str_literals)]` to the crate attributes to enable
22+
LL | m!(c "test");
23+
| +
24+
25+
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `"foo"`
26+
--> $DIR/gate.rs:10:6
27+
|
28+
LL | c"foo";
29+
| ^^^^^ expected one of 8 possible tokens
1830

19-
error: aborting due to 2 previous errors
31+
error: aborting due to 3 previous errors
2032

21-
For more information about this error, try `rustc --explain E0658`.
195 Bytes
Binary file not shown.
Binary file not shown.

tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// run-pass
1+
// FIXME(c_str_literals): This should be `run-pass`
2+
// known-bug: #113333
3+
// edition: 2021
24

35
#![feature(c_str_literals)]
46

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error: prefix `c` is unknown
2+
--> $DIR/non-ascii.rs:9:9
3+
|
4+
LL | c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
5+
| ^ unknown prefix
6+
|
7+
= note: prefixed identifiers and literals are reserved since Rust 2021
8+
help: consider inserting whitespace here
9+
|
10+
LL | c "\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
11+
| +
12+
13+
error: out of range hex escape
14+
--> $DIR/non-ascii.rs:9:11
15+
|
16+
LL | c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
17+
| ^^^^ must be a character in the range [\x00-\x7f]
18+
19+
error: out of range hex escape
20+
--> $DIR/non-ascii.rs:9:15
21+
|
22+
LL | c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
23+
| ^^^^ must be a character in the range [\x00-\x7f]
24+
25+
error: no rules expected the token `"\xEF\x80🦀\u{1F980}"`
26+
--> $DIR/non-ascii.rs:9:10
27+
|
28+
LL | c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
29+
| -^^^^^^^^^^^^^^^^^^^^
30+
| |
31+
| no rules expected this token in macro call
32+
| help: missing comma here
33+
|
34+
note: while trying to match `,`
35+
--> $SRC_DIR/core/src/macros/mod.rs:LL:COL
36+
37+
error: aborting due to 4 previous errors
38+

tests/ui/suggestions/issue-71394-no-from-impl.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ LL | let _: &[i8] = data.into();
55
| ^^^^ the trait `From<&[u8]>` is not implemented for `&[i8]`
66
|
77
= help: the following other types implement trait `From<T>`:
8-
<&'input [u8] as From<gimli::read::endian_slice::EndianSlice<'input, Endian>>>
98
<[T; 10] as From<(T, T, T, T, T, T, T, T, T, T)>>
109
<[T; 11] as From<(T, T, T, T, T, T, T, T, T, T, T)>>
1110
<[T; 12] as From<(T, T, T, T, T, T, T, T, T, T, T, T)>>
1211
<[T; 1] as From<(T,)>>
1312
<[T; 2] as From<(T, T)>>
1413
<[T; 3] as From<(T, T, T)>>
1514
<[T; 4] as From<(T, T, T, T)>>
16-
and 7 others
15+
<[T; 5] as From<(T, T, T, T, T)>>
16+
and 6 others
1717
= note: required for `&[u8]` to implement `Into<&[i8]>`
1818

1919
error: aborting due to previous error

0 commit comments

Comments
 (0)