Skip to content

Commit 077cedc

Browse files
committed
Auto merge of #140040 - ChrisDenton:rollup-56bzfuq, r=ChrisDenton
Rollup of 8 pull requests Successful merges: - #137454 (not lint break with label and unsafe block) - #139297 (Deduplicate & clean up Nix shell) - #139535 (Implement `Default` for raw pointers) - #139919 (Make rustdoc JSON Span column 1-based, just like line numbers) - #139922 (fix incorrect type in cstr `to_string_lossy()` docs) - #140007 (Disable has_thread_local on i686-win7-windows-msvc) - #140016 (std: Use fstatat() on illumos) - #140025 (Re-remove `AdtFlags::IS_ANONYMOUS`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a7c39b6 + 9ebc73e commit 077cedc

File tree

16 files changed

+187
-69
lines changed

16 files changed

+187
-69
lines changed

compiler/rustc_middle/src/ty/adt.rs

-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ bitflags::bitflags! {
5555
const IS_UNSAFE_CELL = 1 << 9;
5656
/// Indicates whether the type is `UnsafePinned`.
5757
const IS_UNSAFE_PINNED = 1 << 10;
58-
/// Indicates whether the type is anonymous.
59-
const IS_ANONYMOUS = 1 << 11;
6058
}
6159
}
6260
rustc_data_structures::external_bitflags_debug! { AdtFlags }

