Skip to content

Commit 7cc3da0

Browse files
committed
Auto merge of rust-lang#113429 - compiler-errors:rollup-wkv4w9a, r=compiler-errors
Rollup of 8 pull requests Successful merges: - rust-lang#111917 (Simplify duplicate checks for mir validator) - rust-lang#112008 (Fix incorrect documented default bufsize in bufreader/writer) - rust-lang#112825 (Don't call `type_of` on TAIT in defining scope in new solver) - rust-lang#113164 (Add a regression test for rust-lang#109054) - rust-lang#113318 (Revert "alloc: Allow comparing Boxs over different allocators", add regression test) - rust-lang#113397 (Prefer object candidates in new selection) - rust-lang#113419 (Avoid calling item_name for RPITIT) - rust-lang#113421 (Do not assert >1 RPITITs on collect_return_position_impl_trait_in_trait_tys) r? `@ghost` `@rustbot` modify labels: rollup
2 parents bb548f9 + 45cb1ba commit 7cc3da0

23 files changed

+307
-151
lines changed

compiler/rustc_const_eval/src/transform/validate.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ impl<'tcx> MirPass<'tcx> for Validator {
6767
unwind_edge_count: 0,
6868
reachable_blocks: traversal::reachable_as_bitset(body),
6969
storage_liveness,
70-
place_cache: Vec::new(),
71-
value_cache: Vec::new(),
70+
place_cache: FxHashSet::default(),
71+
value_cache: FxHashSet::default(),
7272
};
7373
checker.visit_body(body);
7474
checker.check_cleanup_control_flow();
@@ -95,8 +95,8 @@ struct TypeChecker<'a, 'tcx> {
9595
unwind_edge_count: usize,
9696
reachable_blocks: BitSet<BasicBlock>,
9797
storage_liveness: ResultsCursor<'a, 'tcx, MaybeStorageLive<'static>>,
98-
place_cache: Vec<PlaceRef<'tcx>>,
99-
value_cache: Vec<u128>,
98+
place_cache: FxHashSet<PlaceRef<'tcx>>,
99+
value_cache: FxHashSet<u128>,
100100
}
101101

102102
impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
@@ -951,10 +951,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
951951

