Skip to content

Rollup of 8 pull requests #113429

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

Merged
merged 17 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
cdaef2c
Simplify duplicate checks for mir validator
WaffleLapkin May 24, 2023
5488a64
Fix incorrect documented default bufsize in bufreader/writer
shady-katy May 26, 2023
3c9a749
Add a test for `PartialEq` across `Allocator`s breaking inference (#1…
tgross35 Jul 4, 2023
a635bf7
Revert "alloc: Allow comparing `Box`s over different allocators"
tgross35 Jul 4, 2023
86728e7
Add a regression test for #109054
JohnTitor Jun 29, 2023
3acaa56
Prefer object candidates over impl candidates in new selection
compiler-errors Jul 6, 2023
c0c1551
Avoid calling item_name for RPITIT
spastorino Jul 6, 2023
07a230b
Do not assert >1 RPITITs on collect_return_position_impl_trait_in_tra…
spastorino Jul 6, 2023
388c230
Don't call type_of on TAIT in defining scope in new solver
compiler-errors Jun 28, 2023
3aa4561
Rollup merge of #111917 - WaffleLapkin:validate_unalloc, r=oli-obk
compiler-errors Jul 7, 2023
75febc6
Rollup merge of #112008 - intruder-kat:master, r=Nilstrieb
compiler-errors Jul 7, 2023
de49a9f
Rollup merge of #112825 - compiler-errors:tait-defining-cycle, r=lcnr
compiler-errors Jul 7, 2023
1cb31e7
Rollup merge of #113164 - JohnTitor:issue-109054, r=compiler-errors
compiler-errors Jul 7, 2023
7913d76
Rollup merge of #113318 - tgross35:113283-allocator-trait-eq, r=m-ou-se
compiler-errors Jul 7, 2023
f1c9098
Rollup merge of #113397 - compiler-errors:new-select-prefer-obj, r=lcnr
compiler-errors Jul 7, 2023
901c863
Rollup merge of #113419 - spastorino:new-rpitit-28, r=compiler-errors
compiler-errors Jul 7, 2023
45cb1ba
Rollup merge of #113421 - spastorino:new-rpitit-29, r=compiler-errors
compiler-errors Jul 7, 2023
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
23 changes: 9 additions & 14 deletions compiler/rustc_const_eval/src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ impl<'tcx> MirPass<'tcx> for Validator {
unwind_edge_count: 0,
reachable_blocks: traversal::reachable_as_bitset(body),
storage_liveness,
place_cache: Vec::new(),
value_cache: Vec::new(),
place_cache: FxHashSet::default(),
value_cache: FxHashSet::default(),
};
checker.visit_body(body);
checker.check_cleanup_control_flow();
Expand All @@ -95,8 +95,8 @@ struct TypeChecker<'a, 'tcx> {
unwind_edge_count: usize,
reachable_blocks: BitSet<BasicBlock>,
storage_liveness: ResultsCursor<'a, 'tcx, MaybeStorageLive<'static>>,
place_cache: Vec<PlaceRef<'tcx>>,
value_cache: Vec<u128>,
place_cache: FxHashSet<PlaceRef<'tcx>>,
value_cache: FxHashSet<u128>,
}

impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
Expand Down Expand Up @@ -951,10 +951,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {

self.value_cache.clear();
self.value_cache.extend(targets.iter().map(|(value, _)| value));
let all_len = self.value_cache.len();
self.value_cache.sort_unstable();
self.value_cache.dedup();
let has_duplicates = all_len != self.value_cache.len();
let has_duplicates = targets.iter().len() != self.value_cache.len();
if has_duplicates {
self.fail(
location,
Expand Down Expand Up @@ -987,16 +984,14 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
// passed by a reference to the callee. Consequently they must be non-overlapping.
// Currently this simply checks for duplicate places.
self.place_cache.clear();
self.place_cache.push(destination.as_ref());
self.place_cache.insert(destination.as_ref());
let mut has_duplicates = false;
for arg in args {
if let Operand::Move(place) = arg {
self.place_cache.push(place.as_ref());
has_duplicates |= !self.place_cache.insert(place.as_ref());
}
}
let all_len = self.place_cache.len();
let mut dedup = FxHashSet::default();
self.place_cache.retain(|p| dedup.insert(*p));
let has_duplicates = all_len != self.place_cache.len();

if has_duplicates {
self.fail(
location,
Expand Down
12 changes: 7 additions & 5 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,11 +669,13 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
)
.fold_with(&mut collector);

debug_assert_ne!(
collector.types.len(),
0,
"expect >1 RPITITs in call to `collect_return_position_impl_trait_in_trait_tys`"
);
if !unnormalized_trait_sig.output().references_error() {
debug_assert_ne!(
collector.types.len(),
0,
"expect >1 RPITITs in call to `collect_return_position_impl_trait_in_trait_tys`"
);
}

let trait_sig = ocx.normalize(&norm_cause, param_env, unnormalized_trait_sig);
trait_sig.error_reported()?;
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_infer/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ impl<'tcx> InferCtxt<'tcx> {
"impl has stricter requirements than trait"
);

if let Some(span) = self.tcx.hir().span_if_local(trait_item_def_id) {
let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
err.span_label(span, format!("definition of `{}` from trait", item_name));
if !self.tcx.is_impl_trait_in_trait(trait_item_def_id) {
if let Some(span) = self.tcx.hir().span_if_local(trait_item_def_id) {
let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
err.span_label(span, format!("definition of `{}` from trait", item_name));
}
}

err.span_label(error_span, format!("impl has extra requirement {}", requirement));
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/solve/eval_ctxt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
}
}

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

Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,18 @@ fn candidate_should_be_dropped_in_favor_of<'tcx>(
victim_idx >= other_idx
}
(_, CandidateSource::ParamEnv(_)) => true,

(
CandidateSource::BuiltinImpl(BuiltinImplSource::Object),
CandidateSource::BuiltinImpl(BuiltinImplSource::Object),
) => false,
(_, CandidateSource::BuiltinImpl(BuiltinImplSource::Object)) => true,

(CandidateSource::Impl(victim_def_id), CandidateSource::Impl(other_def_id)) => {
tcx.specializes((other_def_id, victim_def_id))
&& other.result.value.certainty == Certainty::Yes
}

_ => false,
}
}
Expand Down
27 changes: 27 additions & 0 deletions compiler/rustc_trait_selection/src/solve/trait_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use rustc_hir::{LangItem, Movability};
use rustc_infer::traits::query::NoSolution;
use rustc_infer::traits::util::supertraits;
use rustc_middle::traits::solve::{CanonicalResponse, Certainty, Goal, QueryResult};
use rustc_middle::traits::Reveal;
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams, TreatProjections};
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
use rustc_middle::ty::{TraitPredicate, TypeVisitableExt};
Expand Down Expand Up @@ -118,6 +119,32 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
return result;
}

