Skip to content

Commit d0f4a52

Browse files
committed
Auto merge of #3894 - rust-lang:rustup-2024-09-17, r=RalfJung
Automatic Rustup
2 parents 9c3a392 + c5f5cfc commit d0f4a52

File tree

81 files changed

+1919
-1402
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1919
-1402
lines changed

Diff for: compiler/rustc_abi/src/layout.rs

+952-920
Large diffs are not rendered by default.

Diff for: compiler/rustc_abi/src/lib.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ mod layout;
2626
#[cfg(test)]
2727
mod tests;
2828

29-
pub use layout::LayoutCalculator;
29+
pub use layout::{LayoutCalculator, LayoutCalculatorError};
3030

3131
/// Requirements for a `StableHashingContext` to be used in this crate.
3232
/// This is a hack to allow using the `HashStable_Generic` derive macro
@@ -393,6 +393,14 @@ impl HasDataLayout for TargetDataLayout {
393393
}
394394
}
395395

396+
// used by rust-analyzer
397+
impl HasDataLayout for &TargetDataLayout {
398+
#[inline]
399+
fn data_layout(&self) -> &TargetDataLayout {
400+
(**self).data_layout()
401+
}
402+
}
403+
396404
/// Endianness of the target, which must match cfg(target-endian).
397405
#[derive(Copy, Clone, PartialEq, Eq)]
398406
pub enum Endian {

Diff for: compiler/rustc_codegen_llvm/src/intrinsic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2066,14 +2066,14 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
20662066
};
20672067
}
20682068