compiler/rustc_parse/src/parser/expr.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1884,13 +1884,15 @@ impl<'a> Parser<'a> {
18841884
let mut expr = self.parse_expr_opt()?;
18851885
if let Some(expr) = &mut expr {
18861886
if label.is_some()
1887-
&& matches!(
1888-
expr.kind,
1887+
&& match &expr.kind {
18891888
ExprKind::While(_, _, None)
1890-
| ExprKind::ForLoop { label: None, .. }
1891-
| ExprKind::Loop(_, None, _)
1892-
| ExprKind::Block(_, None)
1893-
)
1889+
| ExprKind::ForLoop { label: None, .. }
1890+
| ExprKind::Loop(_, None, _) => true,
1891+
ExprKind::Block(block, None) => {
1892+
matches!(block.rules, BlockCheckMode::Default)
1893+
}
1894+
_ => false,
1895+
}
18941896
{
18951897
self.psess.buffer_lint(
18961898
BREAK_WITH_LABEL_AND_LOOP,

compiler/rustc_target/src/spec/targets/i686_win7_windows_msvc.rs

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ pub(crate) fn target() -> Target {
77
base.cpu = "pentium4".into();
88
base.max_atomic_width = Some(64);
99
base.supported_sanitizers = SanitizerSet::ADDRESS;
10+
// On Windows 7 32-bit, the alignment characteristic of the TLS Directory
11+
// don't appear to be respected by the PE Loader, leading to crashes. As
12+
// a result, let's disable has_thread_local to make sure TLS goes through
13+
// the emulation layer.
14+
// See https://github.com/rust-lang/rust/issues/138903
15+
base.has_thread_local = false;
1016

1117
base.add_pre_link_args(
1218
LinkerFlavor::Msvc(Lld::No),

library/alloc/src/ffi/c_str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ impl CStr {
11161116
/// with the corresponding <code>&[str]</code> slice. Otherwise, it will
11171117
/// replace any invalid UTF-8 sequences with
11181118
/// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD] and return a
1119-
/// <code>[Cow]::[Owned]\(&[str])</code> with the result.
1119+
/// <code>[Cow]::[Owned]\([String])</code> with the result.
11201120
///
11211121
/// [str]: prim@str "str"
11221122
/// [Borrowed]: Cow::Borrowed

library/core/src/ptr/const_ptr.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1739,3 +1739,11 @@ impl<T: ?Sized> PartialOrd for *const T {
17391739
*self >= *other
17401740
}
17411741
}
1742+
1743+
#[stable(feature = "raw_ptr_default", since = "CURRENT_RUSTC_VERSION")]
1744+
impl<T: ?Sized + Thin> Default for *const T {
1745+
/// Returns the default value of [`null()`][crate::ptr::null].
1746+
fn default() -> Self {
1747+
crate::ptr::null()
1748+
}
1749+
}

library/core/src/ptr/mut_ptr.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2156,3 +2156,11 @@ impl<T: ?Sized> PartialOrd for *mut T {
21562156
*self >= *other
21572157
}
21582158
}
2159+
2160+
#[stable(feature = "raw_ptr_default", since = "CURRENT_RUSTC_VERSION")]
2161+
impl<T: ?Sized + Thin> Default for *mut T {
2162+
/// Returns the default value of [`null_mut()`][crate::ptr::null_mut].
2163+
fn default() -> Self {
2164+
crate::ptr::null_mut()
2165+
}
2166+
}

library/coretests/tests/ptr.rs

+17
Original file line numberDiff line numberDiff line change
@@ -1020,3 +1020,20 @@ fn test_ptr_swap_nonoverlapping_is_untyped() {
10201020
ptr_swap_nonoverlapping_is_untyped_inner();
10211021
const { ptr_swap_nonoverlapping_is_untyped_inner() };
10221022
}
1023+
1024+
#[test]
1025+
fn test_ptr_default() {
1026+
#[derive(Default)]
1027+
struct PtrDefaultTest {
1028+
ptr: *const u64,
1029+
}
1030+
let default = PtrDefaultTest::default();
1031+
assert!(default.ptr.is_null());
1032+
1033+
#[derive(Default)]
1034+
struct PtrMutDefaultTest {
1035+
ptr: *mut u64,
1036+
}
1037+
let default = PtrMutDefaultTest::default();
1038+
assert!(default.ptr.is_null());
1039+
}

library/std/src/sys/fs/unix.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ use libc::c_char;
1212
all(target_os = "linux", not(target_env = "musl")),
1313
target_os = "android",
1414
target_os = "fuchsia",
15-
target_os = "hurd"
15+
target_os = "hurd",
16+
target_os = "illumos",
1617
))]
1718
use libc::dirfd;
18-
#[cfg(target_os = "fuchsia")]
19+
#[cfg(any(target_os = "fuchsia", target_os = "illumos"))]
1920
use libc::fstatat as fstatat64;
2021
#[cfg(any(all(target_os = "linux", not(target_env = "musl")), target_os = "hurd"))]
2122
use libc::fstatat64;
@@ -892,7 +893,8 @@ impl DirEntry {
892893
all(target_os = "linux", not(target_env = "musl")),
893894
target_os = "android",
894895
target_os = "fuchsia",
895-
target_os = "hurd"
896+
target_os = "hurd",
897+
target_os = "illumos",
896898
),
897899
not(miri) // no dirfd on Miri
898900
))]
@@ -922,6 +924,7 @@ impl DirEntry {
922924
target_os = "android",
923925
target_os = "fuchsia",
924926
target_os = "hurd",
927+
target_os = "illumos",
925928
)),
926929
miri
927930
))]

