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 9 pull requests #109230

Closed
wants to merge 34 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ce6adcc
Prevent stable `libtest` from supporting `-Zunstable-options`
thomcc Mar 12, 2023
9afffc5
Remove box expressions from HIR
clubby789 Mar 14, 2023
fb916a0
Fix riscv64 fuchsia LLVM target name
taiki-e Mar 15, 2023
86a5e36
Fix linker detection for clang with prefix
taiki-e Mar 15, 2023
26c4c1e
Rename impl_trait_in_trait_parent to impl_trait_in_trait_parent_fn
spastorino Mar 10, 2023
39ffe96
Properly implement generics_of for traits
spastorino Mar 14, 2023
39d19ca
Make impl_trait_in_trait_container consider newly generated RPITITs
spastorino Mar 13, 2023
d9ac2be
Handle proc-macro spans pointing at attribute in suggestions
estebank Mar 10, 2023
00a2616
Fix range_minus_one and range_plus_one clippy lints
estebank Mar 14, 2023
f219ab5
Tweak E0412 label for proc-macros
estebank Mar 14, 2023
d692d37
Do not suggest binding from outside of a macro in macro
estebank Mar 14, 2023
b54ba21
Avoid incorrect argument suggestions in macros
estebank Mar 15, 2023
8a47602
Tweak `alloc_error_handler` desugaring
estebank Mar 15, 2023
d7c0bcd
Rename and document span marking method
estebank Mar 15, 2023
0172d15
Fix #90557
estebank Mar 15, 2023
019556d
Small cleanup
estebank Mar 15, 2023
0b9b7dd
inherit_overflow: adapt pattern to also work with v0 mangling
durin42 Mar 15, 2023
e41491f
ImplTraitPlaceholder -> is_impl_trait_in_trait
spastorino Mar 14, 2023
11f1810
Feed is_type_alias_impl_trait for RPITITs on the trait side
spastorino Mar 13, 2023
c5c4340
Add revisions to fixed tests in -Zlower-impl-trait-in-trait-to-assoc-ty
spastorino Mar 14, 2023
738ea1b
Change text -> rust highlighting in sanitizer.md
tgross35 Mar 10, 2023
0949da8
Install projection from RPITIT to default trait method opaque correctly
compiler-errors Mar 15, 2023
ff7c3b8
Don't install default opaque projection predicates in RPITIT associat…
compiler-errors Mar 16, 2023
8d922eb
Fix on_unimplemented_note for RPITITs
compiler-errors Mar 16, 2023
a8839c3
Use sort_by_key instead of sort_by
est31 Mar 16, 2023
11a80a0
Rollup merge of #108958 - clubby789:unbox-the-hir, r=compiler-errors
matthiaskrgr Mar 16, 2023
e505cdc
Rollup merge of #108997 - tgross35:patch-1, r=JohnTitor
matthiaskrgr Mar 16, 2023
3182334
Rollup merge of #109044 - thomcc:disallow-unstable-libtest, r=jyn514
matthiaskrgr Mar 16, 2023
1d17b6a
Rollup merge of #109082 - estebank:macro-spans, r=oli-obk
matthiaskrgr Mar 16, 2023
0148cc4
Rollup merge of #109155 - taiki-e:riscv64-fuchsia-fix-llvm-target, r=…
matthiaskrgr Mar 16, 2023
4612076
Rollup merge of #109156 - taiki-e:linker-detection, r=petrochenkov
matthiaskrgr Mar 16, 2023
4f4a3f0
Rollup merge of #109181 - durin42:v0-mangle-inherit_overflow, r=Nilst…
matthiaskrgr Mar 16, 2023
e9f4cae
Rollup merge of #109198 - compiler-errors:new-rpitit-default-body, r=…
matthiaskrgr Mar 16, 2023
686e832
Rollup merge of #109215 - est31:sort_by_key, r=Nilstrieb
matthiaskrgr Mar 16, 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
Prev Previous commit
Next Next commit
Install projection from RPITIT to default trait method opaque correctly
  • Loading branch information
compiler-errors committed Mar 16, 2023
commit 0949da8f4e309ac5e5035250bd662dfdbd5c32b4
36 changes: 22 additions & 14 deletions compiler/rustc_hir_analysis/src/collect/item_bounds.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ use crate::astconv::AstConv;
use rustc_hir as hir;
use rustc_infer::traits::util;
use rustc_middle::ty::subst::InternalSubsts;
use rustc_middle::ty::{self, ImplTraitInTraitData, Ty, TyCtxt};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::def_id::DefId;
use rustc_span::Span;

