Skip to content

Commit 82faf5e

Browse files
committed
Auto merge of rust-lang#111895 - matthiaskrgr:rollup-9a6szng, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#111861 (Don't ICE on return-type notation when promoting trait preds to associated type bounds) - rust-lang#111864 (Always require closure parameters to be `Sized`) - rust-lang#111870 (Rename `traits_in_crate` query to `traits`) - rust-lang#111880 (Don't ICE when computing PointerLike trait when region vars are in param-env) - rust-lang#111887 (Add regression tests for pretty-printing inherent projections) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9d826e0 + d49d347 commit 82faf5e

File tree

21 files changed

+182
-25
lines changed

21 files changed

+182
-25
lines changed

Diff for: compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+2
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ pub(super) fn explicit_predicates_of<'tcx>(
427427
// supertrait).
428428
if let ty::Alias(ty::Projection, projection) = ty.kind() {
429429
projection.substs == trait_identity_substs
430+
// FIXME(return_type_notation): This check should be more robust
431+
&& !tcx.is_impl_trait_in_trait(projection.def_id)
430432
&& tcx.associated_item(projection.def_id).container_id(tcx)
431433
== def_id.to_def_id()
432434
} else {

Diff for: compiler/rustc_hir_typeck/src/check.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub(super) fn check_fn<'a, 'tcx>(
3232
fn_def_id: LocalDefId,
3333
body: &'tcx hir::Body<'tcx>,
3434
can_be_generator: Option<hir::Movability>,
35+
params_can_be_unsized: bool,
3536
) -> Option<GeneratorTypes<'tcx>> {
3637
let fn_id = fcx.tcx.hir().local_def_id_to_hir_id(fn_def_id);
3738

@@ -94,7 +95,7 @@ pub(super) fn check_fn<'a, 'tcx>(
9495
// The check for a non-trivial pattern is a hack to avoid duplicate warnings
9596
// for simple cases like `fn foo(x: Trait)`,
9697
// where we would error once on the parameter as a whole, and once on the binding `x`.
97-
if param.pat.simple_ident().is_none() && !tcx.features().unsized_fn_params {
98+
if param.pat.simple_ident().is_none() && !params_can_be_unsized {
9899
fcx.require_type_is_sized(param_ty, param.pat.span, traits::SizedArgumentType(ty_span));
99100
}
100101

Diff for: compiler/rustc_hir_typeck/src/closure.rs

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8989
expr_def_id,
9090
body,
9191
closure.movability,
92+
// Closure "rust-call" ABI doesn't support unsized params
93+
false,
9294
);
9395

9496
let parent_substs = InternalSubsts::identity_for_item(

Diff for: compiler/rustc_hir_typeck/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ fn typeck_with_fallback<'tcx>(
212212
let fn_sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), fn_sig);
213213
let fn_sig = fcx.normalize(body.value.span, fn_sig);
214214

215-
check_fn(&mut fcx, fn_sig, decl, def_id, body, None);
215+
check_fn(&mut fcx, fn_sig, decl, def_id, body, None, tcx.features().unsized_fn_params);
216216
} else {
217217
let expected_type = if let Some(&hir::Ty { kind: hir::TyKind::Infer, span, .. }) = body_ty {
218218
Some(fcx.next_ty_var(TypeVariableOrigin {

Diff for: compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ provide! { tcx, def_id, other, cdata,
323323

324324
extra_filename => { cdata.root.extra_filename.clone() }
325325

326-
traits_in_crate => { tcx.arena.alloc_from_iter(cdata.get_traits()) }
326+
traits => { tcx.arena.alloc_from_iter(cdata.get_traits()) }
327327
trait_impls_in_crate => { tcx.arena.alloc_from_iter(cdata.get_trait_impls()) }
328328
implementations_of_trait => { cdata.get_implementations_of_trait(tcx, other) }
329329
crate_incoherent_impls => { cdata.get_incoherent_impls(tcx, other) }

Diff for: compiler/rustc_metadata/src/rmeta/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
19381938

19391939
fn encode_traits(&mut self) -> LazyArray<DefIndex> {
19401940
empty_proc_macro!(self);
1941-
self.lazy_array(self.tcx.traits_in_crate(LOCAL_CRATE).iter().map(|def_id| def_id.index))
1941+
self.lazy_array(self.tcx.traits(LOCAL_CRATE).iter().map(|def_id| def_id.index))
19421942
}
19431943

19441944
/// Encodes an index, mapping each trait to its (local) implementations.
@@ -2329,7 +2329,7 @@ pub fn provide(providers: &mut Providers) {
23292329
.get(&def_id)
23302330
.expect("no traits in scope for a doc link")
23312331
},
2332-
traits_in_crate: |tcx, LocalCrate| {
2332+
traits: |tcx, LocalCrate| {
23332333
let mut traits = Vec::new();
23342334
for id in tcx.hir().items() {
23352335
if matches!(tcx.def_kind(id.owner_id), DefKind::Trait | DefKind::TraitAlias) {

Diff for: compiler/rustc_middle/src/query/mod.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ use crate::traits::query::{
3838
OutlivesBound,
3939
};
4040
use crate::traits::specialization_graph;
41-
use crate::traits::{self, ImplSource};
41+
use crate::traits::{
42+
CanonicalChalkEnvironmentAndGoal, CodegenObligationError, EvaluationResult, ImplSource,
43+
ObjectSafetyViolation, ObligationCause, OverflowError, WellFormedLoc,
44+
};
4245
use crate::ty::fast_reject::SimplifiedType;
4346
use crate::ty::layout::ValidityRequirement;
4447
use crate::ty::subst::{GenericArg, SubstsRef};
@@ -1273,7 +1276,7 @@ rustc_queries! {
12731276

12741277
query codegen_select_candidate(
12751278
key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)
1276-
) -> Result<&'tcx ImplSource<'tcx, ()>, traits::CodegenObligationError> {
1279+
) -> Result<&'tcx ImplSource<'tcx, ()>, CodegenObligationError> {
12771280
cache_on_disk_if { true }
12781281
desc { |tcx| "computing candidate for `{}`", key.1 }
12791282
}
@@ -1294,7 +1297,7 @@ rustc_queries! {
12941297
desc { |tcx| "building specialization graph of trait `{}`", tcx.def_path_str(trait_id) }
12951298
cache_on_disk_if { true }
12961299
}
1297-
query object_safety_violations(trait_id: DefId) -> &'tcx [traits::ObjectSafetyViolation] {
1300+
query object_safety_violations(trait_id: DefId) -> &'tcx [ObjectSafetyViolation] {
12981301
desc { |tcx| "determining object safety of trait `{}`", tcx.def_path_str(trait_id) }
12991302
}
13001303
query check_is_object_safe(trait_id: DefId) -> bool {
@@ -1838,8 +1841,7 @@ rustc_queries! {
18381841
}
18391842

18401843
/// A list of all traits in a crate, used by rustdoc and error reporting.
1841-
/// NOTE: Not named just `traits` due to a naming conflict.
1842-
query traits_in_crate(_: CrateNum) -> &'tcx [DefId] {
1844+
query traits(_: CrateNum) -> &'tcx [DefId] {
18431845
desc { "fetching all traits in a crate" }
18441846
separate_provide_extern
18451847
}
@@ -1953,12 +1955,12 @@ rustc_queries! {
19531955
/// `infcx.predicate_must_hold()` instead.
19541956
query evaluate_obligation(
19551957
goal: CanonicalPredicateGoal<'tcx>
1956-
) -> Result<traits::EvaluationResult, traits::OverflowError> {
1958+
) -> Result<EvaluationResult, OverflowError> {
19571959
desc { "evaluating trait selection obligation `{}`", goal.value.value }
19581960
}
19591961

19601962
query evaluate_goal(
1961-
goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
1963+
goal: CanonicalChalkEnvironmentAndGoal<'tcx>
19621964
) -> Result<
19631965
&'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
19641966
NoSolution
@@ -2128,8 +2130,8 @@ rustc_queries! {
21282130
/// all of the cases that the normal `ty::Ty`-based wfcheck does. This is fine,
21292131
/// because the `ty::Ty`-based wfcheck is always run.
21302132
query diagnostic_hir_wf_check(
2131-
key: (ty::Predicate<'tcx>, traits::WellFormedLoc)
2132-
) -> &'tcx Option<traits::ObligationCause<'tcx>> {
2133+
key: (ty::Predicate<'tcx>, WellFormedLoc)
2134+
) -> &'tcx Option<ObligationCause<'tcx>> {
21332135
arena_cache
21342136
eval_always
21352137
no_hash

Diff for: compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ impl<'tcx> TyCtxt<'tcx> {
11991199
pub fn all_traits(self) -> impl Iterator<Item = DefId> + 'tcx {
12001200
iter::once(LOCAL_CRATE)
12011201
.chain(self.crates(()).iter().copied())
1202-
.flat_map(move |cnum| self.traits_in_crate(cnum).iter().copied())
1202+
.flat_map(move |cnum| self.traits(cnum).iter().copied())
12031203
}
12041204

12051205
#[inline]

Diff for: compiler/rustc_trait_selection/src/solve/trait_goals.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,18 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
177177
return Err(NoSolution);
178178
}
179179

180-
if goal.predicate.self_ty().has_non_region_infer() {
180+
// The regions of a type don't affect the size of the type
181+
let tcx = ecx.tcx();
182+
// We should erase regions from both the param-env and type, since both
183+
// may have infer regions. Specifically, after canonicalizing and instantiating,
184+
// early bound regions turn into region vars in both the new and old solver.
185+
let key = tcx.erase_regions(goal.param_env.and(goal.predicate.self_ty()));
186+
// But if there are inference variables, we have to wait until it's resolved.
187+
if key.has_non_region_infer() {
181188
return ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS);
182189
}
183190

184-
let tcx = ecx.tcx();
185-
let self_ty = tcx.erase_regions(goal.predicate.self_ty());
186-
187-
if let Ok(layout) = tcx.layout_of(goal.param_env.and(self_ty))
191+
if let Ok(layout) = tcx.layout_of(key)
188192
&& layout.layout.is_pointer_like(&tcx.data_layout)
189193
{
190194
// FIXME: We could make this faster by making a no-constraints response

Diff for: compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -967,16 +967,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
967967
) {
968968
// The regions of a type don't affect the size of the type
969969
let tcx = self.tcx();
970-
let self_ty =
971-
tcx.erase_regions(tcx.erase_late_bound_regions(obligation.predicate.self_ty()));
972-
970+
let self_ty = tcx.erase_late_bound_regions(obligation.predicate.self_ty());
971+
// We should erase regions from both the param-env and type, since both
972+
// may have infer regions. Specifically, after canonicalizing and instantiating,
973+
// early bound regions turn into region vars in both the new and old solver.
974+
let key = tcx.erase_regions(obligation.param_env.and(self_ty));
973975
// But if there are inference variables, we have to wait until it's resolved.
974-
if self_ty.has_non_region_infer() {
976+
if key.has_non_region_infer() {
975977
candidates.ambiguous = true;
976978
return;
977979
}
978980

979-
if let Ok(layout) = tcx.layout_of(obligation.param_env.and(self_ty))
981+
if let Ok(layout) = tcx.layout_of(key)
980982
&& layout.layout.is_pointer_like(&tcx.data_layout)
981983
{
982984
candidates.vec.push(BuiltinCandidate { has_nested: false });

Diff for: tests/ui/associated-inherent-types/issue-111879-0.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![feature(inherent_associated_types)]
2+
#![allow(incomplete_features)]
3+
4+
// Check that we don't crash when printing inherent projections in diagnostics.
5+
6+
pub struct Carrier<'a>(&'a ());
7+
8+
pub type User = for<'b> fn(Carrier<'b>::Focus<i32>);
9+
10+
impl<'a> Carrier<'a> {
11+
pub type Focus<T> = &'a mut User; //~ ERROR overflow evaluating associated type
12+
}
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: overflow evaluating associated type `Carrier<'b>::Focus<i32>`
2+
--> $DIR/issue-111879-0.rs:11:25
3+
|
4+
LL | pub type Focus<T> = &'a mut User;
5+
| ^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+

Diff for: tests/ui/associated-inherent-types/issue-111879-1.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(inherent_associated_types)]
2+
#![allow(incomplete_features)]
3+
4+
// Check that we don't crash when printing inherent projections in diagnostics.
5+
6+
struct Foo<T>(T);
7+
8+
impl<'a> Foo<fn(&'a ())> {
9+
type Assoc = &'a ();
10+
}
11+
12+
fn main(_: for<'a> fn(Foo<fn(&'a ())>::Assoc)) {} //~ ERROR `main` function has wrong type
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0580]: `main` function has wrong type
2+
--> $DIR/issue-111879-1.rs:12:1
3+
|
4+
LL | fn main(_: for<'a> fn(Foo<fn(&'a ())>::Assoc)) {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect number of function parameters
6+
|
7+
= note: expected fn pointer `fn()`
8+
found fn pointer `fn(for<'a> fn(Foo<fn(&'a ())>::Assoc))`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0580`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// check-pass
2+
3+
#![feature(return_position_impl_trait_in_trait, return_type_notation)]
4+
//~^ WARN the feature `return_type_notation` is incomplete and may not be safe to use
5+
6+
trait IntFactory {
7+
fn stream(&self) -> impl Iterator<Item = i32>;
8+
}
9+
trait SendIntFactory: IntFactory<stream(): Send> + Send {}
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `return_type_notation` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/supertrait-bound.rs:3:49
3+
|
4+
LL | #![feature(return_position_impl_trait_in_trait, 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+
warning: 1 warning emitted
11+

Diff for: tests/ui/dyn-star/param-env-infer.current.stderr

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/param-env-infer.rs:5:12
3+
|
4+
LL | #![feature(dyn_star, pointer_like_trait)]
5+
| ^^^^^^^^
6+
|
7+
= note: see issue #102425 <https://github.com/rust-lang/rust/issues/102425> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error[E0282]: type annotations needed
11+
--> $DIR/param-env-infer.rs:12:10
12+
|
13+
LL | t as _
14+
| ^ cannot infer type
15+
16+
error: aborting due to previous error; 1 warning emitted
17+
18+
For more information about this error, try `rustc --explain E0282`.

Diff for: tests/ui/dyn-star/param-env-infer.next.stderr

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/param-env-infer.rs:5:12
3+
|
4+
LL | #![feature(dyn_star, pointer_like_trait)]
5+
| ^^^^^^^^
6+
|
7+
= note: see issue #102425 <https://github.com/rust-lang/rust/issues/102425> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error[E0282]: type annotations needed
11+
--> $DIR/param-env-infer.rs:12:10
12+
|
13+
LL | t as _
14+
| ^ cannot infer type
15+
16+
error: aborting due to previous error; 1 warning emitted
17+
18+
For more information about this error, try `rustc --explain E0282`.

Diff for: tests/ui/dyn-star/param-env-infer.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// revisions: current next
2+
//[next] compile-flags: -Ztrait-solver=next
3+
// incremental
4+
5+
#![feature(dyn_star, pointer_like_trait)]
6+
//~^ WARN the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
7+
8+
use std::fmt::Debug;
9+
use std::marker::PointerLike;
10+
11+
fn make_dyn_star<'a, T: PointerLike + Debug + 'a>(t: T) -> impl PointerLike + Debug + 'a {
12+
t as _
13+
//~^ ERROR type annotations needed
14+
}
15+
16+
fn main() {}

Diff for: tests/ui/unsized-locals/issue-67981.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(unsized_fn_params)]
2+
3+
fn main() {
4+
let f: fn([u8]) = |_| {};
5+
//~^ERROR the size for values of type `[u8]` cannot be known at compilation time
6+
let slice: Box<[u8]> = Box::new([1; 8]);
7+
8+
f(*slice);
9+
}

Diff for: tests/ui/unsized-locals/issue-67981.stderr

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
2+
--> $DIR/issue-67981.rs:4:24
3+
|
4+
LL | let f: fn([u8]) = |_| {};
5+
| ^ doesn't have a size known at compile-time
6+
|
7+
= help: the trait `Sized` is not implemented for `[u8]`
8+
help: function arguments must have a statically known size, borrowed types always have a known size
9+
|
10+
LL | let f: fn([u8]) = |&_| {};
11+
| +
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)