提交 aaeae4c7 编写于 作者: A Alex Burka

error for impl trait alias

上级 435fe5b7
...@@ -390,12 +390,18 @@ fn descr(self) -> &'static str { ...@@ -390,12 +390,18 @@ fn descr(self) -> &'static str {
} }
} }
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
enum AliasPossibility {
No,
Maybe,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)] #[derive(Copy, Clone, PartialEq, Eq, Debug)]
enum PathSource<'a> { enum PathSource<'a> {
// Type paths `Path`. // Type paths `Path`.
Type, Type,
// Trait paths in bounds or impls. // Trait paths in bounds or impls.
Trait, Trait(AliasPossibility),
// Expression paths `path`, with optional parent context. // Expression paths `path`, with optional parent context.
Expr(Option<&'a Expr>), Expr(Option<&'a Expr>),
// Paths in path patterns `Path`. // Paths in path patterns `Path`.
...@@ -415,7 +421,7 @@ enum PathSource<'a> { ...@@ -415,7 +421,7 @@ enum PathSource<'a> {
impl<'a> PathSource<'a> { impl<'a> PathSource<'a> {
fn namespace(self) -> Namespace { fn namespace(self) -> Namespace {
match self { match self {
PathSource::Type | PathSource::Trait | PathSource::Struct | PathSource::Type | PathSource::Trait(_) | PathSource::Struct |
PathSource::Visibility | PathSource::ImportPrefix => TypeNS, PathSource::Visibility | PathSource::ImportPrefix => TypeNS,
PathSource::Expr(..) | PathSource::Pat | PathSource::TupleStruct => ValueNS, PathSource::Expr(..) | PathSource::Pat | PathSource::TupleStruct => ValueNS,
PathSource::TraitItem(ns) => ns, PathSource::TraitItem(ns) => ns,
...@@ -427,7 +433,7 @@ fn global_by_default(self) -> bool { ...@@ -427,7 +433,7 @@ fn global_by_default(self) -> bool {
PathSource::Visibility | PathSource::ImportPrefix => true, PathSource::Visibility | PathSource::ImportPrefix => true,
PathSource::Type | PathSource::Expr(..) | PathSource::Pat | PathSource::Type | PathSource::Expr(..) | PathSource::Pat |
PathSource::Struct | PathSource::TupleStruct | PathSource::Struct | PathSource::TupleStruct |
PathSource::Trait | PathSource::TraitItem(..) => false, PathSource::Trait(_) | PathSource::TraitItem(..) => false,
} }
} }
...@@ -435,7 +441,7 @@ fn defer_to_typeck(self) -> bool { ...@@ -435,7 +441,7 @@ fn defer_to_typeck(self) -> bool {
match self { match self {
PathSource::Type | PathSource::Expr(..) | PathSource::Pat | PathSource::Type | PathSource::Expr(..) | PathSource::Pat |
PathSource::Struct | PathSource::TupleStruct => true, PathSource::Struct | PathSource::TupleStruct => true,
PathSource::Trait | PathSource::TraitItem(..) | PathSource::Trait(_) | PathSource::TraitItem(..) |
PathSource::Visibility | PathSource::ImportPrefix => false, PathSource::Visibility | PathSource::ImportPrefix => false,
} }
} }
...@@ -443,7 +449,7 @@ fn defer_to_typeck(self) -> bool { ...@@ -443,7 +449,7 @@ fn defer_to_typeck(self) -> bool {
fn descr_expected(self) -> &'static str { fn descr_expected(self) -> &'static str {
match self { match self {
PathSource::Type => "type", PathSource::Type => "type",
PathSource::Trait => "trait", PathSource::Trait(_) => "trait",
PathSource::Pat => "unit struct/variant or constant", PathSource::Pat => "unit struct/variant or constant",
PathSource::Struct => "struct, variant or union type", PathSource::Struct => "struct, variant or union type",
PathSource::TupleStruct => "tuple struct/variant", PathSource::TupleStruct => "tuple struct/variant",
...@@ -472,7 +478,11 @@ fn is_expected(self, def: Def) -> bool { ...@@ -472,7 +478,11 @@ fn is_expected(self, def: Def) -> bool {
Def::TyForeign(..) => true, Def::TyForeign(..) => true,
_ => false, _ => false,
}, },
PathSource::Trait => match def { PathSource::Trait(AliasPossibility::No) => match def {
Def::Trait(..) => true,
_ => false,
},
PathSource::Trait(AliasPossibility::Maybe) => match def {
Def::Trait(..) => true, Def::Trait(..) => true,
Def::TraitAlias(..) => true, Def::TraitAlias(..) => true,
_ => false, _ => false,
...@@ -531,8 +541,8 @@ fn error_code(self, has_unexpected_resolution: bool) -> &'static str { ...@@ -531,8 +541,8 @@ fn error_code(self, has_unexpected_resolution: bool) -> &'static str {
__diagnostic_used!(E0577); __diagnostic_used!(E0577);
__diagnostic_used!(E0578); __diagnostic_used!(E0578);
match (self, has_unexpected_resolution) { match (self, has_unexpected_resolution) {
(PathSource::Trait, true) => "E0404", (PathSource::Trait(_), true) => "E0404",
(PathSource::Trait, false) => "E0405", (PathSource::Trait(_), false) => "E0405",
(PathSource::Type, true) => "E0573", (PathSource::Type, true) => "E0573",
(PathSource::Type, false) => "E0412", (PathSource::Type, false) => "E0412",
(PathSource::Struct, true) => "E0574", (PathSource::Struct, true) => "E0574",
...@@ -694,7 +704,7 @@ fn visit_poly_trait_ref(&mut self, ...@@ -694,7 +704,7 @@ fn visit_poly_trait_ref(&mut self,
tref: &'tcx ast::PolyTraitRef, tref: &'tcx ast::PolyTraitRef,
m: &'tcx ast::TraitBoundModifier) { m: &'tcx ast::TraitBoundModifier) {
self.smart_resolve_path(tref.trait_ref.ref_id, None, self.smart_resolve_path(tref.trait_ref.ref_id, None,
&tref.trait_ref.path, PathSource::Trait); &tref.trait_ref.path, PathSource::Trait(AliasPossibility::Maybe));
visit::walk_poly_trait_ref(self, tref, m); visit::walk_poly_trait_ref(self, tref, m);
} }
fn visit_variant(&mut self, fn visit_variant(&mut self,
...@@ -2095,7 +2105,7 @@ fn with_optional_trait_ref<T, F>(&mut self, opt_trait_ref: Option<&TraitRef>, f: ...@@ -2095,7 +2105,7 @@ fn with_optional_trait_ref<T, F>(&mut self, opt_trait_ref: Option<&TraitRef>, f:
&path, &path,
trait_ref.path.span, trait_ref.path.span,
trait_ref.path.segments.last().unwrap().span, trait_ref.path.segments.last().unwrap().span,
PathSource::Trait) PathSource::Trait(AliasPossibility::No))
.base_def(); .base_def();
if def != Def::Err { if def != Def::Err {
new_id = Some(def.def_id()); new_id = Some(def.def_id());
...@@ -2647,7 +2657,7 @@ fn smart_resolve_path_fragment(&mut self, ...@@ -2647,7 +2657,7 @@ fn smart_resolve_path_fragment(&mut self,
err.span_label(span, format!("did you mean `{}!(...)`?", path_str)); err.span_label(span, format!("did you mean `{}!(...)`?", path_str));
return (err, candidates); return (err, candidates);
} }
(Def::TyAlias(..), PathSource::Trait) => { (Def::TyAlias(..), PathSource::Trait(_)) => {
err.span_label(span, "type aliases cannot be used for traits"); err.span_label(span, "type aliases cannot be used for traits");
return (err, candidates); return (err, candidates);
} }
......
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
//~^^^ERROR trait aliases are not yet fully implemented //~^^^ERROR trait aliases are not yet fully implemented
impl Alias1 { //~ERROR expected type, found trait alias impl Alias1 { //~ERROR expected type, found trait alias
fn foo() {} }
impl Alias1 for () { //~ERROR expected trait, found trait alias
} }
fn main() {} fn main() {}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册