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

Don't wf-check non-local RPITs #107038

Merged
merged 3 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2602,7 +2602,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
match path.res {
Res::Def(DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder, did) => {
// Check for desugared `impl Trait`.
assert!(ty::is_impl_trait_defn(tcx, did).is_none());
assert!(tcx.is_type_alias_impl_trait(did));
let item_segment = path.segments.split_last().unwrap();
self.prohibit_generics(item_segment.1.iter(), |err| {
err.note("`impl Trait` types can't have type parameters");
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub fn provide(providers: &mut Providers) {
is_foreign_item,
generator_kind,
collect_mod_item_types,
is_type_alias_impl_trait,
..*providers
};
}
Expand Down Expand Up @@ -1537,3 +1538,13 @@ fn generator_kind(tcx: TyCtxt<'_>, def_id: DefId) -> Option<hir::GeneratorKind>
_ => bug!("generator_kind applied to non-local def-id {:?}", def_id),
}
}

fn is_type_alias_impl_trait<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
match tcx.hir().get_if_local(def_id) {
Some(Node::Item(hir::Item { kind: hir::ItemKind::OpaqueTy(opaque), .. })) => {
matches!(opaque.origin, hir::OpaqueTyOrigin::TyAlias)
}
Some(_) => bug!("tried getting opaque_ty_origin for non-opaque: {:?}", def_id),
_ => bug!("tried getting opaque_ty_origin for non-local def-id {:?}", def_id),
}
}
1 change: 1 addition & 0 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ provide! { tcx, def_id, other, cdata,
generator_kind => { table }
trait_def => { table }
deduced_param_attrs => { table }
is_type_alias_impl_trait => { table }
collect_return_position_impl_trait_in_trait_tys => {
Ok(cdata
.root
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
}
hir::ItemKind::OpaqueTy(..) => {
self.encode_explicit_item_bounds(def_id);
record!(self.tables.is_type_alias_impl_trait[def_id] <- self.tcx.is_type_alias_impl_trait(def_id));
}
hir::ItemKind::Enum(..) => {
let adt_def = self.tcx.adt_def(def_id);
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ define_tables! {
proc_macro: Table<DefIndex, MacroKind>,
module_reexports: Table<DefIndex, LazyArray<ModChild>>,
deduced_param_attrs: Table<DefIndex, LazyArray<DeducedParamAttrs>>,
is_type_alias_impl_trait: Table<DefIndex, LazyValue<bool>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
is_type_alias_impl_trait: Table<DefIndex, LazyValue<bool>>,
is_type_alias_impl_trait: Table<DefIndex, ()>,

we usually don't encode false, and just use the lack of an entry for that


trait_impl_trait_tys: Table<DefIndex, LazyValue<FxHashMap<DefId, Ty<'static>>>>,
}
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ rustc_queries! {
separate_provide_extern
}

query is_type_alias_impl_trait(key: DefId) -> bool
{
desc { "determine whether the opaque is a type-alias impl trait" }
separate_provide_extern
}

query analysis(key: ()) -> Result<(), ErrorGuaranteed> {
eval_always
desc { "running analysis passes on this crate" }
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/ty/parameterized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ trivially_parameterized_over_tcx! {
usize,
(),
u32,
bool,
std::string::String,
crate::metadata::ModChild,
crate::middle::codegen_fn_attrs::CodegenFnAttrs,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ impl<'tcx> WfPredicates<'tcx> {
// All of the requirements on type parameters
// have already been checked for `impl Trait` in
// return position. We do need to check type-alias-impl-trait though.
if ty::is_impl_trait_defn(self.tcx, def_id).is_none() {
if self.tcx.is_type_alias_impl_trait(def_id) {
let obligations = self.nominal_obligations(def_id, substs);
self.out.extend(obligations);
}
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/async-await/auxiliary/issue-107036.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// edition:2021

pub trait T {}
impl T for () {}

pub struct S {}

impl S {
pub async fn f<'a>(&self) -> impl T + 'a {
()
}
}
14 changes: 14 additions & 0 deletions tests/ui/async-await/issue-107036.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// aux-build:issue-107036.rs
// edition:2021
// check-pass

extern crate issue_107036;
use issue_107036::S;

async fn f() {
S{}.f().await;
}

fn main() {
let _ = f();
}