Skip to content
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

Rollup of 7 pull requests #86079

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
90 changes: 1 addition & 89 deletions compiler/rustc_codegen_cranelift/src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

use std::path::PathBuf;

use rustc_middle::bug;
use rustc_codegen_ssa::back::link::linker_and_flavor;
use rustc_session::Session;
use rustc_target::spec::LinkerFlavor;

/// Tries to infer the path of a binary for the target toolchain from the linker name.
pub(crate) fn get_toolchain_binary(sess: &Session, tool: &str) -> PathBuf {
Expand All @@ -30,90 +29,3 @@ pub(crate) fn get_toolchain_binary(sess: &Session, tool: &str) -> PathBuf {

linker
}

// Adapted from https://github.com/rust-lang/rust/blob/5db778affee7c6600c8e7a177c48282dab3f6292/src/librustc_codegen_ssa/back/link.rs#L848-L931
fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
fn infer_from(
sess: &Session,
linker: Option<PathBuf>,
flavor: Option<LinkerFlavor>,
) -> Option<(PathBuf, LinkerFlavor)> {
match (linker, flavor) {
(Some(linker), Some(flavor)) => Some((linker, flavor)),
// only the linker flavor is known; use the default linker for the selected flavor
(None, Some(flavor)) => Some((
PathBuf::from(match flavor {
LinkerFlavor::Em => {
if cfg!(windows) {
"emcc.bat"
} else {
"emcc"
}
}
LinkerFlavor::Gcc => {
if cfg!(any(target_os = "solaris", target_os = "illumos")) {
// On historical Solaris systems, "cc" may have
// been Sun Studio, which is not flag-compatible
// with "gcc". This history casts a long shadow,
// and many modern illumos distributions today
// ship GCC as "gcc" without also making it
// available as "cc".
"gcc"
} else {
"cc"
}
}
LinkerFlavor::Ld => "ld",
LinkerFlavor::Msvc => "link.exe",
LinkerFlavor::Lld(_) => "lld",
LinkerFlavor::PtxLinker => "rust-ptx-linker",
LinkerFlavor::BpfLinker => "bpf-linker",
}),
flavor,
)),
(Some(linker), None) => {
let stem = linker.file_stem().and_then(|stem| stem.to_str()).unwrap_or_else(|| {
sess.fatal("couldn't extract file stem from specified linker")
});

let flavor = if stem == "emcc" {
LinkerFlavor::Em
} else if stem == "gcc"
|| stem.ends_with("-gcc")
|| stem == "clang"
|| stem.ends_with("-clang")
{
LinkerFlavor::Gcc
} else if stem == "ld" || stem == "ld.lld" || stem.ends_with("-ld") {
LinkerFlavor::Ld
} else if stem == "link" || stem == "lld-link" {
LinkerFlavor::Msvc
} else if stem == "lld" || stem == "rust-lld" {
LinkerFlavor::Lld(sess.target.lld_flavor)
} else {
// fall back to the value in the target spec
sess.target.linker_flavor
};

Some((linker, flavor))
}
(None, None) => None,
}
}

// linker and linker flavor specified via command line have precedence over what the target
// specification specifies
if let Some(ret) = infer_from(sess, sess.opts.cg.linker.clone(), sess.opts.cg.linker_flavor) {
return ret;
}

if let Some(ret) = infer_from(
sess,
sess.target.linker.clone().map(PathBuf::from),
Some(sess.target.linker_flavor),
) {
return ret;
}

bug!("Not enough information provided to determine how to invoke the linker");
}
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,8 @@ pub fn ignored_for_lto(sess: &Session, info: &CrateInfo, cnum: CrateNum) -> bool
&& (info.compiler_builtins == Some(cnum) || info.is_no_builtins.contains(&cnum))
}

fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
// This functions tries to determine the appropriate linker (and corresponding LinkerFlavor) to use
pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
fn infer_from(
sess: &Session,
linker: Option<PathBuf>,
Expand Down
50 changes: 4 additions & 46 deletions compiler/rustc_codegen_ssa/src/mir/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use rustc_data_structures::graph::dominators::Dominators;
use rustc_index::bit_set::BitSet;
use rustc_index::vec::{Idx, IndexVec};
use rustc_middle::mir::traversal;
use rustc_middle::mir::visit::{
MutatingUseContext, NonMutatingUseContext, NonUseContext, PlaceContext, Visitor,
};
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor};
use rustc_middle::mir::{self, Location, TerminatorKind};
use rustc_middle::ty::layout::HasTyCtxt;
use rustc_target::abi::LayoutOf;
Expand All @@ -20,7 +18,9 @@ pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
let mir = fx.mir;
let mut analyzer = LocalAnalyzer::new(fx);

analyzer.visit_body(&mir);
for (bb, data) in mir.basic_blocks().iter_enumerated() {
analyzer.visit_basic_block_data(bb, data);
}

for (local, decl) in mir.local_decls.iter_enumerated() {
let ty = fx.monomorphize(decl.ty);
Expand Down Expand Up @@ -141,36 +141,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {

if let mir::ProjectionElem::Deref = elem {
// Deref projections typically only read the pointer.
// (the exception being `VarDebugInfo` contexts, handled below)
base_context = PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy);

// Indirect debuginfo requires going through memory, that only
// the debugger accesses, following our emitted DWARF pointer ops.
//
// FIXME(eddyb) Investigate the possibility of relaxing this, but
// note that `llvm.dbg.declare` *must* be used for indirect places,
// even if we start using `llvm.dbg.value` for all other cases,
// as we don't necessarily know when the value changes, but only
// where it lives in memory.
//
// It's possible `llvm.dbg.declare` could support starting from
// a pointer that doesn't point to an `alloca`, but this would
// only be useful if we know the pointer being `Deref`'d comes
// from an immutable place, and if `llvm.dbg.declare` calls
// must be at the very start of the function, then only function
// arguments could contain such pointers.
if context == PlaceContext::NonUse(NonUseContext::VarDebugInfo) {
// We use `NonUseContext::VarDebugInfo` for the base,
// which might not force the base local to memory,
// so we have to do it manually.
self.visit_local(&place_ref.local, context, location);
}
}

// `NonUseContext::VarDebugInfo` needs to flow all the
// way down to the base local (see `visit_local`).
if context == PlaceContext::NonUse(NonUseContext::VarDebugInfo) {
base_context = context;
}

self.process_place(&place_base, base_context, location);
Expand All @@ -185,20 +156,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
);
}
} else {
// FIXME this is super_place code, is repeated here to avoid cloning place or changing
// visit_place API
let mut context = context;

if !place_ref.projection.is_empty() {
context = if context.is_mutating_use() {
PlaceContext::MutatingUse(MutatingUseContext::Projection)
} else {
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
};
}

self.visit_local(&place_ref.local, context, location);
self.visit_projection(*place_ref, context, location);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_error_codes/src/error_codes/E0759.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ fn bar(x: &i32) -> Box<dyn Debug> { // error!

Add `'static` requirement to fix them:

```compile_fail,E0759
```
# use std::fmt::Debug;
fn foo(x: &i32) -> impl Debug + 'static { // ok!
fn foo(x: &'static i32) -> impl Debug + 'static { // ok!
x
}

fn bar(x: &i32) -> Box<dyn Debug + 'static> { // ok!
fn bar(x: &'static i32) -> Box<dyn Debug + 'static> { // ok!
Box::new(x)
}
```
Expand Down
13 changes: 4 additions & 9 deletions compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,15 +711,10 @@ fn ty_is_known_nonnull<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, mode: CItemKi
return false;
}

for variant in &def.variants {
if let Some(field) = transparent_newtype_field(cx.tcx, variant) {
if ty_is_known_nonnull(cx, field.ty(tcx, substs), mode) {
return true;
}
}
}

false
def.variants
.iter()
.filter_map(|variant| transparent_newtype_field(cx.tcx, variant))
.any(|field| ty_is_known_nonnull(cx, field.ty(tcx, substs), mode))
}
_ => false,
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ fn infer_placeholder_type(
if !ty.references_error() {
diag.span_suggestion(
span,
"replace `_` with the correct type",
"replace with the correct type",
ty.to_string(),
Applicability::MaybeIncorrect,
);
Expand Down
17 changes: 11 additions & 6 deletions library/std/src/sys/windows/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

use crate::cmp;
use crate::io::{self, IoSlice, IoSliceMut, Read};
use crate::lazy::SyncOnceCell;
use crate::mem;
use crate::net::{Shutdown, SocketAddr};
use crate::ptr;
use crate::sync::Once;
use crate::sys;
use crate::sys::c;
use crate::sys_common::net;
Expand All @@ -26,26 +26,31 @@ pub mod netc {

pub struct Socket(c::SOCKET);

static INIT: Once = Once::new();
static WSA: SyncOnceCell<unsafe extern "system" fn() -> i32> = SyncOnceCell::new();

/// Checks whether the Windows socket interface has been started already, and
/// if not, starts it.
pub fn init() {
INIT.call_once(|| unsafe {
let _ = WSA.get_or_init(|| unsafe {
let mut data: c::WSADATA = mem::zeroed();
let ret = c::WSAStartup(
0x202, // version 2.2
&mut data,
);
assert_eq!(ret, 0);

// Only register `WSACleanup` if `WSAStartup` is actually ever called.
// Workaround to prevent linking to `WS2_32.dll` when no network functionality is used.
// See issue #85441.
c::WSACleanup
});
}

pub fn cleanup() {
if INIT.is_completed() {
// only close the socket interface if it has actually been started
// only perform cleanup if network functionality was actually initialized
if let Some(cleanup) = WSA.get() {
unsafe {
c::WSACleanup();
cleanup();
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,8 @@ a {

.search-results .result-name > span {
display: inline-block;
margin: 0;
font-weight: normal;
}

body.blur > :not(#help) {
Expand Down
9 changes: 9 additions & 0 deletions src/test/run-make/issue-85441/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# only-windows

-include ../../run-make-fulldeps/tools.mk

# Tests that WS2_32.dll is not unnecessarily linked, see issue #85441

all:
$(RUSTC) empty.rs
objdump -p $(TMPDIR)/empty.exe | $(CGREP) -v -i "WS2_32.dll"
1 change: 1 addition & 0 deletions src/test/run-make/issue-85441/empty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0121.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ LL | static BAR: _ = "test";
| ^
| |
| not allowed in type signatures
| help: replace `_` with the correct type: `&str`
| help: replace with the correct type: `&str`

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ LL | const A = "A".$fn();
| ^
| |
| not allowed in type signatures
| help: replace `_` with the correct type: `bool`
| help: replace with the correct type: `bool`
...
LL | / suite! {
LL | | len;
Expand Down
16 changes: 8 additions & 8 deletions src/test/ui/typeck/typeck_type_placeholder_item.full_tait.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ LL | static TEST3: _ = "test";
| ^
| |
| not allowed in type signatures
| help: replace `_` with the correct type: `&str`
| help: replace with the correct type: `&str`

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:19:15
Expand All @@ -88,7 +88,7 @@ LL | static TEST4: _ = 145;
| ^
| |
| not allowed in type signatures
| help: replace `_` with the correct type: `i32`
| help: replace with the correct type: `i32`

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:22:15
Expand Down Expand Up @@ -210,7 +210,7 @@ LL | static B: _ = 42;
| ^
| |
| not allowed in type signatures
| help: replace `_` with the correct type: `i32`
| help: replace with the correct type: `i32`

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:80:15
Expand Down Expand Up @@ -244,7 +244,7 @@ LL | static FN_TEST3: _ = "test";
| ^
| |
| not allowed in type signatures
| help: replace `_` with the correct type: `&str`
| help: replace with the correct type: `&str`

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:92:22
Expand All @@ -253,7 +253,7 @@ LL | static FN_TEST4: _ = 145;
| ^
| |
| not allowed in type signatures
| help: replace `_` with the correct type: `i32`
| help: replace with the correct type: `i32`

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:95:22
Expand Down Expand Up @@ -435,7 +435,7 @@ LL | const _: Option<_> = map(value);
| ^^^^^^^^^
| |
| not allowed in type signatures
| help: replace `_` with the correct type: `Option<u8>`
| help: replace with the correct type: `Option<u8>`

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:144:31
Expand Down Expand Up @@ -526,7 +526,7 @@ LL | const D: _ = 42;
| ^
| |
| not allowed in type signatures
| help: replace `_` with the correct type: `i32`
| help: replace with the correct type: `i32`

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:201:26
Expand Down Expand Up @@ -639,7 +639,7 @@ LL | const D: _ = 42;
| ^
| |
| not allowed in type signatures
| help: replace `_` with the correct type: `i32`
| help: replace with the correct type: `i32`

error: aborting due to 69 previous errors; 1 warning emitted

Expand Down
Loading