src/librustdoc/json/conversions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ impl JsonRenderer<'_> {
8484
let lo = span.lo(self.sess());
8585
Some(Span {
8686
filename: local_path,
87-
begin: (lo.line, lo.col.to_usize()),
88-
end: (hi.line, hi.col.to_usize()),
87+
begin: (lo.line, lo.col.to_usize() + 1),
88+
end: (hi.line, hi.col.to_usize() + 1),
8989
})
9090
} else {
9191
None

src/rustdoc-json-types/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc
3030
/// This integer is incremented with every breaking change to the API,
3131
/// and is returned along with the JSON blob as [`Crate::format_version`].
3232
/// Consuming code should assert that this value matches the format version(s) that it supports.
33-
pub const FORMAT_VERSION: u32 = 44;
33+
pub const FORMAT_VERSION: u32 = 45;
3434

3535
/// The root of the emitted JSON blob.
3636
///
@@ -205,9 +205,9 @@ pub struct Item {
205205
pub struct Span {
206206
/// The path to the source file for this span relative to the path `rustdoc` was invoked with.
207207
pub filename: PathBuf,
208-
/// Zero indexed Line and Column of the first character of the `Span`
208+
/// One indexed Line and Column of the first character of the `Span`.
209209
pub begin: (usize, usize),
210-
/// Zero indexed Line and Column of the last character of the `Span`
210+
/// One indexed Line and Column of the last character of the `Span`.
211211
pub end: (usize, usize),
212212
}
213213

src/tools/nix-dev-shell/flake.nix

+19-27
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,24 @@
11
{
22
description = "rustc dev shell";
33

4-
inputs = {
5-
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6-
flake-utils.url = "github:numtide/flake-utils";
7-
};
4+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
85

9-
outputs = { self, nixpkgs, flake-utils, ... }:
10-
flake-utils.lib.eachDefaultSystem (system:
11-
let
12-
pkgs = import nixpkgs { inherit system; };
13-
x = import ./x { inherit pkgs; };
14-
in
15-
{
16-
devShells.default = with pkgs; mkShell {
17-
name = "rustc-dev-shell";
18-
nativeBuildInputs = with pkgs; [
19-
binutils cmake ninja pkg-config python3 git curl cacert patchelf nix
20-
];
21-
buildInputs = with pkgs; [
22-
openssl glibc.out glibc.static x
23-
];
24-
# Avoid creating text files for ICEs.
25-
RUSTC_ICE = "0";
26-
# Provide `libstdc++.so.6` for the self-contained lld.
27-
# Provide `libz.so.1`.
28-
LD_LIBRARY_PATH = "${with pkgs; lib.makeLibraryPath [stdenv.cc.cc.lib zlib]}";
29-
};
30-
}
31-
);
6+
outputs =
7+
{
8+
self,
9+
nixpkgs,
10+
}:
11+
let
12+
inherit (nixpkgs) lib;
13+
forEachSystem = lib.genAttrs lib.systems.flakeExposed;
14+
in
15+
{
16+
devShells = forEachSystem (system: {
17+
default = nixpkgs.legacyPackages.${system}.callPackage ./shell.nix { };
18+
});
19+
20+
packages = forEachSystem (system: {
21+
default = nixpkgs.legacyPackages.${system}.callPackage ./x { };
22+
});
23+
};
3224
}

src/tools/nix-dev-shell/shell.nix

+23-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
{ pkgs ? import <nixpkgs> {} }:
2-
let
3-
x = import ./x { inherit pkgs; };
1+
{
2+
pkgs ? import <nixpkgs> { },
3+
}:
4+
let
5+
inherit (pkgs.lib) lists attrsets;
6+
7+
x = pkgs.callPackage ./x { };
8+
inherit (x.passthru) cacert env;
49
in
510
pkgs.mkShell {
6-
name = "rustc";
7-
nativeBuildInputs = with pkgs; [
8-
binutils cmake ninja pkg-config python3 git curl cacert patchelf nix
9-
];
10-
buildInputs = with pkgs; [
11-
openssl glibc.out glibc.static x
12-
];
13-
# Avoid creating text files for ICEs.
14-
RUSTC_ICE = "0";
15-
# Provide `libstdc++.so.6` for the self-contained lld.
16-
# Provide `libz.so.1`
17-
LD_LIBRARY_PATH = "${with pkgs; lib.makeLibraryPath [stdenv.cc.cc.lib zlib]}";
11+
name = "rustc-shell";
12+
13+
inputsFrom = [ x ];
14+
packages = [
15+
pkgs.git
16+
pkgs.nix
17+
x
18+
# Get the runtime deps of the x wrapper
19+
] ++ lists.flatten (attrsets.attrValues env);
20+
21+
env = {
22+
# Avoid creating text files for ICEs.
23+
RUSTC_ICE = 0;
24+
SSL_CERT_FILE = cacert;
25+
};
1826
}

src/tools/nix-dev-shell/x/default.nix

+69-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,83 @@
11
{
2-
pkgs ? import <nixpkgs> { },
2+
pkgs,
3+
lib,
4+
stdenv,
5+
rustc,
6+
python3,
7+
makeBinaryWrapper,
8+
# Bootstrap
9+
curl,
10+
pkg-config,
11+
libiconv,
12+
openssl,
13+
patchelf,
14+
cacert,
15+
zlib,
16+
# LLVM Deps
17+
ninja,
18+
cmake,
19+
glibc,
320
}:
4-
pkgs.stdenv.mkDerivation {
5-
name = "x";
21+
stdenv.mkDerivation (self: {
22+
strictDeps = true;
23+
name = "x-none";
24+
25+
outputs = [
26+
"out"
27+
"unwrapped"
28+
];
629

730
src = ./x.rs;
831
dontUnpack = true;
932

10-
nativeBuildInputs = with pkgs; [ rustc ];
33+
nativeBuildInputs = [
34+
rustc
35+
makeBinaryWrapper
36+
];
1137

38+
env.PYTHON = python3.interpreter;
1239
buildPhase = ''
13-
PYTHON=${pkgs.lib.getExe pkgs.python3} rustc -Copt-level=3 --crate-name x $src --out-dir $out/bin
40+
rustc -Copt-level=3 --crate-name x $src --out-dir $unwrapped/bin
1441
'';
1542

16-
meta = with pkgs.lib; {
43+
installPhase =
44+
let
45+
inherit (self.passthru) cacert env;
46+
in
47+
''
48+
makeWrapper $unwrapped/bin/x $out/bin/x \
49+
--set-default SSL_CERT_FILE ${cacert} \
50+
--prefix CPATH ";" "${lib.makeSearchPath "include" env.cpath}" \
51+
--prefix PATH : ${lib.makeBinPath env.path} \
52+
--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath env.ldLib}
53+
'';
54+
55+
# For accessing them in the devshell
56+
passthru = {
57+
env = {
58+
cpath = [ libiconv ];
59+
path = [
60+
python3
61+
patchelf
62+
curl
63+
pkg-config
64+
cmake
65+
ninja
66+
stdenv.cc
67+
];
68+
ldLib = [
69+
openssl
70+
zlib
71+
stdenv.cc.cc.lib
72+
];
73+
};
74+
cacert = "${cacert}/etc/ssl/certs/ca-bundle.crt";
75+
};
76+
77+
meta = {
1778
description = "Helper for rust-lang/rust x.py";
1879
homepage = "https://github.com/rust-lang/rust/blob/master/src/tools/x";
19-
license = licenses.mit;
80+
license = lib.licenses.mit;
2081
mainProgram = "x";
2182
};
22-
}
83+
})

tests/rustdoc-json/impls/auto.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ impl Foo {
1515
}
1616

1717
// Testing spans, so all tests below code
18-
//@ is "$.index[?(@.docs=='has span')].span.begin" "[13, 0]"
19-
//@ is "$.index[?(@.docs=='has span')].span.end" "[15, 1]"
18+
//@ is "$.index[?(@.docs=='has span')].span.begin" "[13, 1]"
19+
//@ is "$.index[?(@.docs=='has span')].span.end" "[15, 2]"
2020
// FIXME: this doesn't work due to https://github.com/freestrings/jsonpath/issues/91
2121
// is "$.index[?(@.inner.impl.is_synthetic==true)].span" null
2222
pub struct Foo;

tests/rustdoc-json/span.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pub mod bar {}
2+
// This test ensures that spans are 1-indexed.
3+
//@ is "$.index[?(@.name=='span')].span.begin" "[1, 1]"
4+
//@ is "$.index[?(@.name=='bar')].span.begin" "[1, 1]"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ check-pass
2+
3+
#![deny(break_with_label_and_loop)]
4+
5+
unsafe fn foo() -> i32 { 42 }
6+
7+
fn main () {
8+
'label: loop {
9+
break 'label unsafe { foo() }
10+
};
11+
}

0 commit comments

Comments
 (0)