Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 5 pull requests #66446

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6a49b52
TAIT: remove `OpaqueTy` in AST.
Centril Nov 7, 2019
6d8e300
TAIT: feature gate recursive locations
Centril Nov 7, 2019
0e8e176
TAIT: parse recursively instead of hack.
Centril Nov 7, 2019
aa6a72f
TAIT: use hack in ->HIR to avoid more changes
Centril Nov 7, 2019
e31d75c
TAIT: remove redundant check from ast_validation
Centril Nov 7, 2019
89b5907
TAIT: adjust save-analysis
Centril Nov 7, 2019
75aaa85
TAIT: adjust resolve
Centril Nov 7, 2019
8b663ec
TAIT: --bless some span changes for the better
Centril Nov 7, 2019
03cf0d7
TAIT: adjust tests
Centril Nov 7, 2019
a7fffd2
Add --force-run-in-process unstable libtest option
tmandry Nov 14, 2019
ed9c5da
add a unit test for #62524
Nov 15, 2019
759c7e4
Correct `const_in_array_repeat_expressions` feature name
JohnTitor Nov 15, 2019
84070d8
Improve error message for tests with panic=abort
tmandry Nov 14, 2019
9d46208
Clean up E0023
GuillaumeGomez Nov 15, 2019
57564c8
Add link to error code explanation RFC
GuillaumeGomez Nov 15, 2019
88acc84
Clean up E0026
GuillaumeGomez Nov 15, 2019
8650628
Clean up E0027
GuillaumeGomez Nov 15, 2019
f8d575a
Clean up E0029
GuillaumeGomez Nov 15, 2019
cab1955
Clean up E0033
GuillaumeGomez Nov 15, 2019
a5fcc51
Clean up E0040
GuillaumeGomez Nov 15, 2019
11bb297
Clean up E0045
GuillaumeGomez Nov 15, 2019
2312207
Clean up E0049
GuillaumeGomez Nov 15, 2019
1a3c8c8
Clean up E0050
GuillaumeGomez Nov 15, 2019
041c9f6
Clean up E0054
GuillaumeGomez Nov 15, 2019
f9fdc38
Clean up E0025, E0034, E0044, E0046 and E0053
GuillaumeGomez Nov 15, 2019
721e62e
Rollup merge of #66197 - Centril:transparent-ast, r=varkor
Centril Nov 15, 2019
4760bb2
Rollup merge of #66415 - tmandry:force-test-in-process, r=alexcrichton
Centril Nov 15, 2019
0c04c8e
Rollup merge of #66429 - guanqun:add-unit-test, r=Centril
Centril Nov 15, 2019
511573e
Rollup merge of #66435 - JohnTitor:fix-spelling, r=Centril
Centril Nov 15, 2019
3294f41
Rollup merge of #66443 - GuillaumeGomez:port-erased-cleanup, r=Mark-S…
Centril Nov 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@ impl<'a> LoweringContext<'a> {
| ItemKind::Union(_, ref generics)
| ItemKind::Enum(_, ref generics)
| ItemKind::TyAlias(_, ref generics)
| ItemKind::OpaqueTy(_, ref generics)
| ItemKind::Trait(_, _, ref generics, ..) => {
let def_id = self.lctx.resolver.definitions().local_def_id(item.id);
let count = generics
Expand Down
62 changes: 35 additions & 27 deletions src/librustc/hir/lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,20 +337,22 @@ impl LoweringContext<'_> {
ItemKind::Mod(ref m) => hir::ItemKind::Mod(self.lower_mod(m)),
ItemKind::ForeignMod(ref nm) => hir::ItemKind::ForeignMod(self.lower_foreign_mod(nm)),
ItemKind::GlobalAsm(ref ga) => hir::ItemKind::GlobalAsm(self.lower_global_asm(ga)),
ItemKind::TyAlias(ref t, ref generics) => hir::ItemKind::TyAlias(
self.lower_ty(t, ImplTraitContext::disallowed()),
self.lower_generics(generics, ImplTraitContext::disallowed()),
),
ItemKind::OpaqueTy(ref b, ref generics) => hir::ItemKind::OpaqueTy(
hir::OpaqueTy {
generics: self.lower_generics(generics,
ImplTraitContext::OpaqueTy(None)),
bounds: self.lower_param_bounds(b,
ImplTraitContext::OpaqueTy(None)),
impl_trait_fn: None,
origin: hir::OpaqueTyOrigin::TypeAlias,
ItemKind::TyAlias(ref ty, ref generics) => match ty.kind.opaque_top_hack() {
None => {
let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
hir::ItemKind::TyAlias(ty, generics)
},
),
Some(bounds) => {
let ty = hir::OpaqueTy {
generics: self.lower_generics(generics, ImplTraitContext::OpaqueTy(None)),
bounds: self.lower_param_bounds(bounds, ImplTraitContext::OpaqueTy(None)),
impl_trait_fn: None,
origin: hir::OpaqueTyOrigin::TypeAlias,
};
hir::ItemKind::OpaqueTy(ty)
}
}
ItemKind::Enum(ref enum_definition, ref generics) => {
hir::ItemKind::Enum(
hir::EnumDef {
Expand Down Expand Up @@ -916,16 +918,20 @@ impl LoweringContext<'_> {

(generics, hir::ImplItemKind::Method(sig, body_id))
}
ImplItemKind::TyAlias(ref ty) => (
self.lower_generics(&i.generics, ImplTraitContext::disallowed()),
hir::ImplItemKind::TyAlias(self.lower_ty(ty, ImplTraitContext::disallowed())),
),
ImplItemKind::OpaqueTy(ref bounds) => (
self.lower_generics(&i.generics, ImplTraitContext::disallowed()),
hir::ImplItemKind::OpaqueTy(
self.lower_param_bounds(bounds, ImplTraitContext::disallowed()),
),
),
ImplItemKind::TyAlias(ref ty) => {
let generics = self.lower_generics(&i.generics, ImplTraitContext::disallowed());
let kind = match ty.kind.opaque_top_hack() {
None => {
let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
hir::ImplItemKind::TyAlias(ty)
}
Some(bs) => {
let bounds = self.lower_param_bounds(bs, ImplTraitContext::disallowed());
hir::ImplItemKind::OpaqueTy(bounds)
}
};
(generics, kind)
},
ImplItemKind::Macro(..) => bug!("`TyMac` should have been expanded by now"),
};

Expand All @@ -950,11 +956,13 @@ impl LoweringContext<'_> {
span: i.span,
vis: self.lower_visibility(&i.vis, Some(i.id)),
defaultness: self.lower_defaultness(i.defaultness, true /* [1] */),
kind: match i.kind {
kind: match &i.kind {
ImplItemKind::Const(..) => hir::AssocItemKind::Const,
ImplItemKind::TyAlias(..) => hir::AssocItemKind::Type,
ImplItemKind::OpaqueTy(..) => hir::AssocItemKind::OpaqueTy,
ImplItemKind::Method(ref sig, _) => hir::AssocItemKind::Method {
ImplItemKind::TyAlias(ty) => match ty.kind.opaque_top_hack() {
None => hir::AssocItemKind::Type,
Some(_) => hir::AssocItemKind::OpaqueTy,
},
ImplItemKind::Method(sig, _) => hir::AssocItemKind::Method {
has_self: sig.decl.has_self(),
},
ImplItemKind::Macro(..) => unimplemented!(),
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/hir/map/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
}
ItemKind::Mod(..) | ItemKind::Trait(..) | ItemKind::TraitAlias(..) |
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) |
ItemKind::OpaqueTy(..) | ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) |
ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) |
ItemKind::TyAlias(..) => DefPathData::TypeNs(i.ident.name),
ItemKind::Fn(sig, generics, body) if sig.header.asyncness.node.is_async() => {
return self.visit_async_fn(
Expand Down Expand Up @@ -239,8 +239,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
}
ImplItemKind::Method(..) |
ImplItemKind::Const(..) => DefPathData::ValueNs(ii.ident.name),
ImplItemKind::TyAlias(..) |
ImplItemKind::OpaqueTy(..) => DefPathData::TypeNs(ii.ident.name),
ImplItemKind::TyAlias(..) => DefPathData::TypeNs(ii.ident.name),
ImplItemKind::Macro(..) => return self.visit_macro_invoc(ii.id),
};

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2176,15 +2176,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
err.note(&format!("required by cast to type `{}`",
self.ty_to_string(target)));
}
ObligationCauseCode::RepeatVec(suggest_const_in_array_repeat_expression) => {
ObligationCauseCode::RepeatVec(suggest_const_in_array_repeat_expressions) => {
err.note("the `Copy` trait is required because the \
repeated element will be copied");
if suggest_const_in_array_repeat_expression {
if suggest_const_in_array_repeat_expressions {
err.note("this array initializer can be evaluated at compile-time, for more \
information, see issue \
https://github.com/rust-lang/rust/issues/49147");
if tcx.sess.opts.unstable_features.is_nightly_build() {
err.help("add `#![feature(const_in_array_repeat_expression)]` to the \
err.help("add `#![feature(const_in_array_repeat_expressions)]` to the \
crate attributes to enable");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ pub enum ObligationCauseCode<'tcx> {
SizedReturnType,
/// Yield type must be Sized
SizedYieldType,
/// [T,..n] --> T must be Copy. If `true`, suggest `const_in_array_repeat_expression` feature
/// [T,..n] --> T must be Copy. If `true`, suggest `const_in_array_repeat_expressions` feature
/// flag.
RepeatVec(bool),

Expand Down
5 changes: 5 additions & 0 deletions src/librustc_error_codes/error_codes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// Error messages for EXXXX errors. Each message should start and end with a
// new line, and be wrapped to 80 characters. In vim you can `:set tw=80` and
// use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
//
// /!\ IMPORTANT /!\
//
// Error messages' format must follow the RFC 1567 available here:
// https://github.com/rust-lang/rfcs/pull/1567

crate::register_diagnostics! {

Expand Down
9 changes: 6 additions & 3 deletions src/librustc_error_codes/error_codes/E0023.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
A pattern used to match against an enum variant must provide a sub-pattern for
each field of the enum variant. This error indicates that a pattern attempted to
extract an incorrect number of fields from a variant.
A pattern attempted to extract an incorrect number of fields from a variant.

Erroneous code example:

```
enum Fruit {
Expand All @@ -9,6 +9,9 @@ enum Fruit {
}
```

A pattern used to match against an enum variant must provide a sub-pattern for
each field of the enum variant.

Here the `Apple` variant has two fields, and should be matched against like so:

```
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_error_codes/error_codes/E0025.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Each field of a struct can only be bound once in a pattern. Erroneous code
example:
Each field of a struct can only be bound once in a pattern.

Erroneous code example:

```compile_fail,E0025
struct Foo {
Expand Down
37 changes: 10 additions & 27 deletions src/librustc_error_codes/error_codes/E0026.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,34 @@
This error indicates that a struct pattern attempted to extract a non-existent
field from a struct. Struct fields are identified by the name used before the
colon `:` so struct patterns should resemble the declaration of the struct type
being matched.
A struct pattern attempted to extract a non-existent field from a struct.

```
// Correct matching.
struct Thing {
x: u32,
y: u32
}

let thing = Thing { x: 1, y: 2 };

match thing {
Thing { x: xfield, y: yfield } => {}
}
```

If you are using shorthand field patterns but want to refer to the struct field
by a different name, you should rename it explicitly.

Change this:
Erroneous code example:

```compile_fail,E0026
struct Thing {
x: u32,
y: u32
y: u32,
}

let thing = Thing { x: 0, y: 0 };

match thing {
Thing { x, z } => {}
Thing { x, z } => {} // error: `Thing::z` field doesn't exist
}
```

To this:
If you are using shorthand field patterns but want to refer to the struct field
by a different name, you should rename it explicitly. Struct fields are
identified by the name used before the colon `:` so struct patterns should
resemble the declaration of the struct type being matched.

```
struct Thing {
x: u32,
y: u32
y: u32,
}

let thing = Thing { x: 0, y: 0 };

match thing {
Thing { x, y: z } => {}
Thing { x, y: z } => {} // we renamed `y` to `z`
}
```
10 changes: 5 additions & 5 deletions src/librustc_error_codes/error_codes/E0027.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
This error indicates that a pattern for a struct fails to specify a sub-pattern
for every one of the struct's fields. Ensure that each field from the struct's
definition is mentioned in the pattern, or use `..` to ignore unwanted fields.
A pattern for a struct fails to specify a sub-pattern for every one of the
struct's fields.

For example:
Erroneous code example:

```compile_fail,E0027
struct Dog {
Expand All @@ -18,7 +17,8 @@ match d {
}
```

This is correct (explicit):
To fix this error, ensure that each field from the struct's definition is
mentioned in the pattern, or use `..` to ignore unwanted fields. Example:

```
struct Dog {
Expand Down
14 changes: 9 additions & 5 deletions src/librustc_error_codes/error_codes/E0029.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
In a match expression, only numbers and characters can be matched against a
range. This is because the compiler checks that the range is non-empty at
compile-time, and is unable to evaluate arbitrary comparison functions. If you
want to capture values of an orderable type between two end-points, you can use
a guard.
Something other than numbers and characters has been used for a range.

Erroneous code example:

```compile_fail,E0029
let string = "salutations !";
Expand All @@ -20,3 +18,9 @@ match string {
_ => {}
}
```

In a match expression, only numbers and characters can be matched against a
range. This is because the compiler checks that the range is non-empty at
compile-time, and is unable to evaluate arbitrary comparison functions. If you
want to capture values of an orderable type between two end-points, you can use
a guard.
16 changes: 10 additions & 6 deletions src/librustc_error_codes/error_codes/E0033.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
This error indicates that a pointer to a trait type cannot be implicitly
dereferenced by a pattern. Every trait defines a type, but because the
size of trait implementers isn't fixed, this type has no compile-time size.
Therefore, all accesses to trait types must be through pointers. If you
encounter this error you should try to avoid dereferencing the pointer.
A trait type has been dereferenced.

Erroneous code example:

```compile_fail,E0033
# trait SomeTrait { fn method_one(&self){} fn method_two(&self){} }
Expand All @@ -17,7 +15,13 @@ trait_obj.method_one();
trait_obj.method_two();
```

A pointer to a trait type cannot be implicitly dereferenced by a pattern. Every
trait defines a type, but because the size of trait implementers isn't fixed,
this type has no compile-time size. Therefore, all accesses to trait types must
be through pointers. If you encounter this error you should try to avoid
dereferencing the pointer.

You can read more about trait objects in the [Trait Objects] section of the
Reference.

[Trait Objects]: https://doc.rust-lang.org/reference/types.html#trait-objects
[Trait Objects]: https://doc.rust-lang.org/reference/types.html#trait-objects
4 changes: 3 additions & 1 deletion src/librustc_error_codes/error_codes/E0034.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
The compiler doesn't know what method to call because more than one method
has the same prototype. Erroneous code example:
has the same prototype.

Erroneous code example:

```compile_fail,E0034
struct Test;
Expand Down
25 changes: 21 additions & 4 deletions src/librustc_error_codes/error_codes/E0040.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
It is not allowed to manually call destructors in Rust. It is also not
necessary to do this since `drop` is called automatically whenever a value goes
out of scope.
It is not allowed to manually call destructors in Rust.

Here's an example of this error:
Erroneous code example:

```compile_fail,E0040
struct Foo {
Expand All @@ -20,3 +18,22 @@ fn main() {
x.drop(); // error: explicit use of destructor method
}
```

It is unnecessary to do this since `drop` is called automatically whenever a
value goes out of scope. However, if you really need to drop a value by hand,
you can use the `std::mem::drop` function:

```
struct Foo {
x: i32,
}
impl Drop for Foo {
fn drop(&mut self) {
println!("kaboom");
}
}
fn main() {
let mut x = Foo { x: -7 };
drop(x); // ok!
}
```
1 change: 1 addition & 0 deletions src/librustc_error_codes/error_codes/E0044.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
You cannot use type or const parameters on foreign items.

Example of erroneous code:

```compile_fail,E0044
Expand Down
20 changes: 10 additions & 10 deletions src/librustc_error_codes/error_codes/E0045.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Rust only supports variadic parameters for interoperability with C code in its
FFI. As such, variadic parameters can only be used with functions which are
using the C ABI. Examples of erroneous code:

```compile_fail
#![feature(unboxed_closures)]
Variadic parameters have been used on a non-C ABI function.

extern "rust-call" { fn foo(x: u8, ...); }
Erroneous code example:

// or
```compile_fail,E0045
#![feature(unboxed_closures)]

fn foo(x: u8, ...) {}
extern "rust-call" {
fn foo(x: u8, ...); // error!
}
```

To fix such code, put them in an extern "C" block:
Rust only supports variadic parameters for interoperability with C code in its
FFI. As such, variadic parameters can only be used with functions which are
using the C ABI. To fix such code, put them in an extern "C" block:

```
extern "C" {
Expand Down
Loading