Rollup merge of #139568 - nnethercote:empty-trait-name, r=compiler-errors
Don't use empty trait names Helps with #137978. Details in individual commits. r? ```@davidtwco```
This commit is contained in:
commit
7509b4652c
6 changed files with 31 additions and 57 deletions
|
@ -602,21 +602,13 @@ impl<'a> Parser<'a> {
|
||||||
let polarity = self.parse_polarity();
|
let polarity = self.parse_polarity();
|
||||||
|
|
||||||
// Parse both types and traits as a type, then reinterpret if necessary.
|
// Parse both types and traits as a type, then reinterpret if necessary.
|
||||||
let err_path = |span| ast::Path::from_ident(Ident::new(kw::Empty, span));
|
|
||||||
let ty_first = if self.token.is_keyword(kw::For) && self.look_ahead(1, |t| t != &token::Lt)
|
let ty_first = if self.token.is_keyword(kw::For) && self.look_ahead(1, |t| t != &token::Lt)
|
||||||
{
|
{
|
||||||
let span = self.prev_token.span.between(self.token.span);
|
let span = self.prev_token.span.between(self.token.span);
|
||||||
self.dcx().emit_err(errors::MissingTraitInTraitImpl {
|
return Err(self.dcx().create_err(errors::MissingTraitInTraitImpl {
|
||||||
span,
|
span,
|
||||||
for_span: span.to(self.token.span),
|
for_span: span.to(self.token.span),
|
||||||
});
|
}));
|
||||||
|
|
||||||
P(Ty {
|
|
||||||
kind: TyKind::Path(None, err_path(span)),
|
|
||||||
span,
|
|
||||||
id: DUMMY_NODE_ID,
|
|
||||||
tokens: None,
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
self.parse_ty_with_generics_recovery(&generics)?
|
self.parse_ty_with_generics_recovery(&generics)?
|
||||||
};
|
};
|
||||||
|
@ -657,6 +649,7 @@ impl<'a> Parser<'a> {
|
||||||
other => {
|
other => {
|
||||||
if let TyKind::ImplTrait(_, bounds) = other
|
if let TyKind::ImplTrait(_, bounds) = other
|
||||||
&& let [bound] = bounds.as_slice()
|
&& let [bound] = bounds.as_slice()
|
||||||
|
&& let GenericBound::Trait(poly_trait_ref) = bound
|
||||||
{
|
{
|
||||||
// Suggest removing extra `impl` keyword:
|
// Suggest removing extra `impl` keyword:
|
||||||
// `impl<T: Default> impl Default for Wrapper<T>`
|
// `impl<T: Default> impl Default for Wrapper<T>`
|
||||||
|
@ -666,12 +659,12 @@ impl<'a> Parser<'a> {
|
||||||
extra_impl_kw,
|
extra_impl_kw,
|
||||||
impl_trait_span: ty_first.span,
|
impl_trait_span: ty_first.span,
|
||||||
});
|
});
|
||||||
|
poly_trait_ref.trait_ref.path.clone()
|
||||||
} else {
|
} else {
|
||||||
self.dcx().emit_err(errors::ExpectedTraitInTraitImplFoundType {
|
return Err(self.dcx().create_err(
|
||||||
span: ty_first.span,
|
errors::ExpectedTraitInTraitImplFoundType { span: ty_first.span },
|
||||||
});
|
));
|
||||||
}
|
}
|
||||||
err_path(ty_first.span)
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let trait_ref = TraitRef { path, ref_id: ty_first.id };
|
let trait_ref = TraitRef { path, ref_id: ty_first.id };
|
||||||
|
|
|
@ -296,9 +296,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||||
) -> Option<LexicalScopeBinding<'ra>> {
|
) -> Option<LexicalScopeBinding<'ra>> {
|
||||||
assert!(ns == TypeNS || ns == ValueNS);
|
assert!(ns == TypeNS || ns == ValueNS);
|
||||||
let orig_ident = ident;
|
let orig_ident = ident;
|
||||||
if ident.name == kw::Empty {
|
|
||||||
return Some(LexicalScopeBinding::Res(Res::Err));
|
|
||||||
}
|
|
||||||
let (general_span, normalized_span) = if ident.name == kw::SelfUpper {
|
let (general_span, normalized_span) = if ident.name == kw::SelfUpper {
|
||||||
// FIXME(jseyfried) improve `Self` hygiene
|
// FIXME(jseyfried) improve `Self` hygiene
|
||||||
let empty_span = ident.span.with_ctxt(SyntaxContext::root());
|
let empty_span = ident.span.with_ctxt(SyntaxContext::root());
|
||||||
|
|
4
tests/ui/parser/impl-parsing-2.rs
Normal file
4
tests/ui/parser/impl-parsing-2.rs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
impl ! {} // OK
|
||||||
|
|
||||||
|
default unsafe FAIL //~ ERROR expected item, found keyword `unsafe`
|
||||||
|
//~^ ERROR `default` is not followed by an item
|
18
tests/ui/parser/impl-parsing-2.stderr
Normal file
18
tests/ui/parser/impl-parsing-2.stderr
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
error: `default` is not followed by an item
|
||||||
|
--> $DIR/impl-parsing-2.rs:3:1
|
||||||
|
|
|
||||||
|
LL | default unsafe FAIL
|
||||||
|
| ^^^^^^^ the `default` qualifier
|
||||||
|
|
|
||||||
|
= note: only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
|
||||||
|
|
||||||
|
error: expected item, found keyword `unsafe`
|
||||||
|
--> $DIR/impl-parsing-2.rs:3:9
|
||||||
|
|
|
||||||
|
LL | default unsafe FAIL
|
||||||
|
| ^^^^^^ expected item
|
||||||
|
|
|
||||||
|
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
|
@ -2,9 +2,4 @@ impl ! {} // OK
|
||||||
impl ! where u8: Copy {} // OK
|
impl ! where u8: Copy {} // OK
|
||||||
|
|
||||||
impl Trait Type {} //~ ERROR missing `for` in a trait impl
|
impl Trait Type {} //~ ERROR missing `for` in a trait impl
|
||||||
impl Trait .. {} //~ ERROR missing `for` in a trait impl
|
|
||||||
impl ?Sized for Type {} //~ ERROR expected a trait, found type
|
impl ?Sized for Type {} //~ ERROR expected a trait, found type
|
||||||
impl ?Sized for .. {} //~ ERROR expected a trait, found type
|
|
||||||
|
|
||||||
default unsafe FAIL //~ ERROR expected item, found keyword `unsafe`
|
|
||||||
//~^ ERROR `default` is not followed by an item
|
|
||||||
|
|
|
@ -9,44 +9,11 @@ help: add `for` here
|
||||||
LL | impl Trait for Type {}
|
LL | impl Trait for Type {}
|
||||||
| +++
|
| +++
|
||||||
|
|
||||||
error: missing `for` in a trait impl
|
|
||||||
--> $DIR/impl-parsing.rs:5:11
|
|
||||||
|
|
|
||||||
LL | impl Trait .. {}
|
|
||||||
| ^
|
|
||||||
|
|
|
||||||
help: add `for` here
|
|
||||||
|
|
|
||||||
LL | impl Trait for .. {}
|
|
||||||
| +++
|
|
||||||
|
|
||||||
error: expected a trait, found type
|
error: expected a trait, found type
|
||||||
--> $DIR/impl-parsing.rs:6:6
|
--> $DIR/impl-parsing.rs:5:6
|
||||||
|
|
|
|
||||||
LL | impl ?Sized for Type {}
|
LL | impl ?Sized for Type {}
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
||||||
error: expected a trait, found type
|
error: aborting due to 2 previous errors
|
||||||
--> $DIR/impl-parsing.rs:7:6
|
|
||||||
|
|
|
||||||
LL | impl ?Sized for .. {}
|
|
||||||
| ^^^^^^
|
|
||||||
|
|
||||||
error: `default` is not followed by an item
|
|
||||||
--> $DIR/impl-parsing.rs:9:1
|
|
||||||
|
|
|
||||||
LL | default unsafe FAIL
|
|
||||||
| ^^^^^^^ the `default` qualifier
|
|
||||||
|
|
|
||||||
= note: only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
|
|
||||||
|
|
||||||
error: expected item, found keyword `unsafe`
|
|
||||||
--> $DIR/impl-parsing.rs:9:9
|
|
||||||
|
|
|
||||||
LL | default unsafe FAIL
|
|
||||||
| ^^^^^^ expected item
|
|
||||||
|
|
|
||||||
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
|
|
||||||
|
|
||||||
error: aborting due to 6 previous errors
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue