1
Fork 0

Fix ICE that occurs when an associated const is ambiguous.

Also change several error messages to refer to "items" rather than
"methods", since associated items that require resolution during type
checking are not always methods.
This commit is contained in:
Sean Patrick Santos 2015-05-02 23:30:59 -06:00
parent 4774d5d9a1
commit b4bbf3a88d
34 changed files with 182 additions and 148 deletions

View file

@ -16,12 +16,10 @@ use middle::def;
use middle::privacy::{AllPublic, DependsOn, LastPrivate, LastMod}; use middle::privacy::{AllPublic, DependsOn, LastPrivate, LastMod};
use middle::subst; use middle::subst;
use middle::traits; use middle::traits;
use middle::ty::*; use middle::ty::{self, AsPredicate, ToPolyTraitRef};
use middle::ty;
use middle::infer; use middle::infer;
use util::ppaux::Repr; use util::ppaux::Repr;
use std::rc::Rc;
use syntax::ast::DefId; use syntax::ast::DefId;
use syntax::ast; use syntax::ast;
use syntax::codemap::Span; use syntax::codemap::Span;
@ -39,7 +37,7 @@ pub enum MethodError {
// Did not find an applicable method, but we did find various // Did not find an applicable method, but we did find various
// static methods that may apply, as well as a list of // static methods that may apply, as well as a list of
// not-in-scope traits which may work. // not-in-scope traits which may work.
NoMatch(Vec<CandidateSource>, Vec<ast::DefId>), NoMatch(Vec<CandidateSource>, Vec<ast::DefId>, probe::Mode),
// Multiple methods might apply. // Multiple methods might apply.
Ambiguity(Vec<CandidateSource>), Ambiguity(Vec<CandidateSource>),
@ -62,7 +60,7 @@ type ItemIndex = usize; // just for doc purposes
pub fn exists<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, pub fn exists<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
span: Span, span: Span,
method_name: ast::Name, method_name: ast::Name,
self_ty: Ty<'tcx>, self_ty: ty::Ty<'tcx>,
call_expr_id: ast::NodeId) call_expr_id: ast::NodeId)
-> bool -> bool
{ {
@ -92,11 +90,11 @@ pub fn exists<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
pub fn lookup<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, pub fn lookup<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
span: Span, span: Span,
method_name: ast::Name, method_name: ast::Name,
self_ty: Ty<'tcx>, self_ty: ty::Ty<'tcx>,
supplied_method_types: Vec<Ty<'tcx>>, supplied_method_types: Vec<ty::Ty<'tcx>>,
call_expr: &'tcx ast::Expr, call_expr: &'tcx ast::Expr,
self_expr: &'tcx ast::Expr) self_expr: &'tcx ast::Expr)
-> Result<MethodCallee<'tcx>, MethodError> -> Result<ty::MethodCallee<'tcx>, MethodError>
{ {
debug!("lookup(method_name={}, self_ty={}, call_expr={}, self_expr={})", debug!("lookup(method_name={}, self_ty={}, call_expr={}, self_expr={})",
method_name.repr(fcx.tcx()), method_name.repr(fcx.tcx()),
@ -115,9 +113,9 @@ pub fn lookup_in_trait<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
self_expr: Option<&ast::Expr>, self_expr: Option<&ast::Expr>,
m_name: ast::Name, m_name: ast::Name,
trait_def_id: DefId, trait_def_id: DefId,
self_ty: Ty<'tcx>, self_ty: ty::Ty<'tcx>,
opt_input_types: Option<Vec<Ty<'tcx>>>) opt_input_types: Option<Vec<ty::Ty<'tcx>>>)
-> Option<MethodCallee<'tcx>> -> Option<ty::MethodCallee<'tcx>>
{ {
lookup_in_trait_adjusted(fcx, span, self_expr, m_name, trait_def_id, lookup_in_trait_adjusted(fcx, span, self_expr, m_name, trait_def_id,
0, false, self_ty, opt_input_types) 0, false, self_ty, opt_input_types)
@ -139,9 +137,9 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
trait_def_id: DefId, trait_def_id: DefId,
autoderefs: usize, autoderefs: usize,
unsize: bool, unsize: bool,
self_ty: Ty<'tcx>, self_ty: ty::Ty<'tcx>,
opt_input_types: Option<Vec<Ty<'tcx>>>) opt_input_types: Option<Vec<ty::Ty<'tcx>>>)
-> Option<MethodCallee<'tcx>> -> Option<ty::MethodCallee<'tcx>>
{ {
debug!("lookup_in_trait_adjusted(self_ty={}, self_expr={}, m_name={}, trait_def_id={})", debug!("lookup_in_trait_adjusted(self_ty={}, self_expr={}, m_name={}, trait_def_id={})",
self_ty.repr(fcx.tcx()), self_ty.repr(fcx.tcx()),
@ -186,7 +184,9 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
// Trait must have a method named `m_name` and it should not have // Trait must have a method named `m_name` and it should not have
// type parameters or early-bound regions. // type parameters or early-bound regions.
let tcx = fcx.tcx(); let tcx = fcx.tcx();
let (method_num, method_ty) = trait_method(tcx, trait_def_id, m_name).unwrap(); let (method_num, method_ty) = trait_item(tcx, trait_def_id, m_name)
.and_then(|(idx, item)| item.as_opt_method().map(|m| (idx, m)))
.unwrap();
assert_eq!(method_ty.generics.types.len(subst::FnSpace), 0); assert_eq!(method_ty.generics.types.len(subst::FnSpace), 0);
assert_eq!(method_ty.generics.regions.len(subst::FnSpace), 0); assert_eq!(method_ty.generics.regions.len(subst::FnSpace), 0);
@ -288,10 +288,10 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
} }
} }
let callee = MethodCallee { let callee = ty::MethodCallee {
origin: MethodTypeParam(MethodParam{trait_ref: trait_ref.clone(), origin: ty::MethodTypeParam(ty::MethodParam{trait_ref: trait_ref.clone(),
method_num: method_num, method_num: method_num,
impl_def_id: None}), impl_def_id: None}),
ty: fty, ty: fty,
substs: trait_ref.substs.clone() substs: trait_ref.substs.clone()
}; };
@ -304,7 +304,7 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
pub fn resolve_ufcs<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, pub fn resolve_ufcs<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
span: Span, span: Span,
method_name: ast::Name, method_name: ast::Name,
self_ty: Ty<'tcx>, self_ty: ty::Ty<'tcx>,
expr_id: ast::NodeId) expr_id: ast::NodeId)
-> Result<(def::Def, LastPrivate), MethodError> -> Result<(def::Def, LastPrivate), MethodError>
{ {
@ -322,9 +322,9 @@ pub fn resolve_ufcs<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
_ => def::FromTrait(pick.item.container().id()) _ => def::FromTrait(pick.item.container().id())
}; };
let def_result = match pick.item { let def_result = match pick.item {
ImplOrTraitItem::MethodTraitItem(..) => def::DefMethod(def_id, provenance), ty::ImplOrTraitItem::MethodTraitItem(..) => def::DefMethod(def_id, provenance),
ImplOrTraitItem::ConstTraitItem(..) => def::DefAssociatedConst(def_id, provenance), ty::ImplOrTraitItem::ConstTraitItem(..) => def::DefAssociatedConst(def_id, provenance),
ImplOrTraitItem::TypeTraitItem(..) => { ty::ImplOrTraitItem::TypeTraitItem(..) => {
fcx.tcx().sess.span_bug(span, "resolve_ufcs: probe picked associated type"); fcx.tcx().sess.span_bug(span, "resolve_ufcs: probe picked associated type");
} }
}; };
@ -332,31 +332,30 @@ pub fn resolve_ufcs<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
} }
/// Find method with name `method_name` defined in `trait_def_id` and return it, along with its /// Find item with name `item_name` defined in `trait_def_id` and return it, along with its
/// index (or `None`, if no such method). /// index (or `None`, if no such item).
fn trait_method<'tcx>(tcx: &ty::ctxt<'tcx>, fn trait_item<'tcx>(tcx: &ty::ctxt<'tcx>,
trait_def_id: ast::DefId, trait_def_id: ast::DefId,
method_name: ast::Name) item_name: ast::Name)
-> Option<(usize, Rc<ty::Method<'tcx>>)> -> Option<(usize, ty::ImplOrTraitItem<'tcx>)>
{ {
let trait_items = ty::trait_items(tcx, trait_def_id); let trait_items = ty::trait_items(tcx, trait_def_id);
trait_items trait_items
.iter() .iter()
.enumerate() .enumerate()
.find(|&(_, ref item)| item.name() == method_name) .find(|&(_, ref item)| item.name() == item_name)
.and_then(|(idx, item)| item.as_opt_method().map(|m| (idx, m))) .map(|(num, item)| (num, (*item).clone()))
} }
fn impl_method<'tcx>(tcx: &ty::ctxt<'tcx>, fn impl_item<'tcx>(tcx: &ty::ctxt<'tcx>,
impl_def_id: ast::DefId, impl_def_id: ast::DefId,
method_name: ast::Name) item_name: ast::Name)
-> Option<Rc<ty::Method<'tcx>>> -> Option<ty::ImplOrTraitItem<'tcx>>
{ {
let impl_items = tcx.impl_items.borrow(); let impl_items = tcx.impl_items.borrow();
let impl_items = impl_items.get(&impl_def_id).unwrap(); let impl_items = impl_items.get(&impl_def_id).unwrap();
impl_items impl_items
.iter() .iter()
.map(|&did| ty::impl_or_trait_item(tcx, did.def_id())) .map(|&did| ty::impl_or_trait_item(tcx, did.def_id()))
.find(|m| m.name() == method_name) .find(|m| m.name() == item_name)
.and_then(|item| item.as_opt_method())
} }

