Skip to content

Commit ae1c8ea

Browse files
borscompiler-errors
authored andcommitted
Auto merge of #131859 - chriskrycho:update-trpl, r=onur-ozkan
Update TRPL to add new Chapter 17: Async and Await - Add support to `rustbook` to pass through the `-L`/`--library-path` flag to `mdbook` so that references to the `trpl` crate - Build the `trpl` crate as part of the book tests. Make it straightforward to add other such book dependencies in the future if needed by implementing that in a fairly general way. - Update the submodule for the book to pull in the new chapter on async and await, as well as a number of other fixes. This will happen organically/automatically in a week, too, but this lets me group this change with the next one: - Update the compiler messages which reference the existing chapters 17–20, which are now chapters 18-21. There are only two, both previously referencing chapter 18. - Update the UI tests which reference the compiler message outputs.
2 parents 15b663e + 7630b49 commit ae1c8ea

File tree

82 files changed

+297
-219
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+297
-219
lines changed

compiler/rustc_hir_typeck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ fn report_unexpected_variant_res(
364364
.with_code(err_code);
365365
match res {
366366
Res::Def(DefKind::Fn | DefKind::AssocFn, _) if err_code == E0164 => {
367-
let patterns_url = "https://doc.rust-lang.org/book/ch18-00-patterns.html";
367+
let patterns_url = "https://doc.rust-lang.org/book/ch19-00-patterns.html";
368368
err.with_span_label(span, "`fn` calls are not allowed in patterns")
369369
.with_help(format!("for more information, visit {patterns_url}"))
370370
}

compiler/rustc_middle/src/ty/consts.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,6 @@ impl<'tcx> Const<'tcx> {
151151
}
152152

153153
impl<'tcx> rustc_type_ir::inherent::Const<TyCtxt<'tcx>> for Const<'tcx> {
154-
fn try_to_target_usize(self, interner: TyCtxt<'tcx>) -> Option<u64> {
155-
self.try_to_target_usize(interner)
156-
}
157-
158154
fn new_infer(tcx: TyCtxt<'tcx>, infer: ty::InferConst) -> Self {
159155
Const::new_infer(tcx, infer)
160156
}

compiler/rustc_middle/src/ty/error.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,9 @@ impl<'tcx> TypeError<'tcx> {
5858
pluralize!(values.found)
5959
)
6060
.into(),
61-
TypeError::FixedArraySize(values) => format!(
62-
"expected an array with a fixed size of {} element{}, found one with {} element{}",
63-
values.expected,
64-
pluralize!(values.expected),
65-
values.found,
66-
pluralize!(values.found)
61+
TypeError::ArraySize(values) => format!(
62+
"expected an array with a size of {}, found one with a size of {}",
63+
values.expected, values.found,
6764
)
6865
.into(),
6966
TypeError::ArgCount => "incorrect number of function parameters".into(),

compiler/rustc_mir_build/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ mir_build_lower_range_bound_must_be_less_than_or_equal_to_upper =
213213
214214
mir_build_lower_range_bound_must_be_less_than_upper = lower range bound must be less than upper
215215
216-
mir_build_more_information = for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
216+
mir_build_more_information = for more information, visit https://doc.rust-lang.org/book/ch19-02-refutability.html
217217
218218
mir_build_moved = value is moved into `{$name}` here
219219

compiler/rustc_parse/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ parse_unexpected_expr_in_pat =
827827
}, found an expression
828828
829829
.label = not a pattern
830-
.note = arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>
830+
.note = arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch19-00-patterns.html>
831831
832832
parse_unexpected_expr_in_pat_const_sugg = consider extracting the expression into a `const`
833833

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
12061206
let PathSource::TupleStruct(_, _) = source else { return };
12071207
let Some(Res::Def(DefKind::Fn, _)) = res else { return };
12081208
err.primary_message("expected a pattern, found a function call");
1209-
err.note("function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html>");
1209+
err.note("function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch19-00-patterns.html>");
12101210
}
12111211

12121212
fn suggest_changing_type_to_const_param(

compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,12 +1792,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
17921792

17931793
fn suggest_specify_actual_length(
17941794
&self,
1795-
terr: TypeError<'_>,
1796-
trace: &TypeTrace<'_>,
1795+
terr: TypeError<'tcx>,
1796+
trace: &TypeTrace<'tcx>,
17971797
span: Span,
17981798
) -> Option<TypeErrorAdditionalDiags> {
17991799
let hir = self.tcx.hir();
1800-
let TypeError::FixedArraySize(sz) = terr else {
1800+
let TypeError::ArraySize(sz) = terr else {
18011801
return None;
18021802
};
18031803
let tykind = match self.tcx.hir_node_by_def_id(trace.cause.body_id) {
@@ -1838,9 +1838,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
18381838
if let Some(tykind) = tykind
18391839
&& let hir::TyKind::Array(_, length) = tykind
18401840
&& let hir::ArrayLen::Body(ct) = length
1841+
&& let Some((scalar, ty)) = sz.found.try_to_scalar()
1842+
&& ty == self.tcx.types.usize
18411843
{
18421844
let span = ct.span();
1843-
Some(TypeErrorAdditionalDiags::ConsiderSpecifyingLength { span, length: sz.found })
1845+
Some(TypeErrorAdditionalDiags::ConsiderSpecifyingLength {
1846+
span,
1847+
length: scalar.to_target_usize(&self.tcx).unwrap(),
1848+
})
18441849
} else {
18451850
None
18461851
}

compiler/rustc_type_ir/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub enum TypeError<I: Interner> {
2929
Mutability,
3030
ArgumentMutability(usize),
3131
TupleSize(ExpectedFound<usize>),
32-
FixedArraySize(ExpectedFound<u64>),
32+
ArraySize(ExpectedFound<I::Const>),
3333
ArgCount,
3434

3535
RegionsDoesNotOutlive(I::Region, I::Region),
@@ -69,7 +69,7 @@ impl<I: Interner> TypeError<I> {
6969
use self::TypeError::*;
7070
match self {
7171
CyclicTy(_) | CyclicConst(_) | SafetyMismatch(_) | PolarityMismatch(_) | Mismatch
72-
| AbiMismatch(_) | FixedArraySize(_) | ArgumentSorts(..) | Sorts(_)
72+
| AbiMismatch(_) | ArraySize(_) | ArgumentSorts(..) | Sorts(_)
7373
| VariadicMismatch(_) | TargetFeatureCast(_) => false,
7474

7575
Mutability

compiler/rustc_type_ir/src/inherent.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,6 @@ pub trait Const<I: Interner<Const = Self>>:
257257
+ Relate<I>
258258
+ Flags
259259
{
260-
fn try_to_target_usize(self, interner: I) -> Option<u64>;
261-
262260
fn new_infer(interner: I, var: ty::InferConst) -> Self;
263261

264262
fn new_var(interner: I, var: ty::ConstVid) -> Self;

compiler/rustc_type_ir/src/relate.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -501,19 +501,10 @@ pub fn structurally_relate_tys<I: Interner, R: TypeRelation<I>>(
501501
let t = relation.relate(a_t, b_t)?;
502502
match relation.relate(sz_a, sz_b) {
503503
Ok(sz) => Ok(Ty::new_array_with_const_len(cx, t, sz)),
504-
Err(err) => {
505-
// Check whether the lengths are both concrete/known values,
506-
// but are unequal, for better diagnostics.
507-
let sz_a = sz_a.try_to_target_usize(cx);
508-
let sz_b = sz_b.try_to_target_usize(cx);
509-
510-
match (sz_a, sz_b) {
511-
(Some(sz_a_val), Some(sz_b_val)) if sz_a_val != sz_b_val => {
512-
Err(TypeError::FixedArraySize(ExpectedFound::new(sz_a_val, sz_b_val)))
513-
}
514-
_ => Err(err),
515-
}
504+
Err(TypeError::ConstMismatch(_)) => {
505+
Err(TypeError::ArraySize(ExpectedFound::new(sz_a, sz_b)))
516506
}
507+
Err(e) => Err(e),
517508
}
518509
}
519510

0 commit comments

Comments
 (0)