diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2015-10-27 18:29:42 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2015-10-28 15:38:09 -0400 |
| commit | 19996d4cdf754ecb59ba3718d631c1ece307d5a3 (patch) | |
| tree | 3d4bb763ec67edb4e9f0eae69c066cddc524ede4 | |
| parent | d0a84e05009047bb1801360510b2eae2c4a0aa90 (diff) | |
| download | rust-19996d4cdf754ecb59ba3718d631c1ece307d5a3.tar.gz rust-19996d4cdf754ecb59ba3718d631c1ece307d5a3.zip | |
The `source_did` may not be local, so don't unwrap the
`as_local_node_id`, instead just compare against `Some(id)`. Fixes #29161.
| -rw-r--r-- | src/librustc_privacy/lib.rs | 4 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-29161.rs | 26 |
2 files changed, 28 insertions, 2 deletions
diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index bae963c7701..dd990abaa9a 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -671,8 +671,8 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { // ancestry. (Both the item being checked and its parent must // be local.) let def_id = source_did.unwrap_or(to_check); - let node_id = self.tcx.map.as_local_node_id(def_id).unwrap(); - let (err_span, err_msg) = if id == node_id { + let node_id = self.tcx.map.as_local_node_id(def_id); + let (err_span, err_msg) = if Some(id) == node_id { return Some((span, format!("{} is private", msg), None)); } else { (span, format!("{} is inaccessible", msg)) diff --git a/src/test/compile-fail/issue-29161.rs b/src/test/compile-fail/issue-29161.rs new file mode 100644 index 00000000000..1821f5717cf --- /dev/null +++ b/src/test/compile-fail/issue-29161.rs @@ -0,0 +1,26 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +mod a { + struct A; + + impl Default for A { + pub fn default() -> A { + //~^ ERROR E0449 + A; + } + } +} + + +fn main() { + a::A::default(); + //~^ ERROR method `default` is inaccessible + } |
