Skip to content

Commit

Permalink
Auto merge of #64868 - Centril:rollup-dheyb22, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 6 pull requests

Successful merges:

 - #64455 (Add Long error explanation for E0531)
 - #64546 (Bugfix/rfc 2451 rerebalance tests)
 - #64589 (Differentiate AArch64 bare-metal targets between hf and non-hf.)
 - #64763 (Add E0734 and its long explanation)
 - #64793 (Fix format macro expansions spans to be macro-generated)
 - #64799 (Fix double panic when printing query stack during an ICE)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Sep 28, 2019
2 parents f3c8eba + 7e1c5e0 commit 0773d8c
Show file tree
Hide file tree
Showing 58 changed files with 700 additions and 71 deletions.
17 changes: 17 additions & 0 deletions src/librustc/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,23 @@ Examples of erroneous code:
static X: u32 = 42;
```
"##,

E0734: r##"
A stability attribute has been used outside of the standard library.
Erroneous code examples:
```compile_fail,E0734
#[rustc_deprecated(since = "b", reason = "text")] // invalid
#[stable(feature = "a", since = "b")] // invalid
#[unstable(feature = "b", issue = "0")] // invalid
fn foo(){}
```
These attributes are meant to only be used by the standard library and are
rejected in your own crates.
"##,

;
// E0006, // merged with E0005
// E0101, // replaced with E0282
Expand Down
8 changes: 6 additions & 2 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,12 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
let name = attr.name_or_empty();
if [sym::unstable, sym::stable, sym::rustc_deprecated].contains(&name) {
attr::mark_used(attr);
self.tcx.sess.span_err(attr.span, "stability attributes may not be used \
outside of the standard library");
struct_span_err!(
self.tcx.sess,
attr.span,
E0734,
"stability attributes may not be used outside of the standard library",
).emit();
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/librustc/traits/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,15 @@ fn orphan_check_trait_ref<'tcx>(
// Let Ti be the first such type.
// - No uncovered type parameters P1..=Pn may appear in T0..Ti (excluding Ti)
//
for input_ty in trait_ref.input_types() {
fn uncover_fundamental_ty(ty: Ty<'_>) -> Vec<Ty<'_>> {
if fundamental_ty(ty) {
ty.walk_shallow().flat_map(|ty| uncover_fundamental_ty(ty)).collect()
} else {
vec![ty]
}
}

for input_ty in trait_ref.input_types().flat_map(uncover_fundamental_ty) {
debug!("orphan_check_trait_ref: check ty `{:?}`", input_ty);
if ty_is_local(tcx, input_ty, in_crate) {
debug!("orphan_check_trait_ref: ty_is_local `{:?}`", input_ty);
Expand Down
8 changes: 6 additions & 2 deletions src/librustc/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use errors::DiagnosticBuilder;
use errors::Level;
use errors::Diagnostic;
use errors::FatalError;
use errors::Handler;
use rustc_data_structures::fx::{FxHashMap};
use rustc_data_structures::sync::{Lrc, Lock};
use rustc_data_structures::sharded::Sharded;
Expand Down Expand Up @@ -321,9 +322,12 @@ impl<'tcx> TyCtxt<'tcx> {
})
}

pub fn try_print_query_stack() {
pub fn try_print_query_stack(handler: &Handler) {
eprintln!("query stack during panic:");

// Be careful reyling on global state here: this code is called from
// a panic hook, which means that the global `Handler` may be in a weird
// state if it was responsible for triggering the panic.
tls::with_context_opt(|icx| {
if let Some(icx) = icx {
let mut current_query = icx.query.clone();
Expand All @@ -336,7 +340,7 @@ impl<'tcx> TyCtxt<'tcx> {
query.info.query.name(),
query.info.query.describe(icx.tcx)));
diag.span = icx.tcx.sess.source_map().def_span(query.info.span).into();
icx.tcx.sess.diagnostic().force_print_diagnostic(diag);
handler.force_print_diagnostic(diag);

current_query = query.parent.clone();
i += 1;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
let backtrace = env::var_os("RUST_BACKTRACE").map(|x| &x != "0").unwrap_or(false);

if backtrace {
TyCtxt::try_print_query_stack();
TyCtxt::try_print_query_stack(&handler);
}

#[cfg(windows)]
Expand Down
46 changes: 45 additions & 1 deletion src/librustc_resolve/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,51 @@ match r {
```
"##,

