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

FIx ICE on wf check for foreign fns #80548

Merged
merged 1 commit into from
Jan 1, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ fn msg_span_from_early_bound_and_free_regions(
Some(Node::Item(it)) => item_scope_tag(&it),
Some(Node::TraitItem(it)) => trait_item_scope_tag(&it),
Some(Node::ImplItem(it)) => impl_item_scope_tag(&it),
Some(Node::ForeignItem(it)) => foreign_item_scope_tag(&it),
_ => unreachable!(),
};
let (prefix, span) = match *region {
Expand Down Expand Up @@ -233,6 +234,13 @@ fn impl_item_scope_tag(item: &hir::ImplItem<'_>) -> &'static str {
}
}

fn foreign_item_scope_tag(item: &hir::ForeignItem<'_>) -> &'static str {
match item.kind {
hir::ForeignItemKind::Fn(..) => "method body",
hir::ForeignItemKind::Static(..) | hir::ForeignItemKind::Type => "associated item",
}
}

fn explain_span(tcx: TyCtxt<'tcx>, heading: &str, span: Span) -> (String, Option<Span>) {
let lo = tcx.sess.source_map().lookup_char_pos(span.lo());
(format!("the {} at {}:{}", heading, lo.line, lo.col.to_usize() + 1), Some(span))
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<'tcx> CheckWfFcxBuilder<'tcx> {
let fcx = FnCtxt::new(&inh, param_env, id);
if !inh.tcx.features().trivial_bounds {
// As predicates are cached rather than obligations, this
// needsto be called first so that they are checked with an
// needs to be called first so that they are checked with an
// empty `param_env`.
check_false_global_bounds(&fcx, span, id);
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Regression test for #80468.

#![crate_type = "lib"]

pub trait Trait {}

#[repr(transparent)]
pub struct Wrapper<T: Trait>(T);

#[repr(transparent)]
pub struct Ref<'a>(&'a u8);

impl Trait for Ref {} //~ ERROR: implicit elided lifetime not allowed here

extern "C" {
pub fn repro(_: Wrapper<Ref>); //~ ERROR: mismatched types
}
24 changes: 24 additions & 0 deletions src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
error[E0726]: implicit elided lifetime not allowed here
--> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:13:16
|
LL | impl Trait for Ref {}
| ^^^- help: indicate the anonymous lifetime: `<'_>`

error[E0308]: mismatched types
--> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:16:21
|
LL | pub fn repro(_: Wrapper<Ref>);
| ^^^^^^^^^^^^ lifetime mismatch
|
= note: expected trait `Trait`
found trait `Trait`
note: the anonymous lifetime #1 defined on the method body at 16:5...
--> $DIR/wf-in-foreign-fn-decls-issue-80468.rs:16:5
|
LL | pub fn repro(_: Wrapper<Ref>);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: ...does not necessarily outlive the static lifetime

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.