diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2015-02-22 01:52:22 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2015-02-22 01:52:22 +0530 |
| commit | 494dbe9c07839a8eeb2b035f86011df52f625a2d (patch) | |
| tree | 825a0542758469c54cf3ec349ea400cd2472bfff /src | |
| parent | a95d7f53a7f80085c972adb996c6e10f705db4ef (diff) | |
| parent | 9b67d07acc7573276a15dfcd9e4418bc3d838074 (diff) | |
| download | rust-494dbe9c07839a8eeb2b035f86011df52f625a2d.tar.gz rust-494dbe9c07839a8eeb2b035f86011df52f625a2d.zip | |
Rollup merge of #22516 - leejunseok:nonpub_field_sugg, r=jakub-
closes #22421
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_typeck/check/mod.rs | 6 | ||||
| -rw-r--r-- | src/test/compile-fail/suggest-private-fields.rs | 36 |
2 files changed, 41 insertions, 1 deletions
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index cab91b93133..0430954ad7e 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -117,7 +117,7 @@ use std::iter::repeat; use std::slice; use syntax::{self, abi, attr}; use syntax::attr::AttrMetaMethods; -use syntax::ast::{self, ProvidedMethod, RequiredMethod, TypeTraitItem, DefId}; +use syntax::ast::{self, ProvidedMethod, RequiredMethod, TypeTraitItem, DefId, Visibility}; use syntax::ast_util::{self, local_def, PostExpansionMethod}; use syntax::codemap::{self, Span}; use syntax::owned_slice::OwnedSlice; @@ -3117,6 +3117,10 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>, if skip.iter().any(|&x| x == n) { continue; } + // ignore private fields from non-local crates + if id.krate != ast::LOCAL_CRATE && elem.vis != Visibility::Public { + continue; + } let dist = lev_distance(n, name); if dist < best_dist { best = Some(n); diff --git a/src/test/compile-fail/suggest-private-fields.rs b/src/test/compile-fail/suggest-private-fields.rs new file mode 100644 index 00000000000..30648498ba8 --- /dev/null +++ b/src/test/compile-fail/suggest-private-fields.rs @@ -0,0 +1,36 @@ +// Copyright 2014 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. + +// aux-build:struct-field-privacy.rs + +extern crate "struct-field-privacy" as xc; + +use xc::B; + +struct A { + pub a: u32, + b: u32, +} + +fn main () { + // external crate struct + let k = B { + aa: 20, //~ ERROR structure `struct-field-privacy::B` has no field named `aa` + //~^ HELP did you mean `a`? + bb: 20, //~ ERROR structure `struct-field-privacy::B` has no field named `bb` + }; + // local crate struct + let l = A { + aa: 20, //~ ERROR structure `A` has no field named `aa` + //~^ HELP did you mean `a`? + bb: 20, //~ ERROR structure `A` has no field named `bb` + //~^ HELP did you mean `b`? + }; +} |
