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 6 pull requests #113420

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
4 changes: 1 addition & 3 deletions compiler/rustc_trait_selection/src/solve/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for NormalizationFolder<'_, 'tcx> {
// We don't normalize opaque types unless we have
// `Reveal::All`, even if we're in the defining scope.
let data = match *ty.kind() {
ty::Alias(kind, alias_ty) if kind != ty::Opaque || reveal == Reveal::UserFacing => {
alias_ty
}
ty::Alias(kind, alias_ty) if kind != ty::Opaque || reveal == Reveal::All => alias_ty,
_ => return ty.try_super_fold_with(self),
};

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
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
30 changes: 0 additions & 30 deletions tests/ui/async-await/in-trait/async-associated-types2.rs

This file was deleted.

2 changes: 1 addition & 1 deletion tests/ui/dyn-star/param-env-region-infer.current.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0282]: type annotations needed
--> $DIR/param-env-region-infer.rs:16:10
--> $DIR/param-env-region-infer.rs:18:10
|
LL | t as _
| ^ cannot infer type
Expand Down
29 changes: 29 additions & 0 deletions tests/ui/dyn-star/param-env-region-infer.next.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
error[E0391]: cycle detected when computing type of `make_dyn_star::{opaque#0}`
--> $DIR/param-env-region-infer.rs:16:60
|
LL | fn make_dyn_star<'a, T: PointerLike + Debug + 'a>(t: T) -> impl PointerLike + Debug + 'a {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires type-checking `make_dyn_star`...
--> $DIR/param-env-region-infer.rs:16:1
|
LL | fn make_dyn_star<'a, T: PointerLike + Debug + 'a>(t: T) -> impl PointerLike + Debug + 'a {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: ...which requires computing layout of `make_dyn_star::{opaque#0}`...
= note: ...which requires normalizing `make_dyn_star::{opaque#0}`...
= note: ...which again requires computing type of `make_dyn_star::{opaque#0}`, completing the cycle
note: cycle used when checking item types in top-level module
--> $DIR/param-env-region-infer.rs:10:1
|
LL | / #![feature(dyn_star, pointer_like_trait)]
LL | | #![allow(incomplete_features)]
LL | |
LL | | use std::fmt::Debug;
... |
LL | |
LL | | fn main() {}
| |____________^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0391`.
6 changes: 4 additions & 2 deletions tests/ui/dyn-star/param-env-region-infer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// revisions: current next
//[next] compile-flags: -Ztrait-solver=next
//[next] check-pass
// Need `-Zdeduplicate-diagnostics=yes` because the number of cycle errors
// emitted is for some horrible reason platform-specific.
//[next] compile-flags: -Ztrait-solver=next -Zdeduplicate-diagnostics=yes
// incremental

// checks that we don't ICE if there are region inference variables in the environment
Expand All @@ -13,6 +14,7 @@ use std::fmt::Debug;
use std::marker::PointerLike;

fn make_dyn_star<'a, T: PointerLike + Debug + 'a>(t: T) -> impl PointerLike + Debug + 'a {
//[next]~^ ERROR cycle detected when computing
t as _
//[current]~^ ERROR type annotations needed
}
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/impl-trait/reveal-during-codegen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// build-pass
// revisions: current next
//[next] compile-flags: -Ztrait-solver=next

fn test() -> Option<impl Sized> {
Some("")
}

fn main() {
test();
}
1 change: 1 addition & 0 deletions tests/ui/issues/issue-67552.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// build-fail
// compile-flags: -Copt-level=0
// normalize-stderr-test: ".nll/" -> "/"
// ignore-compare-mode-next-solver (hangs)

fn main() {
rec(Empty);
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/issues/issue-67552.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: reached the recursion limit while instantiating `rec::<&mut &mut &mut &mut &mut ...>`
--> $DIR/issue-67552.rs:29:9
--> $DIR/issue-67552.rs:30:9
|
LL | rec(identity(&mut it))
| ^^^^^^^^^^^^^^^^^^^^^^
|
note: `rec` defined here
--> $DIR/issue-67552.rs:22:1
--> $DIR/issue-67552.rs:23:1
|
LL | / fn rec<T>(mut it: T)
LL | | where
Expand Down
1 change: 1 addition & 0 deletions tests/ui/recursion/issue-95134.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// compile-flags: -Copt-level=0
// dont-check-failure-status
// dont-check-compiler-stderr
// ignore-compare-mode-next-solver (hangs)

pub fn encode_num<Writer: ExampleWriter>(n: u32, mut writer: Writer) -> Result<(), Writer::Error> {
if n > 15 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error[E0283]: type annotations needed: cannot satisfy `Foo: Send`
--> $DIR/dont-type_of-tait-in-defining-scope.rs:16:5
|
LL | needs_send::<Foo>();
| ^^^^^^^^^^^^^^^^^
|
= note: cannot satisfy `Foo: Send`
note: required by a bound in `needs_send`
--> $DIR/dont-type_of-tait-in-defining-scope.rs:13:18
|
LL | fn needs_send<T: Send>() {}
| ^^^^ required by this bound in `needs_send`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0283`.
22 changes: 22 additions & 0 deletions tests/ui/traits/new-solver/dont-type_of-tait-in-defining-scope.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// revisions: is_send not_send
// compile-flags: -Ztrait-solver=next
//[is_send] check-pass

#![feature(type_alias_impl_trait)]

#[cfg(is_send)]
type Foo = impl Send;

#[cfg(not_send)]
type Foo = impl Sized;

fn needs_send<T: Send>() {}

fn test() {
needs_send::<Foo>();
//[not_send]~^ ERROR type annotations needed: cannot satisfy `Foo: Send`
}

fn main() {
let _: Foo = ();
}
13 changes: 13 additions & 0 deletions tests/ui/traits/new-solver/dyn-any-dont-prefer-impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// compile-flags: -Ztrait-solver=next
// check-pass

use std::any::Any;

fn needs_usize(_: &usize) {}

fn main() {
let x: &dyn Any = &1usize;
if let Some(x) = x.downcast_ref::<usize>() {
needs_usize(x);
}
}
22 changes: 22 additions & 0 deletions tests/ui/type-alias-impl-trait/issue-109054.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// edition:2021

#![feature(type_alias_impl_trait)]

struct CallMe;

type ReturnType<'a> = impl std::future::Future<Output = u32> + 'a;
type FnType = impl Fn(&u32) -> ReturnType;

impl std::ops::Deref for CallMe {
type Target = FnType;

fn deref(&self) -> &Self::Target {
fn inner(val: &u32) -> ReturnType {
async move { *val * 2 }
}

&inner //~ ERROR: expected generic lifetime parameter, found `'_`
}
}

fn main() {}
12 changes: 12 additions & 0 deletions tests/ui/type-alias-impl-trait/issue-109054.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0792]: expected generic lifetime parameter, found `'_`
--> $DIR/issue-109054.rs:18:9
|
LL | type ReturnType<'a> = impl std::future::Future<Output = u32> + 'a;
| -- this generic parameter must be used with a generic lifetime parameter
...
LL | &inner
| ^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0792`.
Loading