952952
self.value_cache.clear();
953953
self.value_cache.extend(targets.iter().map(|(value, _)| value));
954-
let all_len = self.value_cache.len();
955-
self.value_cache.sort_unstable();
956-
self.value_cache.dedup();
957-
let has_duplicates = all_len != self.value_cache.len();
954+
let has_duplicates = targets.iter().len() != self.value_cache.len();
958955
if has_duplicates {
959956
self.fail(
960957
location,
@@ -987,16 +984,14 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
987984
// passed by a reference to the callee. Consequently they must be non-overlapping.
988985
// Currently this simply checks for duplicate places.
989986
self.place_cache.clear();
990-
self.place_cache.push(destination.as_ref());
987+
self.place_cache.insert(destination.as_ref());
988+
let mut has_duplicates = false;
991989
for arg in args {
992990
if let Operand::Move(place) = arg {
993-
self.place_cache.push(place.as_ref());
991+
has_duplicates |= !self.place_cache.insert(place.as_ref());
994992
}
995993
}
996-
let all_len = self.place_cache.len();
997-
let mut dedup = FxHashSet::default();
998-
self.place_cache.retain(|p| dedup.insert(*p));
999-
let has_duplicates = all_len != self.place_cache.len();
994+
1000995
if has_duplicates {
1001996
self.fail(
1002997
location,

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -669,11 +669,13 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
669669
)
670670
.fold_with(&mut collector);
671671

672-
debug_assert_ne!(
673-
collector.types.len(),
674-
0,
675-
"expect >1 RPITITs in call to `collect_return_position_impl_trait_in_trait_tys`"
676-
);
672+
if !unnormalized_trait_sig.output().references_error() {
673+
debug_assert_ne!(
674+
collector.types.len(),
675+
0,
676+
"expect >1 RPITITs in call to `collect_return_position_impl_trait_in_trait_tys`"
677+
);
678+
}
677679

678680
let trait_sig = ocx.normalize(&norm_cause, param_env, unnormalized_trait_sig);
679681
trait_sig.error_reported()?;

compiler/rustc_infer/src/traits/error_reporting/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ impl<'tcx> InferCtxt<'tcx> {
2525
"impl has stricter requirements than trait"
2626
);
2727

28-
if let Some(span) = self.tcx.hir().span_if_local(trait_item_def_id) {
29-
let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
30-
err.span_label(span, format!("definition of `{}` from trait", item_name));
28+
if !self.tcx.is_impl_trait_in_trait(trait_item_def_id) {
29+
if let Some(span) = self.tcx.hir().span_if_local(trait_item_def_id) {
30+
let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
31+
err.span_label(span, format!("definition of `{}` from trait", item_name));
32+
}
3133
}
3234

3335
err.span_label(error_span, format!("impl has extra requirement {}", requirement));

compiler/rustc_trait_selection/src/solve/eval_ctxt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
837837
}
838838
}
839839

840-
pub(super) fn can_define_opaque_ty(&mut self, def_id: LocalDefId) -> bool {
840+
pub(super) fn can_define_opaque_ty(&self, def_id: LocalDefId) -> bool {
841841
self.infcx.opaque_type_origin(def_id).is_some()
842842
}
843843

compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs

+8
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,18 @@ fn candidate_should_be_dropped_in_favor_of<'tcx>(
173173
victim_idx >= other_idx
174174
}
175175
(_, CandidateSource::ParamEnv(_)) => true,
176+
177+
(
178+
CandidateSource::BuiltinImpl(BuiltinImplSource::Object),
179+
CandidateSource::BuiltinImpl(BuiltinImplSource::Object),
180+
) => false,
181+
(_, CandidateSource::BuiltinImpl(BuiltinImplSource::Object)) => true,
182+
176183
(CandidateSource::Impl(victim_def_id), CandidateSource::Impl(other_def_id)) => {
177184
tcx.specializes((other_def_id, victim_def_id))
178185
&& other.result.value.certainty == Certainty::Yes
179186
}
187+
180188
_ => false,
181189
}
182190
}

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+27
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_hir::{LangItem, Movability};
77
use rustc_infer::traits::query::NoSolution;
88
use rustc_infer::traits::util::supertraits;
99
use rustc_middle::traits::solve::{CanonicalResponse, Certainty, Goal, QueryResult};
10+
use rustc_middle::traits::Reveal;
1011
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams, TreatProjections};
1112
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
1213
use rustc_middle::ty::{TraitPredicate, TypeVisitableExt};
@@ -118,6 +119,32 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
118119
return result;
119120
}
120121

