Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #82262

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
dfa581f
Fix pretty printing of generic associated type constraints
matthewjasper Feb 11, 2021
9bbd3e0
Remove ProjectionTy::from_ref_and_name
matthewjasper Feb 11, 2021
0bf1d73
Don't go through TraitRef to relate projections
matthewjasper Feb 12, 2021
9526c0c
Avoid `trait_ref` when lowering ExistentialProjections
matthewjasper Feb 12, 2021
79f6f11
Remove some unnecessary `trait_ref` calls
matthewjasper Feb 12, 2021
dfee89f
Make ProjectionTy::trait_ref truncate substs again
matthewjasper Feb 12, 2021
d785c8c
Remove unnecessary function parameters project.rs
matthewjasper Feb 12, 2021
eeb82e4
Add more tests for generic associated type bounds
matthewjasper Feb 12, 2021
7e368e5
the environment round here is awfully empty
BoxyUwU Feb 15, 2021
c28d86c
name async generators something more human friendly in type error dia…
guswynn Jan 29, 2021
0f04875
replace if-let and while-let with `if let` and `while let`
TaKO8Ki Feb 17, 2021
43aed74
[libtest] Run the test synchronously when hitting thread limit
Jan 29, 2021
2a66685
Make sure pdbs are copied along with exe and dlls when bootstrapping
rylev Feb 17, 2021
32c97da
In some limited cases, suggest `where` bounds for non-type params
estebank Feb 16, 2021
ec50a20
avoid converting types into themselves (clippy::useless_conversion)
matthiaskrgr Feb 17, 2021
5ae392f
Add long explanation for E0549
jesusprubio Feb 18, 2021
5112cf0
Update compiler/rustc_error_codes/src/error_codes/E0549.md
jesusprubio Feb 18, 2021
0e01c41
Update compiler/rustc_error_codes/src/error_codes/E0549.md
jesusprubio Feb 18, 2021
3c4fe1e
Update compiler/rustc_error_codes/src/error_codes/E0549.md
jesusprubio Feb 18, 2021
8a5c568
nhwn: optimize counting digits in line numbers
nhwn Feb 18, 2021
46b4d8e
Rollup merge of #81496 - guswynn:expected_async_block, r=oli-obk
Dylan-DPC Feb 18, 2021
945dbdd
Rollup merge of #81546 - hyd-dev:libtest-run-out-of-threads, r=Mark-S…
Dylan-DPC Feb 18, 2021
c53cc39
Rollup merge of #82066 - matthewjasper:trait-ref-fix, r=jackh726
Dylan-DPC Feb 18, 2021
5775894
Rollup merge of #82112 - BoxyUwU:tumbleweed, r=varkor
Dylan-DPC Feb 18, 2021
ab642a3
Rollup merge of #82194 - estebank:arbitrary-bounds-suggestion, r=petr…
Dylan-DPC Feb 18, 2021
913cfbf
Rollup merge of #82215 - TaKO8Ki:replace-if-let-while-let, r=varkor
Dylan-DPC Feb 18, 2021
4906bd8
Rollup merge of #82218 - rylev:copy-pdbs, r=Mark-Simulacrum
Dylan-DPC Feb 18, 2021
7d75a22
Rollup merge of #82236 - matthiaskrgr:useless_conv, r=jyn514
Dylan-DPC Feb 18, 2021
3266eb2
Rollup merge of #82246 - jesusprubio:add-long-explanation-e0549, r=Gu…
Dylan-DPC Feb 18, 2021
d744e0b
Rollup merge of #82248 - nhwn:optimize-counting-digits, r=varkor
Dylan-DPC Feb 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
23 changes: 21 additions & 2 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ impl Body<'hir> {
}

/// The type of source expression that caused this generator to be created.
#[derive(Clone, PartialEq, Eq, HashStable_Generic, Encodable, Decodable, Debug, Copy)]
#[derive(Clone, PartialEq, Eq, Hash, HashStable_Generic, Encodable, Decodable, Debug, Copy)]
pub enum GeneratorKind {
/// An explicit `async` block or the body of an async function.
Async(AsyncGeneratorKind),
Expand All @@ -1298,12 +1298,21 @@ impl fmt::Display for GeneratorKind {
}
}

