Skip to content

Commit

Permalink
Auto merge of rust-lang#100245 - matthiaskrgr:rollup-tfoo650, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#100019 (Revive suggestions for boxed trait objects instead of impl Trait)
 - rust-lang#100038 (Document the `no-std` target option in config.toml.example)
 - rust-lang#100194 (Remove even more box syntax uses from src/test)
 - rust-lang#100206 (test: skip terminfo parsing in Miri)
 - rust-lang#100230 (Use start_point instead of next_point to point to elided lifetime amp…)
 - rust-lang#100244 (Add armv4t-none-eabi take2)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Aug 7, 2022
2 parents d394408 + 0f7fe9f commit 93ab13b
Show file tree
Hide file tree
Showing 89 changed files with 555 additions and 243 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} else {
self.next_node_id()
};
let span = self.tcx.sess.source_map().next_point(t.span.shrink_to_lo());
let span = self.tcx.sess.source_map().start_point(t.span);
Lifetime { ident: Ident::new(kw::UnderscoreLifetime, span), id }
});
let lifetime = self.lower_lifetime(&region);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
// Elided lifetime in reference: we resolve as if there was some lifetime `'_` with
// NodeId `ty.id`.
// This span will be used in case of elision failure.
let span = self.r.session.source_map().next_point(ty.span.shrink_to_lo());
let span = self.r.session.source_map().start_point(ty.span);
self.resolve_elided_lifetime(ty.id, span);
visit::walk_ty(self, ty);
}
Expand Down
54 changes: 54 additions & 0 deletions compiler/rustc_target/src/spec/armv4t_none_eabi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//! Targets the ARMv4T, with code as `a32` code by default.
//!
//! Primarily of use for the GBA, but usable with other devices too.
//!
//! Please ping @Lokathor if changes are needed.
//!
//! This target profile assumes that you have the ARM binutils in your path
//! (specifically the linker, `arm-none-eabi-ld`). They can be obtained for free
//! for all major OSes from the ARM developer's website, and they may also be
//! available in your system's package manager. Unfortunately, the standard
//! linker that Rust uses (`lld`) only supports as far back as `ARMv5TE`, so we
//! must use the GNU `ld` linker.
//!
//! **Important:** This target profile **does not** specify a linker script. You
//! just get the default link script when you build a binary for this target.
//! The default link script is very likely wrong, so you should use
//! `-Clink-arg=-Tmy_script.ld` to override that with a correct linker script.
use crate::spec::{cvs, LinkerFlavor, PanicStrategy, RelocModel, Target, TargetOptions};