122+
// Don't call `type_of` on a local TAIT that's in the defining scope,
123+
// since that may require calling `typeck` on the same item we're
124+
// currently type checking, which will result in a fatal cycle that
125+
// ideally we want to avoid, since we can make progress on this goal
126+
// via an alias bound or a locally-inferred hidden type instead.
127+
//
128+
// Also, don't call `type_of` on a TAIT in `Reveal::All` mode, since
129+
// we already normalize the self type in
130+
// `assemble_candidates_after_normalizing_self_ty`, and we'd
131+
// just be registering an identical candidate here.
132+
//
133+
// Returning `Err(NoSolution)` here is ok in `SolverMode::Coherence`
134+
// since we'll always be registering an ambiguous candidate in
135+
// `assemble_candidates_after_normalizing_self_ty` due to normalizing
136+
// the TAIT.
137+
if let ty::Alias(ty::Opaque, opaque_ty) = goal.predicate.self_ty().kind() {
138+
if matches!(goal.param_env.reveal(), Reveal::All)
139+
|| opaque_ty
140+
.def_id
141+
.as_local()
142+
.is_some_and(|def_id| ecx.can_define_opaque_ty(def_id))
143+
{
144+
return Err(NoSolution);
145+
}
146+
}
147+
121148
ecx.probe_and_evaluate_goal_for_constituent_tys(
122149
goal,
123150
structural_traits::instantiate_constituent_tys_for_auto_trait,

library/alloc/src/boxed.rs

+9-26
Original file line numberDiff line numberDiff line change
@@ -1319,56 +1319,39 @@ impl Clone for Box<str> {
13191319
}
13201320

13211321
#[stable(feature = "rust1", since = "1.0.0")]
1322-
impl<T, A1, A2> PartialEq<Box<T, A2>> for Box<T, A1>
1323-
where
1324-
T: ?Sized + PartialEq,
1325-
A1: Allocator,
1326-
A2: Allocator,
1327-
{
1322+
impl<T: ?Sized + PartialEq, A: Allocator> PartialEq for Box<T, A> {
13281323
#[inline]
1329-
fn eq(&self, other: &Box<T, A2>) -> bool {
1324+
fn eq(&self, other: &Self) -> bool {
13301325
PartialEq::eq(&**self, &**other)
13311326
}
1332-
13331327
#[inline]
1334-
fn ne(&self, other: &Box<T, A2>) -> bool {
1328+
fn ne(&self, other: &Self) -> bool {
13351329
PartialEq::ne(&**self, &**other)
13361330
}
13371331
}
1338-
13391332
#[stable(feature = "rust1", since = "1.0.0")]
1340-
impl<T, A1, A2> PartialOrd<Box<T, A2>> for Box<T, A1>
1341-
where
1342-
T: ?Sized + PartialOrd,
1343-
A1: Allocator,
1344-
A2: Allocator,
1345-
{
1333+
impl<T: ?Sized + PartialOrd, A: Allocator> PartialOrd for Box<T, A> {
13461334
#[inline]
1347-
fn partial_cmp(&self, other: &Box<T, A2>) -> Option<Ordering> {
1335+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
13481336
PartialOrd::partial_cmp(&**self, &**other)
13491337
}
1350-
13511338
#[inline]
1352-
fn lt(&self, other: &Box<T, A2>) -> bool {
1339+
fn lt(&self, other: &Self) -> bool {
13531340
PartialOrd::lt(&**self, &**other)
13541341
}
1355-
13561342
#[inline]
1357-
fn le(&self, other: &Box<T, A2>) -> bool {
1343+
fn le(&self, other: &Self) -> bool {
13581344
PartialOrd::le(&**self, &**other)
13591345
}
1360-
13611346
#[inline]
1362-
fn ge(&self, other: &Box<T, A2>) -> bool {
1347+
fn ge(&self, other: &Self) -> bool {
13631348
PartialOrd::ge(&**self, &**other)
13641349
}
1365-
13661350
#[inline]
1367-
fn gt(&self, other: &Box<T, A2>) -> bool {
1351+
fn gt(&self, other: &Self) -> bool {
13681352
PartialOrd::gt(&**self, &**other)
13691353
}
13701354
}
1371-
13721355
#[stable(feature = "rust1", since = "1.0.0")]
13731356
impl<T: ?Sized + Ord, A: Allocator> Ord for Box<T, A> {
13741357
#[inline]

library/std/src/io/buffered/bufreader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub struct BufReader<R: ?Sized> {
5353
}
5454

5555
impl<R: Read> BufReader<R> {
56-
/// Creates a new `BufReader<R>` with a default buffer capacity. The default is currently 8 KB,
56+
/// Creates a new `BufReader<R>` with a default buffer capacity. The default is currently 8 KiB,
5757
/// but may change in the future.
5858
///
5959
/// # Examples

library/std/src/io/buffered/bufwriter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub struct BufWriter<W: ?Sized + Write> {
8181
}
8282

8383
impl<W: Write> BufWriter<W> {
84-
/// Creates a new `BufWriter<W>` with a default buffer capacity. The default is currently 8 KB,
84+
/// Creates a new `BufWriter<W>` with a default buffer capacity. The default is currently 8 KiB,
8585
/// but may change in the future.
8686
///
8787
/// # Examples
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0726]: implicit elided lifetime not allowed here
2+
--> $DIR/return-not-existing-pair.rs:12:20
3+
|
4+
LL | impl<'a, 'b, T, U> MyTrait<T> for U {
5+
| ^^^^^^^^^^ expected lifetime parameters
6+
|
7+
help: indicate the anonymous lifetimes
8+
|
9+
LL | impl<'a, 'b, T, U> MyTrait<'_, '_, T> for U {
10+
| +++++++
11+
12+
error[E0412]: cannot find type `ConnImpl` in this scope
13+
--> $DIR/return-not-existing-pair.rs:8:48
14+
|
15+
LL | async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
16+
| ^^^^^^^^ not found in this scope
17+
18+
error[E0186]: method `foo` has a `&self` declaration in the trait, but not in the impl
19+
--> $DIR/return-not-existing-pair.rs:14:5
20+
|
21+
LL | async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
22+
| ------------------------------------------------------------ `&self` used in trait
23+
...
24+
LL | async fn foo(_: T) -> (&'a U, &'b T) {}
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&self` in impl
26+
27+
error[E0308]: mismatched types
28+
--> $DIR/return-not-existing-pair.rs:14:42
29+
|
30+
LL | async fn foo(_: T) -> (&'a U, &'b T) {}
31+
| ^^ expected `(&U, &T)`, found `()`
32+
|
33+
= note: expected tuple `(&'a U, &'b T)`
34+
found unit type `()`
35+
36+
error: aborting due to 4 previous errors
37+
38+
Some errors have detailed explanations: E0186, E0308, E0412, E0726.
39+
For more information about an error, try `rustc --explain E0186`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0726]: implicit elided lifetime not allowed here
2+
--> $DIR/return-not-existing-pair.rs:12:20
3+
|
4+
LL | impl<'a, 'b, T, U> MyTrait<T> for U {
5+
| ^^^^^^^^^^ expected lifetime parameters
6+
|
7+
help: indicate the anonymous lifetimes
8+
|
9+
LL | impl<'a, 'b, T, U> MyTrait<'_, '_, T> for U {
10+
| +++++++
11+
12+
error[E0412]: cannot find type `ConnImpl` in this scope
13+
--> $DIR/return-not-existing-pair.rs:8:48
14+
|
15+
LL | async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
16+
| ^^^^^^^^ not found in this scope
17+
18+
error[E0186]: method `foo` has a `&self` declaration in the trait, but not in the impl
19+
--> $DIR/return-not-existing-pair.rs:14:5
20+
|
21+
LL | async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
22+
| ------------------------------------------------------------ `&self` used in trait
23+
...
24+
LL | async fn foo(_: T) -> (&'a U, &'b T) {}
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&self` in impl
26+
27+
error[E0308]: mismatched types
28+
--> $DIR/return-not-existing-pair.rs:14:42
29+
|
30+
LL | async fn foo(_: T) -> (&'a U, &'b T) {}
31+
| ^^ expected `(&U, &T)`, found `()`
32+
|
33+
= note: expected tuple `(&'a U, &'b T)`
34+
found unit type `()`
35+
36+
error: aborting due to 4 previous errors
37+
38+
Some errors have detailed explanations: E0186, E0308, E0412, E0726.
39+
For more information about an error, try `rustc --explain E0186`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// edition:2021
2+
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
3+
// revisions: current next
4+
5+
#![feature(async_fn_in_trait)]
6+
7+
trait MyTrait<'a, 'b, T> {
8+
async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
9+
//~^ ERROR: cannot find type `ConnImpl` in this scope [E0412]
10+
}
11+
12+
impl<'a, 'b, T, U> MyTrait<T> for U {
13+
//~^ ERROR: implicit elided lifetime not allowed here [E0726]
14+
async fn foo(_: T) -> (&'a U, &'b T) {}
15+
//~^ ERROR: method `foo` has a `&self` declaration in the trait, but not in the impl [E0186]
16+
//~| ERROR: mismatched types [E0308]
17+
}
18+
19+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0412]: cannot find type `Missing` in this scope
2+
--> $DIR/return-not-existing-type-wrapping-rpitit.rs:10:25
3+
|
4+
LL | fn bar() -> Wrapper<Missing<impl Sized>>;
5+
| ^^^^^^^ not found in this scope
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0412`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0412]: cannot find type `Missing` in this scope
2+
--> $DIR/return-not-existing-type-wrapping-rpitit.rs:10:25
3+
|
4+
LL | fn bar() -> Wrapper<Missing<impl Sized>>;
5+
| ^^^^^^^ not found in this scope
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0412`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// edition:2021
2+
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
3+
// revisions: current next
4+
5+
#![feature(return_position_impl_trait_in_trait)]
6+
7+
struct Wrapper<T>(T);
8+
9+
trait Foo {
10+
fn bar() -> Wrapper<Missing<impl Sized>>;
11+
//~^ ERROR: cannot find type `Missing` in this scope [E0412]
12+
}
13+
14+
impl Foo for () {
15+
fn bar() -> Wrapper<i32> {
16+
Wrapper(0)
17+
}
18+
}
19+
20+
fn main() {}

tests/ui/traits/new-solver/dont-remap-tait-substs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// compile-flags: -Ztrait-solver=next
2-
// known-bug: #112825
2+
// check-pass
33

44
// Makes sure we don't prepopulate the MIR typeck of `define`
55
// with `Foo<T, U> = T`, but instead, `Foo<B, A> = B`, so that

0 commit comments

Comments
 (0)