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 9 pull requests #92907

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d3aecc1
When obligation is a sized predicate, prefer projection or object can…
jackh726 Dec 20, 2021
b1b873f
Extend const_convert to rest of blanket core::convert impls
clarfonthey Dec 29, 2021
7224b00
change `ct_infer` to a delay_span_bug
lcnr Jan 5, 2022
a3e3787
remove unnecessary fixme
lcnr Jan 5, 2022
c0aa0fa
generic_arg_infer: placeholder in signature err
lcnr Jan 5, 2022
1e53a90
export `tcp::IntoIncoming`
ibraheemdev Jan 9, 2022
a3c55ac
privacy: update `visit_infer`
lcnr Jan 10, 2022
ec9c949
Use pre-interned symbols in a couple of places
bjorn3 Jan 10, 2022
f88b501
fix stability attribute for `tcp::IntoIncoming`
ibraheemdev Jan 13, 2022
7e055c6
librustdoc: Address some clippy lints
pierwill Jan 13, 2022
73945fd
fix bug
BoxyUwU Jan 14, 2022
b3d71d9
reduce indentaton
BoxyUwU Jan 14, 2022
fd7cc79
Add myself to .mailmap
JamesHinshelwood Jan 14, 2022
61c07a9
reviews ish
BoxyUwU Jan 14, 2022
9b9fc60
Remove unused link references.
ehuss Jan 13, 2022
ddab0bf
Remove duplicate cargo/4270. It was part of 1.21.
ehuss Jan 13, 2022
c1526c6
Remove duplicate #39983. It was part of 1.19.
ehuss Jan 13, 2022
12fa471
Fix incorrect link for #38622.
ehuss Jan 13, 2022
c7926c7
Fix link name collision for cargo#2365 (1.8cv)
ehuss Jan 13, 2022
6b726a1
Fix some links that had colliding reference names.
ehuss Jan 13, 2022
f212dcc
Rollup merge of #92191 - jackh726:issue-89352, r=nikomatsakis
matthiaskrgr Jan 14, 2022
89ea551
Rollup merge of #92382 - clarfonthey:const_convert, r=scottmcm
matthiaskrgr Jan 14, 2022
b331e0d
Rollup merge of #92582 - lcnr:generic-arg-infer, r=BoxyUwU
matthiaskrgr Jan 14, 2022
a5c24bb
Rollup merge of #92684 - ibraheemdev:patch-10, r=m-ou-se
matthiaskrgr Jan 14, 2022
0bd6ebe
Rollup merge of #92743 - bjorn3:less_symbol_intern, r=camelid
matthiaskrgr Jan 14, 2022
05a4e3b
Rollup merge of #92838 - ehuss:cleanup-release-links, r=Mark-Simulacrum
matthiaskrgr Jan 14, 2022
7613753
Rollup merge of #92868 - pierwill:librustdoc-clippy, r=camelid
matthiaskrgr Jan 14, 2022
4e6c793
Rollup merge of #92875 - BoxyUwU:infer_arg_opt_const_param_of, r=lcnr
matthiaskrgr Jan 14, 2022
fedc8aa
Rollup merge of #92891 - JamesHinshelwood:patch-1, r=Mark-Simulacrum
matthiaskrgr Jan 14, 2022
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 .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Jakub Adam Wieczorek <jakub.adam.wieczorek@gmail.com> <jakub.bukaj@yahoo.com>
Jakub Adam Wieczorek <jakub.adam.wieczorek@gmail.com> <jakub@jakub.cc>
Jakub Adam Wieczorek <jakub.adam.wieczorek@gmail.com> <jakubw@jakubw.net>
James Deng <cnjamesdeng@gmail.com> <cnJamesDeng@gmail.com>
James Hinshelwood <jameshinshelwood1@gmail.com> <james.hinshelwood@bigpayme.com>
James Miller <bladeon@gmail.com> <james@aatch.net>
James Perry <james.austin.perry@gmail.com>
Jason Fager <jfager@gmail.com>
Expand Down
142 changes: 16 additions & 126 deletions RELEASES.md

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_hir::def::Res;
use rustc_hir::definitions::DefPathData;
use rustc_span::hygiene::ExpnId;
use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
use rustc_span::symbol::{sym, Ident, Symbol};
use rustc_span::symbol::{sym, Ident};
use rustc_span::DUMMY_SP;

impl<'hir> LoweringContext<'_, 'hir> {
Expand Down Expand Up @@ -1204,11 +1204,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
};

