From b7fc1a743122e3c45f105a5d1169a042a2c6e8bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 24 Oct 2024 22:16:43 +0000 Subject: [PATCH 01/13] Add trait diff highlighting logic and use it in E0277 When a trait is not implemented for a type, but there *is* an `impl` for another type or different trait params, we format the output to use highlighting in the same way that E0308 does for types. The logic accounts for 3 cases: - When both the type and trait in the expected predicate and the candidate are different - When only the types are different - When only the trait generic params are different For each case, we use slightly different formatting and wording. --- .../src/error_reporting/infer/mod.rs | 61 +++++++++++++++++ .../traits/fulfillment_errors.rs | 68 +++++++++++++++---- .../associated-type-bound-fail.stderr | 3 +- .../defaults/rp_impl_trait_fail.stderr | 6 +- .../defaults/trait_objects_fail.stderr | 6 +- .../ui/const-generics/defaults/wfness.stderr | 6 +- .../occurs-check/unused-substs-1.stderr | 3 +- .../as_expression.current.stderr | 3 +- .../as_expression.next.stderr | 3 +- .../unsatisfied-bounds.stderr | 6 +- ...between-expected-trait-and-found-trait.svg | 28 ++++---- .../return-dont-satisfy-bounds.stderr | 3 +- tests/ui/impl-trait/issues/issue-62742.stderr | 6 +- tests/ui/impl-trait/nested-rpit-hrtb.stderr | 6 +- tests/ui/indexing/index-help.stderr | 3 +- .../indexing/indexing-requires-a-uint.stderr | 3 +- ...int-at-index-for-obligation-failure.stderr | 3 +- tests/ui/integral-indexing.stderr | 24 ++++--- tests/ui/issues/issue-34334.stderr | 3 +- tests/ui/issues/issue-45801.stderr | 3 +- ...e-66923-show-error-for-correct-call.stderr | 6 +- .../invalid-iterator-chain-fixable.stderr | 6 +- .../iterators/invalid-iterator-chain.stderr | 6 +- ...er_breaking_with_unit_fallback.unit.stderr | 3 +- ...lue-fallback-issue-66757.nofallback.stderr | 3 +- tests/ui/on-unimplemented/impl-substs.stderr | 3 +- tests/ui/on-unimplemented/on-impl.stderr | 6 +- tests/ui/on-unimplemented/slice-index.stderr | 3 +- tests/ui/str/str-idx.stderr | 9 ++- tests/ui/str/str-mut-idx.stderr | 9 ++- tests/ui/suggestions/issue-101623.stderr | 3 +- .../suggest-dereferencing-index.stderr | 3 +- tests/ui/traits/coercion-generic-bad.stderr | 3 +- tests/ui/traits/negative-bounds/simple.stderr | 3 +- tests/ui/try-block/try-block-bad-type.stderr | 3 +- tests/ui/try-trait/bad-interconversion.stderr | 9 ++- .../constrain_in_projection.current.stderr | 3 +- .../nested-tait-inference.current.stderr | 3 +- .../self-referential-2.current.stderr | 3 +- ...t-similar-impls-for-root-obligation.stderr | 3 +- 40 files changed, 251 insertions(+), 86 deletions(-) diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs index 574cf1e88b1..4725047090e 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs @@ -766,6 +766,67 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { values } + pub fn cmp_traits( + &self, + def_id1: DefId, + args1: &[ty::GenericArg<'tcx>], + def_id2: DefId, + args2: &[ty::GenericArg<'tcx>], + ) -> (DiagStyledString, DiagStyledString) { + let mut values = (DiagStyledString::new(), DiagStyledString::new()); + + if def_id1 != def_id2 { + values.0.push_highlighted(self.tcx.def_path_str(def_id1).as_str()); + values.1.push_highlighted(self.tcx.def_path_str(def_id2).as_str()); + } else { + values.0.push_normal(self.tcx.item_name(def_id1).as_str()); + values.1.push_normal(self.tcx.item_name(def_id2).as_str()); + } + + if args1.len() != args2.len() { + let (pre, post) = if args1.len() > 0 { ("<", ">") } else { ("", "") }; + values.0.push_normal(format!( + "{pre}{}{post}", + args1.iter().map(|a| a.to_string()).collect::>().join(", ") + )); + let (pre, post) = if args2.len() > 0 { ("<", ">") } else { ("", "") }; + values.1.push_normal(format!( + "{pre}{}{post}", + args2.iter().map(|a| a.to_string()).collect::>().join(", ") + )); + return values; + } + + if args1.len() > 0 { + values.0.push_normal("<"); + values.1.push_normal("<"); + } + for (i, (a, b)) in std::iter::zip(args1, args2).enumerate() { + let a_str = a.to_string(); + let b_str = b.to_string(); + if let (Some(a), Some(b)) = (a.as_type(), b.as_type()) { + let (a, b) = self.cmp(a, b); + values.0.0.extend(a.0); + values.1.0.extend(b.0); + } else if a_str != b_str { + values.0.push_highlighted(a_str); + values.1.push_highlighted(b_str); + } else { + values.0.push_normal(a_str); + values.1.push_normal(b_str); + } + if i + 1 < args1.len() { + values.0.push_normal(", "); + values.1.push_normal(", "); + } + } + if args1.len() > 0 { + values.0.push_normal(">"); + values.1.push_normal(">"); + } + values + } + /// Compares two given types, eliding parts that are the same between them and highlighting /// relevant differences, and return two representation of those types for highlighted printing. pub fn cmp(&self, t1: Ty<'tcx>, t2: Ty<'tcx>) -> (DiagStyledString, DiagStyledString) { diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index 7aa558cfd3f..358c244eca9 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -1832,21 +1832,63 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { if impl_trait_ref.references_error() { return false; } - let self_ty = impl_trait_ref.self_ty().to_string(); - err.highlighted_help(vec![ - StringPart::normal(format!( - "the trait `{}` ", - impl_trait_ref.print_trait_sugared() - )), - StringPart::highlighted("is"), + + let traits = self.cmp_traits( + obligation_trait_ref.def_id, + &obligation_trait_ref.args[1..], + impl_trait_ref.def_id, + &impl_trait_ref.args[1..], + ); + let traits_content = (traits.0.content(), traits.1.content()); + let types = self.cmp(obligation_trait_ref.self_ty(), impl_trait_ref.self_ty()); + let types_content = (types.0.content(), types.1.content()); + let mut msg = vec![StringPart::normal("the trait `")]; + if traits_content.0 == traits_content.1 { + msg.push(StringPart::normal( + impl_trait_ref.print_trait_sugared().to_string(), + )); + } else { + msg.extend(traits.0.0); + } + msg.extend([ + StringPart::normal("` "), + StringPart::highlighted("is not"), StringPart::normal(" implemented for `"), - if let [TypeError::Sorts(_)] = &terrs[..] { - StringPart::normal(self_ty) - } else { - StringPart::highlighted(self_ty) - }, - StringPart::normal("`"), ]); + if types_content.0 == types_content.1 { + msg.push(StringPart::normal(obligation_trait_ref.self_ty().to_string())); + } else { + msg.extend(types.0.0); + } + msg.push(StringPart::normal("`")); + if types_content.0 == types_content.1 { + msg.push(StringPart::normal("\nbut trait `")); + msg.extend(traits.1.0); + msg.extend([ + StringPart::normal("` "), + StringPart::highlighted("is"), + StringPart::normal(" implemented for it"), + ]); + } else if traits_content.0 == traits_content.1 { + msg.extend([ + StringPart::normal("\nbut it "), + StringPart::highlighted("is"), + StringPart::normal(" implemented for `"), + ]); + msg.extend(types.1.0); + msg.push(StringPart::normal("`")); + } else { + msg.push(StringPart::normal("\nbut trait `")); + msg.extend(traits.1.0); + msg.extend([ + StringPart::normal("` "), + StringPart::highlighted("is"), + StringPart::normal(" implemented for `"), + ]); + msg.extend(types.1.0); + msg.push(StringPart::normal("`")); + } + err.highlighted_help(msg); if let [TypeError::Sorts(exp_found)] = &terrs[..] { let exp_found = self.resolve_vars_if_possible(*exp_found); diff --git a/tests/ui/const-generics/associated-type-bound-fail.stderr b/tests/ui/const-generics/associated-type-bound-fail.stderr index 602a8927a85..e92aad7cec3 100644 --- a/tests/ui/const-generics/associated-type-bound-fail.stderr +++ b/tests/ui/const-generics/associated-type-bound-fail.stderr @@ -4,7 +4,8 @@ error[E0277]: the trait bound `u16: Bar` is not satisfied LL | type Assoc = u16; | ^^^ the trait `Bar` is not implemented for `u16` | - = help: the trait `Bar<3>` is implemented for `u16` + = help: the trait `Bar` is not implemented for `u16` + but trait `Bar<3>` is implemented for it note: required by a bound in `Foo::Assoc` --> $DIR/associated-type-bound-fail.rs:4:17 | diff --git a/tests/ui/const-generics/defaults/rp_impl_trait_fail.stderr b/tests/ui/const-generics/defaults/rp_impl_trait_fail.stderr index 45be3126e3b..e36f645b263 100644 --- a/tests/ui/const-generics/defaults/rp_impl_trait_fail.stderr +++ b/tests/ui/const-generics/defaults/rp_impl_trait_fail.stderr @@ -18,7 +18,8 @@ LL | LL | 1_u32 | ----- return type was inferred to be `u32` here | - = help: the trait `Traitor` is implemented for `u32` + = help: the trait `Traitor` is not implemented for `u32` + but trait `Traitor` is implemented for it error[E0277]: the trait bound `u64: Traitor` is not satisfied --> $DIR/rp_impl_trait_fail.rs:21:13 @@ -29,7 +30,8 @@ LL | LL | 1_u64 | ----- return type was inferred to be `u64` here | - = help: the trait `Traitor<1, 2>` is implemented for `u64` + = help: the trait `Traitor<1, 1>` is not implemented for `u64` + but trait `Traitor<1, 2>` is implemented for it error[E0284]: type annotations needed --> $DIR/rp_impl_trait_fail.rs:28:5 diff --git a/tests/ui/const-generics/defaults/trait_objects_fail.stderr b/tests/ui/const-generics/defaults/trait_objects_fail.stderr index 481d77728b9..2390dfeadb9 100644 --- a/tests/ui/const-generics/defaults/trait_objects_fail.stderr +++ b/tests/ui/const-generics/defaults/trait_objects_fail.stderr @@ -4,7 +4,8 @@ error[E0277]: the trait bound `u32: Trait` is not satisfied LL | foo(&10_u32); | ^^^^^^^ the trait `Trait` is not implemented for `u32` | - = help: the trait `Trait<2>` is implemented for `u32` + = help: the trait `Trait<12>` is not implemented for `u32` + but trait `Trait<2>` is implemented for it = note: required for the cast from `&u32` to `&dyn Trait` error[E0277]: the trait bound `bool: Traitor<_>` is not satisfied @@ -13,7 +14,8 @@ error[E0277]: the trait bound `bool: Traitor<_>` is not satisfied LL | bar(&true); | ^^^^^ the trait `Traitor<_>` is not implemented for `bool` | - = help: the trait `Traitor<2, 3>` is implemented for `bool` + = help: the trait `Traitor<_, _>` is not implemented for `bool` + but trait `Traitor<2, 3>` is implemented for it = note: required for the cast from `&bool` to `&dyn Traitor<_>` error: aborting due to 2 previous errors diff --git a/tests/ui/const-generics/defaults/wfness.stderr b/tests/ui/const-generics/defaults/wfness.stderr index bd9bfcd7dad..290a80bd32f 100644 --- a/tests/ui/const-generics/defaults/wfness.stderr +++ b/tests/ui/const-generics/defaults/wfness.stderr @@ -10,7 +10,8 @@ error[E0277]: the trait bound `(): Trait<2>` is not satisfied LL | (): Trait; | ^^^^^^^^ the trait `Trait<2>` is not implemented for `()` | - = help: the trait `Trait<3>` is implemented for `()` + = help: the trait `Trait<2>` is not implemented for `()` + but trait `Trait<3>` is implemented for it error[E0277]: the trait bound `(): Trait<1>` is not satisfied --> $DIR/wfness.rs:18:13 @@ -18,7 +19,8 @@ error[E0277]: the trait bound `(): Trait<1>` is not satisfied LL | fn foo() -> DependentDefaultWfness { | ^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait<1>` is not implemented for `()` | - = help: the trait `Trait<3>` is implemented for `()` + = help: the trait `Trait<1>` is not implemented for `()` + but trait `Trait<3>` is implemented for it note: required by a bound in `WhereClause` --> $DIR/wfness.rs:8:9 | diff --git a/tests/ui/const-generics/occurs-check/unused-substs-1.stderr b/tests/ui/const-generics/occurs-check/unused-substs-1.stderr index 0184a059327..07e86aa17f2 100644 --- a/tests/ui/const-generics/occurs-check/unused-substs-1.stderr +++ b/tests/ui/const-generics/occurs-check/unused-substs-1.stderr @@ -4,7 +4,8 @@ error[E0277]: the trait bound `A<_>: Bar<_>` is not satisfied LL | let _ = A; | ^ the trait `Bar<_>` is not implemented for `A<_>` | - = help: the trait `Bar<_>` is implemented for `A<{ 6 + 1 }>` + = help: the trait `Bar<_>` is not implemented for `A<_>` + but it is implemented for `A<{ 6 + 1 }>` note: required by a bound in `A` --> $DIR/unused-substs-1.rs:9:11 | diff --git a/tests/ui/diagnostic_namespace/do_not_recommend/as_expression.current.stderr b/tests/ui/diagnostic_namespace/do_not_recommend/as_expression.current.stderr index 41f222e46a7..5d0c1826411 100644 --- a/tests/ui/diagnostic_namespace/do_not_recommend/as_expression.current.stderr +++ b/tests/ui/diagnostic_namespace/do_not_recommend/as_expression.current.stderr @@ -4,7 +4,8 @@ error[E0277]: the trait bound `&str: AsExpression` is not satisfied LL | SelectInt.check("bar"); | ^^^^^ the trait `AsExpression` is not implemented for `&str` | - = help: the trait `AsExpression` is implemented for `&str` + = help: the trait `AsExpression` is not implemented for `&str` + but trait `AsExpression` is implemented for it = help: for that trait implementation, expected `Text`, found `Integer` error: aborting due to 1 previous error diff --git a/tests/ui/diagnostic_namespace/do_not_recommend/as_expression.next.stderr b/tests/ui/diagnostic_namespace/do_not_recommend/as_expression.next.stderr index 8c01b61191e..1e1eae852f9 100644 --- a/tests/ui/diagnostic_namespace/do_not_recommend/as_expression.next.stderr +++ b/tests/ui/diagnostic_namespace/do_not_recommend/as_expression.next.stderr @@ -22,7 +22,8 @@ error[E0277]: the trait bound `&str: AsExpression` is not satisfied LL | SelectInt.check("bar"); | ^^^^^ the trait `AsExpression` is not implemented for `&str` | - = help: the trait `AsExpression` is implemented for `&str` + = help: the trait `AsExpression` is not implemented for `&str` + but trait `AsExpression` is implemented for it = help: for that trait implementation, expected `Text`, found `Integer` error[E0271]: type mismatch resolving `::SqlType == Text` diff --git a/tests/ui/generic-const-items/unsatisfied-bounds.stderr b/tests/ui/generic-const-items/unsatisfied-bounds.stderr index 14894cef770..de252b816e5 100644 --- a/tests/ui/generic-const-items/unsatisfied-bounds.stderr +++ b/tests/ui/generic-const-items/unsatisfied-bounds.stderr @@ -16,7 +16,8 @@ error[E0277]: the trait bound `Infallible: From<()>` is not satisfied LL | let () = K::<()>; | ^^ the trait `From<()>` is not implemented for `Infallible` | - = help: the trait `From` is implemented for `Infallible` + = help: the trait `From<()>` is not implemented for `Infallible` + but trait `From` is implemented for it = help: for that trait implementation, expected `!`, found `()` note: required by a bound in `K` --> $DIR/unsatisfied-bounds.rs:12:17 @@ -48,7 +49,8 @@ error[E0277]: the trait bound `Infallible: From<()>` is not satisfied LL | let _ = <() as Trait<&'static str>>::B::<()>; | ^^ the trait `From<()>` is not implemented for `Infallible` | - = help: the trait `From` is implemented for `Infallible` + = help: the trait `From<()>` is not implemented for `Infallible` + but trait `From` is implemented for it = help: for that trait implementation, expected `!`, found `()` note: required by a bound in `Trait::B` --> $DIR/unsatisfied-bounds.rs:21:21 diff --git a/tests/ui/impl-trait/diagnostics/highlight-difference-between-expected-trait-and-found-trait.svg b/tests/ui/impl-trait/diagnostics/highlight-difference-between-expected-trait-and-found-trait.svg index a18fc11a1e3..277fd1536bc 100644 --- a/tests/ui/impl-trait/diagnostics/highlight-difference-between-expected-trait-and-found-trait.svg +++ b/tests/ui/impl-trait/diagnostics/highlight-difference-between-expected-trait-and-found-trait.svg @@ -1,4 +1,4 @@ - + diff --git a/tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.stderr b/tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.stderr index 768224e4c51..663c9a7f2ae 100644 --- a/tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.stderr +++ b/tests/ui/impl-trait/in-trait/return-dont-satisfy-bounds.stderr @@ -32,7 +32,8 @@ LL | fn foo>(self) -> impl Foo { LL | self | ---- return type was inferred to be `Bar` here | - = help: the trait `Foo` is implemented for `Bar` + = help: the trait `Foo` is not implemented for `Bar` + but trait `Foo` is implemented for it = help: for that trait implementation, expected `char`, found `u8` error: aborting due to 3 previous errors diff --git a/tests/ui/impl-trait/issues/issue-62742.stderr b/tests/ui/impl-trait/issues/issue-62742.stderr index 94822e41ccd..98d17b02536 100644 --- a/tests/ui/impl-trait/issues/issue-62742.stderr +++ b/tests/ui/impl-trait/issues/issue-62742.stderr @@ -29,7 +29,8 @@ error[E0277]: the trait bound `RawImpl<_>: Raw<_>` is not satisfied LL | WrongImpl::foo(0i32); | ^^^^^^^^^ the trait `Raw<_>` is not implemented for `RawImpl<_>` | - = help: the trait `Raw<[_]>` is implemented for `RawImpl<_>` + = help: the trait `Raw<_>` is not implemented for `RawImpl<_>` + but trait `Raw<[_]>` is implemented for it note: required by a bound in `SafeImpl` --> $DIR/issue-62742.rs:33:35 | @@ -67,7 +68,8 @@ error[E0277]: the trait bound `RawImpl<()>: Raw<()>` is not satisfied LL | WrongImpl::<()>::foo(0i32); | ^^^^^^^^^^^^^^^ the trait `Raw<()>` is not implemented for `RawImpl<()>` | - = help: the trait `Raw<[()]>` is implemented for `RawImpl<()>` + = help: the trait `Raw<()>` is not implemented for `RawImpl<()>` + but trait `Raw<[()]>` is implemented for it = help: for that trait implementation, expected `[()]`, found `()` note: required by a bound in `SafeImpl` --> $DIR/issue-62742.rs:33:35 diff --git a/tests/ui/impl-trait/nested-rpit-hrtb.stderr b/tests/ui/impl-trait/nested-rpit-hrtb.stderr index d98de650d0d..2e95ef370c7 100644 --- a/tests/ui/impl-trait/nested-rpit-hrtb.stderr +++ b/tests/ui/impl-trait/nested-rpit-hrtb.stderr @@ -83,7 +83,8 @@ error[E0277]: the trait bound `for<'a> &'a (): Qux<'b>` is not satisfied LL | fn one_hrtb_mention_fn_trait_param_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl Qux<'b>> {} | ^^^^^^^^^^^^ the trait `for<'a> Qux<'b>` is not implemented for `&'a ()` | - = help: the trait `Qux<'_>` is implemented for `()` + = help: the trait `Qux<'b>` is not implemented for `&'a ()` + but trait `Qux<'_>` is implemented for `()` = help: for that trait implementation, expected `()`, found `&'a ()` error: implementation of `Bar` is not general enough @@ -101,7 +102,8 @@ error[E0277]: the trait bound `for<'a, 'b> &'a (): Qux<'b>` is not satisfied LL | fn two_htrb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Qux<'b>> {} | ^^^^^^^^^^^^^^^^^^^^ the trait `for<'a, 'b> Qux<'b>` is not implemented for `&'a ()` | - = help: the trait `Qux<'_>` is implemented for `()` + = help: the trait `Qux<'b>` is not implemented for `&'a ()` + but trait `Qux<'_>` is implemented for `()` = help: for that trait implementation, expected `()`, found `&'a ()` error: aborting due to 9 previous errors diff --git a/tests/ui/indexing/index-help.stderr b/tests/ui/indexing/index-help.stderr index 4ec28ddf871..d4637da1426 100644 --- a/tests/ui/indexing/index-help.stderr +++ b/tests/ui/indexing/index-help.stderr @@ -5,7 +5,8 @@ LL | x[0i32]; | ^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[{integer}]>` is not implemented for `i32` - = help: the trait `SliceIndex<[{integer}]>` is implemented for `usize` + = help: the trait `SliceIndex<[{integer}]>` is not implemented for `i32` + but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `i32` = note: required for `Vec<{integer}>` to implement `Index` diff --git a/tests/ui/indexing/indexing-requires-a-uint.stderr b/tests/ui/indexing/indexing-requires-a-uint.stderr index 3041c2c99a1..fdcf9b030a5 100644 --- a/tests/ui/indexing/indexing-requires-a-uint.stderr +++ b/tests/ui/indexing/indexing-requires-a-uint.stderr @@ -5,7 +5,8 @@ LL | [0][0u8]; | ^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[{integer}]>` is not implemented for `u8` - = help: the trait `SliceIndex<[{integer}]>` is implemented for `usize` + = help: the trait `SliceIndex<[{integer}]>` is not implemented for `u8` + but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `u8` = note: required for `[{integer}]` to implement `Index` = note: 1 redundant requirement hidden diff --git a/tests/ui/indexing/point-at-index-for-obligation-failure.stderr b/tests/ui/indexing/point-at-index-for-obligation-failure.stderr index 4cced22789f..0752231356c 100644 --- a/tests/ui/indexing/point-at-index-for-obligation-failure.stderr +++ b/tests/ui/indexing/point-at-index-for-obligation-failure.stderr @@ -4,7 +4,8 @@ error[E0277]: the trait bound `String: Borrow<&str>` is not satisfied LL | &s | ^^ the trait `Borrow<&str>` is not implemented for `String` | - = help: the trait `Borrow` is implemented for `String` + = help: the trait `Borrow<&_>` is not implemented for `String` + but trait `Borrow<_>` is implemented for it = help: for that trait implementation, expected `str`, found `&str` = note: required for `HashMap` to implement `Index<&&str>` diff --git a/tests/ui/integral-indexing.stderr b/tests/ui/integral-indexing.stderr index 97e658617cf..f731d303774 100644 --- a/tests/ui/integral-indexing.stderr +++ b/tests/ui/integral-indexing.stderr @@ -5,7 +5,8 @@ LL | v[3u8]; | ^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `u8` - = help: the trait `SliceIndex<[isize]>` is implemented for `usize` + = help: the trait `SliceIndex<[isize]>` is not implemented for `u8` + but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `u8` = note: required for `Vec` to implement `Index` @@ -16,7 +17,8 @@ LL | v[3i8]; | ^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `i8` - = help: the trait `SliceIndex<[isize]>` is implemented for `usize` + = help: the trait `SliceIndex<[isize]>` is not implemented for `i8` + but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `i8` = note: required for `Vec` to implement `Index` @@ -27,7 +29,8 @@ LL | v[3u32]; | ^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `u32` - = help: the trait `SliceIndex<[isize]>` is implemented for `usize` + = help: the trait `SliceIndex<[isize]>` is not implemented for `u32` + but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `u32` = note: required for `Vec` to implement `Index` @@ -38,7 +41,8 @@ LL | v[3i32]; | ^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `i32` - = help: the trait `SliceIndex<[isize]>` is implemented for `usize` + = help: the trait `SliceIndex<[isize]>` is not implemented for `i32` + but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `i32` = note: required for `Vec` to implement `Index` @@ -49,7 +53,8 @@ LL | s.as_bytes()[3u8]; | ^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[u8]>` is not implemented for `u8` - = help: the trait `SliceIndex<[u8]>` is implemented for `usize` + = help: the trait `SliceIndex<[u8]>` is not implemented for `u8` + but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `u8` = note: required for `[u8]` to implement `Index` @@ -60,7 +65,8 @@ LL | s.as_bytes()[3i8]; | ^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[u8]>` is not implemented for `i8` - = help: the trait `SliceIndex<[u8]>` is implemented for `usize` + = help: the trait `SliceIndex<[u8]>` is not implemented for `i8` + but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `i8` = note: required for `[u8]` to implement `Index` @@ -71,7 +77,8 @@ LL | s.as_bytes()[3u32]; | ^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[u8]>` is not implemented for `u32` - = help: the trait `SliceIndex<[u8]>` is implemented for `usize` + = help: the trait `SliceIndex<[u8]>` is not implemented for `u32` + but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `u32` = note: required for `[u8]` to implement `Index` @@ -82,7 +89,8 @@ LL | s.as_bytes()[3i32]; | ^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[u8]>` is not implemented for `i32` - = help: the trait `SliceIndex<[u8]>` is implemented for `usize` + = help: the trait `SliceIndex<[u8]>` is not implemented for `i32` + but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `i32` = note: required for `[u8]` to implement `Index` diff --git a/tests/ui/issues/issue-34334.stderr b/tests/ui/issues/issue-34334.stderr index e14629f5f3a..8213136faa1 100644 --- a/tests/ui/issues/issue-34334.stderr +++ b/tests/ui/issues/issue-34334.stderr @@ -18,7 +18,8 @@ LL | let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_rece | ^^^^^^^ value of type `Vec<(u32, _, _)>` cannot be built from `std::iter::Iterator` | = help: the trait `FromIterator<()>` is not implemented for `Vec<(u32, _, _)>` - = help: the trait `FromIterator<(u32, _, _)>` is implemented for `Vec<(u32, _, _)>` + = help: the trait `FromIterator<()>` is not implemented for `Vec<(u32, _, _)>` + but trait `FromIterator<(u32, _, _)>` is implemented for it = help: for that trait implementation, expected `(u32, _, _)`, found `()` note: the method call chain might not have had the expected associated types --> $DIR/issue-34334.rs:5:43 diff --git a/tests/ui/issues/issue-45801.stderr b/tests/ui/issues/issue-45801.stderr index 5a10c429564..940c1865fa3 100644 --- a/tests/ui/issues/issue-45801.stderr +++ b/tests/ui/issues/issue-45801.stderr @@ -4,7 +4,8 @@ error[E0277]: the trait bound `Params: Plugin` is not satisfied LL | req.get_ref::(); | ^^^^^^^ the trait `Plugin` is not implemented for `Params` | - = help: the trait `Plugin` is implemented for `Params` + = help: the trait `Plugin` is not implemented for `Params` + but trait `Plugin` is implemented for it = help: for that trait implementation, expected `Foo`, found `i32` error: aborting due to 1 previous error diff --git a/tests/ui/issues/issue-66923-show-error-for-correct-call.stderr b/tests/ui/issues/issue-66923-show-error-for-correct-call.stderr index 128288e28f5..e62be48edf6 100644 --- a/tests/ui/issues/issue-66923-show-error-for-correct-call.stderr +++ b/tests/ui/issues/issue-66923-show-error-for-correct-call.stderr @@ -5,7 +5,8 @@ LL | let x2: Vec = x1.into_iter().collect(); | ^^^^^^^ value of type `Vec` cannot be built from `std::iter::Iterator` | = help: the trait `FromIterator<&f64>` is not implemented for `Vec` - = help: the trait `FromIterator` is implemented for `Vec` + = help: the trait `FromIterator<&_>` is not implemented for `Vec` + but trait `FromIterator<_>` is implemented for it = help: for that trait implementation, expected `f64`, found `&f64` note: the method call chain might not have had the expected associated types --> $DIR/issue-66923-show-error-for-correct-call.rs:8:27 @@ -26,7 +27,8 @@ LL | let x3 = x1.into_iter().collect::>(); | required by a bound introduced by this call | = help: the trait `FromIterator<&f64>` is not implemented for `Vec` - = help: the trait `FromIterator` is implemented for `Vec` + = help: the trait `FromIterator<&_>` is not implemented for `Vec` + but trait `FromIterator<_>` is implemented for it = help: for that trait implementation, expected `f64`, found `&f64` note: the method call chain might not have had the expected associated types --> $DIR/issue-66923-show-error-for-correct-call.rs:12:17 diff --git a/tests/ui/iterators/invalid-iterator-chain-fixable.stderr b/tests/ui/iterators/invalid-iterator-chain-fixable.stderr index 3d3bbab8819..d6f82741c4c 100644 --- a/tests/ui/iterators/invalid-iterator-chain-fixable.stderr +++ b/tests/ui/iterators/invalid-iterator-chain-fixable.stderr @@ -7,7 +7,8 @@ LL | i.collect() | ^^^^^^^ value of type `Vec` cannot be built from `std::iter::Iterator` | = help: the trait `FromIterator<&X>` is not implemented for `Vec` - = help: the trait `FromIterator` is implemented for `Vec` + = help: the trait `FromIterator<&_>` is not implemented for `Vec` + but trait `FromIterator<_>` is implemented for it = help: for that trait implementation, expected `X`, found `&X` note: the method call chain might not have had the expected associated types --> $DIR/invalid-iterator-chain-fixable.rs:5:26 @@ -124,7 +125,8 @@ LL | let g: Vec = f.collect(); | ^^^^^^^ value of type `Vec` cannot be built from `std::iter::Iterator` | = help: the trait `FromIterator<()>` is not implemented for `Vec` - = help: the trait `FromIterator` is implemented for `Vec` + = help: the trait `FromIterator<()>` is not implemented for `Vec` + but trait `FromIterator` is implemented for it = help: for that trait implementation, expected `i32`, found `()` note: the method call chain might not have had the expected associated types --> $DIR/invalid-iterator-chain-fixable.rs:32:15 diff --git a/tests/ui/iterators/invalid-iterator-chain.stderr b/tests/ui/iterators/invalid-iterator-chain.stderr index bc35fcd489d..2522471b3b5 100644 --- a/tests/ui/iterators/invalid-iterator-chain.stderr +++ b/tests/ui/iterators/invalid-iterator-chain.stderr @@ -7,7 +7,8 @@ LL | i.collect() | ^^^^^^^ value of type `Vec` cannot be built from `std::iter::Iterator` | = help: the trait `FromIterator<&X>` is not implemented for `Vec` - = help: the trait `FromIterator` is implemented for `Vec` + = help: the trait `FromIterator<&_>` is not implemented for `Vec` + but trait `FromIterator<_>` is implemented for it = help: for that trait implementation, expected `X`, found `&X` note: the method call chain might not have had the expected associated types --> $DIR/invalid-iterator-chain.rs:4:26 @@ -181,7 +182,8 @@ LL | let g: Vec = f.collect(); | ^^^^^^^ value of type `Vec` cannot be built from `std::iter::Iterator` | = help: the trait `FromIterator<()>` is not implemented for `Vec` - = help: the trait `FromIterator` is implemented for `Vec` + = help: the trait `FromIterator<()>` is not implemented for `Vec` + but trait `FromIterator` is implemented for it = help: for that trait implementation, expected `i32`, found `()` note: the method call chain might not have had the expected associated types --> $DIR/invalid-iterator-chain.rs:44:15 diff --git a/tests/ui/never_type/from_infer_breaking_with_unit_fallback.unit.stderr b/tests/ui/never_type/from_infer_breaking_with_unit_fallback.unit.stderr index 3b8913ccf45..9eacab9a0b7 100644 --- a/tests/ui/never_type/from_infer_breaking_with_unit_fallback.unit.stderr +++ b/tests/ui/never_type/from_infer_breaking_with_unit_fallback.unit.stderr @@ -4,7 +4,8 @@ error[E0277]: the trait bound `E: From<()>` is not satisfied LL | >::from(never); // Should the inference fail? | ^ the trait `From<()>` is not implemented for `E` | - = help: the trait `From` is implemented for `E` + = help: the trait `From<()>` is not implemented for `E` + but trait `From` is implemented for it = help: for that trait implementation, expected `!`, found `()` error: aborting due to 1 previous error diff --git a/tests/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr b/tests/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr index f5249814c78..d6234c8e7e1 100644 --- a/tests/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr +++ b/tests/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr @@ -4,7 +4,8 @@ error[E0277]: the trait bound `E: From<()>` is not satisfied LL | >::from(never); | ^ the trait `From<()>` is not implemented for `E` | - = help: the trait `From` is implemented for `E` + = help: the trait `From<()>` is not implemented for `E` + but trait `From` is implemented for it = help: for that trait implementation, expected `!`, found `()` error: aborting due to 1 previous error diff --git a/tests/ui/on-unimplemented/impl-substs.stderr b/tests/ui/on-unimplemented/impl-substs.stderr index e2ba2474d6c..cdb9172ef0f 100644 --- a/tests/ui/on-unimplemented/impl-substs.stderr +++ b/tests/ui/on-unimplemented/impl-substs.stderr @@ -7,7 +7,8 @@ LL | Foo::::foo((1i32, 1i32, 1i32)); | required by a bound introduced by this call | = help: the trait `Foo` is not implemented for `(i32, i32, i32)` - = help: the trait `Foo` is implemented for `(i32, i32, i32)` + = help: the trait `Foo` is not implemented for `(i32, i32, i32)` + but trait `Foo` is implemented for it = help: for that trait implementation, expected `i32`, found `usize` error: aborting due to 1 previous error diff --git a/tests/ui/on-unimplemented/on-impl.stderr b/tests/ui/on-unimplemented/on-impl.stderr index c7d2a78af6c..d20b559def7 100644 --- a/tests/ui/on-unimplemented/on-impl.stderr +++ b/tests/ui/on-unimplemented/on-impl.stderr @@ -7,7 +7,8 @@ LL | Index::::index(&[1, 2, 3] as &[i32], 2u32); | required by a bound introduced by this call | = help: the trait `Index` is not implemented for `[i32]` - = help: the trait `Index` is implemented for `[i32]` + = help: the trait `Index` is not implemented for `[i32]` + but trait `Index` is implemented for it = help: for that trait implementation, expected `usize`, found `u32` error[E0277]: the trait bound `[i32]: Index` is not satisfied @@ -17,7 +18,8 @@ LL | Index::::index(&[1, 2, 3] as &[i32], 2u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ a usize is required to index into a slice | = help: the trait `Index` is not implemented for `[i32]` - = help: the trait `Index` is implemented for `[i32]` + = help: the trait `Index` is not implemented for `[i32]` + but trait `Index` is implemented for it = help: for that trait implementation, expected `usize`, found `u32` error: aborting due to 2 previous errors diff --git a/tests/ui/on-unimplemented/slice-index.stderr b/tests/ui/on-unimplemented/slice-index.stderr index d53ecb9db0c..8f7169b30d4 100644 --- a/tests/ui/on-unimplemented/slice-index.stderr +++ b/tests/ui/on-unimplemented/slice-index.stderr @@ -5,7 +5,8 @@ LL | x[1i32]; | ^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[i32]>` is not implemented for `i32` - = help: the trait `SliceIndex<[i32]>` is implemented for `usize` + = help: the trait `SliceIndex<[i32]>` is not implemented for `i32` + but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `i32` = note: required for `[i32]` to implement `Index` diff --git a/tests/ui/str/str-idx.stderr b/tests/ui/str/str-idx.stderr index e8bbb8058fa..0ce0c207561 100644 --- a/tests/ui/str/str-idx.stderr +++ b/tests/ui/str/str-idx.stderr @@ -7,7 +7,8 @@ LL | let _: u8 = s[4]; = help: the trait `SliceIndex` is not implemented for `{integer}` = note: you can use `.chars().nth()` or `.bytes().nth()` for more information, see chapter 8 in The Book: - = help: the trait `SliceIndex<[_]>` is implemented for `usize` + = help: the trait `SliceIndex` is not implemented for `{integer}` + but trait `SliceIndex<[_]>` is implemented for `usize` = help: for that trait implementation, expected `[_]`, found `str` = note: required for `str` to implement `Index<{integer}>` @@ -22,7 +23,8 @@ LL | let _ = s.get(4); = help: the trait `SliceIndex` is not implemented for `{integer}` = note: you can use `.chars().nth()` or `.bytes().nth()` for more information, see chapter 8 in The Book: - = help: the trait `SliceIndex<[_]>` is implemented for `usize` + = help: the trait `SliceIndex` is not implemented for `{integer}` + but trait `SliceIndex<[_]>` is implemented for `usize` = help: for that trait implementation, expected `[_]`, found `str` note: required by a bound in `core::str::::get` --> $SRC_DIR/core/src/str/mod.rs:LL:COL @@ -38,7 +40,8 @@ LL | let _ = s.get_unchecked(4); = help: the trait `SliceIndex` is not implemented for `{integer}` = note: you can use `.chars().nth()` or `.bytes().nth()` for more information, see chapter 8 in The Book: - = help: the trait `SliceIndex<[_]>` is implemented for `usize` + = help: the trait `SliceIndex` is not implemented for `{integer}` + but trait `SliceIndex<[_]>` is implemented for `usize` = help: for that trait implementation, expected `[_]`, found `str` note: required by a bound in `core::str::::get_unchecked` --> $SRC_DIR/core/src/str/mod.rs:LL:COL diff --git a/tests/ui/str/str-mut-idx.stderr b/tests/ui/str/str-mut-idx.stderr index 9390d689252..7bc46ff33b3 100644 --- a/tests/ui/str/str-mut-idx.stderr +++ b/tests/ui/str/str-mut-idx.stderr @@ -31,7 +31,8 @@ LL | s[1usize] = bot(); | ^^^^^^ string indices are ranges of `usize` | = help: the trait `SliceIndex` is not implemented for `usize` - = help: the trait `SliceIndex<[_]>` is implemented for `usize` + = help: the trait `SliceIndex` is not implemented for `usize` + but trait `SliceIndex<[_]>` is implemented for it = help: for that trait implementation, expected `[_]`, found `str` = note: required for `str` to implement `Index` @@ -46,7 +47,8 @@ LL | s.get_mut(1); = help: the trait `SliceIndex` is not implemented for `{integer}` = note: you can use `.chars().nth()` or `.bytes().nth()` for more information, see chapter 8 in The Book: - = help: the trait `SliceIndex<[_]>` is implemented for `usize` + = help: the trait `SliceIndex` is not implemented for `{integer}` + but trait `SliceIndex<[_]>` is implemented for `usize` = help: for that trait implementation, expected `[_]`, found `str` note: required by a bound in `core::str::::get_mut` --> $SRC_DIR/core/src/str/mod.rs:LL:COL @@ -62,7 +64,8 @@ LL | s.get_unchecked_mut(1); = help: the trait `SliceIndex` is not implemented for `{integer}` = note: you can use `.chars().nth()` or `.bytes().nth()` for more information, see chapter 8 in The Book: - = help: the trait `SliceIndex<[_]>` is implemented for `usize` + = help: the trait `SliceIndex` is not implemented for `{integer}` + but trait `SliceIndex<[_]>` is implemented for `usize` = help: for that trait implementation, expected `[_]`, found `str` note: required by a bound in `core::str::::get_unchecked_mut` --> $SRC_DIR/core/src/str/mod.rs:LL:COL diff --git a/tests/ui/suggestions/issue-101623.stderr b/tests/ui/suggestions/issue-101623.stderr index 4de91a1b995..0733e67ea02 100644 --- a/tests/ui/suggestions/issue-101623.stderr +++ b/tests/ui/suggestions/issue-101623.stderr @@ -7,7 +7,8 @@ LL | Trait::do_stuff({ fun(&mut *inner) }); | | the trait `Trait<'_>` is not implemented for `*mut ()` | required by a bound introduced by this call | - = help: the trait `Trait<'_>` is implemented for `()` + = help: the trait `Trait<'_>` is not implemented for `*mut ()` + but it is implemented for `()` = help: for that trait implementation, expected `()`, found `*mut ()` error: aborting due to 1 previous error diff --git a/tests/ui/suggestions/suggest-dereferencing-index.stderr b/tests/ui/suggestions/suggest-dereferencing-index.stderr index 2316acbe9da..cd5364fcffb 100644 --- a/tests/ui/suggestions/suggest-dereferencing-index.stderr +++ b/tests/ui/suggestions/suggest-dereferencing-index.stderr @@ -5,7 +5,8 @@ LL | let one_item_please: i32 = [1, 2, 3][i]; | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[{integer}]>` is not implemented for `&usize` - = help: the trait `SliceIndex<[{integer}]>` is implemented for `usize` + = help: the trait `SliceIndex<[{integer}]>` is not implemented for `&_` + but it is implemented for `_` = help: for that trait implementation, expected `usize`, found `&usize` = note: required for `[{integer}]` to implement `Index<&usize>` = note: 1 redundant requirement hidden diff --git a/tests/ui/traits/coercion-generic-bad.stderr b/tests/ui/traits/coercion-generic-bad.stderr index 26136c6f72c..c0553ea62c5 100644 --- a/tests/ui/traits/coercion-generic-bad.stderr +++ b/tests/ui/traits/coercion-generic-bad.stderr @@ -4,7 +4,8 @@ error[E0277]: the trait bound `Struct: Trait` is not satisfied LL | let s: Box> = Box::new(Struct { person: "Fred" }); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `Struct` | - = help: the trait `Trait<&'static str>` is implemented for `Struct` + = help: the trait `Trait` is not implemented for `Struct` + but trait `Trait<&'static str>` is implemented for it = help: for that trait implementation, expected `&'static str`, found `isize` = note: required for the cast from `Box` to `Box>` diff --git a/tests/ui/traits/negative-bounds/simple.stderr b/tests/ui/traits/negative-bounds/simple.stderr index b8d12138794..f8a43e605c4 100644 --- a/tests/ui/traits/negative-bounds/simple.stderr +++ b/tests/ui/traits/negative-bounds/simple.stderr @@ -28,7 +28,8 @@ error[E0277]: the trait bound `Copyable: !Copy` is not satisfied LL | not_copy::(); | ^^^^^^^^ the trait bound `Copyable: !Copy` is not satisfied | - = help: the trait `Copy` is implemented for `Copyable` + = help: the trait `Copy` is not implemented for `Copyable` + but trait `Copy` is implemented for it note: required by a bound in `not_copy` --> $DIR/simple.rs:3:16 | diff --git a/tests/ui/try-block/try-block-bad-type.stderr b/tests/ui/try-block/try-block-bad-type.stderr index d94962e4031..c67ad762a83 100644 --- a/tests/ui/try-block/try-block-bad-type.stderr +++ b/tests/ui/try-block/try-block-bad-type.stderr @@ -7,7 +7,8 @@ LL | Err("")?; | this can't be annotated with `?` because it has type `Result<_, &str>` | = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait - = help: the trait `From` is implemented for `TryFromSliceError` + = help: the trait `From<&str>` is not implemented for `TryFromSliceError` + but trait `From` is implemented for it = help: for that trait implementation, expected `Infallible`, found `&str` = note: required for `Result` to implement `FromResidual>` diff --git a/tests/ui/try-trait/bad-interconversion.stderr b/tests/ui/try-trait/bad-interconversion.stderr index fe28912ba00..20fe2d721bc 100644 --- a/tests/ui/try-trait/bad-interconversion.stderr +++ b/tests/ui/try-trait/bad-interconversion.stderr @@ -67,7 +67,8 @@ LL | ControlFlow::Continue(Err("hello")?) | ^ this `?` produces `Result`, which is incompatible with `ControlFlow` | = help: the trait `FromResidual>` is not implemented for `ControlFlow` - = help: the trait `FromResidual>` is implemented for `ControlFlow` + = help: the trait `FromResidual>` is not implemented for `ControlFlow` + but trait `FromResidual>` is implemented for it = help: for that trait implementation, expected `ControlFlow`, found `Result` error[E0277]: the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow` @@ -79,7 +80,8 @@ LL | Some(3)?; | ^ this `?` produces `Option`, which is incompatible with `ControlFlow` | = help: the trait `FromResidual>` is not implemented for `ControlFlow` - = help: the trait `FromResidual>` is implemented for `ControlFlow` + = help: the trait `FromResidual>` is not implemented for `ControlFlow` + but trait `FromResidual>` is implemented for it = help: for that trait implementation, expected `ControlFlow`, found `Option` error[E0277]: the `?` operator in a function that returns `ControlFlow` can only be used on other `ControlFlow`s (with the same Break type) @@ -92,7 +94,8 @@ LL | ControlFlow::Break(4_u8)?; | = help: the trait `FromResidual>` is not implemented for `ControlFlow` = note: unlike `Result`, there's no `From`-conversion performed for `ControlFlow` - = help: the trait `FromResidual>` is implemented for `ControlFlow` + = help: the trait `FromResidual>` is not implemented for `ControlFlow` + but trait `FromResidual>` is implemented for it = help: for that trait implementation, expected `i64`, found `u8` error: aborting due to 8 previous errors diff --git a/tests/ui/type-alias-impl-trait/constrain_in_projection.current.stderr b/tests/ui/type-alias-impl-trait/constrain_in_projection.current.stderr index c215d197db4..d96c86a2e6f 100644 --- a/tests/ui/type-alias-impl-trait/constrain_in_projection.current.stderr +++ b/tests/ui/type-alias-impl-trait/constrain_in_projection.current.stderr @@ -4,7 +4,8 @@ error[E0277]: the trait bound `Foo: Trait` is not satisfied LL | let x = >::Assoc::default(); | ^^^ the trait `Trait` is not implemented for `Foo` | - = help: the trait `Trait<()>` is implemented for `Foo` + = help: the trait `Trait` is not implemented for `Foo` + but trait `Trait<()>` is implemented for it error: aborting due to 1 previous error diff --git a/tests/ui/type-alias-impl-trait/nested-tait-inference.current.stderr b/tests/ui/type-alias-impl-trait/nested-tait-inference.current.stderr index 34532afcbba..915432bbe67 100644 --- a/tests/ui/type-alias-impl-trait/nested-tait-inference.current.stderr +++ b/tests/ui/type-alias-impl-trait/nested-tait-inference.current.stderr @@ -7,7 +7,8 @@ LL | fn foo() -> impl Foo { LL | () | -- return type was inferred to be `()` here | - = help: the trait `Foo<()>` is implemented for `()` + = help: the trait `Foo` is not implemented for `()` + but trait `Foo<()>` is implemented for it error: aborting due to 1 previous error diff --git a/tests/ui/type-alias-impl-trait/self-referential-2.current.stderr b/tests/ui/type-alias-impl-trait/self-referential-2.current.stderr index 3ae3590ca7f..1e799f15635 100644 --- a/tests/ui/type-alias-impl-trait/self-referential-2.current.stderr +++ b/tests/ui/type-alias-impl-trait/self-referential-2.current.stderr @@ -7,7 +7,8 @@ LL | 42_i32 | ------ return type was inferred to be `i32` here | = help: the trait `PartialEq` is not implemented for `i32` - = help: the trait `PartialEq` is implemented for `i32` + = help: the trait `PartialEq` is not implemented for `i32` + but trait `PartialEq` is implemented for it error: aborting due to 1 previous error diff --git a/tests/ui/typeck/suggest-similar-impls-for-root-obligation.stderr b/tests/ui/typeck/suggest-similar-impls-for-root-obligation.stderr index ab307aadec9..5c0d98735f7 100644 --- a/tests/ui/typeck/suggest-similar-impls-for-root-obligation.stderr +++ b/tests/ui/typeck/suggest-similar-impls-for-root-obligation.stderr @@ -4,7 +4,8 @@ error[E0277]: the trait bound `((),): Into` is not satisfied LL | let _: Bar = ((),).into(); | ^^^^ the trait `Foo<'_>` is not implemented for `((),)` | - = help: the trait `Foo<'_>` is implemented for `()` + = help: the trait `Foo<'_>` is not implemented for `((),)` + but it is implemented for `()` = help: for that trait implementation, expected `()`, found `((),)` note: required for `Bar` to implement `From<((),)>` --> $DIR/suggest-similar-impls-for-root-obligation.rs:7:22 From 7b9105dd8865ef10ef8d5f2f7bc3da180aec9dd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 24 Oct 2024 22:38:50 +0000 Subject: [PATCH 02/13] Trim output of E0277 in some cases Remove default note for "trait is not implemented" in favor of the more colorful diff output from the previous commit. Removes duplicated output. --- .../traits/fulfillment_errors.rs | 20 +++++++++++++++++-- tests/ui/indexing/index-help.stderr | 1 - .../indexing/indexing-requires-a-uint.stderr | 1 - tests/ui/integral-indexing.stderr | 8 -------- tests/ui/issues/issue-34334.stderr | 1 - ...e-66923-show-error-for-correct-call.stderr | 2 -- .../invalid-iterator-chain-fixable.stderr | 2 -- .../iterators/invalid-iterator-chain.stderr | 2 -- tests/ui/on-unimplemented/impl-substs.stderr | 1 - tests/ui/on-unimplemented/on-impl.stderr | 2 -- tests/ui/on-unimplemented/slice-index.stderr | 1 - tests/ui/str/str-idx.stderr | 3 --- tests/ui/str/str-mut-idx.stderr | 3 --- .../suggest-dereferencing-index.stderr | 1 - tests/ui/try-trait/bad-interconversion.stderr | 3 --- .../self-referential-2.current.stderr | 1 - 16 files changed, 18 insertions(+), 34 deletions(-) diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index 358c244eca9..dd2f0ec2096 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -6,8 +6,8 @@ use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::unord::UnordSet; use rustc_errors::codes::*; use rustc_errors::{ - Applicability, Diag, ErrorGuaranteed, MultiSpan, StashKey, StringPart, Suggestions, pluralize, - struct_span_code_err, + Applicability, Diag, ErrorGuaranteed, Level, MultiSpan, StashKey, StringPart, Suggestions, + pluralize, struct_span_code_err, }; use rustc_hir::def::Namespace; use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId}; @@ -1833,6 +1833,22 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { return false; } + if let [child, ..] = &err.children[..] + && child.level == Level::Help + && let Some(line) = child.messages.get(0) + && let Some(line) = line.0.as_str() + && line.starts_with("the trait") + && line.contains("is not implemented for") + { + // HACK(estebank): we remove the pre-existing + // "the trait `X` is not implemented for" note, which only happens if there + // was a custom label. We do this because we want that note to always be the + // first, and making this logic run earlier will get tricky. For now, we + // instead keep the logic the same and modify the already constructed error + // to avoid the wording duplication. + err.children.remove(0); + } + let traits = self.cmp_traits( obligation_trait_ref.def_id, &obligation_trait_ref.args[1..], diff --git a/tests/ui/indexing/index-help.stderr b/tests/ui/indexing/index-help.stderr index d4637da1426..1974e13eabc 100644 --- a/tests/ui/indexing/index-help.stderr +++ b/tests/ui/indexing/index-help.stderr @@ -4,7 +4,6 @@ error[E0277]: the type `[{integer}]` cannot be indexed by `i32` LL | x[0i32]; | ^^^^ slice indices are of type `usize` or ranges of `usize` | - = help: the trait `SliceIndex<[{integer}]>` is not implemented for `i32` = help: the trait `SliceIndex<[{integer}]>` is not implemented for `i32` but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `i32` diff --git a/tests/ui/indexing/indexing-requires-a-uint.stderr b/tests/ui/indexing/indexing-requires-a-uint.stderr index fdcf9b030a5..5c60a30946d 100644 --- a/tests/ui/indexing/indexing-requires-a-uint.stderr +++ b/tests/ui/indexing/indexing-requires-a-uint.stderr @@ -4,7 +4,6 @@ error[E0277]: the type `[{integer}]` cannot be indexed by `u8` LL | [0][0u8]; | ^^^ slice indices are of type `usize` or ranges of `usize` | - = help: the trait `SliceIndex<[{integer}]>` is not implemented for `u8` = help: the trait `SliceIndex<[{integer}]>` is not implemented for `u8` but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `u8` diff --git a/tests/ui/integral-indexing.stderr b/tests/ui/integral-indexing.stderr index f731d303774..e7a45c2c88d 100644 --- a/tests/ui/integral-indexing.stderr +++ b/tests/ui/integral-indexing.stderr @@ -4,7 +4,6 @@ error[E0277]: the type `[isize]` cannot be indexed by `u8` LL | v[3u8]; | ^^^ slice indices are of type `usize` or ranges of `usize` | - = help: the trait `SliceIndex<[isize]>` is not implemented for `u8` = help: the trait `SliceIndex<[isize]>` is not implemented for `u8` but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `u8` @@ -16,7 +15,6 @@ error[E0277]: the type `[isize]` cannot be indexed by `i8` LL | v[3i8]; | ^^^ slice indices are of type `usize` or ranges of `usize` | - = help: the trait `SliceIndex<[isize]>` is not implemented for `i8` = help: the trait `SliceIndex<[isize]>` is not implemented for `i8` but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `i8` @@ -28,7 +26,6 @@ error[E0277]: the type `[isize]` cannot be indexed by `u32` LL | v[3u32]; | ^^^^ slice indices are of type `usize` or ranges of `usize` | - = help: the trait `SliceIndex<[isize]>` is not implemented for `u32` = help: the trait `SliceIndex<[isize]>` is not implemented for `u32` but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `u32` @@ -40,7 +37,6 @@ error[E0277]: the type `[isize]` cannot be indexed by `i32` LL | v[3i32]; | ^^^^ slice indices are of type `usize` or ranges of `usize` | - = help: the trait `SliceIndex<[isize]>` is not implemented for `i32` = help: the trait `SliceIndex<[isize]>` is not implemented for `i32` but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `i32` @@ -52,7 +48,6 @@ error[E0277]: the type `[u8]` cannot be indexed by `u8` LL | s.as_bytes()[3u8]; | ^^^ slice indices are of type `usize` or ranges of `usize` | - = help: the trait `SliceIndex<[u8]>` is not implemented for `u8` = help: the trait `SliceIndex<[u8]>` is not implemented for `u8` but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `u8` @@ -64,7 +59,6 @@ error[E0277]: the type `[u8]` cannot be indexed by `i8` LL | s.as_bytes()[3i8]; | ^^^ slice indices are of type `usize` or ranges of `usize` | - = help: the trait `SliceIndex<[u8]>` is not implemented for `i8` = help: the trait `SliceIndex<[u8]>` is not implemented for `i8` but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `i8` @@ -76,7 +70,6 @@ error[E0277]: the type `[u8]` cannot be indexed by `u32` LL | s.as_bytes()[3u32]; | ^^^^ slice indices are of type `usize` or ranges of `usize` | - = help: the trait `SliceIndex<[u8]>` is not implemented for `u32` = help: the trait `SliceIndex<[u8]>` is not implemented for `u32` but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `u32` @@ -88,7 +81,6 @@ error[E0277]: the type `[u8]` cannot be indexed by `i32` LL | s.as_bytes()[3i32]; | ^^^^ slice indices are of type `usize` or ranges of `usize` | - = help: the trait `SliceIndex<[u8]>` is not implemented for `i32` = help: the trait `SliceIndex<[u8]>` is not implemented for `i32` but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `i32` diff --git a/tests/ui/issues/issue-34334.stderr b/tests/ui/issues/issue-34334.stderr index 8213136faa1..6562ccfdcd2 100644 --- a/tests/ui/issues/issue-34334.stderr +++ b/tests/ui/issues/issue-34334.stderr @@ -17,7 +17,6 @@ error[E0277]: a value of type `Vec<(u32, _, _)>` cannot be built from an iterato LL | let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_receiver)| {}).collect(); | ^^^^^^^ value of type `Vec<(u32, _, _)>` cannot be built from `std::iter::Iterator` | - = help: the trait `FromIterator<()>` is not implemented for `Vec<(u32, _, _)>` = help: the trait `FromIterator<()>` is not implemented for `Vec<(u32, _, _)>` but trait `FromIterator<(u32, _, _)>` is implemented for it = help: for that trait implementation, expected `(u32, _, _)`, found `()` diff --git a/tests/ui/issues/issue-66923-show-error-for-correct-call.stderr b/tests/ui/issues/issue-66923-show-error-for-correct-call.stderr index e62be48edf6..d2852093725 100644 --- a/tests/ui/issues/issue-66923-show-error-for-correct-call.stderr +++ b/tests/ui/issues/issue-66923-show-error-for-correct-call.stderr @@ -4,7 +4,6 @@ error[E0277]: a value of type `Vec` cannot be built from an iterator over e LL | let x2: Vec = x1.into_iter().collect(); | ^^^^^^^ value of type `Vec` cannot be built from `std::iter::Iterator` | - = help: the trait `FromIterator<&f64>` is not implemented for `Vec` = help: the trait `FromIterator<&_>` is not implemented for `Vec` but trait `FromIterator<_>` is implemented for it = help: for that trait implementation, expected `f64`, found `&f64` @@ -26,7 +25,6 @@ LL | let x3 = x1.into_iter().collect::>(); | | | required by a bound introduced by this call | - = help: the trait `FromIterator<&f64>` is not implemented for `Vec` = help: the trait `FromIterator<&_>` is not implemented for `Vec` but trait `FromIterator<_>` is implemented for it = help: for that trait implementation, expected `f64`, found `&f64` diff --git a/tests/ui/iterators/invalid-iterator-chain-fixable.stderr b/tests/ui/iterators/invalid-iterator-chain-fixable.stderr index d6f82741c4c..09439fe8fbd 100644 --- a/tests/ui/iterators/invalid-iterator-chain-fixable.stderr +++ b/tests/ui/iterators/invalid-iterator-chain-fixable.stderr @@ -6,7 +6,6 @@ LL | let i = i.map(|x| x.clone()); LL | i.collect() | ^^^^^^^ value of type `Vec` cannot be built from `std::iter::Iterator` | - = help: the trait `FromIterator<&X>` is not implemented for `Vec` = help: the trait `FromIterator<&_>` is not implemented for `Vec` but trait `FromIterator<_>` is implemented for it = help: for that trait implementation, expected `X`, found `&X` @@ -124,7 +123,6 @@ error[E0277]: a value of type `Vec` cannot be built from an iterator over e LL | let g: Vec = f.collect(); | ^^^^^^^ value of type `Vec` cannot be built from `std::iter::Iterator` | - = help: the trait `FromIterator<()>` is not implemented for `Vec` = help: the trait `FromIterator<()>` is not implemented for `Vec` but trait `FromIterator` is implemented for it = help: for that trait implementation, expected `i32`, found `()` diff --git a/tests/ui/iterators/invalid-iterator-chain.stderr b/tests/ui/iterators/invalid-iterator-chain.stderr index 2522471b3b5..b810e06d0f7 100644 --- a/tests/ui/iterators/invalid-iterator-chain.stderr +++ b/tests/ui/iterators/invalid-iterator-chain.stderr @@ -6,7 +6,6 @@ LL | let i = i.map(|x| x.clone()); LL | i.collect() | ^^^^^^^ value of type `Vec` cannot be built from `std::iter::Iterator` | - = help: the trait `FromIterator<&X>` is not implemented for `Vec` = help: the trait `FromIterator<&_>` is not implemented for `Vec` but trait `FromIterator<_>` is implemented for it = help: for that trait implementation, expected `X`, found `&X` @@ -181,7 +180,6 @@ error[E0277]: a value of type `Vec` cannot be built from an iterator over e LL | let g: Vec = f.collect(); | ^^^^^^^ value of type `Vec` cannot be built from `std::iter::Iterator` | - = help: the trait `FromIterator<()>` is not implemented for `Vec` = help: the trait `FromIterator<()>` is not implemented for `Vec` but trait `FromIterator` is implemented for it = help: for that trait implementation, expected `i32`, found `()` diff --git a/tests/ui/on-unimplemented/impl-substs.stderr b/tests/ui/on-unimplemented/impl-substs.stderr index cdb9172ef0f..b85d45eba5b 100644 --- a/tests/ui/on-unimplemented/impl-substs.stderr +++ b/tests/ui/on-unimplemented/impl-substs.stderr @@ -6,7 +6,6 @@ LL | Foo::::foo((1i32, 1i32, 1i32)); | | | required by a bound introduced by this call | - = help: the trait `Foo` is not implemented for `(i32, i32, i32)` = help: the trait `Foo` is not implemented for `(i32, i32, i32)` but trait `Foo` is implemented for it = help: for that trait implementation, expected `i32`, found `usize` diff --git a/tests/ui/on-unimplemented/on-impl.stderr b/tests/ui/on-unimplemented/on-impl.stderr index d20b559def7..5e7e2c4ea77 100644 --- a/tests/ui/on-unimplemented/on-impl.stderr +++ b/tests/ui/on-unimplemented/on-impl.stderr @@ -6,7 +6,6 @@ LL | Index::::index(&[1, 2, 3] as &[i32], 2u32); | | | required by a bound introduced by this call | - = help: the trait `Index` is not implemented for `[i32]` = help: the trait `Index` is not implemented for `[i32]` but trait `Index` is implemented for it = help: for that trait implementation, expected `usize`, found `u32` @@ -17,7 +16,6 @@ error[E0277]: the trait bound `[i32]: Index` is not satisfied LL | Index::::index(&[1, 2, 3] as &[i32], 2u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ a usize is required to index into a slice | - = help: the trait `Index` is not implemented for `[i32]` = help: the trait `Index` is not implemented for `[i32]` but trait `Index` is implemented for it = help: for that trait implementation, expected `usize`, found `u32` diff --git a/tests/ui/on-unimplemented/slice-index.stderr b/tests/ui/on-unimplemented/slice-index.stderr index 8f7169b30d4..0a9ebe3f088 100644 --- a/tests/ui/on-unimplemented/slice-index.stderr +++ b/tests/ui/on-unimplemented/slice-index.stderr @@ -4,7 +4,6 @@ error[E0277]: the type `[i32]` cannot be indexed by `i32` LL | x[1i32]; | ^^^^ slice indices are of type `usize` or ranges of `usize` | - = help: the trait `SliceIndex<[i32]>` is not implemented for `i32` = help: the trait `SliceIndex<[i32]>` is not implemented for `i32` but it is implemented for `usize` = help: for that trait implementation, expected `usize`, found `i32` diff --git a/tests/ui/str/str-idx.stderr b/tests/ui/str/str-idx.stderr index 0ce0c207561..bedbbd9cb50 100644 --- a/tests/ui/str/str-idx.stderr +++ b/tests/ui/str/str-idx.stderr @@ -4,7 +4,6 @@ error[E0277]: the type `str` cannot be indexed by `{integer}` LL | let _: u8 = s[4]; | ^ string indices are ranges of `usize` | - = help: the trait `SliceIndex` is not implemented for `{integer}` = note: you can use `.chars().nth()` or `.bytes().nth()` for more information, see chapter 8 in The Book: = help: the trait `SliceIndex` is not implemented for `{integer}` @@ -20,7 +19,6 @@ LL | let _ = s.get(4); | | | required by a bound introduced by this call | - = help: the trait `SliceIndex` is not implemented for `{integer}` = note: you can use `.chars().nth()` or `.bytes().nth()` for more information, see chapter 8 in The Book: = help: the trait `SliceIndex` is not implemented for `{integer}` @@ -37,7 +35,6 @@ LL | let _ = s.get_unchecked(4); | | | required by a bound introduced by this call | - = help: the trait `SliceIndex` is not implemented for `{integer}` = note: you can use `.chars().nth()` or `.bytes().nth()` for more information, see chapter 8 in The Book: = help: the trait `SliceIndex` is not implemented for `{integer}` diff --git a/tests/ui/str/str-mut-idx.stderr b/tests/ui/str/str-mut-idx.stderr index 7bc46ff33b3..f09a4c329e5 100644 --- a/tests/ui/str/str-mut-idx.stderr +++ b/tests/ui/str/str-mut-idx.stderr @@ -30,7 +30,6 @@ error[E0277]: the type `str` cannot be indexed by `usize` LL | s[1usize] = bot(); | ^^^^^^ string indices are ranges of `usize` | - = help: the trait `SliceIndex` is not implemented for `usize` = help: the trait `SliceIndex` is not implemented for `usize` but trait `SliceIndex<[_]>` is implemented for it = help: for that trait implementation, expected `[_]`, found `str` @@ -44,7 +43,6 @@ LL | s.get_mut(1); | | | required by a bound introduced by this call | - = help: the trait `SliceIndex` is not implemented for `{integer}` = note: you can use `.chars().nth()` or `.bytes().nth()` for more information, see chapter 8 in The Book: = help: the trait `SliceIndex` is not implemented for `{integer}` @@ -61,7 +59,6 @@ LL | s.get_unchecked_mut(1); | | | required by a bound introduced by this call | - = help: the trait `SliceIndex` is not implemented for `{integer}` = note: you can use `.chars().nth()` or `.bytes().nth()` for more information, see chapter 8 in The Book: = help: the trait `SliceIndex` is not implemented for `{integer}` diff --git a/tests/ui/suggestions/suggest-dereferencing-index.stderr b/tests/ui/suggestions/suggest-dereferencing-index.stderr index cd5364fcffb..0335d8eafde 100644 --- a/tests/ui/suggestions/suggest-dereferencing-index.stderr +++ b/tests/ui/suggestions/suggest-dereferencing-index.stderr @@ -4,7 +4,6 @@ error[E0277]: the type `[{integer}]` cannot be indexed by `&usize` LL | let one_item_please: i32 = [1, 2, 3][i]; | ^ slice indices are of type `usize` or ranges of `usize` | - = help: the trait `SliceIndex<[{integer}]>` is not implemented for `&usize` = help: the trait `SliceIndex<[{integer}]>` is not implemented for `&_` but it is implemented for `_` = help: for that trait implementation, expected `usize`, found `&usize` diff --git a/tests/ui/try-trait/bad-interconversion.stderr b/tests/ui/try-trait/bad-interconversion.stderr index 20fe2d721bc..bb5e5646ad2 100644 --- a/tests/ui/try-trait/bad-interconversion.stderr +++ b/tests/ui/try-trait/bad-interconversion.stderr @@ -66,7 +66,6 @@ LL | fn result_to_control_flow() -> ControlFlow { LL | ControlFlow::Continue(Err("hello")?) | ^ this `?` produces `Result`, which is incompatible with `ControlFlow` | - = help: the trait `FromResidual>` is not implemented for `ControlFlow` = help: the trait `FromResidual>` is not implemented for `ControlFlow` but trait `FromResidual>` is implemented for it = help: for that trait implementation, expected `ControlFlow`, found `Result` @@ -79,7 +78,6 @@ LL | fn option_to_control_flow() -> ControlFlow { LL | Some(3)?; | ^ this `?` produces `Option`, which is incompatible with `ControlFlow` | - = help: the trait `FromResidual>` is not implemented for `ControlFlow` = help: the trait `FromResidual>` is not implemented for `ControlFlow` but trait `FromResidual>` is implemented for it = help: for that trait implementation, expected `ControlFlow`, found `Option` @@ -92,7 +90,6 @@ LL | fn control_flow_to_control_flow() -> ControlFlow { LL | ControlFlow::Break(4_u8)?; | ^ this `?` produces `ControlFlow`, which is incompatible with `ControlFlow` | - = help: the trait `FromResidual>` is not implemented for `ControlFlow` = note: unlike `Result`, there's no `From`-conversion performed for `ControlFlow` = help: the trait `FromResidual>` is not implemented for `ControlFlow` but trait `FromResidual>` is implemented for it diff --git a/tests/ui/type-alias-impl-trait/self-referential-2.current.stderr b/tests/ui/type-alias-impl-trait/self-referential-2.current.stderr index 1e799f15635..e4399f2d8f4 100644 --- a/tests/ui/type-alias-impl-trait/self-referential-2.current.stderr +++ b/tests/ui/type-alias-impl-trait/self-referential-2.current.stderr @@ -6,7 +6,6 @@ LL | fn bar() -> Bar { LL | 42_i32 | ------ return type was inferred to be `i32` here | - = help: the trait `PartialEq` is not implemented for `i32` = help: the trait `PartialEq` is not implemented for `i32` but trait `PartialEq` is implemented for it From c6017badb4ca22b85c70916746c233340be53c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 25 Oct 2024 02:41:39 +0000 Subject: [PATCH 03/13] Fix type shortening writing to file Make sure that we append to the file for long ty paths. Do not write the same type more than once. Shorten the calculated width a bit. --- compiler/rustc_middle/src/ty/error.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index c49824bb418..43d243b0584 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -1,5 +1,7 @@ use std::borrow::Cow; +use std::fs::File; use std::hash::{DefaultHasher, Hash, Hasher}; +use std::io::{Read, Write}; use std::path::PathBuf; use rustc_errors::pluralize; @@ -250,8 +252,8 @@ impl<'tcx> TyCtxt<'tcx> { } let width = self.sess.diagnostic_width(); - let length_limit = width.saturating_sub(30); - if regular.len() <= width { + let length_limit = width / 2; + if regular.len() <= width * 2 / 3 { return regular; } let short = self.ty_string_with_limit(ty, length_limit); @@ -265,7 +267,20 @@ impl<'tcx> TyCtxt<'tcx> { *path = Some(path.take().unwrap_or_else(|| { self.output_filenames(()).temp_path_ext(&format!("long-type-{hash}.txt"), None) })); - match std::fs::write(path.as_ref().unwrap(), &format!("{regular}\n")) { + let Ok(mut file) = + File::options().create(true).read(true).append(true).open(&path.as_ref().unwrap()) + else { + return regular; + }; + + // Do not write the same type to the file multiple times. + let mut contents = String::new(); + let _ = file.read_to_string(&mut contents); + if let Some(_) = contents.lines().find(|line| line == ®ular) { + return short; + } + + match write!(file, "{regular}\n") { Ok(_) => short, Err(_) => regular, } From 86b59656081d2dd03ef42d9d30d7141b1fc3b5f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 25 Oct 2024 02:41:55 +0000 Subject: [PATCH 04/13] Use `short_ty_string` --- .../src/error_reporting/traits/fulfillment_errors.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index dd2f0ec2096..cc56c679031 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -1872,7 +1872,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { StringPart::normal(" implemented for `"), ]); if types_content.0 == types_content.1 { - msg.push(StringPart::normal(obligation_trait_ref.self_ty().to_string())); + let ty = + self.tcx.short_ty_string(obligation_trait_ref.self_ty(), &mut None); + msg.push(StringPart::normal(ty)); } else { msg.extend(types.0.0); } From 092ecca5b92c94ecf6ff373610e18097fb61b8a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 25 Oct 2024 04:38:48 +0000 Subject: [PATCH 05/13] Point at tail expression on rpit E0277 ``` error[E0277]: the trait bound `{gen block@$DIR/gen_block_is_coro.rs:7:5: 7:8}: Coroutine` is not satisfied --> $DIR/gen_block_is_coro.rs:6:13 | LL | fn foo() -> impl Coroutine { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Coroutine` is not implemented for `{gen block@$DIR/gen_block_is_coro.rs:7:5: 7:8}` LL | gen { yield 42 } | ---------------- return type was inferred to be `{gen block@$DIR/gen_block_is_coro.rs:7:5: 7:8}` here ``` The secondary span label is new. --- .../src/error_reporting/traits/suggestions.rs | 39 +++++++++++++------ tests/ui/async-await/async-error-span.stderr | 3 ++ .../arg-count-mismatch-on-unit-input.stderr | 5 ++- tests/ui/coroutine/gen_block_is_coro.stderr | 6 +++ .../coroutine/gen_block_is_no_future.stderr | 2 + tests/ui/coroutine/issue-88653.rs | 1 + tests/ui/coroutine/issue-88653.stderr | 18 +++++++-- ...between-expected-trait-and-found-trait.svg | 30 +++++++------- tests/ui/impl-trait/issue-55872-1.stderr | 6 +++ tests/ui/impl-trait/issue-55872-3.stderr | 3 ++ tests/ui/impl-trait/nested_impl_trait.stderr | 8 +++- .../opaque-cast-field-access-in-future.stderr | 3 ++ ...ction-mismatch-in-impl-where-clause.stderr | 3 ++ .../lifetime-elision-return-type-trait.stderr | 3 ++ tests/ui/lint/issue-106991.stderr | 3 ++ .../ui/never_type/impl_trait_fallback2.stderr | 6 +++ .../ui/never_type/impl_trait_fallback3.stderr | 3 ++ .../ui/never_type/impl_trait_fallback4.stderr | 3 ++ .../ui/type-alias-impl-trait/fallback.stderr | 5 ++- .../non-lifetime-binder-in-constraint.stderr | 3 ++ 20 files changed, 121 insertions(+), 32 deletions(-) diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 553bb61ed04..64edeb35dd2 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -3563,17 +3563,34 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { )]); } ObligationCauseCode::OpaqueReturnType(expr_info) => { - if let Some((expr_ty, hir_id)) = expr_info { - let expr_ty = self.tcx.short_ty_string(expr_ty, long_ty_file); - let expr = self.infcx.tcx.hir().expect_expr(hir_id); - err.span_label( - expr.span, - with_forced_trimmed_paths!(format!( - "return type was inferred to be `{expr_ty}` here", - )), - ); - suggest_remove_deref(err, &expr); - } + let (expr_ty, expr) = if let Some((expr_ty, hir_id)) = expr_info { + let expr_ty = tcx.short_ty_string(expr_ty, long_ty_file); + let expr = tcx.hir().expect_expr(hir_id); + (expr_ty, expr) + } else if let Some(body_id) = tcx.hir_node_by_def_id(body_id).body_id() + && let body = tcx.hir().body(body_id) + && let hir::ExprKind::Block(block, _) = body.value.kind + && let Some(expr) = block.expr + && let Some(expr_ty) = self + .typeck_results + .as_ref() + .and_then(|typeck| typeck.node_type_opt(expr.hir_id)) + && let Some(pred) = predicate.as_clause() + && let ty::ClauseKind::Trait(pred) = pred.kind().skip_binder() + && self.can_eq(param_env, pred.self_ty(), expr_ty) + { + let expr_ty = tcx.short_ty_string(expr_ty, long_ty_file); + (expr_ty, expr) + } else { + return; + }; + err.span_label( + expr.span, + with_forced_trimmed_paths!(format!( + "return type was inferred to be `{expr_ty}` here", + )), + ); + suggest_remove_deref(err, &expr); } } } diff --git a/tests/ui/async-await/async-error-span.stderr b/tests/ui/async-await/async-error-span.stderr index 44f1583f4cc..37b5c329a7d 100644 --- a/tests/ui/async-await/async-error-span.stderr +++ b/tests/ui/async-await/async-error-span.stderr @@ -3,6 +3,9 @@ error[E0277]: `()` is not a future | LL | fn get_future() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not a future +LL | +LL | panic!() + | -------- return type was inferred to be `_` here | = help: the trait `Future` is not implemented for `()` diff --git a/tests/ui/coroutine/arg-count-mismatch-on-unit-input.stderr b/tests/ui/coroutine/arg-count-mismatch-on-unit-input.stderr index c7d6507fd79..839299f1c94 100644 --- a/tests/ui/coroutine/arg-count-mismatch-on-unit-input.stderr +++ b/tests/ui/coroutine/arg-count-mismatch-on-unit-input.stderr @@ -5,7 +5,10 @@ LL | fn foo() -> impl Coroutine { | ^^^^^^^^^^^^^^^^^^ expected due to this ... LL | |_: ()| {} - | ------- found signature defined here + | ---------- + | | + | found signature defined here + | return type was inferred to be `{coroutine@$DIR/arg-count-mismatch-on-unit-input.rs:8:5: 8:12}` here | = note: expected coroutine signature `fn(u8) -> _` found coroutine signature `fn(()) -> _` diff --git a/tests/ui/coroutine/gen_block_is_coro.stderr b/tests/ui/coroutine/gen_block_is_coro.stderr index afcdce1d58d..083e738f3ec 100644 --- a/tests/ui/coroutine/gen_block_is_coro.stderr +++ b/tests/ui/coroutine/gen_block_is_coro.stderr @@ -3,18 +3,24 @@ error[E0277]: the trait bound `{gen block@$DIR/gen_block_is_coro.rs:7:5: 7:8}: C | LL | fn foo() -> impl Coroutine { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Coroutine` is not implemented for `{gen block@$DIR/gen_block_is_coro.rs:7:5: 7:8}` +LL | gen { yield 42 } + | ---------------- return type was inferred to be `{gen block@$DIR/gen_block_is_coro.rs:7:5: 7:8}` here error[E0277]: the trait bound `{gen block@$DIR/gen_block_is_coro.rs:11:5: 11:8}: Coroutine` is not satisfied --> $DIR/gen_block_is_coro.rs:10:13 | LL | fn bar() -> impl Coroutine { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Coroutine` is not implemented for `{gen block@$DIR/gen_block_is_coro.rs:11:5: 11:8}` +LL | gen { yield 42 } + | ---------------- return type was inferred to be `{gen block@$DIR/gen_block_is_coro.rs:11:5: 11:8}` here error[E0277]: the trait bound `{gen block@$DIR/gen_block_is_coro.rs:15:5: 15:8}: Coroutine` is not satisfied --> $DIR/gen_block_is_coro.rs:14:13 | LL | fn baz() -> impl Coroutine { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Coroutine` is not implemented for `{gen block@$DIR/gen_block_is_coro.rs:15:5: 15:8}` +LL | gen { yield 42 } + | ---------------- return type was inferred to be `{gen block@$DIR/gen_block_is_coro.rs:15:5: 15:8}` here error: aborting due to 3 previous errors diff --git a/tests/ui/coroutine/gen_block_is_no_future.stderr b/tests/ui/coroutine/gen_block_is_no_future.stderr index bf0985a76a2..43e18dbc2a9 100644 --- a/tests/ui/coroutine/gen_block_is_no_future.stderr +++ b/tests/ui/coroutine/gen_block_is_no_future.stderr @@ -3,6 +3,8 @@ error[E0277]: `{gen block@$DIR/gen_block_is_no_future.rs:5:5: 5:8}` is not a fut | LL | fn foo() -> impl std::future::Future { | ^^^^^^^^^^^^^^^^^^^^^^^^ `{gen block@$DIR/gen_block_is_no_future.rs:5:5: 5:8}` is not a future +LL | gen { yield 42 } + | ---------------- return type was inferred to be `{gen block@$DIR/gen_block_is_no_future.rs:5:5: 5:8}` here | = help: the trait `Future` is not implemented for `{gen block@$DIR/gen_block_is_no_future.rs:5:5: 5:8}` diff --git a/tests/ui/coroutine/issue-88653.rs b/tests/ui/coroutine/issue-88653.rs index 3afd12a2093..b5936c7960d 100644 --- a/tests/ui/coroutine/issue-88653.rs +++ b/tests/ui/coroutine/issue-88653.rs @@ -14,6 +14,7 @@ fn foo(bar: bool) -> impl Coroutine<(bool,)> { #[coroutine] |bar| { //~^ NOTE: found signature defined here + //~| NOTE: return type was inferred to be if bar { yield bar; } diff --git a/tests/ui/coroutine/issue-88653.stderr b/tests/ui/coroutine/issue-88653.stderr index 8a23ad17b8b..ef0cc11dde8 100644 --- a/tests/ui/coroutine/issue-88653.stderr +++ b/tests/ui/coroutine/issue-88653.stderr @@ -1,11 +1,21 @@ error[E0631]: type mismatch in coroutine arguments --> $DIR/issue-88653.rs:8:22 | -LL | fn foo(bar: bool) -> impl Coroutine<(bool,)> { - | ^^^^^^^^^^^^^^^^^^^^^^^ expected due to this +LL | fn foo(bar: bool) -> impl Coroutine<(bool,)> { + | ^^^^^^^^^^^^^^^^^^^^^^^ expected due to this ... -LL | |bar| { - | ----- found signature defined here +LL | |bar| { + | ----- + | | + | _____found signature defined here + | | +LL | | +LL | | +LL | | if bar { +LL | | yield bar; +LL | | } +LL | | } + | |_____- return type was inferred to be `{coroutine@$DIR/issue-88653.rs:15:5: 15:10}` here | = note: expected coroutine signature `fn((bool,)) -> _` found coroutine signature `fn(bool) -> _` diff --git a/tests/ui/impl-trait/diagnostics/highlight-difference-between-expected-trait-and-found-trait.svg b/tests/ui/impl-trait/diagnostics/highlight-difference-between-expected-trait-and-found-trait.svg index 277fd1536bc..1a79a9d7efa 100644 --- a/tests/ui/impl-trait/diagnostics/highlight-difference-between-expected-trait-and-found-trait.svg +++ b/tests/ui/impl-trait/diagnostics/highlight-difference-between-expected-trait-and-found-trait.svg @@ -1,4 +1,4 @@ - + diff --git a/tests/ui/impl-trait/issue-55872-1.stderr b/tests/ui/impl-trait/issue-55872-1.stderr index 8912cce1b4b..2ccca0b562c 100644 --- a/tests/ui/impl-trait/issue-55872-1.stderr +++ b/tests/ui/impl-trait/issue-55872-1.stderr @@ -12,6 +12,9 @@ error[E0277]: the trait bound `S: Copy` is not satisfied in `(S, T)` | LL | fn foo() -> Self::E { | ^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `S` +... +LL | (S::default(), T::default()) + | ---------------------------- return type was inferred to be `(S, T)` here | = note: required because it appears within the type `(S, T)` help: consider further restricting this bound @@ -24,6 +27,9 @@ error[E0277]: the trait bound `T: Copy` is not satisfied in `(S, T)` | LL | fn foo() -> Self::E { | ^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `T` +... +LL | (S::default(), T::default()) + | ---------------------------- return type was inferred to be `(S, T)` here | = note: required because it appears within the type `(S, T)` help: consider further restricting this bound diff --git a/tests/ui/impl-trait/issue-55872-3.stderr b/tests/ui/impl-trait/issue-55872-3.stderr index f892da2a535..98e9fbf4153 100644 --- a/tests/ui/impl-trait/issue-55872-3.stderr +++ b/tests/ui/impl-trait/issue-55872-3.stderr @@ -3,6 +3,9 @@ error[E0277]: the trait bound `{async block@$DIR/issue-55872-3.rs:15:9: 15:14}: | LL | fn foo() -> Self::E { | ^^^^^^^ the trait `Copy` is not implemented for `{async block@$DIR/issue-55872-3.rs:15:9: 15:14}` +LL | +LL | async {} + | -------- return type was inferred to be `{async block@$DIR/issue-55872-3.rs:15:9: 15:14}` here error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/nested_impl_trait.stderr b/tests/ui/impl-trait/nested_impl_trait.stderr index 31c3e0c9013..d01c5961e81 100644 --- a/tests/ui/impl-trait/nested_impl_trait.stderr +++ b/tests/ui/impl-trait/nested_impl_trait.stderr @@ -46,7 +46,9 @@ error[E0277]: the trait bound `impl Debug: From>` is not satisfie --> $DIR/nested_impl_trait.rs:6:46 | LL | fn bad_in_ret_position(x: impl Into) -> impl Into { x } - | ^^^^^^^^^^^^^^^^^^^^^ the trait `From>` is not implemented for `impl Debug` + | ^^^^^^^^^^^^^^^^^^^^^ - return type was inferred to be `impl Into` here + | | + | the trait `From>` is not implemented for `impl Debug` | = help: the trait `Into` is implemented for `T` = note: required for `impl Into` to implement `Into` @@ -55,7 +57,9 @@ error[E0277]: the trait bound `impl Debug: From>` is not satisfie --> $DIR/nested_impl_trait.rs:19:34 | LL | fn bad(x: impl Into) -> impl Into { x } - | ^^^^^^^^^^^^^^^^^^^^^ the trait `From>` is not implemented for `impl Debug` + | ^^^^^^^^^^^^^^^^^^^^^ - return type was inferred to be `impl Into` here + | | + | the trait `From>` is not implemented for `impl Debug` | = help: the trait `Into` is implemented for `T` = note: required for `impl Into` to implement `Into` diff --git a/tests/ui/impl-trait/opaque-cast-field-access-in-future.stderr b/tests/ui/impl-trait/opaque-cast-field-access-in-future.stderr index 5ade6a69d4b..6866f3f5350 100644 --- a/tests/ui/impl-trait/opaque-cast-field-access-in-future.stderr +++ b/tests/ui/impl-trait/opaque-cast-field-access-in-future.stderr @@ -3,6 +3,9 @@ error[E0283]: type annotations needed | LL | fn run() -> Foo> { | ^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type +LL | +LL | loop {} + | ------- return type was inferred to be `!` here | = note: cannot satisfy `_: Future` diff --git a/tests/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr b/tests/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr index fa71adc6380..96e18f1f1cb 100644 --- a/tests/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr +++ b/tests/ui/impl-trait/projection-mismatch-in-impl-where-clause.stderr @@ -3,6 +3,9 @@ error[E0271]: type mismatch resolving `<() as Super>::Assoc == ()` | LL | fn test() -> impl Test { | ^^^^^^^^^ type mismatch resolving `<() as Super>::Assoc == ()` +LL | +LL | () + | -- return type was inferred to be `()` here | note: expected this to be `()` --> $DIR/projection-mismatch-in-impl-where-clause.rs:6:18 diff --git a/tests/ui/lifetimes/lifetime-elision-return-type-trait.stderr b/tests/ui/lifetimes/lifetime-elision-return-type-trait.stderr index 1664466df3c..f26d6b8d0be 100644 --- a/tests/ui/lifetimes/lifetime-elision-return-type-trait.stderr +++ b/tests/ui/lifetimes/lifetime-elision-return-type-trait.stderr @@ -3,6 +3,9 @@ error[E0277]: the trait bound `Result<(), _>: Future` is not satisfied | LL | fn foo() -> impl Future> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Future` is not implemented for `Result<(), _>` +LL | +LL | Ok(()) + | ------ return type was inferred to be `Result<(), _>` here | help: this trait has no implementations, consider adding one --> $DIR/lifetime-elision-return-type-trait.rs:1:1 diff --git a/tests/ui/lint/issue-106991.stderr b/tests/ui/lint/issue-106991.stderr index 9b4fab68102..0441a6377d0 100644 --- a/tests/ui/lint/issue-106991.stderr +++ b/tests/ui/lint/issue-106991.stderr @@ -3,6 +3,9 @@ error[E0271]: expected `foo` to be a fn item that returns `i32`, but it returns | LL | fn bar() -> impl Iterator { | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `()` +... +LL | x.iter_mut().map(foo) + | --------------------- return type was inferred to be `Map>, for<'a> fn(&'a mut Vec) {foo}>` here | = note: required for `Map>, for<'a> fn(&'a mut Vec) {foo}>` to implement `Iterator` diff --git a/tests/ui/never_type/impl_trait_fallback2.stderr b/tests/ui/never_type/impl_trait_fallback2.stderr index 78cc83bdbfa..4c32dce465b 100644 --- a/tests/ui/never_type/impl_trait_fallback2.stderr +++ b/tests/ui/never_type/impl_trait_fallback2.stderr @@ -3,6 +3,9 @@ error[E0277]: the trait bound `(): T` is not satisfied | LL | fn should_ret_unit() -> impl T { | ^^^^^^ the trait `T` is not implemented for `()` +LL | +LL | panic!() + | -------- return type was inferred to be `_` here | = help: the trait `T` is implemented for `i32` @@ -11,6 +14,9 @@ error[E0277]: the trait bound `(): T` is not satisfied | LL | fn a() -> Foo { | ^^^ the trait `T` is not implemented for `()` +LL | +LL | panic!() + | -------- return type was inferred to be `_` here | = help: the trait `T` is implemented for `i32` diff --git a/tests/ui/never_type/impl_trait_fallback3.stderr b/tests/ui/never_type/impl_trait_fallback3.stderr index e2246eea17c..fde8d0896dd 100644 --- a/tests/ui/never_type/impl_trait_fallback3.stderr +++ b/tests/ui/never_type/impl_trait_fallback3.stderr @@ -3,6 +3,9 @@ error[E0277]: the trait bound `(): T` is not satisfied | LL | fn a() -> Foo { | ^^^ the trait `T` is not implemented for `()` +... +LL | panic!() + | -------- return type was inferred to be `_` here | help: this trait has no implementations, consider adding one --> $DIR/impl_trait_fallback3.rs:5:1 diff --git a/tests/ui/never_type/impl_trait_fallback4.stderr b/tests/ui/never_type/impl_trait_fallback4.stderr index 8f6b5cfea68..c4fc949373a 100644 --- a/tests/ui/never_type/impl_trait_fallback4.stderr +++ b/tests/ui/never_type/impl_trait_fallback4.stderr @@ -3,6 +3,9 @@ error[E0277]: the trait bound `(): T` is not satisfied | LL | fn foo() -> impl T { | ^^^^^^ the trait `T` is not implemented for `()` +LL | +LL | panic!() + | -------- return type was inferred to be `_` here | help: this trait has no implementations, consider adding one --> $DIR/impl_trait_fallback4.rs:3:1 diff --git a/tests/ui/type-alias-impl-trait/fallback.stderr b/tests/ui/type-alias-impl-trait/fallback.stderr index 5250252a0da..c909ab66f0e 100644 --- a/tests/ui/type-alias-impl-trait/fallback.stderr +++ b/tests/ui/type-alias-impl-trait/fallback.stderr @@ -4,7 +4,10 @@ error[E0283]: type annotations needed LL | fn unconstrained_foo() -> Wrapper { | ------------ type must be known at this point LL | Wrapper::Second - | ^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the enum `Wrapper` + | ^^^^^^^^^^^^^^^ + | | + | cannot infer type of the type parameter `T` declared on the enum `Wrapper` + | return type was inferred to be `Wrapper<_>` here | = note: cannot satisfy `_: Copy` help: consider specifying the generic argument diff --git a/tests/ui/type-alias-impl-trait/non-lifetime-binder-in-constraint.stderr b/tests/ui/type-alias-impl-trait/non-lifetime-binder-in-constraint.stderr index fa3306ff11f..6e5bd34ce38 100644 --- a/tests/ui/type-alias-impl-trait/non-lifetime-binder-in-constraint.stderr +++ b/tests/ui/type-alias-impl-trait/non-lifetime-binder-in-constraint.stderr @@ -17,6 +17,9 @@ error[E0277]: the trait bound `{integer}: Trait<()>` is not satisfied | LL | fn produce() -> impl for Trait<(), Assoc = impl Trait> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait<()>` is not implemented for `{integer}` +... +LL | 16 + | -- return type was inferred to be `{integer}` here | help: this trait has no implementations, consider adding one --> $DIR/non-lifetime-binder-in-constraint.rs:4:1 From 1a0c502183835c93f9a60433e05997b040de4f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 25 Oct 2024 05:11:42 +0000 Subject: [PATCH 06/13] On long E0277 primary span label, move it to a `help` Long span labels don't read well. --- .../traits/fulfillment_errors.rs | 5 ++ .../async-closures/not-clone-closure.stderr | 3 +- tests/ui/async-await/coroutine-not-future.rs | 1 + .../async-await/coroutine-not-future.stderr | 30 ++++---- .../const_param_ty_bad.stderr | 3 +- tests/ui/coroutine/clone-impl.rs | 1 + tests/ui/coroutine/clone-impl.stderr | 72 +++++++++---------- tests/ui/coroutine/issue-105084.rs | 1 + tests/ui/coroutine/issue-105084.stderr | 18 ++--- ...rg-where-it-should-have-been-called.stderr | 3 +- tests/ui/suggestions/issue-84973-blacklist.rs | 1 + .../suggestions/issue-84973-blacklist.stderr | 24 +++---- .../bare-fn-no-impl-fn-ptr-99875.stderr | 3 +- tests/ui/transmutability/assoc-bound.stderr | 3 +- .../higher-ranked-fn-type.verbose.stderr | 3 +- 15 files changed, 93 insertions(+), 78 deletions(-) diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index cc56c679031..cef704d8328 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -328,6 +328,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } } else if let Some(custom_explanation) = safe_transmute_explanation { err.span_label(span, custom_explanation); + } else if explanation.len() > self.tcx.sess.diagnostic_width() { + // Really long types don't look good as span labels, instead move it + // to a `help`. + err.span_label(span, "unsatisfied trait bound"); + err.help(explanation); } else { err.span_label(span, explanation); } diff --git a/tests/ui/async-await/async-closures/not-clone-closure.stderr b/tests/ui/async-await/async-closures/not-clone-closure.stderr index 8d5612687db..c2f963f9b92 100644 --- a/tests/ui/async-await/async-closures/not-clone-closure.stderr +++ b/tests/ui/async-await/async-closures/not-clone-closure.stderr @@ -2,8 +2,9 @@ error[E0277]: the trait bound `NotClonableUpvar: Clone` is not satisfied in `{as --> $DIR/not-clone-closure.rs:32:15 | LL | not_clone.clone(); - | ^^^^^ within `{async closure@$DIR/not-clone-closure.rs:29:21: 29:34}`, the trait `Clone` is not implemented for `NotClonableUpvar` + | ^^^^^ unsatisfied trait bound | + = help: within `{async closure@$DIR/not-clone-closure.rs:29:21: 29:34}`, the trait `Clone` is not implemented for `NotClonableUpvar` note: required because it's used within this closure --> $DIR/not-clone-closure.rs:29:21 | diff --git a/tests/ui/async-await/coroutine-not-future.rs b/tests/ui/async-await/coroutine-not-future.rs index 45227435507..de627333fe4 100644 --- a/tests/ui/async-await/coroutine-not-future.rs +++ b/tests/ui/async-await/coroutine-not-future.rs @@ -1,4 +1,5 @@ //@ edition:2018 +//@compile-flags: --diagnostic-width=300 #![feature(coroutines, coroutine_trait, stmt_expr_attributes)] use std::future::Future; diff --git a/tests/ui/async-await/coroutine-not-future.stderr b/tests/ui/async-await/coroutine-not-future.stderr index 72921a72a95..b0f371f6706 100644 --- a/tests/ui/async-await/coroutine-not-future.stderr +++ b/tests/ui/async-await/coroutine-not-future.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `impl Future: Coroutine<_>` is not satisfied - --> $DIR/coroutine-not-future.rs:35:21 + --> $DIR/coroutine-not-future.rs:36:21 | LL | takes_coroutine(async_fn()); | --------------- ^^^^^^^^^^ the trait `Coroutine<_>` is not implemented for `impl Future` @@ -7,13 +7,13 @@ LL | takes_coroutine(async_fn()); | required by a bound introduced by this call | note: required by a bound in `takes_coroutine` - --> $DIR/coroutine-not-future.rs:19:39 + --> $DIR/coroutine-not-future.rs:20:39 | LL | fn takes_coroutine(_g: impl Coroutine) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `takes_coroutine` error[E0277]: the trait bound `impl Future: Coroutine<_>` is not satisfied - --> $DIR/coroutine-not-future.rs:37:21 + --> $DIR/coroutine-not-future.rs:38:21 | LL | takes_coroutine(returns_async_block()); | --------------- ^^^^^^^^^^^^^^^^^^^^^ the trait `Coroutine<_>` is not implemented for `impl Future` @@ -21,27 +21,27 @@ LL | takes_coroutine(returns_async_block()); | required by a bound introduced by this call | note: required by a bound in `takes_coroutine` - --> $DIR/coroutine-not-future.rs:19:39 + --> $DIR/coroutine-not-future.rs:20:39 | LL | fn takes_coroutine(_g: impl Coroutine) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `takes_coroutine` -error[E0277]: the trait bound `{async block@$DIR/coroutine-not-future.rs:39:21: 39:26}: Coroutine<_>` is not satisfied - --> $DIR/coroutine-not-future.rs:39:21 +error[E0277]: the trait bound `{async block@$DIR/coroutine-not-future.rs:40:21: 40:26}: Coroutine<_>` is not satisfied + --> $DIR/coroutine-not-future.rs:40:21 | LL | takes_coroutine(async {}); - | --------------- ^^^^^^^^ the trait `Coroutine<_>` is not implemented for `{async block@$DIR/coroutine-not-future.rs:39:21: 39:26}` + | --------------- ^^^^^^^^ the trait `Coroutine<_>` is not implemented for `{async block@$DIR/coroutine-not-future.rs:40:21: 40:26}` | | | required by a bound introduced by this call | note: required by a bound in `takes_coroutine` - --> $DIR/coroutine-not-future.rs:19:39 + --> $DIR/coroutine-not-future.rs:20:39 | LL | fn takes_coroutine(_g: impl Coroutine) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `takes_coroutine` error[E0277]: `impl Coroutine` is not a future - --> $DIR/coroutine-not-future.rs:43:18 + --> $DIR/coroutine-not-future.rs:44:18 | LL | takes_future(returns_coroutine()); | ------------ ^^^^^^^^^^^^^^^^^^^ `impl Coroutine` is not a future @@ -50,13 +50,13 @@ LL | takes_future(returns_coroutine()); | = help: the trait `Future` is not implemented for `impl Coroutine` note: required by a bound in `takes_future` - --> $DIR/coroutine-not-future.rs:18:26 + --> $DIR/coroutine-not-future.rs:19:26 | LL | fn takes_future(_f: impl Future) {} | ^^^^^^^^^^^^^^^^^^^ required by this bound in `takes_future` -error[E0277]: `{coroutine@$DIR/coroutine-not-future.rs:47:9: 47:14}` is not a future - --> $DIR/coroutine-not-future.rs:47:9 +error[E0277]: `{coroutine@$DIR/coroutine-not-future.rs:48:9: 48:14}` is not a future + --> $DIR/coroutine-not-future.rs:48:9 | LL | takes_future( | ------------ required by a bound introduced by this call @@ -65,11 +65,11 @@ LL | / |ctx| { LL | | LL | | ctx = yield (); LL | | }, - | |_________^ `{coroutine@$DIR/coroutine-not-future.rs:47:9: 47:14}` is not a future + | |_________^ `{coroutine@$DIR/coroutine-not-future.rs:48:9: 48:14}` is not a future | - = help: the trait `Future` is not implemented for `{coroutine@$DIR/coroutine-not-future.rs:47:9: 47:14}` + = help: the trait `Future` is not implemented for `{coroutine@$DIR/coroutine-not-future.rs:48:9: 48:14}` note: required by a bound in `takes_future` - --> $DIR/coroutine-not-future.rs:18:26 + --> $DIR/coroutine-not-future.rs:19:26 | LL | fn takes_future(_f: impl Future) {} | ^^^^^^^^^^^^^^^^^^^ required by this bound in `takes_future` diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr index 694f5a5c1a9..4c8a5e46751 100644 --- a/tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr @@ -20,10 +20,11 @@ error[E0277]: `{closure@$DIR/const_param_ty_bad.rs:8:11: 8:13}` can't be used as --> $DIR/const_param_ty_bad.rs:8:11 | LL | check(|| {}); - | ----- ^^^^^ the trait `UnsizedConstParamTy` is not implemented for closure `{closure@$DIR/const_param_ty_bad.rs:8:11: 8:13}` + | ----- ^^^^^ unsatisfied trait bound | | | required by a bound introduced by this call | + = help: the trait `UnsizedConstParamTy` is not implemented for closure `{closure@$DIR/const_param_ty_bad.rs:8:11: 8:13}` note: required by a bound in `check` --> $DIR/const_param_ty_bad.rs:4:18 | diff --git a/tests/ui/coroutine/clone-impl.rs b/tests/ui/coroutine/clone-impl.rs index 94420e56a22..b07fad18aee 100644 --- a/tests/ui/coroutine/clone-impl.rs +++ b/tests/ui/coroutine/clone-impl.rs @@ -1,6 +1,7 @@ // gate-test-coroutine_clone // Verifies that non-static coroutines can be cloned/copied if all their upvars and locals held // across awaits can be cloned/copied. +//@compile-flags: --diagnostic-width=300 #![feature(coroutines, coroutine_clone, stmt_expr_attributes)] diff --git a/tests/ui/coroutine/clone-impl.stderr b/tests/ui/coroutine/clone-impl.stderr index 1256c97a02f..ed933fe784e 100644 --- a/tests/ui/coroutine/clone-impl.stderr +++ b/tests/ui/coroutine/clone-impl.stderr @@ -1,76 +1,76 @@ -error[E0277]: the trait bound `Vec: Copy` is not satisfied in `{coroutine@$DIR/clone-impl.rs:43:5: 43:12}` - --> $DIR/clone-impl.rs:49:5 +error[E0277]: the trait bound `Vec: Copy` is not satisfied in `{coroutine@$DIR/clone-impl.rs:44:5: 44:12}` + --> $DIR/clone-impl.rs:50:5 | LL | move || { - | ------- within this `{coroutine@$DIR/clone-impl.rs:43:5: 43:12}` + | ------- within this `{coroutine@$DIR/clone-impl.rs:44:5: 44:12}` ... LL | check_copy(&gen_clone_0); - | ^^^^^^^^^^^^^^^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:43:5: 43:12}`, the trait `Copy` is not implemented for `Vec` + | ^^^^^^^^^^^^^^^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:44:5: 44:12}`, the trait `Copy` is not implemented for `Vec` | note: captured value does not implement `Copy` - --> $DIR/clone-impl.rs:47:14 + --> $DIR/clone-impl.rs:48:14 | LL | drop(clonable_0); | ^^^^^^^^^^ has type `Vec` which does not implement `Copy` note: required by a bound in `check_copy` - --> $DIR/clone-impl.rs:89:18 + --> $DIR/clone-impl.rs:90:18 | LL | fn check_copy(_x: &T) {} | ^^^^ required by this bound in `check_copy` -error[E0277]: the trait bound `Vec: Copy` is not satisfied in `{coroutine@$DIR/clone-impl.rs:43:5: 43:12}` - --> $DIR/clone-impl.rs:49:5 +error[E0277]: the trait bound `Vec: Copy` is not satisfied in `{coroutine@$DIR/clone-impl.rs:44:5: 44:12}` + --> $DIR/clone-impl.rs:50:5 | LL | move || { - | ------- within this `{coroutine@$DIR/clone-impl.rs:43:5: 43:12}` + | ------- within this `{coroutine@$DIR/clone-impl.rs:44:5: 44:12}` ... LL | check_copy(&gen_clone_0); - | ^^^^^^^^^^^^^^^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:43:5: 43:12}`, the trait `Copy` is not implemented for `Vec` + | ^^^^^^^^^^^^^^^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:44:5: 44:12}`, the trait `Copy` is not implemented for `Vec` | note: coroutine does not implement `Copy` as this value is used across a yield - --> $DIR/clone-impl.rs:45:9 + --> $DIR/clone-impl.rs:46:9 | LL | let v = vec!['a']; | - has type `Vec` which does not implement `Copy` LL | yield; | ^^^^^ yield occurs here, with `v` maybe used later note: required by a bound in `check_copy` - --> $DIR/clone-impl.rs:89:18 + --> $DIR/clone-impl.rs:90:18 | LL | fn check_copy(_x: &T) {} | ^^^^ required by this bound in `check_copy` -error[E0277]: the trait bound `Vec: Copy` is not satisfied in `{coroutine@$DIR/clone-impl.rs:58:5: 58:12}` - --> $DIR/clone-impl.rs:70:5 +error[E0277]: the trait bound `Vec: Copy` is not satisfied in `{coroutine@$DIR/clone-impl.rs:59:5: 59:12}` + --> $DIR/clone-impl.rs:71:5 | LL | move || { - | ------- within this `{coroutine@$DIR/clone-impl.rs:58:5: 58:12}` + | ------- within this `{coroutine@$DIR/clone-impl.rs:59:5: 59:12}` ... LL | check_copy(&gen_clone_1); - | ^^^^^^^^^^^^^^^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:58:5: 58:12}`, the trait `Copy` is not implemented for `Vec` + | ^^^^^^^^^^^^^^^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:59:5: 59:12}`, the trait `Copy` is not implemented for `Vec` | note: captured value does not implement `Copy` - --> $DIR/clone-impl.rs:68:14 + --> $DIR/clone-impl.rs:69:14 | LL | drop(clonable_1); | ^^^^^^^^^^ has type `Vec` which does not implement `Copy` note: required by a bound in `check_copy` - --> $DIR/clone-impl.rs:89:18 + --> $DIR/clone-impl.rs:90:18 | LL | fn check_copy(_x: &T) {} | ^^^^ required by this bound in `check_copy` -error[E0277]: the trait bound `Vec: Copy` is not satisfied in `{coroutine@$DIR/clone-impl.rs:58:5: 58:12}` - --> $DIR/clone-impl.rs:70:5 +error[E0277]: the trait bound `Vec: Copy` is not satisfied in `{coroutine@$DIR/clone-impl.rs:59:5: 59:12}` + --> $DIR/clone-impl.rs:71:5 | LL | move || { - | ------- within this `{coroutine@$DIR/clone-impl.rs:58:5: 58:12}` + | ------- within this `{coroutine@$DIR/clone-impl.rs:59:5: 59:12}` ... LL | check_copy(&gen_clone_1); - | ^^^^^^^^^^^^^^^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:58:5: 58:12}`, the trait `Copy` is not implemented for `Vec` + | ^^^^^^^^^^^^^^^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:59:5: 59:12}`, the trait `Copy` is not implemented for `Vec` | note: coroutine does not implement `Copy` as this value is used across a yield - --> $DIR/clone-impl.rs:64:9 + --> $DIR/clone-impl.rs:65:9 | LL | let v = vec!['a']; | - has type `Vec` which does not implement `Copy` @@ -78,27 +78,27 @@ LL | let v = vec!['a']; LL | yield; | ^^^^^ yield occurs here, with `v` maybe used later note: required by a bound in `check_copy` - --> $DIR/clone-impl.rs:89:18 + --> $DIR/clone-impl.rs:90:18 | LL | fn check_copy(_x: &T) {} | ^^^^ required by this bound in `check_copy` -error[E0277]: the trait bound `NonClone: Copy` is not satisfied in `{coroutine@$DIR/clone-impl.rs:79:5: 79:12}` - --> $DIR/clone-impl.rs:83:5 +error[E0277]: the trait bound `NonClone: Copy` is not satisfied in `{coroutine@$DIR/clone-impl.rs:80:5: 80:12}` + --> $DIR/clone-impl.rs:84:5 | LL | move || { - | ------- within this `{coroutine@$DIR/clone-impl.rs:79:5: 79:12}` + | ------- within this `{coroutine@$DIR/clone-impl.rs:80:5: 80:12}` ... LL | check_copy(&gen_non_clone); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:79:5: 79:12}`, the trait `Copy` is not implemented for `NonClone` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:80:5: 80:12}`, the trait `Copy` is not implemented for `NonClone` | note: captured value does not implement `Copy` - --> $DIR/clone-impl.rs:81:14 + --> $DIR/clone-impl.rs:82:14 | LL | drop(non_clonable); | ^^^^^^^^^^^^ has type `NonClone` which does not implement `Copy` note: required by a bound in `check_copy` - --> $DIR/clone-impl.rs:89:18 + --> $DIR/clone-impl.rs:90:18 | LL | fn check_copy(_x: &T) {} | ^^^^ required by this bound in `check_copy` @@ -108,22 +108,22 @@ LL + #[derive(Copy)] LL | struct NonClone; | -error[E0277]: the trait bound `NonClone: Clone` is not satisfied in `{coroutine@$DIR/clone-impl.rs:79:5: 79:12}` - --> $DIR/clone-impl.rs:85:5 +error[E0277]: the trait bound `NonClone: Clone` is not satisfied in `{coroutine@$DIR/clone-impl.rs:80:5: 80:12}` + --> $DIR/clone-impl.rs:86:5 | LL | move || { - | ------- within this `{coroutine@$DIR/clone-impl.rs:79:5: 79:12}` + | ------- within this `{coroutine@$DIR/clone-impl.rs:80:5: 80:12}` ... LL | check_clone(&gen_non_clone); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:79:5: 79:12}`, the trait `Clone` is not implemented for `NonClone` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `{coroutine@$DIR/clone-impl.rs:80:5: 80:12}`, the trait `Clone` is not implemented for `NonClone` | note: captured value does not implement `Clone` - --> $DIR/clone-impl.rs:81:14 + --> $DIR/clone-impl.rs:82:14 | LL | drop(non_clonable); | ^^^^^^^^^^^^ has type `NonClone` which does not implement `Clone` note: required by a bound in `check_clone` - --> $DIR/clone-impl.rs:90:19 + --> $DIR/clone-impl.rs:91:19 | LL | fn check_clone(_x: &T) {} | ^^^^^ required by this bound in `check_clone` diff --git a/tests/ui/coroutine/issue-105084.rs b/tests/ui/coroutine/issue-105084.rs index 4e40bc127d7..0f6168ec58b 100644 --- a/tests/ui/coroutine/issue-105084.rs +++ b/tests/ui/coroutine/issue-105084.rs @@ -1,3 +1,4 @@ +//@compile-flags: --diagnostic-width=300 #![feature(coroutines)] #![feature(coroutine_clone)] #![feature(coroutine_trait)] diff --git a/tests/ui/coroutine/issue-105084.stderr b/tests/ui/coroutine/issue-105084.stderr index 11b5852b638..073f1fbea4c 100644 --- a/tests/ui/coroutine/issue-105084.stderr +++ b/tests/ui/coroutine/issue-105084.stderr @@ -1,8 +1,8 @@ error[E0382]: borrow of moved value: `g` - --> $DIR/issue-105084.rs:38:14 + --> $DIR/issue-105084.rs:39:14 | LL | let mut g = #[coroutine] - | ----- move occurs because `g` has type `{coroutine@$DIR/issue-105084.rs:15:5: 15:7}`, which does not implement the `Copy` trait + | ----- move occurs because `g` has type `{coroutine@$DIR/issue-105084.rs:16:5: 16:7}`, which does not implement the `Copy` trait ... LL | let mut h = copy(g); | - value moved here @@ -11,7 +11,7 @@ LL | Pin::new(&mut g).resume(()); | ^^^^^^ value borrowed here after move | note: consider changing this parameter type in function `copy` to borrow instead if owning the value isn't necessary - --> $DIR/issue-105084.rs:9:21 + --> $DIR/issue-105084.rs:10:21 | LL | fn copy(x: T) -> T { | ---- ^ this parameter takes ownership of the value @@ -22,17 +22,17 @@ help: consider cloning the value if the performance cost is acceptable LL | let mut h = copy(g.clone()); | ++++++++ -error[E0277]: the trait bound `Box<(i32, ())>: Copy` is not satisfied in `{coroutine@$DIR/issue-105084.rs:15:5: 15:7}` - --> $DIR/issue-105084.rs:32:17 +error[E0277]: the trait bound `Box<(i32, ())>: Copy` is not satisfied in `{coroutine@$DIR/issue-105084.rs:16:5: 16:7}` + --> $DIR/issue-105084.rs:33:17 | LL | || { - | -- within this `{coroutine@$DIR/issue-105084.rs:15:5: 15:7}` + | -- within this `{coroutine@$DIR/issue-105084.rs:16:5: 16:7}` ... LL | let mut h = copy(g); - | ^^^^^^^ within `{coroutine@$DIR/issue-105084.rs:15:5: 15:7}`, the trait `Copy` is not implemented for `Box<(i32, ())>` + | ^^^^^^^ within `{coroutine@$DIR/issue-105084.rs:16:5: 16:7}`, the trait `Copy` is not implemented for `Box<(i32, ())>` | note: coroutine does not implement `Copy` as this value is used across a yield - --> $DIR/issue-105084.rs:22:22 + --> $DIR/issue-105084.rs:23:22 | LL | Box::new((5, yield)); | -------------^^^^^-- @@ -40,7 +40,7 @@ LL | Box::new((5, yield)); | | yield occurs here, with `Box::new((5, yield))` maybe used later | has type `Box<(i32, ())>` which does not implement `Copy` note: required by a bound in `copy` - --> $DIR/issue-105084.rs:9:12 + --> $DIR/issue-105084.rs:10:12 | LL | fn copy(x: T) -> T { | ^^^^ required by this bound in `copy` diff --git a/tests/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr b/tests/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr index 75a3ae1a83e..60d0263c149 100644 --- a/tests/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr +++ b/tests/ui/suggestions/fn-ctor-passed-as-arg-where-it-should-have-been-called.stderr @@ -20,10 +20,11 @@ error[E0277]: the trait bound `{closure@$DIR/fn-ctor-passed-as-arg-where-it-shou --> $DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:19:9 | LL | bar(closure); - | --- ^^^^^^^ the trait `T` is not implemented for closure `{closure@$DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:18:19: 18:21}` + | --- ^^^^^^^ unsatisfied trait bound | | | required by a bound introduced by this call | + = help: the trait `T` is not implemented for closure `{closure@$DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:18:19: 18:21}` note: required by a bound in `bar` --> $DIR/fn-ctor-passed-as-arg-where-it-should-have-been-called.rs:14:16 | diff --git a/tests/ui/suggestions/issue-84973-blacklist.rs b/tests/ui/suggestions/issue-84973-blacklist.rs index edc0637636b..7edf4d347af 100644 --- a/tests/ui/suggestions/issue-84973-blacklist.rs +++ b/tests/ui/suggestions/issue-84973-blacklist.rs @@ -1,5 +1,6 @@ // Checks that certain traits for which we don't want to suggest borrowing // are blacklisted and don't cause the suggestion to be issued. +//@compile-flags: --diagnostic-width=300 #![feature(coroutines)] diff --git a/tests/ui/suggestions/issue-84973-blacklist.stderr b/tests/ui/suggestions/issue-84973-blacklist.stderr index c1ef1cd428e..a6324a824c1 100644 --- a/tests/ui/suggestions/issue-84973-blacklist.stderr +++ b/tests/ui/suggestions/issue-84973-blacklist.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `String: Copy` is not satisfied - --> $DIR/issue-84973-blacklist.rs:15:12 + --> $DIR/issue-84973-blacklist.rs:16:12 | LL | f_copy("".to_string()); | ------ ^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` @@ -7,7 +7,7 @@ LL | f_copy("".to_string()); | required by a bound introduced by this call | note: required by a bound in `f_copy` - --> $DIR/issue-84973-blacklist.rs:6:14 + --> $DIR/issue-84973-blacklist.rs:7:14 | LL | fn f_copy(t: T) {} | ^^^^ required by this bound in `f_copy` @@ -18,7 +18,7 @@ LL + f_copy(""); | error[E0277]: the trait bound `S: Clone` is not satisfied - --> $DIR/issue-84973-blacklist.rs:16:13 + --> $DIR/issue-84973-blacklist.rs:17:13 | LL | f_clone(S); | ------- ^ the trait `Clone` is not implemented for `S` @@ -26,7 +26,7 @@ LL | f_clone(S); | required by a bound introduced by this call | note: required by a bound in `f_clone` - --> $DIR/issue-84973-blacklist.rs:7:15 + --> $DIR/issue-84973-blacklist.rs:8:15 | LL | fn f_clone(t: T) {} | ^^^^^ required by this bound in `f_clone` @@ -36,24 +36,24 @@ LL + #[derive(Clone)] LL | struct S; | -error[E0277]: `{static coroutine@$DIR/issue-84973-blacklist.rs:17:26: 17:35}` cannot be unpinned - --> $DIR/issue-84973-blacklist.rs:17:26 +error[E0277]: `{static coroutine@$DIR/issue-84973-blacklist.rs:18:26: 18:35}` cannot be unpinned + --> $DIR/issue-84973-blacklist.rs:18:26 | LL | f_unpin(#[coroutine] static || { yield; }); - | ------- ^^^^^^^^^^^^^^^^^^^^ the trait `Unpin` is not implemented for `{static coroutine@$DIR/issue-84973-blacklist.rs:17:26: 17:35}` + | ------- ^^^^^^^^^^^^^^^^^^^^ the trait `Unpin` is not implemented for `{static coroutine@$DIR/issue-84973-blacklist.rs:18:26: 18:35}` | | | required by a bound introduced by this call | = note: consider using the `pin!` macro consider using `Box::pin` if you need to access the pinned value outside of the current scope note: required by a bound in `f_unpin` - --> $DIR/issue-84973-blacklist.rs:8:15 + --> $DIR/issue-84973-blacklist.rs:9:15 | LL | fn f_unpin(t: T) {} | ^^^^^ required by this bound in `f_unpin` error[E0277]: the size for values of type `dyn Fn()` cannot be known at compilation time - --> $DIR/issue-84973-blacklist.rs:22:13 + --> $DIR/issue-84973-blacklist.rs:23:13 | LL | f_sized(*ref_cl); | ------- ^^^^^^^ doesn't have a size known at compile-time @@ -62,7 +62,7 @@ LL | f_sized(*ref_cl); | = help: the trait `Sized` is not implemented for `dyn Fn()` note: required by a bound in `f_sized` - --> $DIR/issue-84973-blacklist.rs:9:15 + --> $DIR/issue-84973-blacklist.rs:10:15 | LL | fn f_sized(t: T) {} | ^^^^^ required by this bound in `f_sized` @@ -73,7 +73,7 @@ LL + f_sized(ref_cl); | error[E0277]: `Rc<{integer}>` cannot be sent between threads safely - --> $DIR/issue-84973-blacklist.rs:27:12 + --> $DIR/issue-84973-blacklist.rs:28:12 | LL | f_send(rc); | ------ ^^ `Rc<{integer}>` cannot be sent between threads safely @@ -82,7 +82,7 @@ LL | f_send(rc); | = help: the trait `Send` is not implemented for `Rc<{integer}>` note: required by a bound in `f_send` - --> $DIR/issue-84973-blacklist.rs:10:14 + --> $DIR/issue-84973-blacklist.rs:11:14 | LL | fn f_send(t: T) {} | ^^^^ required by this bound in `f_send` diff --git a/tests/ui/traits/fn-pointer/bare-fn-no-impl-fn-ptr-99875.stderr b/tests/ui/traits/fn-pointer/bare-fn-no-impl-fn-ptr-99875.stderr index 0666da4c707..5b89158b0db 100644 --- a/tests/ui/traits/fn-pointer/bare-fn-no-impl-fn-ptr-99875.stderr +++ b/tests/ui/traits/fn-pointer/bare-fn-no-impl-fn-ptr-99875.stderr @@ -20,10 +20,11 @@ error[E0277]: the trait bound `{closure@$DIR/bare-fn-no-impl-fn-ptr-99875.rs:14: --> $DIR/bare-fn-no-impl-fn-ptr-99875.rs:14:11 | LL | takes(|_: Argument| -> Return { todo!() }); - | ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for closure `{closure@$DIR/bare-fn-no-impl-fn-ptr-99875.rs:14:11: 14:34}` + | ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound | | | required by a bound introduced by this call | + = help: the trait `Trait` is not implemented for closure `{closure@$DIR/bare-fn-no-impl-fn-ptr-99875.rs:14:11: 14:34}` = help: the trait `Trait` is implemented for fn pointer `fn(Argument) -> Return` note: required by a bound in `takes` --> $DIR/bare-fn-no-impl-fn-ptr-99875.rs:9:18 diff --git a/tests/ui/transmutability/assoc-bound.stderr b/tests/ui/transmutability/assoc-bound.stderr index 08d90894396..b3c7680bf29 100644 --- a/tests/ui/transmutability/assoc-bound.stderr +++ b/tests/ui/transmutability/assoc-bound.stderr @@ -2,8 +2,9 @@ error[E0277]: the trait bound `::AssocA: TransmuteFrom<(), Assume { alig --> $DIR/assoc-bound.rs:16:19 | LL | type AssocB = T::AssocA; - | ^^^^^^^^^ the trait `TransmuteFrom<(), Assume { alignment: false, lifetimes: false, safety: false, validity: false }>` is not implemented for `::AssocA` + | ^^^^^^^^^ unsatisfied trait bound | + = help: the trait `TransmuteFrom<(), Assume { alignment: false, lifetimes: false, safety: false, validity: false }>` is not implemented for `::AssocA` note: required by a bound in `B::AssocB` --> $DIR/assoc-bound.rs:9:18 | diff --git a/tests/ui/where-clauses/higher-ranked-fn-type.verbose.stderr b/tests/ui/where-clauses/higher-ranked-fn-type.verbose.stderr index bb99f4ad277..0d8ec5f8928 100644 --- a/tests/ui/where-clauses/higher-ranked-fn-type.verbose.stderr +++ b/tests/ui/where-clauses/higher-ranked-fn-type.verbose.stderr @@ -2,8 +2,9 @@ error[E0277]: the trait bound `for $DIR/higher-ranked-fn-type.rs:20:5 | LL | called() - | ^^^^^^^^ the trait `for Foo` is not implemented for `fn(&'^1_0.Named(DefId(0:6 ~ higher_ranked_fn_type[9e51]::called::'b), "'b") ())` + | ^^^^^^^^ unsatisfied trait bound | + = help: the trait `for Foo` is not implemented for `fn(&'^1_0.Named(DefId(0:6 ~ higher_ranked_fn_type[9e51]::called::'b), "'b") ())` help: this trait has no implementations, consider adding one --> $DIR/higher-ranked-fn-type.rs:6:1 | From 143b072c629c226c77aa06f225b9326f99698900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 25 Oct 2024 22:54:42 +0000 Subject: [PATCH 07/13] Account for negative bounds in E0277 note and suggestion Do not suggest `#[derive(Copy)]` when we wanted a `!Copy` type. Do not say "`Copy` is not implemented for `T` but `Copy` is". Do not talk about `Trait` having no implementations when `!Trait` was desired. --- .../src/error_reporting/traits/fulfillment_errors.rs | 6 +++++- .../src/error_reporting/traits/suggestions.rs | 3 +++ .../traits/negative-bounds/on-unimplemented.stderr | 6 ------ tests/ui/traits/negative-bounds/simple.stderr | 12 ------------ 4 files changed, 8 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index cef704d8328..524b4139600 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -2540,12 +2540,16 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { && self.tcx.trait_impls_of(trait_def_id).is_empty() && !self.tcx.trait_is_auto(trait_def_id) && !self.tcx.trait_is_alias(trait_def_id) + && trait_predicate.polarity() == ty::PredicatePolarity::Positive { err.span_help( self.tcx.def_span(trait_def_id), crate::fluent_generated::trait_selection_trait_has_no_impls, ); - } else if !suggested && !unsatisfied_const { + } else if !suggested + && !unsatisfied_const + && trait_predicate.polarity() == ty::PredicatePolarity::Positive + { // Can't show anything else useful, try to find similar impls. let impl_candidates = self.find_similar_impl_candidates(trait_predicate); if !self.report_similar_impl_candidates( diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 64edeb35dd2..68aa9cffef2 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -3697,6 +3697,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { err: &mut Diag<'_>, trait_pred: ty::PolyTraitPredicate<'tcx>, ) { + if trait_pred.polarity() == ty::PredicatePolarity::Negative { + return; + } let Some(diagnostic_name) = self.tcx.get_diagnostic_name(trait_pred.def_id()) else { return; }; diff --git a/tests/ui/traits/negative-bounds/on-unimplemented.stderr b/tests/ui/traits/negative-bounds/on-unimplemented.stderr index 07483e788e5..ed473d57917 100644 --- a/tests/ui/traits/negative-bounds/on-unimplemented.stderr +++ b/tests/ui/traits/negative-bounds/on-unimplemented.stderr @@ -6,12 +6,6 @@ LL | fn hello() -> impl !Foo { LL | LL | NotFoo | ------ return type was inferred to be `NotFoo` here - | -help: this trait has no implementations, consider adding one - --> $DIR/on-unimplemented.rs:4:1 - | -LL | trait Foo {} - | ^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/traits/negative-bounds/simple.stderr b/tests/ui/traits/negative-bounds/simple.stderr index f8a43e605c4..499c19bb854 100644 --- a/tests/ui/traits/negative-bounds/simple.stderr +++ b/tests/ui/traits/negative-bounds/simple.stderr @@ -28,18 +28,11 @@ error[E0277]: the trait bound `Copyable: !Copy` is not satisfied LL | not_copy::(); | ^^^^^^^^ the trait bound `Copyable: !Copy` is not satisfied | - = help: the trait `Copy` is not implemented for `Copyable` - but trait `Copy` is implemented for it note: required by a bound in `not_copy` --> $DIR/simple.rs:3:16 | LL | fn not_copy() {} | ^^^^^ required by this bound in `not_copy` -help: consider annotating `Copyable` with `#[derive(Copy)]` - | -LL + #[derive(Copy)] -LL | struct Copyable; - | error[E0277]: the trait bound `NotNecessarilyCopyable: !Copy` is not satisfied --> $DIR/simple.rs:37:16 @@ -52,11 +45,6 @@ note: required by a bound in `not_copy` | LL | fn not_copy() {} | ^^^^^ required by this bound in `not_copy` -help: consider annotating `NotNecessarilyCopyable` with `#[derive(Copy)]` - | -LL + #[derive(Copy)] -LL | struct NotNecessarilyCopyable; - | error: aborting due to 4 previous errors From 66351a61844aaabe76173c7c790c1a9adbc3d4a8 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 2 Nov 2024 09:59:55 +0100 Subject: [PATCH 08/13] get rid of a whole bunch of unnecessary rustc_const_unstable attributes --- library/core/src/array/iter.rs | 2 -- library/core/src/char/methods.rs | 1 - library/core/src/lib.rs | 5 ----- library/core/src/mem/maybe_uninit.rs | 6 ------ library/core/src/net/ip_addr.rs | 1 - library/core/src/num/f32.rs | 2 -- library/core/src/num/f64.rs | 2 -- library/core/src/num/int_macros.rs | 18 ------------------ library/core/src/num/mod.rs | 8 -------- library/core/src/num/nonzero.rs | 1 - library/core/src/num/uint_macros.rs | 16 ---------------- library/core/src/ptr/const_ptr.rs | 5 ----- library/core/src/ptr/mut_ptr.rs | 6 ------ library/core/src/ptr/non_null.rs | 9 --------- library/core/src/str/converts.rs | 2 -- library/core/src/sync/exclusive.rs | 2 -- library/core/src/task/wake.rs | 7 ------- library/core/src/time.rs | 2 -- library/core/src/unicode/unicode_data.rs | 3 --- library/core/tests/lib.rs | 2 -- .../src/range_search.rs | 1 - .../unicode-table-generator/src/raw_emitter.rs | 5 ----- 22 files changed, 106 deletions(-) diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index 2d19e4876f6..9ce0eb61e08 100644 --- a/library/core/src/array/iter.rs +++ b/library/core/src/array/iter.rs @@ -136,7 +136,6 @@ impl IntoIter { /// assert_eq!(r.collect::>(), vec![10, 11, 12, 13, 14, 15]); /// ``` #[unstable(feature = "array_into_iter_constructors", issue = "91583")] - #[rustc_const_unstable(feature = "const_array_into_iter_constructors", issue = "91583")] pub const unsafe fn new_unchecked( buffer: [MaybeUninit; N], initialized: Range, @@ -199,7 +198,6 @@ impl IntoIter { /// assert_eq!(get_bytes(false).collect::>(), vec![]); /// ``` #[unstable(feature = "array_into_iter_constructors", issue = "91583")] - #[rustc_const_unstable(feature = "const_array_into_iter_constructors", issue = "91583")] pub const fn empty() -> Self { let buffer = [const { MaybeUninit::uninit() }; N]; let initialized = 0..0; diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index 206bbf5690e..c37b9aa2aae 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -1515,7 +1515,6 @@ impl char { /// ``` #[must_use] #[unstable(feature = "is_ascii_octdigit", issue = "101288")] - #[rustc_const_unstable(feature = "is_ascii_octdigit", issue = "101288")] #[inline] pub const fn is_ascii_octdigit(&self) -> bool { matches!(*self, '0'..='7') diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 115fdd7a140..bbfe32027e8 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -115,8 +115,6 @@ #![feature(const_align_offset)] #![feature(const_alloc_layout)] #![feature(const_arguments_as_str)] -#![feature(const_array_into_iter_constructors)] -#![feature(const_bigint_helper_methods)] #![feature(const_black_box)] #![feature(const_char_encode_utf16)] #![feature(const_eval_select)] @@ -125,7 +123,6 @@ #![feature(const_hash)] #![feature(const_heap)] #![feature(const_nonnull_new)] -#![feature(const_num_midpoint)] #![feature(const_option_ext)] #![feature(const_pin_2)] #![feature(const_pointer_is_aligned)] @@ -135,7 +132,6 @@ #![feature(const_size_of_val)] #![feature(const_size_of_val_raw)] #![feature(const_sockaddr_setters)] -#![feature(const_strict_overflow_ops)] #![feature(const_swap)] #![feature(const_try)] #![feature(const_type_id)] @@ -167,7 +163,6 @@ #![feature(unchecked_neg)] #![feature(unchecked_shifts)] #![feature(utf16_extra)] -#![feature(utf16_extra_const)] #![feature(variant_count)] // tidy-alphabetical-end // diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index a57e265c7cc..8c6cdf57c58 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -338,7 +338,6 @@ impl MaybeUninit { /// let data = read(&mut buf); /// ``` #[unstable(feature = "maybe_uninit_uninit_array", issue = "96097")] - #[rustc_const_unstable(feature = "const_maybe_uninit_uninit_array", issue = "96097")] #[must_use] #[inline(always)] pub const fn uninit_array() -> [Self; N] { @@ -946,7 +945,6 @@ impl MaybeUninit { /// assert_eq!(array, [0, 1, 2]); /// ``` #[unstable(feature = "maybe_uninit_array_assume_init", issue = "96097")] - #[rustc_const_unstable(feature = "const_maybe_uninit_array_assume_init", issue = "96097")] #[inline(always)] #[track_caller] pub const unsafe fn array_assume_init(array: [Self; N]) -> [T; N] { @@ -973,7 +971,6 @@ impl MaybeUninit { /// /// [`assume_init_ref`]: MaybeUninit::assume_init_ref #[unstable(feature = "maybe_uninit_slice", issue = "63569")] - #[rustc_const_unstable(feature = "maybe_uninit_slice", issue = "63569")] #[inline(always)] pub const unsafe fn slice_assume_init_ref(slice: &[Self]) -> &[T] { // SAFETY: casting `slice` to a `*const [T]` is safe since the caller guarantees that @@ -995,7 +992,6 @@ impl MaybeUninit { /// /// [`assume_init_mut`]: MaybeUninit::assume_init_mut #[unstable(feature = "maybe_uninit_slice", issue = "63569")] - #[rustc_const_unstable(feature = "maybe_uninit_slice", issue = "63569")] #[inline(always)] pub const unsafe fn slice_assume_init_mut(slice: &mut [Self]) -> &mut [T] { // SAFETY: similar to safety notes for `slice_get_ref`, but we have a @@ -1005,7 +1001,6 @@ impl MaybeUninit { /// Gets a pointer to the first element of the array. #[unstable(feature = "maybe_uninit_slice", issue = "63569")] - #[rustc_const_unstable(feature = "maybe_uninit_slice", issue = "63569")] #[inline(always)] pub const fn slice_as_ptr(this: &[MaybeUninit]) -> *const T { this.as_ptr() as *const T @@ -1013,7 +1008,6 @@ impl MaybeUninit { /// Gets a mutable pointer to the first element of the array. #[unstable(feature = "maybe_uninit_slice", issue = "63569")] - #[rustc_const_unstable(feature = "maybe_uninit_slice", issue = "63569")] #[inline(always)] pub const fn slice_as_mut_ptr(this: &mut [MaybeUninit]) -> *mut T { this.as_mut_ptr() as *mut T diff --git a/library/core/src/net/ip_addr.rs b/library/core/src/net/ip_addr.rs index 0d1f4a9ea3e..d3360c18207 100644 --- a/library/core/src/net/ip_addr.rs +++ b/library/core/src/net/ip_addr.rs @@ -373,7 +373,6 @@ impl IpAddr { /// assert_eq!(IpAddr::V6(Ipv6Addr::new(0x2001, 0x2, 0, 0, 0, 0, 0, 0)).is_benchmarking(), true); /// ``` #[unstable(feature = "ip", issue = "27709")] - #[rustc_const_unstable(feature = "const_ipv4", issue = "76205")] #[must_use] #[inline] pub const fn is_benchmarking(&self) -> bool { diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index a01761ee5d4..2672fe773c2 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -748,7 +748,6 @@ impl f32 { /// [`MAX`]: Self::MAX #[inline] #[unstable(feature = "float_next_up_down", issue = "91399")] - #[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")] pub const fn next_up(self) -> Self { // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing // denormals to zero. This is in general unsound and unsupported, but here @@ -797,7 +796,6 @@ impl f32 { /// [`MAX`]: Self::MAX #[inline] #[unstable(feature = "float_next_up_down", issue = "91399")] - #[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")] pub const fn next_down(self) -> Self { // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing // denormals to zero. This is in general unsound and unsupported, but here diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index 2995e41cd6e..86082650e55 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -765,7 +765,6 @@ impl f64 { /// [`MAX`]: Self::MAX #[inline] #[unstable(feature = "float_next_up_down", issue = "91399")] - #[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")] pub const fn next_up(self) -> Self { // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing // denormals to zero. This is in general unsound and unsupported, but here @@ -814,7 +813,6 @@ impl f64 { /// [`MAX`]: Self::MAX #[inline] #[unstable(feature = "float_next_up_down", issue = "91399")] - #[rustc_const_unstable(feature = "float_next_up_down", issue = "91399")] pub const fn next_down(self) -> Self { // Some targets violate Rust's assumption of IEEE semantics, e.g. by flushing // denormals to zero. This is in general unsound and unsupported, but here diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 72adb1bf190..440e75c2113 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -477,7 +477,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = (", stringify!($SelfT), "::MAX - 2).strict_add(3);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -573,7 +572,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = (", stringify!($SelfT), "::MAX - 2).strict_add_unsigned(3);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -629,7 +627,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = (", stringify!($SelfT), "::MIN + 2).strict_sub(3);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -725,7 +722,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = (", stringify!($SelfT), "::MIN + 2).strict_sub_unsigned(3);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -781,7 +777,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = ", stringify!($SelfT), "::MAX.strict_mul(2);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -895,7 +890,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = (1", stringify!($SelfT), ").strict_div(0);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -969,7 +963,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = (1", stringify!($SelfT), ").strict_div_euclid(0);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1042,7 +1035,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.strict_rem(-1);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1115,7 +1107,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.strict_rem_euclid(-1);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1203,7 +1194,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.strict_neg();")] /// #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1266,7 +1256,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = 0x1", stringify!($SelfT), ".strict_shl(129);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1325,7 +1314,6 @@ macro_rules! int_impl { #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".unbounded_shl(129), 0);")] /// ``` #[unstable(feature = "unbounded_shifts", issue = "129375")] - #[rustc_const_unstable(feature = "const_unbounded_shifts", issue = "129375")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1391,7 +1379,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = 0x10", stringify!($SelfT), ".strict_shr(128);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1452,7 +1439,6 @@ macro_rules! int_impl { #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.unbounded_shr(129), -1);")] /// ``` #[unstable(feature = "unbounded_shifts", issue = "129375")] - #[rustc_const_unstable(feature = "const_unbounded_shifts", issue = "129375")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1519,7 +1505,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.strict_abs();")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1594,7 +1579,6 @@ macro_rules! int_impl { #[doc = concat!("let _ = ", stringify!($SelfT), "::MAX.strict_pow(2);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -2368,7 +2352,6 @@ macro_rules! int_impl { /// assert_eq!((sum1, sum0), (6, 8)); /// ``` #[unstable(feature = "bigint_helper_methods", issue = "85532")] - #[rustc_const_unstable(feature = "const_bigint_helper_methods", issue = "85532")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -2476,7 +2459,6 @@ macro_rules! int_impl { #[doc = concat!("assert_eq!((diff1, diff0), (10, ", stringify!($UnsignedT), "::MAX));")] /// ``` #[unstable(feature = "bigint_helper_methods", issue = "85532")] - #[rustc_const_unstable(feature = "const_bigint_helper_methods", issue = "85532")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 6a0b40ff517..9e0af8b2ace 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -114,7 +114,6 @@ macro_rules! midpoint_impl { #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".midpoint(4), 2);")] /// ``` #[unstable(feature = "num_midpoint", issue = "110840")] - #[rustc_const_unstable(feature = "const_num_midpoint", issue = "110840")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -142,7 +141,6 @@ macro_rules! midpoint_impl { #[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(7), 3);")] /// ``` #[unstable(feature = "num_midpoint", issue = "110840")] - #[rustc_const_unstable(feature = "const_num_midpoint", issue = "110840")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -170,7 +168,6 @@ macro_rules! midpoint_impl { #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".midpoint(4), 2);")] /// ``` #[unstable(feature = "num_midpoint", issue = "110840")] - #[rustc_const_unstable(feature = "const_num_midpoint", issue = "110840")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -196,7 +193,6 @@ macro_rules! midpoint_impl { #[doc = concat!("assert_eq!(0", stringify!($SelfT), ".midpoint(7), 3);")] /// ``` #[unstable(feature = "num_midpoint", issue = "110840")] - #[rustc_const_unstable(feature = "const_num_midpoint", issue = "110840")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -229,7 +225,6 @@ macro_rules! widening_impl { /// assert_eq!(1_000_000_000u32.widening_mul(10), (1410065408, 2)); /// ``` #[unstable(feature = "bigint_helper_methods", issue = "85532")] - #[rustc_const_unstable(feature = "const_bigint_helper_methods", issue = "85532")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -320,7 +315,6 @@ macro_rules! widening_impl { /// ); /// ``` #[unstable(feature = "bigint_helper_methods", issue = "85532")] - #[rustc_const_unstable(feature = "bigint_helper_methods", issue = "85532")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -915,7 +909,6 @@ impl u8 { /// ``` #[must_use] #[unstable(feature = "is_ascii_octdigit", issue = "101288")] - #[rustc_const_unstable(feature = "is_ascii_octdigit", issue = "101288")] #[inline] pub const fn is_ascii_octdigit(&self) -> bool { matches!(*self, b'0'..=b'7') @@ -1195,7 +1188,6 @@ impl u16 { /// ``` #[must_use] #[unstable(feature = "utf16_extra", issue = "94919")] - #[rustc_const_unstable(feature = "utf16_extra_const", issue = "94919")] #[inline] pub const fn is_utf16_surrogate(self) -> bool { matches!(self, 0xD800..=0xDFFF) diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index f04c83693ef..e2560f48e59 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -1474,7 +1474,6 @@ macro_rules! nonzero_integer_signedness_dependent_methods { /// # } /// ``` #[unstable(feature = "num_midpoint", issue = "110840")] - #[rustc_const_unstable(feature = "const_num_midpoint", issue = "110840")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index ded8997c634..550b6a087f9 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -524,7 +524,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = (", stringify!($SelfT), "::MAX - 2).strict_add(3);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -626,7 +625,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = (", stringify!($SelfT), "::MAX - 2).strict_add_signed(3);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -691,7 +689,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = 0", stringify!($SelfT), ".strict_sub(1);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -873,7 +870,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = ", stringify!($SelfT), "::MAX.strict_mul(2);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -975,7 +971,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = (1", stringify!($SelfT), ").strict_div(0);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] @@ -1035,7 +1030,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = (1", stringify!($SelfT), ").strict_div_euclid(0);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] @@ -1097,7 +1091,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = 5", stringify!($SelfT), ".strict_rem(0);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] @@ -1159,7 +1152,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = 5", stringify!($SelfT), ".strict_rem_euclid(0);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] @@ -1392,7 +1384,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = 1", stringify!($SelfT), ".strict_neg();")] /// #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1455,7 +1446,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = 0x10", stringify!($SelfT), ".strict_shl(129);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1514,7 +1504,6 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".unbounded_shl(129), 0);")] /// ``` #[unstable(feature = "unbounded_shifts", issue = "129375")] - #[rustc_const_unstable(feature = "const_unbounded_shifts", issue = "129375")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1580,7 +1569,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = 0x10", stringify!($SelfT), ".strict_shr(129);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1639,7 +1627,6 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".unbounded_shr(129), 0);")] /// ``` #[unstable(feature = "unbounded_shifts", issue = "129375")] - #[rustc_const_unstable(feature = "const_unbounded_shifts", issue = "129375")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1714,7 +1701,6 @@ macro_rules! uint_impl { #[doc = concat!("let _ = ", stringify!($SelfT), "::MAX.strict_pow(2);")] /// ``` #[unstable(feature = "strict_overflow_ops", issue = "118260")] - #[rustc_const_unstable(feature = "const_strict_overflow_ops", issue = "118260")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -2290,7 +2276,6 @@ macro_rules! uint_impl { /// assert_eq!((sum1, sum0), (9, 6)); /// ``` #[unstable(feature = "bigint_helper_methods", issue = "85532")] - #[rustc_const_unstable(feature = "const_bigint_helper_methods", issue = "85532")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -2382,7 +2367,6 @@ macro_rules! uint_impl { #[doc = concat!("assert_eq!((diff1, diff0), (3, ", stringify!($SelfT), "::MAX));")] /// ``` #[unstable(feature = "bigint_helper_methods", issue = "85532")] - #[rustc_const_unstable(feature = "const_bigint_helper_methods", issue = "85532")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 57a7c0fc092..f00984da527 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -240,7 +240,6 @@ impl *const T { /// /// The pointer can be later reconstructed with [`from_raw_parts`]. #[unstable(feature = "ptr_metadata", issue = "81513")] - #[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")] #[inline] pub const fn to_raw_parts(self) -> (*const (), ::Metadata) { (self.cast(), metadata(self)) @@ -316,7 +315,6 @@ impl *const T { /// ``` // FIXME: mention it in the docs for `as_ref` and `as_uninit_ref` once stabilized. #[unstable(feature = "ptr_as_ref_unchecked", issue = "122034")] - #[rustc_const_unstable(feature = "ptr_as_ref_unchecked", issue = "122034")] #[inline] #[must_use] pub const unsafe fn as_ref_unchecked<'a>(self) -> &'a T { @@ -1714,7 +1712,6 @@ impl *const [T] { /// ``` #[inline] #[unstable(feature = "slice_ptr_get", issue = "74265")] - #[rustc_const_unstable(feature = "slice_ptr_get", issue = "74265")] pub const fn as_ptr(self) -> *const T { self as *const T } @@ -1814,7 +1811,6 @@ impl *const [T; N] { /// ``` #[inline] #[unstable(feature = "array_ptr_get", issue = "119834")] - #[rustc_const_unstable(feature = "array_ptr_get", issue = "119834")] pub const fn as_ptr(self) -> *const T { self as *const T } @@ -1832,7 +1828,6 @@ impl *const [T; N] { /// ``` #[inline] #[unstable(feature = "array_ptr_get", issue = "119834")] - #[rustc_const_unstable(feature = "array_ptr_get", issue = "119834")] pub const fn as_slice(self) -> *const [T] { self } diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 7aa6a309a06..60a2dcd1ee7 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -225,7 +225,6 @@ impl *mut T { /// /// The pointer can be later reconstructed with [`from_raw_parts_mut`]. #[unstable(feature = "ptr_metadata", issue = "81513")] - #[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")] #[inline] pub const fn to_raw_parts(self) -> (*mut (), ::Metadata) { (self.cast(), super::metadata(self)) @@ -306,7 +305,6 @@ impl *mut T { /// ``` // FIXME: mention it in the docs for `as_ref` and `as_uninit_ref` once stabilized. #[unstable(feature = "ptr_as_ref_unchecked", issue = "122034")] - #[rustc_const_unstable(feature = "ptr_as_ref_unchecked", issue = "122034")] #[inline] #[must_use] pub const unsafe fn as_ref_unchecked<'a>(self) -> &'a T { @@ -659,7 +657,6 @@ impl *mut T { /// ``` // FIXME: mention it in the docs for `as_mut` and `as_uninit_mut` once stabilized. #[unstable(feature = "ptr_as_ref_unchecked", issue = "122034")] - #[rustc_const_unstable(feature = "ptr_as_ref_unchecked", issue = "122034")] #[inline] #[must_use] pub const unsafe fn as_mut_unchecked<'a>(self) -> &'a mut T { @@ -2059,7 +2056,6 @@ impl *mut [T] { /// ``` #[inline(always)] #[unstable(feature = "slice_ptr_get", issue = "74265")] - #[rustc_const_unstable(feature = "slice_ptr_get", issue = "74265")] pub const fn as_mut_ptr(self) -> *mut T { self as *mut T } @@ -2215,7 +2211,6 @@ impl *mut [T; N] { /// ``` #[inline] #[unstable(feature = "array_ptr_get", issue = "119834")] - #[rustc_const_unstable(feature = "array_ptr_get", issue = "119834")] pub const fn as_mut_ptr(self) -> *mut T { self as *mut T } @@ -2236,7 +2231,6 @@ impl *mut [T; N] { /// ``` #[inline] #[unstable(feature = "array_ptr_get", issue = "119834")] - #[rustc_const_unstable(feature = "array_ptr_get", issue = "119834")] pub const fn as_mut_slice(self) -> *mut [T] { self } diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index afc0c0123fa..44eeb052661 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -131,7 +131,6 @@ impl NonNull { #[inline] #[must_use] #[unstable(feature = "ptr_as_uninit", issue = "75402")] - #[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")] pub const unsafe fn as_uninit_ref<'a>(self) -> &'a MaybeUninit { // SAFETY: the caller must guarantee that `self` meets all the // requirements for a reference. @@ -155,7 +154,6 @@ impl NonNull { #[inline] #[must_use] #[unstable(feature = "ptr_as_uninit", issue = "75402")] - #[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")] pub const unsafe fn as_uninit_mut<'a>(self) -> &'a mut MaybeUninit { // SAFETY: the caller must guarantee that `self` meets all the // requirements for a reference. @@ -230,7 +228,6 @@ impl NonNull { /// Converts a reference to a `NonNull` pointer. #[unstable(feature = "non_null_from_ref", issue = "130823")] - #[rustc_const_unstable(feature = "non_null_from_ref", issue = "130823")] #[inline] pub const fn from_ref(r: &T) -> Self { // SAFETY: A reference cannot be null. @@ -239,7 +236,6 @@ impl NonNull { /// Converts a mutable reference to a `NonNull` pointer. #[unstable(feature = "non_null_from_ref", issue = "130823")] - #[rustc_const_unstable(feature = "non_null_from_ref", issue = "130823")] #[inline] pub const fn from_mut(r: &mut T) -> Self { // SAFETY: A mutable reference cannot be null. @@ -253,7 +249,6 @@ impl NonNull { /// /// [`std::ptr::from_raw_parts`]: crate::ptr::from_raw_parts #[unstable(feature = "ptr_metadata", issue = "81513")] - #[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")] #[inline] pub const fn from_raw_parts( data_pointer: NonNull<()>, @@ -269,7 +264,6 @@ impl NonNull { /// /// The pointer can be later reconstructed with [`NonNull::from_raw_parts`]. #[unstable(feature = "ptr_metadata", issue = "81513")] - #[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1545,7 +1539,6 @@ impl NonNull<[T]> { #[inline] #[must_use] #[unstable(feature = "slice_ptr_get", issue = "74265")] - #[rustc_const_unstable(feature = "slice_ptr_get", issue = "74265")] #[rustc_never_returns_null_ptr] pub const fn as_mut_ptr(self) -> *mut T { self.as_non_null_ptr().as_ptr() @@ -1591,7 +1584,6 @@ impl NonNull<[T]> { #[inline] #[must_use] #[unstable(feature = "ptr_as_uninit", issue = "75402")] - #[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")] pub const unsafe fn as_uninit_slice<'a>(self) -> &'a [MaybeUninit] { // SAFETY: the caller must uphold the safety contract for `as_uninit_slice`. unsafe { slice::from_raw_parts(self.cast().as_ptr(), self.len()) } @@ -1656,7 +1648,6 @@ impl NonNull<[T]> { #[inline] #[must_use] #[unstable(feature = "ptr_as_uninit", issue = "75402")] - #[rustc_const_unstable(feature = "ptr_as_uninit", issue = "75402")] pub const unsafe fn as_uninit_slice_mut<'a>(self) -> &'a mut [MaybeUninit] { // SAFETY: the caller must uphold the safety contract for `as_uninit_slice_mut`. unsafe { slice::from_raw_parts_mut(self.cast().as_ptr(), self.len()) } diff --git a/library/core/src/str/converts.rs b/library/core/src/str/converts.rs index c997e5e443d..2bc1f1e4973 100644 --- a/library/core/src/str/converts.rs +++ b/library/core/src/str/converts.rs @@ -218,7 +218,6 @@ pub const unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str { #[inline] #[must_use] #[unstable(feature = "str_from_raw_parts", issue = "119206")] -#[rustc_const_unstable(feature = "str_from_raw_parts", issue = "119206")] pub const unsafe fn from_raw_parts<'a>(ptr: *const u8, len: usize) -> &'a str { // SAFETY: the caller must uphold the safety contract for `from_raw_parts`. unsafe { &*ptr::from_raw_parts(ptr, len) } @@ -237,7 +236,6 @@ pub const unsafe fn from_raw_parts<'a>(ptr: *const u8, len: usize) -> &'a str { #[inline] #[must_use] #[unstable(feature = "str_from_raw_parts", issue = "119206")] -#[rustc_const_unstable(feature = "const_str_from_raw_parts_mut", issue = "119206")] pub const unsafe fn from_raw_parts_mut<'a>(ptr: *mut u8, len: usize) -> &'a mut str { // SAFETY: the caller must uphold the safety contract for `from_raw_parts_mut`. unsafe { &mut *ptr::from_raw_parts_mut(ptr, len) } diff --git a/library/core/src/sync/exclusive.rs b/library/core/src/sync/exclusive.rs index af25f139739..340b0b79e40 100644 --- a/library/core/src/sync/exclusive.rs +++ b/library/core/src/sync/exclusive.rs @@ -130,7 +130,6 @@ impl Exclusive { /// access to the underlying value, but _pinned_ `Exclusive`s only /// produce _pinned_ access to the underlying value. #[unstable(feature = "exclusive_wrapper", issue = "98407")] - #[rustc_const_unstable(feature = "exclusive_wrapper", issue = "98407")] #[must_use] #[inline] pub const fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut T> { @@ -154,7 +153,6 @@ impl Exclusive { /// a _pinned mutable_ reference to a `T`. This allows you to skip /// building an `Exclusive` with [`Exclusive::new`]. #[unstable(feature = "exclusive_wrapper", issue = "98407")] - #[rustc_const_unstable(feature = "exclusive_wrapper", issue = "98407")] #[must_use] #[inline] pub const fn from_pin_mut(r: Pin<&'_ mut T>) -> Pin<&'_ mut Exclusive> { diff --git a/library/core/src/task/wake.rs b/library/core/src/task/wake.rs index fb7af8234dd..34673707f01 100644 --- a/library/core/src/task/wake.rs +++ b/library/core/src/task/wake.rs @@ -253,7 +253,6 @@ impl<'a> Context<'a> { /// Returns a reference to the [`LocalWaker`] for the current task. #[inline] #[unstable(feature = "local_waker", issue = "118959")] - #[rustc_const_unstable(feature = "local_waker", issue = "118959")] pub const fn local_waker(&self) -> &'a LocalWaker { &self.local_waker } @@ -261,7 +260,6 @@ impl<'a> Context<'a> { /// Returns a reference to the extension data for the current task. #[inline] #[unstable(feature = "context_ext", issue = "123392")] - #[rustc_const_unstable(feature = "context_ext", issue = "123392")] pub const fn ext(&mut self) -> &mut dyn Any { // FIXME: this field makes Context extra-weird about unwind safety // can we justify AssertUnwindSafe if we stabilize this? do we care? @@ -337,7 +335,6 @@ impl<'a> ContextBuilder<'a> { /// Creates a ContextBuilder from an existing Context. #[inline] #[unstable(feature = "context_ext", issue = "123392")] - #[rustc_const_unstable(feature = "context_ext", issue = "123392")] pub const fn from(cx: &'a mut Context<'_>) -> Self { let ext = match &mut cx.ext.0 { ExtData::Some(ext) => ExtData::Some(*ext), @@ -355,7 +352,6 @@ impl<'a> ContextBuilder<'a> { /// Sets the value for the waker on `Context`. #[inline] #[unstable(feature = "context_ext", issue = "123392")] - #[rustc_const_unstable(feature = "context_ext", issue = "123392")] pub const fn waker(self, waker: &'a Waker) -> Self { Self { waker, ..self } } @@ -363,7 +359,6 @@ impl<'a> ContextBuilder<'a> { /// Sets the value for the local waker on `Context`. #[inline] #[unstable(feature = "local_waker", issue = "118959")] - #[rustc_const_unstable(feature = "local_waker", issue = "118959")] pub const fn local_waker(self, local_waker: &'a LocalWaker) -> Self { Self { local_waker, ..self } } @@ -371,7 +366,6 @@ impl<'a> ContextBuilder<'a> { /// Sets the value for the extension data on `Context`. #[inline] #[unstable(feature = "context_ext", issue = "123392")] - #[rustc_const_unstable(feature = "context_ext", issue = "123392")] pub const fn ext(self, data: &'a mut dyn Any) -> Self { Self { ext: ExtData::Some(data), ..self } } @@ -834,7 +828,6 @@ impl LocalWaker { #[inline] #[must_use] #[unstable(feature = "local_waker", issue = "118959")] - #[rustc_const_unstable(feature = "local_waker", issue = "118959")] pub const unsafe fn from_raw(waker: RawWaker) -> LocalWaker { Self { waker } } diff --git a/library/core/src/time.rs b/library/core/src/time.rs index 5081e777af4..2d93148bac0 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -883,7 +883,6 @@ impl Duration { #[unstable(feature = "duration_millis_float", issue = "122451")] #[must_use] #[inline] - #[rustc_const_unstable(feature = "duration_millis_float", issue = "122451")] pub const fn as_millis_f64(&self) -> f64 { (self.secs as f64) * (MILLIS_PER_SEC as f64) + (self.nanos.0 as f64) / (NANOS_PER_MILLI as f64) @@ -904,7 +903,6 @@ impl Duration { #[unstable(feature = "duration_millis_float", issue = "122451")] #[must_use] #[inline] - #[rustc_const_unstable(feature = "duration_millis_float", issue = "122451")] pub const fn as_millis_f32(&self) -> f32 { (self.secs as f32) * (MILLIS_PER_SEC as f32) + (self.nanos.0 as f32) / (NANOS_PER_MILLI as f32) diff --git a/library/core/src/unicode/unicode_data.rs b/library/core/src/unicode/unicode_data.rs index cba53bf5054..4101aa5292e 100644 --- a/library/core/src/unicode/unicode_data.rs +++ b/library/core/src/unicode/unicode_data.rs @@ -1,6 +1,5 @@ ///! This file is generated by src/tools/unicode-table-generator; do not edit manually! -#[rustc_const_unstable(feature = "const_unicode_case_lookup", issue = "101400")] #[inline(always)] const fn bitset_search< const N: usize, @@ -424,7 +423,6 @@ pub mod lowercase { (5, 187), (6, 78), (7, 132), ]; - #[rustc_const_unstable(feature = "const_unicode_case_lookup", issue = "101400")] pub const fn lookup(c: char) -> bool { super::bitset_search( c as u32, @@ -549,7 +547,6 @@ pub mod uppercase { (2, 146), (2, 20), (3, 146), (3, 140), (3, 134), (4, 178), (4, 171), ]; - #[rustc_const_unstable(feature = "const_unicode_case_lookup", issue = "101400")] pub const fn lookup(c: char) -> bool { super::bitset_search( c as u32, diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 2a9f1660a62..7346d9f2319 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -17,13 +17,11 @@ #![feature(clone_to_uninit)] #![feature(const_align_of_val_raw)] #![feature(const_align_offset)] -#![feature(const_bigint_helper_methods)] #![feature(const_black_box)] #![feature(const_eval_select)] #![feature(const_hash)] #![feature(const_heap)] #![feature(const_nonnull_new)] -#![feature(const_num_midpoint)] #![feature(const_option_ext)] #![feature(const_pin_2)] #![feature(const_pointer_is_aligned)] diff --git a/src/tools/unicode-table-generator/src/range_search.rs b/src/tools/unicode-table-generator/src/range_search.rs index 221e5d75ef5..9a51979a2f0 100644 --- a/src/tools/unicode-table-generator/src/range_search.rs +++ b/src/tools/unicode-table-generator/src/range_search.rs @@ -1,4 +1,3 @@ -#[rustc_const_unstable(feature = "const_unicode_case_lookup", issue = "101400")] #[inline(always)] const fn bitset_search< const N: usize, diff --git a/src/tools/unicode-table-generator/src/raw_emitter.rs b/src/tools/unicode-table-generator/src/raw_emitter.rs index 8097d6a8caf..46010692fe5 100644 --- a/src/tools/unicode-table-generator/src/raw_emitter.rs +++ b/src/tools/unicode-table-generator/src/raw_emitter.rs @@ -97,11 +97,6 @@ impl RawEmitter { self.blank_line(); - writeln!( - &mut self.file, - r#"#[rustc_const_unstable(feature = "const_unicode_case_lookup", issue = "101400")]"# - ) - .unwrap(); writeln!(&mut self.file, "pub const fn lookup(c: char) -> bool {{").unwrap(); if first_code_point > 0x7f { writeln!(&mut self.file, " (c as u32) >= {first_code_point:#04x} &&").unwrap(); From 7e0d3ed9511f17097f9c88d849321267debd4a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 2 Nov 2024 16:58:50 +0000 Subject: [PATCH 09/13] fix tests Paths in CI can be longer than in devs' machines. --- tests/ui/coroutine/static-not-unpin.current.stderr | 8 ++++---- tests/ui/coroutine/static-not-unpin.next.stderr | 8 ++++---- tests/ui/coroutine/static-not-unpin.rs | 3 ++- tests/ui/traits/next-solver/coroutine.rs | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/ui/coroutine/static-not-unpin.current.stderr b/tests/ui/coroutine/static-not-unpin.current.stderr index 7d6260ac569..19a6e72ccf1 100644 --- a/tests/ui/coroutine/static-not-unpin.current.stderr +++ b/tests/ui/coroutine/static-not-unpin.current.stderr @@ -1,15 +1,15 @@ -error[E0277]: `{static coroutine@$DIR/static-not-unpin.rs:15:5: 15:14}` cannot be unpinned - --> $DIR/static-not-unpin.rs:18:18 +error[E0277]: `{static coroutine@$DIR/static-not-unpin.rs:16:5: 16:14}` cannot be unpinned + --> $DIR/static-not-unpin.rs:19:18 | LL | assert_unpin(coroutine); - | ------------ ^^^^^^^^^ the trait `Unpin` is not implemented for `{static coroutine@$DIR/static-not-unpin.rs:15:5: 15:14}` + | ------------ ^^^^^^^^^ the trait `Unpin` is not implemented for `{static coroutine@$DIR/static-not-unpin.rs:16:5: 16:14}` | | | required by a bound introduced by this call | = note: consider using the `pin!` macro consider using `Box::pin` if you need to access the pinned value outside of the current scope note: required by a bound in `assert_unpin` - --> $DIR/static-not-unpin.rs:11:20 + --> $DIR/static-not-unpin.rs:12:20 | LL | fn assert_unpin(_: T) {} | ^^^^^ required by this bound in `assert_unpin` diff --git a/tests/ui/coroutine/static-not-unpin.next.stderr b/tests/ui/coroutine/static-not-unpin.next.stderr index 7d6260ac569..19a6e72ccf1 100644 --- a/tests/ui/coroutine/static-not-unpin.next.stderr +++ b/tests/ui/coroutine/static-not-unpin.next.stderr @@ -1,15 +1,15 @@ -error[E0277]: `{static coroutine@$DIR/static-not-unpin.rs:15:5: 15:14}` cannot be unpinned - --> $DIR/static-not-unpin.rs:18:18 +error[E0277]: `{static coroutine@$DIR/static-not-unpin.rs:16:5: 16:14}` cannot be unpinned + --> $DIR/static-not-unpin.rs:19:18 | LL | assert_unpin(coroutine); - | ------------ ^^^^^^^^^ the trait `Unpin` is not implemented for `{static coroutine@$DIR/static-not-unpin.rs:15:5: 15:14}` + | ------------ ^^^^^^^^^ the trait `Unpin` is not implemented for `{static coroutine@$DIR/static-not-unpin.rs:16:5: 16:14}` | | | required by a bound introduced by this call | = note: consider using the `pin!` macro consider using `Box::pin` if you need to access the pinned value outside of the current scope note: required by a bound in `assert_unpin` - --> $DIR/static-not-unpin.rs:11:20 + --> $DIR/static-not-unpin.rs:12:20 | LL | fn assert_unpin(_: T) {} | ^^^^^ required by this bound in `assert_unpin` diff --git a/tests/ui/coroutine/static-not-unpin.rs b/tests/ui/coroutine/static-not-unpin.rs index 54148368b13..b66a248654e 100644 --- a/tests/ui/coroutine/static-not-unpin.rs +++ b/tests/ui/coroutine/static-not-unpin.rs @@ -1,6 +1,7 @@ //@ revisions: current next //@ ignore-compare-mode-next-solver (explicit revisions) -//@[next] compile-flags: -Znext-solver +//@[next] compile-flags: -Znext-solver --diagnostic-width=300 +//@[current] compile-flags: --diagnostic-width=300 #![feature(coroutines, stmt_expr_attributes)] diff --git a/tests/ui/traits/next-solver/coroutine.rs b/tests/ui/traits/next-solver/coroutine.rs index bdc34842f6d..7f75f29e4b1 100644 --- a/tests/ui/traits/next-solver/coroutine.rs +++ b/tests/ui/traits/next-solver/coroutine.rs @@ -1,4 +1,4 @@ -//@ compile-flags: -Znext-solver +//@ compile-flags: -Znext-solver --diagnostic-width=300 //@ edition: 2021 //@ revisions: pass fail //@[pass] check-pass From 77d0b4ddfb92108a4c7d97c8f5052aa6abc787fa Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sun, 26 May 2024 20:50:30 +0200 Subject: [PATCH 10/13] move deployment-target tests to print-request --- tests/ui/{deployment-target => print-request}/invalid-target.rs | 0 .../ui/{deployment-target => print-request}/invalid-target.stderr | 0 tests/ui/{deployment-target => print-request}/macos-target.rs | 0 tests/ui/{deployment-target => print-request}/macos-target.stdout | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename tests/ui/{deployment-target => print-request}/invalid-target.rs (100%) rename tests/ui/{deployment-target => print-request}/invalid-target.stderr (100%) rename tests/ui/{deployment-target => print-request}/macos-target.rs (100%) rename tests/ui/{deployment-target => print-request}/macos-target.stdout (100%) diff --git a/tests/ui/deployment-target/invalid-target.rs b/tests/ui/print-request/invalid-target.rs similarity index 100% rename from tests/ui/deployment-target/invalid-target.rs rename to tests/ui/print-request/invalid-target.rs diff --git a/tests/ui/deployment-target/invalid-target.stderr b/tests/ui/print-request/invalid-target.stderr similarity index 100% rename from tests/ui/deployment-target/invalid-target.stderr rename to tests/ui/print-request/invalid-target.stderr diff --git a/tests/ui/deployment-target/macos-target.rs b/tests/ui/print-request/macos-target.rs similarity index 100% rename from tests/ui/deployment-target/macos-target.rs rename to tests/ui/print-request/macos-target.rs diff --git a/tests/ui/deployment-target/macos-target.stdout b/tests/ui/print-request/macos-target.stdout similarity index 100% rename from tests/ui/deployment-target/macos-target.stdout rename to tests/ui/print-request/macos-target.stdout From a26450cf81d67d68d3c6157579f8d968349129e7 Mon Sep 17 00:00:00 2001 From: Noratrieb <48135649+Noratrieb@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:02:32 +0200 Subject: [PATCH 11/13] Rename target triple to target tuple in many places in the compiler This changes the naming to the new naming, used by `--print target-tuple`. It does not change all locations, but many. --- .../rustc_codegen_cranelift/src/global_asm.rs | 4 +- compiler/rustc_codegen_gcc/src/consts.rs | 2 +- compiler/rustc_codegen_llvm/src/back/write.rs | 6 +- compiler/rustc_codegen_ssa/src/back/link.rs | 8 +- compiler/rustc_codegen_ssa/src/back/linker.rs | 2 +- compiler/rustc_driver_impl/src/lib.rs | 14 +- compiler/rustc_errors/src/diagnostic_impls.rs | 4 +- compiler/rustc_hir_typeck/src/lib.rs | 2 +- compiler/rustc_interface/src/util.rs | 4 +- compiler/rustc_metadata/src/creader.rs | 6 +- compiler/rustc_metadata/src/errors.rs | 6 +- compiler/rustc_metadata/src/locator.rs | 16 +- compiler/rustc_metadata/src/rmeta/decoder.rs | 2 +- compiler/rustc_metadata/src/rmeta/mod.rs | 4 +- compiler/rustc_session/src/config.rs | 20 +-- compiler/rustc_session/src/config/cfg.rs | 4 +- compiler/rustc_session/src/errors.rs | 8 +- compiler/rustc_session/src/filesearch.rs | 4 +- compiler/rustc_session/src/options.rs | 4 +- compiler/rustc_session/src/search_paths.rs | 6 +- compiler/rustc_session/src/session.rs | 12 +- compiler/rustc_target/src/spec/mod.rs | 145 +++++++++--------- src/doc/rustdoc/src/command-line-arguments.md | 2 +- src/librustdoc/config.rs | 4 +- src/librustdoc/doctest.rs | 12 +- src/tools/compiletest/src/common.rs | 8 +- src/tools/compiletest/src/runtest.rs | 2 +- src/tools/miri/src/machine.rs | 2 +- src/tools/opt-dist/src/environment.rs | 8 +- src/tools/opt-dist/src/exec.rs | 4 +- src/tools/opt-dist/src/main.rs | 6 +- src/tools/opt-dist/src/tests.rs | 4 +- 32 files changed, 167 insertions(+), 168 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/src/global_asm.rs b/compiler/rustc_codegen_cranelift/src/global_asm.rs index 0c99a5ce12f..6f90d17920d 100644 --- a/compiler/rustc_codegen_cranelift/src/global_asm.rs +++ b/compiler/rustc_codegen_cranelift/src/global_asm.rs @@ -118,8 +118,8 @@ impl GlobalAsmConfig { GlobalAsmConfig { assembler: crate::toolchain::get_toolchain_binary(tcx.sess, "as"), target: match &tcx.sess.opts.target_triple { - rustc_target::spec::TargetTriple::TargetTriple(triple) => triple.clone(), - rustc_target::spec::TargetTriple::TargetJson { path_for_rustdoc, .. } => { + rustc_target::spec::TargetTuple::TargetTuple(triple) => triple.clone(), + rustc_target::spec::TargetTuple::TargetJson { path_for_rustdoc, .. } => { path_for_rustdoc.to_str().unwrap().to_owned() } }, diff --git a/compiler/rustc_codegen_gcc/src/consts.rs b/compiler/rustc_codegen_gcc/src/consts.rs index 3029b934179..660badb6a50 100644 --- a/compiler/rustc_codegen_gcc/src/consts.rs +++ b/compiler/rustc_codegen_gcc/src/consts.rs @@ -146,7 +146,7 @@ impl<'gcc, 'tcx> StaticCodegenMethods for CodegenCx<'gcc, 'tcx> { // Wasm statics with custom link sections get special treatment as they // go into custom sections of the wasm executable. - if self.tcx.sess.opts.target_triple.triple().starts_with("wasm32") { + if self.tcx.sess.opts.target_triple.tuple().starts_with("wasm32") { if let Some(_section) = attrs.link_section { unimplemented!(); } diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 01e2c308ca4..647e9e13fbc 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -946,7 +946,7 @@ fn create_section_with_flags_asm(section_name: &str, section_flags: &str, data: } fn target_is_apple(cgcx: &CodegenContext) -> bool { - let triple = cgcx.opts.target_triple.triple(); + let triple = cgcx.opts.target_triple.tuple(); triple.contains("-ios") || triple.contains("-darwin") || triple.contains("-tvos") @@ -955,7 +955,7 @@ fn target_is_apple(cgcx: &CodegenContext) -> bool { } fn target_is_aix(cgcx: &CodegenContext) -> bool { - cgcx.opts.target_triple.triple().contains("-aix") + cgcx.opts.target_triple.tuple().contains("-aix") } pub(crate) fn bitcode_section_name(cgcx: &CodegenContext) -> &'static CStr { @@ -1031,7 +1031,7 @@ unsafe fn embed_bitcode( let is_aix = target_is_aix(cgcx); let is_apple = target_is_apple(cgcx); unsafe { - if is_apple || is_aix || cgcx.opts.target_triple.triple().starts_with("wasm") { + if is_apple || is_aix || cgcx.opts.target_triple.tuple().starts_with("wasm") { // We don't need custom section flags, create LLVM globals. let llconst = common::bytes_in_context(llcx, bitcode); let llglobal = llvm::LLVMAddGlobal( diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index b01a62b394b..20920d16f3c 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -997,7 +997,7 @@ fn link_natively( { let is_vs_installed = windows_registry::find_vs_version().is_ok(); let has_linker = windows_registry::find_tool( - sess.opts.target_triple.triple(), + sess.opts.target_triple.tuple(), "link.exe", ) .is_some(); @@ -1323,10 +1323,8 @@ fn link_sanitizer_runtime( } else { let default_sysroot = filesearch::get_or_default_sysroot().expect("Failed finding sysroot"); - let default_tlib = filesearch::make_target_lib_path( - &default_sysroot, - sess.opts.target_triple.triple(), - ); + let default_tlib = + filesearch::make_target_lib_path(&default_sysroot, sess.opts.target_triple.tuple()); default_tlib } } diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index c4bb82d0dd7..3b4429535d4 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -47,7 +47,7 @@ pub(crate) fn get_linker<'a>( self_contained: bool, target_cpu: &'a str, ) -> Box { - let msvc_tool = windows_registry::find_tool(sess.opts.target_triple.triple(), "link.exe"); + let msvc_tool = windows_registry::find_tool(sess.opts.target_triple.tuple(), "link.exe"); // If our linker looks like a batch script on Windows then to execute this // we'll need to spawn `cmd` explicitly. This is primarily done to handle diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 92b622fccf2..97210d9a662 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -62,7 +62,7 @@ use rustc_session::{EarlyDiagCtxt, Session, config, filesearch}; use rustc_span::FileName; use rustc_span::source_map::FileLoader; use rustc_target::json::ToJson; -use rustc_target::spec::{Target, TargetTriple}; +use rustc_target::spec::{Target, TargetTuple}; use time::OffsetDateTime; use tracing::trace; @@ -739,7 +739,7 @@ fn print_crate_info( AllTargetSpecs => { let mut targets = BTreeMap::new(); for name in rustc_target::spec::TARGETS { - let triple = TargetTriple::from_triple(name); + let triple = TargetTuple::from_tuple(name); let target = Target::expect_builtin(&triple); targets.insert(name, target.to_json()); } @@ -918,7 +918,7 @@ pub fn version_at_macro_invocation( safe_println!("binary: {binary}"); safe_println!("commit-hash: {commit_hash}"); safe_println!("commit-date: {commit_date}"); - safe_println!("host: {}", config::host_triple()); + safe_println!("host: {}", config::host_tuple()); safe_println!("release: {release}"); let debug_flags = matches.opt_strs("Z"); @@ -1495,7 +1495,7 @@ fn report_ice( } let version = util::version_str!().unwrap_or("unknown_version"); - let triple = config::host_triple(); + let tuple = config::host_tuple(); static FIRST_PANIC: AtomicBool = AtomicBool::new(true); @@ -1505,7 +1505,7 @@ fn report_ice( Ok(mut file) => { dcx.emit_note(session_diagnostics::IcePath { path: path.clone() }); if FIRST_PANIC.swap(false, Ordering::SeqCst) { - let _ = write!(file, "\n\nrustc version: {version}\nplatform: {triple}"); + let _ = write!(file, "\n\nrustc version: {version}\nplatform: {tuple}"); } Some(file) } @@ -1518,12 +1518,12 @@ fn report_ice( .map(PathBuf::from) .map(|env_var| session_diagnostics::IcePathErrorEnv { env_var }), }); - dcx.emit_note(session_diagnostics::IceVersion { version, triple }); + dcx.emit_note(session_diagnostics::IceVersion { version, triple: tuple }); None } } } else { - dcx.emit_note(session_diagnostics::IceVersion { version, triple }); + dcx.emit_note(session_diagnostics::IceVersion { version, triple: tuple }); None }; diff --git a/compiler/rustc_errors/src/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs index 09a608dda7b..798668b8bc1 100644 --- a/compiler/rustc_errors/src/diagnostic_impls.rs +++ b/compiler/rustc_errors/src/diagnostic_impls.rs @@ -11,7 +11,7 @@ use rustc_macros::Subdiagnostic; use rustc_span::Span; use rustc_span::edition::Edition; use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent, Symbol}; -use rustc_target::spec::{PanicStrategy, SplitDebuginfo, StackProtector, TargetTriple}; +use rustc_target::spec::{PanicStrategy, SplitDebuginfo, StackProtector, TargetTuple}; use rustc_type_ir::{ClosureKind, FloatTy}; use {rustc_ast as ast, rustc_hir as hir}; @@ -89,7 +89,7 @@ into_diag_arg_using_display!( MacroRulesNormalizedIdent, ParseIntError, StackProtector, - &TargetTriple, + &TargetTuple, SplitDebuginfo, ExitStatus, ErrCode, diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index 85e11ff6745..d8b63eef577 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -493,7 +493,7 @@ fn fatally_break_rust(tcx: TyCtxt<'_>, span: Span) -> ! { "we would appreciate a joke overview: \ https://github.com/rust-lang/rust/issues/43162#issuecomment-320764675", ); - diag.note(format!("rustc {} running on {}", tcx.sess.cfg_version, config::host_triple(),)); + diag.note(format!("rustc {} running on {}", tcx.sess.cfg_version, config::host_tuple(),)); if let Some((flags, excluded_cargo_defaults)) = rustc_session::utils::extra_compiler_flags() { diag.note(format!("compiler flags: {}", flags.join(" "))); if excluded_cargo_defaults { diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index 71e8accf5a3..b5bddc4b21a 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -11,7 +11,7 @@ use rustc_data_structures::sync; use rustc_metadata::{DylibError, load_symbol_from_dylib}; use rustc_middle::ty::CurrentGcx; use rustc_parse::validate_attr; -use rustc_session::config::{Cfg, OutFileName, OutputFilenames, OutputTypes, host_triple}; +use rustc_session::config::{Cfg, OutFileName, OutputFilenames, OutputTypes, host_tuple}; use rustc_session::filesearch::sysroot_candidates; use rustc_session::lint::{self, BuiltinLintDiag, LintBuffer}; use rustc_session::output::{CRATE_TYPES, categorize_crate_type}; @@ -310,7 +310,7 @@ fn get_codegen_sysroot( "cannot load the default codegen backend twice" ); - let target = host_triple(); + let target = host_tuple(); let sysroot_candidates = sysroot_candidates(); let sysroot = iter::once(sysroot) diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index d2be6ae8d69..e525d94a0c1 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -30,7 +30,7 @@ use rustc_session::search_paths::PathKind; use rustc_span::edition::Edition; use rustc_span::symbol::{Ident, Symbol, sym}; use rustc_span::{DUMMY_SP, Span}; -use rustc_target::spec::{PanicStrategy, Target, TargetTriple}; +use rustc_target::spec::{PanicStrategy, Target, TargetTuple}; use tracing::{debug, info, trace}; use crate::errors; @@ -506,7 +506,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> { locator.reset(); locator.is_proc_macro = true; locator.target = &self.sess.host; - locator.triple = TargetTriple::from_triple(config::host_triple()); + locator.tuple = TargetTuple::from_tuple(config::host_tuple()); locator.filesearch = self.sess.host_filesearch(path_kind); let Some(host_result) = self.load(locator)? else { @@ -635,7 +635,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> { // FIXME: why is this condition necessary? It was adding in #33625 but I // don't know why and the original author doesn't remember ... let can_reuse_cratenum = - locator.triple == self.sess.opts.target_triple || locator.is_proc_macro; + locator.tuple == self.sess.opts.target_triple || locator.is_proc_macro; Ok(Some(if can_reuse_cratenum { let mut result = LoadResult::Loaded(library); for (cnum, data) in self.cstore.iter_crate_data() { diff --git a/compiler/rustc_metadata/src/errors.rs b/compiler/rustc_metadata/src/errors.rs index 6587125ec67..16684ae6f26 100644 --- a/compiler/rustc_metadata/src/errors.rs +++ b/compiler/rustc_metadata/src/errors.rs @@ -5,7 +5,7 @@ use rustc_errors::codes::*; use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level}; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::{Span, Symbol, sym}; -use rustc_target::spec::{PanicStrategy, TargetTriple}; +use rustc_target::spec::{PanicStrategy, TargetTuple}; use crate::fluent_generated as fluent; use crate::locator::CrateFlavor; @@ -630,7 +630,7 @@ pub struct CannotFindCrate { pub current_crate: String, pub is_nightly_build: bool, pub profiler_runtime: Symbol, - pub locator_triple: TargetTriple, + pub locator_triple: TargetTuple, pub is_ui_testing: bool, } @@ -641,7 +641,7 @@ impl Diagnostic<'_, G> for CannotFindCrate { diag.arg("crate_name", self.crate_name); diag.arg("current_crate", self.current_crate); diag.arg("add_info", self.add_info); - diag.arg("locator_triple", self.locator_triple.triple()); + diag.arg("locator_triple", self.locator_triple.tuple()); diag.code(E0463); diag.span(self.span); if self.crate_name == sym::std || self.crate_name == sym::core { diff --git a/compiler/rustc_metadata/src/locator.rs b/compiler/rustc_metadata/src/locator.rs index f924ed48b6f..ddd97fc66f6 100644 --- a/compiler/rustc_metadata/src/locator.rs +++ b/compiler/rustc_metadata/src/locator.rs @@ -231,7 +231,7 @@ use rustc_session::search_paths::PathKind; use rustc_session::utils::CanonicalizedPath; use rustc_span::Span; use rustc_span::symbol::Symbol; -use rustc_target::spec::{Target, TargetTriple}; +use rustc_target::spec::{Target, TargetTuple}; use tracing::{debug, info}; use crate::creader::{Library, MetadataLoader}; @@ -252,7 +252,7 @@ pub(crate) struct CrateLocator<'a> { pub hash: Option, extra_filename: Option<&'a str>, pub target: &'a Target, - pub triple: TargetTriple, + pub tuple: TargetTuple, pub filesearch: FileSearch<'a>, pub is_proc_macro: bool, @@ -338,7 +338,7 @@ impl<'a> CrateLocator<'a> { hash, extra_filename, target: &sess.target, - triple: sess.opts.target_triple.clone(), + tuple: sess.opts.target_triple.clone(), filesearch: sess.target_filesearch(path_kind), is_proc_macro: false, crate_rejections: CrateRejections::default(), @@ -677,8 +677,8 @@ impl<'a> CrateLocator<'a> { return None; } - if header.triple != self.triple { - info!("Rejecting via crate triple: expected {} got {}", self.triple, header.triple); + if header.triple != self.tuple { + info!("Rejecting via crate triple: expected {} got {}", self.tuple, header.triple); self.crate_rejections.via_triple.push(CrateMismatch { path: libpath.to_path_buf(), got: header.triple.to_string(), @@ -766,7 +766,7 @@ impl<'a> CrateLocator<'a> { CrateError::LocatorCombined(Box::new(CombinedLocatorError { crate_name: self.crate_name, root, - triple: self.triple, + triple: self.tuple, dll_prefix: self.target.dll_prefix.to_string(), dll_suffix: self.target.dll_suffix.to_string(), crate_rejections: self.crate_rejections, @@ -909,7 +909,7 @@ struct CrateRejections { pub(crate) struct CombinedLocatorError { crate_name: Symbol, root: Option, - triple: TargetTriple, + triple: TargetTuple, dll_prefix: String, dll_suffix: String, crate_rejections: CrateRejections, @@ -1034,7 +1034,7 @@ impl CrateError { dcx.emit_err(errors::NoCrateWithTriple { span, crate_name, - locator_triple: locator.triple.triple(), + locator_triple: locator.triple.tuple(), add_info, found_crates, }); diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index ebfd3c09fc1..87357b74c41 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -770,7 +770,7 @@ impl MetadataBlob { root.stable_crate_id )?; writeln!(out, "proc_macro {:?}", root.proc_macro_data.is_some())?; - writeln!(out, "triple {}", root.header.triple.triple())?; + writeln!(out, "triple {}", root.header.triple.tuple())?; writeln!(out, "edition {}", root.edition)?; writeln!(out, "symbol_mangling_version {:?}", root.symbol_mangling_version)?; writeln!( diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index ab878760c00..949e26f5f60 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -38,7 +38,7 @@ use rustc_span::edition::Edition; use rustc_span::hygiene::{ExpnIndex, MacroKind, SyntaxContextData}; use rustc_span::symbol::{Ident, Symbol}; use rustc_span::{self, ExpnData, ExpnHash, ExpnId, Span}; -use rustc_target::spec::{PanicStrategy, TargetTriple}; +use rustc_target::spec::{PanicStrategy, TargetTuple}; use table::TableBuilder; use {rustc_ast as ast, rustc_attr as attr, rustc_hir as hir}; @@ -213,7 +213,7 @@ pub(crate) struct ProcMacroData { /// If you do modify this struct, also bump the [`METADATA_VERSION`] constant. #[derive(MetadataEncodable, MetadataDecodable)] pub(crate) struct CrateHeader { - pub(crate) triple: TargetTriple, + pub(crate) triple: TargetTuple, pub(crate) hash: Svh, pub(crate) name: Symbol, /// Whether this is the header for a proc-macro crate. diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 5ee3b4015eb..3ac6e7423ac 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -26,7 +26,7 @@ use rustc_span::{ FileName, FileNameDisplayPreference, RealFileName, SourceFileHashAlgorithm, Symbol, sym, }; use rustc_target::spec::{ - FramePointer, LinkSelfContainedComponents, LinkerFeatures, SplitDebuginfo, Target, TargetTriple, + FramePointer, LinkSelfContainedComponents, LinkerFeatures, SplitDebuginfo, Target, TargetTuple, }; use tracing::debug; @@ -1116,7 +1116,7 @@ bitflags::bitflags! { } } -pub fn host_triple() -> &'static str { +pub fn host_tuple() -> &'static str { // Get the host triple out of the build environment. This ensures that our // idea of the host triple is the same as for the set of libraries we've // actually built. We can't just take LLVM's host triple because they @@ -1158,7 +1158,7 @@ impl Default for Options { output_types: OutputTypes(BTreeMap::new()), search_paths: vec![], maybe_sysroot: None, - target_triple: TargetTriple::from_triple(host_triple()), + target_triple: TargetTuple::from_tuple(host_tuple()), test: false, incremental: None, untracked_state_hash: Default::default(), @@ -1354,7 +1354,7 @@ pub fn build_target_config(early_dcx: &EarlyDiagCtxt, opts: &Options, sysroot: & // rust-lang/compiler-team#695. Warn unconditionally on usage to // raise awareness of the renaming. This code will be deleted in // October 2024. - if opts.target_triple.triple() == "wasm32-wasi" { + if opts.target_triple.tuple() == "wasm32-wasi" { early_dcx.early_warn( "the `wasm32-wasi` target is being renamed to \ `wasm32-wasip1` and the `wasm32-wasi` target will be \ @@ -2030,16 +2030,16 @@ fn collect_print_requests( prints } -pub fn parse_target_triple(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> TargetTriple { +pub fn parse_target_triple(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> TargetTuple { match matches.opt_str("target") { Some(target) if target.ends_with(".json") => { let path = Path::new(&target); - TargetTriple::from_path(path).unwrap_or_else(|_| { + TargetTuple::from_path(path).unwrap_or_else(|_| { early_dcx.early_fatal(format!("target file {path:?} does not exist")) }) } - Some(target) => TargetTriple::TargetTriple(target), - _ => TargetTriple::from_triple(host_triple()), + Some(target) => TargetTuple::TargetTuple(target), + _ => TargetTuple::from_tuple(host_tuple()), } } @@ -3005,7 +3005,7 @@ pub(crate) mod dep_tracking { use rustc_span::edition::Edition; use rustc_target::spec::{ CodeModel, FramePointer, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel, - RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, SymbolVisibility, TargetTriple, + RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, SymbolVisibility, TargetTuple, TlsModel, WasmCAbi, }; @@ -3090,7 +3090,7 @@ pub(crate) mod dep_tracking { SanitizerSet, CFGuard, CFProtection, - TargetTriple, + TargetTuple, Edition, LinkerPluginLto, ResolveDocLinks, diff --git a/compiler/rustc_session/src/config/cfg.rs b/compiler/rustc_session/src/config/cfg.rs index 31ef2bda4f1..347d298bacc 100644 --- a/compiler/rustc_session/src/config/cfg.rs +++ b/compiler/rustc_session/src/config/cfg.rs @@ -29,7 +29,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; use rustc_lint_defs::BuiltinLintDiag; use rustc_lint_defs::builtin::EXPLICIT_BUILTIN_CFGS_IN_FLAGS; use rustc_span::symbol::{Symbol, sym}; -use rustc_target::spec::{PanicStrategy, RelocModel, SanitizerSet, TARGETS, Target, TargetTriple}; +use rustc_target::spec::{PanicStrategy, RelocModel, SanitizerSet, TARGETS, Target, TargetTuple}; use crate::Session; use crate::config::{CrateType, FmtDebug}; @@ -417,7 +417,7 @@ impl CheckCfg { for target in TARGETS .iter() - .map(|target| Target::expect_builtin(&TargetTriple::from_triple(target))) + .map(|target| Target::expect_builtin(&TargetTuple::from_tuple(target))) .chain(iter::once(current_target.clone())) { values_target_abi.insert(Symbol::intern(&target.options.abi)); diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs index 20e8fb38b88..33f84f10447 100644 --- a/compiler/rustc_session/src/errors.rs +++ b/compiler/rustc_session/src/errors.rs @@ -9,7 +9,7 @@ use rustc_errors::{ }; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::{Span, Symbol}; -use rustc_target::spec::{SplitDebuginfo, StackProtector, TargetTriple}; +use rustc_target::spec::{SplitDebuginfo, StackProtector, TargetTuple}; use crate::config::CrateType; use crate::parse::ParseSess; @@ -179,13 +179,13 @@ pub(crate) struct EmbedSourceRequiresDebugInfo; #[diag(session_target_stack_protector_not_supported)] pub(crate) struct StackProtectorNotSupportedForTarget<'a> { pub(crate) stack_protector: StackProtector, - pub(crate) target_triple: &'a TargetTriple, + pub(crate) target_triple: &'a TargetTuple, } #[derive(Diagnostic)] #[diag(session_target_small_data_threshold_not_supported)] pub(crate) struct SmallDataThresholdNotSupportedForTarget<'a> { - pub(crate) target_triple: &'a TargetTriple, + pub(crate) target_triple: &'a TargetTuple, } #[derive(Diagnostic)] @@ -383,7 +383,7 @@ struct BinaryFloatLiteralNotSupported { #[diag(session_unsupported_crate_type_for_target)] pub(crate) struct UnsupportedCrateTypeForTarget<'a> { pub(crate) crate_type: CrateType, - pub(crate) target_triple: &'a TargetTriple, + pub(crate) target_triple: &'a TargetTuple, } pub fn report_lit_error( diff --git a/compiler/rustc_session/src/filesearch.rs b/compiler/rustc_session/src/filesearch.rs index b3e3381d986..213a94ab880 100644 --- a/compiler/rustc_session/src/filesearch.rs +++ b/compiler/rustc_session/src/filesearch.rs @@ -152,7 +152,7 @@ fn current_dll_path() -> Result { } pub fn sysroot_candidates() -> SmallVec<[PathBuf; 2]> { - let target = crate::config::host_triple(); + let target = crate::config::host_tuple(); let mut sysroot_candidates: SmallVec<[PathBuf; 2]> = smallvec![get_or_default_sysroot().expect("Failed finding sysroot")]; let path = current_dll_path().and_then(|s| try_canonicalize(s).map_err(|e| e.to_string())); @@ -218,7 +218,7 @@ pub fn get_or_default_sysroot() -> Result { ))?; // if `dir` points target's dir, move up to the sysroot - let mut sysroot_dir = if dir.ends_with(crate::config::host_triple()) { + let mut sysroot_dir = if dir.ends_with(crate::config::host_tuple()) { dir.parent() // chop off `$target` .and_then(|p| p.parent()) // chop off `rustlib` .and_then(|p| p.parent()) // chop off `lib` diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 2b158627751..5a2a6ab0031 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -14,7 +14,7 @@ use rustc_span::{RealFileName, SourceFileHashAlgorithm}; use rustc_target::spec::{ CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, SymbolVisibility, - TargetTriple, TlsModel, WasmCAbi, + TargetTuple, TlsModel, WasmCAbi, }; use crate::config::*; @@ -146,7 +146,7 @@ top_level_options!( libs: Vec [TRACKED], maybe_sysroot: Option [UNTRACKED], - target_triple: TargetTriple [TRACKED], + target_triple: TargetTuple [TRACKED], /// Effective logical environment used by `env!`/`option_env!` macros logical_env: FxIndexMap [TRACKED], diff --git a/compiler/rustc_session/src/search_paths.rs b/compiler/rustc_session/src/search_paths.rs index ac0d8661115..c148b09c718 100644 --- a/compiler/rustc_session/src/search_paths.rs +++ b/compiler/rustc_session/src/search_paths.rs @@ -1,7 +1,7 @@ use std::path::{Path, PathBuf}; use rustc_macros::{Decodable, Encodable, HashStable_Generic}; -use rustc_target::spec::TargetTriple; +use rustc_target::spec::TargetTuple; use crate::EarlyDiagCtxt; use crate::filesearch::make_target_lib_path; @@ -52,7 +52,7 @@ impl PathKind { impl SearchPath { pub fn from_cli_opt( sysroot: &Path, - triple: &TargetTriple, + triple: &TargetTuple, early_dcx: &EarlyDiagCtxt, path: &str, is_unstable_enabled: bool, @@ -80,7 +80,7 @@ impl SearchPath { ); } - make_target_lib_path(sysroot, triple.triple()).join("builtin").join(stripped) + make_target_lib_path(sysroot, triple.tuple()).join("builtin").join(stripped) } None => PathBuf::from(path), }; diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 45434534c75..470e372ee48 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -32,7 +32,7 @@ use rustc_target::asm::InlineAsmArch; use rustc_target::spec::{ CodeModel, DebuginfoKind, PanicStrategy, RelocModel, RelroLevel, SanitizerSet, SmallDataThresholdSupport, SplitDebuginfo, StackProtector, SymbolVisibility, Target, - TargetTriple, TlsModel, + TargetTuple, TlsModel, }; use crate::code_stats::CodeStats; @@ -451,12 +451,12 @@ impl Session { /// directories are also returned, for example if `--sysroot` is used but tools are missing /// (#125246): we also add the bin directories to the sysroot where rustc is located. pub fn get_tools_search_paths(&self, self_contained: bool) -> Vec { - let bin_path = filesearch::make_target_bin_path(&self.sysroot, config::host_triple()); + let bin_path = filesearch::make_target_bin_path(&self.sysroot, config::host_tuple()); let fallback_sysroot_paths = filesearch::sysroot_candidates() .into_iter() // Ignore sysroot candidate if it was the same as the sysroot path we just used. .filter(|sysroot| *sysroot != self.sysroot) - .map(|sysroot| filesearch::make_target_bin_path(&sysroot, config::host_triple())); + .map(|sysroot| filesearch::make_target_bin_path(&sysroot, config::host_tuple())); let search_paths = std::iter::once(bin_path).chain(fallback_sysroot_paths); if self_contained { @@ -1023,7 +1023,7 @@ pub fn build_session( let cap_lints_allow = sopts.lint_cap.is_some_and(|cap| cap == lint::Allow); let can_emit_warnings = !(warnings_allow || cap_lints_allow); - let host_triple = TargetTriple::from_triple(config::host_triple()); + let host_triple = TargetTuple::from_tuple(config::host_tuple()); let (host, target_warnings) = Target::search(&host_triple, &sysroot).unwrap_or_else(|e| { early_dcx.early_fatal(format!("Error loading host specification: {e}")) }); @@ -1074,8 +1074,8 @@ pub fn build_session( let mut psess = ParseSess::with_dcx(dcx, source_map); psess.assume_incomplete_release = sopts.unstable_opts.assume_incomplete_release; - let host_triple = config::host_triple(); - let target_triple = sopts.target_triple.triple(); + let host_triple = config::host_tuple(); + let target_triple = sopts.target_triple.tuple(); let host_tlib_path = Lrc::new(SearchPath::from_sysroot_and_triple(&sysroot, host_triple)); let target_tlib_path = if host_triple == target_triple { // Use the same `SearchPath` if host and target triple are identical to avoid unnecessary diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index d518ed60469..06408e0b210 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1,21 +1,21 @@ //! [Flexible target specification.](https://github.com/rust-lang/rfcs/pull/131) //! //! Rust targets a wide variety of usecases, and in the interest of flexibility, -//! allows new target triples to be defined in configuration files. Most users +//! allows new target tuples to be defined in configuration files. Most users //! will not need to care about these, but this is invaluable when porting Rust //! to a new platform, and allows for an unprecedented level of control over how //! the compiler works. //! //! # Using custom targets //! -//! A target triple, as passed via `rustc --target=TRIPLE`, will first be +//! A target tuple, as passed via `rustc --target=TUPLE`, will first be //! compared against the list of built-in targets. This is to ease distributing //! rustc (no need for configuration files) and also to hold these built-in -//! targets as immutable and sacred. If `TRIPLE` is not one of the built-in -//! targets, rustc will check if a file named `TRIPLE` exists. If it does, it +//! targets as immutable and sacred. If `TUPLE` is not one of the built-in +//! targets, rustc will check if a file named `TUPLE` exists. If it does, it //! will be loaded as the target configuration. If the file does not exist, //! rustc will search each directory in the environment variable -//! `RUST_TARGET_PATH` for a file named `TRIPLE.json`. The first one found will +//! `RUST_TARGET_PATH` for a file named `TUPLE.json`. The first one found will //! be loaded. If no file is found in any of those directories, a fatal error //! will be given. //! @@ -1586,17 +1586,17 @@ impl fmt::Display for StackProtector { } macro_rules! supported_targets { - ( $(($triple:literal, $module:ident),)+ ) => { + ( $(($tuple:literal, $module:ident),)+ ) => { mod targets { $(pub(crate) mod $module;)+ } /// List of supported targets - pub const TARGETS: &[&str] = &[$($triple),+]; + pub const TARGETS: &[&str] = &[$($tuple),+]; fn load_builtin(target: &str) -> Option { let mut t = match target { - $( $triple => targets::$module::target(), )+ + $( $tuple => targets::$module::target(), )+ _ => return None, }; t.is_builtin = true; @@ -2005,9 +2005,9 @@ impl TargetWarnings { /// Every field here must be specified, and has no default value. #[derive(PartialEq, Clone, Debug)] pub struct Target { - /// Unversioned target triple to pass to LLVM. + /// Unversioned target tuple to pass to LLVM. /// - /// Target triples can optionally contain an OS version (notably Apple targets), which rustc + /// Target tuples can optionally contain an OS version (notably Apple targets), which rustc /// cannot know without querying the environment. /// /// Use `rustc_codegen_ssa::back::versioned_llvm_target` if you need the full LLVM target. @@ -3477,28 +3477,28 @@ impl Target { } /// Load a built-in target - pub fn expect_builtin(target_triple: &TargetTriple) -> Target { - match *target_triple { - TargetTriple::TargetTriple(ref target_triple) => { - load_builtin(target_triple).expect("built-in target") + pub fn expect_builtin(target_tuple: &TargetTuple) -> Target { + match *target_tuple { + TargetTuple::TargetTuple(ref target_tuple) => { + load_builtin(target_tuple).expect("built-in target") } - TargetTriple::TargetJson { .. } => { + TargetTuple::TargetJson { .. } => { panic!("built-in targets doesn't support target-paths") } } } - /// Search for a JSON file specifying the given target triple. + /// Search for a JSON file specifying the given target tuple. /// /// If none is found in `$RUST_TARGET_PATH`, look for a file called `target.json` inside the - /// sysroot under the target-triple's `rustlib` directory. Note that it could also just be a + /// sysroot under the target-tuple's `rustlib` directory. Note that it could also just be a /// bare filename already, so also check for that. If one of the hardcoded targets we know /// about, just return it directly. /// /// The error string could come from any of the APIs called, including filesystem access and /// JSON decoding. pub fn search( - target_triple: &TargetTriple, + target_tuple: &TargetTuple, sysroot: &Path, ) -> Result<(Target, TargetWarnings), String> { use std::{env, fs}; @@ -3509,16 +3509,16 @@ impl Target { Target::from_json(obj) } - match *target_triple { - TargetTriple::TargetTriple(ref target_triple) => { - // check if triple is in list of built-in targets - if let Some(t) = load_builtin(target_triple) { + match *target_tuple { + TargetTuple::TargetTuple(ref target_tuple) => { + // check if tuple is in list of built-in targets + if let Some(t) = load_builtin(target_tuple) { return Ok((t, TargetWarnings::empty())); } - // search for a file named `target_triple`.json in RUST_TARGET_PATH + // search for a file named `target_tuple`.json in RUST_TARGET_PATH let path = { - let mut target = target_triple.to_string(); + let mut target = target_tuple.to_string(); target.push_str(".json"); PathBuf::from(target) }; @@ -3532,9 +3532,9 @@ impl Target { } } - // Additionally look in the sysroot under `lib/rustlib//target.json` + // Additionally look in the sysroot under `lib/rustlib//target.json` // as a fallback. - let rustlib_path = crate::relative_target_rustlib_path(sysroot, target_triple); + let rustlib_path = crate::relative_target_rustlib_path(sysroot, target_tuple); let p = PathBuf::from_iter([ Path::new(sysroot), Path::new(&rustlib_path), @@ -3544,9 +3544,9 @@ impl Target { return load_file(&p); } - Err(format!("Could not find specification for target {target_triple:?}")) + Err(format!("Could not find specification for target {target_tuple:?}")) } - TargetTriple::TargetJson { ref contents, .. } => { + TargetTuple::TargetJson { ref contents, .. } => { let obj = serde_json::from_str(contents).map_err(|e| e.to_string())?; Target::from_json(obj) } @@ -3751,44 +3751,44 @@ impl ToJson for Target { } } -/// Either a target triple string or a path to a JSON file. +/// Either a target tuple string or a path to a JSON file. #[derive(Clone, Debug)] -pub enum TargetTriple { - TargetTriple(String), +pub enum TargetTuple { + TargetTuple(String), TargetJson { /// Warning: This field may only be used by rustdoc. Using it anywhere else will lead to /// inconsistencies as it is discarded during serialization. path_for_rustdoc: PathBuf, - triple: String, + tuple: String, contents: String, }, } // Use a manual implementation to ignore the path field -impl PartialEq for TargetTriple { +impl PartialEq for TargetTuple { fn eq(&self, other: &Self) -> bool { match (self, other) { - (Self::TargetTriple(l0), Self::TargetTriple(r0)) => l0 == r0, + (Self::TargetTuple(l0), Self::TargetTuple(r0)) => l0 == r0, ( - Self::TargetJson { path_for_rustdoc: _, triple: l_triple, contents: l_contents }, - Self::TargetJson { path_for_rustdoc: _, triple: r_triple, contents: r_contents }, - ) => l_triple == r_triple && l_contents == r_contents, + Self::TargetJson { path_for_rustdoc: _, tuple: l_tuple, contents: l_contents }, + Self::TargetJson { path_for_rustdoc: _, tuple: r_tuple, contents: r_contents }, + ) => l_tuple == r_tuple && l_contents == r_contents, _ => false, } } } // Use a manual implementation to ignore the path field -impl Hash for TargetTriple { +impl Hash for TargetTuple { fn hash(&self, state: &mut H) -> () { match self { - TargetTriple::TargetTriple(triple) => { + TargetTuple::TargetTuple(tuple) => { 0u8.hash(state); - triple.hash(state) + tuple.hash(state) } - TargetTriple::TargetJson { path_for_rustdoc: _, triple, contents } => { + TargetTuple::TargetJson { path_for_rustdoc: _, tuple, contents } => { 1u8.hash(state); - triple.hash(state); + tuple.hash(state); contents.hash(state) } } @@ -3796,45 +3796,45 @@ impl Hash for TargetTriple { } // Use a manual implementation to prevent encoding the target json file path in the crate metadata -impl Encodable for TargetTriple { +impl Encodable for TargetTuple { fn encode(&self, s: &mut S) { match self { - TargetTriple::TargetTriple(triple) => { + TargetTuple::TargetTuple(tuple) => { s.emit_u8(0); - s.emit_str(triple); + s.emit_str(tuple); } - TargetTriple::TargetJson { path_for_rustdoc: _, triple, contents } => { + TargetTuple::TargetJson { path_for_rustdoc: _, tuple, contents } => { s.emit_u8(1); - s.emit_str(triple); + s.emit_str(tuple); s.emit_str(contents); } } } } -impl Decodable for TargetTriple { +impl Decodable for TargetTuple { fn decode(d: &mut D) -> Self { match d.read_u8() { - 0 => TargetTriple::TargetTriple(d.read_str().to_owned()), - 1 => TargetTriple::TargetJson { + 0 => TargetTuple::TargetTuple(d.read_str().to_owned()), + 1 => TargetTuple::TargetJson { path_for_rustdoc: PathBuf::new(), - triple: d.read_str().to_owned(), + tuple: d.read_str().to_owned(), contents: d.read_str().to_owned(), }, _ => { - panic!("invalid enum variant tag while decoding `TargetTriple`, expected 0..2"); + panic!("invalid enum variant tag while decoding `TargetTuple`, expected 0..2"); } } } } -impl TargetTriple { - /// Creates a target triple from the passed target triple string. - pub fn from_triple(triple: &str) -> Self { - TargetTriple::TargetTriple(triple.into()) +impl TargetTuple { + /// Creates a target tuple from the passed target tuple string. + pub fn from_tuple(tuple: &str) -> Self { + TargetTuple::TargetTuple(tuple.into()) } - /// Creates a target triple from the passed target path. + /// Creates a target tuple from the passed target path. pub fn from_path(path: &Path) -> Result { let canonicalized_path = try_canonicalize(path)?; let contents = std::fs::read_to_string(&canonicalized_path).map_err(|err| { @@ -3843,46 +3843,47 @@ impl TargetTriple { format!("target path {canonicalized_path:?} is not a valid file: {err}"), ) })?; - let triple = canonicalized_path + let tuple = canonicalized_path .file_stem() .expect("target path must not be empty") .to_str() .expect("target path must be valid unicode") .to_owned(); - Ok(TargetTriple::TargetJson { path_for_rustdoc: canonicalized_path, triple, contents }) + Ok(TargetTuple::TargetJson { path_for_rustdoc: canonicalized_path, tuple, contents }) } - /// Returns a string triple for this target. + /// Returns a string tuple for this target. /// /// If this target is a path, the file name (without extension) is returned. - pub fn triple(&self) -> &str { + pub fn tuple(&self) -> &str { match *self { - TargetTriple::TargetTriple(ref triple) - | TargetTriple::TargetJson { ref triple, .. } => triple, + TargetTuple::TargetTuple(ref tuple) | TargetTuple::TargetJson { ref tuple, .. } => { + tuple + } } } - /// Returns an extended string triple for this target. + /// Returns an extended string tuple for this target. /// - /// If this target is a path, a hash of the path is appended to the triple returned - /// by `triple()`. - pub fn debug_triple(&self) -> String { + /// If this target is a path, a hash of the path is appended to the tuple returned + /// by `tuple()`. + pub fn debug_tuple(&self) -> String { use std::hash::DefaultHasher; match self { - TargetTriple::TargetTriple(triple) => triple.to_owned(), - TargetTriple::TargetJson { path_for_rustdoc: _, triple, contents: content } => { + TargetTuple::TargetTuple(tuple) => tuple.to_owned(), + TargetTuple::TargetJson { path_for_rustdoc: _, tuple, contents: content } => { let mut hasher = DefaultHasher::new(); content.hash(&mut hasher); let hash = hasher.finish(); - format!("{triple}-{hash}") + format!("{tuple}-{hash}") } } } } -impl fmt::Display for TargetTriple { +impl fmt::Display for TargetTuple { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.debug_triple()) + write!(f, "{}", self.debug_tuple()) } } diff --git a/src/doc/rustdoc/src/command-line-arguments.md b/src/doc/rustdoc/src/command-line-arguments.md index 3e104bdb470..f8fb5284472 100644 --- a/src/doc/rustdoc/src/command-line-arguments.md +++ b/src/doc/rustdoc/src/command-line-arguments.md @@ -52,7 +52,7 @@ rustdoc 1.17.0 (56124baa9 2017-04-24) binary: rustdoc commit-hash: hash commit-date: date -host: host-triple +host: host-tuple release: 1.17.0 LLVM version: 3.9 ``` diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 2cd69474b1c..5071ed1c47f 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -17,7 +17,7 @@ use rustc_session::search_paths::SearchPath; use rustc_session::{EarlyDiagCtxt, getopts}; use rustc_span::FileName; use rustc_span::edition::Edition; -use rustc_target::spec::TargetTriple; +use rustc_target::spec::TargetTuple; use crate::core::new_dcx; use crate::externalfiles::ExternalHtml; @@ -96,7 +96,7 @@ pub(crate) struct Options { /// Unstable (`-Z`) options strings to pass to the compiler. pub(crate) unstable_opts_strs: Vec, /// The target used to compile the crate against. - pub(crate) target: TargetTriple, + pub(crate) target: TargetTuple, /// Edition used when reading the crate. Defaults to "2015". Also used by default when /// compiling doctests from the crate. pub(crate) edition: Edition, diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 7b2a5eb3d63..11d8f1947d6 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -24,7 +24,7 @@ use rustc_session::lint; use rustc_span::FileName; use rustc_span::edition::Edition; use rustc_span::symbol::sym; -use rustc_target::spec::{Target, TargetTriple}; +use rustc_target::spec::{Target, TargetTuple}; use tempfile::{Builder as TempFileBuilder, TempDir}; use tracing::debug; @@ -414,10 +414,10 @@ pub(crate) struct UnusedExterns { unused_extern_names: Vec, } -fn add_exe_suffix(input: String, target: &TargetTriple) -> String { +fn add_exe_suffix(input: String, target: &TargetTuple) -> String { let exe_suffix = match target { - TargetTriple::TargetTriple(_) => Target::expect_builtin(target).options.exe_suffix, - TargetTriple::TargetJson { contents, .. } => { + TargetTuple::TargetTuple(_) => Target::expect_builtin(target).options.exe_suffix, + TargetTuple::TargetJson { contents, .. } => { Target::from_json(contents.parse().unwrap()).unwrap().0.options.exe_suffix } }; @@ -513,8 +513,8 @@ fn run_test( compiler.arg("--emit=metadata"); } compiler.arg("--target").arg(match &rustdoc_options.target { - TargetTriple::TargetTriple(s) => s, - TargetTriple::TargetJson { path_for_rustdoc, .. } => { + TargetTuple::TargetTuple(s) => s, + TargetTuple::TargetJson { path_for_rustdoc, .. } => { path_for_rustdoc.to_str().expect("target path must be valid unicode") } }); diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index e4f2f95a91b..ecb8343fba3 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -761,7 +761,7 @@ pub const UI_COVERAGE_MAP: &str = "cov-map"; /// Absolute path to the directory where all output for all tests in the given /// `relative_dir` group should reside. Example: -/// /path/to/build/host-triple/test/ui/relative/ +/// /path/to/build/host-tuple/test/ui/relative/ /// This is created early when tests are collected to avoid race conditions. pub fn output_relative_path(config: &Config, relative_dir: &Path) -> PathBuf { config.build_base.join(relative_dir) @@ -784,7 +784,7 @@ pub fn output_testname_unique( /// Absolute path to the directory where all output for the given /// test/revision should reside. Example: -/// /path/to/build/host-triple/test/ui/relative/testname.revision.mode/ +/// /path/to/build/host-tuple/test/ui/relative/testname.revision.mode/ pub fn output_base_dir(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> PathBuf { output_relative_path(config, &testpaths.relative_dir) .join(output_testname_unique(config, testpaths, revision)) @@ -792,13 +792,13 @@ pub fn output_base_dir(config: &Config, testpaths: &TestPaths, revision: Option< /// Absolute path to the base filename used as output for the given /// test/revision. Example: -/// /path/to/build/host-triple/test/ui/relative/testname.revision.mode/testname +/// /path/to/build/host-tuple/test/ui/relative/testname.revision.mode/testname pub fn output_base_name(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> PathBuf { output_base_dir(config, testpaths, revision).join(testpaths.file.file_stem().unwrap()) } /// Absolute path to the directory to use for incremental compilation. Example: -/// /path/to/build/host-triple/test/ui/relative/testname.mode/testname.inc +/// /path/to/build/host-tuple/test/ui/relative/testname.mode/testname.inc pub fn incremental_dir(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> PathBuf { output_base_name(config, testpaths, revision).with_extension("inc") } diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index b337458f943..bc80c8246ad 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1825,7 +1825,7 @@ impl<'test> TestCx<'test> { /// Gets the absolute path to the directory where all output for the given /// test/revision should reside. - /// E.g., `/path/to/build/host-triple/test/ui/relative/testname.revision.mode/`. + /// E.g., `/path/to/build/host-tuple/test/ui/relative/testname.revision.mode/`. fn output_base_dir(&self) -> PathBuf { output_base_dir(self.config, self.testpaths, self.safe_revision()) } diff --git a/src/tools/miri/src/machine.rs b/src/tools/miri/src/machine.rs index 60d096b92f2..50d3af8cec8 100644 --- a/src/tools/miri/src/machine.rs +++ b/src/tools/miri/src/machine.rs @@ -692,7 +692,7 @@ impl<'tcx> MiriMachine<'tcx> { clock: Clock::new(config.isolated_op == IsolatedOp::Allow), #[cfg(unix)] native_lib: config.native_lib.as_ref().map(|lib_file_path| { - let target_triple = tcx.sess.opts.target_triple.triple(); + let target_triple = tcx.sess.opts.target_triple.tuple(); // Check if host target == the session target. if env!("TARGET") != target_triple { panic!( diff --git a/src/tools/opt-dist/src/environment.rs b/src/tools/opt-dist/src/environment.rs index bc01b7fb8a3..90d0ca717b2 100644 --- a/src/tools/opt-dist/src/environment.rs +++ b/src/tools/opt-dist/src/environment.rs @@ -3,7 +3,7 @@ use derive_builder::Builder; #[derive(Builder)] pub struct Environment { - host_triple: String, + host_tuple: String, python_binary: String, /// The rustc checkout, where the compiler source is located. checkout_dir: Utf8PathBuf, @@ -28,8 +28,8 @@ pub struct Environment { } impl Environment { - pub fn host_triple(&self) -> &str { - &self.host_triple + pub fn host_tuple(&self) -> &str { + &self.host_tuple } pub fn python_binary(&self) -> &str { @@ -45,7 +45,7 @@ impl Environment { } pub fn build_artifacts(&self) -> Utf8PathBuf { - self.build_root().join("build").join(&self.host_triple) + self.build_root().join("build").join(&self.host_tuple) } pub fn artifact_dir(&self) -> Utf8PathBuf { diff --git a/src/tools/opt-dist/src/exec.rs b/src/tools/opt-dist/src/exec.rs index e50f2600e85..deff69a7f9c 100644 --- a/src/tools/opt-dist/src/exec.rs +++ b/src/tools/opt-dist/src/exec.rs @@ -105,9 +105,9 @@ impl Bootstrap { env.checkout_path().join("x.py").as_str(), "build", "--target", - &env.host_triple(), + &env.host_tuple(), "--host", - &env.host_triple(), + &env.host_tuple(), "--stage", "2", "library/std", diff --git a/src/tools/opt-dist/src/main.rs b/src/tools/opt-dist/src/main.rs index 6211b5670aa..c871200f3cf 100644 --- a/src/tools/opt-dist/src/main.rs +++ b/src/tools/opt-dist/src/main.rs @@ -127,7 +127,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec)> shared, } => { let env = EnvironmentBuilder::default() - .host_triple(target_triple) + .host_tuple(target_triple) .python_binary(python) .checkout_dir(checkout_dir.clone()) .host_llvm_dir(llvm_dir) @@ -148,7 +148,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec)> let checkout_dir = Utf8PathBuf::from("/checkout"); let env = EnvironmentBuilder::default() - .host_triple(target_triple) + .host_tuple(target_triple) .python_binary("python3".to_string()) .checkout_dir(checkout_dir.clone()) .host_llvm_dir(Utf8PathBuf::from("/rustroot")) @@ -170,7 +170,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec)> let checkout_dir: Utf8PathBuf = std::env::current_dir()?.try_into()?; let env = EnvironmentBuilder::default() - .host_triple(target_triple) + .host_tuple(target_triple) .python_binary("python".to_string()) .checkout_dir(checkout_dir.clone()) .host_llvm_dir(checkout_dir.join("citools").join("clang-rust")) diff --git a/src/tools/opt-dist/src/tests.rs b/src/tools/opt-dist/src/tests.rs index e401554640c..887055798e0 100644 --- a/src/tools/opt-dist/src/tests.rs +++ b/src/tools/opt-dist/src/tests.rs @@ -22,7 +22,7 @@ pub fn run_tests(env: &Environment) -> anyhow::Result<()> { assert!(extracted_path.is_dir()); Ok(extracted_path) }; - let host_triple = env.host_triple(); + let host_triple = env.host_tuple(); let version = find_dist_version(&dist_dir)?; // Extract rustc, libstd, cargo and src archives to create the optimized sysroot @@ -87,7 +87,7 @@ llvm-config = "{llvm_config}" x_py.as_str(), "test", "--build", - env.host_triple(), + env.host_tuple(), "--stage", "0", "tests/assembly", From ba481518da240b5e532785fce51106c962dcd5fa Mon Sep 17 00:00:00 2001 From: Noratrieb <48135649+Noratrieb@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:03:06 +0200 Subject: [PATCH 12/13] Add `--print host-triple` People often parse `-vV` output to get to the host triple, which is annoying to do. It's easier to just get it directly. --- compiler/rustc_driver_impl/src/lib.rs | 1 + compiler/rustc_session/src/config.rs | 2 ++ src/doc/rustc/src/command-line-arguments.md | 5 +++-- tests/ui/invalid-compile-flags/print.stderr | 2 +- tests/ui/print-request/host.rs | 5 +++++ tests/ui/print-request/host.stdout | 1 + 6 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 tests/ui/print-request/host.rs create mode 100644 tests/ui/print-request/host.stdout diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 97210d9a662..4362007d4ba 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -731,6 +731,7 @@ fn print_crate_info( targets.sort_unstable(); println_info!("{}", targets.join("\n")); } + HostTuple => println_info!("{}", rustc_session::config::host_tuple()), Sysroot => println_info!("{}", sess.sysroot.display()), TargetLibdir => println_info!("{}", sess.target_tlib_path.dir.display()), TargetSpec => { diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 3ac6e7423ac..bb730592068 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -813,6 +813,7 @@ pub struct PrintRequest { #[derive(Copy, Clone, PartialEq, Eq, Debug)] pub enum PrintKind { FileNames, + HostTuple, Sysroot, TargetLibdir, CrateName, @@ -1945,6 +1946,7 @@ fn collect_print_requests( ("crate-name", PrintKind::CrateName), ("deployment-target", PrintKind::DeploymentTarget), ("file-names", PrintKind::FileNames), + ("host-tuple", PrintKind::HostTuple), ("link-args", PrintKind::LinkArgs), ("native-static-libs", PrintKind::NativeStaticLibs), ("relocation-models", PrintKind::RelocationModels), diff --git a/src/doc/rustc/src/command-line-arguments.md b/src/doc/rustc/src/command-line-arguments.md index e5631ba4274..f38d34fccd4 100644 --- a/src/doc/rustc/src/command-line-arguments.md +++ b/src/doc/rustc/src/command-line-arguments.md @@ -256,7 +256,8 @@ The valid types of print values are: - `crate-name` — The name of the crate. - `file-names` — The names of the files created by the `link` emit kind. - `sysroot` — Path to the sysroot. -- `target-libdir` - Path to the target libdir. +- `target-libdir` — Path to the target libdir. +- `host-tuple` — The target-tuple string of the host compiler (e.g. `x86_64-unknown-linux-gnu`) - `cfg` — List of cfg values. See [conditional compilation] for more information about cfg values. - `target-list` — List of known targets. The target may be selected with the @@ -286,7 +287,7 @@ The valid types of print values are: exact format of this debugging output is not a stable guarantee, other than that it will include the linker executable and the text of each command-line argument passed to the linker. -- `deployment-target` - The currently selected [deployment target] (or minimum OS version) +- `deployment-target` — The currently selected [deployment target] (or minimum OS version) for the selected Apple platform target. This value can be used or passed along to other components alongside a Rust build that need this information, such as C compilers. This returns rustc's minimum supported deployment target if no `*_DEPLOYMENT_TARGET` variable diff --git a/tests/ui/invalid-compile-flags/print.stderr b/tests/ui/invalid-compile-flags/print.stderr index 70b4a394dd0..df0c3977dc8 100644 --- a/tests/ui/invalid-compile-flags/print.stderr +++ b/tests/ui/invalid-compile-flags/print.stderr @@ -1,4 +1,4 @@ error: unknown print request: `yyyy` | - = help: valid print requests are: `all-target-specs-json`, `calling-conventions`, `cfg`, `check-cfg`, `code-models`, `crate-name`, `deployment-target`, `file-names`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `tls-models` + = help: valid print requests are: `all-target-specs-json`, `calling-conventions`, `cfg`, `check-cfg`, `code-models`, `crate-name`, `deployment-target`, `file-names`, `host-tuple`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `tls-models` diff --git a/tests/ui/print-request/host.rs b/tests/ui/print-request/host.rs new file mode 100644 index 00000000000..d54da9b35d0 --- /dev/null +++ b/tests/ui/print-request/host.rs @@ -0,0 +1,5 @@ +//@ only-x86_64-unknown-linux-gnu +//@ compile-flags: --print host-tuple +//@ check-pass + +fn main() {} diff --git a/tests/ui/print-request/host.stdout b/tests/ui/print-request/host.stdout new file mode 100644 index 00000000000..21696ec3a0c --- /dev/null +++ b/tests/ui/print-request/host.stdout @@ -0,0 +1 @@ +x86_64-unknown-linux-gnu From 19e287060de9a641d7000a5575bb943a9bfba318 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 31 Oct 2024 21:30:23 +0100 Subject: [PATCH 13/13] remove const-support for align_offset Operations like is_aligned would return actively wrong results at compile-time, i.e. calling it on the same pointer at compiletime and runtime could yield different results. That's no good. Instead of having hacks to make align_offset kind-of work in const-eval, just use const_eval_select in the few places where it makes sense, which also ensures those places are all aware they need to make sure the fallback behavior is consistent. --- compiler/rustc_const_eval/messages.ftl | 3 - .../src/const_eval/machine.rs | 88 +----- compiler/rustc_hir/src/lang_items.rs | 3 - compiler/rustc_span/src/symbol.rs | 1 - library/core/src/lib.rs | 2 - library/core/src/ptr/const_ptr.rs | 192 +------------ library/core/src/ptr/mod.rs | 10 +- library/core/src/ptr/mut_ptr.rs | 186 +------------ library/core/src/ptr/non_null.rs | 170 +----------- library/core/src/slice/ascii.rs | 157 +++++------ library/core/src/slice/memchr.rs | 95 ++++--- library/core/src/str/converts.rs | 1 - library/core/src/str/validations.rs | 26 +- library/core/src/ub_checks.rs | 14 +- library/core/tests/lib.rs | 2 - library/core/tests/ptr.rs | 257 ------------------ 16 files changed, 185 insertions(+), 1022 deletions(-) diff --git a/compiler/rustc_const_eval/messages.ftl b/compiler/rustc_const_eval/messages.ftl index 3e4f83c8242..2bc5adb2dce 100644 --- a/compiler/rustc_const_eval/messages.ftl +++ b/compiler/rustc_const_eval/messages.ftl @@ -1,9 +1,6 @@ const_eval_address_space_full = there are no more free addresses in the address space -const_eval_align_offset_invalid_align = - `align_offset` called with non-power-of-two align: {$target_align} - const_eval_alignment_check_failed = {$msg -> [AccessedPtr] accessing memory diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 5f0bc8539ee..5938e836a8b 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -1,7 +1,6 @@ use std::borrow::{Borrow, Cow}; use std::fmt; use std::hash::Hash; -use std::ops::ControlFlow; use rustc_ast::Mutability; use rustc_data_structures::fx::{FxHashMap, FxIndexMap, IndexEntry}; @@ -9,7 +8,7 @@ use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::{self as hir, CRATE_HIR_ID, LangItem}; use rustc_middle::mir::AssertMessage; use rustc_middle::query::TyCtxtAt; -use rustc_middle::ty::layout::{FnAbiOf, TyAndLayout}; +use rustc_middle::ty::layout::TyAndLayout; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::{bug, mir}; use rustc_span::Span; @@ -23,9 +22,9 @@ use crate::errors::{LongRunning, LongRunningWarn}; use crate::fluent_generated as fluent; use crate::interpret::{ self, AllocId, AllocRange, ConstAllocation, CtfeProvenance, FnArg, Frame, GlobalAlloc, ImmTy, - InterpCx, InterpResult, MPlaceTy, OpTy, Pointer, PointerArithmetic, RangeSet, Scalar, - StackPopCleanup, compile_time_machine, interp_ok, throw_exhaust, throw_inval, throw_ub, - throw_ub_custom, throw_unsup, throw_unsup_format, + InterpCx, InterpResult, MPlaceTy, OpTy, Pointer, RangeSet, Scalar, compile_time_machine, + interp_ok, throw_exhaust, throw_inval, throw_ub, throw_ub_custom, throw_unsup, + throw_unsup_format, }; /// When hitting this many interpreted terminators we emit a deny by default lint @@ -227,8 +226,8 @@ impl<'tcx> CompileTimeInterpCx<'tcx> { &mut self, instance: ty::Instance<'tcx>, args: &[FnArg<'tcx>], - dest: &MPlaceTy<'tcx>, - ret: Option, + _dest: &MPlaceTy<'tcx>, + _ret: Option, ) -> InterpResult<'tcx, Option>> { let def_id = instance.def_id(); @@ -260,85 +259,10 @@ impl<'tcx> CompileTimeInterpCx<'tcx> { ); return interp_ok(Some(new_instance)); - } else if self.tcx.is_lang_item(def_id, LangItem::AlignOffset) { - let args = self.copy_fn_args(args); - // For align_offset, we replace the function call if the pointer has no address. - match self.align_offset(instance, &args, dest, ret)? { - ControlFlow::Continue(()) => return interp_ok(Some(instance)), - ControlFlow::Break(()) => return interp_ok(None), - } } interp_ok(Some(instance)) } - /// `align_offset(ptr, target_align)` needs special handling in const eval, because the pointer - /// may not have an address. - /// - /// If `ptr` does have a known address, then we return `Continue(())` and the function call should - /// proceed as normal. - /// - /// If `ptr` doesn't have an address, but its underlying allocation's alignment is at most - /// `target_align`, then we call the function again with an dummy address relative to the - /// allocation. - /// - /// If `ptr` doesn't have an address and `target_align` is stricter than the underlying - /// allocation's alignment, then we return `usize::MAX` immediately. - fn align_offset( - &mut self, - instance: ty::Instance<'tcx>, - args: &[OpTy<'tcx>], - dest: &MPlaceTy<'tcx>, - ret: Option, - ) -> InterpResult<'tcx, ControlFlow<()>> { - assert_eq!(args.len(), 2); - - let ptr = self.read_pointer(&args[0])?; - let target_align = self.read_scalar(&args[1])?.to_target_usize(self)?; - - if !target_align.is_power_of_two() { - throw_ub_custom!( - fluent::const_eval_align_offset_invalid_align, - target_align = target_align, - ); - } - - match self.ptr_try_get_alloc_id(ptr, 0) { - Ok((alloc_id, offset, _extra)) => { - let (_size, alloc_align, _kind) = self.get_alloc_info(alloc_id); - - if target_align <= alloc_align.bytes() { - // Extract the address relative to the allocation base that is definitely - // sufficiently aligned and call `align_offset` again. - let addr = ImmTy::from_uint(offset.bytes(), args[0].layout).into(); - let align = ImmTy::from_uint(target_align, args[1].layout).into(); - let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty())?; - - // Push the stack frame with our own adjusted arguments. - self.init_stack_frame( - instance, - self.load_mir(instance.def, None)?, - fn_abi, - &[FnArg::Copy(addr), FnArg::Copy(align)], - /* with_caller_location = */ false, - dest, - StackPopCleanup::Goto { ret, unwind: mir::UnwindAction::Unreachable }, - )?; - interp_ok(ControlFlow::Break(())) - } else { - // Not alignable in const, return `usize::MAX`. - let usize_max = Scalar::from_target_usize(self.target_usize_max(), self); - self.write_scalar(usize_max, dest)?; - self.return_to_block(ret)?; - interp_ok(ControlFlow::Break(())) - } - } - Err(_addr) => { - // The pointer has an address, continue with function call. - interp_ok(ControlFlow::Continue(())) - } - } - } - /// See documentation on the `ptr_guaranteed_cmp` intrinsic. fn guaranteed_cmp(&mut self, a: Scalar, b: Scalar) -> InterpResult<'tcx, u8> { interp_ok(match (a, b) { diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index 7d81f977c22..c952d5f6d77 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -348,9 +348,6 @@ language_item_table! { MaybeUninit, sym::maybe_uninit, maybe_uninit, Target::Union, GenericRequirement::None; - /// Align offset for stride != 1; must not panic. - AlignOffset, sym::align_offset, align_offset_fn, Target::Fn, GenericRequirement::None; - Termination, sym::termination, termination, Target::Trait, GenericRequirement::None; Try, sym::Try, try_trait, Target::Trait, GenericRequirement::None; diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 890c4fdafef..fac2180d63b 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -378,7 +378,6 @@ symbols! { aggregate_raw_ptr, alias, align, - align_offset, alignment, all, alloc, diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index bbfe32027e8..686378fc5cf 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -112,7 +112,6 @@ #![feature(asm_experimental_arch)] #![feature(const_align_of_val)] #![feature(const_align_of_val_raw)] -#![feature(const_align_offset)] #![feature(const_alloc_layout)] #![feature(const_arguments_as_str)] #![feature(const_black_box)] @@ -125,7 +124,6 @@ #![feature(const_nonnull_new)] #![feature(const_option_ext)] #![feature(const_pin_2)] -#![feature(const_pointer_is_aligned)] #![feature(const_ptr_is_null)] #![feature(const_ptr_sub_ptr)] #![feature(const_raw_ptr_comparison)] diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index f00984da527..a4e8e373e04 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -1358,15 +1358,6 @@ impl *const T { /// beyond the allocation that the pointer points into. It is up to the caller to ensure that /// the returned offset is correct in all terms other than alignment. /// - /// When this is called during compile-time evaluation (which is unstable), the implementation - /// may return `usize::MAX` in cases where that can never happen at runtime. This is because the - /// actual alignment of pointers is not known yet during compile-time, so an offset with - /// guaranteed alignment can sometimes not be computed. For example, a buffer declared as `[u8; - /// N]` might be allocated at an odd or an even address, but at compile-time this is not yet - /// known, so the execution has to be correct for either choice. It is therefore impossible to - /// find an offset that is guaranteed to be 2-aligned. (This behavior is subject to change, as usual - /// for unstable APIs.) - /// /// # Panics /// /// The function panics if `align` is not a power-of-two. @@ -1395,8 +1386,7 @@ impl *const T { #[must_use] #[inline] #[stable(feature = "align_offset", since = "1.36.0")] - #[rustc_const_unstable(feature = "const_align_offset", issue = "90962")] - pub const fn align_offset(self, align: usize) -> usize + pub fn align_offset(self, align: usize) -> usize where T: Sized, { @@ -1431,94 +1421,10 @@ impl *const T { /// assert!(ptr.is_aligned()); /// assert!(!ptr.wrapping_byte_add(1).is_aligned()); /// ``` - /// - /// # At compiletime - /// **Note: Alignment at compiletime is experimental and subject to change. See the - /// [tracking issue] for details.** - /// - /// At compiletime, the compiler may not know where a value will end up in memory. - /// Calling this function on a pointer created from a reference at compiletime will only - /// return `true` if the pointer is guaranteed to be aligned. This means that the pointer - /// is never aligned if cast to a type with a stricter alignment than the reference's - /// underlying allocation. - /// - /// ``` - /// #![feature(const_pointer_is_aligned)] - /// - /// // On some platforms, the alignment of primitives is less than their size. - /// #[repr(align(4))] - /// struct AlignedI32(i32); - /// #[repr(align(8))] - /// struct AlignedI64(i64); - /// - /// const _: () = { - /// let data = AlignedI32(42); - /// let ptr = &data as *const AlignedI32; - /// assert!(ptr.is_aligned()); - /// - /// // At runtime either `ptr1` or `ptr2` would be aligned, but at compiletime neither is aligned. - /// let ptr1 = ptr.cast::(); - /// let ptr2 = ptr.wrapping_add(1).cast::(); - /// assert!(!ptr1.is_aligned()); - /// assert!(!ptr2.is_aligned()); - /// }; - /// ``` - /// - /// Due to this behavior, it is possible that a runtime pointer derived from a compiletime - /// pointer is aligned, even if the compiletime pointer wasn't aligned. - /// - /// ``` - /// #![feature(const_pointer_is_aligned)] - /// - /// // On some platforms, the alignment of primitives is less than their size. - /// #[repr(align(4))] - /// struct AlignedI32(i32); - /// #[repr(align(8))] - /// struct AlignedI64(i64); - /// - /// // At compiletime, neither `COMPTIME_PTR` nor `COMPTIME_PTR + 1` is aligned. - /// const COMPTIME_PTR: *const AlignedI32 = &AlignedI32(42); - /// const _: () = assert!(!COMPTIME_PTR.cast::().is_aligned()); - /// const _: () = assert!(!COMPTIME_PTR.wrapping_add(1).cast::().is_aligned()); - /// - /// // At runtime, either `runtime_ptr` or `runtime_ptr + 1` is aligned. - /// let runtime_ptr = COMPTIME_PTR; - /// assert_ne!( - /// runtime_ptr.cast::().is_aligned(), - /// runtime_ptr.wrapping_add(1).cast::().is_aligned(), - /// ); - /// ``` - /// - /// If a pointer is created from a fixed address, this function behaves the same during - /// runtime and compiletime. - /// - /// ``` - /// #![feature(const_pointer_is_aligned)] - /// - /// // On some platforms, the alignment of primitives is less than their size. - /// #[repr(align(4))] - /// struct AlignedI32(i32); - /// #[repr(align(8))] - /// struct AlignedI64(i64); - /// - /// const _: () = { - /// let ptr = 40 as *const AlignedI32; - /// assert!(ptr.is_aligned()); - /// - /// // For pointers with a known address, runtime and compiletime behavior are identical. - /// let ptr1 = ptr.cast::(); - /// let ptr2 = ptr.wrapping_add(1).cast::(); - /// assert!(ptr1.is_aligned()); - /// assert!(!ptr2.is_aligned()); - /// }; - /// ``` - /// - /// [tracking issue]: https://github.com/rust-lang/rust/issues/104203 #[must_use] #[inline] #[stable(feature = "pointer_is_aligned", since = "1.79.0")] - #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")] - pub const fn is_aligned(self) -> bool + pub fn is_aligned(self) -> bool where T: Sized, { @@ -1555,105 +1461,15 @@ impl *const T { /// /// assert_ne!(ptr.is_aligned_to(8), ptr.wrapping_add(1).is_aligned_to(8)); /// ``` - /// - /// # At compiletime - /// **Note: Alignment at compiletime is experimental and subject to change. See the - /// [tracking issue] for details.** - /// - /// At compiletime, the compiler may not know where a value will end up in memory. - /// Calling this function on a pointer created from a reference at compiletime will only - /// return `true` if the pointer is guaranteed to be aligned. This means that the pointer - /// cannot be stricter aligned than the reference's underlying allocation. - /// - /// ``` - /// #![feature(pointer_is_aligned_to)] - /// #![feature(const_pointer_is_aligned)] - /// - /// // On some platforms, the alignment of i32 is less than 4. - /// #[repr(align(4))] - /// struct AlignedI32(i32); - /// - /// const _: () = { - /// let data = AlignedI32(42); - /// let ptr = &data as *const AlignedI32; - /// - /// assert!(ptr.is_aligned_to(1)); - /// assert!(ptr.is_aligned_to(2)); - /// assert!(ptr.is_aligned_to(4)); - /// - /// // At compiletime, we know for sure that the pointer isn't aligned to 8. - /// assert!(!ptr.is_aligned_to(8)); - /// assert!(!ptr.wrapping_add(1).is_aligned_to(8)); - /// }; - /// ``` - /// - /// Due to this behavior, it is possible that a runtime pointer derived from a compiletime - /// pointer is aligned, even if the compiletime pointer wasn't aligned. - /// - /// ``` - /// #![feature(pointer_is_aligned_to)] - /// #![feature(const_pointer_is_aligned)] - /// - /// // On some platforms, the alignment of i32 is less than 4. - /// #[repr(align(4))] - /// struct AlignedI32(i32); - /// - /// // At compiletime, neither `COMPTIME_PTR` nor `COMPTIME_PTR + 1` is aligned. - /// const COMPTIME_PTR: *const AlignedI32 = &AlignedI32(42); - /// const _: () = assert!(!COMPTIME_PTR.is_aligned_to(8)); - /// const _: () = assert!(!COMPTIME_PTR.wrapping_add(1).is_aligned_to(8)); - /// - /// // At runtime, either `runtime_ptr` or `runtime_ptr + 1` is aligned. - /// let runtime_ptr = COMPTIME_PTR; - /// assert_ne!( - /// runtime_ptr.is_aligned_to(8), - /// runtime_ptr.wrapping_add(1).is_aligned_to(8), - /// ); - /// ``` - /// - /// If a pointer is created from a fixed address, this function behaves the same during - /// runtime and compiletime. - /// - /// ``` - /// #![feature(pointer_is_aligned_to)] - /// #![feature(const_pointer_is_aligned)] - /// - /// const _: () = { - /// let ptr = 40 as *const u8; - /// assert!(ptr.is_aligned_to(1)); - /// assert!(ptr.is_aligned_to(2)); - /// assert!(ptr.is_aligned_to(4)); - /// assert!(ptr.is_aligned_to(8)); - /// assert!(!ptr.is_aligned_to(16)); - /// }; - /// ``` - /// - /// [tracking issue]: https://github.com/rust-lang/rust/issues/104203 #[must_use] #[inline] #[unstable(feature = "pointer_is_aligned_to", issue = "96284")] - #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")] - pub const fn is_aligned_to(self, align: usize) -> bool { + pub fn is_aligned_to(self, align: usize) -> bool { if !align.is_power_of_two() { panic!("is_aligned_to: align is not a power-of-two"); } - #[inline] - fn runtime_impl(ptr: *const (), align: usize) -> bool { - ptr.addr() & (align - 1) == 0 - } - - #[inline] - #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")] - const fn const_impl(ptr: *const (), align: usize) -> bool { - // We can't use the address of `self` in a `const fn`, so we use `align_offset` instead. - ptr.align_offset(align) == 0 - } - - // The cast to `()` is used to - // 1. deal with fat pointers; and - // 2. ensure that `align_offset` (in `const_impl`) doesn't actually try to compute an offset. - const_eval_select((self.cast::<()>(), align), const_impl, runtime_impl) + self.addr() & (align - 1) == 0 } } diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index 7c2205fdcd1..b98e2b5eac8 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -1852,9 +1852,7 @@ pub unsafe fn write_volatile(dst: *mut T, src: T) { /// /// Any questions go to @nagisa. #[allow(ptr_to_integer_transmute_in_consts)] -#[lang = "align_offset"] -#[rustc_const_unstable(feature = "const_align_offset", issue = "90962")] -pub(crate) const unsafe fn align_offset(p: *const T, a: usize) -> usize { +pub(crate) unsafe fn align_offset(p: *const T, a: usize) -> usize { // FIXME(#75598): Direct use of these intrinsics improves codegen significantly at opt-level <= // 1, where the method versions of these operations are not inlined. use intrinsics::{ @@ -1915,11 +1913,7 @@ pub(crate) const unsafe fn align_offset(p: *const T, a: usize) -> usiz let stride = mem::size_of::(); - // SAFETY: This is just an inlined `p.addr()` (which is not - // a `const fn` so we cannot call it). - // During const eval, we hook this function to ensure that the pointer never - // has provenance, making this sound. - let addr: usize = unsafe { mem::transmute(p) }; + let addr: usize = p.addr(); // SAFETY: `a` is a power-of-two, therefore non-zero. let a_minus_one = unsafe { unchecked_sub(a, 1) }; diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 60a2dcd1ee7..0d94a7f491c 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -1,6 +1,5 @@ use super::*; use crate::cmp::Ordering::{Equal, Greater, Less}; -use crate::intrinsics::const_eval_select; use crate::mem::SizedTypeProperties; use crate::slice::{self, SliceIndex}; @@ -1636,8 +1635,7 @@ impl *mut T { #[must_use] #[inline] #[stable(feature = "align_offset", since = "1.36.0")] - #[rustc_const_unstable(feature = "const_align_offset", issue = "90962")] - pub const fn align_offset(self, align: usize) -> usize + pub fn align_offset(self, align: usize) -> usize where T: Sized, { @@ -1675,95 +1673,10 @@ impl *mut T { /// assert!(ptr.is_aligned()); /// assert!(!ptr.wrapping_byte_add(1).is_aligned()); /// ``` - /// - /// # At compiletime - /// **Note: Alignment at compiletime is experimental and subject to change. See the - /// [tracking issue] for details.** - /// - /// At compiletime, the compiler may not know where a value will end up in memory. - /// Calling this function on a pointer created from a reference at compiletime will only - /// return `true` if the pointer is guaranteed to be aligned. This means that the pointer - /// is never aligned if cast to a type with a stricter alignment than the reference's - /// underlying allocation. - /// - /// ``` - /// #![feature(const_pointer_is_aligned)] - /// - /// // On some platforms, the alignment of primitives is less than their size. - /// #[repr(align(4))] - /// struct AlignedI32(i32); - /// #[repr(align(8))] - /// struct AlignedI64(i64); - /// - /// const _: () = { - /// let mut data = AlignedI32(42); - /// let ptr = &mut data as *mut AlignedI32; - /// assert!(ptr.is_aligned()); - /// - /// // At runtime either `ptr1` or `ptr2` would be aligned, but at compiletime neither is aligned. - /// let ptr1 = ptr.cast::(); - /// let ptr2 = ptr.wrapping_add(1).cast::(); - /// assert!(!ptr1.is_aligned()); - /// assert!(!ptr2.is_aligned()); - /// }; - /// ``` - /// - /// Due to this behavior, it is possible that a runtime pointer derived from a compiletime - /// pointer is aligned, even if the compiletime pointer wasn't aligned. - /// - /// ``` - /// #![feature(const_pointer_is_aligned)] - /// - /// // On some platforms, the alignment of primitives is less than their size. - /// #[repr(align(4))] - /// struct AlignedI32(i32); - /// #[repr(align(8))] - /// struct AlignedI64(i64); - /// - /// // At compiletime, neither `COMPTIME_PTR` nor `COMPTIME_PTR + 1` is aligned. - /// // Also, note that mutable references are not allowed in the final value of constants. - /// const COMPTIME_PTR: *mut AlignedI32 = (&AlignedI32(42) as *const AlignedI32).cast_mut(); - /// const _: () = assert!(!COMPTIME_PTR.cast::().is_aligned()); - /// const _: () = assert!(!COMPTIME_PTR.wrapping_add(1).cast::().is_aligned()); - /// - /// // At runtime, either `runtime_ptr` or `runtime_ptr + 1` is aligned. - /// let runtime_ptr = COMPTIME_PTR; - /// assert_ne!( - /// runtime_ptr.cast::().is_aligned(), - /// runtime_ptr.wrapping_add(1).cast::().is_aligned(), - /// ); - /// ``` - /// - /// If a pointer is created from a fixed address, this function behaves the same during - /// runtime and compiletime. - /// - /// ``` - /// #![feature(const_pointer_is_aligned)] - /// - /// // On some platforms, the alignment of primitives is less than their size. - /// #[repr(align(4))] - /// struct AlignedI32(i32); - /// #[repr(align(8))] - /// struct AlignedI64(i64); - /// - /// const _: () = { - /// let ptr = 40 as *mut AlignedI32; - /// assert!(ptr.is_aligned()); - /// - /// // For pointers with a known address, runtime and compiletime behavior are identical. - /// let ptr1 = ptr.cast::(); - /// let ptr2 = ptr.wrapping_add(1).cast::(); - /// assert!(ptr1.is_aligned()); - /// assert!(!ptr2.is_aligned()); - /// }; - /// ``` - /// - /// [tracking issue]: https://github.com/rust-lang/rust/issues/104203 #[must_use] #[inline] #[stable(feature = "pointer_is_aligned", since = "1.79.0")] - #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")] - pub const fn is_aligned(self) -> bool + pub fn is_aligned(self) -> bool where T: Sized, { @@ -1800,106 +1713,15 @@ impl *mut T { /// /// assert_ne!(ptr.is_aligned_to(8), ptr.wrapping_add(1).is_aligned_to(8)); /// ``` - /// - /// # At compiletime - /// **Note: Alignment at compiletime is experimental and subject to change. See the - /// [tracking issue] for details.** - /// - /// At compiletime, the compiler may not know where a value will end up in memory. - /// Calling this function on a pointer created from a reference at compiletime will only - /// return `true` if the pointer is guaranteed to be aligned. This means that the pointer - /// cannot be stricter aligned than the reference's underlying allocation. - /// - /// ``` - /// #![feature(pointer_is_aligned_to)] - /// #![feature(const_pointer_is_aligned)] - /// - /// // On some platforms, the alignment of i32 is less than 4. - /// #[repr(align(4))] - /// struct AlignedI32(i32); - /// - /// const _: () = { - /// let mut data = AlignedI32(42); - /// let ptr = &mut data as *mut AlignedI32; - /// - /// assert!(ptr.is_aligned_to(1)); - /// assert!(ptr.is_aligned_to(2)); - /// assert!(ptr.is_aligned_to(4)); - /// - /// // At compiletime, we know for sure that the pointer isn't aligned to 8. - /// assert!(!ptr.is_aligned_to(8)); - /// assert!(!ptr.wrapping_add(1).is_aligned_to(8)); - /// }; - /// ``` - /// - /// Due to this behavior, it is possible that a runtime pointer derived from a compiletime - /// pointer is aligned, even if the compiletime pointer wasn't aligned. - /// - /// ``` - /// #![feature(pointer_is_aligned_to)] - /// #![feature(const_pointer_is_aligned)] - /// - /// // On some platforms, the alignment of i32 is less than 4. - /// #[repr(align(4))] - /// struct AlignedI32(i32); - /// - /// // At compiletime, neither `COMPTIME_PTR` nor `COMPTIME_PTR + 1` is aligned. - /// // Also, note that mutable references are not allowed in the final value of constants. - /// const COMPTIME_PTR: *mut AlignedI32 = (&AlignedI32(42) as *const AlignedI32).cast_mut(); - /// const _: () = assert!(!COMPTIME_PTR.is_aligned_to(8)); - /// const _: () = assert!(!COMPTIME_PTR.wrapping_add(1).is_aligned_to(8)); - /// - /// // At runtime, either `runtime_ptr` or `runtime_ptr + 1` is aligned. - /// let runtime_ptr = COMPTIME_PTR; - /// assert_ne!( - /// runtime_ptr.is_aligned_to(8), - /// runtime_ptr.wrapping_add(1).is_aligned_to(8), - /// ); - /// ``` - /// - /// If a pointer is created from a fixed address, this function behaves the same during - /// runtime and compiletime. - /// - /// ``` - /// #![feature(pointer_is_aligned_to)] - /// #![feature(const_pointer_is_aligned)] - /// - /// const _: () = { - /// let ptr = 40 as *mut u8; - /// assert!(ptr.is_aligned_to(1)); - /// assert!(ptr.is_aligned_to(2)); - /// assert!(ptr.is_aligned_to(4)); - /// assert!(ptr.is_aligned_to(8)); - /// assert!(!ptr.is_aligned_to(16)); - /// }; - /// ``` - /// - /// [tracking issue]: https://github.com/rust-lang/rust/issues/104203 #[must_use] #[inline] #[unstable(feature = "pointer_is_aligned_to", issue = "96284")] - #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")] - pub const fn is_aligned_to(self, align: usize) -> bool { + pub fn is_aligned_to(self, align: usize) -> bool { if !align.is_power_of_two() { panic!("is_aligned_to: align is not a power-of-two"); } - #[inline] - fn runtime_impl(ptr: *mut (), align: usize) -> bool { - ptr.addr() & (align - 1) == 0 - } - - #[inline] - #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")] - const fn const_impl(ptr: *mut (), align: usize) -> bool { - // We can't use the address of `self` in a `const fn`, so we use `align_offset` instead. - ptr.align_offset(align) == 0 - } - - // The cast to `()` is used to - // 1. deal with fat pointers; and - // 2. ensure that `align_offset` (in `const_impl`) doesn't actually try to compute an offset. - const_eval_select((self.cast::<()>(), align), const_impl, runtime_impl) + self.addr() & (align - 1) == 0 } } diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 44eeb052661..ad24e50aa15 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -1192,8 +1192,7 @@ impl NonNull { #[inline] #[must_use] #[stable(feature = "non_null_convenience", since = "1.80.0")] - #[rustc_const_unstable(feature = "const_align_offset", issue = "90962")] - pub const fn align_offset(self, align: usize) -> usize + pub fn align_offset(self, align: usize) -> usize where T: Sized, { @@ -1224,98 +1223,10 @@ impl NonNull { /// assert!(ptr.is_aligned()); /// assert!(!NonNull::new(ptr.as_ptr().wrapping_byte_add(1)).unwrap().is_aligned()); /// ``` - /// - /// # At compiletime - /// **Note: Alignment at compiletime is experimental and subject to change. See the - /// [tracking issue] for details.** - /// - /// At compiletime, the compiler may not know where a value will end up in memory. - /// Calling this function on a pointer created from a reference at compiletime will only - /// return `true` if the pointer is guaranteed to be aligned. This means that the pointer - /// is never aligned if cast to a type with a stricter alignment than the reference's - /// underlying allocation. - /// - /// ``` - /// #![feature(const_nonnull_new)] - /// #![feature(const_pointer_is_aligned)] - /// use std::ptr::NonNull; - /// - /// // On some platforms, the alignment of primitives is less than their size. - /// #[repr(align(4))] - /// struct AlignedI32(i32); - /// #[repr(align(8))] - /// struct AlignedI64(i64); - /// - /// const _: () = { - /// let data = [AlignedI32(42), AlignedI32(42)]; - /// let ptr = NonNull::::new(&data[0] as *const _ as *mut _).unwrap(); - /// assert!(ptr.is_aligned()); - /// - /// // At runtime either `ptr1` or `ptr2` would be aligned, but at compiletime neither is aligned. - /// let ptr1 = ptr.cast::(); - /// let ptr2 = unsafe { ptr.add(1).cast::() }; - /// assert!(!ptr1.is_aligned()); - /// assert!(!ptr2.is_aligned()); - /// }; - /// ``` - /// - /// Due to this behavior, it is possible that a runtime pointer derived from a compiletime - /// pointer is aligned, even if the compiletime pointer wasn't aligned. - /// - /// ``` - /// #![feature(const_pointer_is_aligned)] - /// - /// // On some platforms, the alignment of primitives is less than their size. - /// #[repr(align(4))] - /// struct AlignedI32(i32); - /// #[repr(align(8))] - /// struct AlignedI64(i64); - /// - /// // At compiletime, neither `COMPTIME_PTR` nor `COMPTIME_PTR + 1` is aligned. - /// const COMPTIME_PTR: *const AlignedI32 = &AlignedI32(42); - /// const _: () = assert!(!COMPTIME_PTR.cast::().is_aligned()); - /// const _: () = assert!(!COMPTIME_PTR.wrapping_add(1).cast::().is_aligned()); - /// - /// // At runtime, either `runtime_ptr` or `runtime_ptr + 1` is aligned. - /// let runtime_ptr = COMPTIME_PTR; - /// assert_ne!( - /// runtime_ptr.cast::().is_aligned(), - /// runtime_ptr.wrapping_add(1).cast::().is_aligned(), - /// ); - /// ``` - /// - /// If a pointer is created from a fixed address, this function behaves the same during - /// runtime and compiletime. - /// - /// ``` - /// #![feature(const_pointer_is_aligned)] - /// #![feature(const_nonnull_new)] - /// use std::ptr::NonNull; - /// - /// // On some platforms, the alignment of primitives is less than their size. - /// #[repr(align(4))] - /// struct AlignedI32(i32); - /// #[repr(align(8))] - /// struct AlignedI64(i64); - /// - /// const _: () = { - /// let ptr = NonNull::new(40 as *mut AlignedI32).unwrap(); - /// assert!(ptr.is_aligned()); - /// - /// // For pointers with a known address, runtime and compiletime behavior are identical. - /// let ptr1 = ptr.cast::(); - /// let ptr2 = NonNull::new(ptr.as_ptr().wrapping_add(1)).unwrap().cast::(); - /// assert!(ptr1.is_aligned()); - /// assert!(!ptr2.is_aligned()); - /// }; - /// ``` - /// - /// [tracking issue]: https://github.com/rust-lang/rust/issues/104203 #[inline] #[must_use] #[stable(feature = "pointer_is_aligned", since = "1.79.0")] - #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")] - pub const fn is_aligned(self) -> bool + pub fn is_aligned(self) -> bool where T: Sized, { @@ -1352,85 +1263,10 @@ impl NonNull { /// /// assert_ne!(ptr.is_aligned_to(8), ptr.wrapping_add(1).is_aligned_to(8)); /// ``` - /// - /// # At compiletime - /// **Note: Alignment at compiletime is experimental and subject to change. See the - /// [tracking issue] for details.** - /// - /// At compiletime, the compiler may not know where a value will end up in memory. - /// Calling this function on a pointer created from a reference at compiletime will only - /// return `true` if the pointer is guaranteed to be aligned. This means that the pointer - /// cannot be stricter aligned than the reference's underlying allocation. - /// - /// ``` - /// #![feature(pointer_is_aligned_to)] - /// #![feature(const_pointer_is_aligned)] - /// - /// // On some platforms, the alignment of i32 is less than 4. - /// #[repr(align(4))] - /// struct AlignedI32(i32); - /// - /// const _: () = { - /// let data = AlignedI32(42); - /// let ptr = &data as *const AlignedI32; - /// - /// assert!(ptr.is_aligned_to(1)); - /// assert!(ptr.is_aligned_to(2)); - /// assert!(ptr.is_aligned_to(4)); - /// - /// // At compiletime, we know for sure that the pointer isn't aligned to 8. - /// assert!(!ptr.is_aligned_to(8)); - /// assert!(!ptr.wrapping_add(1).is_aligned_to(8)); - /// }; - /// ``` - /// - /// Due to this behavior, it is possible that a runtime pointer derived from a compiletime - /// pointer is aligned, even if the compiletime pointer wasn't aligned. - /// - /// ``` - /// #![feature(pointer_is_aligned_to)] - /// #![feature(const_pointer_is_aligned)] - /// - /// // On some platforms, the alignment of i32 is less than 4. - /// #[repr(align(4))] - /// struct AlignedI32(i32); - /// - /// // At compiletime, neither `COMPTIME_PTR` nor `COMPTIME_PTR + 1` is aligned. - /// const COMPTIME_PTR: *const AlignedI32 = &AlignedI32(42); - /// const _: () = assert!(!COMPTIME_PTR.is_aligned_to(8)); - /// const _: () = assert!(!COMPTIME_PTR.wrapping_add(1).is_aligned_to(8)); - /// - /// // At runtime, either `runtime_ptr` or `runtime_ptr + 1` is aligned. - /// let runtime_ptr = COMPTIME_PTR; - /// assert_ne!( - /// runtime_ptr.is_aligned_to(8), - /// runtime_ptr.wrapping_add(1).is_aligned_to(8), - /// ); - /// ``` - /// - /// If a pointer is created from a fixed address, this function behaves the same during - /// runtime and compiletime. - /// - /// ``` - /// #![feature(pointer_is_aligned_to)] - /// #![feature(const_pointer_is_aligned)] - /// - /// const _: () = { - /// let ptr = 40 as *const u8; - /// assert!(ptr.is_aligned_to(1)); - /// assert!(ptr.is_aligned_to(2)); - /// assert!(ptr.is_aligned_to(4)); - /// assert!(ptr.is_aligned_to(8)); - /// assert!(!ptr.is_aligned_to(16)); - /// }; - /// ``` - /// - /// [tracking issue]: https://github.com/rust-lang/rust/issues/104203 #[inline] #[must_use] #[unstable(feature = "pointer_is_aligned_to", issue = "96284")] - #[rustc_const_unstable(feature = "const_pointer_is_aligned", issue = "104203")] - pub const fn is_aligned_to(self, align: usize) -> bool { + pub fn is_aligned_to(self, align: usize) -> bool { self.pointer.is_aligned_to(align) } } diff --git a/library/core/src/slice/ascii.rs b/library/core/src/slice/ascii.rs index 21e0460072f..8dcd34929e1 100644 --- a/library/core/src/slice/ascii.rs +++ b/library/core/src/slice/ascii.rs @@ -3,6 +3,7 @@ use core::ascii::EscapeDefault; use crate::fmt::{self, Write}; +use crate::intrinsics::const_eval_select; use crate::{ascii, iter, mem, ops}; #[cfg(not(test))] @@ -346,89 +347,93 @@ pub const fn is_ascii_simple(mut bytes: &[u8]) -> bool { /// If any of these loads produces something for which `contains_nonascii` /// (above) returns true, then we know the answer is false. #[inline] -#[rustc_allow_const_fn_unstable(const_raw_ptr_comparison, const_pointer_is_aligned)] // only in a debug assertion -#[rustc_allow_const_fn_unstable(const_align_offset)] // behavior does not change when `align_offset` fails +#[rustc_allow_const_fn_unstable(const_eval_select)] // fallback impl has same behavior const fn is_ascii(s: &[u8]) -> bool { - const USIZE_SIZE: usize = mem::size_of::(); + // The runtime version behaves the same as the compiletime version, it's + // just more optimized. + return const_eval_select((s,), compiletime, runtime); - let len = s.len(); - let align_offset = s.as_ptr().align_offset(USIZE_SIZE); - - // If we wouldn't gain anything from the word-at-a-time implementation, fall - // back to a scalar loop. - // - // We also do this for architectures where `size_of::()` isn't - // sufficient alignment for `usize`, because it's a weird edge case. - if len < USIZE_SIZE || len < align_offset || USIZE_SIZE < mem::align_of::() { - return is_ascii_simple(s); + const fn compiletime(s: &[u8]) -> bool { + is_ascii_simple(s) } - // We always read the first word unaligned, which means `align_offset` is - // 0, we'd read the same value again for the aligned read. - let offset_to_aligned = if align_offset == 0 { USIZE_SIZE } else { align_offset }; + #[inline] + fn runtime(s: &[u8]) -> bool { + const USIZE_SIZE: usize = mem::size_of::(); - let start = s.as_ptr(); - // SAFETY: We verify `len < USIZE_SIZE` above. - let first_word = unsafe { (start as *const usize).read_unaligned() }; + let len = s.len(); + let align_offset = s.as_ptr().align_offset(USIZE_SIZE); - if contains_nonascii(first_word) { - return false; - } - // We checked this above, somewhat implicitly. Note that `offset_to_aligned` - // is either `align_offset` or `USIZE_SIZE`, both of are explicitly checked - // above. - debug_assert!(offset_to_aligned <= len); - - // SAFETY: word_ptr is the (properly aligned) usize ptr we use to read the - // middle chunk of the slice. - let mut word_ptr = unsafe { start.add(offset_to_aligned) as *const usize }; - - // `byte_pos` is the byte index of `word_ptr`, used for loop end checks. - let mut byte_pos = offset_to_aligned; - - // Paranoia check about alignment, since we're about to do a bunch of - // unaligned loads. In practice this should be impossible barring a bug in - // `align_offset` though. - // While this method is allowed to spuriously fail in CTFE, if it doesn't - // have alignment information it should have given a `usize::MAX` for - // `align_offset` earlier, sending things through the scalar path instead of - // this one, so this check should pass if it's reachable. - debug_assert!(word_ptr.is_aligned_to(mem::align_of::())); - - // Read subsequent words until the last aligned word, excluding the last - // aligned word by itself to be done in tail check later, to ensure that - // tail is always one `usize` at most to extra branch `byte_pos == len`. - while byte_pos < len - USIZE_SIZE { - // Sanity check that the read is in bounds - debug_assert!(byte_pos + USIZE_SIZE <= len); - // And that our assumptions about `byte_pos` hold. - debug_assert!(matches!( - word_ptr.cast::().guaranteed_eq(start.wrapping_add(byte_pos)), - // These are from the same allocation, so will hopefully always be - // known to match even in CTFE, but if it refuses to compare them - // that's ok since it's just a debug check anyway. - None | Some(true), - )); - - // SAFETY: We know `word_ptr` is properly aligned (because of - // `align_offset`), and we know that we have enough bytes between `word_ptr` and the end - let word = unsafe { word_ptr.read() }; - if contains_nonascii(word) { - return false; + // If we wouldn't gain anything from the word-at-a-time implementation, fall + // back to a scalar loop. + // + // We also do this for architectures where `size_of::()` isn't + // sufficient alignment for `usize`, because it's a weird edge case. + if len < USIZE_SIZE || len < align_offset || USIZE_SIZE < mem::align_of::() { + return is_ascii_simple(s); } - byte_pos += USIZE_SIZE; - // SAFETY: We know that `byte_pos <= len - USIZE_SIZE`, which means that - // after this `add`, `word_ptr` will be at most one-past-the-end. - word_ptr = unsafe { word_ptr.add(1) }; + // We always read the first word unaligned, which means `align_offset` is + // 0, we'd read the same value again for the aligned read. + let offset_to_aligned = if align_offset == 0 { USIZE_SIZE } else { align_offset }; + + let start = s.as_ptr(); + // SAFETY: We verify `len < USIZE_SIZE` above. + let first_word = unsafe { (start as *const usize).read_unaligned() }; + + if contains_nonascii(first_word) { + return false; + } + // We checked this above, somewhat implicitly. Note that `offset_to_aligned` + // is either `align_offset` or `USIZE_SIZE`, both of are explicitly checked + // above. + debug_assert!(offset_to_aligned <= len); + + // SAFETY: word_ptr is the (properly aligned) usize ptr we use to read the + // middle chunk of the slice. + let mut word_ptr = unsafe { start.add(offset_to_aligned) as *const usize }; + + // `byte_pos` is the byte index of `word_ptr`, used for loop end checks. + let mut byte_pos = offset_to_aligned; + + // Paranoia check about alignment, since we're about to do a bunch of + // unaligned loads. In practice this should be impossible barring a bug in + // `align_offset` though. + // While this method is allowed to spuriously fail in CTFE, if it doesn't + // have alignment information it should have given a `usize::MAX` for + // `align_offset` earlier, sending things through the scalar path instead of + // this one, so this check should pass if it's reachable. + debug_assert!(word_ptr.is_aligned_to(mem::align_of::())); + + // Read subsequent words until the last aligned word, excluding the last + // aligned word by itself to be done in tail check later, to ensure that + // tail is always one `usize` at most to extra branch `byte_pos == len`. + while byte_pos < len - USIZE_SIZE { + // Sanity check that the read is in bounds + debug_assert!(byte_pos + USIZE_SIZE <= len); + // And that our assumptions about `byte_pos` hold. + debug_assert!(word_ptr.cast::() == start.wrapping_add(byte_pos)); + + // SAFETY: We know `word_ptr` is properly aligned (because of + // `align_offset`), and we know that we have enough bytes between `word_ptr` and the end + let word = unsafe { word_ptr.read() }; + if contains_nonascii(word) { + return false; + } + + byte_pos += USIZE_SIZE; + // SAFETY: We know that `byte_pos <= len - USIZE_SIZE`, which means that + // after this `add`, `word_ptr` will be at most one-past-the-end. + word_ptr = unsafe { word_ptr.add(1) }; + } + + // Sanity check to ensure there really is only one `usize` left. This should + // be guaranteed by our loop condition. + debug_assert!(byte_pos <= len && len - byte_pos <= USIZE_SIZE); + + // SAFETY: This relies on `len >= USIZE_SIZE`, which we check at the start. + let last_word = unsafe { (start.add(len - USIZE_SIZE) as *const usize).read_unaligned() }; + + !contains_nonascii(last_word) } - - // Sanity check to ensure there really is only one `usize` left. This should - // be guaranteed by our loop condition. - debug_assert!(byte_pos <= len && len - byte_pos <= USIZE_SIZE); - - // SAFETY: This relies on `len >= USIZE_SIZE`, which we check at the start. - let last_word = unsafe { (start.add(len - USIZE_SIZE) as *const usize).read_unaligned() }; - - !contains_nonascii(last_word) } diff --git a/library/core/src/slice/memchr.rs b/library/core/src/slice/memchr.rs index 57604623262..b7c4a1f6f08 100644 --- a/library/core/src/slice/memchr.rs +++ b/library/core/src/slice/memchr.rs @@ -1,6 +1,7 @@ // Original implementation taken from rust-memchr. // Copyright 2015 Andrew Gallant, bluss and Nicolas Koch +use crate::intrinsics::const_eval_select; use crate::mem; const LO_USIZE: usize = usize::repeat_u8(0x01); @@ -50,58 +51,66 @@ const fn memchr_naive(x: u8, text: &[u8]) -> Option { None } -#[rustc_allow_const_fn_unstable(const_cmp)] -#[rustc_allow_const_fn_unstable(const_align_offset)] +#[rustc_allow_const_fn_unstable(const_eval_select)] // fallback impl has same behavior #[cfg_attr(bootstrap, rustc_const_stable(feature = "const_memchr", since = "1.65.0"))] const fn memchr_aligned(x: u8, text: &[u8]) -> Option { - // Scan for a single byte value by reading two `usize` words at a time. - // - // Split `text` in three parts - // - unaligned initial part, before the first word aligned address in text - // - body, scan by 2 words at a time - // - the last remaining part, < 2 word size + // The runtime version behaves the same as the compiletime version, it's + // just more optimized. + return const_eval_select((x, text), compiletime, runtime); - // search up to an aligned boundary - let len = text.len(); - let ptr = text.as_ptr(); - let mut offset = ptr.align_offset(USIZE_BYTES); - - if offset > 0 { - // FIXME(const-hack, fee1-dead): replace with min - offset = if offset < len { offset } else { len }; - // FIXME(const-hack, fee1-dead): replace with range slicing - // SAFETY: offset is within bounds - let slice = unsafe { super::from_raw_parts(text.as_ptr(), offset) }; - if let Some(index) = memchr_naive(x, slice) { - return Some(index); - } + const fn compiletime(x: u8, text: &[u8]) -> Option { + memchr_naive(x, text) } - // search the body of the text - let repeated_x = usize::repeat_u8(x); - while offset <= len - 2 * USIZE_BYTES { - // SAFETY: the while's predicate guarantees a distance of at least 2 * usize_bytes - // between the offset and the end of the slice. - unsafe { - let u = *(ptr.add(offset) as *const usize); - let v = *(ptr.add(offset + USIZE_BYTES) as *const usize); + #[inline] + fn runtime(x: u8, text: &[u8]) -> Option { + // Scan for a single byte value by reading two `usize` words at a time. + // + // Split `text` in three parts + // - unaligned initial part, before the first word aligned address in text + // - body, scan by 2 words at a time + // - the last remaining part, < 2 word size - // break if there is a matching byte - let zu = contains_zero_byte(u ^ repeated_x); - let zv = contains_zero_byte(v ^ repeated_x); - if zu || zv { - break; + // search up to an aligned boundary + let len = text.len(); + let ptr = text.as_ptr(); + let mut offset = ptr.align_offset(USIZE_BYTES); + + if offset > 0 { + offset = offset.min(len); + let slice = &text[..offset]; + if let Some(index) = memchr_naive(x, slice) { + return Some(index); } } - offset += USIZE_BYTES * 2; - } - // Find the byte after the point the body loop stopped. - // FIXME(const-hack): Use `?` instead. - // FIXME(const-hack, fee1-dead): use range slicing - // SAFETY: offset is within bounds - let slice = unsafe { super::from_raw_parts(text.as_ptr().add(offset), text.len() - offset) }; - if let Some(i) = memchr_naive(x, slice) { Some(offset + i) } else { None } + // search the body of the text + let repeated_x = usize::repeat_u8(x); + while offset <= len - 2 * USIZE_BYTES { + // SAFETY: the while's predicate guarantees a distance of at least 2 * usize_bytes + // between the offset and the end of the slice. + unsafe { + let u = *(ptr.add(offset) as *const usize); + let v = *(ptr.add(offset + USIZE_BYTES) as *const usize); + + // break if there is a matching byte + let zu = contains_zero_byte(u ^ repeated_x); + let zv = contains_zero_byte(v ^ repeated_x); + if zu || zv { + break; + } + } + offset += USIZE_BYTES * 2; + } + + // Find the byte after the point the body loop stopped. + // FIXME(const-hack): Use `?` instead. + // FIXME(const-hack, fee1-dead): use range slicing + let slice = + // SAFETY: offset is within bounds + unsafe { super::from_raw_parts(text.as_ptr().add(offset), text.len() - offset) }; + if let Some(i) = memchr_naive(x, slice) { Some(offset + i) } else { None } + } } /// Returns the last index matching the byte `x` in `text`. diff --git a/library/core/src/str/converts.rs b/library/core/src/str/converts.rs index 2bc1f1e4973..c7bae42765f 100644 --- a/library/core/src/str/converts.rs +++ b/library/core/src/str/converts.rs @@ -82,7 +82,6 @@ use crate::{mem, ptr}; /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_str_from_utf8_shared", since = "1.63.0")] -#[rustc_allow_const_fn_unstable(str_internals)] #[rustc_diagnostic_item = "str_from_utf8"] pub const fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> { // FIXME(const-hack): This should use `?` again, once it's `const` diff --git a/library/core/src/str/validations.rs b/library/core/src/str/validations.rs index cca8ff74dda..6095b589e18 100644 --- a/library/core/src/str/validations.rs +++ b/library/core/src/str/validations.rs @@ -1,6 +1,7 @@ //! Operations related to UTF-8 validation. use super::Utf8Error; +use crate::intrinsics::const_eval_select; use crate::mem; /// Returns the initial codepoint accumulator for the first byte. @@ -122,15 +123,28 @@ const fn contains_nonascii(x: usize) -> bool { /// Walks through `v` checking that it's a valid UTF-8 sequence, /// returning `Ok(())` in that case, or, if it is invalid, `Err(err)`. #[inline(always)] -#[rustc_const_unstable(feature = "str_internals", issue = "none")] +#[rustc_allow_const_fn_unstable(const_eval_select)] // fallback impl has same behavior pub(super) const fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> { let mut index = 0; let len = v.len(); - let usize_bytes = mem::size_of::(); - let ascii_block_size = 2 * usize_bytes; + const USIZE_BYTES: usize = mem::size_of::(); + + let ascii_block_size = 2 * USIZE_BYTES; let blocks_end = if len >= ascii_block_size { len - ascii_block_size + 1 } else { 0 }; - let align = v.as_ptr().align_offset(usize_bytes); + let align = { + const fn compiletime(_v: &[u8]) -> usize { + usize::MAX + } + + fn runtime(v: &[u8]) -> usize { + v.as_ptr().align_offset(USIZE_BYTES) + } + + // Below, we safely fall back to a slower codepath if the offset is `usize::MAX`, + // so the end-to-end behavior is the same at compiletime and runtime. + const_eval_select((v,), compiletime, runtime) + }; while index < len { let old_offset = index; @@ -209,11 +223,11 @@ pub(super) const fn run_utf8_validation(v: &[u8]) -> Result<(), Utf8Error> { // Ascii case, try to skip forward quickly. // When the pointer is aligned, read 2 words of data per iteration // until we find a word containing a non-ascii byte. - if align != usize::MAX && align.wrapping_sub(index) % usize_bytes == 0 { + if align != usize::MAX && align.wrapping_sub(index) % USIZE_BYTES == 0 { let ptr = v.as_ptr(); while index < blocks_end { // SAFETY: since `align - index` and `ascii_block_size` are - // multiples of `usize_bytes`, `block = ptr.add(index)` is + // multiples of `USIZE_BYTES`, `block = ptr.add(index)` is // always aligned with a `usize` so it's safe to dereference // both `block` and `block.add(1)`. unsafe { diff --git a/library/core/src/ub_checks.rs b/library/core/src/ub_checks.rs index 91566439ade..dd1454f401e 100644 --- a/library/core/src/ub_checks.rs +++ b/library/core/src/ub_checks.rs @@ -120,7 +120,19 @@ pub(crate) const fn check_language_ub() -> bool { #[inline] #[rustc_const_unstable(feature = "const_ub_checks", issue = "none")] pub(crate) const fn is_aligned_and_not_null(ptr: *const (), align: usize, is_zst: bool) -> bool { - ptr.is_aligned_to(align) && (is_zst || !ptr.is_null()) + #[inline] + fn runtime(ptr: *const (), align: usize, is_zst: bool) -> bool { + ptr.is_aligned_to(align) && (is_zst || !ptr.is_null()) + } + + #[inline] + #[rustc_const_unstable(feature = "const_ub_checks", issue = "none")] + const fn comptime(ptr: *const (), _align: usize, is_zst: bool) -> bool { + is_zst || !ptr.is_null() + } + + // This is just for safety checks so we can const_eval_select. + const_eval_select((ptr, align, is_zst), comptime, runtime) } #[inline] diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 7346d9f2319..5f14baf96ae 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -16,7 +16,6 @@ #![feature(cell_update)] #![feature(clone_to_uninit)] #![feature(const_align_of_val_raw)] -#![feature(const_align_offset)] #![feature(const_black_box)] #![feature(const_eval_select)] #![feature(const_hash)] @@ -24,7 +23,6 @@ #![feature(const_nonnull_new)] #![feature(const_option_ext)] #![feature(const_pin_2)] -#![feature(const_pointer_is_aligned)] #![feature(const_three_way_compare)] #![feature(const_trait_impl)] #![feature(core_intrinsics)] diff --git a/library/core/tests/ptr.rs b/library/core/tests/ptr.rs index 78d1b137e63..91f8c977d08 100644 --- a/library/core/tests/ptr.rs +++ b/library/core/tests/ptr.rs @@ -359,22 +359,6 @@ fn align_offset_zst() { } } -#[test] -fn align_offset_zst_const() { - const { - // For pointers of stride = 0, the pointer is already aligned or it cannot be aligned at - // all, because no amount of elements will align the pointer. - let mut p = 1; - while p < 1024 { - assert!(ptr::without_provenance::<()>(p).align_offset(p) == 0); - if p != 1 { - assert!(ptr::without_provenance::<()>(p + 1).align_offset(p) == !0); - } - p = (p + 1).next_power_of_two(); - } - } -} - #[test] fn align_offset_stride_one() { // For pointers of stride = 1, the pointer can always be aligned. The offset is equal to @@ -396,25 +380,6 @@ fn align_offset_stride_one() { } } -#[test] -fn align_offset_stride_one_const() { - const { - // For pointers of stride = 1, the pointer can always be aligned. The offset is equal to - // number of bytes. - let mut align = 1; - while align < 1024 { - let mut ptr = 1; - while ptr < 2 * align { - let expected = ptr % align; - let offset = if expected == 0 { 0 } else { align - expected }; - assert!(ptr::without_provenance::(ptr).align_offset(align) == offset); - ptr += 1; - } - align = (align + 1).next_power_of_two(); - } - } -} - #[test] fn align_offset_various_strides() { unsafe fn test_stride(ptr: *const T, align: usize) -> bool { @@ -495,192 +460,6 @@ fn align_offset_various_strides() { assert!(!x); } -#[test] -fn align_offset_various_strides_const() { - const unsafe fn test_stride(ptr: *const T, numptr: usize, align: usize) { - let mut expected = usize::MAX; - // Naive but definitely correct way to find the *first* aligned element of stride::. - let mut el = 0; - while el < align { - if (numptr + el * ::std::mem::size_of::()) % align == 0 { - expected = el; - break; - } - el += 1; - } - let got = ptr.align_offset(align); - assert!(got == expected); - } - - const { - // For pointers of stride != 1, we verify the algorithm against the naivest possible - // implementation - let mut align = 1; - let limit = 32; - while align < limit { - let mut ptr = 1; - while ptr < 4 * align { - unsafe { - #[repr(packed)] - struct A3(#[allow(dead_code)] u16, #[allow(dead_code)] u8); - test_stride::(ptr::without_provenance::(ptr), ptr, align); - - struct A4(#[allow(dead_code)] u32); - test_stride::(ptr::without_provenance::(ptr), ptr, align); - - #[repr(packed)] - struct A5(#[allow(dead_code)] u32, #[allow(dead_code)] u8); - test_stride::(ptr::without_provenance::(ptr), ptr, align); - - #[repr(packed)] - struct A6(#[allow(dead_code)] u32, #[allow(dead_code)] u16); - test_stride::(ptr::without_provenance::(ptr), ptr, align); - - #[repr(packed)] - struct A7( - #[allow(dead_code)] u32, - #[allow(dead_code)] u16, - #[allow(dead_code)] u8, - ); - test_stride::(ptr::without_provenance::(ptr), ptr, align); - - #[repr(packed)] - struct A8(#[allow(dead_code)] u32, #[allow(dead_code)] u32); - test_stride::(ptr::without_provenance::(ptr), ptr, align); - - #[repr(packed)] - struct A9( - #[allow(dead_code)] u32, - #[allow(dead_code)] u32, - #[allow(dead_code)] u8, - ); - test_stride::(ptr::without_provenance::(ptr), ptr, align); - - #[repr(packed)] - struct A10( - #[allow(dead_code)] u32, - #[allow(dead_code)] u32, - #[allow(dead_code)] u16, - ); - test_stride::(ptr::without_provenance::(ptr), ptr, align); - - test_stride::(ptr::without_provenance::(ptr), ptr, align); - test_stride::(ptr::without_provenance::(ptr), ptr, align); - } - ptr += 1; - } - align = (align + 1).next_power_of_two(); - } - } -} - -#[test] -fn align_offset_with_provenance_const() { - const { - // On some platforms (e.g. msp430-none-elf), the alignment of `i32` is less than 4. - #[repr(align(4))] - struct AlignedI32(i32); - - let data = AlignedI32(42); - - // `stride % align == 0` (usual case) - - let ptr: *const i32 = &data.0; - assert!(ptr.align_offset(1) == 0); - assert!(ptr.align_offset(2) == 0); - assert!(ptr.align_offset(4) == 0); - assert!(ptr.align_offset(8) == usize::MAX); - assert!(ptr.wrapping_byte_add(1).align_offset(1) == 0); - assert!(ptr.wrapping_byte_add(1).align_offset(2) == usize::MAX); - assert!(ptr.wrapping_byte_add(2).align_offset(1) == 0); - assert!(ptr.wrapping_byte_add(2).align_offset(2) == 0); - assert!(ptr.wrapping_byte_add(2).align_offset(4) == usize::MAX); - assert!(ptr.wrapping_byte_add(3).align_offset(1) == 0); - assert!(ptr.wrapping_byte_add(3).align_offset(2) == usize::MAX); - - assert!(ptr.wrapping_add(42).align_offset(4) == 0); - assert!(ptr.wrapping_add(42).align_offset(8) == usize::MAX); - - let ptr1: *const i8 = ptr.cast(); - assert!(ptr1.align_offset(1) == 0); - assert!(ptr1.align_offset(2) == 0); - assert!(ptr1.align_offset(4) == 0); - assert!(ptr1.align_offset(8) == usize::MAX); - assert!(ptr1.wrapping_byte_add(1).align_offset(1) == 0); - assert!(ptr1.wrapping_byte_add(1).align_offset(2) == 1); - assert!(ptr1.wrapping_byte_add(1).align_offset(4) == 3); - assert!(ptr1.wrapping_byte_add(1).align_offset(8) == usize::MAX); - assert!(ptr1.wrapping_byte_add(2).align_offset(1) == 0); - assert!(ptr1.wrapping_byte_add(2).align_offset(2) == 0); - assert!(ptr1.wrapping_byte_add(2).align_offset(4) == 2); - assert!(ptr1.wrapping_byte_add(2).align_offset(8) == usize::MAX); - assert!(ptr1.wrapping_byte_add(3).align_offset(1) == 0); - assert!(ptr1.wrapping_byte_add(3).align_offset(2) == 1); - assert!(ptr1.wrapping_byte_add(3).align_offset(4) == 1); - assert!(ptr1.wrapping_byte_add(3).align_offset(8) == usize::MAX); - - let ptr2: *const i16 = ptr.cast(); - assert!(ptr2.align_offset(1) == 0); - assert!(ptr2.align_offset(2) == 0); - assert!(ptr2.align_offset(4) == 0); - assert!(ptr2.align_offset(8) == usize::MAX); - assert!(ptr2.wrapping_byte_add(1).align_offset(1) == 0); - assert!(ptr2.wrapping_byte_add(1).align_offset(2) == usize::MAX); - assert!(ptr2.wrapping_byte_add(2).align_offset(1) == 0); - assert!(ptr2.wrapping_byte_add(2).align_offset(2) == 0); - assert!(ptr2.wrapping_byte_add(2).align_offset(4) == 1); - assert!(ptr2.wrapping_byte_add(2).align_offset(8) == usize::MAX); - assert!(ptr2.wrapping_byte_add(3).align_offset(1) == 0); - assert!(ptr2.wrapping_byte_add(3).align_offset(2) == usize::MAX); - - let ptr3: *const i64 = ptr.cast(); - assert!(ptr3.align_offset(1) == 0); - assert!(ptr3.align_offset(2) == 0); - assert!(ptr3.align_offset(4) == 0); - assert!(ptr3.align_offset(8) == usize::MAX); - assert!(ptr3.wrapping_byte_add(1).align_offset(1) == 0); - assert!(ptr3.wrapping_byte_add(1).align_offset(2) == usize::MAX); - - // `stride % align != 0` (edge case) - - let ptr4: *const [u8; 3] = ptr.cast(); - assert!(ptr4.align_offset(1) == 0); - assert!(ptr4.align_offset(2) == 0); - assert!(ptr4.align_offset(4) == 0); - assert!(ptr4.align_offset(8) == usize::MAX); - assert!(ptr4.wrapping_byte_add(1).align_offset(1) == 0); - assert!(ptr4.wrapping_byte_add(1).align_offset(2) == 1); - assert!(ptr4.wrapping_byte_add(1).align_offset(4) == 1); - assert!(ptr4.wrapping_byte_add(1).align_offset(8) == usize::MAX); - assert!(ptr4.wrapping_byte_add(2).align_offset(1) == 0); - assert!(ptr4.wrapping_byte_add(2).align_offset(2) == 0); - assert!(ptr4.wrapping_byte_add(2).align_offset(4) == 2); - assert!(ptr4.wrapping_byte_add(2).align_offset(8) == usize::MAX); - assert!(ptr4.wrapping_byte_add(3).align_offset(1) == 0); - assert!(ptr4.wrapping_byte_add(3).align_offset(2) == 1); - assert!(ptr4.wrapping_byte_add(3).align_offset(4) == 3); - assert!(ptr4.wrapping_byte_add(3).align_offset(8) == usize::MAX); - - let ptr5: *const [u8; 5] = ptr.cast(); - assert!(ptr5.align_offset(1) == 0); - assert!(ptr5.align_offset(2) == 0); - assert!(ptr5.align_offset(4) == 0); - assert!(ptr5.align_offset(8) == usize::MAX); - assert!(ptr5.wrapping_byte_add(1).align_offset(1) == 0); - assert!(ptr5.wrapping_byte_add(1).align_offset(2) == 1); - assert!(ptr5.wrapping_byte_add(1).align_offset(4) == 3); - assert!(ptr5.wrapping_byte_add(1).align_offset(8) == usize::MAX); - assert!(ptr5.wrapping_byte_add(2).align_offset(1) == 0); - assert!(ptr5.wrapping_byte_add(2).align_offset(2) == 0); - assert!(ptr5.wrapping_byte_add(2).align_offset(4) == 2); - assert!(ptr5.wrapping_byte_add(2).align_offset(8) == usize::MAX); - assert!(ptr5.wrapping_byte_add(3).align_offset(1) == 0); - assert!(ptr5.wrapping_byte_add(3).align_offset(2) == 1); - assert!(ptr5.wrapping_byte_add(3).align_offset(4) == 1); - assert!(ptr5.wrapping_byte_add(3).align_offset(8) == usize::MAX); - } -} - #[test] fn align_offset_issue_103361() { #[cfg(target_pointer_width = "64")] @@ -693,23 +472,6 @@ fn align_offset_issue_103361() { let _ = ptr::without_provenance::(SIZE).align_offset(SIZE); } -#[test] -fn align_offset_issue_103361_const() { - #[cfg(target_pointer_width = "64")] - const SIZE: usize = 1 << 47; - #[cfg(target_pointer_width = "32")] - const SIZE: usize = 1 << 30; - #[cfg(target_pointer_width = "16")] - const SIZE: usize = 1 << 13; - struct HugeSize(#[allow(dead_code)] [u8; SIZE - 1]); - - const { - assert!(ptr::without_provenance::(SIZE - 1).align_offset(SIZE) == SIZE - 1); - assert!(ptr::without_provenance::(SIZE).align_offset(SIZE) == 0); - assert!(ptr::without_provenance::(SIZE + 1).align_offset(SIZE) == 1); - } -} - #[test] fn is_aligned() { let data = 42; @@ -726,25 +488,6 @@ fn is_aligned() { assert_ne!(ptr.is_aligned_to(8), ptr.wrapping_add(1).is_aligned_to(8)); } -#[test] -fn is_aligned_const() { - const { - let data = 42; - let ptr: *const i32 = &data; - assert!(ptr.is_aligned()); - assert!(ptr.is_aligned_to(1)); - assert!(ptr.is_aligned_to(2)); - assert!(ptr.is_aligned_to(4)); - assert!(ptr.wrapping_byte_add(2).is_aligned_to(1)); - assert!(ptr.wrapping_byte_add(2).is_aligned_to(2)); - assert!(!ptr.wrapping_byte_add(2).is_aligned_to(4)); - - // At comptime neither `ptr` nor `ptr+1` is aligned to 8. - assert!(!ptr.is_aligned_to(8)); - assert!(!ptr.wrapping_add(1).is_aligned_to(8)); - } -} - #[test] fn offset_from() { let mut a = [0; 5];