impl GeneratorKind {
pub fn descr(&self) -> &'static str {
match self {
GeneratorKind::Async(ask) => ask.descr(),
GeneratorKind::Gen => "generator",
}
}
}

/// In the case of a generator created as part of an async construct,
/// which kind of async construct caused it to be created?
///
/// This helps error messages but is also used to drive coercions in
/// type-checking (see #60424).
#[derive(Clone, PartialEq, Eq, HashStable_Generic, Encodable, Decodable, Debug, Copy)]
#[derive(Clone, PartialEq, Eq, Hash, HashStable_Generic, Encodable, Decodable, Debug, Copy)]
pub enum AsyncGeneratorKind {
/// An explicit `async` block written by the user.
Block,
Expand All @@ -1325,6 +1334,16 @@ impl fmt::Display for AsyncGeneratorKind {
}
}

impl AsyncGeneratorKind {
pub fn descr(&self) -> &'static str {
match self {
AsyncGeneratorKind::Block => "`async` block",
AsyncGeneratorKind::Closure => "`async` closure body",
AsyncGeneratorKind::Fn => "`async fn` body",
}
}
}

#[derive(Copy, Clone, Debug)]
pub enum BodyOwnerKind {
/// Functions and methods.
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
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)),
}
}
}
16 changes: 9 additions & 7 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

impl<'tcx> ty::fold::TypeVisitor<'tcx> for OpaqueTypesVisitor<'tcx> {
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
if let Some((kind, def_id)) = TyCategory::from_ty(t) {
if let Some((kind, def_id)) = TyCategory::from_ty(self.tcx, t) {
let span = self.tcx.def_span(def_id);
// Avoid cluttering the output when the "found" and error span overlap:
//
Expand Down Expand Up @@ -1582,11 +1582,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
};
if let Some((expected, found)) = expected_found {
let expected_label = match exp_found {
Mismatch::Variable(ef) => ef.expected.prefix_string(),
Mismatch::Variable(ef) => ef.expected.prefix_string(self.tcx),
Mismatch::Fixed(s) => s.into(),
};
let found_label = match exp_found {
Mismatch::Variable(ef) => ef.found.prefix_string(),
Mismatch::Variable(ef) => ef.found.prefix_string(self.tcx),
Mismatch::Fixed(s) => s.into(),
};
let exp_found = match exp_found {
Expand Down Expand Up @@ -2489,7 +2489,7 @@ impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
pub enum TyCategory {
Closure,
Opaque,
Generator,
Generator(hir::GeneratorKind),
Foreign,
}

Expand All @@ -2498,16 +2498,18 @@ impl TyCategory {
match self {
Self::Closure => "closure",
Self::Opaque => "opaque type",
Self::Generator => "generator",
Self::Generator(gk) => gk.descr(),
Self::Foreign => "foreign type",
}
}

pub fn from_ty(ty: Ty<'_>) -> Option<(Self, DefId)> {
pub fn from_ty(tcx: TyCtxt<'_>, ty: Ty<'_>) -> Option<(Self, DefId)> {
match *ty.kind() {
ty::Closure(def_id, _) => Some((Self::Closure, def_id)),
ty::Opaque(def_id, _) => Some((Self::Opaque, def_id)),
ty::Generator(def_id, ..) => Some((Self::Generator, def_id)),
ty::Generator(def_id, ..) => {
Some((Self::Generator(tcx.generator_kind(def_id).unwrap()), def_id))
}
ty::Foreign(def_id) => Some((Self::Foreign, def_id)),
_ => None,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
InferenceDiagnosticsData {
name: s,
span: None,
kind: UnderspecifiedArgKind::Type { prefix: ty.prefix_string() },
kind: UnderspecifiedArgKind::Type { prefix: ty.prefix_string(self.tcx) },
parent: None,
}
}
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
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