Skip to content

Commit 0773d8c

Browse files
committed
Auto merge of #64868 - Centril:rollup-dheyb22, r=Centril
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
2 parents f3c8eba + 7e1c5e0 commit 0773d8c

File tree

58 files changed

+700
-71
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+700
-71
lines changed

src/librustc/error_codes.rs

+17
Original file line numberDiff line numberDiff line change
@@ -2217,6 +2217,23 @@ Examples of erroneous code:
22172217
static X: u32 = 42;
22182218
```
22192219
"##,
2220+
2221+
E0734: r##"
2222+
A stability attribute has been used outside of the standard library.
2223+
2224+
Erroneous code examples:
2225+
2226+
```compile_fail,E0734
2227+
#[rustc_deprecated(since = "b", reason = "text")] // invalid
2228+
#[stable(feature = "a", since = "b")] // invalid
2229+
#[unstable(feature = "b", issue = "0")] // invalid
2230+
fn foo(){}
2231+
```
2232+
2233+
These attributes are meant to only be used by the standard library and are
2234+
rejected in your own crates.
2235+
"##,
2236+
22202237
;
22212238
// E0006, // merged with E0005
22222239
// E0101, // replaced with E0282

src/librustc/middle/stability.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,12 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
199199
let name = attr.name_or_empty();
200200
if [sym::unstable, sym::stable, sym::rustc_deprecated].contains(&name) {
201201
attr::mark_used(attr);
202-
self.tcx.sess.span_err(attr.span, "stability attributes may not be used \
203-
outside of the standard library");
202+
struct_span_err!(
203+
self.tcx.sess,
204+
attr.span,
205+
E0734,
206+
"stability attributes may not be used outside of the standard library",
207+
).emit();
204208
}
205209
}
206210

src/librustc/traits/coherence.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,15 @@ fn orphan_check_trait_ref<'tcx>(
378378
// Let Ti be the first such type.
379379
// - No uncovered type parameters P1..=Pn may appear in T0..Ti (excluding Ti)
380380
//
381-
for input_ty in trait_ref.input_types() {
381+
fn uncover_fundamental_ty(ty: Ty<'_>) -> Vec<Ty<'_>> {
382+
if fundamental_ty(ty) {
383+
ty.walk_shallow().flat_map(|ty| uncover_fundamental_ty(ty)).collect()
384+
} else {
385+
vec![ty]
386+
}
387+
}
388+
389+
for input_ty in trait_ref.input_types().flat_map(uncover_fundamental_ty) {
382390
debug!("orphan_check_trait_ref: check ty `{:?}`", input_ty);
383391
if ty_is_local(tcx, input_ty, in_crate) {
384392
debug!("orphan_check_trait_ref: ty_is_local `{:?}`", input_ty);

src/librustc/ty/query/plumbing.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use errors::DiagnosticBuilder;
1515
use errors::Level;
1616
use errors::Diagnostic;
1717
use errors::FatalError;
18+
use errors::Handler;
1819
use rustc_data_structures::fx::{FxHashMap};
1920
use rustc_data_structures::sync::{Lrc, Lock};
2021
use rustc_data_structures::sharded::Sharded;
@@ -321,9 +322,12 @@ impl<'tcx> TyCtxt<'tcx> {
321322
})
322323
}
323324

324-
pub fn try_print_query_stack() {
325+
pub fn try_print_query_stack(handler: &Handler) {
325326
eprintln!("query stack during panic:");
326327

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

341345
current_query = query.parent.clone();
342346
i += 1;

src/librustc_driver/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
12311231
let backtrace = env::var_os("RUST_BACKTRACE").map(|x| &x != "0").unwrap_or(false);
12321232

12331233
if backtrace {
1234-
TyCtxt::try_print_query_stack();
1234+
TyCtxt::try_print_query_stack(&handler);
12351235
}
12361236

12371237
#[cfg(windows)]

src/librustc_resolve/error_codes.rs

+45-1
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,51 @@ match r {
15251525
```
15261526
"##,
15271527

