Skip to content

Commit 2dcaadb

Browse files
Rollup merge of rust-lang#119420 - cjgillot:issue-119295, r=compiler-errors
Handle ForeignItem as TAIT scope. Fixes rust-lang#119295
2 parents 3a19a92 + 7fd2d8d commit 2dcaadb

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs

+7
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub(super) fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: Local
6969
Node::Item(it) => locator.visit_item(it),
7070
Node::ImplItem(it) => locator.visit_impl_item(it),
7171
Node::TraitItem(it) => locator.visit_trait_item(it),
72+
Node::ForeignItem(it) => locator.visit_foreign_item(it),
7273
other => bug!("{:?} is not a valid scope for an opaque type item", other),
7374
}
7475
}
@@ -240,6 +241,12 @@ impl<'tcx> intravisit::Visitor<'tcx> for TaitConstraintLocator<'tcx> {
240241
self.check(it.owner_id.def_id);
241242
intravisit::walk_trait_item(self, it);
242243
}
244+
fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) {
245+
trace!(?it.owner_id);
246+
assert_ne!(it.owner_id.def_id, self.def_id);
247+
// No need to call `check`, as we do not run borrowck on foreign items.
248+
intravisit::walk_foreign_item(self, it);
249+
}
243250
}
244251

245252
pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Regression test for issue #119295.
2+
3+
#![feature(type_alias_impl_trait)]
4+
5+
type Bar<T> = T;
6+
type S<const A: usize> = [i32; A];
7+
8+
extern "C" {
9+
pub fn lint_me(
10+
x: Bar<
11+
S<
12+
{ //~ ERROR mismatched types
13+
type B<Z> = impl Sized;
14+
//~^ ERROR unconstrained opaque type
15+
},
16+
>,
17+
>,
18+
);
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/nested-in-anon-const.rs:12:17
3+
|
4+
LL | / {
5+
LL | | type B<Z> = impl Sized;
6+
LL | |
7+
LL | | },
8+
| |_________________^ expected `usize`, found `()`
9+
10+
error: unconstrained opaque type
11+
--> $DIR/nested-in-anon-const.rs:13:33
12+
|
13+
LL | type B<Z> = impl Sized;
14+
| ^^^^^^^^^^
15+
|
16+
= note: `B` must be used in combination with a concrete type within the same item
17+
18+
error: aborting due to 2 previous errors
19+
20+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)