2069-
arith_red!(simd_reduce_add_ordered: vector_reduce_add, vector_reduce_fadd, true, add, 0.0);
2069+
arith_red!(simd_reduce_add_ordered: vector_reduce_add, vector_reduce_fadd, true, add, -0.0);
20702070
arith_red!(simd_reduce_mul_ordered: vector_reduce_mul, vector_reduce_fmul, true, mul, 1.0);
20712071
arith_red!(
20722072
simd_reduce_add_unordered: vector_reduce_add,
20732073
vector_reduce_fadd_reassoc,
20742074
false,
20752075
add,
2076-
0.0
2076+
-0.0
20772077
);
20782078
arith_red!(
20792079
simd_reduce_mul_unordered: vector_reduce_mul,

Diff for: compiler/rustc_codegen_ssa/src/back/linker.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use std::{env, iter, mem, str};
77

88
use cc::windows_registry;
99
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
10-
use rustc_metadata::{find_native_static_library, try_find_native_static_library};
10+
use rustc_metadata::{
11+
find_native_static_library, try_find_native_dynamic_library, try_find_native_static_library,
12+
};
1113
use rustc_middle::bug;
1214
use rustc_middle::middle::dependency_format::Linkage;
1315
use rustc_middle::middle::exported_symbols;
@@ -876,7 +878,13 @@ impl<'a> Linker for MsvcLinker<'a> {
876878
}
877879

878880
fn link_dylib_by_name(&mut self, name: &str, verbatim: bool, _as_needed: bool) {
879-
self.link_arg(format!("{}{}", name, if verbatim { "" } else { ".lib" }));
881+
// On MSVC-like targets rustc supports import libraries using alternative naming
882+
// scheme (`libfoo.a`) unsupported by linker, search for such libraries manually.
883+
if let Some(path) = try_find_native_dynamic_library(self.sess, name, verbatim) {
884+
self.link_arg(path);
885+
} else {
886+
self.link_arg(format!("{}{}", name, if verbatim { "" } else { ".lib" }));
887+
}
880888
}
881889

882890
fn link_dylib_by_path(&mut self, path: &Path, _as_needed: bool) {

Diff for: compiler/rustc_const_eval/src/const_eval/valtrees.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ pub fn valtree_to_const_value<'tcx>(
319319
let branches = valtree.unwrap_branch();
320320
// Find the non-ZST field. (There can be aligned ZST!)
321321
for (i, &inner_valtree) in branches.iter().enumerate() {
322-
let field = layout.field(&LayoutCx { tcx, param_env }, i);
322+
let field = layout.field(&LayoutCx::new(tcx, param_env), i);
323323
if !field.is_zst() {
324324
return valtree_to_const_value(tcx, param_env.and(field.ty), inner_valtree);
325325
}

Diff for: compiler/rustc_const_eval/src/interpret/validity.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_middle::mir::interpret::{
2121
UnsupportedOpInfo, ValidationErrorInfo,
2222
};
2323
use rustc_middle::ty::layout::{LayoutCx, LayoutOf, TyAndLayout};
24-
use rustc_middle::ty::{self, Ty, TyCtxt};
24+
use rustc_middle::ty::{self, Ty};
2525
use rustc_span::symbol::{sym, Symbol};
2626
use rustc_target::abi::{
2727
Abi, FieldIdx, FieldsShape, Scalar as ScalarAbi, Size, VariantIdx, Variants, WrappingRange,
@@ -940,7 +940,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
940940
) -> Cow<'e, RangeSet> {
941941
assert!(layout.ty.is_union());
942942
assert!(layout.abi.is_sized(), "there are no unsized unions");
943-
let layout_cx = LayoutCx { tcx: *ecx.tcx, param_env: ecx.param_env };
943+
let layout_cx = LayoutCx::new(*ecx.tcx, ecx.param_env);
944944
return M::cached_union_data_range(ecx, layout.ty, || {
945945
let mut out = RangeSet(Vec::new());
946946
union_data_range_uncached(&layout_cx, layout, Size::ZERO, &mut out);
@@ -949,7 +949,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
949949

950950
/// Helper for recursive traversal: add data ranges of the given type to `out`.
951951
fn union_data_range_uncached<'tcx>(
952-
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
952+
cx: &LayoutCx<'tcx>,
953953
layout: TyAndLayout<'tcx>,
954954
base_offset: Size,
955955
out: &mut RangeSet,

Diff for: compiler/rustc_const_eval/src/util/check_validity_requirement.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use rustc_middle::bug;
2-
use rustc_middle::ty::layout::{LayoutCx, LayoutError, LayoutOf, TyAndLayout, ValidityRequirement};
2+
use rustc_middle::ty::layout::{
3+
HasTyCtxt, LayoutCx, LayoutError, LayoutOf, TyAndLayout, ValidityRequirement,
4+
};
35
use rustc_middle::ty::{ParamEnvAnd, Ty, TyCtxt};
46
use rustc_target::abi::{Abi, FieldsShape, Scalar, Variants};
57

@@ -30,7 +32,7 @@ pub fn check_validity_requirement<'tcx>(
3032
return Ok(!layout.abi.is_uninhabited());
3133
}
3234

33-
let layout_cx = LayoutCx { tcx, param_env: param_env_and_ty.param_env };
35+
let layout_cx = LayoutCx::new(tcx, param_env_and_ty.param_env);
3436
if kind == ValidityRequirement::Uninit || tcx.sess.opts.unstable_opts.strict_init_checks {
3537
check_validity_requirement_strict(layout, &layout_cx, kind)
3638
} else {
@@ -42,12 +44,12 @@ pub fn check_validity_requirement<'tcx>(
4244
/// for details.
4345
fn check_validity_requirement_strict<'tcx>(
4446
ty: TyAndLayout<'tcx>,
45-
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
47+
cx: &LayoutCx<'tcx>,
4648
kind: ValidityRequirement,
4749
) -> Result<bool, &'tcx LayoutError<'tcx>> {
4850
let machine = CompileTimeMachine::new(CanAccessMutGlobal::No, CheckAlignment::Error);
4951

50-
let mut cx = InterpCx::new(cx.tcx, rustc_span::DUMMY_SP, cx.param_env, machine);
52+
let mut cx = InterpCx::new(cx.tcx(), rustc_span::DUMMY_SP, cx.param_env, machine);
5153

5254
let allocated = cx
5355
.allocate(ty, MemoryKind::Machine(crate::const_eval::MemoryKind::Heap))
@@ -80,7 +82,7 @@ fn check_validity_requirement_strict<'tcx>(
8082
/// function for details.
8183
fn check_validity_requirement_lax<'tcx>(
8284
this: TyAndLayout<'tcx>,
83-
cx: &LayoutCx<'tcx, TyCtxt<'tcx>>,
85+
cx: &LayoutCx<'tcx>,
8486
init_kind: ValidityRequirement,
8587
) -> Result<bool, &'tcx LayoutError<'tcx>> {
8688
let scalar_allows_raw_init = move |s: Scalar| -> bool {

Diff for: compiler/rustc_error_codes/src/error_codes/E0799.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Something other than a type or const parameter has been used when one was
2+
expected.
3+
4+
Erroneous code example:
5+
6+
```compile_fail,E0799
7+
fn bad1() -> impl Sized + use<main> {}
8+
9+
fn bad2(x: ()) -> impl Sized + use<x> {}
10+
11+
fn main() {}
12+
```
13+
14+
In the given examples, for `bad1`, the name `main` corresponds to a function
15+
rather than a type or const parameter. In `bad2`, the name `x` corresponds to
16+
a function argument rather than a type or const parameter.
17+
18+
Only type and const parameters, including `Self`, may be captured by
19+
`use<...>` precise capturing bounds.

Diff for: compiler/rustc_error_codes/src/error_codes/E0800.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
A type or const parameter of the given name is not in scope.
2+
3+
Erroneous code examples:
4+
5+
```compile_fail,E0800
6+
fn missing() -> impl Sized + use<T> {}
7+
```
8+
9+
To fix this error, please verify you didn't misspell the type or const
10+
parameter, or double-check if you forgot to declare the parameter in
11+
the list of generics.

Diff for: compiler/rustc_error_codes/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,8 @@ E0795: 0795,
538538
E0796: 0796,
539539
E0797: 0797,
540540
E0798: 0798,
541+
E0799: 0799,
542+
E0800: 0800,
541543
);
542544
)
543545
}

Diff for: compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
726726
num_trait_args,
727727
num_impl_args,
728728
def_id,
729-
impl_def_id: impl_m.container_id(tcx),
729+
impl_m_def_id: impl_m.def_id,
730730
ty,
731731
return_span,
732732
}) {
@@ -844,12 +844,18 @@ where
844844

845845
struct RemapHiddenTyRegions<'tcx> {
846846
tcx: TyCtxt<'tcx>,
847+
/// Map from early/late params of the impl to identity regions of the RPITIT (GAT)
848+
/// in the trait.
847849
map: FxIndexMap<ty::Region<'tcx>, ty::Region<'tcx>>,
848850
num_trait_args: usize,
849851
num_impl_args: usize,
852+
/// Def id of the RPITIT (GAT) in the *trait*.
850853
def_id: DefId,
851-
impl_def_id: DefId,
854+
/// Def id of the impl method which owns the opaque hidden type we're remapping.
855+
impl_m_def_id: DefId,
856+
/// The hidden type we're remapping. Useful for diagnostics.
852857
ty: Ty<'tcx>,
858+
/// Span of the return type. Useful for diagnostics.
853859
return_span: Span,
854860
}
855861

@@ -885,8 +891,7 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
885891
ty::ReLateParam(_) => {}
886892
// Remap early-bound regions as long as they don't come from the `impl` itself,
887893
// in which case we don't really need to renumber them.
888-
ty::ReEarlyParam(ebr)
889-
if ebr.index >= self.tcx.generics_of(self.impl_def_id).count() as u32 => {}
894+
ty::ReEarlyParam(ebr) if ebr.index as usize >= self.num_impl_args => {}
890895
_ => return Ok(region),
891896
}
892897

