Skip to content

Commit 29210cb

Browse files
committed
Auto merge of rust-lang#137283 - matthiaskrgr:rollup-nm296fd, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#120580 (Add `MAX_LEN_UTF8` and `MAX_LEN_UTF16` Constants) - rust-lang#132268 (Impl TryFrom<Vec<u8>> for String) - rust-lang#136093 (Match Ergonomics 2024: update old-edition behavior of feature gates) - rust-lang#136344 (Suggest replacing `.` with `::` in more error diagnostics.) - rust-lang#136690 (Use more explicit and reliable ptr select in sort impls) - rust-lang#136815 (CI: Stop /msys64/bin from being prepended to PATH in msys2 shell) - rust-lang#136923 (Lint `#[must_use]` attributes applied to methods in trait impls) - rust-lang#137155 (Organize `OsString`/`OsStr` shims) - rust-lang#137225 (vectorcall ABI: require SSE2) Failed merges: - rust-lang#136780 (std: move stdio to `sys`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ed49386 + 1d12831 commit 29210cb

File tree

98 files changed

+3089
-1017
lines changed

Some content is hidden

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

98 files changed

+3089
-1017
lines changed

.github/workflows/ci.yml

+5
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ jobs:
173173
- name: ensure the stable version number is correct
174174
run: src/ci/scripts/verify-stable-version-number.sh
175175

176+
# Show the environment just before we run the build
177+
# This makes it easier to diagnose problems with the above install scripts.
178+
- name: show the current environment
179+
run: src/ci/scripts/dump-environment.sh
180+
176181
- name: run the build
177182
# Redirect stderr to stdout to avoid reordering the two streams in the GHA logs.
178183
run: src/ci/scripts/run-build-from-ci.sh 2>&1

compiler/rustc_hir_typeck/src/pat.rs

+60-7
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,19 @@ enum InheritedRefMatchRule {
230230
/// underlying type is not a reference type, the inherited reference will be consumed.
231231
EatInner,
232232
/// When the underlying type is a reference type, reference patterns consume both layers of
233-
/// reference, i.e. they both reset the binding mode and consume the reference type. Reference
234-
/// patterns are not permitted when there is no underlying reference type, i.e. they can't eat
235-
/// only an inherited reference. This is the current stable Rust behavior.
236-
EatBoth,
233+
/// reference, i.e. they both reset the binding mode and consume the reference type.
234+
EatBoth {
235+
/// If `true`, an inherited reference will be considered when determining whether a reference
236+
/// pattern matches a given type:
237+
/// - If the underlying type is not a reference, a reference pattern may eat the inherited reference;
238+
/// - If the underlying type is a reference, a reference pattern matches if it can eat either one
239+
/// of the underlying and inherited references. E.g. a `&mut` pattern is allowed if either the
240+
/// underlying type is `&mut` or the inherited reference is `&mut`.
241+
/// If `false`, a reference pattern is only matched against the underlying type.
242+
/// This is `false` for stable Rust and `true` for both the `ref_pat_eat_one_layer_2024` and
243+
/// `ref_pat_eat_one_layer_2024_structural` feature gates.
244+
consider_inherited_ref: bool,
245+
},
237246
}
238247

239248
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
@@ -259,10 +268,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
259268
} else {
260269
// Currently, matching against an inherited ref on edition 2024 is an error.
261270
// Use `EatBoth` as a fallback to be similar to stable Rust.
262-
InheritedRefMatchRule::EatBoth
271+
InheritedRefMatchRule::EatBoth { consider_inherited_ref: false }
263272
}
264273
} else {
265-
InheritedRefMatchRule::EatBoth
274+
InheritedRefMatchRule::EatBoth {
275+
consider_inherited_ref: self.tcx.features().ref_pat_eat_one_layer_2024()
276+
|| self.tcx.features().ref_pat_eat_one_layer_2024_structural(),
277+
}
266278
}
267279
}
268280

