diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-28 17:17:34 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-28 17:17:34 +0100 |
| commit | b95945c8d642b0b6949e19a185d1dd916ee6ec31 (patch) | |
| tree | e91bc734ddbd1511c0e2a3e62b1fc32270c4fb8d | |
| parent | e4cedc9df29d87aa5382986ffa6a91fdfef9e64e (diff) | |
| parent | 85b585daaf735deda96c6e087e2a3f203c64d52d (diff) | |
| download | rust-b95945c8d642b0b6949e19a185d1dd916ee6ec31.tar.gz rust-b95945c8d642b0b6949e19a185d1dd916ee6ec31.zip | |
Rollup merge of #69539 - Centril:fix-69401, r=petrochenkov
late resolve, visit_fn: bail early if there's no body. Fixes https://github.com/rust-lang/rust/issues/69401 which was injected by https://github.com/rust-lang/rust/commit/b2c6eeb713d4cf9b35b7dda6ff2b0274e7f24684 in https://github.com/rust-lang/rust/pull/68788. r? @petrochenkov
| -rw-r--r-- | src/librustc_resolve/late.rs | 5 | ||||
| -rw-r--r-- | src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.rs | 6 | ||||
| -rw-r--r-- | src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.stderr | 9 |
3 files changed, 18 insertions, 2 deletions
diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index c924fef4dc9..48a2f829d19 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -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)); diff --git a/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.rs b/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.rs new file mode 100644 index 00000000000..4397baea4a9 --- /dev/null +++ b/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.rs @@ -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 +} diff --git a/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.stderr b/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.stderr new file mode 100644 index 00000000000..109409d2731 --- /dev/null +++ b/src/test/ui/resolve/issue-69401-trait-fn-no-body-ty-local.stderr @@ -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`. |
