From 763bc13ccce4b81ec623d4e8c0a34f77d0401f0f Mon Sep 17 00:00:00 2001 From: Piotr Kubaj Date: Thu, 22 Jul 2021 17:29:33 +0200 Subject: Add support for powerpc-unknown-freebsd --- src/bootstrap/native.rs | 9 +++++++++ src/doc/rustc/src/platform-support.md | 1 + 2 files changed, 10 insertions(+) (limited to 'src') diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 1be414b29a1..b8a1513f2a6 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -118,6 +118,10 @@ impl Step for Llvm { let idx = target.triple.find('-').unwrap(); format!("riscv{}{}", &target.triple[5..7], &target.triple[idx..]) + } else if self.target.starts_with("powerpc") && self.target.ends_with("freebsd") { + // FreeBSD 13 had incompatible ABI changes on all PowerPC platforms. + // Set the version suffix to 13.0 so the correct target details are used. + format!("{}{}", self.target, "13.0") } else { target.to_string() }; @@ -277,6 +281,11 @@ impl Step for Llvm { } } + // Workaround for ppc32 lld limitation + if target == "powerpc-unknown-freebsd" { + cfg.define("CMAKE_EXE_LINKER_FLAGS", "-fuse-ld=bfd"); + } + // https://llvm.org/docs/HowToCrossCompileLLVM.html if target != builder.config.build { builder.ensure(Llvm { target: builder.config.build }); diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 885010b039e..90ef48798dd 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -249,6 +249,7 @@ target | std | host | notes `powerpc-wrs-vxworks` | ? | | `powerpc64-unknown-freebsd` | ✓ | ✓ | PPC64 FreeBSD (ELFv1 and ELFv2) `powerpc64le-unknown-freebsd` | | | PPC64LE FreeBSD +`powerpc-unknown-freebsd` | | | PowerPC FreeBSD `powerpc64-unknown-linux-musl` | ? | | `powerpc64-wrs-vxworks` | ? | | `powerpc64le-unknown-linux-musl` | ? | | -- cgit 1.4.1-3-g733a5 From d1bc9413858b334b6cdaf345bd6b50cb9aa4cec2 Mon Sep 17 00:00:00 2001 From: Giacomo Stevanato Date: Wed, 21 Jul 2021 14:42:32 +0200 Subject: Add regression test --- src/test/ui/associated-types/issue-87261.rs | 99 ++++++++++ src/test/ui/associated-types/issue-87261.stderr | 238 ++++++++++++++++++++++++ 2 files changed, 337 insertions(+) create mode 100644 src/test/ui/associated-types/issue-87261.rs create mode 100644 src/test/ui/associated-types/issue-87261.stderr (limited to 'src') diff --git a/src/test/ui/associated-types/issue-87261.rs b/src/test/ui/associated-types/issue-87261.rs new file mode 100644 index 00000000000..a70f771e482 --- /dev/null +++ b/src/test/ui/associated-types/issue-87261.rs @@ -0,0 +1,99 @@ +trait Foo {} + +trait Trait { + type Associated; +} +trait DerivedTrait: Trait {} +trait GenericTrait { + type Associated; +} + +struct Impl; +impl Foo for Impl {} +impl Trait for Impl { + type Associated = (); +} +impl DerivedTrait for Impl {} +impl GenericTrait for Impl { + type Associated = (); +} + +fn returns_opaque() -> impl Trait + 'static { + Impl +} +fn returns_opaque_derived() -> impl DerivedTrait + 'static { + Impl +} +fn returns_opaque_foo() -> impl Trait + Foo { + Impl +} +fn returns_opaque_derived_foo() -> impl DerivedTrait + Foo { + Impl +} +fn returns_opaque_generic() -> impl GenericTrait<()> + 'static { + Impl +} +fn returns_opaque_generic_foo() -> impl GenericTrait<()> + Foo { + Impl +} +fn returns_opaque_generic_duplicate() -> impl GenericTrait<()> + GenericTrait { + Impl +} + +fn accepts_trait>(_: T) {} +fn accepts_generic_trait>(_: T) {} + +fn check_generics(a: A, b: B, c: C, d: D, e: E, f: F, g: G) +where + A: Trait + 'static, + B: DerivedTrait + 'static, + C: Trait + Foo, + D: DerivedTrait + Foo, + E: GenericTrait<()> + 'static, + F: GenericTrait<()> + Foo, + G: GenericTrait<()> + GenericTrait, +{ + accepts_trait(a); + //~^ ERROR type mismatch resolving `::Associated == ()` + + accepts_trait(b); + //~^ ERROR type mismatch resolving `::Associated == ()` + + accepts_trait(c); + //~^ ERROR type mismatch resolving `::Associated == ()` + + accepts_trait(d); + //~^ ERROR type mismatch resolving `::Associated == ()` + + accepts_generic_trait(e); + //~^ ERROR type mismatch resolving `>::Associated == ()` + + accepts_generic_trait(f); + //~^ ERROR type mismatch resolving `>::Associated == ()` + + accepts_generic_trait(g); + //~^ ERROR type mismatch resolving `>::Associated == ()` +} + +fn main() { + accepts_trait(returns_opaque()); + //~^ ERROR type mismatch resolving `::Associated == ()` + + accepts_trait(returns_opaque_derived()); + //~^ ERROR type mismatch resolving `::Associated == ()` + + accepts_trait(returns_opaque_foo()); + //~^ ERROR type mismatch resolving `::Associated == ()` + + accepts_trait(returns_opaque_derived_foo()); + //~^ ERROR type mismatch resolving `::Associated == ()` + + accepts_generic_trait(returns_opaque_generic()); + //~^ ERROR type mismatch resolving ` as GenericTrait<()>>::Associated == ()` + + accepts_generic_trait(returns_opaque_generic_foo()); + //~^ ERROR type mismatch resolving `+Foo as GenericTrait<()>>::Associated == ()` + + accepts_generic_trait(returns_opaque_generic_duplicate()); + //~^ ERROR type mismatch resolving `+GenericTrait as GenericTrait<()>>::Associated == ()` +} diff --git a/src/test/ui/associated-types/issue-87261.stderr b/src/test/ui/associated-types/issue-87261.stderr new file mode 100644 index 00000000000..0725acfe537 --- /dev/null +++ b/src/test/ui/associated-types/issue-87261.stderr @@ -0,0 +1,238 @@ +error[E0271]: type mismatch resolving `::Associated == ()` + --> $DIR/issue-87261.rs:56:5 + | +LL | fn accepts_trait>(_: T) {} + | --------------- required by this bound in `accepts_trait` +... +LL | accepts_trait(a); + | ^^^^^^^^^^^^^ expected `()`, found associated type + | + = note: expected unit type `()` + found associated type `::Associated` +help: consider constraining the associated type `::Associated` to `()` + | +LL | A: Trait + 'static, + | ^^^^^^^^^^^^^^^^^ + +error[E0271]: type mismatch resolving `::Associated == ()` + --> $DIR/issue-87261.rs:59:5 + | +LL | fn accepts_trait>(_: T) {} + | --------------- required by this bound in `accepts_trait` +... +LL | accepts_trait(b); + | ^^^^^^^^^^^^^ expected `()`, found associated type + | + = note: expected unit type `()` + found associated type `::Associated` + = help: consider constraining the associated type `::Associated` to `()` + = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html + +error[E0271]: type mismatch resolving `::Associated == ()` + --> $DIR/issue-87261.rs:62:5 + | +LL | fn accepts_trait>(_: T) {} + | --------------- required by this bound in `accepts_trait` +... +LL | accepts_trait(c); + | ^^^^^^^^^^^^^ expected `()`, found associated type + | + = note: expected unit type `()` + found associated type `::Associated` +help: consider constraining the associated type `::Associated` to `()` + | +LL | C: Trait + Foo, + | ^^^^^^^^^^^^^^^^^ + +error[E0271]: type mismatch resolving `::Associated == ()` + --> $DIR/issue-87261.rs:65:5 + | +LL | fn accepts_trait>(_: T) {} + | --------------- required by this bound in `accepts_trait` +... +LL | accepts_trait(d); + | ^^^^^^^^^^^^^ expected `()`, found associated type + | + = note: expected unit type `()` + found associated type `::Associated` + = help: consider constraining the associated type `::Associated` to `()` + = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html + +error[E0271]: type mismatch resolving `>::Associated == ()` + --> $DIR/issue-87261.rs:68:5 + | +LL | fn accepts_generic_trait>(_: T) {} + | --------------- required by this bound in `accepts_generic_trait` +... +LL | accepts_generic_trait(e); + | ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type + | + = note: expected unit type `()` + found associated type `>::Associated` +help: consider constraining the associated type `>::Associated` to `()` + | +LL | E: GenericTrait<(), Associated = ()> + 'static, + | ^^^^^^^^^^^^^^^^^ + +error[E0271]: type mismatch resolving `>::Associated == ()` + --> $DIR/issue-87261.rs:71:5 + | +LL | fn accepts_generic_trait>(_: T) {} + | --------------- required by this bound in `accepts_generic_trait` +... +LL | accepts_generic_trait(f); + | ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type + | + = note: expected unit type `()` + found associated type `>::Associated` +help: consider constraining the associated type `>::Associated` to `()` + | +LL | F: GenericTrait<(), Associated = ()> + Foo, + | ^^^^^^^^^^^^^^^^^ + +error[E0271]: type mismatch resolving `>::Associated == ()` + --> $DIR/issue-87261.rs:74:5 + | +LL | fn accepts_generic_trait>(_: T) {} + | --------------- required by this bound in `accepts_generic_trait` +... +LL | accepts_generic_trait(g); + | ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type + | + = note: expected unit type `()` + found associated type `>::Associated` + = help: consider constraining the associated type `>::Associated` to `()` + = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html + +error[E0271]: type mismatch resolving `::Associated == ()` + --> $DIR/issue-87261.rs:79:5 + | +LL | fn returns_opaque() -> impl Trait + 'static { + | -------------------- the found opaque type +... +LL | fn accepts_trait>(_: T) {} + | --------------- required by this bound in `accepts_trait` +... +LL | accepts_trait(returns_opaque()); + | ^^^^^^^^^^^^^ expected `()`, found associated type + | + = note: expected unit type `()` + found associated type `::Associated` +help: consider constraining the associated type `::Associated` to `()` + | +LL | fn returns_opaque() -> impl Trait + 'static { + | ^^^^^^^^^^^^^^^^^ + +error[E0271]: type mismatch resolving `::Associated == ()` + --> $DIR/issue-87261.rs:82:5 + | +LL | fn returns_opaque_derived() -> impl DerivedTrait + 'static { + | --------------------------- the found opaque type +... +LL | fn accepts_trait>(_: T) {} + | --------------- required by this bound in `accepts_trait` +... +LL | accepts_trait(returns_opaque_derived()); + | ^^^^^^^^^^^^^ expected `()`, found associated type + | + = note: expected unit type `()` + found associated type `::Associated` +help: consider constraining the associated type `::Associated` to `()` + | +LL | fn returns_opaque_derived() -> impl DerivedTrait + 'static { + | ^^^^^^^^^^^^^^^^^ + +error[E0271]: type mismatch resolving `::Associated == ()` + --> $DIR/issue-87261.rs:85:5 + | +LL | fn returns_opaque_foo() -> impl Trait + Foo { + | ---------------- the found opaque type +... +LL | fn accepts_trait>(_: T) {} + | --------------- required by this bound in `accepts_trait` +... +LL | accepts_trait(returns_opaque_foo()); + | ^^^^^^^^^^^^^ expected `()`, found associated type + | + = note: expected unit type `()` + found associated type `::Associated` +help: consider constraining the associated type `::Associated` to `()` + | +LL | fn returns_opaque_foo() -> impl Trait + Foo { + | ^^^^^^^^^^^^^^^^^ + +error[E0271]: type mismatch resolving `::Associated == ()` + --> $DIR/issue-87261.rs:88:5 + | +LL | fn returns_opaque_derived_foo() -> impl DerivedTrait + Foo { + | ----------------------- the found opaque type +... +LL | fn accepts_trait>(_: T) {} + | --------------- required by this bound in `accepts_trait` +... +LL | accepts_trait(returns_opaque_derived_foo()); + | ^^^^^^^^^^^^^ expected `()`, found associated type + | + = note: expected unit type `()` + found associated type `::Associated` + = help: consider constraining the associated type `::Associated` to `()` + = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html + +error[E0271]: type mismatch resolving ` as GenericTrait<()>>::Associated == ()` + --> $DIR/issue-87261.rs:91:5 + | +LL | fn returns_opaque_generic() -> impl GenericTrait<()> + 'static { + | ------------------------------- the found opaque type +... +LL | fn accepts_generic_trait>(_: T) {} + | --------------- required by this bound in `accepts_generic_trait` +... +LL | accepts_generic_trait(returns_opaque_generic()); + | ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type + | + = note: expected unit type `()` + found associated type ` as GenericTrait<()>>::Associated` +help: consider constraining the associated type ` as GenericTrait<()>>::Associated` to `()` + | +LL | fn returns_opaque_generic() -> impl GenericTrait<(), Associated = ()> + 'static { + | ^^^^^^^^^^^^^^^^^ + +error[E0271]: type mismatch resolving `+Foo as GenericTrait<()>>::Associated == ()` + --> $DIR/issue-87261.rs:94:5 + | +LL | fn returns_opaque_generic_foo() -> impl GenericTrait<()> + Foo { + | --------------------------- the found opaque type +... +LL | fn accepts_generic_trait>(_: T) {} + | --------------- required by this bound in `accepts_generic_trait` +... +LL | accepts_generic_trait(returns_opaque_generic_foo()); + | ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type + | + = note: expected unit type `()` + found associated type `+Foo as GenericTrait<()>>::Associated` +help: consider constraining the associated type `+Foo as GenericTrait<()>>::Associated` to `()` + | +LL | fn returns_opaque_generic_foo() -> impl GenericTrait<(), Associated = ()> + Foo { + | ^^^^^^^^^^^^^^^^^ + +error[E0271]: type mismatch resolving `+GenericTrait as GenericTrait<()>>::Associated == ()` + --> $DIR/issue-87261.rs:97:5 + | +LL | fn returns_opaque_generic_duplicate() -> impl GenericTrait<()> + GenericTrait { + | ---------------------------------------- the found opaque type +... +LL | fn accepts_generic_trait>(_: T) {} + | --------------- required by this bound in `accepts_generic_trait` +... +LL | accepts_generic_trait(returns_opaque_generic_duplicate()); + | ^^^^^^^^^^^^^^^^^^^^^ expected `()`, found associated type + | + = note: expected unit type `()` + found associated type `+GenericTrait as GenericTrait<()>>::Associated` + = help: consider constraining the associated type `+GenericTrait as GenericTrait<()>>::Associated` to `()` + = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html + +error: aborting due to 14 previous errors + +For more information about this error, try `rustc --explain E0271`. -- cgit 1.4.1-3-g733a5 From c5dda05e4e47f8435400c27e31f198f88147dd9e Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Fri, 23 Jul 2021 15:26:12 +0200 Subject: Implement `AssignToDroppingUnionField` in THIR unsafeck --- compiler/rustc_mir_build/src/check_unsafety.rs | 48 +++++++++++++++++--------- src/test/ui/union/union-unsafe.rs | 4 +-- src/test/ui/union/union-unsafe.thir.stderr | 18 +++++++++- 3 files changed, 50 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 82e19c05527..21534290d12 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -5,7 +5,7 @@ use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_middle::mir::BorrowKind; use rustc_middle::thir::*; -use rustc_middle::ty::{self, ParamEnv, TyCtxt}; +use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt}; use rustc_session::lint::builtin::{UNSAFE_OP_IN_UNSAFE_FN, UNUSED_UNSAFE}; use rustc_session::lint::Level; use rustc_span::def_id::{DefId, LocalDefId}; @@ -27,7 +27,9 @@ struct UnsafetyVisitor<'a, 'tcx> { /// The `#[target_feature]` attributes of the body. Used for checking /// calls to functions with `#[target_feature]` (RFC 2396). body_target_features: &'tcx Vec, - in_possible_lhs_union_assign: bool, + /// When inside the LHS of an assignment to a field, this is the type + /// of the LHS and the span of the assignment expression. + assignment_info: Option<(Ty<'tcx>, Span)>, in_union_destructure: bool, param_env: ParamEnv<'tcx>, inside_adt: bool, @@ -287,7 +289,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { } fn visit_expr(&mut self, expr: &Expr<'tcx>) { - // could we be in a the LHS of an assignment of a union? + // could we be in the LHS of an assignment to a field? match expr.kind { ExprKind::Field { .. } | ExprKind::VarRef { .. } @@ -329,7 +331,12 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { | ExprKind::InlineAsm { .. } | ExprKind::LlvmInlineAsm { .. } | ExprKind::LogicalOp { .. } - | ExprKind::Use { .. } => self.in_possible_lhs_union_assign = false, + | ExprKind::Use { .. } => { + // We don't need to save the old value and restore it + // because all the place expressions can't have more + // than one child. + self.assignment_info = None; + } }; match expr.kind { ExprKind::Scope { value, lint_level: LintLevel::Explicit(hir_id), region_scope: _ } => { @@ -409,11 +416,21 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { self.safety_context = closure_visitor.safety_context; } ExprKind::Field { lhs, .. } => { - // assigning to union field is okay for AccessToUnionField - if let ty::Adt(adt_def, _) = &self.thir[lhs].ty.kind() { + let lhs = &self.thir[lhs]; + if let ty::Adt(adt_def, _) = lhs.ty.kind() { if adt_def.is_union() { - if self.in_possible_lhs_union_assign { - // FIXME: trigger AssignToDroppingUnionField unsafety if needed + if let Some((assigned_ty, assignment_span)) = self.assignment_info { + // To avoid semver hazard, we only consider `Copy` and `ManuallyDrop` non-dropping. + if !(assigned_ty + .ty_adt_def() + .map_or(false, |adt| adt.is_manually_drop()) + || assigned_ty + .is_copy_modulo_regions(self.tcx.at(expr.span), self.param_env)) + { + self.requires_unsafe(assignment_span, AssignToDroppingUnionField); + } else { + // write to non-drop union field, safe + } } else { self.requires_unsafe(expr.span, AccessToUnionField); } @@ -421,9 +438,10 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { } } ExprKind::Assign { lhs, rhs } | ExprKind::AssignOp { lhs, rhs, .. } => { + let lhs = &self.thir[lhs]; // First, check whether we are mutating a layout constrained field let mut visitor = LayoutConstrainedPlaceVisitor::new(self.thir, self.tcx); - visit::walk_expr(&mut visitor, &self.thir[lhs]); + visit::walk_expr(&mut visitor, lhs); if visitor.found { self.requires_unsafe(expr.span, MutationOfLayoutConstrainedField); } @@ -431,10 +449,9 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { // Second, check for accesses to union fields // don't have any special handling for AssignOp since it causes a read *and* write to lhs if matches!(expr.kind, ExprKind::Assign { .. }) { - // assigning to a union is safe, check here so it doesn't get treated as a read later - self.in_possible_lhs_union_assign = true; - visit::walk_expr(self, &self.thir()[lhs]); - self.in_possible_lhs_union_assign = false; + self.assignment_info = Some((lhs.ty, expr.span)); + visit::walk_expr(self, lhs); + self.assignment_info = None; visit::walk_expr(self, &self.thir()[rhs]); return; // we have already visited everything by now } @@ -506,12 +523,9 @@ enum UnsafeOpKind { UseOfMutableStatic, UseOfExternStatic, DerefOfRawPointer, - #[allow(dead_code)] // FIXME AssignToDroppingUnionField, AccessToUnionField, - #[allow(dead_code)] // FIXME MutationOfLayoutConstrainedField, - #[allow(dead_code)] // FIXME BorrowOfLayoutConstrainedField, CallToFunctionWith, } @@ -619,7 +633,7 @@ pub fn check_unsafety<'tcx>(tcx: TyCtxt<'tcx>, def: ty::WithOptConstParam $DIR/union-unsafe.rs:39:5 + | +LL | u.a = (RefCell::new(0), 1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ assignment to union field that might need dropping + | + = note: the previous content of the field will be dropped, which causes undefined behavior if the field was not properly initialized + +error[E0133]: assignment to union field that might need dropping is unsafe and requires unsafe function or block + --> $DIR/union-unsafe.rs:40:5 + | +LL | u.a.0 = RefCell::new(0); + | ^^^^^^^^^^^^^^^^^^^^^^^ assignment to union field that might need dropping + | + = note: the previous content of the field will be dropped, which causes undefined behavior if the field was not properly initialized + error[E0133]: access to union field is unsafe and requires unsafe function or block --> $DIR/union-unsafe.rs:47:6 | @@ -70,6 +86,6 @@ LL | *u3.a = String::from("new"); | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior -error: aborting due to 9 previous errors +error: aborting due to 11 previous errors For more information about this error, try `rustc --explain E0133`. -- cgit 1.4.1-3-g733a5 From 17f7536fb220fc53cd0af2de46528070cfab012c Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 22 Jul 2021 02:04:05 +0000 Subject: Remove detection of rustup and cargo in 'missing extern crate' diagnostics Previously, this would change the test output when RUSTUP_HOME was set: ``` ---- [ui] ui/issues/issue-49851/compiler-builtins-error.rs stdout ---- diff of stderr: 1 error[E0463]: can't find crate for `core` 2 | 3 = note: the `thumbv7em-none-eabihf` target may not be installed + = help: consider downloading the target with `rustup target add thumbv7em-none-eabihf` 4 5 error: aborting due to previous error 6 ``` Originally, I fixed it by explicitly unsetting RUSTUP_HOME in compiletest. Then I realized that almost no one has RUSTUP_HOME set, since rustup doesn't set it itself; although it does set RUST_RECURSION_COUNT whenever it launches a proxy. Then it was pointed out that this runtime check doesn't really make sense and it's fine to make it unconditional. --- compiler/rustc_metadata/src/locator.rs | 7 +++++-- src/test/ui/crate-loading/missing-std.rs | 1 - src/test/ui/crate-loading/missing-std.stderr | 2 +- src/test/ui/issues/issue-37131.stderr | 2 ++ src/test/ui/issues/issue-49851/compiler-builtins-error.stderr | 2 ++ 5 files changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index 028104fd6b5..4936b22c7b9 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -1080,7 +1080,10 @@ impl CrateError { locator.triple )); } - if missing_core && std::env::var("RUSTUP_HOME").is_ok() { + // NOTE: this suggests using rustup, even though the user may not have it installed. + // That's because they could choose to install it; or this may give them a hint which + // target they need to install from their distro. + if missing_core { err.help(&format!( "consider downloading the target with `rustup target add {}`", locator.triple @@ -1097,7 +1100,7 @@ impl CrateError { current_crate )); } - if sess.is_nightly_build() && std::env::var("CARGO").is_ok() { + if sess.is_nightly_build() { err.help("consider building the standard library from source with `cargo build -Zbuild-std`"); } } else if Some(crate_name) diff --git a/src/test/ui/crate-loading/missing-std.rs b/src/test/ui/crate-loading/missing-std.rs index de4ccc18560..1a34c21ba54 100644 --- a/src/test/ui/crate-loading/missing-std.rs +++ b/src/test/ui/crate-loading/missing-std.rs @@ -1,7 +1,6 @@ // compile-flags: --target x86_64-unknown-uefi // needs-llvm-components: x86 // rustc-env:CARGO=/usr/bin/cargo -// rustc-env:RUSTUP_HOME=/home/bors/.rustup #![no_core] extern crate core; //~^ ERROR can't find crate for `core` diff --git a/src/test/ui/crate-loading/missing-std.stderr b/src/test/ui/crate-loading/missing-std.stderr index e61486fdc6f..25808efdfa6 100644 --- a/src/test/ui/crate-loading/missing-std.stderr +++ b/src/test/ui/crate-loading/missing-std.stderr @@ -1,5 +1,5 @@ error[E0463]: can't find crate for `core` - --> $DIR/missing-std.rs:6:1 + --> $DIR/missing-std.rs:5:1 | LL | extern crate core; | ^^^^^^^^^^^^^^^^^^ can't find crate diff --git a/src/test/ui/issues/issue-37131.stderr b/src/test/ui/issues/issue-37131.stderr index 660a6935f36..b45574f0c49 100644 --- a/src/test/ui/issues/issue-37131.stderr +++ b/src/test/ui/issues/issue-37131.stderr @@ -1,6 +1,8 @@ error[E0463]: can't find crate for `std` | = note: the `thumbv6m-none-eabi` target may not be installed + = help: consider downloading the target with `rustup target add thumbv6m-none-eabi` + = help: consider building the standard library from source with `cargo build -Zbuild-std` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-49851/compiler-builtins-error.stderr b/src/test/ui/issues/issue-49851/compiler-builtins-error.stderr index 7e23e0fd747..d963c07ea91 100644 --- a/src/test/ui/issues/issue-49851/compiler-builtins-error.stderr +++ b/src/test/ui/issues/issue-49851/compiler-builtins-error.stderr @@ -1,6 +1,8 @@ error[E0463]: can't find crate for `core` | = note: the `thumbv7em-none-eabihf` target may not be installed + = help: consider downloading the target with `rustup target add thumbv7em-none-eabihf` + = help: consider building the standard library from source with `cargo build -Zbuild-std` error: aborting due to previous error -- cgit 1.4.1-3-g733a5