Skip to content

Commit 24c0b81

Browse files
committed
Auto merge of rust-lang#109043 - matthiaskrgr:rollup-genkz0e, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#108726 (tidy: enforce comment blocks to have an even number of backticks) - rust-lang#108797 (Allow binary files to go through the `FileLoader`) - rust-lang#108841 (Add suggestion to diagnostic when user has array but trait wants slice. (rebased)) - rust-lang#108984 (bootstrap: document tidy) - rust-lang#109013 (Give proper error message when tcx wasn't passed to decoder) - rust-lang#109017 (remove duplicated calls to sort_string) - rust-lang#109018 (Expand on the allocator comment in `rustc-main`) - rust-lang#109028 (Add eslint checks for rustdoc-js tester) - rust-lang#109034 (Commit some tests for the new solver + lazy norm) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 150cb38 + 3166b4a commit 24c0b81

File tree

39 files changed

+914
-87
lines changed

39 files changed

+914
-87
lines changed

compiler/rustc/src/main.rs

+9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
// The two crates we link to here, `std` and `rustc_driver`, are both dynamic
2525
// libraries. So we must reference jemalloc symbols one way or another, because
2626
// this file is the only object code in the rustc executable.
27+
//
28+
// NOTE: if you are reading this comment because you want to set a custom `global_allocator` for
29+
// benchmarking, consider using the benchmarks in the `rustc-perf` collector suite instead:
30+
// https://github.com/rust-lang/rustc-perf/blob/master/collector/README.md#profiling
31+
//
32+
// NOTE: if you are reading this comment because you want to replace jemalloc with another allocator
33+
// to compare their performance, see
34+
// https://github.com/rust-lang/rust/commit/b90cfc887c31c3e7a9e6d462e2464db1fe506175#diff-43914724af6e464c1da2171e4a9b6c7e607d5bc1203fa95c0ab85be4122605ef
35+
// for an example of how to do so.
2736

