Skip to content

Commit a166af7

Browse files
committed
Auto merge of #120903 - matthiaskrgr:rollup-tmsuzth, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #119213 (simd intrinsics: add simd_shuffle_generic and other missing intrinsics) - #120272 (Suppress suggestions in derive macro) - #120773 (large_assignments: Allow moves into functions) - #120874 (Take empty `where` bounds into account when suggesting predicates) - #120882 (interpret/write_discriminant: when encoding niched variant, ensure the stored value matches) - #120883 (interpret: rename ReadExternStatic → ExternStatic) - #120890 (Adapt `llvm-has-rust-patches` validation to take `llvm-config` into account.) - #120895 (don't skip coercions for types with errors) - #120896 (Print kind of coroutine closure) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 980cf08 + 870435b commit a166af7

File tree

47 files changed

+491
-137
lines changed

Some content is hidden

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

47 files changed

+491
-137
lines changed

compiler/rustc_const_eval/messages.ftl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ const_eval_error = {$error_kind ->
9898
const_eval_exact_div_has_remainder =
9999
exact_div: {$a} cannot be divided by {$b} without remainder
100100
101+
const_eval_extern_static =
102+
cannot access extern static ({$did})
101103
const_eval_fn_ptr_call =
102104
function pointers need an RFC before allowed to be called in {const_eval_const_context}s
103105
const_eval_for_loop_into_iter_non_const =
@@ -172,6 +174,10 @@ const_eval_invalid_meta =
172174
invalid metadata in wide pointer: total size is bigger than largest supported object
173175
const_eval_invalid_meta_slice =
174176
invalid metadata in wide pointer: slice is bigger than largest supported object
177+
178+
const_eval_invalid_niched_enum_variant_written =
179+
trying to set discriminant of a {$ty} to the niched variant, but the value does not match
180+
175181
const_eval_invalid_str =
176182
this string is not valid UTF-8: {$err}
177183
const_eval_invalid_tag =
@@ -298,8 +304,6 @@ const_eval_raw_ptr_to_int =
298304
.note = at compile-time, pointers do not have an integer value
299305
.note2 = avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior
300306
301-
const_eval_read_extern_static =
302-
cannot read from extern static ({$did})
303307
const_eval_read_pointer_as_int =
304308
unable to turn pointer into integer
305309
const_eval_realloc_or_alloc_with_offset =

compiler/rustc_const_eval/src/errors.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,9 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
497497
ScalarSizeMismatch(_) => const_eval_scalar_size_mismatch,
498498
UninhabitedEnumVariantWritten(_) => const_eval_uninhabited_enum_variant_written,
499499
UninhabitedEnumVariantRead(_) => const_eval_uninhabited_enum_variant_read,
500+
InvalidNichedEnumVariantWritten { .. } => {
501+
const_eval_invalid_niched_enum_variant_written
502+
}
500503
AbiMismatchArgument { .. } => const_eval_incompatible_types,
501504
AbiMismatchReturn { .. } => const_eval_incompatible_return_types,
502505
}
@@ -585,6 +588,9 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
585588
builder.arg("target_size", info.target_size);
586589
builder.arg("data_size", info.data_size);
587590
}
591+
InvalidNichedEnumVariantWritten { enum_ty } => {
592+
builder.arg("ty", enum_ty.to_string());
593+
}
588594
AbiMismatchArgument { caller_ty, callee_ty }
589595
| AbiMismatchReturn { caller_ty, callee_ty } => {
590596
builder.arg("caller_ty", caller_ty.to_string());
@@ -793,7 +799,7 @@ impl ReportErrorExt for UnsupportedOpInfo {
793799
UnsupportedOpInfo::ReadPartialPointer(_) => const_eval_partial_pointer_copy,
794800
UnsupportedOpInfo::ReadPointerAsInt(_) => const_eval_read_pointer_as_int,
795801
UnsupportedOpInfo::ThreadLocalStatic(_) => const_eval_thread_local_static,
796-
UnsupportedOpInfo::ReadExternStatic(_) => const_eval_read_extern_static,
802+
UnsupportedOpInfo::ExternStatic(_) => const_eval_extern_static,
797803
}
798804
}
799805
fn add_args<G: EmissionGuarantee>(self, _: &DiagCtxt, builder: &mut DiagnosticBuilder<'_, G>) {
@@ -812,7 +818,7 @@ impl ReportErrorExt for UnsupportedOpInfo {
812818
OverwritePartialPointer(ptr) | ReadPartialPointer(ptr) => {
813819
builder.arg("ptr", ptr);
814820
}
815-
ThreadLocalStatic(did) | ReadExternStatic(did) => {
821+
ThreadLocalStatic(did) | ExternStatic(did) => {
816822
builder.arg("did", format!("{did:?}"));
817823
}
818824
}

compiler/rustc_const_eval/src/interpret/discriminant.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
8585
// Write result.
8686
let niche_dest = self.project_field(dest, tag_field)?;
8787
self.write_immediate(*tag_val, &niche_dest)?;
88+
} else {
89+
// The untagged variant is implicitly encoded simply by having a value that is
90+
// outside the niche variants. But what if the data stored here does not
91+
// actually encode this variant? That would be bad! So let's double-check...
92+
let actual_variant = self.read_discriminant(&dest.to_op(self)?)?;
93+
if actual_variant != variant_index {
94+
throw_ub!(InvalidNichedEnumVariantWritten { enum_ty: dest.layout().ty });
95+
}
8896
}
8997
}
9098
}

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
557557
if self.tcx.is_foreign_item(def_id) {
558558
// This is unreachable in Miri, but can happen in CTFE where we actually *do* support
559559
// referencing arbitrary (declared) extern statics.
560-
throw_unsup!(ReadExternStatic(def_id));
560+
throw_unsup!(ExternStatic(def_id));
561561
}
562562

