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 9 pull requests #137283

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0cd8694
Impl TryFrom<Vec<u8>> for String
elichai Oct 28, 2024
4c9b9d7
Use more explicit and reliable ptr select in sort impls
Voultapher Nov 3, 2024
5573cd3
Prevent /msys64/bin from being prepended to PATH
ChrisDenton Feb 10, 2025
ec8ec41
Print the environment a second time
ChrisDenton Feb 10, 2025
f3515fb
Remove ignored `#[must_use]` attributes from portable-simd
samueltardieu Feb 12, 2025
3e66ba7
Remove ignored `#[must_use]` attributes from Clippy
samueltardieu Feb 12, 2025
eec49bb
add MAX_LEN_UTF8 and MAX_LEN_UTF16 constants
HTGAzureX1212 Feb 2, 2024
09dc38f
Improve WTF-8 comments
thaliaarchi Feb 5, 2025
8b1a3a2
Simplify control flow with while-let
thaliaarchi Feb 6, 2025
05e4175
Synchronize platform adaptors for OsString/OsStr
thaliaarchi Feb 6, 2025
fe37ada
Suggest using :: instead of . in more cases.
zachs18 Jan 30, 2025
bfde43c
Suggest using :: instead of . for enums in some cases.
zachs18 Jan 31, 2025
ae7b45a
When giving a suggestion to use :: instead of . where the rhs is a ma…
zachs18 Jan 31, 2025
e639e88
Lint `#[must_use]` attributes applied to methods in trait impls
samueltardieu Feb 12, 2025
2c37250
Update `.` -> `::` tests for new diff suggestion format.
zachs18 Feb 11, 2025
e24833a
add test revisions for old-edition behavior of feature gates
dianne Jan 23, 2025
3e77657
remove old edition-2021-specific tests
dianne Jan 23, 2025
8dc64a4
"classic2021" and "structural2021" rulesets: add eat-inherited-ref-al…
dianne Jan 26, 2025
443c51d
"structural2021" ruleset: add fallback-to-outer (eat both) deref rule
dianne Jan 26, 2025
1ed74aa
add mixed-edition tests
dianne Jan 26, 2025
2c595d6
update unstable book
dianne Jan 26, 2025
799e0f7
add FIXMEs for diagnostic improvements
dianne Jan 31, 2025
2014962
"classic2021" ruleset: experimentally add fallback-to-outer (eat both)
dianne Jan 26, 2025
37bcc1c
clarify wording on doc comment
dianne Feb 17, 2025
0e758c4
rename `consider_inherited_ref_first` -> `consider_inherited_ref`
dianne Feb 17, 2025
0a15bfb
simplify fallback-to-outer condition on old editions
dianne Feb 17, 2025
7b1d030
mono-time abi_check: unify error paths for call and definition sites
RalfJung Feb 18, 2025
cd9b5c1
vectorcall ABI: error if sse2 is not available
RalfJung Feb 18, 2025
67d185b
Rollup merge of #120580 - HTGAzureX1212:HTGAzureX1212/issue-45795, r=…
matthiaskrgr Feb 19, 2025
a68d822
Rollup merge of #132268 - elichai:string_try_from_vec, r=Amanieu
matthiaskrgr Feb 19, 2025
ed57267
Rollup merge of #136093 - dianne:match-2024-for-edition-2021, r=Nadri…
matthiaskrgr Feb 19, 2025
6e368f3
Rollup merge of #136344 - zachs18:dot_notation_more_defkinds_3, r=dav…
matthiaskrgr Feb 19, 2025
3a96943
Rollup merge of #136690 - Voultapher:use-more-explicit-and-reliable-p…
matthiaskrgr Feb 19, 2025
a06ebac
Rollup merge of #136815 - ChrisDenton:fix-mingw-ci, r=Kobzol
matthiaskrgr Feb 19, 2025
93121f1
Rollup merge of #136923 - samueltardieu:push-vxxqvqwspssv, r=davidtwco
matthiaskrgr Feb 19, 2025
a3b1e03
Rollup merge of #137155 - thaliaarchi:wtf8-organize, r=ChrisDenton
matthiaskrgr Feb 19, 2025
1d12831
Rollup merge of #137225 - RalfJung:vectorcall, r=nnethercote
matthiaskrgr Feb 19, 2025
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
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ jobs:
- name: ensure the stable version number is correct
run: src/ci/scripts/verify-stable-version-number.sh

# Show the environment just before we run the build
# This makes it easier to diagnose problems with the above install scripts.
- name: show the current environment
run: src/ci/scripts/dump-environment.sh

