Skip to content

Commit 9fab382

Browse files
committed
---
yaml --- r: 273788 b: refs/heads/beta c: 6f16c5c h: refs/heads/master
1 parent 1a2a8b1 commit 9fab382

File tree

5 files changed

+47
-15
lines changed

5 files changed

+47
-15
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 62d181f474f5d3bb99ff157a9f27ec9f7e87938f
26+
refs/heads/beta: 6f16c5c81f86be4b4b50ef5396c6412844235dbf
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/librustc_typeck/check/method/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ pub enum MethodError<'tcx> {
4343

4444
// Using a `Fn`/`FnMut`/etc method on a raw closure type before we have inferred its kind.
4545
ClosureAmbiguity(/* DefId of fn trait */ DefId),
46+
47+
// Found an applicable method, but it is not visible.
48+
PrivateMatch(Def),
4649
}
4750

4851
// Contains a list of static methods that may apply, a list of unsatisfied trait predicates which
@@ -90,6 +93,7 @@ pub fn exists<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
9093
Err(NoMatch(..)) => false,
9194
Err(Ambiguity(..)) => true,
9295
Err(ClosureAmbiguity(..)) => true,
96+
Err(PrivateMatch(..)) => true,
9397
}
9498
}
9599

branches/beta/src/librustc_typeck/check/method/probe.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use super::suggest;
1616
use check;
1717
use check::{FnCtxt, UnresolvedTypeAction};
1818
use middle::def_id::DefId;
19+
use middle::def::Def;
1920
use rustc::ty::subst;
2021
use rustc::ty::subst::Subst;
2122
use rustc::traits;
@@ -47,6 +48,9 @@ struct ProbeContext<'a, 'tcx:'a> {
4748
/// used for error reporting
4849
static_candidates: Vec<CandidateSource>,
4950

51+
/// Some(candidate) if there is a private candidate
52+
private_candidate: Option<Def>,
53+
5054
/// Collects near misses when trait bounds for type parameters are unsatisfied and is only used
5155
/// for error reporting
5256
unsatisfied_predicates: Vec<TraitRef<'tcx>>
@@ -247,6 +251,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
247251
steps: Rc::new(steps),
248252
opt_simplified_steps: opt_simplified_steps,
249253
static_candidates: Vec::new(),
254+
private_candidate: None,
250255
unsatisfied_predicates: Vec::new(),
251256
}
252257
}
@@ -256,6 +261,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
256261
self.extension_candidates.clear();
257262
self.impl_dups.clear();
258263
self.static_candidates.clear();
264+
self.private_candidate = None;
259265
}
260266

261267
fn tcx(&self) -> &'a TyCtxt<'tcx> {
@@ -407,6 +413,11 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
407413
return self.record_static_candidate(ImplSource(impl_def_id));
408414
}
409415

416+
if item.vis() != hir::Public && !self.fcx.private_item_is_visible(item.def_id()) {
417+
self.private_candidate = Some(item.def());
418+
return
419+
}
420+
410421
let (impl_ty, impl_substs) = self.impl_ty_and_substs(impl_def_id);
411422
let impl_ty = impl_ty.subst(self.tcx(), &impl_substs);
412423

@@ -846,6 +857,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
846857
}
847858

848859
let static_candidates = mem::replace(&mut self.static_candidates, vec![]);
860+
let private_candidate = mem::replace(&mut self.private_candidate, None);
849861
let unsatisfied_predicates = mem::replace(&mut self.unsatisfied_predicates, vec![]);
850862

851863
// things failed, so lets look at all traits, for diagnostic purposes now:
@@ -879,9 +891,13 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
879891
// this error only occurs when assembling candidates
880892
tcx.sess.span_bug(span, "encountered ClosureAmbiguity from pick_core");
881893
}
882-
None => vec![],
894+
_ => vec![],
883895
};
884896

897+
if let Some(def) = private_candidate {
898+
return Err(MethodError::PrivateMatch(def));
899+
}
900+
885901
Err(MethodError::NoMatch(NoMatchData::new(static_candidates, unsatisfied_predicates,
886902
out_of_scope_traits, self.mode)))
887903
}

branches/beta/src/librustc_typeck/check/method/suggest.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
9191
MethodError::NoMatch(NoMatchData { static_candidates: static_sources,
9292
unsatisfied_predicates,
9393
out_of_scope_traits,
94-
mode }) => {
94+
mode, .. }) => {
9595
let cx = fcx.tcx();
9696

9797
let mut err = fcx.type_error_struct(
@@ -208,6 +208,11 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
208208
};
209209
fcx.sess().span_err(span, &msg);
210210
}
211+
212+
MethodError::PrivateMatch(def) => {
213+
let msg = format!("{} `{}` is private", def.kind_name(), item_name);
214+
fcx.tcx().sess.span_err(span, &msg);
215+
}
211216
}
212217

213218
fn report_candidates(fcx: &FnCtxt,

branches/beta/src/librustc_typeck/check/mod.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3757,23 +3757,30 @@ pub fn resolve_ty_and_def_ufcs<'a, 'b, 'tcx>(fcx: &FnCtxt<'b, 'tcx>,
37573757
&ty_segments[base_ty_end..]);
37583758
let item_segment = path.segments.last().unwrap();
37593759
let item_name = item_segment.identifier.name;
3760-
match method::resolve_ufcs(fcx, span, item_name, ty, node_id) {
3761-
Ok(def) => {
3762-
// Write back the new resolution.
3763-
fcx.ccx.tcx.def_map.borrow_mut()
3764-
.insert(node_id, def::PathResolution {
3765-
base_def: def,
3766-
depth: 0
3767-
});
3768-
Some((Some(ty), slice::ref_slice(item_segment), def))
3769-
}
3760+
let def = match method::resolve_ufcs(fcx, span, item_name, ty, node_id) {
3761+
Ok(def) => Some(def),
37703762
Err(error) => {
3763+
let def = match error {
3764+
method::MethodError::PrivateMatch(def) => Some(def),
3765+
_ => None,
3766+
};
37713767
if item_name != special_idents::invalid.name {
37723768
method::report_error(fcx, span, ty, item_name, None, error);
37733769
}
3774-
fcx.write_error(node_id);
3775-
None
3770+
def
37763771
}
3772+
};
3773+
3774+
if let Some(def) = def {
3775+
// Write back the new resolution.
3776+
fcx.ccx.tcx.def_map.borrow_mut().insert(node_id, def::PathResolution {
3777+
base_def: def,
3778+
depth: 0,
3779+
});
3780+
Some((Some(ty), slice::ref_slice(item_segment), def))
3781+
} else {
3782+
fcx.write_error(node_id);
3783+
None
37773784
}
37783785
}
37793786
}

0 commit comments

Comments
 (0)