Rollup merge of #22516 - leejunseok:nonpub_field_sugg, r=jakub-
closes #22421
This commit is contained in:
commit
494dbe9c07
@ -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);
|
||||
|
36
src/test/compile-fail/suggest-private-fields.rs
Normal file
36
src/test/compile-fail/suggest-private-fields.rs
Normal file
@ -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`?
|
||||
};
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user