- name: run the build
# Redirect stderr to stdout to avoid reordering the two streams in the GHA logs.
run: src/ci/scripts/run-build-from-ci.sh 2>&1
Expand Down
67 changes: 60 additions & 7 deletions compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,19 @@ enum InheritedRefMatchRule {
/// underlying type is not a reference type, the inherited reference will be consumed.
EatInner,
/// When the underlying type is a reference type, reference patterns consume both layers of
/// reference, i.e. they both reset the binding mode and consume the reference type. Reference
/// patterns are not permitted when there is no underlying reference type, i.e. they can't eat
/// only an inherited reference. This is the current stable Rust behavior.
EatBoth,
/// reference, i.e. they both reset the binding mode and consume the reference type.
EatBoth {
/// If `true`, an inherited reference will be considered when determining whether a reference
/// pattern matches a given type:
/// - If the underlying type is not a reference, a reference pattern may eat the inherited reference;
/// - If the underlying type is a reference, a reference pattern matches if it can eat either one
/// of the underlying and inherited references. E.g. a `&mut` pattern is allowed if either the
/// underlying type is `&mut` or the inherited reference is `&mut`.
/// If `false`, a reference pattern is only matched against the underlying type.
/// This is `false` for stable Rust and `true` for both the `ref_pat_eat_one_layer_2024` and
/// `ref_pat_eat_one_layer_2024_structural` feature gates.
consider_inherited_ref: bool,
},
}

impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Expand All @@ -259,10 +268,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else {
// Currently, matching against an inherited ref on edition 2024 is an error.
// Use `EatBoth` as a fallback to be similar to stable Rust.
InheritedRefMatchRule::EatBoth
InheritedRefMatchRule::EatBoth { consider_inherited_ref: false }
}
} else {
InheritedRefMatchRule::EatBoth
InheritedRefMatchRule::EatBoth {
consider_inherited_ref: self.tcx.features().ref_pat_eat_one_layer_2024()
|| self.tcx.features().ref_pat_eat_one_layer_2024_structural(),
}
}
}

Expand Down Expand Up @@ -2371,6 +2383,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// NB: This assumes that `&` patterns can match against mutable
// references (RFC 3627, Rule 5). If we implement a pattern typing
// ruleset with Rule 4 but not Rule 5, we'll need to check that here.
// FIXME(ref_pat_eat_one_layer_2024_structural): If we already tried
// matching the real reference, the error message should explain that
// falling back to the inherited reference didn't work. This should be
// the same error as the old-Edition version below.
debug_assert!(ref_pat_matches_mut_ref);
self.error_inherited_ref_mutability_mismatch(pat, pat_prefix_span);
}
Expand All @@ -2381,9 +2397,46 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return expected;
}
}
InheritedRefMatchRule::EatBoth => {
InheritedRefMatchRule::EatBoth { consider_inherited_ref: true } => {
// Reset binding mode on old editions
pat_info.binding_mode = ByRef::No;

if let ty::Ref(_, inner_ty, _) = *expected.kind() {
// Consume both the inherited and inner references.
if pat_mutbl.is_mut() && inh_mut.is_mut() {
// As a special case, a `&mut` reference pattern will be able to match
// against a reference type of any mutability if the inherited ref is
// mutable. Since this allows us to match against a shared reference
// type, we refer to this as "falling back" to matching the inherited
// reference, though we consume the real reference as well. We handle
// this here to avoid adding this case to the common logic below.
self.check_pat(inner, inner_ty, pat_info);
return expected;
} else {
// Otherwise, use the common logic below for matching the inner
// reference type.
// FIXME(ref_pat_eat_one_layer_2024_structural): If this results in a
// mutability mismatch, the error message should explain that falling
// back to the inherited reference didn't work. This should be the same
// error as the Edition 2024 version above.
}
} else {
// The expected type isn't a reference type, so only match against the
// inherited reference.
if pat_mutbl > inh_mut {
// We can't match a lone inherited shared reference with `&mut`.
self.error_inherited_ref_mutability_mismatch(pat, pat_prefix_span);
}

self.typeck_results.borrow_mut().skipped_ref_pats_mut().insert(pat.hir_id);
self.check_pat(inner, expected, pat_info);
return expected;
}
}
InheritedRefMatchRule::EatBoth { consider_inherited_ref: false } => {
// Reset binding mode on stable Rust. This will be a type error below if
// `expected` is not a reference type.
pat_info.binding_mode = ByRef::No;
self.add_rust_2024_migration_desugared_pat(
pat_info.top_info.hir_id,
pat,
Expand Down
48 changes: 35 additions & 13 deletions compiler/rustc_monomorphize/messages.ftl
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
monomorphize_abi_error_disabled_vector_type_call =
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
.label = function called here
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
monomorphize_abi_error_disabled_vector_type_def =
this function definition uses SIMD vector type `{$ty}` which (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled
.label = function defined here
monomorphize_abi_error_disabled_vector_type =
this function {$is_call ->
[true] call
*[false] definition
} uses SIMD vector type `{$ty}` which (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled{$is_call ->
[true] {" "}in the caller
*[false] {""}
}
.label = function {$is_call ->
[true] called
*[false] defined
} here
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)

monomorphize_abi_error_unsupported_vector_type_call =
this function call uses SIMD vector type `{$ty}` which is not currently supported with the chosen ABI
.label = function called here
monomorphize_abi_error_unsupported_vector_type_def =
this function definition uses SIMD vector type `{$ty}` which is not currently supported with the chosen ABI
.label = function defined here
monomorphize_abi_error_unsupported_vector_type =
this function {$is_call ->
[true] call
*[false] definition
} uses SIMD vector type `{$ty}` which is not currently supported with the chosen ABI
.label = function {$is_call ->
[true] called
*[false] defined
} here

monomorphize_abi_required_target_feature =
this function {$is_call ->
[true] call
*[false] definition
} uses ABI "{$abi}" which requires the `{$required_feature}` target feature, which is not enabled{$is_call ->
[true] {" "}in the caller
*[false] {""}
}
.label = function {$is_call ->
[true] called
*[false] defined
} here
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)

monomorphize_couldnt_dump_mono_stats =
unexpected error occurred while dumping monomorphization stats: {$error}
Expand Down
35 changes: 17 additions & 18 deletions compiler/rustc_monomorphize/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,36 @@ pub(crate) struct UnknownCguCollectionMode<'a> {
}

#[derive(LintDiagnostic)]
#[diag(monomorphize_abi_error_disabled_vector_type_def)]
#[diag(monomorphize_abi_error_disabled_vector_type)]
#[help]
pub(crate) struct AbiErrorDisabledVectorTypeDef<'a> {
pub(crate) struct AbiErrorDisabledVectorType<'a> {
#[label]
pub span: Span,
pub required_feature: &'a str,
pub ty: Ty<'a>,
/// Whether this is a problem at a call site or at a declaration.
pub is_call: bool,
}

#[derive(LintDiagnostic)]
#[diag(monomorphize_abi_error_disabled_vector_type_call)]
#[help]
pub(crate) struct AbiErrorDisabledVectorTypeCall<'a> {
#[label]
pub span: Span,
pub required_feature: &'a str,
pub ty: Ty<'a>,
}