@@ -76,18 +76,26 @@ pub(super) fn explicit_item_bounds(
tcx: TyCtxt<'_>,
def_id: DefId,
) -> &'_ [(ty::Predicate<'_>, Span)] {
// If the def_id is about an RPITIT, delegate explicit_item_bounds to the opaque_def_id that
// generated the synthesized associate type.
let rpitit_info = if let Some(ImplTraitInTraitData::Trait { opaque_def_id, .. }) =
tcx.opt_rpitit_info(def_id)
{
Some(opaque_def_id)
} else {
None
};
match tcx.opt_rpitit_info(def_id) {
// RPITIT's bounds are the same as opaque type bounds, but with
// a projection self type.
Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {
let item = tcx.hir().get_by_def_id(opaque_def_id.expect_local()).expect_item();
let opaque_ty = item.expect_opaque_ty();
return opaque_type_bounds(
tcx,
opaque_def_id,
opaque_ty.bounds,
tcx.mk_projection(def_id, ty::InternalSubsts::identity_for_item(tcx, def_id)),
item.span,
);
}
// These should have been fed!
Some(ty::ImplTraitInTraitData::Impl { .. }) => unreachable!(),
None => {}
}

let bounds_def_id = rpitit_info.unwrap_or(def_id);
let hir_id = tcx.hir().local_def_id_to_hir_id(bounds_def_id.expect_local());
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
match tcx.hir().get(hir_id) {
hir::Node::TraitItem(hir::TraitItem {
kind: hir::TraitItemKind::Type(bounds, _),
@@ -100,12 +108,12 @@ pub(super) fn explicit_item_bounds(
..
}) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id);
let item_ty = if *in_trait || rpitit_info.is_some() {
let item_ty = if *in_trait && !tcx.lower_impl_trait_in_trait_to_assoc_ty() {
tcx.mk_projection(def_id, substs)
} else {
tcx.mk_opaque(def_id, substs)
};
opaque_type_bounds(tcx, bounds_def_id, bounds, item_ty, *span)
opaque_type_bounds(tcx, def_id, bounds, item_ty, *span)
}
_ => bug!("item_bounds called on {:?}", def_id),
}
17 changes: 14 additions & 3 deletions compiler/rustc_ty_utils/src/ty.rs
Original file line number Diff line number Diff line change
@@ -268,8 +268,6 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> {

fn visit_ty(&mut self, ty: Ty<'tcx>) -> std::ops::ControlFlow<Self::BreakTy> {
if let ty::Alias(ty::Projection, alias_ty) = *ty.kind()
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty) need to project to the opaque, could
// get it via type_of + subst.
&& self.tcx.is_impl_trait_in_trait(alias_ty.def_id)
&& self.tcx.impl_trait_in_trait_parent_fn(alias_ty.def_id) == self.fn_def_id
&& self.seen.insert(alias_ty.def_id)
@@ -284,11 +282,24 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> {
re
}
});

// If we're lowering to associated item, install the opaque type which is just
// the `type_of` of the trait's associated item. If we're using the old lowering
// strategy, then just reinterpret the associated type like an opaque :^)
let default_ty = if self.tcx.lower_impl_trait_in_trait_to_assoc_ty() {
self
.tcx
.type_of(alias_ty.def_id)
.subst(self.tcx, alias_ty.substs)
} else {
self.tcx.mk_alias(ty::Opaque, alias_ty)
};

self.predicates.push(
ty::Binder::bind_with_vars(
ty::ProjectionPredicate {
projection_ty: alias_ty,
term: self.tcx.mk_alias(ty::Opaque, alias_ty).into(),
term: default_ty.into(),
},
self.bound_vars,
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: the feature `async_fn_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/async-default-fn-overridden.rs:4:12
--> $DIR/async-default-fn-overridden.rs:6:12
|
LL | #![feature(async_fn_in_trait)]
| ^^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: the feature `async_fn_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/async-default-fn-overridden.rs:6:12
|
LL | #![feature(async_fn_in_trait)]
| ^^^^^^^^^^^^^^^^^
|
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
= note: `#[warn(incomplete_features)]` on by default

warning: 1 warning emitted

2 changes: 2 additions & 0 deletions tests/ui/async-await/in-trait/async-default-fn-overridden.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// run-pass
// edition:2021
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
// revisions: current next

#![feature(async_fn_in_trait)]
//~^ WARN the feature `async_fn_in_trait` is incomplete and may not be safe to use
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: the feature `return_position_impl_trait_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/default-method-constraint.rs:5:12
--> $DIR/default-method-constraint.rs:7:12
|
LL | #![feature(return_position_impl_trait_in_trait)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11 changes: 11 additions & 0 deletions tests/ui/impl-trait/in-trait/default-method-constraint.next.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: the feature `return_position_impl_trait_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/default-method-constraint.rs:7:12
|
LL | #![feature(return_position_impl_trait_in_trait)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
= note: `#[warn(incomplete_features)]` on by default

warning: 1 warning emitted

2 changes: 2 additions & 0 deletions tests/ui/impl-trait/in-trait/default-method-constraint.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// check-pass
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
// revisions: current next

// This didn't work in the previous default RPITIT method hack attempt