Skip to content

Commit 2bf3bec

Browse files
committed
Rollup merge of #22516 - leejunseok:nonpub_field_sugg, r=jakub-
closes #22421
2 parents e846dcd + c34b8dc commit 2bf3bec

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ use std::iter::repeat;
117117
use std::slice;
118118
use syntax::{self, abi, attr};
119119
use syntax::attr::AttrMetaMethods;
120-
use syntax::ast::{self, ProvidedMethod, RequiredMethod, TypeTraitItem, DefId};
120+
use syntax::ast::{self, ProvidedMethod, RequiredMethod, TypeTraitItem, DefId, Visibility};
121121
use syntax::ast_util::{self, local_def, PostExpansionMethod};
122122
use syntax::codemap::{self, Span};
123123
use syntax::owned_slice::OwnedSlice;
@@ -3117,6 +3117,10 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
31173117
if skip.iter().any(|&x| x == n) {
31183118
continue;
31193119
}
3120+
// ignore private fields from non-local crates
3121+
if id.krate != ast::LOCAL_CRATE && elem.vis != Visibility::Public {
3122+
continue;
3123+
}
31203124
let dist = lev_distance(n, name);
31213125
if dist < best_dist {
31223126
best = Some(n);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:struct-field-privacy.rs
12+
13+
extern crate "struct-field-privacy" as xc;
14+
15+
use xc::B;
16+
17+
struct A {
18+
pub a: u32,
19+
b: u32,
20+
}
21+
22+
fn main () {
23+
// external crate struct
24+
let k = B {
25+
aa: 20, //~ ERROR structure `struct-field-privacy::B` has no field named `aa`
26+
//~^ HELP did you mean `a`?
27+
bb: 20, //~ ERROR structure `struct-field-privacy::B` has no field named `bb`
28+
};
29+
// local crate struct
30+
let l = A {
31+
aa: 20, //~ ERROR structure `A` has no field named `aa`
32+
//~^ HELP did you mean `a`?
33+
bb: 20, //~ ERROR structure `A` has no field named `bb`
34+
//~^ HELP did you mean `b`?
35+
};
36+
}

0 commit comments

Comments
 (0)