From b4bbf3a88dd965222c8e06ee113aa3a3730e3739 Mon Sep 17 00:00:00 2001 From: Sean Patrick Santos Date: Sat, 2 May 2015 23:30:59 -0600 Subject: [PATCH] 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. --- src/librustc_typeck/check/method/mod.rs | 73 +++++++++---------- src/librustc_typeck/check/method/probe.rs | 6 +- src/librustc_typeck/check/method/suggest.rs | 71 +++++++++--------- .../associated-const-ambiguity-report.rs | 33 +++++++++ .../compile-fail/auto-ref-slice-plus-ref.rs | 8 +- src/test/compile-fail/class-cast-to-trait.rs | 2 +- src/test/compile-fail/coherence_inherent.rs | 2 +- .../compile-fail/coherence_inherent_cc.rs | 2 +- src/test/compile-fail/copy-a-resource.rs | 2 +- src/test/compile-fail/issue-10465.rs | 2 +- src/test/compile-fail/issue-13853.rs | 2 +- src/test/compile-fail/issue-18343.rs | 2 +- src/test/compile-fail/issue-1871.rs | 2 +- src/test/compile-fail/issue-19521.rs | 2 +- src/test/compile-fail/issue-19692.rs | 2 +- src/test/compile-fail/issue-2149.rs | 2 +- src/test/compile-fail/issue-2823.rs | 2 +- src/test/compile-fail/issue-3563.rs | 2 +- src/test/compile-fail/issue-3702-2.rs | 2 +- src/test/compile-fail/issue-3707.rs | 2 +- src/test/compile-fail/issue-5153.rs | 3 +- src/test/compile-fail/issue-7575.rs | 6 +- src/test/compile-fail/issue-7950.rs | 2 +- .../macro-backtrace-invalid-internals.rs | 4 +- src/test/compile-fail/method-call-err-msg.rs | 2 +- .../method-suggestion-no-duplication.rs | 2 +- .../no-method-suggested-traits.rs | 72 +++++++++--------- src/test/compile-fail/non-copyable-void.rs | 2 +- src/test/compile-fail/noncopyable-class.rs | 2 +- src/test/compile-fail/object-pointer-types.rs | 6 +- src/test/compile-fail/trait-impl-1.rs | 2 +- ...nboxed-closures-static-call-wrong-trait.rs | 2 +- .../compile-fail/unique-object-noncopyable.rs | 2 +- src/test/compile-fail/unique-pinned-nocopy.rs | 2 +- 34 files changed, 182 insertions(+), 148 deletions(-) create mode 100644 src/test/compile-fail/associated-const-ambiguity-report.rs diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index fb2ad444005c3..90df0b853a083 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -16,12 +16,10 @@ use middle::def; use middle::privacy::{AllPublic, DependsOn, LastPrivate, LastMod}; use middle::subst; use middle::traits; -use middle::ty::*; -use middle::ty; +use middle::ty::{self, AsPredicate, ToPolyTraitRef}; use middle::infer; use util::ppaux::Repr; -use std::rc::Rc; use syntax::ast::DefId; use syntax::ast; use syntax::codemap::Span; @@ -39,7 +37,7 @@ pub enum MethodError { // Did not find an applicable method, but we did find various // static methods that may apply, as well as a list of // not-in-scope traits which may work. - NoMatch(Vec, Vec), + NoMatch(Vec, Vec, probe::Mode), // Multiple methods might apply. Ambiguity(Vec), @@ -62,7 +60,7 @@ type ItemIndex = usize; // just for doc purposes pub fn exists<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, span: Span, method_name: ast::Name, - self_ty: Ty<'tcx>, + self_ty: ty::Ty<'tcx>, call_expr_id: ast::NodeId) -> bool { @@ -92,11 +90,11 @@ pub fn exists<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, pub fn lookup<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, span: Span, method_name: ast::Name, - self_ty: Ty<'tcx>, - supplied_method_types: Vec>, + self_ty: ty::Ty<'tcx>, + supplied_method_types: Vec>, call_expr: &'tcx ast::Expr, self_expr: &'tcx ast::Expr) - -> Result, MethodError> + -> Result, MethodError> { debug!("lookup(method_name={}, self_ty={}, call_expr={}, self_expr={})", 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>, m_name: ast::Name, trait_def_id: DefId, - self_ty: Ty<'tcx>, - opt_input_types: Option>>) - -> Option> + self_ty: ty::Ty<'tcx>, + opt_input_types: Option>>) + -> Option> { lookup_in_trait_adjusted(fcx, span, self_expr, m_name, trait_def_id, 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, autoderefs: usize, unsize: bool, - self_ty: Ty<'tcx>, - opt_input_types: Option>>) - -> Option> + self_ty: ty::Ty<'tcx>, + opt_input_types: Option>>) + -> Option> { debug!("lookup_in_trait_adjusted(self_ty={}, self_expr={}, m_name={}, trait_def_id={})", 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 // type parameters or early-bound regions. 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.regions.len(subst::FnSpace), 0); @@ -288,10 +288,10 @@ pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, } } - let callee = MethodCallee { - origin: MethodTypeParam(MethodParam{trait_ref: trait_ref.clone(), - method_num: method_num, - impl_def_id: None}), + let callee = ty::MethodCallee { + origin: ty::MethodTypeParam(ty::MethodParam{trait_ref: trait_ref.clone(), + method_num: method_num, + impl_def_id: None}), ty: fty, 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>, span: Span, method_name: ast::Name, - self_ty: Ty<'tcx>, + self_ty: ty::Ty<'tcx>, expr_id: ast::NodeId) -> 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()) }; let def_result = match pick.item { - ImplOrTraitItem::MethodTraitItem(..) => def::DefMethod(def_id, provenance), - ImplOrTraitItem::ConstTraitItem(..) => def::DefAssociatedConst(def_id, provenance), - ImplOrTraitItem::TypeTraitItem(..) => { + ty::ImplOrTraitItem::MethodTraitItem(..) => def::DefMethod(def_id, provenance), + ty::ImplOrTraitItem::ConstTraitItem(..) => def::DefAssociatedConst(def_id, provenance), + ty::ImplOrTraitItem::TypeTraitItem(..) => { 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 -/// index (or `None`, if no such method). -fn trait_method<'tcx>(tcx: &ty::ctxt<'tcx>, - trait_def_id: ast::DefId, - method_name: ast::Name) - -> Option<(usize, Rc>)> +/// Find item with name `item_name` defined in `trait_def_id` and return it, along with its +/// index (or `None`, if no such item). +fn trait_item<'tcx>(tcx: &ty::ctxt<'tcx>, + trait_def_id: ast::DefId, + item_name: ast::Name) + -> Option<(usize, ty::ImplOrTraitItem<'tcx>)> { let trait_items = ty::trait_items(tcx, trait_def_id); trait_items .iter() .enumerate() - .find(|&(_, ref item)| item.name() == method_name) - .and_then(|(idx, item)| item.as_opt_method().map(|m| (idx, m))) + .find(|&(_, ref item)| item.name() == item_name) + .map(|(num, item)| (num, (*item).clone())) } -fn impl_method<'tcx>(tcx: &ty::ctxt<'tcx>, - impl_def_id: ast::DefId, - method_name: ast::Name) - -> Option>> +fn impl_item<'tcx>(tcx: &ty::ctxt<'tcx>, + impl_def_id: ast::DefId, + item_name: ast::Name) + -> Option> { let impl_items = tcx.impl_items.borrow(); let impl_items = impl_items.get(&impl_def_id).unwrap(); impl_items .iter() .map(|&did| ty::impl_or_trait_item(tcx, did.def_id())) - .find(|m| m.name() == method_name) - .and_then(|item| item.as_opt_method()) + .find(|m| m.name() == item_name) } diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 6171df218bb60..2eca855d5960b 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -136,7 +136,7 @@ pub fn probe<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, let steps = if mode == Mode::MethodCall { match create_steps(fcx, span, self_ty) { Some(steps) => steps, - None => return Err(MethodError::NoMatch(Vec::new(), Vec::new())), + None => return Err(MethodError::NoMatch(Vec::new(), Vec::new(), mode)), } } else { vec![CandidateStep { @@ -866,7 +866,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { } } }).collect(), - Some(Err(MethodError::NoMatch(_, others))) => { + Some(Err(MethodError::NoMatch(_, others, _))) => { assert!(others.is_empty()); vec![] } @@ -877,7 +877,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { 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> { diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 17658675ee280..93239df60e164 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // 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. use CrateCtxt; @@ -27,12 +27,13 @@ use syntax::print::pprust; use std::cell; 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>, span: Span, rcvr_ty: Ty<'tcx>, - method_name: ast::Name, + item_name: ast::Name, rcvr_expr: Option<&ast::Expr>, error: MethodError) { @@ -42,28 +43,30 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, } match error { - MethodError::NoMatch(static_sources, out_of_scope_traits) => { + MethodError::NoMatch(static_sources, out_of_scope_traits, mode) => { let cx = fcx.tcx(); - let method_ustring = method_name.user_string(cx); + let item_ustring = item_name.user_string(cx); fcx.type_error_message( span, |actual| { - format!("type `{}` does not implement any \ - method in scope named `{}`", - actual, - method_ustring) + format!("no {} named `{}` found for type `{}` \ + in the current scope", + if mode == Mode::MethodCall { "method" } + else { "associated item" }, + item_ustring, + actual) }, rcvr_ty, 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) { 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, &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, "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) } MethodError::Ambiguity(sources) => { 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) => { let msg = format!("the `{}` method from the `{}` trait cannot be explicitly \ invoked on this closure as we have not yet inferred what \ 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)); let msg = if let Some(callee) = rcvr_expr { 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, span: Span, - method_name: ast::Name, + item_name: ast::Name, mut sources: Vec) { sources.sort(); sources.dedup(); @@ -112,11 +115,11 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, for (idx, source) in sources.iter().enumerate() { match *source { CandidateSource::ImplSource(impl_did) => { - // Provide the best span we can. Use the method, if local to crate, else - // the impl, if local to crate (method may be defaulted), else the call site. - let method = impl_method(fcx.tcx(), impl_did, method_name).unwrap(); + // Provide the best span we can. Use the item, if local to crate, else + // the impl, if local to crate (item may be defaulted), else the call site. + let item = impl_item(fcx.tcx(), impl_did, item_name).unwrap(); 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; @@ -127,16 +130,16 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, 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 `{}`", idx + 1, insertion, impl_ty.user_string(fcx.tcx())); } CandidateSource::TraitSource(trait_did) => { - let (_, method) = trait_method(fcx.tcx(), trait_did, method_name).unwrap(); - let method_span = fcx.tcx().map.def_id_span(method.def_id, span); - span_note!(fcx.sess(), method_span, + let (_, item) = trait_item(fcx.tcx(), trait_did, item_name).unwrap(); + let item_span = fcx.tcx().map.def_id_span(item.def_id(), span); + span_note!(fcx.sess(), item_span, "candidate #{} is defined in the trait `{}`", idx + 1, ty::item_path_str(fcx.tcx(), trait_did)); @@ -152,19 +155,19 @@ pub type AllTraitsVec = Vec; fn suggest_traits_to_import<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, span: Span, rcvr_ty: Ty<'tcx>, - method_name: ast::Name, + item_name: ast::Name, rcvr_expr: Option<&ast::Expr>, valid_out_of_scope_traits: Vec) { 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() { let mut candidates = valid_out_of_scope_traits; candidates.sort(); candidates.dedup(); 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, \ perhaps add a `use` for {one_of_them}:", 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); // 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. let mut candidates = all_traits(fcx.ccx) .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 // here). (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::>(); @@ -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 // than implementing. let msg = format!( - "methods from traits can only be called if the trait is implemented and in scope; \ - the following {traits_define} a method `{name}`, \ + "items from traits can only be used if the trait is implemented and in scope; \ + the following {traits_define} an item `{name}`, \ perhaps you need to implement {one_of_them}:", traits_define = if candidates.len() == 1 {"trait defines"} else {"traits define"}, one_of_them = if candidates.len() == 1 {"it"} else {"one of them"}, - name = method_ustring); + name = item_ustring); fcx.sess().fileline_help(span, &msg[..]); diff --git a/src/test/compile-fail/associated-const-ambiguity-report.rs b/src/test/compile-fail/associated-const-ambiguity-report.rs new file mode 100644 index 0000000000000..22292a6da9dff --- /dev/null +++ b/src/test/compile-fail/associated-const-ambiguity-report.rs @@ -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 or the MIT license +// , 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 = ::ID; //~ ERROR E0034 + +fn main() { + assert_eq!(1, X); +} diff --git a/src/test/compile-fail/auto-ref-slice-plus-ref.rs b/src/test/compile-fail/auto-ref-slice-plus-ref.rs index ad3f467a45471..f0f0bdfb38ee3 100644 --- a/src/test/compile-fail/auto-ref-slice-plus-ref.rs +++ b/src/test/compile-fail/auto-ref-slice-plus-ref.rs @@ -15,11 +15,11 @@ fn main() { // vectors to slices then automatically create a self reference. let mut a = vec!(0); - a.test_mut(); //~ ERROR does not implement any method in scope named `test_mut` - a.test(); //~ ERROR does not implement any method in scope named `test` + a.test_mut(); //~ ERROR no method named `test_mut` found + a.test(); //~ ERROR no method named `test` found - ([1]).test(); //~ ERROR does not implement any method in scope named `test` - (&[1]).test(); //~ ERROR does not implement any method in scope named `test` + ([1]).test(); //~ ERROR no method named `test` found + (&[1]).test(); //~ ERROR no method named `test` found } trait MyIter { diff --git a/src/test/compile-fail/class-cast-to-trait.rs b/src/test/compile-fail/class-cast-to-trait.rs index 31e09e877c708..af83b0ecbf22c 100644 --- a/src/test/compile-fail/class-cast-to-trait.rs +++ b/src/test/compile-fail/class-cast-to-trait.rs @@ -60,5 +60,5 @@ fn cat(in_x : usize, in_y : isize, in_name: String) -> cat { fn main() { let nyan: Box = box cat(0, 2, "nyan".to_string()) as Box; - nyan.eat(); //~ ERROR does not implement any method in scope named `eat` + nyan.eat(); //~ ERROR no method named `eat` found } diff --git a/src/test/compile-fail/coherence_inherent.rs b/src/test/compile-fail/coherence_inherent.rs index 2c3fbc827aad6..087b8c14e3575 100644 --- a/src/test/compile-fail/coherence_inherent.rs +++ b/src/test/compile-fail/coherence_inherent.rs @@ -38,7 +38,7 @@ mod NoImport { use Lib::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 } } diff --git a/src/test/compile-fail/coherence_inherent_cc.rs b/src/test/compile-fail/coherence_inherent_cc.rs index 4eb9864bc9c59..442c4c89de4e1 100644 --- a/src/test/compile-fail/coherence_inherent_cc.rs +++ b/src/test/compile-fail/coherence_inherent_cc.rs @@ -30,7 +30,7 @@ mod NoImport { use coherence_inherent_cc_lib::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 } } diff --git a/src/test/compile-fail/copy-a-resource.rs b/src/test/compile-fail/copy-a-resource.rs index 98402591e728a..70633c92e6433 100644 --- a/src/test/compile-fail/copy-a-resource.rs +++ b/src/test/compile-fail/copy-a-resource.rs @@ -26,6 +26,6 @@ fn foo(i:isize) -> foo { fn main() { let x = foo(10); let _y = x.clone(); - //~^ ERROR does not implement any method in scope + //~^ ERROR no method named `clone` found println!("{:?}", x); } diff --git a/src/test/compile-fail/issue-10465.rs b/src/test/compile-fail/issue-10465.rs index a5e374a7a8b19..ed91e935407b9 100644 --- a/src/test/compile-fail/issue-10465.rs +++ b/src/test/compile-fail/issue-10465.rs @@ -24,7 +24,7 @@ pub mod b { use 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 } } diff --git a/src/test/compile-fail/issue-13853.rs b/src/test/compile-fail/issue-13853.rs index 251da2c6b3ee9..f5d158d64e19f 100644 --- a/src/test/compile-fail/issue-13853.rs +++ b/src/test/compile-fail/issue-13853.rs @@ -31,7 +31,7 @@ impl Node for Stuff { } fn iterate>(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 } } diff --git a/src/test/compile-fail/issue-18343.rs b/src/test/compile-fail/issue-18343.rs index f87a0d774fa7c..43e9ca5fa6e7a 100644 --- a/src/test/compile-fail/issue-18343.rs +++ b/src/test/compile-fail/issue-18343.rs @@ -14,6 +14,6 @@ struct Obj where F: FnMut() -> u32 { fn main() { 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 } diff --git a/src/test/compile-fail/issue-1871.rs b/src/test/compile-fail/issue-1871.rs index 423d87861cb68..e4d132c86415a 100644 --- a/src/test/compile-fail/issue-1871.rs +++ b/src/test/compile-fail/issue-1871.rs @@ -14,7 +14,7 @@ fn main() { let f = 42; 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 { () diff --git a/src/test/compile-fail/issue-19521.rs b/src/test/compile-fail/issue-19521.rs index 61cff598b2aee..58a95e9da2bf3 100644 --- a/src/test/compile-fail/issue-19521.rs +++ b/src/test/compile-fail/issue-19521.rs @@ -11,5 +11,5 @@ #![feature(unboxed_closures)] fn main() { - "".homura()(); //~ ERROR does not implement any method + "".homura()(); //~ ERROR no method named `homura` found } diff --git a/src/test/compile-fail/issue-19692.rs b/src/test/compile-fail/issue-19692.rs index 7b84ba0343a33..88ae0f835d0d7 100644 --- a/src/test/compile-fail/issue-19692.rs +++ b/src/test/compile-fail/issue-19692.rs @@ -11,7 +11,7 @@ struct 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 } diff --git a/src/test/compile-fail/issue-2149.rs b/src/test/compile-fail/issue-2149.rs index ea305c96af4a1..bb170ef7d0036 100644 --- a/src/test/compile-fail/issue-2149.rs +++ b/src/test/compile-fail/issue-2149.rs @@ -22,5 +22,5 @@ impl vec_monad for Vec { } fn main() { ["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 } diff --git a/src/test/compile-fail/issue-2823.rs b/src/test/compile-fail/issue-2823.rs index 1996cb737fc72..631bcb7bd9eb9 100644 --- a/src/test/compile-fail/issue-2823.rs +++ b/src/test/compile-fail/issue-2823.rs @@ -20,5 +20,5 @@ impl Drop for C { fn main() { 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 } diff --git a/src/test/compile-fail/issue-3563.rs b/src/test/compile-fail/issue-3563.rs index 0e1cc18dba910..29c1c584eed24 100644 --- a/src/test/compile-fail/issue-3563.rs +++ b/src/test/compile-fail/issue-3563.rs @@ -11,7 +11,7 @@ trait A { fn a(&self) { || 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 //~| expected `()` //~| found closure diff --git a/src/test/compile-fail/issue-3702-2.rs b/src/test/compile-fail/issue-3702-2.rs index 026ee89c0b2b5..325f05841f408 100644 --- a/src/test/compile-fail/issue-3702-2.rs +++ b/src/test/compile-fail/issue-3702-2.rs @@ -23,7 +23,7 @@ trait Add { impl Add for isize { fn to_int(&self) -> isize { *self } 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 } } diff --git a/src/test/compile-fail/issue-3707.rs b/src/test/compile-fail/issue-3707.rs index 0d57a8a50cc6a..ad56b125b087f 100644 --- a/src/test/compile-fail/issue-3707.rs +++ b/src/test/compile-fail/issue-3707.rs @@ -17,7 +17,7 @@ impl Obj { return 1+1 == 2 } 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 } } diff --git a/src/test/compile-fail/issue-5153.rs b/src/test/compile-fail/issue-5153.rs index c10c7cba45559..da32408e19924 100644 --- a/src/test/compile-fail/issue-5153.rs +++ b/src/test/compile-fail/issue-5153.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern: type `&Foo` does not implement any method in scope named `foo` - trait Foo { fn foo(self: Box); } @@ -20,4 +18,5 @@ impl Foo for isize { fn main() { (&5 as &Foo).foo(); + //~^ ERROR: no method named `foo` found for type `&Foo` in the current scope } diff --git a/src/test/compile-fail/issue-7575.rs b/src/test/compile-fail/issue-7575.rs index 6b320f400a809..6c7196527efdb 100644 --- a/src/test/compile-fail/issue-7575.rs +++ b/src/test/compile-fail/issue-7575.rs @@ -71,15 +71,15 @@ impl ManyImplTrait for Myisize {} fn no_param_bound(u: usize, m: Myisize) -> usize { 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? - //~^^^ 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? } fn param_bound(t: T) -> bool { 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? } diff --git a/src/test/compile-fail/issue-7950.rs b/src/test/compile-fail/issue-7950.rs index 01b90f5680f2c..003329a2d7de2 100644 --- a/src/test/compile-fail/issue-7950.rs +++ b/src/test/compile-fail/issue-7950.rs @@ -13,5 +13,5 @@ struct Foo; 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 } diff --git a/src/test/compile-fail/macro-backtrace-invalid-internals.rs b/src/test/compile-fail/macro-backtrace-invalid-internals.rs index df906d723566c..34aa1c75872f3 100644 --- a/src/test/compile-fail/macro-backtrace-invalid-internals.rs +++ b/src/test/compile-fail/macro-backtrace-invalid-internals.rs @@ -12,7 +12,7 @@ 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 () => { - 1.fake() //~ ERROR does not implement any method + 1.fake() //~ ERROR no method named `fake` found } } diff --git a/src/test/compile-fail/method-call-err-msg.rs b/src/test/compile-fail/method-call-err-msg.rs index 2f82441762f75..3434cf96fce94 100644 --- a/src/test/compile-fail/method-call-err-msg.rs +++ b/src/test/compile-fail/method-call-err-msg.rs @@ -25,6 +25,6 @@ fn main() { let y = Foo; 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); } diff --git a/src/test/compile-fail/method-suggestion-no-duplication.rs b/src/test/compile-fail/method-suggestion-no-duplication.rs index 1d0c4254eda2e..e6f3c8ab3170e 100644 --- a/src/test/compile-fail/method-suggestion-no-duplication.rs +++ b/src/test/compile-fail/method-suggestion-no-duplication.rs @@ -16,7 +16,7 @@ fn foo(f: F) where F: FnMut(Foo) {} fn main() { foo(|s| s.is_empty()); - //~^ ERROR does not implement any method + //~^ ERROR no method named `is_empty` found //~^^ HELP #1: `core::slice::SliceExt` //~^^^ HELP #2: `core::str::StrExt` } diff --git a/src/test/compile-fail/no-method-suggested-traits.rs b/src/test/compile-fail/no-method-suggested-traits.rs index 21f8a982806a9..08c848a09ab09 100644 --- a/src/test/compile-fail/no-method-suggested-traits.rs +++ b/src/test/compile-fail/no-method-suggested-traits.rs @@ -33,36 +33,36 @@ fn main() { 1u32.method(); //~^ 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 `no_method_suggested_traits::foo::PubPub` 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 - //~^^ ERROR does not implement + //~^^ ERROR no method named //~^^^ HELP `foo::Bar` //~^^^^ HELP `no_method_suggested_traits::foo::PubPub` '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 `foo::Bar` 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 `foo::Bar` 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 `no_method_suggested_traits::foo::PubPub` 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 `no_method_suggested_traits::foo::PubPub` Foo.method(); - //~^ ERROR does not implement - //~^^ HELP following traits define a method `method`, perhaps you need to implement one of them + //~^ ERROR no method named + //~^^ HELP following traits define an item `method`, perhaps you need to implement one of them //~^^^ HELP `foo::Bar` //~^^^^ HELP `no_method_suggested_traits::foo::PubPub` //~^^^^^ 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::quz::PrivPriv` std::rc::Rc::new(&mut Box::new(&Foo)).method(); - //~^ ERROR does not implement - //~^^ HELP following traits define a method `method`, perhaps you need to implement one of them + //~^ ERROR no method named + //~^^ HELP following traits define an item `method`, perhaps you need to implement one of them //~^^^ HELP `foo::Bar` //~^^^^ HELP `no_method_suggested_traits::foo::PubPub` //~^^^^^ HELP `no_method_suggested_traits::reexport::Reexported` @@ -80,55 +80,55 @@ fn main() { //~^^^^^^^^ HELP `no_method_suggested_traits::quz::PrivPriv` 1u64.method2(); - //~^ ERROR does not implement - //~^^ HELP the following trait defines a method `method2`, perhaps you need to implement it + //~^ ERROR no method named + //~^^ HELP the following trait defines an item `method2`, perhaps you need to implement it //~^^^ HELP `foo::Bar` std::rc::Rc::new(&mut Box::new(&1u64)).method2(); - //~^ ERROR does not implement - //~^^ HELP the following trait defines a method `method2`, perhaps you need to implement it + //~^ ERROR no method named + //~^^ HELP the following trait defines an item `method2`, perhaps you need to implement it //~^^^ HELP `foo::Bar` no_method_suggested_traits::Foo.method2(); - //~^ ERROR does not implement - //~^^ HELP following trait defines a method `method2`, perhaps you need to implement it + //~^ ERROR no method named + //~^^ HELP following trait defines an item `method2`, perhaps you need to implement it //~^^^ HELP `foo::Bar` std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method2(); - //~^ ERROR does not implement - //~^^ HELP following trait defines a method `method2`, perhaps you need to implement it + //~^ ERROR no method named + //~^^ HELP following trait defines an item `method2`, perhaps you need to implement it //~^^^ HELP `foo::Bar` no_method_suggested_traits::Bar::X.method2(); - //~^ ERROR does not implement - //~^^ HELP following trait defines a method `method2`, perhaps you need to implement it + //~^ ERROR no method named + //~^^ HELP following trait defines an item `method2`, perhaps you need to implement it //~^^^ HELP `foo::Bar` std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Bar::X)).method2(); - //~^ ERROR does not implement - //~^^ HELP following trait defines a method `method2`, perhaps you need to implement it + //~^ ERROR no method named + //~^^ HELP following trait defines an item `method2`, perhaps you need to implement it //~^^^ HELP `foo::Bar` Foo.method3(); - //~^ ERROR does not implement - //~^^ HELP following trait defines a method `method3`, perhaps you need to implement it + //~^ ERROR no method named + //~^^ HELP following trait defines an item `method3`, perhaps you need to implement it //~^^^ HELP `no_method_suggested_traits::foo::PubPub` std::rc::Rc::new(&mut Box::new(&Foo)).method3(); - //~^ ERROR does not implement - //~^^ HELP following trait defines a method `method3`, perhaps you need to implement it + //~^ ERROR no method named + //~^^ HELP following trait defines an item `method3`, perhaps you need to implement it //~^^^ HELP `no_method_suggested_traits::foo::PubPub` Bar::X.method3(); - //~^ ERROR does not implement - //~^^ HELP following trait defines a method `method3`, perhaps you need to implement it + //~^ ERROR no method named + //~^^ HELP following trait defines an item `method3`, perhaps you need to implement it //~^^^ HELP `no_method_suggested_traits::foo::PubPub` std::rc::Rc::new(&mut Box::new(&Bar::X)).method3(); - //~^ ERROR does not implement - //~^^ HELP following trait defines a method `method3`, perhaps you need to implement it + //~^ ERROR no method named + //~^^ HELP following trait defines an item `method3`, perhaps you need to implement it //~^^^ HELP `no_method_suggested_traits::foo::PubPub` // should have no help: - 1_usize.method3(); //~ ERROR does not implement - std::rc::Rc::new(&mut Box::new(&1_usize)).method3(); //~ ERROR does not implement - no_method_suggested_traits::Foo.method3(); //~ ERROR does not implement + 1_usize.method3(); //~ ERROR no method named + std::rc::Rc::new(&mut Box::new(&1_usize)).method3(); //~ ERROR no method named + no_method_suggested_traits::Foo.method3(); //~ ERROR no method named std::rc::Rc::new(&mut Box::new(&no_method_suggested_traits::Foo)).method3(); - //~^ ERROR does not implement - no_method_suggested_traits::Bar::X.method3(); //~ ERROR does not implement + //~^ ERROR no method named + 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(); - //~^ ERROR does not implement + //~^ ERROR no method named } diff --git a/src/test/compile-fail/non-copyable-void.rs b/src/test/compile-fail/non-copyable-void.rs index 40b641519b06d..fd245f38a0c92 100644 --- a/src/test/compile-fail/non-copyable-void.rs +++ b/src/test/compile-fail/non-copyable-void.rs @@ -15,6 +15,6 @@ fn main() { let y : *const libc::c_void = x as *const libc::c_void; unsafe { let _z = (*y).clone(); - //~^ ERROR does not implement any method in scope + //~^ ERROR no method named `clone` found } } diff --git a/src/test/compile-fail/noncopyable-class.rs b/src/test/compile-fail/noncopyable-class.rs index df135c3a8e309..f5712b0c957ba 100644 --- a/src/test/compile-fail/noncopyable-class.rs +++ b/src/test/compile-fail/noncopyable-class.rs @@ -41,6 +41,6 @@ fn foo(i:isize) -> foo { fn main() { 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); } diff --git a/src/test/compile-fail/object-pointer-types.rs b/src/test/compile-fail/object-pointer-types.rs index 84e7f98a40dc2..98c14cee942ed 100644 --- a/src/test/compile-fail/object-pointer-types.rs +++ b/src/test/compile-fail/object-pointer-types.rs @@ -19,19 +19,19 @@ trait Foo { fn borrowed_receiver(x: &Foo) { x.borrowed(); 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) { x.borrowed(); x.borrowed_mut(); - x.owned(); //~ ERROR does not implement any method + x.owned(); //~ ERROR no method named `owned` found } fn owned_receiver(x: Box) { x.borrowed(); x.borrowed_mut(); // See [1] - x.managed(); //~ ERROR does not implement any method + x.managed(); //~ ERROR no method named `managed` found x.owned(); } diff --git a/src/test/compile-fail/trait-impl-1.rs b/src/test/compile-fail/trait-impl-1.rs index dadcbd5bce710..e682d3c81e793 100644 --- a/src/test/compile-fail/trait-impl-1.rs +++ b/src/test/compile-fail/trait-impl-1.rs @@ -22,5 +22,5 @@ impl T for i32 {} fn main() { 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 } diff --git a/src/test/compile-fail/unboxed-closures-static-call-wrong-trait.rs b/src/test/compile-fail/unboxed-closures-static-call-wrong-trait.rs index 1a52e22419eb4..1c133fbfcdbbf 100644 --- a/src/test/compile-fail/unboxed-closures-static-call-wrong-trait.rs +++ b/src/test/compile-fail/unboxed-closures-static-call-wrong-trait.rs @@ -14,5 +14,5 @@ fn to_fn_mut>(f: F) -> F { f } fn main() { 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 } diff --git a/src/test/compile-fail/unique-object-noncopyable.rs b/src/test/compile-fail/unique-object-noncopyable.rs index 5074d00ca1587..c44718c4fc9c2 100644 --- a/src/test/compile-fail/unique-object-noncopyable.rs +++ b/src/test/compile-fail/unique-object-noncopyable.rs @@ -31,5 +31,5 @@ impl Foo for Bar { fn main() { let x = box Bar { x: 10 }; let y: Box = x as Box; - let _z = y.clone(); //~ ERROR does not implement any method in scope + let _z = y.clone(); //~ ERROR no method named `clone` found } diff --git a/src/test/compile-fail/unique-pinned-nocopy.rs b/src/test/compile-fail/unique-pinned-nocopy.rs index 2ec10d08bb41d..d971940db38f5 100644 --- a/src/test/compile-fail/unique-pinned-nocopy.rs +++ b/src/test/compile-fail/unique-pinned-nocopy.rs @@ -20,6 +20,6 @@ impl Drop for r { fn main() { // FIXME (#22405): Replace `Box::new` with `box` here when/if possible. 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); }