Skip to content

Commit

Permalink
Rollup merge of #69539 - Centril:fix-69401, r=petrochenkov
Browse files Browse the repository at this point in the history
late resolve, visit_fn: bail early if there's no body.

Fixes #69401 which was injected by b2c6eeb in #68788.

r? @petrochenkov
  • Loading branch information
Centril authored Feb 28, 2020
2 parents e4cedc9 + 85b585d commit b95945c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/librustc_resolve/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,9 @@ impl<'a, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
}
fn visit_fn(&mut self, fn_kind: FnKind<'ast>, sp: Span, _: NodeId) {
let rib_kind = match fn_kind {
FnKind::Fn(FnCtxt::Foreign, ..) => return visit::walk_fn(self, fn_kind, sp),
FnKind::Fn(FnCtxt::Free, ..) => FnItemRibKind,
// Bail if there's no body.
FnKind::Fn(.., None) => return visit::walk_fn(self, fn_kind, sp),
FnKind::Fn(FnCtxt::Free, ..) | FnKind::Fn(FnCtxt::Foreign, ..) => FnItemRibKind,
FnKind::Fn(FnCtxt::Assoc(_), ..) | FnKind::Closure(..) => NormalRibKind,
};
let previous_value = replace(&mut self.diagnostic_metadata.current_function, Some(sp));
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {}

trait Foo {
fn fn_with_type_named_same_as_local_in_param(b: b);
//~^ ERROR cannot find type `b` in this scope
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0412]: cannot find type `b` in this scope
--> $DIR/issue-69401-trait-fn-no-body-ty-local.rs:4:53
|
LL | fn fn_with_type_named_same_as_local_in_param(b: b);
| ^ not found in this scope

error: aborting due to previous error

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

0 comments on commit b95945c

Please sign in to comment.