Auto merge of #35145 - jseyfried:avoid_extra_resolve_error, r=arielb1
resolve: Avoid emitting an unhelpful cascading resolution error Fixes #35142.
This commit is contained in:
commit
32e462ef99
4 changed files with 26 additions and 40 deletions
|
@ -1807,39 +1807,25 @@ impl<'a> Resolver<'a> {
|
||||||
path_depth: usize)
|
path_depth: usize)
|
||||||
-> Result<PathResolution, ()> {
|
-> Result<PathResolution, ()> {
|
||||||
self.resolve_path(id, trait_path, path_depth, TypeNS).and_then(|path_res| {
|
self.resolve_path(id, trait_path, path_depth, TypeNS).and_then(|path_res| {
|
||||||
if let Def::Trait(_) = path_res.base_def {
|
match path_res.base_def {
|
||||||
debug!("(resolving trait) found trait def: {:?}", path_res);
|
Def::Trait(_) => {
|
||||||
Ok(path_res)
|
debug!("(resolving trait) found trait def: {:?}", path_res);
|
||||||
} else {
|
return Ok(path_res);
|
||||||
let mut err =
|
|
||||||
resolve_struct_error(self,
|
|
||||||
trait_path.span,
|
|
||||||
ResolutionError::IsNotATrait(&path_names_to_string(trait_path,
|
|
||||||
path_depth)));
|
|
||||||
|
|
||||||
// If it's a typedef, give a note
|
|
||||||
if let Def::TyAlias(..) = path_res.base_def {
|
|
||||||
let trait_name = trait_path.segments.last().unwrap().identifier.name;
|
|
||||||
err.span_label(trait_path.span,
|
|
||||||
&format!("`{}` is not a trait", trait_name));
|
|
||||||
|
|
||||||
let definition_site = {
|
|
||||||
let segments = &trait_path.segments;
|
|
||||||
if trait_path.global {
|
|
||||||
self.resolve_crate_relative_path(trait_path.span, segments, TypeNS)
|
|
||||||
} else {
|
|
||||||
self.resolve_module_relative_path(trait_path.span, segments, TypeNS)
|
|
||||||
}.map(|binding| binding.span).unwrap_or(syntax_pos::DUMMY_SP)
|
|
||||||
};
|
|
||||||
|
|
||||||
if definition_site != syntax_pos::DUMMY_SP {
|
|
||||||
err.span_label(definition_site,
|
|
||||||
&format!("type aliases cannot be used for traits"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
err.emit();
|
Def::Err => return Err(true),
|
||||||
Err(true)
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut err = resolve_struct_error(self, trait_path.span, {
|
||||||
|
ResolutionError::IsNotATrait(&path_names_to_string(trait_path, path_depth))
|
||||||
|
});
|
||||||
|
|
||||||
|
// If it's a typedef, give a note
|
||||||
|
if let Def::TyAlias(..) = path_res.base_def {
|
||||||
|
err.note(&format!("type aliases cannot be used for traits"));
|
||||||
|
}
|
||||||
|
err.emit();
|
||||||
|
Err(true)
|
||||||
}).map_err(|error_reported| {
|
}).map_err(|error_reported| {
|
||||||
if error_reported { return }
|
if error_reported { return }
|
||||||
|
|
||||||
|
|
|
@ -11,14 +11,14 @@
|
||||||
// aux-build:issue_3907.rs
|
// aux-build:issue_3907.rs
|
||||||
extern crate issue_3907;
|
extern crate issue_3907;
|
||||||
|
|
||||||
type Foo = issue_3907::Foo; //~ NOTE: type aliases cannot be used for traits
|
type Foo = issue_3907::Foo;
|
||||||
|
|
||||||
struct S {
|
struct S {
|
||||||
name: isize
|
name: isize
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Foo for S { //~ ERROR: `Foo` is not a trait
|
impl Foo for S { //~ ERROR: `Foo` is not a trait
|
||||||
//~| `Foo` is not a trait
|
//~| NOTE: type aliases cannot be used for traits
|
||||||
fn bar() { }
|
fn bar() { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,10 @@
|
||||||
|
|
||||||
trait I {}
|
trait I {}
|
||||||
type K = I;
|
type K = I;
|
||||||
//~^ NOTE: aliases cannot be used for traits
|
|
||||||
impl K for isize {} //~ ERROR: `K` is not a trait
|
impl K for isize {} //~ ERROR: `K` is not a trait
|
||||||
//~| is not a trait
|
//~| NOTE: aliases cannot be used for traits
|
||||||
|
|
||||||
|
use ImportError; //~ ERROR unresolved
|
||||||
|
impl ImportError for () {} // check that this is not an additional error (c.f. #35142)
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -2,12 +2,9 @@ error[E0404]: `Bar` is not a trait
|
||||||
--> $DIR/two_files.rs:16:6
|
--> $DIR/two_files.rs:16:6
|
||||||
|
|
|
|
||||||
16 | impl Bar for Baz { }
|
16 | impl Bar for Baz { }
|
||||||
| ^^^ `Bar` is not a trait
|
| ^^^
|
||||||
|
|
|
||||||
::: $DIR/two_files_data.rs
|
|
||||||
|
|
|
|
||||||
15 | type Bar = Foo;
|
= note: type aliases cannot be used for traits
|
||||||
| --------------- type aliases cannot be used for traits
|
|
||||||
|
|
||||||
error: cannot continue compilation due to previous error
|
error: cannot continue compilation due to previous error
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue