Skip to content

Commit 7008911

Browse files
committed
FIx ICE on wf check for foreign fns
1 parent 507bff9 commit 7008911

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ fn msg_span_from_early_bound_and_free_regions(
153153
Some(Node::Item(it)) => item_scope_tag(&it),
154154
Some(Node::TraitItem(it)) => trait_item_scope_tag(&it),
155155
Some(Node::ImplItem(it)) => impl_item_scope_tag(&it),
156+
Some(Node::ForeignItem(it)) => foreign_item_scope_tag(&it),
156157
_ => unreachable!(),
157158
};
158159
let (prefix, span) = match *region {
@@ -233,6 +234,13 @@ fn impl_item_scope_tag(item: &hir::ImplItem<'_>) -> &'static str {
233234
}
234235
}
235236

237+
fn foreign_item_scope_tag(item: &hir::ForeignItem<'_>) -> &'static str {
238+
match item.kind {
239+
hir::ForeignItemKind::Fn(..) => "method body",
240+
hir::ForeignItemKind::Static(..) | hir::ForeignItemKind::Type => "associated item",
241+
}
242+
}
243+
236244
fn explain_span(tcx: TyCtxt<'tcx>, heading: &str, span: Span) -> (String, Option<Span>) {
237245
let lo = tcx.sess.source_map().lookup_char_pos(span.lo());
238246
(format!("the {} at {}:{}", heading, lo.line, lo.col.to_usize() + 1), Some(span))

compiler/rustc_typeck/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'tcx> CheckWfFcxBuilder<'tcx> {
5151
let fcx = FnCtxt::new(&inh, param_env, id);
5252
if !inh.tcx.features().trivial_bounds {
5353
// As predicates are cached rather than obligations, this
54-
// needsto be called first so that they are checked with an
54+
// needs to be called first so that they are checked with an
5555
// empty `param_env`.
5656
check_false_global_bounds(&fcx, span, id);
5757
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Regression test for #80468.
2+
3+
#![crate_type = "lib"]
4+
5+
pub trait Trait {}
6+
7+
#[repr(transparent)]
8+
pub struct Wrapper<T: Trait>(T);
9+
10+
#[repr(transparent)]
11+
pub struct Ref<'a>(&'a u8);
12+
13+
impl Trait for Ref {} //~ ERROR: implicit elided lifetime not allowed here
14+
15+
extern "C" {
16+
pub fn repro(_: Wrapper<Ref>); //~ ERROR: mismatched types
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0726]: implicit elided lifetime not allowed here
2+
--> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:13:16
3+
|
4+
LL | impl Trait for Ref {}
5+
| ^^^- help: indicate the anonymous lifetime: `<'_>`
6+
7+
error[E0308]: mismatched types
8+
--> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:16:21
9+
|
10+
LL | pub fn repro(_: Wrapper<Ref>);
11+
| ^^^^^^^^^^^^ lifetime mismatch
12+
|
13+
= note: expected trait `Trait`
14+
found trait `Trait`
15+
note: the anonymous lifetime #1 defined on the method body at 16:5...
16+
--> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:16:5
17+
|
18+
LL | pub fn repro(_: Wrapper<Ref>);
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
= note: ...does not necessarily outlive the static lifetime
21+
22+
error: aborting due to 2 previous errors
23+
24+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)