Skip to content

Commit 93ab13b

Browse files
committed
Auto merge of #100245 - matthiaskrgr:rollup-tfoo650, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #100019 (Revive suggestions for boxed trait objects instead of impl Trait) - #100038 (Document the `no-std` target option in config.toml.example) - #100194 (Remove even more box syntax uses from src/test) - #100206 (test: skip terminfo parsing in Miri) - #100230 (Use start_point instead of next_point to point to elided lifetime amp…) - #100244 (Add armv4t-none-eabi take2) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents d394408 + 0f7fe9f commit 93ab13b

File tree

89 files changed

+555
-243
lines changed

Some content is hidden

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

89 files changed

+555
-243
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12281228
} else {
12291229
self.next_node_id()
12301230
};
1231-
let span = self.tcx.sess.source_map().next_point(t.span.shrink_to_lo());
1231+
let span = self.tcx.sess.source_map().start_point(t.span);
12321232
Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id }
12331233
});
12341234
let lifetime = self.lower_lifetime(&region);

compiler/rustc_resolve/src/late.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
629629
// Elided lifetime in reference: we resolve as if there was some lifetime `'_` with
630630
// NodeId `ty.id`.
631631
// This span will be used in case of elision failure.
632-
let span = self.r.session.source_map().next_point(ty.span.shrink_to_lo());
632+
let span = self.r.session.source_map().start_point(ty.span);
633633
self.resolve_elided_lifetime(ty.id, span);
634634
visit::walk_ty(self, ty);
635635
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//! Targets the ARMv4T, with code as `a32` code by default.
2+
//!
3+
//! Primarily of use for the GBA, but usable with other devices too.
4+
//!
5+
//! Please ping @Lokathor if changes are needed.
6+
//!
7+
//! This target profile assumes that you have the ARM binutils in your path
8+
//! (specifically the linker, `arm-none-eabi-ld`). They can be obtained for free
9+
//! for all major OSes from the ARM developer's website, and they may also be
10+
//! available in your system's package manager. Unfortunately, the standard
11+
//! linker that Rust uses (`lld`) only supports as far back as `ARMv5TE`, so we
12+
//! must use the GNU `ld` linker.
13+
//!
14+
//! **Important:** This target profile **does not** specify a linker script. You
15+
//! just get the default link script when you build a binary for this target.
16+
//! The default link script is very likely wrong, so you should use
17+
//! `-Clink-arg=-Tmy_script.ld` to override that with a correct linker script.
18+
19+
use crate::spec::{cvs, LinkerFlavor, PanicStrategy, RelocModel, Target, TargetOptions};
20+
21+
pub fn target() -> Target {
22+
Target {
23+
llvm_target: "armv4t-none-eabi".into(),
24+
pointer_width: 32,
25+
arch: "arm".into(),
26+
/* Data layout args are '-' separated:
27+
* little endian
28+
* stack is 64-bit aligned (EABI)
29+
* pointers are 32-bit
30+
* i64 must be 64-bit aligned (EABI)
31+
* mangle names with ELF style
32+
* native integers are 32-bit
33+
* All other elements are default
34+
*/
35+
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
36+
options: TargetOptions {
37+
abi: "eabi".into(),
38+
linker_flavor: LinkerFlavor::Ld,
39+
linker: Some("arm-none-eabi-ld".into()),
40+
asm_args: cvs!["-mthumb-interwork", "-march=armv4t", "-mlittle-endian",],
41+
features: "+soft-float,+strict-align".into(),
42+
main_needs_argc_argv: false,
43+
atomic_cas: false,
44+
has_thumb_interworking: true,
45+
relocation_model: RelocModel::Static,
46+
panic_strategy: PanicStrategy::Abort,
47+
// from thumb_base, rust-lang/rust#44993.
48+
emit_debug_gdb_scripts: false,
49+
// from thumb_base, apparently gcc/clang give enums a minimum of 8 bits on no-os targets
50+
c_enum_min_bits: 8,
51+
..Default::default()
52+
},
53+
}
54+
}

compiler/rustc_typeck/src/check/_match.rs