#[derive(LintDiagnostic)]
#[diag(monomorphize_abi_error_unsupported_vector_type_def)]
pub(crate) struct AbiErrorUnsupportedVectorTypeDef<'a> {
#[diag(monomorphize_abi_error_unsupported_vector_type)]
pub(crate) struct AbiErrorUnsupportedVectorType<'a> {
#[label]
pub span: Span,
pub ty: Ty<'a>,
/// Whether this is a problem at a call site or at a declaration.
pub is_call: bool,
}

#[derive(LintDiagnostic)]
#[diag(monomorphize_abi_error_unsupported_vector_type_call)]
pub(crate) struct AbiErrorUnsupportedVectorTypeCall<'a> {
#[derive(Diagnostic)]
#[diag(monomorphize_abi_required_target_feature)]
#[help]
pub(crate) struct AbiRequiredTargetFeature<'a> {
#[primary_span]
#[label]
pub span: Span,
pub ty: Ty<'a>,
pub required_feature: &'a str,
pub abi: &'a str,
/// Whether this is a problem at a call site or at a declaration.
pub is_call: bool,
}
107 changes: 55 additions & 52 deletions compiler/rustc_monomorphize/src/mono_checks/abi_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ use rustc_middle::ty::inherent::*;
use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TyCtxt};
use rustc_session::lint::builtin::ABI_UNSUPPORTED_VECTOR_TYPES;
use rustc_span::def_id::DefId;
use rustc_span::{DUMMY_SP, Span, Symbol};
use rustc_target::callconv::{FnAbi, PassMode};
use rustc_span::{DUMMY_SP, Span, Symbol, sym};
use rustc_target::callconv::{Conv, FnAbi, PassMode};

use crate::errors::{
AbiErrorDisabledVectorTypeCall, AbiErrorDisabledVectorTypeDef,
AbiErrorUnsupportedVectorTypeCall, AbiErrorUnsupportedVectorTypeDef,
};
use crate::errors;

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