E0531: r##"
An unknown tuple struct/variant has been used.
Erroneous code example:
```compile_fail,E0531
let Type(x) = Type(12); // error!
match Bar(12) {
Bar(x) => {} // error!
_ => {}
}
```
In most cases, it's either a forgotten import or a typo. However, let's look at
how you can have such a type:
```edition2018
struct Type(u32); // this is a tuple struct
enum Foo {
Bar(u32), // this is a tuple variant
}
use Foo::*; // To use Foo's variant directly, we need to import them in
// the scope.
```
Either way, it should work fine with our previous code:
```edition2018
struct Type(u32);
enum Foo {
Bar(u32),
}
use Foo::*;
let Type(x) = Type(12); // ok!
match Type(12) {
Type(x) => {} // ok!
_ => {}
}
```
"##,

E0532: r##"
Pattern arm did not match expected kind.
Expand Down Expand Up @@ -1675,7 +1720,6 @@ fn const_id<T, const N: T>() -> T { // error: const parameter
// E0419, merged into 531
// E0420, merged into 532
// E0421, merged into 531
E0531, // unresolved pattern path kind `name`
// E0427, merged into 530
// E0467, removed
// E0470, removed
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_target/spec/aarch64_unknown_none.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generic AArch64 target for bare-metal code
// Generic AArch64 target for bare-metal code - Floating point enabled
//
// Can be used in conjunction with the `target-feature` and
// `target-cpu` compiler flags to opt-in more hardware-specific
Expand All @@ -11,7 +11,7 @@ use super::{LldFlavor, LinkerFlavor, Target, TargetOptions, PanicStrategy};
pub fn target() -> Result<Target, String> {
let opts = TargetOptions {
linker: Some("rust-lld".to_owned()),
features: "+strict-align".to_string(),
features: "+strict-align,+neon,+fp-armv8".to_string(),
executables: true,
relocation_model: "static".to_string(),
disable_redzone: true,
Expand Down
37 changes: 37 additions & 0 deletions src/librustc_target/spec/aarch64_unknown_none_softfloat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Generic AArch64 target for bare-metal code - Floating point disabled
//
// Can be used in conjunction with the `target-feature` and
// `target-cpu` compiler flags to opt-in more hardware-specific
// features.
//
// For example, `-C target-cpu=cortex-a53`.

use super::{LldFlavor, LinkerFlavor, Target, TargetOptions, PanicStrategy};

pub fn target() -> Result<Target, String> {
let opts = TargetOptions {
linker: Some("rust-lld".to_owned()),
features: "+strict-align,-neon,-fp-armv8".to_string(),
executables: true,
relocation_model: "static".to_string(),
disable_redzone: true,
linker_is_gnu: true,
max_atomic_width: Some(128),
panic_strategy: PanicStrategy::Abort,
abi_blacklist: super::arm_base::abi_blacklist(),
.. Default::default()
};
Ok(Target {
llvm_target: "aarch64-unknown-none".to_string(),
target_endian: "little".to_string(),
target_pointer_width: "64".to_string(),
target_c_int_width: "32".to_string(),
target_os: "none".to_string(),
target_env: String::new(),
target_vendor: String::new(),
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
options: opts,
})
}
1 change: 1 addition & 0 deletions src/librustc_target/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ supported_targets! {
("riscv64gc-unknown-none-elf", riscv64gc_unknown_none_elf),

("aarch64-unknown-none", aarch64_unknown_none),
("aarch64-unknown-none-softfloat", aarch64_unknown_none_softfloat),

("x86_64-fortanix-unknown-sgx", x86_64_fortanix_unknown_sgx),

Expand Down
12 changes: 6 additions & 6 deletions src/libsyntax_ext/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ impl<'a, 'b> Context<'a, 'b> {
// Now create a vector containing all the arguments
let args = locals.into_iter().chain(counts.into_iter());

let args_array = self.ecx.expr_vec(self.fmtsp, args.collect());
let args_array = self.ecx.expr_vec(self.macsp, args.collect());

// Constructs an AST equivalent to:
//
Expand Down Expand Up @@ -724,12 +724,12 @@ impl<'a, 'b> Context<'a, 'b> {
//
// But the nested match expression is proved to perform not as well
// as series of let's; the first approach does.
let pat = self.ecx.pat_tuple(self.fmtsp, pats);
let arm = self.ecx.arm(self.fmtsp, pat, args_array);
let head = self.ecx.expr(self.fmtsp, ast::ExprKind::Tup(heads));
let result = self.ecx.expr_match(self.fmtsp, head, vec![arm]);
let pat = self.ecx.pat_tuple(self.macsp, pats);
let arm = self.ecx.arm(self.macsp, pat, args_array);
let head = self.ecx.expr(self.macsp, ast::ExprKind::Tup(heads));
let result = self.ecx.expr_match(self.macsp, head, vec![arm]);

let args_slice = self.ecx.expr_addr_of(self.fmtsp, result);
let args_slice = self.ecx.expr_addr_of(self.macsp, result);

// Now create the fmt::Arguments struct with all our locals we created.
let (fn_name, fn_args) = if self.all_pieces_simple {
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/coherence/auxiliary/coherence_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ pub trait Remote {
}

pub trait Remote1<T> {
fn foo(&self, t: T) { }
fn foo(&self, _t: T) { }
}

pub trait Remote2<T, U> {
fn foo(&self, t: T, u: U) { }
fn foo(&self, _t: T, _u: U) { }
}

pub struct Pair<T,U>(T,U);
17 changes: 17 additions & 0 deletions src/test/ui/coherence/impl-foreign[foreign]-for-foreign.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![feature(re_rebalance_coherence)]

// compile-flags:--crate-name=test
// aux-build:coherence_lib.rs

extern crate coherence_lib as lib;
use lib::*;
use std::rc::Rc;

struct Local;

impl Remote1<u32> for f64 {
//~^ ERROR only traits defined in the current crate
// | can be implemented for arbitrary types [E0117]
}

fn main() {}
12 changes: 12 additions & 0 deletions src/test/ui/coherence/impl-foreign[foreign]-for-foreign.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/impl-foreign[foreign]-for-foreign.rs:12:1
|
LL | impl Remote1<u32> for f64 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
|
= note: the impl does not reference only types defined in this crate
= note: define and implement a trait or new type instead

error: aborting due to previous error

For more information about this error, try `rustc --explain E0117`.
16 changes: 16 additions & 0 deletions src/test/ui/coherence/impl-foreign[foreign]-for-local.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![feature(re_rebalance_coherence)]

// compile-flags:--crate-name=test
// aux-build:coherence_lib.rs
// check-pass

extern crate coherence_lib as lib;
use lib::*;
use std::rc::Rc;

struct Local;

impl Remote1<u32> for Local {
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![feature(re_rebalance_coherence)]

// check-pass
// compile-flags:--crate-name=test
// aux-build:coherence_lib.rs

extern crate coherence_lib as lib;
use lib::*;
use std::rc::Rc;

struct Local;
impl<T> Remote2<Rc<T>, Local> for usize { }

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#![feature(re_rebalance_coherence)]

// compile-flags:--crate-name=test
// aux-build:coherence_lib.rs

extern crate coherence_lib as lib;
use lib::*;
use std::rc::Rc;

struct Local;

impl<T> Remote1<u32> for Box<T> {
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
}

impl<'a, T> Remote1<u32> for &'a T {
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
--> $DIR/impl[t]-foreign[foreign]-for-fundamental[t].rs:12:1
|
LL | impl<T> Remote1<u32> for Box<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
|
= note: only traits defined in the current crate can be implemented for a type parameter

error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
--> $DIR/impl[t]-foreign[foreign]-for-fundamental[t].rs:16:1
|
LL | impl<'a, T> Remote1<u32> for &'a T {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
|
= note: only traits defined in the current crate can be implemented for a type parameter

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0210`.
16 changes: 16 additions & 0 deletions src/test/ui/coherence/impl[t]-foreign[foreign]-for-t.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![feature(re_rebalance_coherence)]

// compile-flags:--crate-name=test
// aux-build:coherence_lib.rs

extern crate coherence_lib as lib;
use lib::*;
use std::rc::Rc;

struct Local;

impl<T> Remote1<u32> for T {
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
}

fn main() {}
11 changes: 11 additions & 0 deletions src/test/ui/coherence/impl[t]-foreign[foreign]-for-t.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
--> $DIR/impl[t]-foreign[foreign]-for-t.rs:12:1
|
LL | impl<T> Remote1<u32> for T {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
|
= note: only traits defined in the current crate can be implemented for a type parameter

error: aborting due to previous error

For more information about this error, try `rustc --explain E0210`.
Loading

0 comments on commit 0773d8c

Please sign in to comment.