1528+
E0531: r##"
1529+
An unknown tuple struct/variant has been used.
1530+
1531+
Erroneous code example:
1532+
1533+
```compile_fail,E0531
1534+
let Type(x) = Type(12); // error!
1535+
match Bar(12) {
1536+
Bar(x) => {} // error!
1537+
_ => {}
1538+
}
1539+
```
1540+
1541+
In most cases, it's either a forgotten import or a typo. However, let's look at
1542+
how you can have such a type:
1543+
1544+
```edition2018
1545+
struct Type(u32); // this is a tuple struct
1546+
1547+
enum Foo {
1548+
Bar(u32), // this is a tuple variant
1549+
}
1550+
1551+
use Foo::*; // To use Foo's variant directly, we need to import them in
1552+
// the scope.
1553+
```
1554+
1555+
Either way, it should work fine with our previous code:
1556+
1557+
```edition2018
1558+
struct Type(u32);
1559+
1560+
enum Foo {
1561+
Bar(u32),
1562+
}
1563+
use Foo::*;
1564+
1565+
let Type(x) = Type(12); // ok!
1566+
match Type(12) {
1567+
Type(x) => {} // ok!
1568+
_ => {}
1569+
}
1570+
```
1571+
"##,
1572+
15281573
E0532: r##"
15291574
Pattern arm did not match expected kind.
15301575
@@ -1675,7 +1720,6 @@ fn const_id<T, const N: T>() -> T { // error: const parameter
16751720
// E0419, merged into 531
16761721
// E0420, merged into 532
16771722
// E0421, merged into 531
1678-
E0531, // unresolved pattern path kind `name`
16791723
// E0427, merged into 530
16801724
// E0467, removed
16811725
// E0470, removed

src/librustc_target/spec/aarch64_unknown_none.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generic AArch64 target for bare-metal code
1+
// Generic AArch64 target for bare-metal code - Floating point enabled
22
//
33
// Can be used in conjunction with the `target-feature` and
44
// `target-cpu` compiler flags to opt-in more hardware-specific
@@ -11,7 +11,7 @@ use super::{LldFlavor, LinkerFlavor, Target, TargetOptions, PanicStrategy};
1111
pub fn target() -> Result<Target, String> {
1212
let opts = TargetOptions {
1313
linker: Some("rust-lld".to_owned()),
14-
features: "+strict-align".to_string(),
14+
features: "+strict-align,+neon,+fp-armv8".to_string(),
1515
executables: true,
1616
relocation_model: "static".to_string(),
1717
disable_redzone: true,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Generic AArch64 target for bare-metal code - Floating point disabled
2+
//
3+
// Can be used in conjunction with the `target-feature` and
4+
// `target-cpu` compiler flags to opt-in more hardware-specific
5+
// features.
6+
//
7+
// For example, `-C target-cpu=cortex-a53`.
8+
9+
use super::{LldFlavor, LinkerFlavor, Target, TargetOptions, PanicStrategy};
10+
11+
pub fn target() -> Result<Target, String> {
12+
let opts = TargetOptions {
13+
linker: Some("rust-lld".to_owned()),
14+
features: "+strict-align,-neon,-fp-armv8".to_string(),
15+
executables: true,
16+
relocation_model: "static".to_string(),
17+
disable_redzone: true,
18+
linker_is_gnu: true,
19+
max_atomic_width: Some(128),
20+
panic_strategy: PanicStrategy::Abort,
21+
abi_blacklist: super::arm_base::abi_blacklist(),
22+
.. Default::default()
23+
};
24+
Ok(Target {
25+
llvm_target: "aarch64-unknown-none".to_string(),
26+
target_endian: "little".to_string(),
27+
target_pointer_width: "64".to_string(),
28+
target_c_int_width: "32".to_string(),
29+
target_os: "none".to_string(),
30+
target_env: String::new(),
31+
target_vendor: String::new(),
32+
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
33+
arch: "aarch64".to_string(),
34+
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
35+
options: opts,
36+
})
37+
}

src/librustc_target/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ supported_targets! {
489489
("riscv64gc-unknown-none-elf", riscv64gc_unknown_none_elf),
490490

491491
("aarch64-unknown-none", aarch64_unknown_none),
492+
("aarch64-unknown-none-softfloat", aarch64_unknown_none_softfloat),
492493

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

src/libsyntax_ext/format.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ impl<'a, 'b> Context<'a, 'b> {
695695
// Now create a vector containing all the arguments
696696
let args = locals.into_iter().chain(counts.into_iter());
697697

698-
let args_array = self.ecx.expr_vec(self.fmtsp, args.collect());
698+
let args_array = self.ecx.expr_vec(self.macsp, args.collect());
699699

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

732-
let args_slice = self.ecx.expr_addr_of(self.fmtsp, result);
732+
let args_slice = self.ecx.expr_addr_of(self.macsp, result);
733733

734734
// Now create the fmt::Arguments struct with all our locals we created.
735735
let (fn_name, fn_args) = if self.all_pieces_simple {

src/test/ui/coherence/auxiliary/coherence_lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ pub trait Remote {
55
}
66

77
pub trait Remote1<T> {
8-
fn foo(&self, t: T) { }
8+
fn foo(&self, _t: T) { }
99
}
1010

1111
pub trait Remote2<T, U> {
12-
fn foo(&self, t: T, u: U) { }
12+
fn foo(&self, _t: T, _u: U) { }
1313
}
1414

1515
pub struct Pair<T,U>(T,U);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![feature(re_rebalance_coherence)]
2+
3+
// compile-flags:--crate-name=test
4+
// aux-build:coherence_lib.rs
5+
6+
extern crate coherence_lib as lib;
7+
use lib::*;
8+
use std::rc::Rc;
9+
10+
struct Local;
11+
12+
impl Remote1<u32> for f64 {
13+
//~^ ERROR only traits defined in the current crate
14+
// | can be implemented for arbitrary types [E0117]
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
2+
--> $DIR/impl-foreign[foreign]-for-foreign.rs:12:1
3+
|
4+
LL | impl Remote1<u32> for f64 {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
6+
|
7+
= note: the impl does not reference only types defined in this crate
8+
= note: define and implement a trait or new type instead
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0117`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![feature(re_rebalance_coherence)]
2+
3+
// compile-flags:--crate-name=test
4+
// aux-build:coherence_lib.rs
5+
// check-pass
6+
7+
extern crate coherence_lib as lib;
8+
use lib::*;
9+
use std::rc::Rc;
10+
11+
struct Local;
12+
13+
impl Remote1<u32> for Local {
14+
}
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![feature(re_rebalance_coherence)]
2+
3+
// check-pass
4+
// compile-flags:--crate-name=test
5+
// aux-build:coherence_lib.rs
6+
7+
extern crate coherence_lib as lib;
8+
use lib::*;
9+
use std::rc::Rc;
10+
11+
struct Local;
12+
impl<T> Remote2<Rc<T>, Local> for usize { }
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![feature(re_rebalance_coherence)]
2+
3+
// compile-flags:--crate-name=test
4+
// aux-build:coherence_lib.rs
5+
6+
extern crate coherence_lib as lib;
7+
use lib::*;
8+
use std::rc::Rc;
9+
10+
struct Local;
11+
12+
impl<T> Remote1<u32> for Box<T> {
13+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
14+
}
15+
16+
impl<'a, T> Remote1<u32> for &'a T {
17+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
18+
}
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
2+
--> $DIR/impl[t]-foreign[foreign]-for-fundamental[t].rs:12:1
3+
|
4+
LL | impl<T> Remote1<u32> for Box<T> {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
6+
|
7+
= note: only traits defined in the current crate can be implemented for a type parameter
8+
9+
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
10+
--> $DIR/impl[t]-foreign[foreign]-for-fundamental[t].rs:16:1
11+
|
12+
LL | impl<'a, T> Remote1<u32> for &'a T {
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
14+
|
15+
= note: only traits defined in the current crate can be implemented for a type parameter
16+
17+
error: aborting due to 2 previous errors
18+
19+
For more information about this error, try `rustc --explain E0210`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![feature(re_rebalance_coherence)]
2+
3+
// compile-flags:--crate-name=test
4+
// aux-build:coherence_lib.rs
5+
6+
extern crate coherence_lib as lib;
7+
use lib::*;
8+
use std::rc::Rc;
9+
10+
struct Local;
11+
12+
impl<T> Remote1<u32> for T {
13+
//~^ ERROR type parameter `T` must be used as the type parameter for some local type
14+
}
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
2+
--> $DIR/impl[t]-foreign[foreign]-for-t.rs:12:1
3+
|
4+
LL | impl<T> Remote1<u32> for T {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
6+
|
7+
= note: only traits defined in the current crate can be implemented for a type parameter
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0210`.

0 commit comments

Comments
 (0)