/// Checks whether a certain function ABI is compatible with the target features currently enabled
/// for a certain function.
/// If not, `emit_err` is called, with `Some(feature)` if a certain feature should be enabled and
/// with `None` if no feature is known that would make the ABI compatible.
/// `is_call` indicates whether this is a call-site check or a definition-site check;
/// this is only relevant for the wording in the emitted error.
fn do_check_abi<'tcx>(
tcx: TyCtxt<'tcx>,
abi: &FnAbi<'tcx, Ty<'tcx>>,
target_feature_def: DefId,
mut emit_err: impl FnMut(Ty<'tcx>, Option<&'static str>),
def_id: DefId,
is_call: bool,
span: impl Fn() -> Span,
) {
let feature_def = tcx.sess.target.features_for_correct_vector_abi();
let codegen_attrs = tcx.codegen_fn_attrs(target_feature_def);
let codegen_attrs = tcx.codegen_fn_attrs(def_id);
let have_feature = |feat: Symbol| {
tcx.sess.unstable_target_features.contains(&feat)
|| codegen_attrs.target_features.iter().any(|x| x.name == feat)
};
for arg_abi in abi.args.iter().chain(std::iter::once(&abi.ret)) {
let size = arg_abi.layout.size;
if uses_vector_registers(&arg_abi.mode, &arg_abi.layout.backend_repr) {
// Find the first feature that provides at least this vector size.
let feature = match feature_def.iter().find(|(bits, _)| size.bits() <= *bits) {
Some((_, feature)) => feature,
None => {
emit_err(arg_abi.layout.ty, None);
let span = span();
tcx.emit_node_span_lint(
ABI_UNSUPPORTED_VECTOR_TYPES,
CRATE_HIR_ID,
span,
errors::AbiErrorUnsupportedVectorType {
span,
ty: arg_abi.layout.ty,
is_call,
},
);
continue;
}
};
let feature_sym = Symbol::intern(feature);
if !tcx.sess.unstable_target_features.contains(&feature_sym)
&& !codegen_attrs.target_features.iter().any(|x| x.name == feature_sym)
{
emit_err(arg_abi.layout.ty, Some(&feature));
if !have_feature(Symbol::intern(feature)) {
// Emit error.
let span = span();
tcx.emit_node_span_lint(
ABI_UNSUPPORTED_VECTOR_TYPES,
CRATE_HIR_ID,
span,
errors::AbiErrorDisabledVectorType {
span,
required_feature: feature,
ty: arg_abi.layout.ty,
is_call,
},
);
}
}
}
// The `vectorcall` ABI is special in that it requires SSE2 no matter which types are being passed.
if abi.conv == Conv::X86VectorCall && !have_feature(sym::sse2) {
tcx.dcx().emit_err(errors::AbiRequiredTargetFeature {
span: span(),
required_feature: "sse2",
abi: "vectorcall",
is_call,
});
}
}

/// Checks that the ABI of a given instance of a function does not contain vector-passed arguments
Expand All @@ -69,24 +99,13 @@ fn check_instance_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
// function.
return;
};
do_check_abi(tcx, abi, instance.def_id(), |ty, required_feature| {
let span = tcx.def_span(instance.def_id());
if let Some(required_feature) = required_feature {
tcx.emit_node_span_lint(
ABI_UNSUPPORTED_VECTOR_TYPES,
CRATE_HIR_ID,
span,
AbiErrorDisabledVectorTypeDef { span, required_feature, ty },
);
} else {
tcx.emit_node_span_lint(
ABI_UNSUPPORTED_VECTOR_TYPES,
CRATE_HIR_ID,
span,
AbiErrorUnsupportedVectorTypeDef { span, ty },
);
}
})
do_check_abi(
tcx,
abi,
instance.def_id(),
/*is_call*/ false,
|| tcx.def_span(instance.def_id()),
)
}

/// Checks that a call expression does not try to pass a vector-passed argument which requires a
Expand Down Expand Up @@ -123,23 +142,7 @@ fn check_call_site_abi<'tcx>(
// ABI failed to compute; this will not get through codegen.
return;
};
do_check_abi(tcx, callee_abi, caller.def_id(), |ty, required_feature| {
if let Some(required_feature) = required_feature {
tcx.emit_node_span_lint(
ABI_UNSUPPORTED_VECTOR_TYPES,
CRATE_HIR_ID,
span,
AbiErrorDisabledVectorTypeCall { span, required_feature, ty },
);
} else {
tcx.emit_node_span_lint(
ABI_UNSUPPORTED_VECTOR_TYPES,
CRATE_HIR_ID,
span,
AbiErrorUnsupportedVectorTypeCall { span, ty },
);
}
});
do_check_abi(tcx, callee_abi, caller.def_id(), /*is_call*/ true, || span);
}

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