Skip to content

Commit ce519c5

Browse files
committed
Auto merge of #113474 - compiler-errors:rollup-07x1up7, r=compiler-errors
Rollup of 8 pull requests Successful merges: - #113413 (Add needs-triage to all new issues) - #113426 (Don't ICE in `resolve_bound_vars` when associated return-type bounds are in bad positions) - #113427 (Remove `variances_of` on RPITIT GATs, remove its one use-case) - #113441 (miri: check that assignments do not self-overlap) - #113453 (Remove unused from_method from rustc_on_unimplemented) - #113456 (Avoid calling report_forbidden_specialization for RPITITs) - #113466 (Update cargo) - #113467 (Fix comment of `fn_can_unwind`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d4096e0 + 7a22c7e commit ce519c5

File tree

20 files changed

+251
-57
lines changed

20 files changed

+251
-57
lines changed

compiler/rustc_const_eval/src/interpret/place.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -700,8 +700,13 @@ where
700700
assert_eq!(src.layout.size, dest.layout.size);
701701
}
702702

703+
// Setting `nonoverlapping` here only has an effect when we don't hit the fast-path above,
704+
// but that should at least match what LLVM does where `memcpy` is also only used when the
705+
// type does not have Scalar/ScalarPair layout.
706+
// (Or as the `Assign` docs put it, assignments "not producing primitives" must be
707+
// non-overlapping.)
703708
self.mem_copy(
704-
src.ptr, src.align, dest.ptr, dest.align, dest_size, /*nonoverlapping*/ false,
709+
src.ptr, src.align, dest.ptr, dest.align, dest_size, /*nonoverlapping*/ true,
705710
)
706711
}
707712

compiler/rustc_hir_analysis/src/check/check.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,14 @@ pub(super) fn check_specialization_validity<'tcx>(
722722
let result = opt_result.unwrap_or(Ok(()));
723723

724724
if let Err(parent_impl) = result {
725-
report_forbidden_specialization(tcx, impl_item, parent_impl);
725+
if !tcx.is_impl_trait_in_trait(impl_item) {
726+
report_forbidden_specialization(tcx, impl_item, parent_impl);
727+
} else {
728+
tcx.sess.delay_span_bug(
729+
DUMMY_SP,
730+
format!("parent item: {:?} not marked as default", parent_impl),
731+
);
732+
}
726733
}
727734
}
728735

@@ -1485,7 +1492,9 @@ fn opaque_type_cycle_error(
14851492
}
14861493

14871494
for closure_def_id in visitor.closures {
1488-
let Some(closure_local_did) = closure_def_id.as_local() else { continue; };
1495+
let Some(closure_local_did) = closure_def_id.as_local() else {
1496+
continue;
1497+
};
14891498
let typeck_results = tcx.typeck(closure_local_did);
14901499

14911500
let mut label_match = |ty: Ty<'_>, span| {

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_middle::ty::{self, TyCtxt, TypeSuperVisitable, TypeVisitor};
2222
use rustc_session::lint;
2323
use rustc_span::def_id::DefId;
2424
use rustc_span::symbol::{sym, Ident};
25-
use rustc_span::Span;
25+
use rustc_span::{Span, DUMMY_SP};
2626
use std::fmt;
2727

2828
use crate::errors;
@@ -338,7 +338,17 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
338338

339339
Scope::TraitRefBoundary { .. } => {
340340
// We should only see super trait lifetimes if there is a `Binder` above
341-
assert!(supertrait_bound_vars.is_empty());
341+
// though this may happen when we call `poly_trait_ref_binder_info` with
342+
// an (erroneous, #113423) associated return type bound in an impl header.
343+
if !supertrait_bound_vars.is_empty() {
344+
self.tcx.sess.delay_span_bug(
345+
DUMMY_SP,
346+
format!(
347+
"found supertrait lifetimes without a binder to append \
348+
them to: {supertrait_bound_vars:?}"
349+
),
350+
);
351+
}
342352
break (vec![], BinderScopeType::Normal);
343353
}
344354

compiler/rustc_hir_analysis/src/variance/mod.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_arena::DroplessArena;
77
use rustc_hir::def::DefKind;
88
use rustc_hir::def_id::{DefId, LocalDefId};
99
use rustc_middle::query::Providers;
10-
use rustc_middle::ty::{self, CrateVariancesMap, ImplTraitInTraitData, SubstsRef, Ty, TyCtxt};
10+
use rustc_middle::ty::{self, CrateVariancesMap, SubstsRef, Ty, TyCtxt};
1111
use rustc_middle::ty::{TypeSuperVisitable, TypeVisitable};
1212
use std::ops::ControlFlow;
1313

@@ -59,13 +59,6 @@ fn variances_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Variance] {
5959
DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder => {
6060
return variance_of_opaque(tcx, item_def_id);
6161
}
62-
DefKind::AssocTy => {
63-
if let Some(ImplTraitInTraitData::Trait { .. }) =
64-
tcx.opt_rpitit_info(item_def_id.to_def_id())
65-
{
66-
return variance_of_opaque(tcx, item_def_id);
67-
}
68-
}
6962
_ => {}
7063
}
7164