563563
// We don't give a span -- statics don't need that, they cannot be generic or associated.

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,17 @@ impl Diagnostic {
516516

517517
/// Helper for pushing to `self.suggestions`, if available (not disable).
518518
fn push_suggestion(&mut self, suggestion: CodeSuggestion) {
519+
for subst in &suggestion.substitutions {
520+
for part in &subst.parts {
521+
let span = part.span;
522+
let call_site = span.ctxt().outer_expn_data().call_site;
523+
if span.in_derive_expansion() && span.overlaps_or_adjacent(call_site) {
524+
// Ignore if spans is from derive macro.
525+
return;
526+
}
527+
}
528+
}
529+
519530
if let Ok(suggestions) = &mut self.suggestions {
520531
suggestions.push(suggestion);
521532
}

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
186186
let b = self.shallow_resolve(b);
187187
debug!("Coerce.tys({:?} => {:?})", a, b);
188188

189-
// Just ignore error types.
190-
if let Err(guar) = (a, b).error_reported() {
191-
// Best-effort try to unify these types -- we're already on the error path,
192-
// so this will have the side-effect of making sure we have no ambiguities
193-
// due to `[type error]` and `_` not coercing together.
194-
let _ = self.commit_if_ok(|_| {
195-
self.at(&self.cause, self.param_env).eq(DefineOpaqueTypes::Yes, a, b)
196-
});
197-
return success(vec![], Ty::new_error(self.fcx.tcx, guar), vec![]);
198-
}
199-
200189
// Coercing from `!` to any type is allowed:
201190
if a.is_never() {
202191
return success(simple(Adjust::NeverToAny)(b), b, vec![]);

compiler/rustc_middle/src/mir/interpret/error.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ pub enum UndefinedBehaviorInfo<'tcx> {
356356
UninhabitedEnumVariantWritten(VariantIdx),
357357
/// An uninhabited enum variant is projected.
358358
UninhabitedEnumVariantRead(VariantIdx),
359+
/// Trying to set discriminant to the niched variant, but the value does not match.
360+
InvalidNichedEnumVariantWritten { enum_ty: Ty<'tcx> },
359361
/// ABI-incompatible argument types.
360362
AbiMismatchArgument { caller_ty: Ty<'tcx>, callee_ty: Ty<'tcx> },
361363
/// ABI-incompatible return types.
@@ -468,7 +470,7 @@ pub enum UnsupportedOpInfo {
468470
/// Accessing thread local statics
469471
ThreadLocalStatic(DefId),
470472
/// Accessing an unsupported extern static.
471-
ReadExternStatic(DefId),
473+
ExternStatic(DefId),
472474
}
473475

474476
/// Error information for when the program exhausted the resources granted to it

compiler/rustc_middle/src/ty/diagnostics.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,17 @@ pub fn suggest_constraining_type_params<'a>(
358358
// trait Foo<T=()> {... }
359359
// - insert: `where T: Zar`
360360
if matches!(param.kind, hir::GenericParamKind::Type { default: Some(_), .. }) {
361+
// If we are here and the where clause span is of non-zero length
362+
// it means we're dealing with an empty where clause like this:
363+
// fn foo<X>(x: X) where { ... }
364+
// In that case we don't want to add another "where" (Fixes #120838)
365+
let where_prefix = if generics.where_clause_span.is_empty() { " where" } else { "" };
366+
361367
// Suggest a bound, but there is no existing `where` clause *and* the type param has a
362368
// default (`<T=Foo>`), so we suggest adding `where T: Bar`.
363369
suggestions.push((
364370
generics.tail_span_for_predicate_suggestion(),
365-
format!(" where {param_name}: {constraint}"),
371+
format!("{where_prefix} {param_name}: {constraint}"),
366372
SuggestChangingConstraintsMessage::RestrictTypeFurther { ty: param_name },
367373
));
368374
continue;

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,24 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
877877
ty::CoroutineClosure(did, args) => {
878878
p!(write("{{"));
879879
if !self.should_print_verbose() {
880-
p!(write("coroutine-closure"));
880+
match self.tcx().coroutine_kind(self.tcx().coroutine_for_closure(did)).unwrap()
881+
{
882+
hir::CoroutineKind::Desugared(
883+
hir::CoroutineDesugaring::Async,
884+
hir::CoroutineSource::Closure,
885+
) => p!("async closure"),
886+
hir::CoroutineKind::Desugared(
887+
hir::CoroutineDesugaring::AsyncGen,
888+
hir::CoroutineSource::Closure,
889+
) => p!("async gen closure"),
890+
hir::CoroutineKind::Desugared(
891+
hir::CoroutineDesugaring::Gen,
892+
hir::CoroutineSource::Closure,
893+
) => p!("gen closure"),
894+
_ => unreachable!(
895+
"coroutine from coroutine-closure should have CoroutineSource::Closure"
896+
),
897+
}
881898
// FIXME(eddyb) should use `def_span`.
882899
if let Some(did) = did.as_local() {
883900
if self.tcx().sess.opts.unstable_opts.span_free_formats {

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,15 @@ impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> {
666666
debug!(?def_id, ?fn_span);
667667

668668
for arg in args {
669-
if let Some(too_large_size) = self.operand_size_if_too_large(limit, &arg.node) {
669+
// Moving args into functions is typically implemented with pointer
670+
// passing at the llvm-ir level and not by memcpy's. So always allow
671+
// moving args into functions.
672+
let operand: &mir::Operand<'tcx> = &arg.node;
673+
if let mir::Operand::Move(_) = operand {
674+
continue;
675+
}
676+
677+
if let Some(too_large_size) = self.operand_size_if_too_large(limit, operand) {
670678
self.lint_large_assignment(limit.0, too_large_size, location, arg.span);
671679
};
672680
}

0 commit comments

Comments
 (0)