+35-28
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_errors::{Applicability, MultiSpan};
44
use rustc_hir::{self as hir, ExprKind};
55
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
66
use rustc_infer::traits::Obligation;
7-
use rustc_middle::ty::{self, ToPredicate, Ty, TypeVisitable};
7+
use rustc_middle::ty::{self, ToPredicate, Ty};
88
use rustc_span::Span;
99
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
1010
use rustc_trait_selection::traits::{
@@ -94,7 +94,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9494
let arm_ty = self.check_expr_with_expectation(&arm.body, expected);
9595
all_arms_diverge &= self.diverges.get();
9696

97-
let opt_suggest_box_span = self.opt_suggest_box_span(arm_ty, orig_expected);
97+
let opt_suggest_box_span = prior_arm.and_then(|(_, prior_arm_ty, _)| {
98+
self.opt_suggest_box_span(prior_arm_ty, arm_ty, orig_expected)
99+
});
98100

99101
let (arm_block_id, arm_span) = if let hir::ExprKind::Block(blk, _) = arm.body.kind {
100102
(Some(blk.hir_id), self.find_block_span(blk))
@@ -473,43 +475,48 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
473475
// provide a structured suggestion in that case.
474476
pub(crate) fn opt_suggest_box_span(
475477
&self,
476-
outer_ty: Ty<'tcx>,
478+
first_ty: Ty<'tcx>,
479+
second_ty: Ty<'tcx>,
477480
orig_expected: Expectation<'tcx>,
478481
) -> Option<Span> {
479482
match orig_expected {
480483
Expectation::ExpectHasType(expected)
481484
if self.in_tail_expr
482-
&& self.ret_coercion.as_ref()?.borrow().merged_ty().has_opaque_types()
483-
&& self.can_coerce(outer_ty, expected) =>
485+
&& self.return_type_has_opaque
486+
&& self.can_coerce(first_ty, expected)
487+
&& self.can_coerce(second_ty, expected) =>
484488
{
485489
let obligations = self.fulfillment_cx.borrow().pending_obligations();
486490
let mut suggest_box = !obligations.is_empty();
487-
for o in obligations {
488-
match o.predicate.kind().skip_binder() {
489-
ty::PredicateKind::Trait(t) => {
490-
let pred =
491-
ty::Binder::dummy(ty::PredicateKind::Trait(ty::TraitPredicate {
492-
trait_ref: ty::TraitRef {
493-
def_id: t.def_id(),
494-
substs: self.tcx.mk_substs_trait(outer_ty, &[]),
491+
'outer: for o in obligations {
492+
for outer_ty in &[first_ty, second_ty] {
493+
match o.predicate.kind().skip_binder() {
494+
ty::PredicateKind::Trait(t) => {
495+
let pred = ty::Binder::dummy(ty::PredicateKind::Trait(
496+
ty::TraitPredicate {
497+
trait_ref: ty::TraitRef {
498+
def_id: t.def_id(),
499+
substs: self.tcx.mk_substs_trait(*outer_ty, &[]),
500+
},
501+
constness: t.constness,
502+
polarity: t.polarity,
495503
},
496-
constness: t.constness,
497-
polarity: t.polarity,
498-
}));
499-
let obl = Obligation::new(
500-
o.cause.clone(),
501-
self.param_env,
502-
pred.to_predicate(self.tcx),
503-
);
504-
suggest_box &= self.predicate_must_hold_modulo_regions(&obl);
505-
if !suggest_box {
506-
// We've encountered some obligation that didn't hold, so the
507-
// return expression can't just be boxed. We don't need to
508-
// evaluate the rest of the obligations.
509-
break;
504+
));
505+
let obl = Obligation::new(
506+
o.cause.clone(),
507+
self.param_env,
508+
pred.to_predicate(self.tcx),
509+
);
510+
suggest_box &= self.predicate_must_hold_modulo_regions(&obl);
511+
if !suggest_box {
512+
// We've encountered some obligation that didn't hold, so the
513+
// return expression can't just be boxed. We don't need to
514+
// evaluate the rest of the obligations.
515+
break 'outer;
516+
}
510517
}
518+
_ => {}
511519
}
512-
_ => {}
513520
}
514521
}
515522
// If all the obligations hold (or there are no obligations) the tail expression

compiler/rustc_typeck/src/check/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10021002
let else_ty = self.check_expr_with_expectation(else_expr, expected);
10031003
let else_diverges = self.diverges.get();
10041004

1005-
let opt_suggest_box_span = self.opt_suggest_box_span(else_ty, orig_expected);
1005+
let opt_suggest_box_span = self.opt_suggest_box_span(then_ty, else_ty, orig_expected);
10061006
let if_cause = self.if_cause(
10071007
sp,
10081008
cond_expr.span,

config.toml.example

+4
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,10 @@ changelog-seen = 2
721721
# probably don't want to use this.
722722
#qemu-rootfs = <none> (path)
723723

724+
# Skip building the `std` library for this target. Enabled by default for
725+
# target triples containing `-none`, `nvptx`, `switch`, or `-uefi`.
726+
#no-std = <platform-specific> (bool)
727+
724728
# =============================================================================
725729
# Distribution options
726730
#

library/test/src/term/terminfo/mod.rs

+20
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ impl TermInfo {
8080

8181
/// Creates a TermInfo for the named terminal.
8282
pub(crate) fn from_name(name: &str) -> Result<TermInfo, Error> {
83+
if cfg!(miri) {
84+
// Avoid all the work of parsing the terminfo (it's pretty slow under Miri), and just
85+
// assume that the standard color codes work (like e.g. the 'colored' crate).
86+
return Ok(TermInfo {
87+
names: Default::default(),
88+
bools: Default::default(),
89+
numbers: Default::default(),
90+
strings: Default::default(),
91+
});
92+
}
93+
8394
get_dbpath_for_term(name)
8495
.ok_or_else(|| {
8596
Error::IoError(io::Error::new(io::ErrorKind::NotFound, "terminfo file not found"))
@@ -119,13 +130,22 @@ pub(crate) struct TerminfoTerminal<T> {
119130
impl<T: Write + Send> Terminal for TerminfoTerminal<T> {
120131
fn fg(&mut self, color: color::Color) -> io::Result<bool> {
121132
let color = self.dim_if_necessary(color);
133+
if cfg!(miri) && color < 8 {
134+
// The Miri logic for this only works for the most basic 8 colors, which we just assume
135+
// the terminal will support. (`num_colors` is always 0 in Miri, so higher colors will
136+
// just fail. But libtest doesn't use any higher colors anyway.)
137+
return write!(self.out, "\x1B[3{color}m").and(Ok(true));
138+
}
122139
if self.num_colors > color {
123140
return self.apply_cap("setaf", &[Param::Number(color as i32)]);
124141
}
125142
Ok(false)
126143
}
127144

128145
fn reset(&mut self) -> io::Result<bool> {
146+
if cfg!(miri) {
147+
return write!(self.out, "\x1B[0m").and(Ok(true));
148+
}
129149
// are there any terminals that have color/attrs and not sgr0?
130150
// Try falling back to sgr, then op
131151
let cmd = match ["sgr0", "sgr", "op"].iter().find_map(|cap| self.ti.strings.get(*cap)) {

src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- [aarch64-apple-ios-sim](platform-support/aarch64-apple-ios-sim.md)
1919
- [\*-apple-watchos\*](platform-support/apple-watchos.md)
2020
- [aarch64-nintendo-switch-freestanding](platform-support/aarch64-nintendo-switch-freestanding.md)
21+
- [armv4t-none-eabi](platform-support/armv4t-none-eabi.md)
2122
- [armv6k-nintendo-3ds](platform-support/armv6k-nintendo-3ds.md)
2223
- [armv7-unknown-linux-uclibceabi](platform-support/armv7-unknown-linux-uclibceabi.md)
2324
- [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# armv4t-none-eabi
2+
3+
Tier 3
4+
5+
Bare-metal target for any cpu in the ARMv4T architecture family, supporting
6+
ARM/Thumb code interworking (aka `a32`/`t32`), with ARM code as the default code
7+
generation.
8+
9+
In particular this supports the Gameboy Advance (GBA), but there's nothing GBA
10+
specific with this target, so any ARMv4T device should work fine.
11+
12+
## Target Maintainers
13+
14+
* [@Lokathor](https://github.com/lokathor)
15+
16+
## Requirements
17+
18+
The target is cross-compiled, and uses static linking.
19+
20+
The linker that comes with rustc cannot link for this platform (the platform is
21+
too old). You will need the `arm-none-eabi-ld` linker from a GNU Binutils
22+
targeting ARM. This can be obtained for Windows/Mac/Linux from the [ARM
23+
Developer Website][arm-dev], or possibly from your OS's package manager.
24+
25+
[arm-dev]: https://developer.arm.com/Tools%20and%20Software/GNU%20Toolchain
26+
27+
This target doesn't provide a linker script, you'll need to bring your own
28+
according to the specific device you want to target. Pass
29+
`-Clink-arg=-Tyour_script.ld` as a rustc argument to make the linker use
30+
`your_script.ld` during linking.
31+
32+
## Building Rust Programs
33+
34+
Because it is Tier 3, rust does not yet ship pre-compiled artifacts for this target.
35+
36+
Just use the `build-std` nightly cargo feature to build the `core` library. You
37+
can pass this as a command line argument to cargo, or your `.cargo/config.toml`
38+
file might include the following lines:
39+
40+
```toml
41+
[unstable]
42+
build-std = ["core"]
43+
```
44+
45+
Most of `core` should work as expected, with the following notes:
46+
* the target is "soft float", so `f32` and `f64` operations are emulated in
47+
software.
48+
* integer division is also emulated in software.
49+
* the target is old enough that it doesn't have atomic instructions.
50+
51+
Rust programs are output as ELF files.
52+
53+
For running on hardware, you'll generally need to extract the "raw" program code
54+
out of the ELF and into a file of its own. The `objcopy` program provided as
55+
part of the GNU Binutils can do this:
56+
57+
```shell
58+
arm-none-eabi-objcopy --output-target binary [in_file] [out_file]
59+
```
60+
61+
## Testing
62+
63+
This is a cross-compiled target that you will need to emulate during testing.
64+
65+
Because this is a device-agnostic target, and the exact emulator that you'll
66+
need depends on the specific device you want to run your code on.
67+
68+
For example, when programming for the Gameboy Advance, the
69+
[mgba-test-runner](https://github.com/agbrs/agb) program could be used to make a
70+
normal set of rust tests be run within the `mgba` emulator.

src/test/mir-opt/simplify-locals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// unit-test: SimplifyLocals
22

3-
#![feature(box_syntax)]
3+
44
#![feature(thread_local)]
55

66
#[derive(Copy, Clone)]

src/test/run-make-fulldeps/save-analysis-fail/foo.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![crate_name = "test"]
2-
#![feature(box_syntax)]
32
#![feature(rustc_private)]
43

54
extern crate rustc_graphviz;
@@ -261,9 +260,9 @@ fn hello<X: SomeTrait>((z, a): (u32, String), ex: X) {
261260
let x = 32.0f32;
262261
let _ = (x + ((x * x) + 1.0).sqrt()).ln();
263262

264-
let s: Box<SomeTrait> = box some_fields { field1: 43 };
265-
let s2: Box<some_fields> = box some_fields { field1: 43 };
266-
let s3 = box nofields;
263+
let s: Box<SomeTrait> = Box::new(some_fields { field1: 43 });
264+
let s2: Box<some_fields> = Box::new(some_fields { field1: 43 });
265+
let s3 = Box::new(nofields);
267266

268267
s.Method(43);
269268
s3.Method(43);
@@ -317,7 +316,7 @@ mod macro_use_test {
317316

318317
fn main() {
319318
// foo
320-
let s = box some_fields { field1: 43 };
319+
let s = Box::new(some_fields { field1: 43 });
321320
hello((43, "a".to_string()), *s);
322321
sub::sub2::hello();
323322
sub2::sub3::hello();
@@ -345,17 +344,17 @@ fn main() {
345344
let s4: msalias::nested_struct = sub::sub2::nested_struct { field2: 55 };
346345
let s4: msalias::nested_struct = sub2::nested_struct { field2: 55 };
347346
println(&s2.field1.to_string());
348-
let s5: MyType = box some_fields { field1: 55 };
347+
let s5: MyType = Box::new(some_fields { field1: 55 });
349348
let s = SameDir::SameStruct { name: "Bob".to_string() };
350349
let s = SubDir::SubStruct { name: "Bob".to_string() };
351-
let s6: SomeEnum = SomeEnum::MyTypes(box s2.clone(), s5);
350+
let s6: SomeEnum = SomeEnum::MyTypes(Box::new(s2.clone()), s5);
352351
let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
353352
matchSomeEnum(s6);
354353
matchSomeEnum(s7);
355354
let s8: SomeOtherEnum = SomeOtherEnum::SomeConst2;
356355
matchSomeOtherEnum(s8);
357356
let s9: SomeStructEnum =
358-
SomeStructEnum::EnumStruct2 { f1: box some_fields { field1: 10 }, f2: box s2 };
357+
SomeStructEnum::EnumStruct2 { f1: Box::new(some_fields { field1: 10 }), f2: Box::new(s2) };
359358
matchSomeStructEnum(s9);
360359

361360
for x in &vec![1, 2, 3] {

0 commit comments

Comments
 (0)