Skip to content

Commit

Permalink
Auto merge of rust-lang#113483 - Mark-Simulacrum:beta-backport, r=Mar…
Browse files Browse the repository at this point in the history
…k-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`
  • Loading branch information
bors committed Jul 8, 2023
2 parents f06c1b8 + df2ddb7 commit 01b5c40
Show file tree
Hide file tree
Showing 20 changed files with 217 additions and 39 deletions.
27 changes: 17 additions & 10 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@ version = 3

[[package]]
name = "addr2line"
version = "0.19.0"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97"
checksum = "6ca9b76e919fd83ccfb509f51b28c333c0e03f2221616e347a129215cec4e4a9"
dependencies = [
"compiler_builtins",
"gimli 0.27.2",
"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 = [
"gimli 0.27.2",
]

[[package]]
name = "adler"
version = "1.0.2"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
]

Expand All @@ -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"
Expand Down Expand Up @@ -4718,7 +4725,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
name = "std"
version = "0.0.0"
dependencies = [
"addr2line",
"addr2line 0.18.0",
"alloc",
"cfg-if",
"compiler_builtins",
Expand Down
18 changes: 16 additions & 2 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
)
}));
}
});
}

Expand Down
7 changes: 0 additions & 7 deletions compiler/rustc_lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/drop_forget_useless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 7 additions & 0 deletions tests/run-make/allocator-shim-circular-deps/Makefile
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions tests/run-make/allocator-shim-circular-deps/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#![crate_type = "bin"]

fn main() {
my_lib::do_something();
}
10 changes: 10 additions & 0 deletions tests/run-make/allocator-shim-circular-deps/my_lib.rs
Original file line number Diff line number Diff line change
@@ -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!");
}
19 changes: 19 additions & 0 deletions tests/ui/lint/dropping_copy_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
19 changes: 19 additions & 0 deletions tests/ui/lint/dropping_references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
4 changes: 3 additions & 1 deletion tests/ui/rfcs/rfc-3348-c-string-literals/basic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// run-pass
// FIXME(c_str_literals): This should be `run-pass`
// known-bug: #113333
// edition: 2021

#![feature(c_str_literals)]

Expand Down
25 changes: 25 additions & 0 deletions tests/ui/rfcs/rfc-3348-c-string-literals/basic.stderr
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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");
}
6 changes: 4 additions & 2 deletions tests/ui/rfcs/rfc-3348-c-string-literals/gate.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// gate-test-c_str_literals
// known-bug: #113333
// edition: 2021

macro_rules! m {
($t:tt) => {}
}

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`
}
35 changes: 23 additions & 12 deletions tests/ui/rfcs/rfc-3348-c-string-literals/gate.stderr
Original file line number Diff line number Diff line change
@@ -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: prefixed identifiers and literals are reserved since Rust 2021
help: consider inserting whitespace here
|
= 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
LL | m!(c "test");
| +

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 2 previous errors
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0658`.
Binary file modified tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.rs
Binary file not shown.
Binary file modified tests/ui/rfcs/rfc-3348-c-string-literals/no-nuls.stderr
Binary file not shown.
4 changes: 3 additions & 1 deletion tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// run-pass
// FIXME(c_str_literals): This should be `run-pass`
// known-bug: #113333
// edition: 2021

#![feature(c_str_literals)]

Expand Down
38 changes: 38 additions & 0 deletions tests/ui/rfcs/rfc-3348-c-string-literals/non-ascii.stderr
Original file line number Diff line number Diff line change
@@ -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

4 changes: 2 additions & 2 deletions tests/ui/suggestions/issue-71394-no-from-impl.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ 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)>>
<[T; 1] as From<(T,)>>
<[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
Expand Down

0 comments on commit 01b5c40

Please sign in to comment.