Skip to content

Rollup of 7 pull requests #124040

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 22 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
96e7d25
add missing lld directive to compiletest
lqd Apr 14, 2024
682535e
add regex to run_make_support
lqd Apr 14, 2024
9779592
port `rust-lld` test to rmake
lqd Apr 14, 2024
8fa6984
port `rust-lld-custom-target` test to rmake
lqd Apr 14, 2024
8acfe9a
add `link_arg` helper to `run_make_support`
lqd Apr 15, 2024
af887d3
mention json target specs in `run_make_support`
lqd Apr 15, 2024
8a981b6
Use /* value */ as a placeholder
compiler-errors Apr 16, 2024
c957613
Make array suggestions slightly more accurate
compiler-errors Apr 16, 2024
801413e
Taint const qualifs if a static is referenced that didn't pass wfcheck
oli-obk Apr 9, 2024
fe18afe
Unset test env vars before setting new ones.
oli-obk Apr 9, 2024
4f75d67
Make ui_test backtraces short by default
oli-obk Apr 9, 2024
0a88339
Don't ICE for kind mismatches during error rendering
oli-obk Apr 9, 2024
8606efa
Box::into_raw: make Miri understand that this is a box-to-raw cast
RalfJung Apr 16, 2024
9cc4e23
Prefer identity equality over equating types during coercion.
oli-obk Apr 16, 2024
f25668c
Remove `default_hidden_visibility: false` from wasm targets
alexcrichton Apr 16, 2024
4aaa8f9
Rollup merge of #123673 - oli-obk:sig_wfcheck_ice, r=jieyouxu,estebank
GuillaumeGomez Apr 16, 2024
4885ddf
Rollup merge of #123675 - oli-obk:static_wf_ice, r=compiler-errors
GuillaumeGomez Apr 16, 2024
ec1618c
Rollup merge of #123975 - lqd:rust-lld-tests, r=jieyouxu
GuillaumeGomez Apr 16, 2024
4764dce
Rollup merge of #124000 - compiler-errors:sugg-tweaks, r=wesleywiser
GuillaumeGomez Apr 16, 2024
51cfa95
Rollup merge of #124013 - RalfJung:box-to-raw, r=oli-obk
GuillaumeGomez Apr 16, 2024
c7b009f
Rollup merge of #124027 - oli-obk:define_opaque_types9, r=compiler-er…
GuillaumeGomez Apr 16, 2024
a0ca118
Rollup merge of #124036 - alexcrichton:wasm-use-default-visbility, r=…
GuillaumeGomez Apr 16, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3342,6 +3342,7 @@ name = "run_make_support"
version = "0.0.0"
dependencies = [
"object 0.34.0",
"regex",
"wasmparser",
]

Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_const_eval/src/transform/check_consts/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
if self.tcx.is_thread_local_static(def_id) {
self.tcx.dcx().span_bug(span, "tls access is checked in `Rvalue::ThreadLocalRef`");
}
if let Some(def_id) = def_id.as_local()
&& let Err(guar) = self.tcx.at(span).check_well_formed(hir::OwnerId { def_id })
{
self.error_emitted = Some(guar);
}
self.check_op_spanned(ops::StaticAccess, span)
}

