Skip to content

Commit 1189851

Browse files
committed
Auto merge of #125203 - matthiaskrgr:rollup-5pv7drz, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #123694 (expand: fix minor diagnostics bug) - #125171 (Rename `flatten(_mut)` → `as_flattened(_mut)`) - #125181 (set `rust.channel` properly in source tarballs) - #125186 (Remove duplicate word from addr docs) - #125191 (Report better WF obligation leaf obligations in new solver) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8af67ba + 3695449 commit 1189851

25 files changed

+183
-126
lines changed

compiler/rustc_expand/messages.ftl

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ expand_attribute_meta_item =
1010
expand_attribute_single_word =
1111
attribute must only be a single word
1212
13+
expand_attributes_on_expressions_experimental =
14+
attributes on expressions are experimental
15+
.help_outer_doc = `///` is used for outer documentation comments; for a plain comment, use `//`
16+
.help_inner_doc = `//!` is used for inner documentation comments; for a plain comment, use `//` by removing the `!` or inserting a space in between them: `// !`
17+
1318
expand_attributes_wrong_form =
1419
attribute must be of form: `attributes(foo, bar)`
1520

compiler/rustc_expand/src/config.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@ impl<'a> StripUnconfigured<'a> {
382382
}
383383

384384
/// If attributes are not allowed on expressions, emit an error for `attr`
385-
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
386385
#[instrument(level = "trace", skip(self))]
387386
pub(crate) fn maybe_emit_expr_attr_err(&self, attr: &Attribute) {
388387
if self.features.is_some_and(|features| !features.stmt_expr_attributes)
@@ -392,11 +391,15 @@ impl<'a> StripUnconfigured<'a> {
392391
&self.sess,
393392
sym::stmt_expr_attributes,
394393
attr.span,
395-
"attributes on expressions are experimental",
394+
crate::fluent_generated::expand_attributes_on_expressions_experimental,
396395
);
397396

398397
if attr.is_doc_comment() {
399-
err.help("`///` is for documentation comments. For a plain comment, use `//`.");
398+
err.help(if attr.style == AttrStyle::Outer {
399+
crate::fluent_generated::expand_help_outer_doc
400+
} else {
401+
crate::fluent_generated::expand_help_inner_doc
402+
});
400403
}
401404

402405
err.emit();

compiler/rustc_trait_selection/src/solve/fulfill.rs

+57-20
Original file line numberDiff line numberDiff line change
@@ -384,39 +384,64 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
384384
return ControlFlow::Break(self.obligation.clone());
385385
}
386386