View file

@ -136,7 +136,7 @@ pub fn probe<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
let steps = if mode == Mode::MethodCall { let steps = if mode == Mode::MethodCall {
match create_steps(fcx, span, self_ty) { match create_steps(fcx, span, self_ty) {
Some(steps) => steps, Some(steps) => steps,
None => return Err(MethodError::NoMatch(Vec::new(), Vec::new())), None => return Err(MethodError::NoMatch(Vec::new(), Vec::new(), mode)),
} }
} else { } else {
vec![CandidateStep { vec![CandidateStep {
@ -866,7 +866,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
} }
} }
}).collect(), }).collect(),
Some(Err(MethodError::NoMatch(_, others))) => { Some(Err(MethodError::NoMatch(_, others, _))) => {
assert!(others.is_empty()); assert!(others.is_empty());
vec![] vec![]
} }
@ -877,7 +877,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
None => vec![], None => vec![],
}; };
Err(MethodError::NoMatch(static_candidates, out_of_scope_traits)) Err(MethodError::NoMatch(static_candidates, out_of_scope_traits, self.mode))
} }
fn pick_core(&mut self) -> Option<PickResult<'tcx>> { fn pick_core(&mut self) -> Option<PickResult<'tcx>> {

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
//! Give useful errors and suggestions to users when a method can't be //! Give useful errors and suggestions to users when an item can't be
//! found or is otherwise invalid. //! found or is otherwise invalid.
use CrateCtxt; use CrateCtxt;
@ -27,12 +27,13 @@ use syntax::print::pprust;
use std::cell; use std::cell;
use std::cmp::Ordering; use std::cmp::Ordering;
use super::{MethodError, CandidateSource, impl_method, trait_method}; use super::{MethodError, CandidateSource, impl_item, trait_item};
use super::probe::Mode;
pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
span: Span, span: Span,
rcvr_ty: Ty<'tcx>, rcvr_ty: Ty<'tcx>,
method_name: ast::Name, item_name: ast::Name,
rcvr_expr: Option<&ast::Expr>, rcvr_expr: Option<&ast::Expr>,
error: MethodError) error: MethodError)
{ {
@ -42,28 +43,30 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
} }
match error { match error {
MethodError::NoMatch(static_sources, out_of_scope_traits) => { MethodError::NoMatch(static_sources, out_of_scope_traits, mode) => {
let cx = fcx.tcx(); let cx = fcx.tcx();
let method_ustring = method_name.user_string(cx); let item_ustring = item_name.user_string(cx);
fcx.type_error_message( fcx.type_error_message(
span, span,
|actual| { |actual| {
format!("type `{}` does not implement any \ format!("no {} named `{}` found for type `{}` \
method in scope named `{}`", in the current scope",
actual, if mode == Mode::MethodCall { "method" }
method_ustring) else { "associated item" },
item_ustring,
actual)
}, },
rcvr_ty, rcvr_ty,
None); None);
// If the method has the name of a field, give a help note // If the item has the name of a field, give a help note
if let (&ty::ty_struct(did, _), Some(_)) = (&rcvr_ty.sty, rcvr_expr) { if let (&ty::ty_struct(did, _), Some(_)) = (&rcvr_ty.sty, rcvr_expr) {
let fields = ty::lookup_struct_fields(cx, did); let fields = ty::lookup_struct_fields(cx, did);
if fields.iter().any(|f| f.name == method_name) { if fields.iter().any(|f| f.name == item_name) {
cx.sess.span_note(span, cx.sess.span_note(span,
&format!("use `(s.{0})(...)` if you meant to call the \ &format!("use `(s.{0})(...)` if you meant to call the \
function stored in the `{0}` field", method_ustring)); function stored in the `{0}` field", item_ustring));
} }
} }
@ -72,25 +75,25 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
span, span,
"found defined static methods, maybe a `self` is missing?"); "found defined static methods, maybe a `self` is missing?");
report_candidates(fcx, span, method_name, static_sources); report_candidates(fcx, span, item_name, static_sources);
} }
suggest_traits_to_import(fcx, span, rcvr_ty, method_name, suggest_traits_to_import(fcx, span, rcvr_ty, item_name,
rcvr_expr, out_of_scope_traits) rcvr_expr, out_of_scope_traits)
} }
MethodError::Ambiguity(sources) => { MethodError::Ambiguity(sources) => {
span_err!(fcx.sess(), span, E0034, span_err!(fcx.sess(), span, E0034,
"multiple applicable methods in scope"); "multiple applicable items in scope");
report_candidates(fcx, span, method_name, sources); report_candidates(fcx, span, item_name, sources);
} }
MethodError::ClosureAmbiguity(trait_def_id) => { MethodError::ClosureAmbiguity(trait_def_id) => {
let msg = format!("the `{}` method from the `{}` trait cannot be explicitly \ let msg = format!("the `{}` method from the `{}` trait cannot be explicitly \
invoked on this closure as we have not yet inferred what \ invoked on this closure as we have not yet inferred what \
kind of closure it is", kind of closure it is",
method_name.user_string(fcx.tcx()), item_name.user_string(fcx.tcx()),
ty::item_path_str(fcx.tcx(), trait_def_id)); ty::item_path_str(fcx.tcx(), trait_def_id));
let msg = if let Some(callee) = rcvr_expr { let msg = if let Some(callee) = rcvr_expr {
format!("{}; use overloaded call notation instead (e.g., `{}()`)", format!("{}; use overloaded call notation instead (e.g., `{}()`)",
@ -104,7 +107,7 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
fn report_candidates(fcx: &FnCtxt, fn report_candidates(fcx: &FnCtxt,
span: Span, span: Span,
method_name: ast::Name, item_name: ast::Name,
mut sources: Vec<CandidateSource>) { mut sources: Vec<CandidateSource>) {
sources.sort(); sources.sort();
sources.dedup(); sources.dedup();
@ -112,11 +115,11 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
for (idx, source) in sources.iter().enumerate() { for (idx, source) in sources.iter().enumerate() {
match *source { match *source {
CandidateSource::ImplSource(impl_did) => { CandidateSource::ImplSource(impl_did) => {
// Provide the best span we can. Use the method, if local to crate, else // Provide the best span we can. Use the item, if local to crate, else
// the impl, if local to crate (method may be defaulted), else the call site. // the impl, if local to crate (item may be defaulted), else the call site.
let method = impl_method(fcx.tcx(), impl_did, method_name).unwrap(); let item = impl_item(fcx.tcx(), impl_did, item_name).unwrap();
let impl_span = fcx.tcx().map.def_id_span(impl_did, span); let impl_span = fcx.tcx().map.def_id_span(impl_did, span);
let method_span = fcx.tcx().map.def_id_span(method.def_id, impl_span); let item_span = fcx.tcx().map.def_id_span(item.def_id(), impl_span);
let impl_ty = check::impl_self_ty(fcx, span, impl_did).ty; let impl_ty = check::impl_self_ty(fcx, span, impl_did).ty;
@ -127,16 +130,16 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
trait_ref.def_id)), trait_ref.def_id)),
}; };
span_note!(fcx.sess(), method_span, span_note!(fcx.sess(), item_span,
"candidate #{} is defined in an impl{} for the type `{}`", "candidate #{} is defined in an impl{} for the type `{}`",
idx + 1, idx + 1,
insertion, insertion,
impl_ty.user_string(fcx.tcx())); impl_ty.user_string(fcx.tcx()));
} }
CandidateSource::TraitSource(trait_did) => { CandidateSource::TraitSource(trait_did) => {
let (_, method) = trait_method(fcx.tcx(), trait_did, method_name).unwrap(); let (_, item) = trait_item(fcx.tcx(), trait_did, item_name).unwrap();
let method_span = fcx.tcx().map.def_id_span(method.def_id, span); let item_span = fcx.tcx().map.def_id_span(item.def_id(), span);
span_note!(fcx.sess(), method_span, span_note!(fcx.sess(), item_span,
"candidate #{} is defined in the trait `{}`", "candidate #{} is defined in the trait `{}`",
idx + 1, idx + 1,
ty::item_path_str(fcx.tcx(), trait_did)); ty::item_path_str(fcx.tcx(), trait_did));
@ -152,19 +155,19 @@ pub type AllTraitsVec = Vec<TraitInfo>;
fn suggest_traits_to_import<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, fn suggest_traits_to_import<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
span: Span, span: Span,
rcvr_ty: Ty<'tcx>, rcvr_ty: Ty<'tcx>,
method_name: ast::Name, item_name: ast::Name,
rcvr_expr: Option<&ast::Expr>, rcvr_expr: Option<&ast::Expr>,
valid_out_of_scope_traits: Vec<ast::DefId>) valid_out_of_scope_traits: Vec<ast::DefId>)
{ {
let tcx = fcx.tcx(); let tcx = fcx.tcx();
let method_ustring = method_name.user_string(tcx); let item_ustring = item_name.user_string(tcx);
if !valid_out_of_scope_traits.is_empty() { if !valid_out_of_scope_traits.is_empty() {
let mut candidates = valid_out_of_scope_traits; let mut candidates = valid_out_of_scope_traits;
candidates.sort(); candidates.sort();
candidates.dedup(); candidates.dedup();
let msg = format!( let msg = format!(
"methods from traits can only be called if the trait is in scope; \ "items from traits can only be used if the trait is in scope; \
the following {traits_are} implemented but not in scope, \ the following {traits_are} implemented but not in scope, \
perhaps add a `use` for {one_of_them}:", perhaps add a `use` for {one_of_them}:",
traits_are = if candidates.len() == 1 {"trait is"} else {"traits are"}, traits_are = if candidates.len() == 1 {"trait is"} else {"traits are"},
@ -185,7 +188,7 @@ fn suggest_traits_to_import<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
let type_is_local = type_derefs_to_local(fcx, span, rcvr_ty, rcvr_expr); let type_is_local = type_derefs_to_local(fcx, span, rcvr_ty, rcvr_expr);
// there's no implemented traits, so lets suggest some traits to // there's no implemented traits, so lets suggest some traits to
// implement, by finding ones that have the method name, and are // implement, by finding ones that have the item name, and are
// legal to implement. // legal to implement.
let mut candidates = all_traits(fcx.ccx) let mut candidates = all_traits(fcx.ccx)
.filter(|info| { .filter(|info| {
@ -196,7 +199,7 @@ fn suggest_traits_to_import<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
// implementing a trait would be legal but is rejected // implementing a trait would be legal but is rejected
// here). // here).
(type_is_local || ast_util::is_local(info.def_id)) (type_is_local || ast_util::is_local(info.def_id))
&& trait_method(tcx, info.def_id, method_name).is_some() && trait_item(tcx, info.def_id, item_name).is_some()
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@ -209,12 +212,12 @@ fn suggest_traits_to_import<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
// of a type parameter: suggest adding a trait bound rather // of a type parameter: suggest adding a trait bound rather
// than implementing. // than implementing.
let msg = format!( let msg = format!(
"methods from traits can only be called if the trait is implemented and in scope; \ "items from traits can only be used if the trait is implemented and in scope; \
the following {traits_define} a method `{name}`, \ the following {traits_define} an item `{name}`, \
perhaps you need to implement {one_of_them}:", perhaps you need to implement {one_of_them}:",
traits_define = if candidates.len() == 1 {"trait defines"} else {"traits define"}, traits_define = if candidates.len() == 1 {"trait defines"} else {"traits define"},
one_of_them = if candidates.len() == 1 {"it"} else {"one of them"}, one_of_them = if candidates.len() == 1 {"it"} else {"one of them"},
name = method_ustring); name = item_ustring);
fcx.sess().fileline_help(span, &msg[..]); fcx.sess().fileline_help(span, &msg[..]);

View file

@ -0,0 +1,33 @@
// Copyright 2015 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.
#![feature(associated_consts)]
trait Foo {
const ID: i32;
}
trait Bar {
const ID: i32;
}
impl Foo for i32 {
const ID: i32 = 1;
}
impl Bar for i32 {
const ID: i32 = 3;
}
const X: i32 = <i32>::ID; //~ ERROR E0034
fn main() {
assert_eq!(1, X);
}

View file

@ -15,11 +15,11 @@ fn main() {
// vectors to slices then automatically create a self reference. // vectors to slices then automatically create a self reference.
let mut a = vec!(0); let mut a = vec!(0);
a.test_mut(); //~ ERROR does not implement any method in scope named `test_mut` a.test_mut(); //~ ERROR no method named `test_mut` found
a.test(); //~ ERROR does not implement any method in scope named `test` a.test(); //~ ERROR no method named `test` found
([1]).test(); //~ ERROR does not implement any method in scope named `test` ([1]).test(); //~ ERROR no method named `test` found
(&[1]).test(); //~ ERROR does not implement any method in scope named `test` (&[1]).test(); //~ ERROR no method named `test` found
} }
trait MyIter { trait MyIter {

View file

@ -60,5 +60,5 @@ fn cat(in_x : usize, in_y : isize, in_name: String) -> cat {
fn main() { fn main() {
let nyan: Box<noisy> = box cat(0, 2, "nyan".to_string()) as Box<noisy>; let nyan: Box<noisy> = box cat(0, 2, "nyan".to_string()) as Box<noisy>;
nyan.eat(); //~ ERROR does not implement any method in scope named `eat` nyan.eat(); //~ ERROR no method named `eat` found
} }

View file

@ -38,7 +38,7 @@ mod NoImport {
use Lib::TheStruct; use Lib::TheStruct;
fn call_the_fn(s: &TheStruct) { fn call_the_fn(s: &TheStruct) {
s.the_fn(); //~ ERROR does not implement any method in scope named `the_fn` s.the_fn(); //~ ERROR no method named `the_fn` found
} }
} }

View file

@ -30,7 +30,7 @@ mod NoImport {
use coherence_inherent_cc_lib::TheStruct; use coherence_inherent_cc_lib::TheStruct;
fn call_the_fn(s: &TheStruct) { fn call_the_fn(s: &TheStruct) {
s.the_fn(); //~ ERROR does not implement any method in scope named `the_fn` s.the_fn(); //~ ERROR no method named `the_fn` found
} }
} }

View file

@ -26,6 +26,6 @@ fn foo(i:isize) -> foo {
fn main() { fn main() {
let x = foo(10); let x = foo(10);
let _y = x.clone(); let _y = x.clone();
//~^ ERROR does not implement any method in scope //~^ ERROR no method named `clone` found
println!("{:?}", x); println!("{:?}", x);
} }

View file

@ -24,7 +24,7 @@ pub mod b {
use b::B; use b::B;
fn foo(b: &B) { fn foo(b: &B) {
b.foo(); //~ ERROR: does not implement any method in scope named b.foo(); //~ ERROR: no method named `foo` found
} }
} }

View file

@ -31,7 +31,7 @@ impl Node for Stuff {
} }
fn iterate<N: Node, G: Graph<N>>(graph: &G) { fn iterate<N: Node, G: Graph<N>>(graph: &G) {
for node in graph.iter() { //~ ERROR does not implement any method in scope named for node in graph.iter() { //~ ERROR no method named `iter` found
node.zomg(); //~ error: the type of this value must be known in this context node.zomg(); //~ error: the type of this value must be known in this context
} }
} }

View file

@ -14,6 +14,6 @@ struct Obj<F> where F: FnMut() -> u32 {
fn main() { fn main() {
let o = Obj { closure: || 42 }; let o = Obj { closure: || 42 };
o.closure(); //~ ERROR does not implement any method in scope named `closure` o.closure(); //~ ERROR no method named `closure` found
//~^ NOTE use `(s.closure)(...)` if you meant to call the function stored in the `closure` field //~^ NOTE use `(s.closure)(...)` if you meant to call the function stored in the `closure` field
} }

View file

@ -14,7 +14,7 @@ fn main() {
let f = 42; let f = 42;
let _g = if f < 5 { let _g = if f < 5 {
f.honk() //~ ERROR does not implement any method in scope named `honk` f.honk() //~ ERROR no method named `honk` found
} }
else { else {
() ()

View file

@ -11,5 +11,5 @@
#![feature(unboxed_closures)] #![feature(unboxed_closures)]
fn main() { fn main() {
"".homura()(); //~ ERROR does not implement any method "".homura()(); //~ ERROR no method named `homura` found
} }

View file

@ -11,7 +11,7 @@
struct Homura; struct Homura;
fn akemi(homura: Homura) { fn akemi(homura: Homura) {
let Some(ref madoka) = Some(homura.kaname()); //~ ERROR does not implement any method let Some(ref madoka) = Some(homura.kaname()); //~ ERROR no method named `kaname` found
madoka.clone(); //~ ERROR the type of this value must be known in this context madoka.clone(); //~ ERROR the type of this value must be known in this context
} }

View file

@ -22,5 +22,5 @@ impl<A> vec_monad<A> for Vec<A> {
} }
fn main() { fn main() {
["hi"].bind(|x| [x] ); ["hi"].bind(|x| [x] );
//~^ ERROR type `[&str; 1]` does not implement any method in scope named `bind` //~^ ERROR no method named `bind` found for type `[&str; 1]` in the current scope
} }

View file

@ -20,5 +20,5 @@ impl Drop for C {
fn main() { fn main() {
let c = C{ x: 2}; let c = C{ x: 2};
let _d = c.clone(); //~ ERROR does not implement any method in scope let _d = c.clone(); //~ ERROR no method named `clone` found
} }

View file

@ -11,7 +11,7 @@
trait A { trait A {
fn a(&self) { fn a(&self) {
|| self.b() || self.b()
//~^ ERROR type `&Self` does not implement any method in scope named `b` //~^ ERROR no method named `b` found for type `&Self` in the current scope
//~| ERROR mismatched types //~| ERROR mismatched types
//~| expected `()` //~| expected `()`
//~| found closure //~| found closure

View file

@ -23,7 +23,7 @@ trait Add {
impl Add for isize { impl Add for isize {
fn to_int(&self) -> isize { *self } fn to_int(&self) -> isize { *self }
fn add_dynamic(&self, other: &Add) -> isize { fn add_dynamic(&self, other: &Add) -> isize {
self.to_int() + other.to_int() //~ ERROR multiple applicable methods in scope self.to_int() + other.to_int() //~ ERROR multiple applicable items in scope
} }
} }

View file

@ -17,7 +17,7 @@ impl Obj {
return 1+1 == 2 return 1+1 == 2
} }
pub fn chirp(&self) { pub fn chirp(&self) {
self.boom(); //~ ERROR `&Obj` does not implement any method in scope named `boom` self.boom(); //~ ERROR no method named `boom` found for type `&Obj` in the current scope
} }
} }

View file

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
// error-pattern: type `&Foo` does not implement any method in scope named `foo`
trait Foo { trait Foo {
fn foo(self: Box<Self>); fn foo(self: Box<Self>);
} }
@ -20,4 +18,5 @@ impl Foo for isize {
fn main() { fn main() {
(&5 as &Foo).foo(); (&5 as &Foo).foo();
//~^ ERROR: no method named `foo` found for type `&Foo` in the current scope
} }

View file

@ -71,15 +71,15 @@ impl ManyImplTrait for Myisize {}
fn no_param_bound(u: usize, m: Myisize) -> usize { fn no_param_bound(u: usize, m: Myisize) -> usize {
u.f8(42) + u.f9(342) + m.fff(42) u.f8(42) + u.f9(342) + m.fff(42)
//~^ ERROR type `usize` does not implement any method in scope named `f9` //~^ ERROR no method named `f9` found for type `usize` in the current scope
//~^^ NOTE found defined static methods, maybe a `self` is missing? //~^^ NOTE found defined static methods, maybe a `self` is missing?
//~^^^ ERROR type `Myisize` does not implement any method in scope named `fff` //~^^^ ERROR no method named `fff` found for type `Myisize` in the current scope
//~^^^^ NOTE found defined static methods, maybe a `self` is missing? //~^^^^ NOTE found defined static methods, maybe a `self` is missing?
} }
fn param_bound<T: ManyImplTrait>(t: T) -> bool { fn param_bound<T: ManyImplTrait>(t: T) -> bool {
t.is_str() t.is_str()
//~^ ERROR type `T` does not implement any method in scope named `is_str` //~^ ERROR no method named `is_str` found for type `T` in the current scope
//~^^ NOTE found defined static methods, maybe a `self` is missing? //~^^ NOTE found defined static methods, maybe a `self` is missing?
} }

View file

@ -13,5 +13,5 @@
struct Foo; struct Foo;
fn main() { fn main() {
Foo::bar(); //~ ERROR type `Foo` does not implement any method in scope named `bar` Foo::bar(); //~ ERROR no associated item named `bar` found for type `Foo` in the current scope
} }

View file

@ -12,7 +12,7 @@
macro_rules! fake_method_stmt { //~ NOTE in expansion of macro_rules! fake_method_stmt { //~ NOTE in expansion of
() => { () => {
1.fake() //~ ERROR does not implement any method 1.fake() //~ ERROR no method named `fake` found
} }
} }
@ -30,7 +30,7 @@ macro_rules! fake_anon_field_stmt { //~ NOTE in expansion of
macro_rules! fake_method_expr { //~ NOTE in expansion of macro_rules! fake_method_expr { //~ NOTE in expansion of
() => { () => {
1.fake() //~ ERROR does not implement any method 1.fake() //~ ERROR no method named `fake` found
} }
} }

View file

@ -25,6 +25,6 @@ fn main() {
let y = Foo; let y = Foo;
y.zero() y.zero()
.take() //~ ERROR type `Foo` does not implement any method in scope named `take` .take() //~ ERROR no method named `take` found for type `Foo` in the current scope
.one(0); .one(0);
} }

View file

@ -16,7 +16,7 @@ fn foo<F>(f: F) where F: FnMut(Foo) {}
fn main() { fn main() {
foo(|s| s.is_empty()); foo(|s| s.is_empty());
//~^ ERROR does not implement any method //~^ ERROR no method named `is_empty` found
//~^^ HELP #1: `core::slice::SliceExt` //~^^ HELP #1: `core::slice::SliceExt`
//~^^^ HELP #2: `core::str::StrExt` //~^^^ HELP #2: `core::str::StrExt`
} }

View file

@ -33,36 +33,36 @@ fn main() {
1u32.method(); 1u32.method();
//~^ HELP following traits are implemented but not in scope, perhaps add a `use` for one of them //~^ HELP following traits are implemented but not in scope, perhaps add a `use` for one of them
//~^^ ERROR does not implement //~^^ ERROR no method named
//~^^^ HELP `foo::Bar` //~^^^ HELP `foo::Bar`
//~^^^^ HELP `no_method_suggested_traits::foo::PubPub` //~^^^^ HELP `no_method_suggested_traits::foo::PubPub`
std::rc::Rc::new(&mut Box::new(&1u32)).method(); std::rc::Rc::new(&mut Box::new(&1u32)).method();
//~^ HELP following traits are implemented but not in scope, perhaps add a `use` for one of them //~^ HELP following traits are implemented but not in scope, perhaps add a `use` for one of them
//~^^ ERROR does not implement //~^^ ERROR no method named
//~^^^ HELP `foo::Bar` //~^^^ HELP `foo::Bar`
//~^^^^ HELP `no_method_suggested_traits::foo::PubPub` //~^^^^ HELP `no_method_suggested_traits::foo::PubPub`
'a'.method(); 'a'.method();
//~^ ERROR does not implement //~^ ERROR no method named
//~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it: //~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it:
//~^^^ HELP `foo::Bar` //~^^^ HELP `foo::Bar`
std::rc::Rc::new(&mut Box::new(&'a')).method(); std::rc::Rc::new(&mut Box::new(&'a')).method();
//~^ ERROR does not implement //~^ ERROR no method named
//~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it: //~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it:
//~^^^ HELP `foo::Bar` //~^^^ HELP `foo::Bar`
1i32.method(); 1i32.method();
//~^ ERROR does not implement //~^ ERROR no method named
//~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it: //~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it:
//~^^^ HELP `no_method_suggested_traits::foo::PubPub` //~^^^ HELP `no_method_suggested_traits::foo::PubPub`
std::rc::Rc::new(&mut Box::new(&1i32)).method(); std::rc::Rc::new(&mut Box::new(&1i32)).method();
//~^ ERROR does not implement //~^ ERROR no method named
//~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it: //~^^ HELP the following trait is implemented but not in scope, perhaps add a `use` for it:
//~^^^ HELP `no_method_suggested_traits::foo::PubPub` //~^^^ HELP `no_method_suggested_traits::foo::PubPub`
Foo.method(); Foo.method();
//~^ ERROR does not implement //~^ ERROR no method named
//~^^ HELP following traits define a method `method`, perhaps you need to implement one of them //~^^ HELP following traits define an item `method`, perhaps you need to implement one of them
//~^^^ HELP `foo::Bar` //~^^^ HELP `foo::Bar`
//~^^^^ HELP `no_method_suggested_traits::foo::PubPub` //~^^^^ HELP `no_method_suggested_traits::foo::PubPub`
//~^^^^^ HELP `no_method_suggested_traits::reexport::Reexported` //~^^^^^ HELP `no_method_suggested_traits::reexport::Reexported`
@ -70,8 +70,8 @@ fn main() {
//~^^^^^^^ HELP `no_method_suggested_traits::qux::PrivPub` //~^^^^^^^ HELP `no_method_suggested_traits::qux::PrivPub`
//~^^^^^^^^ HELP `no_method_suggested_traits::quz::PrivPriv` //~^^^^^^^^ HELP `no_method_suggested_traits::quz::PrivPriv`
std::rc::Rc::new(&mut Box::new(&Foo)).method(); std::rc::Rc::new(&mut Box::new(&Foo)).method();
//~^ ERROR does not implement //~^ ERROR no method named
//~^^ HELP following traits define a method `method`, perhaps you need to implement one of them //~^^ HELP following traits define an item `method`, perhaps you need to implement one of them
//~^^^ HELP `foo::Bar` //~^^^ HELP `foo::Bar`
//~^^^^ HELP `no_method_suggested_traits::foo::PubPub` //~^^^^ HELP `no_method_suggested_traits::foo::PubPub`
//~^^^^^ HELP `no_method_suggested_traits::reexport::Reexported` //~^^^^^ HELP `no_method_suggested_traits::reexport::Reexported`
@ -80,55 +80,55 @@ fn main() {
//~^^^^^^^^ HELP `no_method_suggested_traits::quz::PrivPriv` //~^^^^^^^^ HELP `no_method_suggested_traits::quz::PrivPriv`
1u64.method2(); 1u64.method2();
//~^ ERROR does not implement //~^ ERROR no method named
//~^^ HELP the following trait defines a method `method2`, perhaps you need to implement it //~^^ HELP the following trait defines an item `method2`, perhaps you need to implement it
//~^^^ HELP `foo::Bar` //~^^^ HELP `foo::Bar`
std::rc::Rc::new(&mut Box::new(&1u64)).method2(); std::rc::Rc::new(&mut Box::new(&1u64)).method2();
//~^ ERROR does not implement //~^ ERROR no method named
//~^^ HELP the following trait defines a method `method2`, perhaps you need to implement it //~^^ HELP the following trait defines an item `method2`, perhaps you need to implement it
//~^^^ HELP `foo::Bar` //~^^^ HELP `foo::Bar`
no_method_suggested_traits::Foo.method2(); no_method_suggested_traits::Foo.method2();
//~^ ERROR does not implement //~^ ERROR no method named
//~^^ HELP following trait defines a method `method2`, perhaps you need to implement it //~^^ HELP following trait defines an item `method2`, perhaps you need to implement it
//~^^^ HELP `foo::Bar` //~^^^ HELP `foo::Bar`
std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method2(); std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method2();
//~^ ERROR does not implement //~^ ERROR no method named
//~^^ HELP following trait defines a method `method2`, perhaps you need to implement it //~^^ HELP following trait defines an item `method2`, perhaps you need to implement it
//~^^^ HELP `foo::Bar` //~^^^ HELP `foo::Bar`
no_method_suggested_traits::Bar::X.method2(); no_method_suggested_traits::Bar::X.method2();
//~^ ERROR does not implement //~^ ERROR no method named
//~^^ HELP following trait defines a method `method2`, perhaps you need to implement it //~^^ HELP following trait defines an item `method2`, perhaps you need to implement it
//~^^^ HELP `foo::Bar` //~^^^ HELP `foo::Bar`
std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method2(); std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method2();
//~^ ERROR does not implement //~^ ERROR no method named
//~^^ HELP following trait defines a method `method2`, perhaps you need to implement it //~^^ HELP following trait defines an item `method2`, perhaps you need to implement it
//~^^^ HELP `foo::Bar` //~^^^ HELP `foo::Bar`
Foo.method3(); Foo.method3();
//~^ ERROR does not implement //~^ ERROR no method named
//~^^ HELP following trait defines a method `method3`, perhaps you need to implement it //~^^ HELP following trait defines an item `method3`, perhaps you need to implement it
//~^^^ HELP `no_method_suggested_traits::foo::PubPub` //~^^^ HELP `no_method_suggested_traits::foo::PubPub`
std::rc::Rc::new(&mut Box::new(&Foo)).method3(); std::rc::Rc::new(&mut Box::new(&Foo)).method3();
//~^ ERROR does not implement //~^ ERROR no method named
//~^^ HELP following trait defines a method `method3`, perhaps you need to implement it //~^^ HELP following trait defines an item `method3`, perhaps you need to implement it
//~^^^ HELP `no_method_suggested_traits::foo::PubPub` //~^^^ HELP `no_method_suggested_traits::foo::PubPub`
Bar::X.method3(); Bar::X.method3();
//~^ ERROR does not implement //~^ ERROR no method named
//~^^ HELP following trait defines a method `method3`, perhaps you need to implement it //~^^ HELP following trait defines an item `method3`, perhaps you need to implement it
//~^^^ HELP `no_method_suggested_traits::foo::PubPub` //~^^^ HELP `no_method_suggested_traits::foo::PubPub`
std::rc::Rc::new(&mut Box::new(&Bar::X)).method3(); std::rc::Rc::new(&mut Box::new(&Bar::X)).method3();
//~^ ERROR does not implement //~^ ERROR no method named
//~^^ HELP following trait defines a method `method3`, perhaps you need to implement it //~^^ HELP following trait defines an item `method3`, perhaps you need to implement it
//~^^^ HELP `no_method_suggested_traits::foo::PubPub` //~^^^ HELP `no_method_suggested_traits::foo::PubPub`
// should have no help: // should have no help:
1_usize.method3(); //~ ERROR does not implement 1_usize.method3(); //~ ERROR no method named
std::rc::Rc::new(&mut Box::new(&1_usize)).method3(); //~ ERROR does not implement std::rc::Rc::new(&mut Box::new(&1_usize)).method3(); //~ ERROR no method named
no_method_suggested_traits::Foo.method3(); //~ ERROR does not implement no_method_suggested_traits::Foo.method3(); //~ ERROR no method named
std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method3(); std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method3();
//~^ ERROR does not implement //~^ ERROR no method named
no_method_suggested_traits::Bar::X.method3(); //~ ERROR does not implement no_method_suggested_traits::Bar::X.method3(); //~ ERROR no method named
std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method3(); std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method3();
//~^ ERROR does not implement //~^ ERROR no method named
} }

View file

@ -15,6 +15,6 @@ fn main() {
let y : *const libc::c_void = x as *const libc::c_void; let y : *const libc::c_void = x as *const libc::c_void;
unsafe { unsafe {
let _z = (*y).clone(); let _z = (*y).clone();
//~^ ERROR does not implement any method in scope //~^ ERROR no method named `clone` found
} }
} }

View file

@ -41,6 +41,6 @@ fn foo(i:isize) -> foo {
fn main() { fn main() {
let x = foo(10); let x = foo(10);
let _y = x.clone(); //~ ERROR does not implement any method in scope let _y = x.clone(); //~ ERROR no method named `clone` found
println!("{:?}", x); println!("{:?}", x);
} }

View file

@ -19,19 +19,19 @@ trait Foo {
fn borrowed_receiver(x: &Foo) { fn borrowed_receiver(x: &Foo) {
x.borrowed(); x.borrowed();
x.borrowed_mut(); // See [1] x.borrowed_mut(); // See [1]
x.owned(); //~ ERROR does not implement any method x.owned(); //~ ERROR no method named `owned` found
} }
fn borrowed_mut_receiver(x: &mut Foo) { fn borrowed_mut_receiver(x: &mut Foo) {
x.borrowed(); x.borrowed();
x.borrowed_mut(); x.borrowed_mut();
x.owned(); //~ ERROR does not implement any method x.owned(); //~ ERROR no method named `owned` found
} }
fn owned_receiver(x: Box<Foo>) { fn owned_receiver(x: Box<Foo>) {
x.borrowed(); x.borrowed();
x.borrowed_mut(); // See [1] x.borrowed_mut(); // See [1]
x.managed(); //~ ERROR does not implement any method x.managed(); //~ ERROR no method named `managed` found
x.owned(); x.owned();
} }

View file

@ -22,5 +22,5 @@ impl T for i32 {}
fn main() { fn main() {
let x = &42i32; let x = &42i32;
x.foo(); //~ERROR: type `&i32` does not implement any method in scope named `foo` x.foo(); //~ERROR: no method named `foo` found for type `&i32` in the current scope
} }

View file

@ -14,5 +14,5 @@ fn to_fn_mut<A,F:FnMut<A>>(f: F) -> F { f }
fn main() { fn main() {
let mut_ = to_fn_mut(|x| x); let mut_ = to_fn_mut(|x| x);
mut_.call((0, )); //~ ERROR does not implement any method in scope named `call` mut_.call((0, )); //~ ERROR no method named `call` found
} }

View file

@ -31,5 +31,5 @@ impl Foo for Bar {
fn main() { fn main() {
let x = box Bar { x: 10 }; let x = box Bar { x: 10 };
let y: Box<Foo> = x as Box<Foo>; let y: Box<Foo> = x as Box<Foo>;
let _z = y.clone(); //~ ERROR does not implement any method in scope let _z = y.clone(); //~ ERROR no method named `clone` found
} }

View file

@ -20,6 +20,6 @@ impl Drop for r {
fn main() { fn main() {
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible. // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
let i = Box::new(r { b: true }); let i = Box::new(r { b: true });
let _j = i.clone(); //~ ERROR not implement let _j = i.clone(); //~ ERROR no method named `clone` found
println!("{:?}", i); println!("{:?}", i);
} }