Auto merge of #113483 - Mark-Simulacrum:beta-backport, r=Mark-Simulacrum
[beta] backport This PR backports: - #113334: Revert the lexing of `c"…"` string literals - #113231: Fix `dropping_copy_types` lint from linting in match-arm with side-effects - #112794: Fix linker failures when #[global_allocator] is used in a dependency r? `@Mark-Simulacrum`
This commit is contained in:
commit
01b5c40dc1
20 changed files with 217 additions and 39 deletions
27
Cargo.lock
27
Cargo.lock
|
|
@ -2,16 +2,25 @@
|
|||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "addr2line"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ca9b76e919fd83ccfb509f51b28c333c0e03f2221616e347a129215cec4e4a9"
|
||||
dependencies = [
|
||||
"compiler_builtins",
|
||||
"gimli 0.26.2",
|
||||
"rustc-std-workspace-alloc",
|
||||
"rustc-std-workspace-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "addr2line"
|
||||
version = "0.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97"
|
||||
dependencies = [
|
||||
"compiler_builtins",
|
||||
"gimli 0.27.2",
|
||||
"rustc-std-workspace-alloc",
|
||||
"rustc-std-workspace-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -228,7 +237,7 @@ version = "0.3.67"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca"
|
||||
dependencies = [
|
||||
"addr2line",
|
||||
"addr2line 0.19.0",
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
|
|
@ -1524,8 +1533,11 @@ version = "0.26.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d"
|
||||
dependencies = [
|
||||
"compiler_builtins",
|
||||
"fallible-iterator",
|
||||
"indexmap",
|
||||
"rustc-std-workspace-alloc",
|
||||
"rustc-std-workspace-core",
|
||||
"stable_deref_trait",
|
||||
]
|
||||
|
||||
|
|
@ -1534,11 +1546,6 @@ name = "gimli"
|
|||
version = "0.27.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4"
|
||||
dependencies = [
|
||||
"compiler_builtins",
|
||||
"rustc-std-workspace-alloc",
|
||||
"rustc-std-workspace-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
|
|
@ -4718,7 +4725,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
|||
name = "std"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"addr2line",
|
||||
"addr2line 0.18.0",
|
||||
"alloc",
|
||||
"cfg-if",
|
||||
"compiler_builtins",
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use crate::mir::place::PlaceRef;
|
|||
use crate::traits::*;
|
||||
use crate::{CachedModuleCodegen, CompiledModule, CrateInfo, MemFlags, ModuleCodegen, ModuleKind};
|
||||
|
||||
use rustc_ast::expand::allocator::AllocatorKind;
|
||||
use rustc_ast::expand::allocator::{global_fn_name, AllocatorKind, ALLOCATOR_METHODS};
|
||||
use rustc_attr as attr;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
|
||||
|
|
@ -909,7 +909,21 @@ impl CrateInfo {
|
|||
missing_weak_lang_items
|
||||
.iter()
|
||||
.map(|item| (format!("{prefix}{item}"), SymbolExportKind::Text)),
|
||||
)
|
||||
);
|
||||
if tcx.allocator_kind(()).is_some() {
|
||||
// At least one crate needs a global allocator. This crate may be placed
|
||||
// after the crate that defines it in the linker order, in which case some
|
||||
// linkers return an error. By adding the global allocator shim methods to
|
||||
// the linked_symbols list, linking the generated symbols.o will ensure that
|
||||
// circular dependencies involving the global allocator don't lead to linker
|
||||
// errors.
|
||||
linked_symbols.extend(ALLOCATOR_METHODS.iter().map(|method| {
|
||||
(
|
||||
format!("{prefix}{}", global_fn_name(method.name).as_str()),
|
||||
SymbolExportKind::Text,
|
||||
)
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -367,13 +367,6 @@ impl Cursor<'_> {
|
|||
Some(|terminated| Byte { terminated }),
|
||||
),
|
||||
|
||||
// c-string literal, raw c-string literal or identifier.
|
||||
'c' => self.c_or_byte_string(
|
||||
|terminated| CStr { terminated },
|
||||
|n_hashes| RawCStr { n_hashes },
|
||||
None,
|
||||
),
|
||||
|
||||
// Identifier (this should be checked after other variant that can
|
||||
// start as identifier).
|
||||
c if is_id_start(c) => self.ident_or_unknown_prefix(),
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ fn is_single_call_in_arm<'tcx>(
|
|||
arg: &'tcx Expr<'_>,
|
||||
drop_expr: &'tcx Expr<'_>,
|
||||
) -> bool {
|
||||
if matches!(arg.kind, ExprKind::Call(..) | ExprKind::MethodCall(..)) {
|
||||
if arg.can_have_side_effects() {
|
||||
let parent_node = cx.tcx.hir().find_parent(drop_expr.hir_id);
|
||||
if let Some(Node::Arm(Arm { body, .. })) = &parent_node {
|
||||
return body.hir_id == drop_expr.hir_id;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ hashbrown = { version = "0.13", default-features = false, features = ['rustc-dep
|
|||
std_detect = { path = "../stdarch/crates/std_detect", default-features = false, features = ['rustc-dep-of-std'] }
|
||||
|
||||
# Dependencies of the `backtrace` crate
|
||||
addr2line = { version = "0.19.0", optional = true, default-features = false }
|
||||
addr2line = { version = "0.18.0", optional = true, default-features = false }
|
||||
rustc-demangle = { version = "0.1.21", features = ['rustc-dep-of-std'] }
|
||||
miniz_oxide = { version = "0.6.0", optional = true, default-features = false }
|
||||
[dependencies.object]
|
||||
|
|
|
|||
7
tests/run-make/allocator-shim-circular-deps/Makefile
Normal file
7
tests/run-make/allocator-shim-circular-deps/Makefile
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# ignore-cross-compile
|
||||
include ../tools.mk
|
||||
|
||||
all:
|
||||
rm -rf $(TMPDIR) && mkdir $(TMPDIR)
|
||||
$(RUSTC) my_lib.rs
|
||||
$(RUSTC) main.rs --test --extern my_lib=$(TMPDIR)/libmy_lib.rlib
|
||||
5
tests/run-make/allocator-shim-circular-deps/main.rs
Normal file
5
tests/run-make/allocator-shim-circular-deps/main.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#![crate_type = "bin"]
|
||||
|
||||
fn main() {
|
||||
my_lib::do_something();
|
||||
}
|
||||
10
tests/run-make/allocator-shim-circular-deps/my_lib.rs
Normal file
10
tests/run-make/allocator-shim-circular-deps/my_lib.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#![crate_type = "lib"]
|
||||
|
||||
use std::alloc::System;
|
||||
|
||||
#[global_allocator]
|
||||
static ALLOCATOR: System = System;
|
||||
|
||||
pub fn do_something() {
|
||||
format!("allocating a string!");
|
||||
}
|
||||
|
|
@ -77,3 +77,22 @@ fn issue9482(x: u8) {
|
|||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn issue112653() {
|
||||
fn foo() -> Result<u8, ()> {
|
||||
println!("doing foo");
|
||||
Ok(0) // result is not always useful, the side-effect matters
|
||||
}
|
||||
fn bar() {
|
||||
println!("doing bar");
|
||||
}
|
||||
|
||||
fn stuff() -> Result<(), ()> {
|
||||
match 42 {
|
||||
0 => drop(foo()?), // drop is needed because we only care about side-effects
|
||||
1 => bar(),
|
||||
_ => (), // doing nothing (no side-effects needed here)
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,3 +97,22 @@ fn issue10122(x: u8) {
|
|||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn issue112653() {
|
||||
fn foo() -> Result<&'static u8, ()> {
|
||||
println!("doing foo");
|
||||
Ok(&0) // result is not always useful, the side-effect matters
|
||||
}
|
||||
fn bar() {
|
||||
println!("doing bar");
|
||||
}
|
||||
|
||||
fn stuff() -> Result<(), ()> {
|
||||
match 42 {
|
||||
0 => drop(foo()?), // drop is needed because we only care about side-effects
|
||||
1 => bar(),
|
||||
_ => (), // doing nothing (no side-effects needed here)
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
// run-pass
|
||||
// FIXME(c_str_literals): This should be `run-pass`
|
||||
// known-bug: #113333
|
||||
// edition: 2021
|
||||
|
||||
#![feature(c_str_literals)]
|
||||
|
||||
|
|
|
|||
25
tests/ui/rfcs/rfc-3348-c-string-literals/basic.stderr
Normal file
25
tests/ui/rfcs/rfc-3348-c-string-literals/basic.stderr
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
error: prefix `c` is unknown
|
||||
--> $DIR/basic.rs:8:27
|
||||
|
|
||||
LL | assert_eq!(b"test\0", c"test".to_bytes_with_nul());
|
||||
| ^ unknown prefix
|
||||
|
|
||||
= note: prefixed identifiers and literals are reserved since Rust 2021
|
||||
help: consider inserting whitespace here
|
||||
|
|
||||
LL | assert_eq!(b"test\0", c "test".to_bytes_with_nul());
|
||||
| +
|
||||
|
||||
error: no rules expected the token `"test"`
|
||||
--> $DIR/basic.rs:8:28
|
||||
|
|
||||
LL | assert_eq!(b"test\0", c"test".to_bytes_with_nul());
|
||||
| -^^^^^
|
||||
| |
|
||||
| no rules expected this token in macro call
|
||||
| help: missing comma here
|
||||
|
|
||||
= note: while trying to match sequence start
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
// Regression test for issue #113235.
|
||||
|
||||
// check-pass
|
||||
// revisions: edition2015 edition2018
|
||||
//[edition2015] edition: 2015
|
||||
//[edition2018] edition: 2018
|
||||
|
||||
// Make sure that in pre-2021 editions we continue to parse the snippet
|
||||
// `c"hello"` as an identifier followed by a (normal) string literal and
|
||||
// allow the code below to compile.
|
||||
// Prefixes including `c` as used by C string literals are only reserved
|
||||
// in edition 2021 and onward.
|
||||
//
|
||||
// Consider checking out rust-2021/reserved-prefixes-migration.rs as well.
|
||||
|
||||
macro_rules! parse {
|
||||
(c $e:expr) => {
|
||||
$e
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _: &'static str = parse!(c"hello");
|
||||
}
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
// gate-test-c_str_literals
|
||||
// known-bug: #113333
|
||||
// edition: 2021
|
||||
|
||||
macro_rules! m {
|
||||
($t:tt) => {}
|
||||
|
|
@ -6,8 +8,8 @@ macro_rules! m {
|
|||
|
||||
fn main() {
|
||||
c"foo";
|
||||
//~^ ERROR: `c".."` literals are experimental
|
||||
// FIXME(c_str_literals): This should be ``c".."` literals are experimental`
|
||||
|
||||
m!(c"test");
|
||||
//~^ ERROR: `c".."` literals are experimental
|
||||
// FIXME(c_str_literals): This should be ``c".."` literals are experimental`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,32 @@
|
|||
error[E0658]: `c".."` literals are experimental
|
||||
--> $DIR/gate.rs:8:5
|
||||
error: prefix `c` is unknown
|
||||
--> $DIR/gate.rs:10:5
|
||||
|
|
||||
LL | c"foo";
|
||||
| ^^^^^^
|
||||
| ^ unknown prefix
|
||||
|
|
||||
= note: see issue #105723 <https://github.com/rust-lang/rust/issues/105723> for more information
|
||||
= help: add `#![feature(c_str_literals)]` to the crate attributes to enable
|
||||
= note: prefixed identifiers and literals are reserved since Rust 2021
|
||||
help: consider inserting whitespace here
|
||||
|
|
||||
LL | c "foo";
|
||||
| +
|
||||
|
||||
error[E0658]: `c".."` literals are experimental
|
||||
--> $DIR/gate.rs:11:8
|
||||
error: prefix `c` is unknown
|
||||
--> $DIR/gate.rs:13:8
|
||||
|
|
||||
LL | m!(c"test");
|
||||
| ^^^^^^^
|
||||
| ^ unknown prefix
|
||||
|
|
||||
= note: see issue #105723 <https://github.com/rust-lang/rust/issues/105723> for more information
|
||||
= help: add `#![feature(c_str_literals)]` to the crate attributes to enable
|
||||
= note: prefixed identifiers and literals are reserved since Rust 2021
|
||||
help: consider inserting whitespace here
|
||||
|
|
||||
LL | m!(c "test");
|
||||
| +
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `"foo"`
|
||||
--> $DIR/gate.rs:10:6
|
||||
|
|
||||
LL | c"foo";
|
||||
| ^^^^^ expected one of 8 possible tokens
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
|
@ -1,4 +1,6 @@
|
|||
// run-pass
|
||||
// FIXME(c_str_literals): This should be `run-pass`
|
||||
// known-bug: #113333
|
||||
// edition: 2021
|
||||
|
||||
#![feature(c_str_literals)]
|
||||
|
||||
|
|
|
|||
38
tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.stderr
Normal file
38
tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.stderr
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
error: prefix `c` is unknown
|
||||
--> $DIR/non-ascii.rs:9:9
|
||||
|
|
||||
LL | c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
|
||||
| ^ unknown prefix
|
||||
|
|
||||
= note: prefixed identifiers and literals are reserved since Rust 2021
|
||||
help: consider inserting whitespace here
|
||||
|
|
||||
LL | c "\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
|
||||
| +
|
||||
|
||||
error: out of range hex escape
|
||||
--> $DIR/non-ascii.rs:9:11
|
||||
|
|
||||
LL | c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
|
||||
| ^^^^ must be a character in the range [\x00-\x7f]
|
||||
|
||||
error: out of range hex escape
|
||||
--> $DIR/non-ascii.rs:9:15
|
||||
|
|
||||
LL | c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
|
||||
| ^^^^ must be a character in the range [\x00-\x7f]
|
||||
|
||||
error: no rules expected the token `"\xEF\x80🦀\u{1F980}"`
|
||||
--> $DIR/non-ascii.rs:9:10
|
||||
|
|
||||
LL | c"\xEF\x80🦀\u{1F980}".to_bytes_with_nul(),
|
||||
| -^^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| no rules expected this token in macro call
|
||||
| help: missing comma here
|
||||
|
|
||||
note: while trying to match `,`
|
||||
--> $SRC_DIR/core/src/macros/mod.rs:LL:COL
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
@ -5,7 +5,6 @@ LL | let _: &[i8] = data.into();
|
|||
| ^^^^ the trait `From<&[u8]>` is not implemented for `&[i8]`
|
||||
|
|
||||
= help: the following other types implement trait `From<T>`:
|
||||
<&'input [u8] as From<gimli::read::endian_slice::EndianSlice<'input, Endian>>>
|
||||
<[T; 10] as From<(T, T, T, T, T, T, T, T, T, T)>>
|
||||
<[T; 11] as From<(T, T, T, T, T, T, T, T, T, T, T)>>
|
||||
<[T; 12] as From<(T, T, T, T, T, T, T, T, T, T, T, T)>>
|
||||
|
|
@ -13,7 +12,8 @@ LL | let _: &[i8] = data.into();
|
|||
<[T; 2] as From<(T, T)>>
|
||||
<[T; 3] as From<(T, T, T)>>
|
||||
<[T; 4] as From<(T, T, T, T)>>
|
||||
and 7 others
|
||||
<[T; 5] as From<(T, T, T, T, T)>>
|
||||
and 6 others
|
||||
= note: required for `&[u8]` to implement `Into<&[i8]>`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue