From b6badee1400b60b84623a3eaa65ba668ff1aa251 Mon Sep 17 00:00:00 2001 From: Giacomo Stevanato Date: Wed, 21 Jul 2021 14:42:20 +0200 Subject: [PATCH 1/8] Fix span when suggesting to add an associated type bound --- compiler/rustc_middle/src/ty/error.rs | 65 ++++++++++++++++++--------- 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index 96aae3bd70cd2..f1c7c1ea852a2 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -628,6 +628,7 @@ impl Trait for X { assoc_substs, ty, msg, + false, ) { return true; } @@ -646,6 +647,7 @@ impl Trait for X { assoc_substs, ty, msg, + false, ); } } @@ -771,13 +773,24 @@ fn foo(&self) -> Self::T { String::new() } ) -> bool { let assoc = self.associated_item(proj_ty.item_def_id); if let ty::Opaque(def_id, _) = *proj_ty.self_ty().kind() { - self.constrain_associated_type_structured_suggestion( + let opaque_local_def_id = def_id.expect_local(); + let opaque_hir_id = self.hir().local_def_id_to_hir_id(opaque_local_def_id); + let opaque_hir_ty = match &self.hir().expect_item(opaque_hir_id).kind { + hir::ItemKind::OpaqueTy(opaque_hir_ty) => opaque_hir_ty, + _ => bug!("The HirId comes from a `ty::Opaque`"), + }; + + let (trait_ref, assoc_substs) = proj_ty.trait_ref_and_own_substs(self); + + self.constrain_generic_bound_associated_type_structured_suggestion( db, - self.def_span(def_id), - &assoc, - proj_ty.trait_ref_and_own_substs(self).1, + &trait_ref, + opaque_hir_ty.bounds, + assoc, + assoc_substs, ty, - &msg, + msg, + true, ) } else { false @@ -899,6 +912,11 @@ fn foo(&self) -> Self::T { String::new() } /// Given a slice of `hir::GenericBound`s, if any of them corresponds to the `trait_ref` /// requirement, provide a structured suggestion to constrain it to a given type `ty`. + /// + /// `is_bound_surely_present` indicates whether we know the bound we're looking for is + /// inside `bounds`. If that's the case then we can consider `bounds` containing only one + /// trait bound as the one we're looking for. This can help in cases where the associated + /// type is defined on a supertrait of the one present in the bounds. fn constrain_generic_bound_associated_type_structured_suggestion( self, db: &mut DiagnosticBuilder<'_>, @@ -908,23 +926,30 @@ fn foo(&self) -> Self::T { String::new() } assoc_substs: &[ty::GenericArg<'tcx>], ty: Ty<'tcx>, msg: &str, + is_bound_surely_present: bool, ) -> bool { // FIXME: we would want to call `resolve_vars_if_possible` on `ty` before suggesting. - bounds.iter().any(|bound| match bound { - hir::GenericBound::Trait(ptr, hir::TraitBoundModifier::None) => { - // Relate the type param against `T` in `::Foo`. - ptr.trait_ref.trait_def_id() == Some(trait_ref.def_id) - && self.constrain_associated_type_structured_suggestion( - db, - ptr.span, - assoc, - assoc_substs, - ty, - msg, - ) - } - _ => false, - }) + + let trait_bounds = bounds.iter().filter_map(|bound| match bound { + hir::GenericBound::Trait(ptr, hir::TraitBoundModifier::None) => Some(ptr), + _ => None, + }); + + let matching_trait_bounds = trait_bounds + .clone() + .filter(|ptr| ptr.trait_ref.trait_def_id() == Some(trait_ref.def_id)) + .collect::>(); + + let span = match &matching_trait_bounds[..] { + &[ptr] => ptr.span, + &[] if is_bound_surely_present => match &trait_bounds.collect::>()[..] { + &[ptr] => ptr.span, + _ => return false, + }, + _ => return false, + }; + + self.constrain_associated_type_structured_suggestion(db, span, assoc, assoc_substs, ty, msg) } /// Given a span corresponding to a bound, provide a structured suggestion to set an From d1bc9413858b334b6cdaf345bd6b50cb9aa4cec2 Mon Sep 17 00:00:00 2001 From: Giacomo Stevanato Date: Wed, 21 Jul 2021 14:42:32 +0200 Subject: [PATCH 2/8] Add regression test --- src/test/ui/associated-types/issue-87261.rs | 99 ++++++++ .../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 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 0000000000000..a70f771e4826f --- /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 0000000000000..0725acfe537db --- /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`. From 04634e88a35d8989966c181e326e41ed1973d35e Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 23 Jul 2021 19:04:07 +0200 Subject: [PATCH 3/8] Mark `format_args_nl` as `#[doc(hidden)]` --- library/core/src/macros/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 3ca8f27c79ab7..07ee589e29f56 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -845,6 +845,7 @@ pub(crate) mod builtin { language use and is subject to change" )] #[allow_internal_unstable(fmt_internals)] + #[doc(hidden)] #[rustc_builtin_macro] #[macro_export] macro_rules! format_args_nl { From 74f01a4bbe441816aa5de489ca87f77d3474af37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Nogueira=20Rolim?= <34201958+ericonr@users.noreply.github.com> Date: Fri, 23 Jul 2021 02:32:55 -0300 Subject: [PATCH 4/8] Fix parameter names in std::env documentation. The function parameters were renamed, but the documentation wasn't. --- library/std/src/env.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/library/std/src/env.rs b/library/std/src/env.rs index 64f88c1aba68e..5709d97d6430f 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -294,7 +294,7 @@ impl Error for VarError { } } -/// Sets the environment variable `k` to the value `v` for the currently running +/// Sets the environment variable `key` to the value `value` for the currently running /// process. /// /// Note that while concurrent access to environment variables is safe in Rust, @@ -310,9 +310,8 @@ impl Error for VarError { /// /// # Panics /// -/// This function may panic if `key` is empty, contains an ASCII equals sign -/// `'='` or the NUL character `'\0'`, or when the value contains the NUL -/// character. +/// This function may panic if `key` is empty, contains an ASCII equals sign `'='` +/// or the NUL character `'\0'`, or when `value` contains the NUL character. /// /// # Examples /// From a2ae1912954bf6e21c706258348735218ceb1ab4 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Thu, 22 Jul 2021 17:40:01 -0500 Subject: [PATCH 5/8] Rename `known_attrs` to `expanded_inert_attrs` and move to rustc_expand There's no need for this to be (untracked) global state. --- compiler/rustc_expand/src/base.rs | 6 ++++++ compiler/rustc_expand/src/expand.rs | 4 ++-- compiler/rustc_session/src/session.rs | 10 ---------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 8c6aef80635cf..3d5bc770c4fb0 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -1,6 +1,7 @@ use crate::expand::{self, AstFragment, Invocation}; use crate::module::DirOwnership; +use rustc_ast::attr::MarkedAttrs; use rustc_ast::ptr::P; use rustc_ast::token::{self, Nonterminal}; use rustc_ast::tokenstream::{CanSynthesizeMissingTokens, TokenStream}; @@ -951,6 +952,10 @@ pub struct ExtCtxt<'a> { /// /// `Ident` is the module name. pub(super) extern_mod_loaded: OnExternModLoaded<'a>, + /// When we 'expand' an inert attribute, we leave it + /// in the AST, but insert it here so that we know + /// not to expand it again. + pub(super) expanded_inert_attrs: MarkedAttrs, } impl<'a> ExtCtxt<'a> { @@ -977,6 +982,7 @@ impl<'a> ExtCtxt<'a> { }, force_mode: false, expansions: FxHashMap::default(), + expanded_inert_attrs: MarkedAttrs::new(), } } diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index dcd871c9d2050..a9250bf978778 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -754,7 +754,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { } } SyntaxExtensionKind::NonMacroAttr { mark_used } => { - self.cx.sess.mark_attr_known(&attr); + self.cx.expanded_inert_attrs.mark(&attr); if *mark_used { self.cx.sess.mark_attr_used(&attr); } @@ -1040,7 +1040,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { item.visit_attrs(|attrs| { attr = attrs .iter() - .position(|a| !self.cx.sess.is_attr_known(a) && !is_builtin_attr(a)) + .position(|a| !self.cx.expanded_inert_attrs.is_marked(a) && !is_builtin_attr(a)) .map(|attr_pos| { let attr = attrs.remove(attr_pos); let following_derives = attrs[attr_pos..] diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 86d495c3353b3..369af437c4384 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -219,7 +219,6 @@ pub struct Session { /// Set of enabled features for the current target. pub target_features: FxHashSet, - known_attrs: Lock, used_attrs: Lock, /// `Span`s for `if` conditions that we have suggested turning into `if let`. @@ -1076,14 +1075,6 @@ impl Session { == config::InstrumentCoverage::ExceptUnusedFunctions } - pub fn mark_attr_known(&self, attr: &Attribute) { - self.known_attrs.lock().mark(attr) - } - - pub fn is_attr_known(&self, attr: &Attribute) -> bool { - self.known_attrs.lock().is_marked(attr) - } - pub fn mark_attr_used(&self, attr: &Attribute) { self.used_attrs.lock().mark(attr) } @@ -1389,7 +1380,6 @@ pub fn build_session( miri_unleashed_features: Lock::new(Default::default()), asm_arch, target_features: FxHashSet::default(), - known_attrs: Lock::new(MarkedAttrs::new()), used_attrs: Lock::new(MarkedAttrs::new()), if_let_suggestions: Default::default(), }; From 30b619771d41a9fb0914b5064050bb1aa202439a Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Fri, 23 Jul 2021 17:35:18 -0700 Subject: [PATCH 6/8] IEEE 754 is not an RFC --- RELEASES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASES.md b/RELEASES.md index 35e5627e61ff8..6eb70dee3952f 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -44,7 +44,7 @@ Libraries - [`leading_zeros`, and `trailing_zeros` are now available on all `NonZero` integer types.][84082] - [`{f32, f64}::from_str` now parse and print special values - (`NaN`, `-0`) according to IEEE RFC 754.][78618] + (`NaN`, `-0`) according to IEEE 754.][78618] - [You can now index into slices using `(Bound, Bound)`.][77704] - [Add the `BITS` associated constant to all numeric types.][82565] From 17f7536fb220fc53cd0af2de46528070cfab012c Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 22 Jul 2021 02:04:05 +0000 Subject: [PATCH 7/8] 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 ++ .../ui/issues/issue-49851/compiler-builtins-error.stderr | 2 ++ 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index 028104fd6b505..4936b22c7b983 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 de4ccc185608c..1a34c21ba5413 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 e61486fdc6ffd..25808efdfa699 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 660a6935f36cb..b45574f0c49af 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 7e23e0fd747fb..d963c07ea9175 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 From 7879a59ac72e2c53659358bcaa3b7c32e06047f7 Mon Sep 17 00:00:00 2001 From: Matthias Geier Date: Sat, 24 Jul 2021 11:27:42 +0200 Subject: [PATCH 8/8] DOC: remove unnecessary feature crate attribute from example code --- library/core/src/mem/maybe_uninit.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index 5122421ea8c85..d3ebc1cebb67b 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -461,7 +461,6 @@ impl MaybeUninit { /// With `write`, we can avoid the need to write through a raw pointer: /// /// ```rust - /// #![feature(maybe_uninit_extra)] /// use core::pin::Pin; /// use core::mem::MaybeUninit; ///