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 12 pull requests #122241

Merged
merged 30 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c5aa659
Reduce alignment of TypeId to u64 alignment
GnomedDev Feb 20, 2024
aa25c48
Add extra detail to field comment
GnomedDev Feb 20, 2024
f142476
Fix Hash impl
GnomedDev Feb 25, 2024
5c87ca2
Add some weird test cases to the non_local_definitions lint tests
Urgau Feb 29, 2024
20200f6
Remove useless smallvec dependency in rustc_lint::non_local_def
Urgau Feb 29, 2024
6c4eadd
Add early-return when checking if a path is local
Urgau Feb 29, 2024
98dbe9a
Use was_invoked_from_cargo method instead of hand-written one
Urgau Feb 29, 2024
4663fbb
Eagerly translate HelpUseLatestEdition in parser diagnostics
jieyouxu Mar 7, 2024
bef1cd8
ci: add a runner for vanilla LLVM 18
cuviper Mar 8, 2024
fdff4d7
Move metadata header and version checks together
bjorn3 Mar 8, 2024
87ab9e8
Some tweaks to the parallel query cycle handler
Zoxc Mar 8, 2024
564837e
Fix typo in `VisitorResult`
Jarcho Mar 9, 2024
7c13421
fix incorrect path resolution in tidy
onur-ozkan Mar 8, 2024
b1f4657
Add missing regression tests
gurry Mar 9, 2024
6aff1ca
fix warning when building libcore for Miri
RalfJung Mar 9, 2024
1082c36
fn is_align_to: move some comments closer to the cast they refer to
RalfJung Mar 9, 2024
e632e3f
miri: do not apply aliasing restrictions to Box with custom allocator
RalfJung Mar 9, 2024
7e1969a
Remove `Ord` from `ClosureKind`
fee1-dead Mar 9, 2024
a1f6191
Rollup merge of #121358 - GnomedDev:lower-align-typeid, r=Mark-Simula…
matthiaskrgr Mar 9, 2024
a979f97
Rollup merge of #121813 - Urgau:misc-non_local_defs-lint, r=cjgillot
matthiaskrgr Mar 9, 2024
985befe
Rollup merge of #122160 - jieyouxu:eager-translate-help-use-latest-ed…
matthiaskrgr Mar 9, 2024
577632d
Rollup merge of #122178 - cuviper:ci-llvm-18, r=Kobzol
matthiaskrgr Mar 9, 2024
9ac5cc8
Rollup merge of #122187 - bjorn3:merge_header_version_checks, r=petro…
matthiaskrgr Mar 9, 2024
a5adac0
Rollup merge of #122209 - onur-ozkan:fix-tidy-path-resolution, r=comp…
matthiaskrgr Mar 9, 2024
dc7a9f6
Rollup merge of #122215 - Zoxc:cycle-detect-names, r=oli-obk
matthiaskrgr Mar 9, 2024
2894585
Rollup merge of #122223 - Jarcho:visit_fix, r=oli-obk
matthiaskrgr Mar 9, 2024
d1d43b8
Rollup merge of #122224 - gurry:add-tests, r=Nadrieril
matthiaskrgr Mar 9, 2024
2bb4b99
Rollup merge of #122232 - RalfJung:misc, r=jhpratt
matthiaskrgr Mar 9, 2024
b14e805
Rollup merge of #122233 - RalfJung:custom-alloc-box, r=oli-obk
matthiaskrgr Mar 9, 2024
7193ce0
Rollup merge of #122237 - fee1-dead-contrib:rmord, r=compiler-errors
matthiaskrgr Mar 9, 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
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ jobs:
- name: x86_64-gnu-distcheck
os: ubuntu-20.04-8core-32gb
env: {}
- name: x86_64-gnu-llvm-18
env:
RUST_BACKTRACE: 1
os: ubuntu-20.04-8core-32gb
- name: x86_64-gnu-llvm-17
env:
RUST_BACKTRACE: 1
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4133,7 +4133,6 @@ dependencies = [
"rustc_target",
"rustc_trait_selection",
"rustc_type_ir",
"smallvec",
"tracing",
"unicode-security",
]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_ir/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl VisitorResult for () {
type Residual = !;

#[cfg(not(feature = "nightly"))]
type Residual = core::ops::Infallible;
type Residual = core::convert::Infallible;

fn output() -> Self {}
fn from_residual(_: Self::Residual) -> Self {}
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_const_eval/src/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use rustc_middle::mir::interpret::{
ExpectedKind, InterpError, InvalidMetaKind, Misalignment, PointerKind, Provenance,
ValidationErrorInfo, ValidationErrorKind, ValidationErrorKind::*,
};
use rustc_middle::ty;
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
use rustc_middle::ty::{self, Ty};
use rustc_span::symbol::{sym, Symbol};
use rustc_target::abi::{
Abi, FieldIdx, Scalar as ScalarAbi, Size, VariantIdx, Variants, WrappingRange,
Expand Down Expand Up @@ -783,7 +783,11 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
}

#[inline]
fn visit_box(&mut self, op: &OpTy<'tcx, M::Provenance>) -> InterpResult<'tcx> {
fn visit_box(
&mut self,
_box_ty: Ty<'tcx>,
op: &OpTy<'tcx, M::Provenance>,
) -> InterpResult<'tcx> {
self.check_safe_pointer(op, PointerKind::Box)?;
Ok(())
}
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_const_eval/src/interpret/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use rustc_index::IndexVec;
use rustc_middle::mir::interpret::InterpResult;
use rustc_middle::ty;
use rustc_middle::ty::{self, Ty};
use rustc_target::abi::FieldIdx;
use rustc_target::abi::{FieldsShape, VariantIdx, Variants};

Expand Down Expand Up @@ -47,10 +47,10 @@ pub trait ValueVisitor<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>: Sized {
Ok(())
}
/// Visits the given value as the pointer of a `Box`. There is nothing to recurse into.
/// The type of `v` will be a raw pointer, but this is a field of `Box<T>` and the
/// pointee type is the actual `T`.
/// The type of `v` will be a raw pointer to `T`, but this is a field of `Box<T>` and the
/// pointee type is the actual `T`. `box_ty` provides the full type of the `Box` itself.
#[inline(always)]
fn visit_box(&mut self, _v: &Self::V) -> InterpResult<'tcx> {
fn visit_box(&mut self, _box_ty: Ty<'tcx>, _v: &Self::V) -> InterpResult<'tcx> {
Ok(())
}

Expand Down Expand Up @@ -144,7 +144,7 @@ pub trait ValueVisitor<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>: Sized {
assert_eq!(nonnull_ptr.layout().fields.count(), 1);
let raw_ptr = self.ecx().project_field(&nonnull_ptr, 0)?; // the actual raw ptr
// ... whose only field finally is a raw ptr we can dereference.
self.visit_box(&raw_ptr)?;
self.visit_box(ty, &raw_ptr)?;

// The second `Box` field is the allocator, which we recursively check for validity
// like in regular structs.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ fn list_metadata(early_dcx: &EarlyDiagCtxt, sess: &Session, metadata_loader: &dy
metadata_loader,
&mut v,
&sess.opts.unstable_opts.ls,
sess.cfg_version,
)
.unwrap();
safe_println!("{}", String::from_utf8(v).unwrap());
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_hir_analysis/src/check/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,10 @@ pub fn check_intrinsic_type(
sym::simd_shuffle => (3, 0, vec![param(0), param(0), param(1)], param(2)),
sym::simd_shuffle_generic => (2, 1, vec![param(0), param(0)], param(1)),

sym::retag_box_to_raw => {
(2, 0, vec![Ty::new_mut_ptr(tcx, param(0))], Ty::new_mut_ptr(tcx, param(0)))
}

other => {
tcx.dcx().emit_err(UnrecognizedIntrinsicFunction { span, name: other });
return;
Expand Down
17 changes: 12 additions & 5 deletions compiler/rustc_hir_typeck/src/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rustc_target::spec::abi::Abi;
use rustc_trait_selection::traits;
use rustc_trait_selection::traits::error_reporting::ArgKind;
use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _;
use std::cmp;
use rustc_type_ir::ClosureKind;
use std::iter;
use std::ops::ControlFlow;

Expand Down Expand Up @@ -437,10 +437,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};

if let Some(found_kind) = found_kind {
expected_kind = Some(
expected_kind
.map_or_else(|| found_kind, |current| cmp::min(current, found_kind)),
);
// always use the closure kind that is more permissive.
match (expected_kind, found_kind) {
(None, _) => expected_kind = Some(found_kind),
(Some(ClosureKind::FnMut), ClosureKind::Fn) => {
expected_kind = Some(ClosureKind::Fn)
}
(Some(ClosureKind::FnOnce), ClosureKind::Fn | ClosureKind::FnMut) => {
expected_kind = Some(found_kind)
}
_ => {}
}
}
}
}
Expand Down
19 changes: 16 additions & 3 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
threads: usize,
f: F,
) -> R {
use rustc_data_structures::{jobserver, sync::FromDyn};
use rustc_data_structures::{defer, jobserver, sync::FromDyn};
use rustc_middle::ty::tls;
use rustc_query_impl::QueryCtxt;
use rustc_query_system::query::{deadlock, QueryContext};
use rustc_query_system::query::{break_query_cycles, QueryContext};
use std::process;

let registry = sync::Registry::new(std::num::NonZero::new(threads).unwrap());

Expand All @@ -128,7 +129,19 @@ pub(crate) fn run_in_thread_pool_with_globals<F: FnOnce() -> R + Send, R: Send>(
let query_map =
FromDyn::from(tls::with(|tcx| QueryCtxt::new(tcx).collect_active_jobs()));
let registry = rayon_core::Registry::current();
thread::spawn(move || deadlock(query_map.into_inner(), &registry));
thread::Builder::new()
.name("rustc query cycle handler".to_string())
.spawn(move || {
let on_panic = defer(|| {
eprintln!("query cycle handler thread panicked, aborting process");
// We need to abort here as we failed to resolve the deadlock,
// otherwise the compiler could just hang,
process::abort();
});
break_query_cycles(query_map.into_inner(), &registry);
on_panic.disable();
})
.unwrap();
});
if let Some(size) = get_stack_size() {
builder = builder.stack_size(size);
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_lint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" }
rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_type_ir = { path = "../rustc_type_ir" }
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
tracing = "0.1"
unicode-security = "0.1.0"
# tidy-alphabetical-end
34 changes: 21 additions & 13 deletions compiler/rustc_lint/src/non_local_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use rustc_hir::{def::DefKind, Body, Item, ItemKind, Node, Path, QPath, TyKind};
use rustc_span::def_id::{DefId, LOCAL_CRATE};
use rustc_span::{sym, symbol::kw, ExpnKind, MacroKind};

use smallvec::{smallvec, SmallVec};

use crate::lints::{NonLocalDefinitionsCargoUpdateNote, NonLocalDefinitionsDiag};
use crate::{LateContext, LateLintPass, LintContext};

Expand Down Expand Up @@ -85,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
if let Some(def_id) = oexpn.macro_def_id
&& let ExpnKind::Macro(macro_kind, macro_name) = oexpn.kind
&& def_id.krate != LOCAL_CRATE
&& std::env::var_os("CARGO").is_some()
&& rustc_session::utils::was_invoked_from_cargo()
{
Some(NonLocalDefinitionsCargoUpdateNote {
macro_kind: macro_kind.descr(),
Expand Down Expand Up @@ -114,25 +112,25 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
// is using local items and so we don't lint on it.

// We also ignore anon-const in item by including the anon-const
// parent as well; and since it's quite uncommon, we use smallvec
// to avoid unnecessary heap allocations.
let local_parents: SmallVec<[DefId; 1]> = if parent_def_kind == DefKind::Const
// parent as well.
let parent_parent = if parent_def_kind == DefKind::Const
&& parent_opt_item_name == Some(kw::Underscore)
{
smallvec![parent, cx.tcx.parent(parent)]
Some(cx.tcx.parent(parent))
} else {
smallvec![parent]
None
};

let self_ty_has_local_parent = match impl_.self_ty.kind {
TyKind::Path(QPath::Resolved(_, ty_path)) => {
path_has_local_parent(ty_path, cx, &*local_parents)
path_has_local_parent(ty_path, cx, parent, parent_parent)
}
TyKind::TraitObject([principle_poly_trait_ref, ..], _, _) => {
path_has_local_parent(
principle_poly_trait_ref.trait_ref.path,
cx,
&*local_parents,
parent,
parent_parent,
)
}
TyKind::TraitObject([], _, _)
Expand All @@ -154,7 +152,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {

let of_trait_has_local_parent = impl_
.of_trait
.map(|of_trait| path_has_local_parent(of_trait.path, cx, &*local_parents))
.map(|of_trait| path_has_local_parent(of_trait.path, cx, parent, parent_parent))
.unwrap_or(false);

// If none of them have a local parent (LOGICAL NOR) this means that
Expand Down Expand Up @@ -218,6 +216,16 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
/// std::convert::PartialEq<Foo<Bar>>
/// ^^^^^^^^^^^^^^^^^^^^^^^
/// ```
fn path_has_local_parent(path: &Path<'_>, cx: &LateContext<'_>, local_parents: &[DefId]) -> bool {
path.res.opt_def_id().is_some_and(|did| local_parents.contains(&cx.tcx.parent(did)))
fn path_has_local_parent(
path: &Path<'_>,
cx: &LateContext<'_>,
impl_parent: DefId,
impl_parent_parent: Option<DefId>,
) -> bool {
path.res.opt_def_id().is_some_and(|did| {
did.is_local() && {
let res_parent = cx.tcx.parent(did);
res_parent == impl_parent || Some(res_parent) == impl_parent_parent
}
})
}
Loading
Loading