@@ -2371,6 +2383,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23712383
// NB: This assumes that `&` patterns can match against mutable
23722384
// references (RFC 3627, Rule 5). If we implement a pattern typing
23732385
// ruleset with Rule 4 but not Rule 5, we'll need to check that here.
2386+
// FIXME(ref_pat_eat_one_layer_2024_structural): If we already tried
2387+
// matching the real reference, the error message should explain that
2388+
// falling back to the inherited reference didn't work. This should be
2389+
// the same error as the old-Edition version below.
23742390
debug_assert!(ref_pat_matches_mut_ref);
23752391
self.error_inherited_ref_mutability_mismatch(pat, pat_prefix_span);
23762392
}
@@ -2381,9 +2397,46 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23812397
return expected;
23822398
}
23832399
}
2384-
InheritedRefMatchRule::EatBoth => {
2400+
InheritedRefMatchRule::EatBoth { consider_inherited_ref: true } => {
23852401
// Reset binding mode on old editions
23862402
pat_info.binding_mode = ByRef::No;
2403+
2404+
if let ty::Ref(_, inner_ty, _) = *expected.kind() {
2405+
// Consume both the inherited and inner references.
2406+
if pat_mutbl.is_mut() && inh_mut.is_mut() {
2407+
// As a special case, a `&mut` reference pattern will be able to match
2408+
// against a reference type of any mutability if the inherited ref is
2409+
// mutable. Since this allows us to match against a shared reference
2410+
// type, we refer to this as "falling back" to matching the inherited
2411+
// reference, though we consume the real reference as well. We handle
2412+
// this here to avoid adding this case to the common logic below.
2413+
self.check_pat(inner, inner_ty, pat_info);
2414+
return expected;
2415+
} else {
2416+
// Otherwise, use the common logic below for matching the inner
2417+
// reference type.
2418+
// FIXME(ref_pat_eat_one_layer_2024_structural): If this results in a
2419+
// mutability mismatch, the error message should explain that falling
2420+
// back to the inherited reference didn't work. This should be the same
2421+
// error as the Edition 2024 version above.
2422+
}
2423+
} else {
2424+
// The expected type isn't a reference type, so only match against the
2425+
// inherited reference.
2426+
if pat_mutbl > inh_mut {
2427+
// We can't match a lone inherited shared reference with `&mut`.
2428+
self.error_inherited_ref_mutability_mismatch(pat, pat_prefix_span);
2429+
}
2430+
2431+
self.typeck_results.borrow_mut().skipped_ref_pats_mut().insert(pat.hir_id);
2432+
self.check_pat(inner, expected, pat_info);
2433+
return expected;
2434+
}
2435+
}
2436+
InheritedRefMatchRule::EatBoth { consider_inherited_ref: false } => {
2437+
// Reset binding mode on stable Rust. This will be a type error below if
2438+
// `expected` is not a reference type.
2439+
pat_info.binding_mode = ByRef::No;
23872440
self.add_rust_2024_migration_desugared_pat(
23882441
pat_info.top_info.hir_id,
23892442
pat,

compiler/rustc_monomorphize/messages.ftl

+35-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,40 @@
1-
monomorphize_abi_error_disabled_vector_type_call =
2-
this function call uses SIMD vector type `{$ty}` which (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled in the caller
3-
.label = function called here
4-
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
5-
monomorphize_abi_error_disabled_vector_type_def =
6-
this function definition uses SIMD vector type `{$ty}` which (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled
7-
.label = function defined here
1+
monomorphize_abi_error_disabled_vector_type =
2+
this function {$is_call ->
3+
[true] call
4+
*[false] definition
5+
} uses SIMD vector type `{$ty}` which (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled{$is_call ->
6+
[true] {" "}in the caller
7+
*[false] {""}
8+
}
9+
.label = function {$is_call ->
10+
[true] called
11+
*[false] defined
12+
} here
813
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
914
10-
monomorphize_abi_error_unsupported_vector_type_call =
11-
this function call uses SIMD vector type `{$ty}` which is not currently supported with the chosen ABI
12-
.label = function called here
13-
monomorphize_abi_error_unsupported_vector_type_def =
14-
this function definition uses SIMD vector type `{$ty}` which is not currently supported with the chosen ABI
15-
.label = function defined here
15+
monomorphize_abi_error_unsupported_vector_type =
16+
this function {$is_call ->
17+
[true] call
18+
*[false] definition
19+
} uses SIMD vector type `{$ty}` which is not currently supported with the chosen ABI
20+
.label = function {$is_call ->
21+
[true] called
22+
*[false] defined
23+
} here
24+
25+
monomorphize_abi_required_target_feature =
26+
this function {$is_call ->
27+
[true] call
28+
*[false] definition
29+
} uses ABI "{$abi}" which requires the `{$required_feature}` target feature, which is not enabled{$is_call ->
30+
[true] {" "}in the caller
31+
*[false] {""}
32+
}
33+
.label = function {$is_call ->
34+
[true] called
35+
*[false] defined
36+
} here
37+
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
1638
1739
monomorphize_couldnt_dump_mono_stats =
1840
unexpected error occurred while dumping monomorphization stats: {$error}

compiler/rustc_monomorphize/src/errors.rs

+17-18
Original file line numberDiff line numberDiff line change
@@ -70,37 +70,36 @@ pub(crate) struct UnknownCguCollectionMode<'a> {
7070
}
7171

7272
#[derive(LintDiagnostic)]
73-
#[diag(monomorphize_abi_error_disabled_vector_type_def)]
73+
#[diag(monomorphize_abi_error_disabled_vector_type)]
7474
#[help]
75-
pub(crate) struct AbiErrorDisabledVectorTypeDef<'a> {
75+
pub(crate) struct AbiErrorDisabledVectorType<'a> {
7676
#[label]
7777
pub span: Span,
7878
pub required_feature: &'a str,
7979
pub ty: Ty<'a>,
80+
/// Whether this is a problem at a call site or at a declaration.
81+
pub is_call: bool,
8082
}
8183

8284
#[derive(LintDiagnostic)]
83-
#[diag(monomorphize_abi_error_disabled_vector_type_call)]
84-
#[help]
85-
pub(crate) struct AbiErrorDisabledVectorTypeCall<'a> {
86-
#[label]
87-
pub span: Span,
88-
pub required_feature: &'a str,
89-
pub ty: Ty<'a>,
90-
}
91-
92-
#[derive(LintDiagnostic)]
93-
#[diag(monomorphize_abi_error_unsupported_vector_type_def)]
94-
pub(crate) struct AbiErrorUnsupportedVectorTypeDef<'a> {
85+
#[diag(monomorphize_abi_error_unsupported_vector_type)]
86+
pub(crate) struct AbiErrorUnsupportedVectorType<'a> {
9587
#[label]
9688
pub span: Span,
9789
pub ty: Ty<'a>,
90+
/// Whether this is a problem at a call site or at a declaration.
91+
pub is_call: bool,
9892
}
9993

100-
#[derive(LintDiagnostic)]
101-
#[diag(monomorphize_abi_error_unsupported_vector_type_call)]
102-
pub(crate) struct AbiErrorUnsupportedVectorTypeCall<'a> {
94+
#[derive(Diagnostic)]
95+
#[diag(monomorphize_abi_required_target_feature)]
96+
#[help]
97+
pub(crate) struct AbiRequiredTargetFeature<'a> {
98+
#[primary_span]
10399
#[label]
104100
pub span: Span,
105-
pub ty: Ty<'a>,
101+
pub required_feature: &'a str,
102+
pub abi: &'a str,
103+
/// Whether this is a problem at a call site or at a declaration.
104+
pub is_call: bool,
106105
}

compiler/rustc_monomorphize/src/mono_checks/abi_check.rs

+55-52
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ use rustc_middle::ty::inherent::*;
77
use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TyCtxt};
88
use rustc_session::lint::builtin::ABI_UNSUPPORTED_VECTOR_TYPES;
99
use rustc_span::def_id::DefId;
10-
use rustc_span::{DUMMY_SP, Span, Symbol};
11-
use rustc_target::callconv::{FnAbi, PassMode};
10+
use rustc_span::{DUMMY_SP, Span, Symbol, sym};
11+
use rustc_target::callconv::{Conv, FnAbi, PassMode};
1212