@@ -899,7 +904,7 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
899904
);
900905
}
901906
} else {
902-
let guar = match region.opt_param_def_id(self.tcx, self.tcx.parent(self.def_id)) {
907+
let guar = match region.opt_param_def_id(self.tcx, self.impl_m_def_id) {
903908
Some(def_id) => {
904909
let return_span = if let ty::Alias(ty::Opaque, opaque_ty) = self.ty.kind() {
905910
self.tcx.def_span(opaque_ty.def_id)

Diff for: compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,6 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
584584
| Res::SelfTyParam { trait_: def_id } => {
585585
self.resolve_type_ref(def_id.expect_local(), param.hir_id);
586586
}
587-
Res::Err => {}
588587
Res::SelfTyAlias { alias_to, .. } => {
589588
self.tcx.dcx().emit_err(errors::PreciseCaptureSelfAlias {
590589
span: param.ident.span,
@@ -593,11 +592,10 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
593592
});
594593
}
595594
res => {
596-
self.tcx.dcx().emit_err(errors::BadPreciseCapture {
597-
span: param.ident.span,
598-
kind: "type or const",
599-
found: res.descr().to_string(),
600-
});
595+
self.tcx.dcx().span_delayed_bug(
596+
param.ident.span,
597+
format!("expected type or const param, found {res:?}"),
598+
);
601599
}
602600
},
603601
}

Diff for: compiler/rustc_hir_analysis/src/errors/precise_captures.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rustc_errors::E0799;
12
use rustc_macros::Diagnostic;
23
use rustc_span::{Span, Symbol};
34

@@ -43,7 +44,7 @@ pub(crate) struct BadPreciseCapture {
4344
}
4445

4546
#[derive(Diagnostic)]
46-
#[diag(hir_analysis_precise_capture_self_alias)]
47+
#[diag(hir_analysis_precise_capture_self_alias, code = E0799)]
4748
pub(crate) struct PreciseCaptureSelfAlias {
4849
#[primary_span]
4950
pub span: Span,

Diff for: compiler/rustc_hir_typeck/src/coercion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10491049
/// trait or region sub-obligations. (presumably we could, but it's not
10501050
/// particularly important for diagnostics...)
10511051
pub(crate) fn deref_once_mutably_for_diagnostic(&self, expr_ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
1052-
self.autoderef(DUMMY_SP, expr_ty).nth(1).and_then(|(deref_ty, _)| {
1052+
self.autoderef(DUMMY_SP, expr_ty).silence_errors().nth(1).and_then(|(deref_ty, _)| {
10531053
self.infcx
10541054
.type_implements_trait(
10551055
self.tcx.lang_items().deref_mut_trait()?,

Diff for: compiler/rustc_hir_typeck/src/expr.rs

+31-16
Original file line numberDiff line numberDiff line change
@@ -2864,13 +2864,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
28642864
(expr_t, "")
28652865
};
28662866
for (found_fields, args) in
2867-
self.get_field_candidates_considering_privacy(span, ty, mod_id, id)
2867+
self.get_field_candidates_considering_privacy_for_diag(span, ty, mod_id, id)
28682868
{
28692869
let field_names = found_fields.iter().map(|field| field.name).collect::<Vec<_>>();
28702870
let mut candidate_fields: Vec<_> = found_fields
28712871
.into_iter()
28722872
.filter_map(|candidate_field| {
2873-
self.check_for_nested_field_satisfying(
2873+
self.check_for_nested_field_satisfying_condition_for_diag(
28742874
span,
28752875
&|candidate_field, _| candidate_field.ident(self.tcx()) == field,
28762876
candidate_field,
@@ -2933,7 +2933,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29332933
.with_span_label(field.span, "private field")
29342934
}
29352935

2936-
pub(crate) fn get_field_candidates_considering_privacy(
2936+
pub(crate) fn get_field_candidates_considering_privacy_for_diag(
29372937
&self,
29382938
span: Span,
29392939
base_ty: Ty<'tcx>,
@@ -2942,7 +2942,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29422942
) -> Vec<(Vec<&'tcx ty::FieldDef>, GenericArgsRef<'tcx>)> {
29432943
debug!("get_field_candidates(span: {:?}, base_t: {:?}", span, base_ty);
29442944

2945-
self.autoderef(span, base_ty)
2945+
let mut autoderef = self.autoderef(span, base_ty).silence_errors();
2946+
let deref_chain: Vec<_> = autoderef.by_ref().collect();
2947+
2948+
// Don't probe if we hit the recursion limit, since it may result in
2949+
// quadratic blowup if we then try to further deref the results of this
2950+
// function. This is a best-effort method, after all.
2951+
if autoderef.reached_recursion_limit() {
2952+
return vec![];
2953+
}
2954+
2955+
deref_chain
2956+
.into_iter()
29462957
.filter_map(move |(base_t, _)| {
29472958
match base_t.kind() {
29482959
ty::Adt(base_def, args) if !base_def.is_enum() => {
@@ -2975,7 +2986,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29752986

29762987
/// This method is called after we have encountered a missing field error to recursively
29772988
/// search for the field
2978-
pub(crate) fn check_for_nested_field_satisfying(
2989+
pub(crate) fn check_for_nested_field_satisfying_condition_for_diag(
29792990
&self,
29802991
span: Span,
29812992
matches: &impl Fn(&ty::FieldDef, Ty<'tcx>) -> bool,
@@ -3000,20 +3011,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
30003011
if matches(candidate_field, field_ty) {
30013012
return Some(field_path);
30023013
} else {
3003-
for (nested_fields, subst) in
3004-
self.get_field_candidates_considering_privacy(span, field_ty, mod_id, hir_id)
3014+
for (nested_fields, subst) in self
3015+
.get_field_candidates_considering_privacy_for_diag(
3016+
span, field_ty, mod_id, hir_id,
3017+
)
30053018
{
30063019
// recursively search fields of `candidate_field` if it's a ty::Adt
30073020
for field in nested_fields {
3008-
if let Some(field_path) = self.check_for_nested_field_satisfying(
3009-
span,
3010-
matches,
3011-
field,
3012-
subst,
3013-
field_path.clone(),
3014-
mod_id,
3015-
hir_id,
3016-
) {
3021+
if let Some(field_path) = self
3022+
.check_for_nested_field_satisfying_condition_for_diag(
3023+
span,
3024+
matches,
3025+
field,
3026+
subst,
3027+
field_path.clone(),
3028+
mod_id,
3029+
hir_id,
3030+
)
3031+
{
30173032
return Some(field_path);
30183033
}
30193034
}

0 commit comments

Comments
 (0)