// Don't call `type_of` on a local TAIT that's in the defining scope,
// since that may require calling `typeck` on the same item we're
// currently type checking, which will result in a fatal cycle that
// ideally we want to avoid, since we can make progress on this goal
// via an alias bound or a locally-inferred hidden type instead.
//
// Also, don't call `type_of` on a TAIT in `Reveal::All` mode, since
// we already normalize the self type in
// `assemble_candidates_after_normalizing_self_ty`, and we'd
// just be registering an identical candidate here.
//
// Returning `Err(NoSolution)` here is ok in `SolverMode::Coherence`
// since we'll always be registering an ambiguous candidate in
// `assemble_candidates_after_normalizing_self_ty` due to normalizing
// the TAIT.
if let ty::Alias(ty::Opaque, opaque_ty) = goal.predicate.self_ty().kind() {
if matches!(goal.param_env.reveal(), Reveal::All)
|| opaque_ty
.def_id
.as_local()
.is_some_and(|def_id| ecx.can_define_opaque_ty(def_id))
{
return Err(NoSolution);
}
}

ecx.probe_and_evaluate_goal_for_constituent_tys(
goal,
structural_traits::instantiate_constituent_tys_for_auto_trait,
Expand Down
35 changes: 9 additions & 26 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1319,56 +1319,39 @@ impl Clone for Box<str> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T, A1, A2> PartialEq<Box<T, A2>> for Box<T, A1>
where
T: ?Sized + PartialEq,
A1: Allocator,
A2: Allocator,
{
impl<T: ?Sized + PartialEq, A: Allocator> PartialEq for Box<T, A> {
#[inline]
fn eq(&self, other: &Box<T, A2>) -> bool {
fn eq(&self, other: &Self) -> bool {
PartialEq::eq(&**self, &**other)
}

#[inline]
fn ne(&self, other: &Box<T, A2>) -> bool {
fn ne(&self, other: &Self) -> bool {
PartialEq::ne(&**self, &**other)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T, A1, A2> PartialOrd<Box<T, A2>> for Box<T, A1>
where
T: ?Sized + PartialOrd,
A1: Allocator,
A2: Allocator,
{
impl<T: ?Sized + PartialOrd, A: Allocator> PartialOrd for Box<T, A> {
#[inline]
fn partial_cmp(&self, other: &Box<T, A2>) -> Option<Ordering> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
PartialOrd::partial_cmp(&**self, &**other)
}

#[inline]
fn lt(&self, other: &Box<T, A2>) -> bool {
fn lt(&self, other: &Self) -> bool {
PartialOrd::lt(&**self, &**other)
}

#[inline]
fn le(&self, other: &Box<T, A2>) -> bool {
fn le(&self, other: &Self) -> bool {
PartialOrd::le(&**self, &**other)
}

#[inline]
fn ge(&self, other: &Box<T, A2>) -> bool {
fn ge(&self, other: &Self) -> bool {
PartialOrd::ge(&**self, &**other)
}

#[inline]
fn gt(&self, other: &Box<T, A2>) -> bool {
fn gt(&self, other: &Self) -> bool {
PartialOrd::gt(&**self, &**other)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized + Ord, A: Allocator> Ord for Box<T, A> {
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/io/buffered/bufreader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct BufReader<R: ?Sized> {
}

impl<R: Read> BufReader<R> {
/// Creates a new `BufReader<R>` with a default buffer capacity. The default is currently 8 KB,
/// Creates a new `BufReader<R>` with a default buffer capacity. The default is currently 8 KiB,
/// but may change in the future.
///
/// # Examples
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/io/buffered/bufwriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub struct BufWriter<W: ?Sized + Write> {
}

impl<W: Write> BufWriter<W> {
/// Creates a new `BufWriter<W>` with a default buffer capacity. The default is currently 8 KB,
/// Creates a new `BufWriter<W>` with a default buffer capacity. The default is currently 8 KiB,
/// but may change in the future.
///
/// # Examples
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
error[E0726]: implicit elided lifetime not allowed here
--> $DIR/return-not-existing-pair.rs:12:20
|
LL | impl<'a, 'b, T, U> MyTrait<T> for U {
| ^^^^^^^^^^ expected lifetime parameters
|
help: indicate the anonymous lifetimes
|
LL | impl<'a, 'b, T, U> MyTrait<'_, '_, T> for U {
| +++++++

error[E0412]: cannot find type `ConnImpl` in this scope
--> $DIR/return-not-existing-pair.rs:8:48
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
| ^^^^^^^^ not found in this scope

error[E0186]: method `foo` has a `&self` declaration in the trait, but not in the impl
--> $DIR/return-not-existing-pair.rs:14:5
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
| ------------------------------------------------------------ `&self` used in trait
...
LL | async fn foo(_: T) -> (&'a U, &'b T) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&self` in impl

error[E0308]: mismatched types
--> $DIR/return-not-existing-pair.rs:14:42
|
LL | async fn foo(_: T) -> (&'a U, &'b T) {}
| ^^ expected `(&U, &T)`, found `()`
|
= note: expected tuple `(&'a U, &'b T)`
found unit type `()`

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0186, E0308, E0412, E0726.
For more information about an error, try `rustc --explain E0186`.
39 changes: 39 additions & 0 deletions tests/ui/async-await/in-trait/return-not-existing-pair.next.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
error[E0726]: implicit elided lifetime not allowed here
--> $DIR/return-not-existing-pair.rs:12:20
|
LL | impl<'a, 'b, T, U> MyTrait<T> for U {
| ^^^^^^^^^^ expected lifetime parameters
|
help: indicate the anonymous lifetimes
|
LL | impl<'a, 'b, T, U> MyTrait<'_, '_, T> for U {
| +++++++

error[E0412]: cannot find type `ConnImpl` in this scope
--> $DIR/return-not-existing-pair.rs:8:48
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
| ^^^^^^^^ not found in this scope

error[E0186]: method `foo` has a `&self` declaration in the trait, but not in the impl
--> $DIR/return-not-existing-pair.rs:14:5
|
LL | async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
| ------------------------------------------------------------ `&self` used in trait
...
LL | async fn foo(_: T) -> (&'a U, &'b T) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&self` in impl

error[E0308]: mismatched types
--> $DIR/return-not-existing-pair.rs:14:42
|
LL | async fn foo(_: T) -> (&'a U, &'b T) {}
| ^^ expected `(&U, &T)`, found `()`
|
= note: expected tuple `(&'a U, &'b T)`
found unit type `()`

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0186, E0308, E0412, E0726.
For more information about an error, try `rustc --explain E0186`.
19 changes: 19 additions & 0 deletions tests/ui/async-await/in-trait/return-not-existing-pair.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// edition:2021
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
// revisions: current next

#![feature(async_fn_in_trait)]

trait MyTrait<'a, 'b, T> {
async fn foo(&'a self, key: &'b T) -> (&'a ConnImpl, &'b T);
//~^ ERROR: cannot find type `ConnImpl` in this scope [E0412]
}

impl<'a, 'b, T, U> MyTrait<T> for U {
//~^ ERROR: implicit elided lifetime not allowed here [E0726]
async fn foo(_: T) -> (&'a U, &'b T) {}
//~^ ERROR: method `foo` has a `&self` declaration in the trait, but not in the impl [E0186]
//~| ERROR: mismatched types [E0308]
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0412]: cannot find type `Missing` in this scope
--> $DIR/return-not-existing-type-wrapping-rpitit.rs:10:25
|
LL | fn bar() -> Wrapper<Missing<impl Sized>>;
| ^^^^^^^ not found in this scope

error: aborting due to previous error

For more information about this error, try `rustc --explain E0412`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0412]: cannot find type `Missing` in this scope
--> $DIR/return-not-existing-type-wrapping-rpitit.rs:10:25
|
LL | fn bar() -> Wrapper<Missing<impl Sized>>;
| ^^^^^^^ not found in this scope

error: aborting due to previous error

For more information about this error, try `rustc --explain E0412`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// edition:2021
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
// revisions: current next

#![feature(return_position_impl_trait_in_trait)]

struct Wrapper<T>(T);

trait Foo {
fn bar() -> Wrapper<Missing<impl Sized>>;
//~^ ERROR: cannot find type `Missing` in this scope [E0412]
}

impl Foo for () {
fn bar() -> Wrapper<i32> {
Wrapper(0)
}
}

fn main() {}
2 changes: 1 addition & 1 deletion tests/ui/traits/new-solver/dont-remap-tait-substs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// compile-flags: -Ztrait-solver=next
// known-bug: #112825
// check-pass

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