Expand Down
35 changes: 13 additions & 22 deletions compiler/rustc_hir_analysis/src/coherence/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::lang_items::LangItem;
use rustc_hir::ItemKind;
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::infer::{self, RegionResolutionError};
use rustc_infer::infer::{DefineOpaqueTypes, TyCtxtInferExt};
use rustc_infer::traits::Obligation;
use rustc_middle::ty::adjustment::CoerceUnsizedInfo;
use rustc_middle::ty::{self, suggest_constraining_type_params, Ty, TyCtxt, TypeVisitableExt};
Expand Down Expand Up @@ -189,10 +189,7 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<()
// even if they do not carry that attribute.
use rustc_type_ir::TyKind::*;
match (source.kind(), target.kind()) {
(&Ref(r_a, _, mutbl_a), Ref(r_b, _, mutbl_b))
if infcx.at(&cause, param_env).eq(DefineOpaqueTypes::No, r_a, *r_b).is_ok()
&& mutbl_a == *mutbl_b =>
{
(&Ref(r_a, _, mutbl_a), Ref(r_b, _, mutbl_b)) if r_a == *r_b && mutbl_a == *mutbl_b => {
Ok(())
}
(&RawPtr(_, a_mutbl), &RawPtr(_, b_mutbl)) if a_mutbl == b_mutbl => Ok(()),
Expand Down Expand Up @@ -230,18 +227,14 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<()
}
}

