Skip to content

Commit 7c44c27

Browse files
authored
Unrolled build for rust-lang#139568
Rollup merge of rust-lang#139568 - nnethercote:empty-trait-name, r=compiler-errors Don't use empty trait names Helps with rust-lang#137978. Details in individual commits. r? ```@davidtwco```
2 parents 7d7de5b + 7ae5c7f commit 7c44c27

File tree

6 files changed

+31
-57
lines changed

6 files changed

+31
-57
lines changed

compiler/rustc_parse/src/parser/item.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -602,21 +602,13 @@ impl<'a> Parser<'a> {
602602
let polarity = self.parse_polarity();
603603

604604
// Parse both types and traits as a type, then reinterpret if necessary.
605-
let err_path = |span| ast::Path::from_ident(Ident::new(kw::Empty, span));
606605
let ty_first = if self.token.is_keyword(kw::For) && self.look_ahead(1, |t| t != &token::Lt)
607606
{
608607
let span = self.prev_token.span.between(self.token.span);
609-
self.dcx().emit_err(errors::MissingTraitInTraitImpl {
608+
return Err(self.dcx().create_err(errors::MissingTraitInTraitImpl {
610609
span,
611610
for_span: span.to(self.token.span),
612-
});
613-
614-
P(Ty {
615-
kind: TyKind::Path(None, err_path(span)),
616-
span,
617-
id: DUMMY_NODE_ID,
618-
tokens: None,
619-
})
611+
}));
620612
} else {
621613
self.parse_ty_with_generics_recovery(&generics)?
622614
};
@@ -657,6 +649,7 @@ impl<'a> Parser<'a> {
657649
other => {
658650
if let TyKind::ImplTrait(_, bounds) = other
659651
&& let [bound] = bounds.as_slice()
652+
&& let GenericBound::Trait(poly_trait_ref) = bound
660653
{
661654
// Suggest removing extra `impl` keyword:
662655
// `impl<T: Default> impl Default for Wrapper<T>`
@@ -666,12 +659,12 @@ impl<'a> Parser<'a> {
666659
extra_impl_kw,
667660
impl_trait_span: ty_first.span,
668661
});
662+
poly_trait_ref.trait_ref.path.clone()
669663
} else {
670-
self.dcx().emit_err(errors::ExpectedTraitInTraitImplFoundType {
671-
span: ty_first.span,
672-
});
664+
return Err(self.dcx().create_err(
665+
errors::ExpectedTraitInTraitImplFoundType { span: ty_first.span },
666+
));
673667
}
674-
err_path(ty_first.span)
675668
}
676669
};
677670
let trait_ref = TraitRef { path, ref_id: ty_first.id };

compiler/rustc_resolve/src/ident.rs

-3
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
296296
) -> Option<LexicalScopeBinding<'ra>> {
297297
assert!(ns == TypeNS || ns == ValueNS);
298298
let orig_ident = ident;
299-
if ident.name == kw::Empty {
300-
return Some(LexicalScopeBinding::Res(Res::Err));
301-
}
302299
let (general_span, normalized_span) = if ident.name == kw::SelfUpper {
303300
// FIXME(jseyfried) improve `Self` hygiene
304301
let empty_span = ident.span.with_ctxt(SyntaxContext::root());

tests/ui/parser/impl-parsing-2.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
impl ! {} // OK
2+
3+
default unsafe FAIL //~ ERROR expected item, found keyword `unsafe`
4+
//~^ ERROR `default` is not followed by an item

tests/ui/parser/impl-parsing-2.stderr

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: `default` is not followed by an item
2+
--> $DIR/impl-parsing-2.rs:3:1
3+
|
4+
LL | default unsafe FAIL
5+
| ^^^^^^^ the `default` qualifier
6+
|
7+
= note: only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
8+
9+
error: expected item, found keyword `unsafe`
10+
--> $DIR/impl-parsing-2.rs:3:9
11+
|
12+
LL | default unsafe FAIL
13+
| ^^^^^^ expected item
14+
|
15+
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
16+
17+
error: aborting due to 2 previous errors
18+

tests/ui/parser/impl-parsing.rs

-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,4 @@ impl ! {} // OK
22
impl ! where u8: Copy {} // OK
33

44
impl Trait Type {} //~ ERROR missing `for` in a trait impl
5-
impl Trait .. {} //~ ERROR missing `for` in a trait impl
65
impl ?Sized for Type {} //~ ERROR expected a trait, found type
7-
impl ?Sized for .. {} //~ ERROR expected a trait, found type
8-
9-
default unsafe FAIL //~ ERROR expected item, found keyword `unsafe`
10-
//~^ ERROR `default` is not followed by an item

tests/ui/parser/impl-parsing.stderr

+2-35
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,11 @@ help: add `for` here
99
LL | impl Trait for Type {}
1010
| +++
1111

12-
error: missing `for` in a trait impl
13-
--> $DIR/impl-parsing.rs:5:11
14-
|
15-
LL | impl Trait .. {}
16-
| ^
17-
|
18-
help: add `for` here
19-
|
20-
LL | impl Trait for .. {}
21-
| +++
22-
2312
error: expected a trait, found type
24-
--> $DIR/impl-parsing.rs:6:6
13+
--> $DIR/impl-parsing.rs:5:6
2514
|
2615
LL | impl ?Sized for Type {}
2716
| ^^^^^^
2817

29-
error: expected a trait, found type
30-
--> $DIR/impl-parsing.rs:7:6
31-
|
32-
LL | impl ?Sized for .. {}
33-
| ^^^^^^
34-
35-
error: `default` is not followed by an item
36-
--> $DIR/impl-parsing.rs:9:1
37-
|
38-
LL | default unsafe FAIL
39-
| ^^^^^^^ the `default` qualifier
40-
|
41-
= note: only `fn`, `const`, `type`, or `impl` items may be prefixed by `default`
42-
43-
error: expected item, found keyword `unsafe`
44-
--> $DIR/impl-parsing.rs:9:9
45-
|
46-
LL | default unsafe FAIL
47-
| ^^^^^^ expected item
48-
|
49-
= note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>
50-
51-
error: aborting due to 6 previous errors
18+
error: aborting due to 2 previous errors
5219

0 commit comments

Comments
 (0)