Skip to content

Rollup of 8 pull requests #140040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Apr 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
3fe0b3d
not lint break with label and unsafe block
mu001999 Feb 23, 2025
830bd8b
Implement Default for raw pointers
ChrisDenton Apr 6, 2025
2f0ba67
fix incorrect type in cstr `to_string_lossy()` docs
jnqnfe Apr 16, 2025
5a38550
Deduplicate nix code
RossSmyth Apr 3, 2025
1b39302
Disable has_thread_local on i686-win7-windows-msvc
roblabla Apr 18, 2025
59477a8
Make rustdoc JSON Span column 1-based, just like line numbers
GuillaumeGomez Apr 16, 2025
ba9a008
Add regression test for span 1-indexed check
GuillaumeGomez Apr 16, 2025
076016d
Update rustdoc-json-types `FORMAT_VERSION` to 45
GuillaumeGomez Apr 18, 2025
fb3cae0
std: Use fstatat() on illumos
pfmooney Apr 18, 2025
d863f81
Re-remove `AdtFlags::IS_ANONYMOUS`
Sky9x Apr 19, 2025
db98b72
Rollup merge of #137454 - mu001999-contrib:fix-137414, r=wesleywiser
ChrisDenton Apr 19, 2025
103be60
Rollup merge of #139297 - RossSmyth:NixClean, r=WaffleLapkin
ChrisDenton Apr 19, 2025
dff14f0
Rollup merge of #139535 - ChrisDenton:default-ptr, r=tgross35
ChrisDenton Apr 19, 2025
d49361a
Rollup merge of #139919 - GuillaumeGomez:rustdoc-json-1-indexed, r=aD…
ChrisDenton Apr 19, 2025
3c5aef3
Rollup merge of #139922 - jnqnfe:cstr_doc_fix, r=jhpratt
ChrisDenton Apr 19, 2025
67a97ba
Rollup merge of #140007 - roblabla:fix-win7, r=ChrisDenton
ChrisDenton Apr 19, 2025
9951149
Rollup merge of #140016 - pfmooney:illumos-fstatat, r=jhpratt
ChrisDenton Apr 19, 2025
9ebc73e
Rollup merge of #140025 - Sky9x:re-remove-adtflags-anon, r=compiler-e…
ChrisDenton Apr 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions compiler/rustc_middle/src/ty/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ bitflags::bitflags! {
const IS_UNSAFE_CELL = 1 << 9;
/// Indicates whether the type is `UnsafePinned`.
const IS_UNSAFE_PINNED = 1 << 10;
/// Indicates whether the type is anonymous.
const IS_ANONYMOUS = 1 << 11;
}
}
rustc_data_structures::external_bitflags_debug! { AdtFlags }
Expand Down
14 changes: 8 additions & 6 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1884,13 +1884,15 @@ impl<'a> Parser<'a> {
let mut expr = self.parse_expr_opt()?;
if let Some(expr) = &mut expr {
if label.is_some()
&& matches!(
expr.kind,
&& match &expr.kind {
ExprKind::While(_, _, None)
| ExprKind::ForLoop { label: None, .. }
| ExprKind::Loop(_, None, _)
| ExprKind::Block(_, None)
)
| ExprKind::ForLoop { label: None, .. }
| ExprKind::Loop(_, None, _) => true,
ExprKind::Block(block, None) => {
matches!(block.rules, BlockCheckMode::Default)
}
_ => false,
}
{
self.psess.buffer_lint(
BREAK_WITH_LABEL_AND_LOOP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ pub(crate) fn target() -> Target {
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.supported_sanitizers = SanitizerSet::ADDRESS;
// On Windows 7 32-bit, the alignment characteristic of the TLS Directory
// don't appear to be respected by the PE Loader, leading to crashes. As
// a result, let's disable has_thread_local to make sure TLS goes through
// the emulation layer.
// See https://github.com/rust-lang/rust/issues/138903
base.has_thread_local = false;

base.add_pre_link_args(
LinkerFlavor::Msvc(Lld::No),
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ impl CStr {
/// with the corresponding <code>&[str]</code> slice. Otherwise, it will
/// replace any invalid UTF-8 sequences with
/// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD] and return a
/// <code>[Cow]::[Owned]\(&[str])</code> with the result.
/// <code>[Cow]::[Owned]\([String])</code> with the result.
///
/// [str]: prim@str "str"
/// [Borrowed]: Cow::Borrowed
Expand Down
8 changes: 8 additions & 0 deletions library/core/src/ptr/const_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1739,3 +1739,11 @@ impl<T: ?Sized> PartialOrd for *const T {
*self >= *other
}
}

#[stable(feature = "raw_ptr_default", since = "CURRENT_RUSTC_VERSION")]
impl<T: ?Sized + Thin> Default for *const T {
/// Returns the default value of [`null()`][crate::ptr::null].
fn default() -> Self {
crate::ptr::null()
}
}
8 changes: 8 additions & 0 deletions library/core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2156,3 +2156,11 @@ impl<T: ?Sized> PartialOrd for *mut T {
*self >= *other
}
}

#[stable(feature = "raw_ptr_default", since = "CURRENT_RUSTC_VERSION")]
impl<T: ?Sized + Thin> Default for *mut T {
/// Returns the default value of [`null_mut()`][crate::ptr::null_mut].
fn default() -> Self {
crate::ptr::null_mut()
}
}
17 changes: 17 additions & 0 deletions library/coretests/tests/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,3 +1020,20 @@ fn test_ptr_swap_nonoverlapping_is_untyped() {
ptr_swap_nonoverlapping_is_untyped_inner();
const { ptr_swap_nonoverlapping_is_untyped_inner() };
}

#[test]
fn test_ptr_default() {
#[derive(Default)]
struct PtrDefaultTest {
ptr: *const u64,
}
let default = PtrDefaultTest::default();
assert!(default.ptr.is_null());

#[derive(Default)]
struct PtrMutDefaultTest {
ptr: *mut u64,
}
let default = PtrMutDefaultTest::default();
assert!(default.ptr.is_null());
}
9 changes: 6 additions & 3 deletions library/std/src/sys/fs/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ use libc::c_char;
all(target_os = "linux", not(target_env = "musl")),
target_os = "android",
target_os = "fuchsia",
target_os = "hurd"
target_os = "hurd",
target_os = "illumos",
))]
use libc::dirfd;
#[cfg(target_os = "fuchsia")]
#[cfg(any(target_os = "fuchsia", target_os = "illumos"))]
use libc::fstatat as fstatat64;
#[cfg(any(all(target_os = "linux", not(target_env = "musl")), target_os = "hurd"))]
use libc::fstatat64;
Expand Down Expand Up @@ -892,7 +893,8 @@ impl DirEntry {
all(target_os = "linux", not(target_env = "musl")),
target_os = "android",
target_os = "fuchsia",
target_os = "hurd"
target_os = "hurd",
target_os = "illumos",
),
not(miri) // no dirfd on Miri
))]
Expand Down Expand Up @@ -922,6 +924,7 @@ impl DirEntry {
target_os = "android",
target_os = "fuchsia",
target_os = "hurd",
target_os = "illumos",
)),
miri
))]
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ impl JsonRenderer<'_> {
let lo = span.lo(self.sess());
Some(Span {
filename: local_path,
begin: (lo.line, lo.col.to_usize()),
end: (hi.line, hi.col.to_usize()),
begin: (lo.line, lo.col.to_usize() + 1),
end: (hi.line, hi.col.to_usize() + 1),
})
} else {
None
Expand Down
6 changes: 3 additions & 3 deletions src/rustdoc-json-types/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc
/// This integer is incremented with every breaking change to the API,
/// and is returned along with the JSON blob as [`Crate::format_version`].
/// Consuming code should assert that this value matches the format version(s) that it supports.
pub const FORMAT_VERSION: u32 = 44;
pub const FORMAT_VERSION: u32 = 45;

/// The root of the emitted JSON blob.
///
Expand Down Expand Up @@ -205,9 +205,9 @@ pub struct Item {
pub struct Span {
/// The path to the source file for this span relative to the path `rustdoc` was invoked with.
pub filename: PathBuf,
/// Zero indexed Line and Column of the first character of the `Span`
/// One indexed Line and Column of the first character of the `Span`.
pub begin: (usize, usize),
/// Zero indexed Line and Column of the last character of the `Span`
/// One indexed Line and Column of the last character of the `Span`.
pub end: (usize, usize),
}

Expand Down
46 changes: 19 additions & 27 deletions src/tools/nix-dev-shell/flake.nix
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
{
description = "rustc dev shell";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

outputs = { self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
x = import ./x { inherit pkgs; };
in
{
devShells.default = with pkgs; mkShell {
name = "rustc-dev-shell";
nativeBuildInputs = with pkgs; [
binutils cmake ninja pkg-config python3 git curl cacert patchelf nix
];
buildInputs = with pkgs; [
openssl glibc.out glibc.static x
];
# Avoid creating text files for ICEs.
RUSTC_ICE = "0";
# Provide `libstdc++.so.6` for the self-contained lld.
# Provide `libz.so.1`.
LD_LIBRARY_PATH = "${with pkgs; lib.makeLibraryPath [stdenv.cc.cc.lib zlib]}";
};
}
);
outputs =
{
self,
nixpkgs,
}:
let
inherit (nixpkgs) lib;
forEachSystem = lib.genAttrs lib.systems.flakeExposed;
in
{
devShells = forEachSystem (system: {
default = nixpkgs.legacyPackages.${system}.callPackage ./shell.nix { };
});

packages = forEachSystem (system: {
default = nixpkgs.legacyPackages.${system}.callPackage ./x { };
});
};
}
38 changes: 23 additions & 15 deletions src/tools/nix-dev-shell/shell.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
{ pkgs ? import <nixpkgs> {} }:
let
x = import ./x { inherit pkgs; };
{
pkgs ? import <nixpkgs> { },
}:
let
inherit (pkgs.lib) lists attrsets;

x = pkgs.callPackage ./x { };
inherit (x.passthru) cacert env;
in
pkgs.mkShell {
name = "rustc";
nativeBuildInputs = with pkgs; [
binutils cmake ninja pkg-config python3 git curl cacert patchelf nix
];
buildInputs = with pkgs; [
openssl glibc.out glibc.static x
];
# Avoid creating text files for ICEs.
RUSTC_ICE = "0";
# Provide `libstdc++.so.6` for the self-contained lld.
# Provide `libz.so.1`
LD_LIBRARY_PATH = "${with pkgs; lib.makeLibraryPath [stdenv.cc.cc.lib zlib]}";
name = "rustc-shell";

inputsFrom = [ x ];
packages = [
pkgs.git
pkgs.nix
x
# Get the runtime deps of the x wrapper
] ++ lists.flatten (attrsets.attrValues env);

env = {
# Avoid creating text files for ICEs.
RUSTC_ICE = 0;
SSL_CERT_FILE = cacert;
};
}
77 changes: 69 additions & 8 deletions src/tools/nix-dev-shell/x/default.nix
Original file line number Diff line number Diff line change
@@ -1,22 +1,83 @@
{
pkgs ? import <nixpkgs> { },
pkgs,
lib,
stdenv,
rustc,
python3,
makeBinaryWrapper,
# Bootstrap
curl,
pkg-config,
libiconv,
openssl,
patchelf,
cacert,
zlib,
# LLVM Deps
ninja,
cmake,
glibc,
}:
pkgs.stdenv.mkDerivation {
name = "x";
stdenv.mkDerivation (self: {
strictDeps = true;
name = "x-none";

outputs = [
"out"
"unwrapped"
];

src = ./x.rs;
dontUnpack = true;

nativeBuildInputs = with pkgs; [ rustc ];
nativeBuildInputs = [
rustc
makeBinaryWrapper
];

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

meta = with pkgs.lib; {
installPhase =
let
inherit (self.passthru) cacert env;
in
''
makeWrapper $unwrapped/bin/x $out/bin/x \
--set-default SSL_CERT_FILE ${cacert} \
--prefix CPATH ";" "${lib.makeSearchPath "include" env.cpath}" \
--prefix PATH : ${lib.makeBinPath env.path} \
--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath env.ldLib}
'';

# For accessing them in the devshell
passthru = {
env = {
cpath = [ libiconv ];
path = [
python3
patchelf
curl
pkg-config
cmake
ninja
stdenv.cc
];
ldLib = [
openssl
zlib
stdenv.cc.cc.lib
];
};
cacert = "${cacert}/etc/ssl/certs/ca-bundle.crt";
};

meta = {
description = "Helper for rust-lang/rust x.py";
homepage = "https://github.com/rust-lang/rust/blob/master/src/tools/x";
license = licenses.mit;
license = lib.licenses.mit;
mainProgram = "x";
};
}
})
4 changes: 2 additions & 2 deletions tests/rustdoc-json/impls/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ impl Foo {
}

// Testing spans, so all tests below code
//@ is "$.index[?(@.docs=='has span')].span.begin" "[13, 0]"
//@ is "$.index[?(@.docs=='has span')].span.end" "[15, 1]"
//@ is "$.index[?(@.docs=='has span')].span.begin" "[13, 1]"
//@ is "$.index[?(@.docs=='has span')].span.end" "[15, 2]"
// FIXME: this doesn't work due to https://github.com/freestrings/jsonpath/issues/91
// is "$.index[?(@.inner.impl.is_synthetic==true)].span" null
pub struct Foo;
4 changes: 4 additions & 0 deletions tests/rustdoc-json/span.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod bar {}
// This test ensures that spans are 1-indexed.
//@ is "$.index[?(@.name=='span')].span.begin" "[1, 1]"
//@ is "$.index[?(@.name=='bar')].span.begin" "[1, 1]"
11 changes: 11 additions & 0 deletions tests/ui/lint/break-with-label-and-unsafe-block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//@ check-pass

#![deny(break_with_label_and_loop)]

unsafe fn foo() -> i32 { 42 }

fn main () {
'label: loop {
break 'label unsafe { foo() }
};
}
Loading