if let Ok(ok) =
infcx.at(&cause, param_env).eq(DefineOpaqueTypes::No, ty_a, ty_b)
{
if ok.obligations.is_empty() {
res = Err(tcx.dcx().emit_err(errors::DispatchFromDynZST {
span,
name: field.name,
ty: ty_a,
}));
if ty_a == ty_b {
res = Err(tcx.dcx().emit_err(errors::DispatchFromDynZST {
span,
name: field.name,
ty: ty_a,
}));

return false;
}
return false;
}

return true;
Expand Down Expand Up @@ -433,14 +426,12 @@ pub fn coerce_unsized_info<'tcx>(
// something more accepting, but we use
// equality because we want to be able to
// perform this check without computing
// variance where possible. (This is because
// we may have to evaluate constraint
// variance or constraining opaque types' hidden types.
// (This is because we may have to evaluate constraint
// expressions in the course of execution.)
// See e.g., #41936.
if let Ok(ok) = infcx.at(&cause, param_env).eq(DefineOpaqueTypes::No, a, b) {
if ok.obligations.is_empty() {
return None;
}
if a == b {
return None;
}

// Collect up all fields that were significantly changed
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_target/src/spec/base/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ pub fn options() -> TargetOptions {
// threaded model which will legalize atomics to normal operations.
singlethread: true,

// no dynamic linking, no need for default visibility!
default_hidden_visibility: true,

// Symbol visibility takes care of this for the WebAssembly.
// Additionally the only known linker, LLD, doesn't support the script
// arguments just yet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4545,7 +4545,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
self.type_implements_trait(default_trait, [ty], param_env).must_apply_modulo_regions()
};

Some(match ty.kind() {
Some(match *ty.kind() {
ty::Never | ty::Error(_) => return None,
ty::Bool => "false".to_string(),
ty::Char => "\'x\'".to_string(),
Expand All @@ -4572,12 +4572,19 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
if let (ty::Str, hir::Mutability::Not) = (ty.kind(), mutability) {
"\"\"".to_string()
} else {
let ty = self.ty_kind_suggestion(param_env, *ty)?;
let ty = self.ty_kind_suggestion(param_env, ty)?;
format!("&{}{ty}", mutability.prefix_str())
}
}
ty::Array(ty, len) if let Some(len) = len.try_eval_target_usize(tcx, param_env) => {
format!("[{}; {}]", self.ty_kind_suggestion(param_env, *ty)?, len)
if len == 0 {
"[]".to_string()
} else if self.type_is_copy_modulo_regions(param_env, ty) || len == 1 {
// Can only suggest `[ty; 0]` if sz == 1 or copy
format!("[{}; {}]", self.ty_kind_suggestion(param_env, ty)?, len)
} else {
"/* value */".to_string()
}
}
ty::Tuple(tys) => format!(
"({}{})",
Expand All @@ -4587,7 +4594,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
.join(", "),
if tys.len() == 1 { "," } else { "" }
),
_ => "value".to_string(),
_ => "/* value */".to_string(),
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1977,6 +1977,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
for (obligation_arg, impl_arg) in
std::iter::zip(obligation_trait_ref.args, impl_trait_ref.args)
{
if (obligation_arg, impl_arg).references_error() {
return false;
}
if let Err(terr) =
ocx.eq(&ObligationCause::dummy(), param_env, impl_arg, obligation_arg)
{
Expand Down
8 changes: 6 additions & 2 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,8 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
#[stable(feature = "box_raw", since = "1.4.0")]
#[inline]
pub fn into_raw(b: Self) -> *mut T {
Self::into_raw_with_allocator(b).0
// Make sure Miri realizes that we transition from a noalias pointer to a raw pointer here.
unsafe { addr_of_mut!(*&mut *Self::into_raw_with_allocator(b).0) }
}

/// Consumes the `Box`, returning a wrapped raw pointer and the allocator.
Expand Down Expand Up @@ -1112,7 +1113,10 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
pub fn into_raw_with_allocator(b: Self) -> (*mut T, A) {
let mut b = mem::ManuallyDrop::new(b);
// We carefully get the raw pointer out in a way that Miri's aliasing model understands what
// is happening: using the primitive "deref" of `Box`.
// is happening: using the primitive "deref" of `Box`. In case `A` is *not* `Global`, we
// want *no* aliasing requirements here!
// In case `A` *is* `Global`, this does not quite have the right behavior; `into_raw`
// works around that.
let ptr = addr_of_mut!(**b);
let alloc = unsafe { ptr::read(&b.1) };
(ptr, alloc)
Expand Down
6 changes: 5 additions & 1 deletion src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,10 @@ impl TestProps {
aux_bins: vec![],
aux_crates: vec![],
revisions: vec![],
rustc_env: vec![("RUSTC_ICE".to_string(), "0".to_string())],
rustc_env: vec![
("RUSTC_ICE".to_string(), "0".to_string()),
("RUST_BACKTRACE".to_string(), "short".to_string()),
],
unset_rustc_env: vec![("RUSTC_LOG_COLOR".to_string())],
exec_env: vec![],
unset_exec_env: vec![],
Expand Down Expand Up @@ -839,6 +842,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"needs-profiler-support",
"needs-relocation-model-pic",
"needs-run-enabled",
"needs-rust-lld",
"needs-rust-lldb",
"needs-sanitizer-address",
"needs-sanitizer-cfi",
Expand Down
4 changes: 2 additions & 2 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2173,8 +2173,8 @@ impl<'test> TestCx<'test> {
let aux_dir = self.aux_output_dir();
self.build_all_auxiliary(&self.testpaths, &aux_dir, &mut rustc);

self.props.unset_rustc_env.iter().fold(&mut rustc, Command::env_remove);
rustc.envs(self.props.rustc_env.clone());
self.props.unset_rustc_env.iter().fold(&mut rustc, Command::env_remove);
self.compose_and_run(
rustc,
self.config.compile_lib_path.to_str().unwrap(),
Expand Down Expand Up @@ -2220,10 +2220,10 @@ impl<'test> TestCx<'test> {
);
aux_cx.build_all_auxiliary(of, &aux_dir, &mut aux_rustc);

aux_rustc.envs(aux_props.rustc_env.clone());
for key in &aux_props.unset_rustc_env {
aux_rustc.env_remove(key);
}
aux_rustc.envs(aux_props.rustc_env.clone());

let (aux_type, crate_type) = if is_bin {
(AuxType::Bin, Some("bin"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc)
|
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <TAG> was created by a Unique retag at offsets [0x0..0x4]
help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4]
--> $DIR/newtype_pair_retagging.rs:LL:CC
|
LL | let ptr = Box::into_raw(Box::new(0i32));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc)
|
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <TAG> was created by a Unique retag at offsets [0x0..0x4]
help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4]
--> $DIR/newtype_retagging.rs:LL:CC
|
LL | let ptr = Box::into_raw(Box::new(0i32));
Expand Down
28 changes: 28 additions & 0 deletions src/tools/miri/tests/pass/issues/issue-miri-3473.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//@revisions: stack tree
//@[tree]compile-flags: -Zmiri-tree-borrows
use std::cell::UnsafeCell;

#[repr(C)]
#[derive(Default)]
struct Node {
_meta: UnsafeCell<usize>,
value: usize,
}

impl Node {
fn value(&self) -> &usize {
&self.value
}
}

/// This used to cause Stacked Borrows errors because of trouble around conversion
/// from Box to raw pointer.
fn main() {
unsafe {
let a = Box::into_raw(Box::new(Node::default()));
let ptr = &*a;
*UnsafeCell::raw_get(a.cast::<UnsafeCell<usize>>()) = 2;
assert_eq!(*ptr.value(), 0);
drop(Box::from_raw(a));
}
}
12 changes: 12 additions & 0 deletions src/tools/miri/tests/pass/stacked-borrows/stacked-borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fn main() {
wide_raw_ptr_in_tuple();
not_unpin_not_protected();
write_does_not_invalidate_all_aliases();
box_into_raw_allows_interior_mutable_alias();
}

// Make sure that reading from an `&mut` does, like reborrowing to `&`,
Expand Down Expand Up @@ -263,3 +264,14 @@ fn write_does_not_invalidate_all_aliases() {
other::lib2();
assert_eq!(*x, 1337); // oops, the value changed! I guess not all pointers were invalidated
}

fn box_into_raw_allows_interior_mutable_alias() { unsafe {
let b = Box::new(std::cell::Cell::new(42));
let raw = Box::into_raw(b);
let c = &*raw;
let d = raw.cast::<i32>(); // bypassing `Cell` -- only okay in Miri tests
// `c` and `d` should permit arbitrary aliasing with each other now.
*d = 1;
c.set(2);
drop(Box::from_raw(raw));
} }
1 change: 1 addition & 0 deletions src/tools/run-make-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ edition = "2021"
[dependencies]
object = "0.34.0"
wasmparser = "0.118.2"
regex = "1.8" # 1.8 to avoid memchr 2.6.0, as 2.5.0 is pinned in the workspace
1 change: 1 addition & 0 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::path::{Path, PathBuf};
use std::process::{Command, Output};

pub use object;
pub use regex;
pub use wasmparser;

pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
Expand Down
9 changes: 7 additions & 2 deletions src/tools/run-make-support/src/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ impl Rustc {
self
}

/// Specify target triple.
/// Specify the target triple, or a path to a custom target json spec file.
pub fn target(&mut self, target: &str) -> &mut Self {
assert!(!target.contains(char::is_whitespace), "target triple cannot contain spaces");
self.cmd.arg(format!("--target={target}"));
self
}
Expand All @@ -149,6 +148,12 @@ impl Rustc {
self
}

/// Add an extra argument to the linker invocation, via `-Clink-arg`.
pub fn link_arg(&mut self, link_arg: &str) -> &mut Self {
self.cmd.arg(format!("-Clink-arg={link_arg}"));
self
}

#[track_caller]
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
let caller_location = std::panic::Location::caller();
Expand Down
2 changes: 0 additions & 2 deletions src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,6 @@ run-make/rlib-format-packed-bundled-libs-2/Makefile
run-make/rlib-format-packed-bundled-libs-3/Makefile
run-make/rlib-format-packed-bundled-libs/Makefile
run-make/rmeta-preferred/Makefile
run-make/rust-lld-custom-target/Makefile
run-make/rust-lld/Makefile
run-make/rustc-macro-dep-files/Makefile
run-make/rustdoc-determinism/Makefile
run-make/rustdoc-error-lines/Makefile
Expand Down
17 changes: 0 additions & 17 deletions tests/crashes/123153.rs

This file was deleted.

7 changes: 0 additions & 7 deletions tests/run-make/rust-lld-custom-target/Makefile

This file was deleted.

Loading
Loading