let fields = self.arena.alloc_from_iter(
e1.iter().map(|e| ("start", e)).chain(e2.iter().map(|e| ("end", e))).map(|(s, e)| {
let expr = self.lower_expr(&e);
let ident = Ident::new(Symbol::intern(s), self.lower_span(e.span));
self.expr_field(ident, expr, e.span)
}),
e1.iter().map(|e| (sym::start, e)).chain(e2.iter().map(|e| (sym::end, e))).map(
|(s, e)| {
let expr = self.lower_expr(&e);
let ident = Ident::new(s, self.lower_span(e.span));
self.expr_field(ident, expr, e.span)
},
),
);

hir::ExprKind::Struct(
Expand Down
11 changes: 7 additions & 4 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,6 @@ impl GenericArg<'_> {
}
}

pub fn is_const(&self) -> bool {
matches!(self, GenericArg::Const(_))
}

pub fn is_synthetic(&self) -> bool {
matches!(self, GenericArg::Lifetime(lifetime) if lifetime.name.ident() == Ident::empty())
}
Expand All @@ -318,6 +314,13 @@ impl GenericArg<'_> {
GenericArg::Infer(_) => ast::ParamKindOrd::Infer,
}
}

pub fn is_ty_or_const(&self) -> bool {
match self {
GenericArg::Lifetime(_) => false,
GenericArg::Type(_) | GenericArg::Const(_) | GenericArg::Infer(_) => true,
}
}
}

#[derive(Debug, HashStable_Generic)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_middle::ty::print::Print;
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
use rustc_middle::ty::{self, Const, DefIdTree, InferConst, Ty, TyCtxt, TypeFoldable, TypeFolder};
use rustc_span::symbol::kw;
use rustc_span::Span;
use rustc_span::{sym, Span};
use std::borrow::Cow;

struct FindHirNodeVisitor<'a, 'tcx> {
Expand Down Expand Up @@ -1003,9 +1003,9 @@ impl<'tcx> TypeFolder<'tcx> for ResolvedTypeParamEraser<'tcx> {
| ty::Opaque(..)
| ty::Projection(_)
| ty::Never => t.super_fold_with(self),
ty::Array(ty, c) => self
.tcx()
.mk_ty(ty::Array(self.fold_ty(ty), self.replace_infers(c, 0, Symbol::intern("N")))),
ty::Array(ty, c) => {
self.tcx().mk_ty(ty::Array(self.fold_ty(ty), self.replace_infers(c, 0, sym::N)))
}
// We don't want to hide type params that haven't been resolved yet.
// This would be the type that will be written out with the type param
// name in the output.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/traits/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl<'tcx> Elaborator<'tcx> {
obligation.cause.clone(),
)
});
debug!("super_predicates: data={:?}", data);
debug!(?data, ?obligations, "super_predicates");

// Only keep those bounds that we haven't already seen.
// This is necessary to prevent infinite recursion in some
Expand Down
20 changes: 17 additions & 3 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1209,11 +1209,25 @@ impl<'tcx> TyCtxt<'tcx> {
self.mk_ty(Error(DelaySpanBugEmitted(())))
}

/// Like `err` but for constants.
/// Like [`ty_error`] but for constants.
#[track_caller]
pub fn const_error(self, ty: Ty<'tcx>) -> &'tcx Const<'tcx> {
self.sess
.delay_span_bug(DUMMY_SP, "ty::ConstKind::Error constructed but no error reported.");
self.const_error_with_message(
ty,
DUMMY_SP,
"ty::ConstKind::Error constructed but no error reported",
)
}

/// Like [`ty_error_with_message`] but for constants.
#[track_caller]
pub fn const_error_with_message<S: Into<MultiSpan>>(
self,
ty: Ty<'tcx>,
span: S,
msg: &str,
) -> &'tcx Const<'tcx> {
self.sess.delay_span_bug(span, msg);
self.mk_const(ty::Const { val: ty::ConstKind::Error(DelaySpanBugEmitted(())), ty })
}

Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_middle/src/ty/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ impl GenericParamDefKind {
GenericParamDefKind::Const { .. } => ast::ParamKindOrd::Const,
}
}

pub fn is_ty_or_const(&self) -> bool {
match self {
GenericParamDefKind::Lifetime => false,
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => true,
}
}
}

#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_middle/src/ty/print/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ pub trait Printer<'tcx>: Sized {
own_params.start = 1;
}

// If we're in verbose mode, then print default-equal args too
if self.tcx().sess.verbose() {
return &substs[own_params];
}