13-
use crate::errors::{
14-
AbiErrorDisabledVectorTypeCall, AbiErrorDisabledVectorTypeDef,
15-
AbiErrorUnsupportedVectorTypeCall, AbiErrorUnsupportedVectorTypeDef,
16-
};
13+
use crate::errors;
1714

1815
fn uses_vector_registers(mode: &PassMode, repr: &BackendRepr) -> bool {
1916
match mode {
@@ -28,35 +25,68 @@ fn uses_vector_registers(mode: &PassMode, repr: &BackendRepr) -> bool {
2825

2926
/// Checks whether a certain function ABI is compatible with the target features currently enabled
3027
/// for a certain function.
31-
/// If not, `emit_err` is called, with `Some(feature)` if a certain feature should be enabled and
32-
/// with `None` if no feature is known that would make the ABI compatible.
28+
/// `is_call` indicates whether this is a call-site check or a definition-site check;
29+
/// this is only relevant for the wording in the emitted error.
3330
fn do_check_abi<'tcx>(
3431
tcx: TyCtxt<'tcx>,
3532
abi: &FnAbi<'tcx, Ty<'tcx>>,
36-
target_feature_def: DefId,
37-
mut emit_err: impl FnMut(Ty<'tcx>, Option<&'static str>),
33+
def_id: DefId,
34+
is_call: bool,
35+
span: impl Fn() -> Span,
3836
) {
3937
let feature_def = tcx.sess.target.features_for_correct_vector_abi();
40-
let codegen_attrs = tcx.codegen_fn_attrs(target_feature_def);
38+
let codegen_attrs = tcx.codegen_fn_attrs(def_id);
39+
let have_feature = |feat: Symbol| {
40+
tcx.sess.unstable_target_features.contains(&feat)
41+
|| codegen_attrs.target_features.iter().any(|x| x.name == feat)
42+
};
4143
for arg_abi in abi.args.iter().chain(std::iter::once(&abi.ret)) {
4244
let size = arg_abi.layout.size;
4345
if uses_vector_registers(&arg_abi.mode, &arg_abi.layout.backend_repr) {
4446
// Find the first feature that provides at least this vector size.
4547
let feature = match feature_def.iter().find(|(bits, _)| size.bits() <= *bits) {
4648
Some((_, feature)) => feature,
4749
None => {
48-
emit_err(arg_abi.layout.ty, None);
50+
let span = span();
51+
tcx.emit_node_span_lint(
52+
ABI_UNSUPPORTED_VECTOR_TYPES,
53+
CRATE_HIR_ID,
54+
span,
55+
errors::AbiErrorUnsupportedVectorType {
56+
span,
57+
ty: arg_abi.layout.ty,
58+
is_call,
59+
},
60+
);
4961
continue;
5062
}
5163
};
52-
let feature_sym = Symbol::intern(feature);
53-
if !tcx.sess.unstable_target_features.contains(&feature_sym)
54-
&& !codegen_attrs.target_features.iter().any(|x| x.name == feature_sym)
55-
{
56-
emit_err(arg_abi.layout.ty, Some(&feature));
64+
if !have_feature(Symbol::intern(feature)) {
65+
// Emit error.
66+
let span = span();
67+
tcx.emit_node_span_lint(
68+
ABI_UNSUPPORTED_VECTOR_TYPES,
69+
CRATE_HIR_ID,
70+
span,
71+
errors::AbiErrorDisabledVectorType {
72+
span,
73+
required_feature: feature,
74+
ty: arg_abi.layout.ty,
75+
is_call,
76+
},
77+
);
5778
}
5879
}
5980
}
81+
// The `vectorcall` ABI is special in that it requires SSE2 no matter which types are being passed.
82+
if abi.conv == Conv::X86VectorCall && !have_feature(sym::sse2) {
83+
tcx.dcx().emit_err(errors::AbiRequiredTargetFeature {
84+
span: span(),
85+
required_feature: "sse2",
86+
abi: "vectorcall",
87+
is_call,
88+
});
89+
}
6090
}
6191

6292
/// Checks that the ABI of a given instance of a function does not contain vector-passed arguments
@@ -69,24 +99,13 @@ fn check_instance_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
6999
// function.
70100
return;
71101
};
72-
do_check_abi(tcx, abi, instance.def_id(), |ty, required_feature| {
73-
let span = tcx.def_span(instance.def_id());
74-
if let Some(required_feature) = required_feature {
75-
tcx.emit_node_span_lint(
76-
ABI_UNSUPPORTED_VECTOR_TYPES,
77-
CRATE_HIR_ID,
78-
span,
79-
AbiErrorDisabledVectorTypeDef { span, required_feature, ty },
80-
);
81-
} else {
82-
tcx.emit_node_span_lint(
83-
ABI_UNSUPPORTED_VECTOR_TYPES,
84-
CRATE_HIR_ID,
85-
span,
86-
AbiErrorUnsupportedVectorTypeDef { span, ty },
87-
);
88-
}
89-
})
102+
do_check_abi(
103+
tcx,
104+
abi,
105+
instance.def_id(),
106+
/*is_call*/ false,
107+
|| tcx.def_span(instance.def_id()),
108+
)
90109
}
91110

92111
/// Checks that a call expression does not try to pass a vector-passed argument which requires a
@@ -123,23 +142,7 @@ fn check_call_site_abi<'tcx>(
123142
// ABI failed to compute; this will not get through codegen.
124143
return;
125144
};
126-
do_check_abi(tcx, callee_abi, caller.def_id(), |ty, required_feature| {
127-
if let Some(required_feature) = required_feature {
128-
tcx.emit_node_span_lint(
129-
ABI_UNSUPPORTED_VECTOR_TYPES,
130-
CRATE_HIR_ID,
131-
span,
132-
AbiErrorDisabledVectorTypeCall { span, required_feature, ty },
133-
);
134-
} else {
135-
tcx.emit_node_span_lint(
136-
ABI_UNSUPPORTED_VECTOR_TYPES,
137-
CRATE_HIR_ID,
138-
span,
139-
AbiErrorUnsupportedVectorTypeCall { span, ty },
140-
);
141-
}
142-
});
145+
do_check_abi(tcx, callee_abi, caller.def_id(), /*is_call*/ true, || span);
143146
}
144147

145148
fn check_callees_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>, body: &mir::Body<'tcx>) {

0 commit comments

Comments
 (0)