Skip to content

Commit

Permalink
Auto merge of rust-lang#82263 - Dylan-DPC:rollup-cypm2uw, r=Dylan-DPC
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Feb 18, 2021
2 parents cb2effd + efdcb43 commit 0148b97
Show file tree
Hide file tree
Showing 89 changed files with 877 additions and 391 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ impl<'a> State<'a> {

pub fn print_assoc_constraint(&mut self, constraint: &ast::AssocTyConstraint) {
self.print_ident(constraint.ident);
constraint.gen_args.as_ref().map(|args| self.print_generic_args(args, false));
self.s.space();
match &constraint.kind {
ast::AssocTyConstraintKind::Equality { ty } => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ pub fn print_time_passes_entry(
(None, None) => String::new(),
};

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

// Hack up our own formatting for the duration to make it easier for scripts
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ E0543: include_str!("./error_codes/E0543.md"),
E0545: include_str!("./error_codes/E0545.md"),
E0546: include_str!("./error_codes/E0546.md"),
E0547: include_str!("./error_codes/E0547.md"),
E0549: include_str!("./error_codes/E0549.md"),
E0550: include_str!("./error_codes/E0550.md"),
E0551: include_str!("./error_codes/E0551.md"),
E0552: include_str!("./error_codes/E0552.md"),
Expand Down Expand Up @@ -608,9 +609,6 @@ E0781: include_str!("./error_codes/E0781.md"),
// E0540, // multiple rustc_deprecated attributes
E0544, // multiple stability levels
// E0548, // replaced with a generic attribute input check
// rustc_deprecated attribute must be paired with either stable or unstable
// attribute
E0549,
E0553, // multiple rustc_const_unstable attributes
// E0555, // replaced with a generic attribute input check
// E0558, // replaced with a generic attribute input check
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes/E0162.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#### Note: this error code is no longer emitted by the compiler.

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

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes/E0165.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#### Note: this error code is no longer emitted by the compiler.

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

Expand Down
37 changes: 37 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0549.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
A `rustc_deprecated` attribute wasn't paired with a `stable`/`unstable`
attribute.

Erroneous code example:

```compile_fail,E0549
#![feature(staged_api)]
#![stable(since = "1.0.0", feature = "test")]
#[rustc_deprecated(
since = "1.0.1",
reason = "explanation for deprecation"
)] // invalid
fn _deprecated_fn() {}
```

To fix this issue, you need to add also an attribute `stable` or `unstable`.
Example:

```
#![feature(staged_api)]
#![stable(since = "1.0.0", feature = "test")]
#[stable(since = "1.0.0", feature = "test")]
#[rustc_deprecated(
since = "1.0.1",
reason = "explanation for deprecation"
)] // ok!
fn _deprecated_fn() {}
```

See the [How Rust is Made and “Nightly Rust”][how-rust-made-nightly] appendix
of the Book and the [Stability attributes][stability-attributes] section of the
Rustc Dev Guide for more details.

[how-rust-made-nightly]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
[stability-attributes]: https://rustc-dev-guide.rust-lang.org/stability.html
13 changes: 12 additions & 1 deletion compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,18 @@ impl EmitterWriter {
let max_line_num_len = if self.ui_testing {
ANONYMIZED_LINE_NUM.len()
} else {
self.get_max_line_num(span, children).to_string().len()
// Instead of using .to_string().len(), we iteratively count the
// number of digits to avoid allocation. This strategy has sizable
// performance gains over the old string strategy.
let mut n = self.get_max_line_num(span, children);
let mut num_digits = 0;
loop {
num_digits += 1;
n /= 10;
if n == 0 {
break num_digits;
}
}
};

match self.emit_message_default(span, message, code, level, max_line_num_len, false) {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ language_item_table! {

Deref, sym::deref, deref_trait, Target::Trait;
DerefMut, sym::deref_mut, deref_mut_trait, Target::Trait;
DerefTarget, sym::deref_target, deref_target, Target::AssocTy;
Receiver, sym::receiver, receiver_trait, Target::Trait;

Fn, kw::Fn, fn_trait, Target::Trait;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_incremental/src/persist/file_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn report_format_mismatch(report_incremental_info: bool, file: &Path, message: &
debug!("read_file: {}", message);

if report_incremental_info {
println!(
eprintln!(
"[incremental] ignoring cache artifact `{}`: {}",
file.file_name().unwrap().to_string_lossy(),
message
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_incremental/src/persist/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,12 @@ fn copy_files(sess: &Session, target_dir: &Path, source_dir: &Path) -> Result<bo
}

if sess.opts.debugging_opts.incremental_info {
println!(
eprintln!(
"[incremental] session directory: \
{} files hard-linked",
files_linked
);
println!(
eprintln!(
"[incremental] session directory: \
{} files copied",
files_copied
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_incremental/src/persist/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {

if prev_commandline_args_hash != expected_hash {
if report_incremental_info {
println!(
eprintln!(
"[incremental] completely ignoring cache because of \
differing commandline arguments"
);
Expand Down
25 changes: 24 additions & 1 deletion compiler/rustc_infer/src/infer/at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

pub trait ToTrace<'tcx>: Relate<'tcx> + Copy {
fn to_trace(
tcx: TyCtxt<'tcx>,
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
Expand Down Expand Up @@ -178,7 +179,7 @@ impl<'a, 'tcx> At<'a, 'tcx> {
where
T: ToTrace<'tcx>,
{
let trace = ToTrace::to_trace(self.cause, a_is_expected, a, b);
let trace = ToTrace::to_trace(self.infcx.tcx, self.cause, a_is_expected, a, b);
Trace { at: self, trace, a_is_expected }
}
}
Expand Down Expand Up @@ -251,6 +252,7 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {

impl<'tcx> ToTrace<'tcx> for Ty<'tcx> {
fn to_trace(
_: TyCtxt<'tcx>,
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
Expand All @@ -262,6 +264,7 @@ impl<'tcx> ToTrace<'tcx> for Ty<'tcx> {

impl<'tcx> ToTrace<'tcx> for ty::Region<'tcx> {
fn to_trace(
_: TyCtxt<'tcx>,
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
Expand All @@ -273,6 +276,7 @@ impl<'tcx> ToTrace<'tcx> for ty::Region<'tcx> {

impl<'tcx> ToTrace<'tcx> for &'tcx Const<'tcx> {
fn to_trace(
_: TyCtxt<'tcx>,
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
Expand All @@ -284,6 +288,7 @@ impl<'tcx> ToTrace<'tcx> for &'tcx Const<'tcx> {

impl<'tcx> ToTrace<'tcx> for ty::TraitRef<'tcx> {
fn to_trace(
_: TyCtxt<'tcx>,
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
Expand All @@ -298,6 +303,7 @@ impl<'tcx> ToTrace<'tcx> for ty::TraitRef<'tcx> {

impl<'tcx> ToTrace<'tcx> for ty::PolyTraitRef<'tcx> {
fn to_trace(
_: TyCtxt<'tcx>,
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
Expand All @@ -309,3 +315,20 @@ impl<'tcx> ToTrace<'tcx> for ty::PolyTraitRef<'tcx> {
}
}
}

impl<'tcx> ToTrace<'tcx> for ty::ProjectionTy<'tcx> {
fn to_trace(
tcx: TyCtxt<'tcx>,
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
let a_ty = tcx.mk_projection(a.item_def_id, a.substs);
let b_ty = tcx.mk_projection(b.item_def_id, b.substs);
TypeTrace {
cause: cause.clone(),
values: Types(ExpectedFound::new(a_is_expected, a_ty, b_ty)),
}
}
}
6 changes: 3 additions & 3 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ pub fn parse<'a>(sess: &'a Session, input: &Input) -> PResult<'a, ast::Crate> {
}

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

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

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

if sess.opts.debugging_opts.hir_stats {
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1815,7 +1815,7 @@ declare_lint! {

declare_lint! {
/// The `irrefutable_let_patterns` lint detects detects [irrefutable
/// patterns] in [if-let] and [while-let] statements.
/// patterns] in [`if let`] and [`while let`] statements.
///
///
///
Expand All @@ -1832,7 +1832,7 @@ declare_lint! {
/// ### Explanation
///
/// There usually isn't a reason to have an irrefutable pattern in an
/// if-let or while-let statement, because the pattern will always match
/// `if let` or `while let` statement, because the pattern will always match
/// successfully. A [`let`] or [`loop`] statement will suffice. However,
/// when generating code with a macro, forbidding irrefutable patterns
/// would require awkward workarounds in situations where the macro
Expand All @@ -1843,14 +1843,14 @@ declare_lint! {
/// See [RFC 2086] for more details.
///
/// [irrefutable patterns]: https://doc.rust-lang.org/reference/patterns.html#refutability
/// [if-let]: https://doc.rust-lang.org/reference/expressions/if-expr.html#if-let-expressions
/// [while-let]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops
/// [`if let`]: https://doc.rust-lang.org/reference/expressions/if-expr.html#if-let-expressions
/// [`while let`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops
/// [`let`]: https://doc.rust-lang.org/reference/statements.html#let-statements
/// [`loop`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#infinite-loops
/// [RFC 2086]: https://github.com/rust-lang/rfcs/blob/master/text/2086-allow-if-let-irrefutables.md
pub IRREFUTABLE_LET_PATTERNS,
Warn,
"detects irrefutable patterns in if-let and while-let statements"
"detects irrefutable patterns in `if let` and `while let` statements"
}

declare_lint! {
Expand Down
34 changes: 17 additions & 17 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,23 +695,23 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
}
}

println!("metadata stats:");
println!(" dep bytes: {}", dep_bytes);
println!(" lib feature bytes: {}", lib_feature_bytes);
println!(" lang item bytes: {}", lang_item_bytes);
println!(" diagnostic item bytes: {}", diagnostic_item_bytes);
println!(" native bytes: {}", native_lib_bytes);
println!(" source_map bytes: {}", source_map_bytes);
println!(" impl bytes: {}", impl_bytes);
println!(" exp. symbols bytes: {}", exported_symbols_bytes);
println!(" def-path table bytes: {}", def_path_table_bytes);
println!(" proc-macro-data-bytes: {}", proc_macro_data_bytes);
println!(" mir bytes: {}", mir_bytes);
println!(" item bytes: {}", item_bytes);
println!(" table bytes: {}", tables_bytes);
println!(" hygiene bytes: {}", hygiene_bytes);
println!(" zero bytes: {}", zero_bytes);
println!(" total bytes: {}", total_bytes);
eprintln!("metadata stats:");
eprintln!(" dep bytes: {}", dep_bytes);
eprintln!(" lib feature bytes: {}", lib_feature_bytes);
eprintln!(" lang item bytes: {}", lang_item_bytes);
eprintln!(" diagnostic item bytes: {}", diagnostic_item_bytes);
eprintln!(" native bytes: {}", native_lib_bytes);
eprintln!(" source_map bytes: {}", source_map_bytes);
eprintln!(" impl bytes: {}", impl_bytes);
eprintln!(" exp. symbols bytes: {}", exported_symbols_bytes);
eprintln!(" def-path table bytes: {}", def_path_table_bytes);
eprintln!(" proc-macro-data-bytes: {}", proc_macro_data_bytes);
eprintln!(" mir bytes: {}", mir_bytes);
eprintln!(" item bytes: {}", item_bytes);
eprintln!(" table bytes: {}", tables_bytes);
eprintln!(" hygiene bytes: {}", hygiene_bytes);
eprintln!(" zero bytes: {}", zero_bytes);
eprintln!(" total bytes: {}", total_bytes);
}

root
Expand Down
30 changes: 30 additions & 0 deletions compiler/rustc_middle/src/ty/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,36 @@ impl<'tcx> TyS<'tcx> {
}
}

pub fn suggest_arbitrary_trait_bound(
generics: &hir::Generics<'_>,
err: &mut DiagnosticBuilder<'_>,
param_name: &str,
constraint: &str,
) -> bool {
let param = generics.params.iter().find(|p| p.name.ident().as_str() == param_name);
match (param, param_name) {
(Some(_), "Self") => return false,
_ => {}
}
// Suggest a where clause bound for a non-type paremeter.
let (action, prefix) = if generics.where_clause.predicates.is_empty() {
("introducing a", " where ")
} else {
("extending the", ", ")
};
err.span_suggestion_verbose(
generics.where_clause.tail_span_for_suggestion(),
&format!(
"consider {} `where` bound, but there might be an alternative better way to express \
this requirement",
action,
),
format!("{}{}: {}", prefix, param_name, constraint),
Applicability::MaybeIncorrect,
);
true
}

/// Suggest restricting a type param with a new bound.
pub fn suggest_constraining_type_param(
tcx: TyCtxt<'_>,
Expand Down
Loading

0 comments on commit 0148b97

Please sign in to comment.