387-
// FIXME: Could we extract a trait ref from a projection here too?
387+
let tcx = goal.infcx().tcx;
388388
// FIXME: Also, what about considering >1 layer up the stack? May be necessary
389389
// for normalizes-to.
390-
let Some(parent_trait_pred) = goal.goal().predicate.to_opt_poly_trait_pred() else {
391-
return ControlFlow::Break(self.obligation.clone());
390+
let pred_kind = goal.goal().predicate.kind();
391+
let child_mode = match pred_kind.skip_binder() {
392+
ty::PredicateKind::Clause(ty::ClauseKind::Trait(parent_trait_pred)) => {
393+
ChildMode::Trait(pred_kind.rebind(parent_trait_pred))
394+
}
395+
ty::PredicateKind::NormalizesTo(normalizes_to)
396+
if matches!(
397+
normalizes_to.alias.kind(tcx),
398+
ty::AliasTermKind::ProjectionTy | ty::AliasTermKind::ProjectionConst
399+
) =>
400+
{
401+
ChildMode::Trait(pred_kind.rebind(ty::TraitPredicate {
402+
trait_ref: normalizes_to.alias.trait_ref(tcx),
403+
polarity: ty::PredicatePolarity::Positive,
404+
}))
405+
}
406+
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => {
407+
ChildMode::WellFormedObligation
408+
}
409+
_ => {
410+
return ControlFlow::Break(self.obligation.clone());
411+
}
392412
};
393413

394-
let tcx = goal.infcx().tcx;
395414
let mut impl_where_bound_count = 0;
396415
for nested_goal in candidate.instantiate_nested_goals(self.span()) {
416+
let make_obligation = |cause| Obligation {
417+
cause,
418+
param_env: nested_goal.goal().param_env,
419+
predicate: nested_goal.goal().predicate,
420+
recursion_depth: self.obligation.recursion_depth + 1,
421+
};
422+
397423
let obligation;
398-
match nested_goal.source() {
399-
GoalSource::Misc => {
424+
match (child_mode, nested_goal.source()) {
425+
(ChildMode::Trait(_), GoalSource::Misc) => {
400426
continue;
401427
}
402-
GoalSource::ImplWhereBound => {
403-
obligation = Obligation {
404-
cause: derive_cause(
405-
tcx,
406-
candidate.kind(),
407-
self.obligation.cause.clone(),
408-
impl_where_bound_count,
409-
parent_trait_pred,
410-
),
411-
param_env: nested_goal.goal().param_env,
412-
predicate: nested_goal.goal().predicate,
413-
recursion_depth: self.obligation.recursion_depth + 1,
414-
};
428+
(ChildMode::Trait(parent_trait_pred), GoalSource::ImplWhereBound) => {
429+
obligation = make_obligation(derive_cause(
430+
tcx,
431+
candidate.kind(),
432+
self.obligation.cause.clone(),
433+
impl_where_bound_count,
434+
parent_trait_pred,
435+
));
415436
impl_where_bound_count += 1;
416437
}
417-
GoalSource::InstantiateHigherRanked => {
438+
// Skip over a higher-ranked predicate.
439+
(_, GoalSource::InstantiateHigherRanked) => {
418440
obligation = self.obligation.clone();
419441
}
442+
(ChildMode::WellFormedObligation, _) => {
443+
obligation = make_obligation(self.obligation.cause.clone());
444+
}
420445
}
421446

422447
// Skip nested goals that aren't the *reason* for our goal's failure.
@@ -436,6 +461,18 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
436461
}
437462
}
438463

464+
#[derive(Copy, Clone)]
465+
enum ChildMode<'tcx> {
466+
// Try to derive an `ObligationCause::{ImplDerived,BuiltinDerived}`,
467+
// and skip all `GoalSource::Misc`, which represent useless obligations
468+
// such as alias-eq which may not hold.
469+
Trait(ty::PolyTraitPredicate<'tcx>),
470+
// Skip trying to derive an `ObligationCause` from this obligation, and
471+
// report *all* sub-obligations as if they came directly from the parent
472+
// obligation.
473+
WellFormedObligation,
474+
}
475+
439476
fn derive_cause<'tcx>(
440477
tcx: TyCtxt<'tcx>,
441478
candidate_kind: ProbeKind<'tcx>,

library/core/src/ptr/mut_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl<T: ?Sized> *mut T {
187187
///
188188
/// This is similar to `self as usize`, which semantically discards *provenance* and
189189
/// *address-space* information. However, unlike `self as usize`, casting the returned address
190-
/// back to a pointer yields yields a [pointer without provenance][without_provenance_mut], which is undefined
190+
/// back to a pointer yields a [pointer without provenance][without_provenance_mut], which is undefined
191191
/// behavior to dereference. To properly restore the lost information and obtain a
192192
/// dereferenceable pointer, use [`with_addr`][pointer::with_addr] or
193193
/// [`map_addr`][pointer::map_addr].

library/core/src/slice/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -4533,21 +4533,21 @@ impl<T, const N: usize> [[T; N]] {
45334533
/// ```
45344534
/// #![feature(slice_flatten)]
45354535
///
4536-
/// assert_eq!([[1, 2, 3], [4, 5, 6]].flatten(), &[1, 2, 3, 4, 5, 6]);
4536+
/// assert_eq!([[1, 2, 3], [4, 5, 6]].as_flattened(), &[1, 2, 3, 4, 5, 6]);
45374537
///
45384538
/// assert_eq!(
4539-
/// [[1, 2, 3], [4, 5, 6]].flatten(),
4540-
/// [[1, 2], [3, 4], [5, 6]].flatten(),
4539+
/// [[1, 2, 3], [4, 5, 6]].as_flattened(),
4540+
/// [[1, 2], [3, 4], [5, 6]].as_flattened(),
45414541
/// );
45424542
///
45434543
/// let slice_of_empty_arrays: &[[i32; 0]] = &[[], [], [], [], []];
4544-
/// assert!(slice_of_empty_arrays.flatten().is_empty());
4544+
/// assert!(slice_of_empty_arrays.as_flattened().is_empty());
45454545
///
45464546
/// let empty_slice_of_arrays: &[[u32; 10]] = &[];
4547-
/// assert!(empty_slice_of_arrays.flatten().is_empty());
4547+
/// assert!(empty_slice_of_arrays.as_flattened().is_empty());
45484548
/// ```
45494549
#[unstable(feature = "slice_flatten", issue = "95629")]
4550-
pub const fn flatten(&self) -> &[T] {
4550+
pub const fn as_flattened(&self) -> &[T] {
45514551
let len = if T::IS_ZST {
45524552
self.len().checked_mul(N).expect("slice len overflow")
45534553
} else {
@@ -4581,11 +4581,11 @@ impl<T, const N: usize> [[T; N]] {
45814581
/// }
45824582
///
45834583
/// let mut array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
4584-
/// add_5_to_all(array.flatten_mut());
4584+
/// add_5_to_all(array.as_flattened_mut());
45854585
/// assert_eq!(array, [[6, 7, 8], [9, 10, 11], [12, 13, 14]]);
45864586
/// ```
45874587
#[unstable(feature = "slice_flatten", issue = "95629")]
4588-
pub fn flatten_mut(&mut self) -> &mut [T] {
4588+
pub fn as_flattened_mut(&mut self) -> &mut [T] {
45894589
let len = if T::IS_ZST {
45904590
self.len().checked_mul(N).expect("slice len overflow")
45914591
} else {

library/core/tests/slice.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2609,14 +2609,14 @@ fn test_slice_from_ptr_range() {
26092609
#[should_panic = "slice len overflow"]
26102610
fn test_flatten_size_overflow() {
26112611
let x = &[[(); usize::MAX]; 2][..];
2612-
let _ = x.flatten();
2612+
let _ = x.as_flattened();
26132613
}
26142614

26152615
#[test]
26162616
#[should_panic = "slice len overflow"]
26172617
fn test_flatten_mut_size_overflow() {
26182618
let x = &mut [[(); usize::MAX]; 2][..];
2619-
let _ = x.flatten_mut();
2619+
let _ = x.as_flattened_mut();
26202620
}
26212621

26222622
#[test]

src/bootstrap/src/core/config/config.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,9 @@ impl Config {
13071307
toml_path = config.src.join(toml_path);
13081308
}
13091309

1310+
let file_content = t!(fs::read_to_string(config.src.join("src/ci/channel")));
1311+
let ci_channel = file_content.trim_end();
1312+
13101313
// Give a hard error if `--config` or `RUST_BOOTSTRAP_CONFIG` are set to a missing path,
13111314
// but not if `config.toml` hasn't been created.
13121315
let mut toml = if !using_default_path || toml_path.exists() {
@@ -1534,6 +1537,7 @@ impl Config {
15341537
let mut omit_git_hash = None;
15351538
let mut lld_enabled = None;
15361539

1540+
let mut is_user_configured_rust_channel = false;
15371541
if let Some(rust) = toml.rust {
15381542
let Rust {
15391543
optimize: optimize_toml,
@@ -1591,15 +1595,14 @@ impl Config {
15911595
lld_mode,
15921596
} = rust;
15931597

1598+
is_user_configured_rust_channel = channel.is_some();
15941599
set(&mut config.channel, channel);
15951600

15961601
config.download_rustc_commit = config.download_ci_rustc_commit(download_rustc);
15971602
// This list is incomplete, please help by expanding it!
15981603
if config.download_rustc_commit.is_some() {
15991604
// We need the channel used by the downloaded compiler to match the one we set for rustdoc;
16001605
// otherwise rustdoc-ui tests break.
1601-
let ci_channel = t!(fs::read_to_string(config.src.join("src/ci/channel")));
1602-
let ci_channel = ci_channel.trim_end();
16031606
if config.channel != ci_channel
16041607
&& !(config.channel == "dev" && ci_channel == "nightly")
16051608
{
@@ -1717,6 +1720,10 @@ impl Config {
17171720
config.omit_git_hash = omit_git_hash.unwrap_or(default);
17181721
config.rust_info = GitInfo::new(config.omit_git_hash, &config.src);
17191722

1723+
if config.rust_info.is_from_tarball() && !is_user_configured_rust_channel {
1724+
ci_channel.clone_into(&mut config.channel);
1725+
}
1726+
17201727
if let Some(llvm) = toml.llvm {
17211728
let Llvm {
17221729
optimize: optimize_toml,
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
error: the type `Foo::Bar<Vec<[u32]>>` is not well-formed
2-
--> $DIR/wf-check-skipped.rs:17:14
1+
error[E0277]: the size for values of type `[u32]` cannot be known at compilation time
2+
--> $DIR/wf-check-skipped.rs:17:25
33
|
44
LL | fn main() -> Foo::Bar::<Vec<[u32]>> {}
5-
| ^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^ doesn't have a size known at compile-time
6+
|
7+
= help: the trait `Sized` is not implemented for `[u32]`
68

79
error: aborting due to 1 previous error
810

11+
For more information about this error, try `rustc --explain E0277`.

tests/ui/associated-inherent-types/bugs/wf-check-skipped.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ impl Foo {
1515
}
1616

1717
fn main() -> Foo::Bar::<Vec<[u32]>> {}
18-
//[next]~^ ERROR the type `Foo::Bar<Vec<[u32]>>` is not well-formed
18+
//[next]~^ ERROR the size for values of type `[u32]` cannot be known at compilation time
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
const X: i32 = #[allow(dead_code)] 8;
22
//~^ ERROR attributes on expressions are experimental
33

4+
const Y: i32 =
5+
/// foo
6+
//~^ ERROR attributes on expressions are experimental
7+
8;
8+
9+
const Z: i32 = {
10+
//! foo
11+
//~^ ERROR attributes on expressions are experimental
12+
8
13+
};
14+
415
fn main() {}

tests/ui/feature-gates/feature-gate-stmt_expr_attributes.stderr

+23-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,28 @@ LL | const X: i32 = #[allow(dead_code)] 8;
88
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
99
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1010

11-
error: aborting due to 1 previous error
11+
error[E0658]: attributes on expressions are experimental
12+
--> $DIR/feature-gate-stmt_expr_attributes.rs:5:5
13+
|
14+
LL | /// foo
15+
| ^^^^^^^
16+
|
17+
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
18+
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
19+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
20+
= help: `///` is used for outer documentation comments; for a plain comment, use `//`
21+
22+
error[E0658]: attributes on expressions are experimental
23+
--> $DIR/feature-gate-stmt_expr_attributes.rs:10:5
24+
|
25+
LL | //! foo
26+
| ^^^^^^^
27+
|
28+
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
29+
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
30+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
31+
= help: `//!` is used for inner documentation comments; for a plain comment, use `//` by removing the `!` or inserting a space in between them: `// !`
32+
33+
error: aborting due to 3 previous errors
1234

1335
For more information about this error, try `rustc --explain E0658`.

tests/ui/for/issue-20605.next.stderr

+1-19
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,13 @@ help: consider mutably borrowing here
1111
LL | for item in &mut *things { *item = 0 }
1212
| ++++
1313

14-
error: the type `<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter` is not well-formed
15-
--> $DIR/issue-20605.rs:6:17
16-
|
17-
LL | for item in *things { *item = 0 }
18-
| ^^^^^^^
19-
20-
error: the type `&mut <dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter` is not well-formed
21-
--> $DIR/issue-20605.rs:6:17
22-
|
23-
LL | for item in *things { *item = 0 }
24-
| ^^^^^^^
25-
26-
error: the type `Option<<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item>` is not well-formed
27-
--> $DIR/issue-20605.rs:6:17
28-
|
29-
LL | for item in *things { *item = 0 }
30-
| ^^^^^^^
31-
3214
error[E0614]: type `<dyn Iterator<Item = &'a mut u8> as IntoIterator>::Item` cannot be dereferenced
3315
--> $DIR/issue-20605.rs:6:27
3416
|
3517
LL | for item in *things { *item = 0 }
3618
| ^^^^^
3719

38-
error: aborting due to 5 previous errors
20+
error: aborting due to 2 previous errors
3921

4022
Some errors have detailed explanations: E0277, E0614.
4123
For more information about an error, try `rustc --explain E0277`.

tests/ui/for/issue-20605.rs

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ fn changer<'a>(mut things: Box<dyn Iterator<Item=&'a mut u8>>) {
66
for item in *things { *item = 0 }
77
//[current]~^ ERROR `dyn Iterator<Item = &'a mut u8>` is not an iterator
88
//[next]~^^ ERROR `dyn Iterator<Item = &'a mut u8>` is not an iterator
9-
//[next]~| ERROR the type `<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter` is not well-formed
10-
//[next]~| ERROR the type `&mut <dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter` is not well-formed
11-
//[next]~| ERROR the type `Option<<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item>` is not well-formed
129
//[next]~| ERROR type `<dyn Iterator<Item = &'a mut u8> as IntoIterator>::Item` cannot be dereferenced
1310

1411
// FIXME(-Znext-solver): these error messages are horrible and have to be

tests/ui/impl-trait/in-trait/alias-bounds-when-not-wf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ struct W<T>(T);
1414
// `usize: Foo` doesn't hold. Therefore we ICE, because we don't expect to still
1515
// encounter weak types in `assemble_alias_bound_candidates_recur`.
1616
fn hello(_: W<A<usize>>) {}
17-
//~^ ERROR the type `W<A<usize>>` is not well-formed
17+
//~^ ERROR the size for values of type `A<usize>` cannot be known at compilation time
1818

1919
fn main() {}

tests/ui/impl-trait/in-trait/alias-bounds-when-not-wf.stderr

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ LL | #![feature(lazy_type_alias)]
77
= note: see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information
88
= note: `#[warn(incomplete_features)]` on by default
99

10-
error: the type `W<A<usize>>` is not well-formed
10+
error[E0277]: the size for values of type `A<usize>` cannot be known at compilation time
1111
--> $DIR/alias-bounds-when-not-wf.rs:16:13
1212
|
1313
LL | fn hello(_: W<A<usize>>) {}
14-
| ^^^^^^^^^^^
14+
| ^^^^^^^^^^^ doesn't have a size known at compile-time
15+
|
16+
= help: the trait `Sized` is not implemented for `A<usize>`
1517

1618
error: aborting due to 1 previous error; 1 warning emitted
1719

20+
For more information about this error, try `rustc --explain E0277`.

tests/ui/lint/unused/unused-doc-comments-edge-cases.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | (/// useless doc comment
1313
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
1414
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
1515
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
16-
= help: `///` is for documentation comments. For a plain comment, use `//`.
16+
= help: `///` is used for outer documentation comments; for a plain comment, use `//`
1717

1818
error: unused doc comment
1919
--> $DIR/unused-doc-comments-edge-cases.rs:6:9

0 commit comments

Comments
 (0)