// Don't print args that are the defaults of their respective parameters.
own_params.end -= generics
.params
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1784,10 +1784,11 @@ impl<'tcx, F: fmt::Write> Printer<'tcx> for FmtPrinter<'_, 'tcx, F> {
self = print_prefix(self)?;

// Don't print `'_` if there's no unerased regions.
let print_regions = args.iter().any(|arg| match arg.unpack() {
GenericArgKind::Lifetime(r) => *r != ty::ReErased,
_ => false,
});
let print_regions = self.tcx.sess.verbose()
|| args.iter().any(|arg| match arg.unpack() {
GenericArgKind::Lifetime(r) => *r != ty::ReErased,
_ => false,
});
let args = args.iter().cloned().filter(|arg| match arg.unpack() {
GenericArgKind::Lifetime(_) => print_regions,
_ => true,
Expand Down
14 changes: 3 additions & 11 deletions compiler/rustc_privacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,19 +1152,11 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
if self.visit(ty).is_break() {
return;
}
} else {
// We don't do anything for const infers here.
}
} else {
let local_id = self.tcx.hir().local_def_id(inf.hir_id);
if let Some(did) = self.tcx.opt_const_param_of(local_id) {
if self.visit_def_id(did, "inferred", &"").is_break() {
return;
}
}

// FIXME see above note for same issue.
if self.visit(rustc_typeck::hir_ty_to_ty(self.tcx, &inf.to_ty())).is_break() {
return;
}
bug!("visit_infer without typeck_results");
}
intravisit::walk_inf(self, inf);
}
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ symbols! {
LinkedList,
LintPass,
Mutex,
N,
None,
Ok,
Option,
Expand Down Expand Up @@ -327,6 +328,7 @@ symbols! {
array,
arrays,
as_ptr,
as_ref,
as_str,
asm,
asm_const,
Expand Down Expand Up @@ -592,6 +594,7 @@ symbols! {
enable,
enclosing_scope,
encode,
end,
env,
eq,
ermsb_target_feature,
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,10 @@ fn assemble_candidates_from_object_ty<'cx, 'tcx>(
);
}

#[tracing::instrument(
level = "debug",
skip(selcx, candidate_set, ctor, env_predicates, potentially_unnormalized_candidates)
)]
fn assemble_candidates_from_predicates<'cx, 'tcx>(
selcx: &mut SelectionContext<'cx, 'tcx>,
obligation: &ProjectionTyObligation<'tcx>,
Expand All @@ -1233,8 +1237,6 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
env_predicates: impl Iterator<Item = ty::Predicate<'tcx>>,
potentially_unnormalized_candidates: bool,
) {
debug!(?obligation, "assemble_candidates_from_predicates");

let infcx = selcx.infcx();
for predicate in env_predicates {
debug!(?predicate);
Expand Down Expand Up @@ -1270,13 +1272,12 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
}
}