@@ -125,7 +118,8 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
125118
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty) check whether this is necessary
126119
// at all for RPITITs.
127120
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
128-
if self.tcx.is_impl_trait_in_trait(*def_id) =>
121+
if self.tcx.is_impl_trait_in_trait(*def_id)
122+
&& !self.tcx.lower_impl_trait_in_trait_to_assoc_ty() =>
129123
{
130124
self.visit_opaque(*def_id, substs)
131125
}

compiler/rustc_infer/src/infer/opaque_types.rs

-11
Original file line numberDiff line numberDiff line change
@@ -473,17 +473,6 @@ where
473473
}
474474
}
475475

476-
ty::Alias(ty::Projection, proj) if self.tcx.is_impl_trait_in_trait(proj.def_id) => {
477-
// Skip lifetime parameters that are not captures.
478-
let variances = self.tcx.variances_of(proj.def_id);
479-
480-
for (v, s) in std::iter::zip(variances, proj.substs.iter()) {
481-
if *v != ty::Variance::Bivariant {
482-
s.visit_with(self);
483-
}
484-
}
485-
}
486-
487476
_ => {
488477
ty.super_visit_with(self);
489478
}

compiler/rustc_middle/src/ty/layout.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -1110,12 +1110,11 @@ where
11101110
///
11111111
/// This takes two primary parameters:
11121112
///
1113-
/// * `codegen_fn_attr_flags` - these are flags calculated as part of the
1114-
/// codegen attrs for a defined function. For function pointers this set of
1115-
/// flags is the empty set. This is only applicable for Rust-defined
1116-
/// functions, and generally isn't needed except for small optimizations where
1117-
/// we try to say a function which otherwise might look like it could unwind
1118-
/// doesn't actually unwind (such as for intrinsics and such).
1113+
/// * `fn_def_id` - the `DefId` of the function. If this is provided then we can
1114+
/// determine more precisely if the function can unwind. If this is not provided
1115+
/// then we will only infer whether the function can unwind or not based on the
1116+
/// ABI of the function. For example, a function marked with `#[rustc_nounwind]`
1117+
/// is known to not unwind even if it's using Rust ABI.
11191118
///
11201119
/// * `abi` - this is the ABI that the function is defined with. This is the
11211120
/// primary factor for determining whether a function can unwind or not.
@@ -1147,11 +1146,6 @@ where
11471146
/// aborts the process.
11481147
/// * This affects whether functions have the LLVM `nounwind` attribute, which
11491148
/// affects various optimizations and codegen.
1150-
///
1151-
/// FIXME: this is actually buggy with respect to Rust functions. Rust functions
1152-
/// compiled with `-Cpanic=unwind` and referenced from another crate compiled
1153-
/// with `-Cpanic=abort` will look like they can't unwind when in fact they
1154-
/// might (from a foreign exception or similar).
11551149
#[inline]
11561150
#[tracing::instrument(level = "debug", skip(tcx))]
11571151
pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: SpecAbi) -> bool {

compiler/rustc_span/src/symbol.rs

-1
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,6 @@ symbols! {
759759
from_desugaring,
760760
from_fn,
761761
from_iter,
762-
from_method,
763762
from_output,
764763
from_residual,
765764
from_size_align_unchecked,

compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs

+1-19
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ pub trait TypeErrCtxtExt<'tcx> {
4141
static ALLOWED_FORMAT_SYMBOLS: &[Symbol] = &[
4242
kw::SelfUpper,
4343
sym::ItemContext,
44-
sym::from_method,
4544
sym::from_desugaring,
4645
sym::direct,
4746
sym::cause,
@@ -172,23 +171,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
172171
}
173172
}
174173

175-
if let ObligationCauseCode::ItemObligation(item)
176-
| ObligationCauseCode::BindingObligation(item, _)
177-
| ObligationCauseCode::ExprItemObligation(item, ..)
178-
| ObligationCauseCode::ExprBindingObligation(item, ..) = *obligation.cause.code()
179-
{
180-
// FIXME: maybe also have some way of handling methods
181-
// from other traits? That would require name resolution,
182-
// which we might want to be some sort of hygienic.
183-
//
184-
// Currently I'm leaving it for what I need for `try`.
185-
if self.tcx.trait_of_item(item) == Some(trait_ref.def_id) {
186-
let method = self.tcx.item_name(item);
187-
flags.push((sym::from_method, None));
188-
flags.push((sym::from_method, Some(method.to_string())));
189-
}
190-
}
191-
192174
if let Some(k) = obligation.cause.span.desugaring_kind() {
193175
flags.push((sym::from_desugaring, None));
194176
flags.push((sym::from_desugaring, Some(format!("{:?}", k))));
@@ -672,7 +654,7 @@ impl<'tcx> OnUnimplementedFormatString {
672654
None => {
673655
if let Some(val) = options.get(&s) {
674656
val
675-
} else if s == sym::from_desugaring || s == sym::from_method {
657+
} else if s == sym::from_desugaring {
676658
// don't break messages using these two arguments incorrectly
677659
&empty_string
678660
} else if s == sym::ItemContext {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#![feature(core_intrinsics)]
2+
#![feature(custom_mir)]
3+
4+
use std::intrinsics::mir::*;
5+
6+
// It's not that easy to fool the MIR validity check
7+
// which wants to prevent overlapping assignments...
8+
// So we use two separate pointer arguments, and then arrange for them to alias.
9+
#[custom_mir(dialect = "runtime", phase = "optimized")]
10+
pub fn self_copy(ptr1: *mut [i32; 4], ptr2: *mut [i32; 4]) {
11+
mir! {
12+
{
13+
*ptr1 = *ptr2; //~ERROR: overlapping ranges
14+
Return()
15+
}
16+
}
17+
}
18+
19+
pub fn main() {
20+
let mut x = [0; 4];
21+
let ptr = std::ptr::addr_of_mut!(x);
22+
self_copy(ptr, ptr);
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: Undefined Behavior: `copy_nonoverlapping` called on overlapping ranges
2+
--> $DIR/overlapping_assignment.rs:LL:CC
3+
|
4+
LL | *ptr1 = *ptr2;
5+
| ^^^^^^^^^^^^^ `copy_nonoverlapping` called on overlapping ranges
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
= note: BACKTRACE:
10+
= note: inside `self_copy` at $DIR/overlapping_assignment.rs:LL:CC
11+
note: inside `main`
12+
--> $DIR/overlapping_assignment.rs:LL:CC
13+
|
14+
LL | self_copy(ptr, ptr);
15+
| ^^^^^^^^^^^^^^^^^^^
16+
17+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
18+
19+
error: aborting due to previous error
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error[E0046]: not all trait items implemented, missing: `foo`
2+
--> $DIR/missing-feature-flag.rs:14:1
3+
|
4+
LL | async fn foo(_: T) -> &'static str;
5+
| ----------------------------------- `foo` from trait
6+
...
7+
LL | impl<T> MyTrait<T> for MyStruct {}
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `foo` in implementation
9+
10+
error[E0520]: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
11+
--> $DIR/missing-feature-flag.rs:18:5
12+
|
13+
LL | impl<T> MyTrait<T> for MyStruct {}
14+
| ------------------------------- parent `impl` is here
15+
...
16+
LL | async fn foo(_: i32) -> &'static str {}
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot specialize default item `foo`
18+
|
19+
= note: to specialize, `foo` in the parent `impl` must be marked `default`
20+
21+
error[E0308]: mismatched types
22+
--> $DIR/missing-feature-flag.rs:18:42
23+
|
24+
LL | async fn foo(_: i32) -> &'static str {}
25+
| ^^ expected `&str`, found `()`
26+
27+
error: aborting due to 3 previous errors
28+
29+
Some errors have detailed explanations: E0046, E0308, E0520.
30+
For more information about an error, try `rustc --explain E0046`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error[E0046]: not all trait items implemented, missing: `foo`
2+
--> $DIR/missing-feature-flag.rs:14:1
3+
|
4+
LL | async fn foo(_: T) -> &'static str;
5+
| ----------------------------------- `foo` from trait
6+
...
7+
LL | impl<T> MyTrait<T> for MyStruct {}
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `foo` in implementation
9+
10+
error[E0520]: `foo` specializes an item from a parent `impl`, but that item is not marked `default`
11+
--> $DIR/missing-feature-flag.rs:18:5
12+
|
13+
LL | impl<T> MyTrait<T> for MyStruct {}
14+
| ------------------------------- parent `impl` is here
15+
...
16+
LL | async fn foo(_: i32) -> &'static str {}
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot specialize default item `foo`
18+
|
19+
= note: to specialize, `foo` in the parent `impl` must be marked `default`
20+
21+
error[E0308]: mismatched types
22+
--> $DIR/missing-feature-flag.rs:18:42
23+
|
24+
LL | async fn foo(_: i32) -> &'static str {}
25+
| ^^ expected `&str`, found `()`
26+
27+
error: aborting due to 3 previous errors
28+
29+
Some errors have detailed explanations: E0046, E0308, E0520.
30+
For more information about an error, try `rustc --explain E0046`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// edition:2018
2+
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
3+
// revisions: current next
4+
5+
#![feature(async_fn_in_trait)]
6+
#![feature(min_specialization)]
7+
8+
struct MyStruct;
9+
10+
trait MyTrait<T> {
11+
async fn foo(_: T) -> &'static str;
12+
}
13+
14+
impl<T> MyTrait<T> for MyStruct {}
15+
//~^ ERROR: not all trait items implemented, missing: `foo` [E0046]
16+
17+
impl MyTrait<i32> for MyStruct {
18+
async fn foo(_: i32) -> &'static str {}
19+
//~^ ERROR: `foo` specializes an item from a parent `impl`, but that item is not marked `default` [E0520]
20+
//~| ERROR: mismatched types [E0308]
21+
}
22+
23+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(return_type_notation)]
2+
//~^ WARN the feature `return_type_notation` is incomplete
3+
4+
// Shouldn't ICE when we have a (bad) RTN in an impl header
5+
6+
trait Super1<'a> {
7+
fn bar<'b>() -> bool;
8+
}
9+
10+
impl Super1<'_, bar(): Send> for () {}
11+
//~^ ERROR associated type bindings are not allowed here
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/rtn-in-impl-signature.rs:1:12
3+
|
4+
LL | #![feature(return_type_notation)]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #109417 <https://github.com/rust-lang/rust/issues/109417> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error[E0229]: associated type bindings are not allowed here
11+
--> $DIR/rtn-in-impl-signature.rs:10:17
12+
|
13+
LL | impl Super1<'_, bar(): Send> for () {}
14+
| ^^^^^^^^^^^ associated type not allowed here
15+
16+
error: aborting due to previous error; 1 warning emitted
17+
18+
For more information about this error, try `rustc --explain E0229`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0277]: the trait bound `impl Foo<u8>: Foo<char>` is not satisfied
2+
--> $DIR/return-dont-satisfy-bounds.rs:13:34
3+
|
4+
LL | fn foo<F2: Foo<u8>>(self) -> impl Foo<u8> {
5+
| ^^^^^^^^^^^^ the trait `Foo<char>` is not implemented for `impl Foo<u8>`
6+
|
7+
= help: the trait `Foo<char>` is implemented for `Bar`
8+
note: required by a bound in `Foo::foo::{opaque#0}`
9+
--> $DIR/return-dont-satisfy-bounds.rs:7:30
10+
|
11+
LL | fn foo<F2>(self) -> impl Foo<T>;
12+
| ^^^^^^ required by this bound in `Foo::foo::{opaque#0}`
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)