2837
#[unix_sigpipe = "sig_dfl"]
2938
fn main() {

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,7 @@ impl<'a> MethodDef<'a> {
10521052
/// ::core::hash::Hash::hash(&{ self.y }, state)
10531053
/// }
10541054
/// }
1055+
/// ```
10551056
fn expand_struct_method_body<'b>(
10561057
&self,
10571058
cx: &mut ExtCtxt<'_>,

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs

+1
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ fn build_enum_variant_member_di_node<'ll, 'tcx>(
438438
/// DW_TAG_structure_type (type of variant 1)
439439
/// DW_TAG_structure_type (type of variant 2)
440440
/// DW_TAG_structure_type (type of variant 3)
441+
/// ```
441442
struct VariantMemberInfo<'a, 'll> {
442443
variant_index: VariantIdx,
443444
variant_name: Cow<'a, str>,

compiler/rustc_error_codes/src/error_codes/E0368.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Add for Foo {
4141
4242
fn main() {
4343
let mut x: Foo = Foo(5);
44-
x += Foo(7); // error, `+= cannot be applied to the type `Foo`
44+
x += Foo(7); // error, `+=` cannot be applied to the type `Foo`
4545
}
4646
```
4747

compiler/rustc_error_codes/src/error_codes/E0710.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ An unknown tool name was found in a scoped lint.
33
Erroneous code examples:
44

55
```compile_fail,E0710
6-
#[allow(clipp::filter_map)] // error!`
6+
#[allow(clipp::filter_map)] // error!
77
fn main() {
88
// business logic
99
}
1010
```
1111

1212
```compile_fail,E0710
13-
#[warn(clipp::filter_map)] // error!`
13+
#[warn(clipp::filter_map)] // error!
1414
fn main() {
1515
// business logic
1616
}

compiler/rustc_hir_typeck/src/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
398398
///
399399
/// Here:
400400
/// - E would be `fn(&u32) -> &u32`.
401-
/// - S would be `fn(&u32) ->
401+
/// - S would be `fn(&u32) -> ?T`
402402
/// - E' is `&'!0 u32 -> &'!0 u32`
403403
/// - S' is `&'?0 u32 -> ?T`
404404
///

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
104104
let (mention_influencer, influencer_point) =
105105
if sup_origin.span().overlaps(param.param_ty_span) {
106106
// Account for `async fn` like in `async-await/issues/issue-62097.rs`.
107-
// The desugaring of `async `fn`s causes `sup_origin` and `param` to point at the same
107+
// The desugaring of `async fn`s causes `sup_origin` and `param` to point at the same
108108
// place (but with different `ctxt`, hence `overlaps` instead of `==` above).
109109
//
110110
// This avoids the following:

compiler/rustc_metadata/src/rmeta/decoder.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,11 @@ impl<T: ParameterizedOverTcx> LazyArray<T> {
311311
impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
312312
#[inline]
313313
fn tcx(&self) -> TyCtxt<'tcx> {
314-
debug_assert!(self.tcx.is_some(), "missing TyCtxt in DecodeContext");
315-
self.tcx.unwrap()
314+
let Some(tcx) = self.tcx else {
315+
bug!("No TyCtxt found for decoding. \
316+
You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`.");
317+
};
318+
tcx
316319
}
317320

318321
#[inline]
@@ -454,7 +457,12 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ast::AttrId {
454457
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for SyntaxContext {
455458
fn decode(decoder: &mut DecodeContext<'a, 'tcx>) -> SyntaxContext {
456459
let cdata = decoder.cdata();
457-
let sess = decoder.sess.unwrap();
460+
461+
let Some(sess) = decoder.sess else {
462+
bug!("Cannot decode SyntaxContext without Session.\
463+
You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`.");
464+
};
465+
458466
let cname = cdata.root.name;
459467
rustc_span::hygiene::decode_syntax_context(decoder, &cdata.hygiene_context, |_, id| {
460468
debug!("SpecializedDecoder<SyntaxContext>: decoding {}", id);
@@ -471,7 +479,11 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for SyntaxContext {
471479
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for ExpnId {
472480
fn decode(decoder: &mut DecodeContext<'a, 'tcx>) -> ExpnId {
473481
let local_cdata = decoder.cdata();
474-
let sess = decoder.sess.unwrap();
482+
483+
let Some(sess) = decoder.sess else {
484+
bug!("Cannot decode ExpnId without Session. \
485+
You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`.");
486+
};
475487

476488
let cnum = CrateNum::decode(decoder);
477489
let index = u32::decode(decoder);
@@ -520,7 +532,8 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for Span {
520532
let hi = lo + len;
521533

522534
let Some(sess) = decoder.sess else {
523-
bug!("Cannot decode Span without Session.")
535+
bug!("Cannot decode Span without Session. \
536+
You need to explicitly pass `(crate_metadata_ref, tcx)` to `decode` instead of just `crate_metadata_ref`.")
524537
};
525538

526539
// Index of the file in the corresponding crate's list of encoded files.

compiler/rustc_middle/src/mir/pretty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ fn dump_matched_mir_node<'tcx, F>(
123123
// see notes on #41697 above
124124
let def_path =
125125
ty::print::with_forced_impl_filename_line!(tcx.def_path_str(body.source.def_id()));
126+
// ignore-tidy-odd-backticks the literal below is fine
126127
write!(file, "// MIR for `{}", def_path)?;
127128
match body.source.promoted {
128129
None => write!(file, "`")?,

compiler/rustc_middle/src/ty/error.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,8 @@ impl<'tcx> TypeError<'tcx> {
151151
.into(),
152152
RegionsPlaceholderMismatch => "one type is more general than the other".into(),
153153
ArgumentSorts(values, _) | Sorts(values) => {
154-
let mut expected = values.expected.sort_string(tcx);
155-
let mut found = values.found.sort_string(tcx);
156-
if expected == found {
157-
expected = values.expected.sort_string(tcx);
158-
found = values.found.sort_string(tcx);
159-
}
154+
let expected = values.expected.sort_string(tcx);
155+
let found = values.found.sort_string(tcx);
160156
report_maybe_different(&expected, &found).into()
161157
}
162158
Traits(values) => {

compiler/rustc_mir_build/src/build/matches/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1886,6 +1886,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
18861886
// let place = Foo::new();
18871887
// match place { Foo { .. } if { let tmp1 = &place; inspect(*tmp1) }
18881888
// => { let tmp2 = place; feed(tmp2) }, ... }
1889+
// ```
18891890
//
18901891
// And an input like:
18911892
//

compiler/rustc_span/src/source_map.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ pub trait FileLoader {
100100

101101
/// Read the contents of a UTF-8 file into memory.
102102
fn read_file(&self, path: &Path) -> io::Result<String>;
103+
104+
/// Read the contents of a potentially non-UTF-8 file into memory.
105+
fn read_binary_file(&self, path: &Path) -> io::Result<Vec<u8>>;
103106
}
104107

105108
/// A FileLoader that uses std::fs to load real files.
@@ -113,6 +116,10 @@ impl FileLoader for RealFileLoader {
113116
fn read_file(&self, path: &Path) -> io::Result<String> {
114117
fs::read_to_string(path)
115118
}
119+
120+
fn read_binary_file(&self, path: &Path) -> io::Result<Vec<u8>> {
121+
fs::read(path)
122+
}
116123
}
117124

118125
/// This is a [SourceFile] identifier that is used to correlate source files between
@@ -220,9 +227,7 @@ impl SourceMap {
220227
/// Unlike `load_file`, guarantees that no normalization like BOM-removal
221228
/// takes place.
222229
pub fn load_binary_file(&self, path: &Path) -> io::Result<Vec<u8>> {
223-
// Ideally, this should use `self.file_loader`, but it can't
224-
// deal with binary files yet.
225-
let bytes = fs::read(path)?;
230+
let bytes = self.file_loader.read_binary_file(path)?;
226231

227232
// We need to add file to the `SourceMap`, so that it is present
228233
// in dep-info. There's also an edge case that file might be both

compiler/rustc_trait_selection/src/solve/assembly.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
248248
///
249249
/// To deal with this, we first try to normalize the self type and add the candidates for the normalized
250250
/// self type to the list of candidates in case that succeeds. Note that we can't just eagerly return in
251-
/// this case as projections as self types add `
251+
/// this case as projections as self types add
252+
// FIXME complete the unfinished sentence above
252253
fn assemble_candidates_after_normalizing_self_ty<G: GoalKind<'tcx>>(
253254
&mut self,
254255
goal: Goal<'tcx, G>,

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

+14-6
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
10241024
// Can't show anything else useful, try to find similar impls.
10251025
let impl_candidates = self.find_similar_impl_candidates(trait_predicate);
10261026
if !self.report_similar_impl_candidates(
1027-
impl_candidates,
1027+
&impl_candidates,
10281028
trait_ref,
10291029
body_def_id,
10301030
&mut err,
@@ -1060,14 +1060,21 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
10601060
let impl_candidates =
10611061
self.find_similar_impl_candidates(trait_pred);
10621062
self.report_similar_impl_candidates(
1063-
impl_candidates,
1063+
&impl_candidates,
10641064
trait_ref,
10651065
body_def_id,
10661066
&mut err,
10671067
true,
10681068
);
10691069
}
10701070
}
1071+
1072+
self.maybe_suggest_convert_to_slice(
1073+
&mut err,
1074+
trait_ref,
1075+
impl_candidates.as_slice(),
1076+
span,
1077+
);
10711078
}
10721079

10731080
// Changing mutability doesn't make a difference to whether we have
@@ -1514,7 +1521,7 @@ trait InferCtxtPrivExt<'tcx> {
15141521

15151522
fn report_similar_impl_candidates(
15161523
&self,
1517-
impl_candidates: Vec<ImplCandidate<'tcx>>,
1524+
impl_candidates: &[ImplCandidate<'tcx>],
15181525
trait_ref: ty::PolyTraitRef<'tcx>,
15191526
body_def_id: LocalDefId,
15201527
err: &mut Diagnostic,
@@ -2004,7 +2011,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
20042011

20052012
fn report_similar_impl_candidates(
20062013
&self,
2007-
impl_candidates: Vec<ImplCandidate<'tcx>>,
2014+
impl_candidates: &[ImplCandidate<'tcx>],
20082015
trait_ref: ty::PolyTraitRef<'tcx>,
20092016
body_def_id: LocalDefId,
20102017
err: &mut Diagnostic,
@@ -2113,7 +2120,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
21132120
// Prefer more similar candidates first, then sort lexicographically
21142121
// by their normalized string representation.
21152122
let mut normalized_impl_candidates_and_similarities = impl_candidates
2116-
.into_iter()
2123+
.iter()
2124+
.copied()
21172125
.map(|ImplCandidate { trait_ref, similarity }| {
21182126
// FIXME(compiler-errors): This should be using `NormalizeExt::normalize`
21192127
let normalized = self
@@ -2326,7 +2334,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
23262334
);
23272335
if impl_candidates.len() < 10 {
23282336
self.report_similar_impl_candidates(
2329-
impl_candidates,
2337+
impl_candidates.as_slice(),
23302338
trait_ref,
23312339
obligation.cause.body_id,
23322340
&mut err,

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+77-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ignore-tidy-filelength
22

33
use super::{
4-
DefIdOrName, FindExprBySpan, Obligation, ObligationCause, ObligationCauseCode,
4+
DefIdOrName, FindExprBySpan, ImplCandidate, Obligation, ObligationCause, ObligationCauseCode,
55
PredicateObligation,
66
};
77

@@ -382,6 +382,14 @@ pub trait TypeErrCtxtExt<'tcx> {
382382
body_id: hir::HirId,
383383
param_env: ty::ParamEnv<'tcx>,
384384
) -> Vec<Option<(Span, (DefId, Ty<'tcx>))>>;
385+
386+
fn maybe_suggest_convert_to_slice(
387+
&self,
388+
err: &mut Diagnostic,
389+
trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
390+
candidate_impls: &[ImplCandidate<'tcx>],
391+
span: Span,
392+
);
385393
}
386394

387395
fn predicate_constraint(generics: &hir::Generics<'_>, pred: ty::Predicate<'_>) -> (Span, String) {
@@ -2220,7 +2228,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
22202228
// - `BuiltinDerivedObligation` with a generator witness (A)
22212229
// - `BuiltinDerivedObligation` with a generator (A)
22222230
// - `BuiltinDerivedObligation` with `impl std::future::Future` (A)
2223-
// - `BindingObligation` with `impl_send (Send requirement)
2231+
// - `BindingObligation` with `impl_send` (Send requirement)
22242232
//
22252233
// The first obligation in the chain is the most useful and has the generator that captured
22262234
// the type. The last generator (`outer_generator` below) has information about where the
@@ -3826,6 +3834,73 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
38263834
}
38273835
assocs_in_this_method
38283836
}
3837+
3838+
/// If the type that failed selection is an array or a reference to an array,
3839+
/// but the trait is implemented for slices, suggest that the user converts
3840+
/// the array into a slice.
3841+
fn maybe_suggest_convert_to_slice(
3842+
&self,
3843+
err: &mut Diagnostic,
3844+
trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
3845+
candidate_impls: &[ImplCandidate<'tcx>],
3846+
span: Span,
3847+
) {
3848+
// Three cases where we can make a suggestion:
3849+
// 1. `[T; _]` (array of T)
3850+
// 2. `&[T; _]` (reference to array of T)
3851+
// 3. `&mut [T; _]` (mutable reference to array of T)
3852+
let (element_ty, mut mutability) = match *trait_ref.skip_binder().self_ty().kind() {
3853+
ty::Array(element_ty, _) => (element_ty, None),
3854+
3855+
ty::Ref(_, pointee_ty, mutability) => match *pointee_ty.kind() {
3856+
ty::Array(element_ty, _) => (element_ty, Some(mutability)),
3857+
_ => return,
3858+
},
3859+
3860+
_ => return,
3861+
};
3862+
3863+
// Go through all the candidate impls to see if any of them is for
3864+
// slices of `element_ty` with `mutability`.
3865+
let mut is_slice = |candidate: Ty<'tcx>| match *candidate.kind() {
3866+
ty::RawPtr(ty::TypeAndMut { ty: t, mutbl: m }) | ty::Ref(_, t, m) => {
3867+
if matches!(*t.kind(), ty::Slice(e) if e == element_ty)
3868+
&& m == mutability.unwrap_or(m)
3869+
{
3870+
// Use the candidate's mutability going forward.
3871+
mutability = Some(m);
3872+
true
3873+
} else {
3874+
false
3875+
}
3876+
}
3877+
_ => false,
3878+
};
3879+
3880+
// Grab the first candidate that matches, if any, and make a suggestion.
3881+
if let Some(slice_ty) = candidate_impls
3882+
.iter()
3883+
.map(|trait_ref| trait_ref.trait_ref.self_ty())
3884+
.filter(|t| is_slice(*t))
3885+
.next()
3886+
{
3887+
let msg = &format!("convert the array to a `{}` slice instead", slice_ty);
3888+
3889+
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
3890+
let mut suggestions = vec![];
3891+
if snippet.starts_with('&') {
3892+
} else if let Some(hir::Mutability::Mut) = mutability {
3893+
suggestions.push((span.shrink_to_lo(), "&mut ".into()));
3894+
} else {
3895+
suggestions.push((span.shrink_to_lo(), "&".into()));
3896+
}
3897+
suggestions.push((span.shrink_to_hi(), "[..]".into()));
3898+
err.multipart_suggestion_verbose(msg, suggestions, Applicability::MaybeIncorrect);
3899+
} else {
3900+
err.span_help(span, msg);
3901+
}
3902+
}
3903+
}
38293904
}
38303905

38313906
/// Add a hint to add a missing borrow or remove an unnecessary one.

compiler/rustc_type_ir/src/fold.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//! It defines a "skeleton" of how they should be folded.
1919
//! - `TypeSuperFoldable`. This is implemented only for each type of interest,
2020
//! and defines the folding "skeleton" for these types.
21-
//! - `TypeFolder`/`FallibleTypeFolder. One of these is implemented for each
21+
//! - `TypeFolder`/`FallibleTypeFolder`. One of these is implemented for each
2222
//! folder. This defines how types of interest are folded.
2323
//!
2424
//! This means each fold is a mixture of (a) generic folding operations, and (b)

src/bootstrap/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ impl<'a> Builder<'a> {
741741
doc::EmbeddedBook,
742742
doc::EditionGuide,
743743
doc::StyleGuide,
744+
doc::Tidy,
744745
),
745746
Kind::Dist => describe!(
746747
dist::Docs,

0 commit comments

Comments
 (0)