Skip to content

Commit 0148b97

Browse files
committed
Auto merge of rust-lang#82263 - Dylan-DPC:rollup-cypm2uw, r=Dylan-DPC
Rollup of 10 pull requests Successful merges: - rust-lang#81546 ([libtest] Run the test synchronously when hitting thread limit) - rust-lang#82066 (Ensure valid TraitRefs are created for GATs) - rust-lang#82112 (const_generics: Dont evaluate array length const when handling yet another error ) - rust-lang#82194 (In some limited cases, suggest `where` bounds for non-type params) - rust-lang#82215 (Replace if-let and while-let with `if let` and `while let`) - rust-lang#82218 (Make sure pdbs are copied along with exe and dlls when bootstrapping) - rust-lang#82236 (avoid converting types into themselves (clippy::useless_conversion)) - rust-lang#82246 (Add long explanation for E0549) - rust-lang#82248 (Optimize counting digits in line numbers during error reporting) - rust-lang#82256 (Print -Ztime-passes (and misc stats/logs) on stderr, not stdout.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents cb2effd + efdcb43 commit 0148b97

File tree

89 files changed

+877
-391
lines changed

Some content is hidden

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

89 files changed

+877
-391
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

+1
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,7 @@ impl<'a> State<'a> {
914914

915915
pub fn print_assoc_constraint(&mut self, constraint: &ast::AssocTyConstraint) {
916916
self.print_ident(constraint.ident);
917+
constraint.gen_args.as_ref().map(|args| self.print_generic_args(args, false));
917918
self.s.space();
918919
match &constraint.kind {
919920
ast::AssocTyConstraintKind::Equality { ty } => {

compiler/rustc_data_structures/src/profiling.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ pub fn print_time_passes_entry(
608608
(None, None) => String::new(),
609609
};
610610

611-
println!("time: {:>7}{}\t{}", duration_to_secs_str(dur), mem_string, what);
611+
eprintln!("time: {:>7}{}\t{}", duration_to_secs_str(dur), mem_string, what);
612612
}
613613

614614
// Hack up our own formatting for the duration to make it easier for scripts

compiler/rustc_error_codes/src/error_codes.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ E0543: include_str!("./error_codes/E0543.md"),
290290
E0545: include_str!("./error_codes/E0545.md"),
291291
E0546: include_str!("./error_codes/E0546.md"),
292292
E0547: include_str!("./error_codes/E0547.md"),
293+
E0549: include_str!("./error_codes/E0549.md"),
293294
E0550: include_str!("./error_codes/E0550.md"),
294295
E0551: include_str!("./error_codes/E0551.md"),
295296
E0552: include_str!("./error_codes/E0552.md"),
@@ -608,9 +609,6 @@ E0781: include_str!("./error_codes/E0781.md"),
608609
// E0540, // multiple rustc_deprecated attributes
609610
E0544, // multiple stability levels
610611
// E0548, // replaced with a generic attribute input check
611-
// rustc_deprecated attribute must be paired with either stable or unstable
612-
// attribute
613-
E0549,
614612
E0553, // multiple rustc_const_unstable attributes
615613
// E0555, // replaced with a generic attribute input check
616614
// E0558, // replaced with a generic attribute input check

compiler/rustc_error_codes/src/error_codes/E0162.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#### Note: this error code is no longer emitted by the compiler.
22

3-
An if-let pattern attempts to match the pattern, and enters the body if the
3+
An `if let` pattern attempts to match the pattern, and enters the body if the
44
match was successful. If the match is irrefutable (when it cannot fail to
55
match), use a regular `let`-binding instead. For instance:
66

compiler/rustc_error_codes/src/error_codes/E0165.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#### Note: this error code is no longer emitted by the compiler.
22

3-
A while-let pattern attempts to match the pattern, and enters the body if the
3+
A `while let` pattern attempts to match the pattern, and enters the body if the
44
match was successful. If the match is irrefutable (when it cannot fail to
55
match), use a regular `let`-binding inside a `loop` instead. For instance:
66

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
A `rustc_deprecated` attribute wasn't paired with a `stable`/`unstable`
2+
attribute.
3+
4+
Erroneous code example:
5+
6+
```compile_fail,E0549
7+
#![feature(staged_api)]
8+
#![stable(since = "1.0.0", feature = "test")]
9+
10+
#[rustc_deprecated(
11+
since = "1.0.1",
12+
reason = "explanation for deprecation"
13+
)] // invalid
14+
fn _deprecated_fn() {}
15+
```
16+
17+
To fix this issue, you need to add also an attribute `stable` or `unstable`.
18+
Example:
19+
20+
```
21+
#![feature(staged_api)]
22+
#![stable(since = "1.0.0", feature = "test")]
23+
24+
#[stable(since = "1.0.0", feature = "test")]
25+
#[rustc_deprecated(
26+
since = "1.0.1",
27+
reason = "explanation for deprecation"
28+
)] // ok!
29+
fn _deprecated_fn() {}
30+
```
31+
32+
See the [How Rust is Made and “Nightly Rust”][how-rust-made-nightly] appendix
33+
of the Book and the [Stability attributes][stability-attributes] section of the
34+
Rustc Dev Guide for more details.
35+
36+
[how-rust-made-nightly]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
37+
[stability-attributes]: https://rustc-dev-guide.rust-lang.org/stability.html

compiler/rustc_errors/src/emitter.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1713,7 +1713,18 @@ impl EmitterWriter {
17131713
let max_line_num_len = if self.ui_testing {
17141714
ANONYMIZED_LINE_NUM.len()
17151715
} else {
1716-
self.get_max_line_num(span, children).to_string().len()
1716+
// Instead of using .to_string().len(), we iteratively count the
1717+
// number of digits to avoid allocation. This strategy has sizable
1718+
// performance gains over the old string strategy.
1719+
let mut n = self.get_max_line_num(span, children);
1720+
let mut num_digits = 0;
1721+
loop {
1722+
num_digits += 1;
1723+
n /= 10;
1724+
if n == 0 {
1725+
break num_digits;
1726+
}
1727+
}
17171728
};
17181729

17191730
match self.emit_message_default(span, message, code, level, max_line_num_len, false) {

compiler/rustc_hir/src/lang_items.rs

+1
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ language_item_table! {
242242

243243
Deref, sym::deref, deref_trait, Target::Trait;
244244
DerefMut, sym::deref_mut, deref_mut_trait, Target::Trait;
245+
DerefTarget, sym::deref_target, deref_target, Target::AssocTy;
245246
Receiver, sym::receiver, receiver_trait, Target::Trait;
246247

247248
Fn, kw::Fn, fn_trait, Target::Trait;

compiler/rustc_incremental/src/persist/file_format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fn report_format_mismatch(report_incremental_info: bool, file: &Path, message: &
109109
debug!("read_file: {}", message);
110110

111111
if report_incremental_info {
112-
println!(
112+
eprintln!(
113113
"[incremental] ignoring cache artifact `{}`: {}",
114114
file.file_name().unwrap().to_string_lossy(),
115115
message

compiler/rustc_incremental/src/persist/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,12 @@ fn copy_files(sess: &Session, target_dir: &Path, source_dir: &Path) -> Result<bo
440440
}
441441

442442
if sess.opts.debugging_opts.incremental_info {
443-
println!(
443+
eprintln!(
444444
"[incremental] session directory: \
445445
{} files hard-linked",
446446
files_linked
447447
);
448-
println!(
448+
eprintln!(
449449
"[incremental] session directory: \
450450
{} files copied",
451451
files_copied

compiler/rustc_incremental/src/persist/load.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
170170

171171
if prev_commandline_args_hash != expected_hash {
172172
if report_incremental_info {
173-
println!(
173+
eprintln!(
174174
"[incremental] completely ignoring cache because of \
175175
differing commandline arguments"
176176
);

compiler/rustc_infer/src/infer/at.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
5555

5656
pub trait ToTrace<'tcx>: Relate<'tcx> + Copy {
5757
fn to_trace(
58+
tcx: TyCtxt<'tcx>,
5859
cause: &ObligationCause<'tcx>,
5960
a_is_expected: bool,
6061
a: Self,
@@ -178,7 +179,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
178179
where
179180
T: ToTrace<'tcx>,
180181
{
181-
let trace = ToTrace::to_trace(self.cause, a_is_expected, a, b);
182+
let trace = ToTrace::to_trace(self.infcx.tcx, self.cause, a_is_expected, a, b);
182183
Trace { at: self, trace, a_is_expected }
183184
}
184185
}
@@ -251,6 +252,7 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
251252

252253
impl<'tcx> ToTrace<'tcx> for Ty<'tcx> {
253254
fn to_trace(
255+
_: TyCtxt<'tcx>,
254256
cause: &ObligationCause<'tcx>,
255257
a_is_expected: bool,
256258
a: Self,
@@ -262,6 +264,7 @@ impl<'tcx> ToTrace<'tcx> for Ty<'tcx> {
262264

263265
impl<'tcx> ToTrace<'tcx> for ty::Region<'tcx> {
264266
fn to_trace(
267+
_: TyCtxt<'tcx>,
265268
cause: &ObligationCause<'tcx>,
266269
a_is_expected: bool,
267270
a: Self,
@@ -273,6 +276,7 @@ impl<'tcx> ToTrace<'tcx> for ty::Region<'tcx> {
273276

274277
impl<'tcx> ToTrace<'tcx> for &'tcx Const<'tcx> {
275278
fn to_trace(
279+
_: TyCtxt<'tcx>,
276280
cause: &ObligationCause<'tcx>,
277281
a_is_expected: bool,
278282
a: Self,
@@ -284,6 +288,7 @@ impl<'tcx> ToTrace<'tcx> for &'tcx Const<'tcx> {
284288

285289
impl<'tcx> ToTrace<'tcx> for ty::TraitRef<'tcx> {
286290
fn to_trace(
291+
_: TyCtxt<'tcx>,
287292
cause: &ObligationCause<'tcx>,
288293
a_is_expected: bool,
289294
a: Self,
@@ -298,6 +303,7 @@ impl<'tcx> ToTrace<'tcx> for ty::TraitRef<'tcx> {
298303

299304
impl<'tcx> ToTrace<'tcx> for ty::PolyTraitRef<'tcx> {
300305
fn to_trace(
306+
_: TyCtxt<'tcx>,
301307
cause: &ObligationCause<'tcx>,
302308
a_is_expected: bool,
303309
a: Self,
@@ -309,3 +315,20 @@ impl<'tcx> ToTrace<'tcx> for ty::PolyTraitRef<'tcx> {
309315
}
310316
}
311317
}
318+
319+
impl<'tcx> ToTrace<'tcx> for ty::ProjectionTy<'tcx> {
320+
fn to_trace(
321+
tcx: TyCtxt<'tcx>,
322+
cause: &ObligationCause<'tcx>,
323+
a_is_expected: bool,
324+
a: Self,
325+
b: Self,
326+
) -> TypeTrace<'tcx> {
327+
let a_ty = tcx.mk_projection(a.item_def_id, a.substs);
328+
let b_ty = tcx.mk_projection(b.item_def_id, b.substs);
329+
TypeTrace {
330+
cause: cause.clone(),
331+
values: Types(ExpectedFound::new(a_is_expected, a_ty, b_ty)),
332+
}
333+
}
334+
}

compiler/rustc_interface/src/passes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ pub fn parse<'a>(sess: &'a Session, input: &Input) -> PResult<'a, ast::Crate> {
6464
}
6565

6666
if sess.opts.debugging_opts.input_stats {
67-
println!("Lines of code: {}", sess.source_map().count_lines());
68-
println!("Pre-expansion node count: {}", count_nodes(&krate));
67+
eprintln!("Lines of code: {}", sess.source_map().count_lines());
68+
eprintln!("Pre-expansion node count: {}", count_nodes(&krate));
6969
}
7070

7171
if let Some(ref s) = sess.opts.debugging_opts.show_span {
@@ -394,7 +394,7 @@ fn configure_and_expand_inner<'a>(
394394
// Done with macro expansion!
395395

396396
if sess.opts.debugging_opts.input_stats {
397-
println!("Post-expansion node count: {}", count_nodes(&krate));
397+
eprintln!("Post-expansion node count: {}", count_nodes(&krate));
398398
}
399399

400400
if sess.opts.debugging_opts.hir_stats {

compiler/rustc_lint_defs/src/builtin.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,7 @@ declare_lint! {
18151815

18161816
declare_lint! {
18171817
/// The `irrefutable_let_patterns` lint detects detects [irrefutable
1818-
/// patterns] in [if-let] and [while-let] statements.
1818+
/// patterns] in [`if let`] and [`while let`] statements.
18191819
///
18201820
///
18211821
///
@@ -1832,7 +1832,7 @@ declare_lint! {
18321832
/// ### Explanation
18331833
///
18341834
/// There usually isn't a reason to have an irrefutable pattern in an
1835-
/// if-let or while-let statement, because the pattern will always match
1835+
/// `if let` or `while let` statement, because the pattern will always match
18361836
/// successfully. A [`let`] or [`loop`] statement will suffice. However,
18371837
/// when generating code with a macro, forbidding irrefutable patterns
18381838
/// would require awkward workarounds in situations where the macro
@@ -1843,14 +1843,14 @@ declare_lint! {
18431843
/// See [RFC 2086] for more details.
18441844
///
18451845
/// [irrefutable patterns]: https://doc.rust-lang.org/reference/patterns.html#refutability
1846-
/// [if-let]: https://doc.rust-lang.org/reference/expressions/if-expr.html#if-let-expressions
1847-
/// [while-let]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops
1846+
/// [`if let`]: https://doc.rust-lang.org/reference/expressions/if-expr.html#if-let-expressions
1847+
/// [`while let`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops
18481848
/// [`let`]: https://doc.rust-lang.org/reference/statements.html#let-statements
18491849
/// [`loop`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#infinite-loops
18501850
/// [RFC 2086]: https://github.com/rust-lang/rfcs/blob/master/text/2086-allow-if-let-irrefutables.md
18511851
pub IRREFUTABLE_LET_PATTERNS,
18521852
Warn,
1853-
"detects irrefutable patterns in if-let and while-let statements"
1853+
"detects irrefutable patterns in `if let` and `while let` statements"
18541854
}
18551855

18561856
declare_lint! {

compiler/rustc_metadata/src/rmeta/encoder.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -695,23 +695,23 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
695695
}
696696
}
697697

698-
println!("metadata stats:");
699-
println!(" dep bytes: {}", dep_bytes);
700-
println!(" lib feature bytes: {}", lib_feature_bytes);
701-
println!(" lang item bytes: {}", lang_item_bytes);
702-
println!(" diagnostic item bytes: {}", diagnostic_item_bytes);
703-
println!(" native bytes: {}", native_lib_bytes);
704-
println!(" source_map bytes: {}", source_map_bytes);
705-
println!(" impl bytes: {}", impl_bytes);
706-
println!(" exp. symbols bytes: {}", exported_symbols_bytes);
707-
println!(" def-path table bytes: {}", def_path_table_bytes);
708-
println!(" proc-macro-data-bytes: {}", proc_macro_data_bytes);
709-
println!(" mir bytes: {}", mir_bytes);
710-
println!(" item bytes: {}", item_bytes);
711-
println!(" table bytes: {}", tables_bytes);
712-
println!(" hygiene bytes: {}", hygiene_bytes);
713-
println!(" zero bytes: {}", zero_bytes);
714-
println!(" total bytes: {}", total_bytes);
698+
eprintln!("metadata stats:");
699+
eprintln!(" dep bytes: {}", dep_bytes);
700+
eprintln!(" lib feature bytes: {}", lib_feature_bytes);
701+
eprintln!(" lang item bytes: {}", lang_item_bytes);
702+
eprintln!(" diagnostic item bytes: {}", diagnostic_item_bytes);
703+
eprintln!(" native bytes: {}", native_lib_bytes);
704+
eprintln!(" source_map bytes: {}", source_map_bytes);
705+
eprintln!(" impl bytes: {}", impl_bytes);
706+
eprintln!(" exp. symbols bytes: {}", exported_symbols_bytes);
707+
eprintln!(" def-path table bytes: {}", def_path_table_bytes);
708+
eprintln!(" proc-macro-data-bytes: {}", proc_macro_data_bytes);
709+
eprintln!(" mir bytes: {}", mir_bytes);
710+
eprintln!(" item bytes: {}", item_bytes);
711+
eprintln!(" table bytes: {}", tables_bytes);
712+
eprintln!(" hygiene bytes: {}", hygiene_bytes);
713+
eprintln!(" zero bytes: {}", zero_bytes);
714+
eprintln!(" total bytes: {}", total_bytes);
715715
}
716716

717717
root

compiler/rustc_middle/src/ty/diagnostics.rs

+30
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,36 @@ impl<'tcx> TyS<'tcx> {
7575
}
7676
}
7777

78+
pub fn suggest_arbitrary_trait_bound(
79+
generics: &hir::Generics<'_>,
80+
err: &mut DiagnosticBuilder<'_>,
81+
param_name: &str,
82+
constraint: &str,
83+
) -> bool {
84+
let param = generics.params.iter().find(|p| p.name.ident().as_str() == param_name);
85+
match (param, param_name) {
86+
(Some(_), "Self") => return false,
87+
_ => {}
88+
}
89+
// Suggest a where clause bound for a non-type paremeter.
90+
let (action, prefix) = if generics.where_clause.predicates.is_empty() {
91+
("introducing a", " where ")
92+
} else {
93+
("extending the", ", ")
94+
};
95+
err.span_suggestion_verbose(
96+
generics.where_clause.tail_span_for_suggestion(),
97+
&format!(
98+
"consider {} `where` bound, but there might be an alternative better way to express \
99+
this requirement",
100+
action,
101+
),
102+
format!("{}{}: {}", prefix, param_name, constraint),
103+
Applicability::MaybeIncorrect,
104+
);
105+
true
106+
}
107+
78108
/// Suggest restricting a type param with a new bound.
79109
pub fn suggest_constraining_type_param(
80110
tcx: TyCtxt<'_>,

0 commit comments

Comments
 (0)