Skip to content

Rollup of 9 pull requests #33548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
6fed013
middle: reset loop labels while visiting closure
birkenfeld May 2, 2016
201d9ed
add help on pattern guard
mrmiywj Apr 30, 2016
1bd4c9d
Doc improvement on std::fmt module
GuillaumeGomez May 1, 2016
38a5338
Add detailed error explanation for E0504
cramertj May 3, 2016
9d2c45d
doc: Fix tiny typo in vec-alloc.md
briangreenery May 9, 2016
d8882e2
E0061 typo fix
cramertj May 10, 2016
84034d4
typeck: if a private field exists, also check for a public method
birkenfeld May 2, 2016
de0906f
fix DFS for region error reporting
nikomatsakis May 10, 2016
a5a2f2b
Improve "since" tag placement
GuillaumeGomez May 10, 2016
b6b3b7b
Rollup merge of #33129 - GuillaumeGomez:fmt_doc, r=steveklabnik
steveklabnik May 10, 2016
1590fdd
Rollup merge of #33260 - mrmiywj:help-on-pattern-guard, r=guillaumegomez
steveklabnik May 10, 2016
fc299c0
Rollup merge of #33342 - birkenfeld:issue-26472, r=jseyfried
steveklabnik May 10, 2016
a9b9782
Rollup merge of #33345 - birkenfeld:issue-31754, r=pnkfelix
steveklabnik May 10, 2016
cb12cf0
Rollup merge of #33386 - cramertj:E0504, r=steveklabnik
steveklabnik May 10, 2016
25ce1f9
Rollup merge of #33524 - briangreenery:briangreenery-fast-and-loose, …
steveklabnik May 10, 2016
5d38a87
Rollup merge of #33528 - cramertj:E0061typeo, r=jseyfried
steveklabnik May 10, 2016
26cca1a
Rollup merge of #33539 - nikomatsakis:static-error, r=pnkfelix
steveklabnik May 10, 2016
d0580a7
Rollup merge of #33542 - GuillaumeGomez:move_since, r=steveklabnik
steveklabnik May 10, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/librustc_typeck/check/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ pub fn exists<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
span: Span,
method_name: ast::Name,
self_ty: ty::Ty<'tcx>,
call_expr_id: ast::NodeId)
call_expr_id: ast::NodeId,
allow_private: bool)
-> bool
{
let mode = probe::Mode::MethodCall;
Expand All @@ -92,7 +93,7 @@ pub fn exists<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
Err(NoMatch(..)) => false,
Err(Ambiguity(..)) => true,
Err(ClosureAmbiguity(..)) => true,
Err(PrivateMatch(..)) => true,
Err(PrivateMatch(..)) => allow_private,
}
}

Expand Down
12 changes: 9 additions & 3 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2947,12 +2947,18 @@ fn check_expr_with_expectation_and_lvalue_pref<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,

if let Some((did, field_ty)) = private_candidate {
let struct_path = fcx.tcx().item_path_str(did);
let msg = format!("field `{}` of struct `{}` is private", field.node, struct_path);
fcx.tcx().sess.span_err(expr.span, &msg);
fcx.write_ty(expr.id, field_ty);
let msg = format!("field `{}` of struct `{}` is private", field.node, struct_path);
let mut err = fcx.tcx().sess.struct_span_err(expr.span, &msg);
// Also check if an accessible method exists, which is often what is meant.
if method::exists(fcx, field.span, field.node, expr_t, expr.id, false) {
err.note(&format!("a method `{}` also exists, \
perhaps you wish to call it", field.node));
}
err.emit();
} else if field.node == keywords::Invalid.name() {
fcx.write_error(expr.id);
} else if method::exists(fcx, field.span, field.node, expr_t, expr.id) {
} else if method::exists(fcx, field.span, field.node, expr_t, expr.id, true) {
fcx.type_error_struct(field.span,
|actual| {
format!("attempted to take value of method `{}` on type \
Expand Down
24 changes: 24 additions & 0 deletions src/test/compile-fail/issue-26472.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2016 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 sub {
pub struct S { len: usize }
impl S {
pub fn new() -> S { S { len: 0 } }
pub fn len(&self) -> usize { self.len }
}
}

fn main() {
let s = sub::S::new();
let v = s.len;
//~^ ERROR field `len` of struct `sub::S` is private
//~| NOTE a method `len` also exists, perhaps you wish to call it
}