#[tracing::instrument(level = "debug", skip(selcx, obligation, candidate_set))]
fn assemble_candidates_from_impls<'cx, 'tcx>(
selcx: &mut SelectionContext<'cx, 'tcx>,
obligation: &ProjectionTyObligation<'tcx>,
candidate_set: &mut ProjectionTyCandidateSet<'tcx>,
) {
debug!("assemble_candidates_from_impls");

// If we are resolving `<T as TraitRef<...>>::Item == Type`,
// start out by selecting the predicate `T as TraitRef<...>`:
let poly_trait_ref = ty::Binder::dummy(obligation.predicate.trait_ref(selcx.tcx()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {

let needs_infer = stack.obligation.predicate.has_infer_types_or_consts();

let sized_predicate = self.tcx().lang_items().sized_trait()
== Some(stack.obligation.predicate.skip_binder().def_id());

// If there are STILL multiple candidates, we can further
// reduce the list by dropping duplicates -- including
// resolving specializations.
Expand All @@ -181,6 +184,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
while i < candidates.len() {
let is_dup = (0..candidates.len()).filter(|&j| i != j).any(|j| {
self.candidate_should_be_dropped_in_favor_of(
sized_predicate,
&candidates[i],
&candidates[j],
needs_infer,
Expand Down Expand Up @@ -338,13 +342,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
Ok(candidates)
}

#[tracing::instrument(level = "debug", skip(self, candidates))]
fn assemble_candidates_from_projected_tys(
&mut self,
obligation: &TraitObligation<'tcx>,
candidates: &mut SelectionCandidateSet<'tcx>,
) {
debug!(?obligation, "assemble_candidates_from_projected_tys");

// Before we go into the whole placeholder thing, just
// quickly check if the self-type is a projection at all.
match obligation.predicate.skip_binder().trait_ref.self_ty().kind() {
Expand All @@ -369,12 +372,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
/// supplied to find out whether it is listed among them.
///
/// Never affects the inference environment.
#[tracing::instrument(level = "debug", skip(self, stack, candidates))]
fn assemble_candidates_from_caller_bounds<'o>(
&mut self,
stack: &TraitObligationStack<'o, 'tcx>,
candidates: &mut SelectionCandidateSet<'tcx>,
) -> Result<(), SelectionError<'tcx>> {
debug!(?stack.obligation, "assemble_candidates_from_caller_bounds");
debug!(?stack.obligation);

let all_bounds = stack
.obligation
Expand Down Expand Up @@ -876,14 +880,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
};
}

#[tracing::instrument(level = "debug", skip(self, obligation, candidates))]
fn assemble_candidates_for_trait_alias(
&mut self,
obligation: &TraitObligation<'tcx>,
candidates: &mut SelectionCandidateSet<'tcx>,
) {
// Okay to skip binder here because the tests we do below do not involve bound regions.
let self_ty = obligation.self_ty().skip_binder();
debug!(?self_ty, "assemble_candidates_for_trait_alias");
debug!(?self_ty);

let def_id = obligation.predicate.def_id();

Expand All @@ -894,21 +899,20 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {

/// Assembles the trait which are built-in to the language itself:
/// `Copy`, `Clone` and `Sized`.
#[tracing::instrument(level = "debug", skip(self, candidates))]
fn assemble_builtin_bound_candidates(
&mut self,
conditions: BuiltinImplConditions<'tcx>,
candidates: &mut SelectionCandidateSet<'tcx>,
) {
match conditions {
BuiltinImplConditions::Where(nested) => {
debug!(?nested, "builtin_bound");
candidates
.vec
.push(BuiltinCandidate { has_nested: !nested.skip_binder().is_empty() });
}
BuiltinImplConditions::None => {}
BuiltinImplConditions::Ambiguous => {
debug!("assemble_builtin_bound_candidates: ambiguous builtin");
candidates.ambiguous = true;
}
}
Expand Down
23 changes: 14 additions & 9 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ struct EvaluatedCandidate<'tcx> {
}

/// When does the builtin impl for `T: Trait` apply?
#[derive(Debug)]
enum BuiltinImplConditions<'tcx> {
/// The impl is conditional on `T1, T2, ...: Trait`.
Where(ty::Binder<'tcx, Vec<Ty<'tcx>>>),
Expand Down Expand Up @@ -344,7 +345,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
Err(e) => Err(e),
Ok(candidate) => {
debug!(?candidate);
debug!(?candidate, "confirmed");
Ok(Some(candidate))
}
}
Expand Down Expand Up @@ -1523,6 +1524,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
/// See the comment for "SelectionCandidate" for more details.
fn candidate_should_be_dropped_in_favor_of(
&mut self,
sized_predicate: bool,
victim: &EvaluatedCandidate<'tcx>,
other: &EvaluatedCandidate<'tcx>,
needs_infer: bool,
Expand Down Expand Up @@ -1594,6 +1596,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// Drop otherwise equivalent non-const fn pointer candidates
(FnPointerCandidate { .. }, FnPointerCandidate { is_const: false }) => true,

// If obligation is a sized predicate or the where-clause bound is
// global, prefer the projection or object candidate. See issue
// #50825 and #89352.
(ObjectCandidate(_) | ProjectionCandidate(_), ParamCandidate(ref cand)) => {
sized_predicate || is_global(cand)
}
(ParamCandidate(ref cand), ObjectCandidate(_) | ProjectionCandidate(_)) => {
!(sized_predicate || is_global(cand))
}

// Global bounds from the where clause should be ignored
// here (see issue #50825). Otherwise, we have a where
// clause so don't go around looking for impls.
Expand All @@ -1609,15 +1621,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
| BuiltinUnsizeCandidate
| TraitUpcastingUnsizeCandidate(_)
| BuiltinCandidate { .. }
| TraitAliasCandidate(..)
| ObjectCandidate(_)
| ProjectionCandidate(_),
| TraitAliasCandidate(..),
) => !is_global(cand),
(ObjectCandidate(_) | ProjectionCandidate(_), ParamCandidate(ref cand)) => {
// Prefer these to a global where-clause bound
// (see issue #50825).
is_global(cand)
}
(
ImplCandidate(_)
| ClosureCandidate
Expand Down
Loading