pub fn target() -> Target {
Target {
llvm_target: "armv4t-none-eabi".into(),
pointer_width: 32,
arch: "arm".into(),
/* Data layout args are '-' separated:
* little endian
* stack is 64-bit aligned (EABI)
* pointers are 32-bit
* i64 must be 64-bit aligned (EABI)
* mangle names with ELF style
* native integers are 32-bit
* All other elements are default
*/
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
options: TargetOptions {
abi: "eabi".into(),
linker_flavor: LinkerFlavor::Ld,
linker: Some("arm-none-eabi-ld".into()),
asm_args: cvs!["-mthumb-interwork", "-march=armv4t", "-mlittle-endian",],
features: "+soft-float,+strict-align".into(),
main_needs_argc_argv: false,
atomic_cas: false,
has_thumb_interworking: true,
relocation_model: RelocModel::Static,
panic_strategy: PanicStrategy::Abort,
// from thumb_base, rust-lang/rust#44993.
emit_debug_gdb_scripts: false,
// from thumb_base, apparently gcc/clang give enums a minimum of 8 bits on no-os targets
c_enum_min_bits: 8,
..Default::default()
},
}
}
63 changes: 35 additions & 28 deletions compiler/rustc_typeck/src/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_errors::{Applicability, MultiSpan};
use rustc_hir::{self as hir, ExprKind};
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_infer::traits::Obligation;
use rustc_middle::ty::{self, ToPredicate, Ty, TypeVisitable};
use rustc_middle::ty::{self, ToPredicate, Ty};
use rustc_span::Span;
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
use rustc_trait_selection::traits::{
Expand Down Expand Up @@ -94,7 +94,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let arm_ty = self.check_expr_with_expectation(&arm.body, expected);
all_arms_diverge &= self.diverges.get();

let opt_suggest_box_span = self.opt_suggest_box_span(arm_ty, orig_expected);
let opt_suggest_box_span = prior_arm.and_then(|(_, prior_arm_ty, _)| {
self.opt_suggest_box_span(prior_arm_ty, arm_ty, orig_expected)
});

let (arm_block_id, arm_span) = if let hir::ExprKind::Block(blk, _) = arm.body.kind {
(Some(blk.hir_id), self.find_block_span(blk))
Expand Down Expand Up @@ -473,43 +475,48 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// provide a structured suggestion in that case.
pub(crate) fn opt_suggest_box_span(
&self,
outer_ty: Ty<'tcx>,
first_ty: Ty<'tcx>,
second_ty: Ty<'tcx>,
orig_expected: Expectation<'tcx>,
) -> Option<Span> {
match orig_expected {
Expectation::ExpectHasType(expected)
if self.in_tail_expr
&& self.ret_coercion.as_ref()?.borrow().merged_ty().has_opaque_types()
&& self.can_coerce(outer_ty, expected) =>
&& self.return_type_has_opaque
&& self.can_coerce(first_ty, expected)
&& self.can_coerce(second_ty, expected) =>
{
let obligations = self.fulfillment_cx.borrow().pending_obligations();
let mut suggest_box = !obligations.is_empty();
for o in obligations {
match o.predicate.kind().skip_binder() {
ty::PredicateKind::Trait(t) => {
let pred =
ty::Binder::dummy(ty::PredicateKind::Trait(ty::TraitPredicate {
trait_ref: ty::TraitRef {
def_id: t.def_id(),
substs: self.tcx.mk_substs_trait(outer_ty, &[]),
'outer: for o in obligations {
for outer_ty in &[first_ty, second_ty] {
match o.predicate.kind().skip_binder() {
ty::PredicateKind::Trait(t) => {
let pred = ty::Binder::dummy(ty::PredicateKind::Trait(
ty::TraitPredicate {
trait_ref: ty::TraitRef {
def_id: t.def_id(),
substs: self.tcx.mk_substs_trait(*outer_ty, &[]),
},
constness: t.constness,
polarity: t.polarity,
},
constness: t.constness,
polarity: t.polarity,
}));
let obl = Obligation::new(
o.cause.clone(),
self.param_env,
pred.to_predicate(self.tcx),
);
suggest_box &= self.predicate_must_hold_modulo_regions(&obl);
if !suggest_box {
// We've encountered some obligation that didn't hold, so the
// return expression can't just be boxed. We don't need to
// evaluate the rest of the obligations.
break;
));
let obl = Obligation::new(
o.cause.clone(),
self.param_env,
pred.to_predicate(self.tcx),
);
suggest_box &= self.predicate_must_hold_modulo_regions(&obl);
if !suggest_box {
// We've encountered some obligation that didn't hold, so the
// return expression can't just be boxed. We don't need to
// evaluate the rest of the obligations.
break 'outer;
}
}
_ => {}
}
_ => {}
}
}
// If all the obligations hold (or there are no obligations) the tail expression
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let else_ty = self.check_expr_with_expectation(else_expr, expected);
let else_diverges = self.diverges.get();

let opt_suggest_box_span = self.opt_suggest_box_span(else_ty, orig_expected);
let opt_suggest_box_span = self.opt_suggest_box_span(then_ty, else_ty, orig_expected);
let if_cause = self.if_cause(
sp,
cond_expr.span,
Expand Down
4 changes: 4 additions & 0 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,10 @@ changelog-seen = 2
# probably don't want to use this.
#qemu-rootfs = <none> (path)

# Skip building the `std` library for this target. Enabled by default for
# target triples containing `-none`, `nvptx`, `switch`, or `-uefi`.
#no-std = <platform-specific> (bool)

# =============================================================================
# Distribution options
#
Expand Down
20 changes: 20 additions & 0 deletions library/test/src/term/terminfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ impl TermInfo {

/// Creates a TermInfo for the named terminal.
pub(crate) fn from_name(name: &str) -> Result<TermInfo, Error> {
if cfg!(miri) {
// Avoid all the work of parsing the terminfo (it's pretty slow under Miri), and just
// assume that the standard color codes work (like e.g. the 'colored' crate).
return Ok(TermInfo {
names: Default::default(),
bools: Default::default(),
numbers: Default::default(),
strings: Default::default(),
});
}

get_dbpath_for_term(name)
.ok_or_else(|| {
Error::IoError(io::Error::new(io::ErrorKind::NotFound, "terminfo file not found"))
Expand Down Expand Up @@ -119,13 +130,22 @@ pub(crate) struct TerminfoTerminal<T> {
impl<T: Write + Send> Terminal for TerminfoTerminal<T> {
fn fg(&mut self, color: color::Color) -> io::Result<bool> {
let color = self.dim_if_necessary(color);
if cfg!(miri) && color < 8 {
// The Miri logic for this only works for the most basic 8 colors, which we just assume
// the terminal will support. (`num_colors` is always 0 in Miri, so higher colors will
// just fail. But libtest doesn't use any higher colors anyway.)
return write!(self.out, "\x1B[3{color}m").and(Ok(true));
}
if self.num_colors > color {
return self.apply_cap("setaf", &[Param::Number(color as i32)]);
}
Ok(false)
}

fn reset(&mut self) -> io::Result<bool> {
if cfg!(miri) {
return write!(self.out, "\x1B[0m").and(Ok(true));
}
// are there any terminals that have color/attrs and not sgr0?
// Try falling back to sgr, then op
let cmd = match ["sgr0", "sgr", "op"].iter().find_map(|cap| self.ti.strings.get(*cap)) {
Expand Down
1 change: 1 addition & 0 deletions src/doc/rustc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [aarch64-apple-ios-sim](platform-support/aarch64-apple-ios-sim.md)
- [\*-apple-watchos\*](platform-support/apple-watchos.md)
- [aarch64-nintendo-switch-freestanding](platform-support/aarch64-nintendo-switch-freestanding.md)
- [armv4t-none-eabi](platform-support/armv4t-none-eabi.md)
- [armv6k-nintendo-3ds](platform-support/armv6k-nintendo-3ds.md)
- [armv7-unknown-linux-uclibceabi](platform-support/armv7-unknown-linux-uclibceabi.md)
- [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md)
Expand Down
70 changes: 70 additions & 0 deletions src/doc/rustc/src/platform-support/armv4t_none_eabi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# armv4t-none-eabi

Tier 3

Bare-metal target for any cpu in the ARMv4T architecture family, supporting
ARM/Thumb code interworking (aka `a32`/`t32`), with ARM code as the default code
generation.

In particular this supports the Gameboy Advance (GBA), but there's nothing GBA
specific with this target, so any ARMv4T device should work fine.

## Target Maintainers

* [@Lokathor](https://github.com/lokathor)

## Requirements

The target is cross-compiled, and uses static linking.

The linker that comes with rustc cannot link for this platform (the platform is
too old). You will need the `arm-none-eabi-ld` linker from a GNU Binutils
targeting ARM. This can be obtained for Windows/Mac/Linux from the [ARM
Developer Website][arm-dev], or possibly from your OS's package manager.

[arm-dev]: https://developer.arm.com/Tools%20and%20Software/GNU%20Toolchain

This target doesn't provide a linker script, you'll need to bring your own
according to the specific device you want to target. Pass
`-Clink-arg=-Tyour_script.ld` as a rustc argument to make the linker use
`your_script.ld` during linking.

## Building Rust Programs

Because it is Tier 3, rust does not yet ship pre-compiled artifacts for this target.

Just use the `build-std` nightly cargo feature to build the `core` library. You
can pass this as a command line argument to cargo, or your `.cargo/config.toml`
file might include the following lines:

```toml
[unstable]
build-std = ["core"]
```

Most of `core` should work as expected, with the following notes:
* the target is "soft float", so `f32` and `f64` operations are emulated in
software.
* integer division is also emulated in software.
* the target is old enough that it doesn't have atomic instructions.

Rust programs are output as ELF files.

For running on hardware, you'll generally need to extract the "raw" program code
out of the ELF and into a file of its own. The `objcopy` program provided as
part of the GNU Binutils can do this:

```shell
arm-none-eabi-objcopy --output-target binary [in_file] [out_file]
```

## Testing

This is a cross-compiled target that you will need to emulate during testing.

Because this is a device-agnostic target, and the exact emulator that you'll
need depends on the specific device you want to run your code on.

For example, when programming for the Gameboy Advance, the
[mgba-test-runner](https://github.com/agbrs/agb) program could be used to make a
normal set of rust tests be run within the `mgba` emulator.
2 changes: 1 addition & 1 deletion src/test/mir-opt/simplify-locals.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// unit-test: SimplifyLocals

#![feature(box_syntax)]

#![feature(thread_local)]

#[derive(Copy, Clone)]
Expand Down
15 changes: 7 additions & 8 deletions src/test/run-make-fulldeps/save-analysis-fail/foo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![crate_name = "test"]
#![feature(box_syntax)]
#![feature(rustc_private)]

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

let s: Box<SomeTrait> = box some_fields { field1: 43 };
let s2: Box<some_fields> = box some_fields { field1: 43 };
let s3 = box nofields;
let s: Box<SomeTrait> = Box::new(some_fields { field1: 43 });
let s2: Box<some_fields> = Box::new(some_fields { field1: 43 });
let s3 = Box::new(nofields);

s.Method(43);
s3.Method(43);
Expand Down Expand Up @@ -317,7 +316,7 @@ mod macro_use_test {

fn main() {
// foo
let s = box some_fields { field1: 43 };
let s = Box::new(some_fields { field1: 43 });
hello((43, "a".to_string()), *s);
sub::sub2::hello();
sub2::sub3::hello();
Expand Down Expand Up @@ -345,17 +344,17 @@ fn main() {
let s4: msalias::nested_struct = sub::sub2::nested_struct { field2: 55 };
let s4: msalias::nested_struct = sub2::nested_struct { field2: 55 };
println(&s2.field1.to_string());
let s5: MyType = box some_fields { field1: 55 };
let s5: MyType = Box::new(some_fields { field1: 55 });
let s = SameDir::SameStruct { name: "Bob".to_string() };
let s = SubDir::SubStruct { name: "Bob".to_string() };
let s6: SomeEnum = SomeEnum::MyTypes(box s2.clone(), s5);
let s6: SomeEnum = SomeEnum::MyTypes(Box::new(s2.clone()), s5);
let s7: SomeEnum = SomeEnum::Strings("one", "two", "three");
matchSomeEnum(s6);
matchSomeEnum(s7);
let s8: SomeOtherEnum = SomeOtherEnum::SomeConst2;
matchSomeOtherEnum(s8);
let s9: SomeStructEnum =
SomeStructEnum::EnumStruct2 { f1: box some_fields { field1: 10 }, f2: box s2 };
SomeStructEnum::EnumStruct2 { f1: Box::new(some_fields { field1: 10 }), f2: Box::new(s2) };
matchSomeStructEnum(s9);

for x in &vec![1, 2, 3] {
Expand Down
Loading

0 comments on commit 93ab13b

Please sign in to comment.