Skip to content

Commit 8b4d852

Browse files
leoyvenspetrochenkov
authored andcommitted
Address review.
1 parent 4e3953b commit 8b4d852

File tree

6 files changed

+16
-75
lines changed

6 files changed

+16
-75
lines changed

src/librustc_passes/ast_validation.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,15 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
248248
// Auto traits cannot have generics, super traits nor contain items.
249249
if generics.is_parameterized() {
250250
struct_span_err!(self.session, item.span, E0567,
251-
"Auto traits cannot have generic parameters").emit();
251+
"auto traits cannot have generic parameters").emit();
252252
}
253253
if !bounds.is_empty() {
254254
struct_span_err!(self.session, item.span, E0568,
255-
"Auto traits cannot have predicates").emit();
255+
"auto traits cannot have super traits").emit();
256256
}
257257
if !trait_items.is_empty() {
258258
struct_span_err!(self.session, item.span, E0380,
259-
"Auto traits cannot have methods or associated items").emit();
259+
"auto traits cannot have methods or associated items").emit();
260260
}
261261
}
262262
self.no_questions_in_bounds(bounds, "supertraits", true);

src/librustc_passes/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ register_diagnostics! {
271271
E0226, // only a single explicit lifetime bound is permitted
272272
E0472, // asm! is unsupported on this target
273273
E0561, // patterns aren't allowed in function pointer types
274-
E0567, // auto traits can not have type parameters
275-
E0568, // auto traits can not have predicates
274+
E0567, // auto traits can not have generic parameters
275+
E0568, // auto traits can not have super traits
276276
E0642, // patterns aren't allowed in methods without bodies
277277
}

src/librustc_typeck/collect.rs

+1-52
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ fn trait_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
714714

715715
let (is_auto, unsafety) = match item.node {
716716
hir::ItemTrait(is_auto, unsafety, ..) => (is_auto == hir::IsAuto::Yes, unsafety),
717-
hir::ItemTraitAlias(..) => (hir::IsAuto::No, hir::Unsafety::Normal),
717+
hir::ItemTraitAlias(..) => (false, hir::Unsafety::Normal),
718718
_ => span_bug!(item.span, "trait_def_of_item invoked on non-trait"),
719719
};
720720

@@ -1714,54 +1714,3 @@ fn is_foreign_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
17141714
_ => bug!("is_foreign_item applied to non-local def-id {:?}", def_id)
17151715
}
17161716
}
1717-
1718-
struct ImplTraitUniversalInfo<'hir> {
1719-
id: ast::NodeId,
1720-
def_id: DefId,
1721-
span: Span,
1722-
bounds: &'hir [hir::TyParamBound],
1723-
}
1724-
1725-
/// Take some possible list of arguments and return the DefIds of the ImplTraitUniversal
1726-
/// arguments
1727-
fn extract_universal_impl_trait_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1728-
opt_inputs: Option<&'tcx [P<hir::Ty>]>)
1729-
-> Vec<ImplTraitUniversalInfo<'tcx>>
1730-
{
1731-
// A visitor for simply collecting Universally quantified impl Trait arguments
1732-
struct ImplTraitUniversalVisitor<'tcx> {
1733-
items: Vec<&'tcx hir::Ty>
1734-
}
1735-
1736-
impl<'tcx> Visitor<'tcx> for ImplTraitUniversalVisitor<'tcx> {
1737-
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
1738-
NestedVisitorMap::None
1739-
}
1740-
1741-
fn visit_ty(&mut self, ty: &'tcx hir::Ty) {
1742-
if let hir::TyImplTraitUniversal(..) = ty.node {
1743-
self.items.push(ty);
1744-
}
1745-
intravisit::walk_ty(self, ty);
1746-
}
1747-
}
1748-
1749-
let mut visitor = ImplTraitUniversalVisitor { items: Vec::new() };
1750-
1751-
if let Some(inputs) = opt_inputs {
1752-
for t in inputs.iter() {
1753-
visitor.visit_ty(t);
1754-
}
1755-
}
1756-
1757-
visitor.items.into_iter().map(|ty| if let hir::TyImplTraitUniversal(_, ref bounds) = ty.node {
1758-
ImplTraitUniversalInfo {
1759-
id: ty.id,
1760-
def_id: tcx.hir.local_def_id(ty.id),
1761-
span: ty.span,
1762-
bounds: bounds
1763-
}
1764-
} else {
1765-
span_bug!(ty.span, "this type should be a universally quantified impl trait. this is a bug")
1766-
}).collect()
1767-
}

src/libsyntax/parse/parser.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6370,8 +6370,8 @@ impl<'a> Parser<'a> {
63706370
let is_auto = if self.eat_keyword(keywords::Trait) {
63716371
IsAuto::No
63726372
} else {
6373-
self.eat_keyword(keywords::Auto);
6374-
self.eat_keyword(keywords::Trait);
6373+
self.expect_keyword(keywords::Auto)?;
6374+
self.expect_keyword(keywords::Trait)?;
63756375
IsAuto::Yes
63766376
};
63776377
let (ident, item_, extra_attrs) =
@@ -6485,8 +6485,8 @@ impl<'a> Parser<'a> {
64856485
let is_auto = if self.eat_keyword(keywords::Trait) {
64866486
IsAuto::No
64876487
} else {
6488-
self.eat_keyword(keywords::Auto);
6489-
self.eat_keyword(keywords::Trait);
6488+
self.expect_keyword(keywords::Auto)?;
6489+
self.expect_keyword(keywords::Trait)?;
64906490
IsAuto::Yes
64916491
};
64926492
// TRAIT ITEM

src/test/compile-fail/auto-trait-validation.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#![feature(optin_builtin_traits)]
1212

1313
auto trait Generic<T> {}
14-
//~^ Auto traits cannot have type parameters [E0567]
14+
//~^ auto traits cannot have generic parameters [E0567]
1515
auto trait Bound : Copy {}
16-
//~^ Auto traits cannot have predicates [E0568]
16+
//~^ auto traits cannot have super traits [E0568]
1717
auto trait MyTrait { fn foo() {} }
18-
//~^ Auto traits cannot have methods or associated items [E0380]
18+
//~^ auto traits cannot have methods or associated items [E0380]
1919
fn main() {}

src/test/ui/feature-gate-optin-builtin-traits.stderr

+3-11
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,13 @@ error: auto traits are experimental and possibly buggy (see issue #13231)
66
|
77
= help: add #![feature(optin_builtin_traits)] to the crate attributes to enable
88

9-
error: auto trait implementations are experimental and possibly buggy (see issue #13231)
10-
--> $DIR/feature-gate-optin-builtin-traits.rs:24:1
11-
|
12-
24 | impl DummyTrait for .. {}
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
14-
|
15-
= help: add #![feature(optin_builtin_traits)] to the crate attributes to enable
16-
179
error: negative trait bounds are not yet fully implemented; use marker types for now (see issue #13231)
18-
--> $DIR/feature-gate-optin-builtin-traits.rs:27:1
10+
--> $DIR/feature-gate-optin-builtin-traits.rs:23:1
1911
|
20-
27 | impl !DummyTrait for DummyStruct {}
12+
23 | impl !DummyTrait for DummyStruct {}
2113
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2214
|
2315
= help: add #![feature(optin_builtin_traits)] to the crate attributes to enable
2416

25-
error: aborting due to 3 previous errors
17+
error: aborting due to 2 previous errors
2618

0 commit comments

Comments
 (0)