Skip to content

Commit c51ce16

Browse files
committed
Auto merge of rust-lang#3131 - RalfJung:rustup, r=RalfJung
Rustup Also fix josh build (they have a `deny(warnings)` that's causing issues).
2 parents 1e71277 + b824bb1 commit c51ce16

File tree

387 files changed

+1764
-756
lines changed

Some content is hidden

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

387 files changed

+1764
-756
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -4271,7 +4271,6 @@ dependencies = [
42714271
"rustc_errors",
42724272
"rustc_fluent_macro",
42734273
"rustc_hir",
4274-
"rustc_index",
42754274
"rustc_macros",
42764275
"rustc_middle",
42774276
"rustc_session",

compiler/rustc_errors/src/emitter.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::{
2323
use rustc_lint_defs::pluralize;
2424

2525
use derive_setters::Setters;
26-
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
26+
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
2727
use rustc_data_structures::sync::{DynSend, IntoDynSyncSend, Lrc};
2828
use rustc_error_messages::{FluentArgs, SpanLabel};
2929
use rustc_span::hygiene::{ExpnKind, MacroKind};
@@ -370,7 +370,7 @@ pub trait Emitter: Translate {
370370
}
371371

372372
fn render_multispan_macro_backtrace(&self, span: &mut MultiSpan, always_backtrace: bool) {
373-
let mut new_labels: Vec<(Span, String)> = vec![];
373+
let mut new_labels = FxIndexSet::default();
374374

375375
for &sp in span.primary_spans() {
376376
if sp.is_dummy() {
@@ -387,7 +387,7 @@ pub trait Emitter: Translate {
387387
}
388388

389389
if always_backtrace {
390-
new_labels.push((
390+
new_labels.insert((
391391
trace.def_site,
392392
format!(
393393
"in this expansion of `{}`{}",
@@ -431,7 +431,7 @@ pub trait Emitter: Translate {
431431
format!("this {} desugaring", kind.descr()).into()
432432
}
433433
};
434-
new_labels.push((
434+
new_labels.insert((
435435
trace.call_site,
436436
format!(
437437
"in {}{}",

compiler/rustc_hir_typeck/src/method/suggest.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use rustc_infer::infer::{
2626
RegionVariableOrigin,
2727
};
2828
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
29-
use rustc_middle::traits::util::supertraits;
3029
use rustc_middle::ty::fast_reject::DeepRejectCtxt;
3130
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
3231
use rustc_middle::ty::print::{with_crate_prefix, with_forced_trimmed_paths};
@@ -40,7 +39,7 @@ use rustc_trait_selection::traits::error_reporting::on_unimplemented::OnUnimplem
4039
use rustc_trait_selection::traits::error_reporting::on_unimplemented::TypeErrCtxtExt as _;
4140
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
4241
use rustc_trait_selection::traits::{
43-
FulfillmentError, Obligation, ObligationCause, ObligationCauseCode,
42+
supertraits, FulfillmentError, Obligation, ObligationCause, ObligationCauseCode,
4443
};
4544
use std::borrow::Cow;
4645

compiler/rustc_infer/src/traits/util.rs

+29-34
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use smallvec::smallvec;
22

33
use crate::infer::outlives::components::{push_outlives_components, Component};
44
use crate::traits::{self, Obligation, PredicateObligation};
5-
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
5+
use rustc_data_structures::fx::FxHashSet;
66
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
77
use rustc_span::symbol::Ident;
88
use rustc_span::Span;
@@ -76,7 +76,13 @@ impl<'tcx> Extend<ty::Predicate<'tcx>> for PredicateSet<'tcx> {
7676
pub struct Elaborator<'tcx, O> {
7777
stack: Vec<O>,
7878
visited: PredicateSet<'tcx>,
79-
only_self: bool,
79+
mode: Filter,
80+
}
81+
82+
enum Filter {
83+
All,
84+
OnlySelf,
85+
OnlySelfThatDefines(Ident),
8086
}
8187

8288
/// Describes how to elaborate an obligation into a sub-obligation.
@@ -224,7 +230,7 @@ pub fn elaborate<'tcx, O: Elaboratable<'tcx>>(
224230
obligations: impl IntoIterator<Item = O>,
225231
) -> Elaborator<'tcx, O> {
226232
let mut elaborator =
227-
Elaborator { stack: Vec::new(), visited: PredicateSet::new(tcx), only_self: false };
233+
Elaborator { stack: Vec::new(), visited: PredicateSet::new(tcx), mode: Filter::All };
228234
elaborator.extend_deduped(obligations);
229235
elaborator
230236
}
@@ -242,7 +248,13 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> {
242248
/// Filter to only the supertraits of trait predicates, i.e. only the predicates
243249
/// that have `Self` as their self type, instead of all implied predicates.
244250
pub fn filter_only_self(mut self) -> Self {
245-
self.only_self = true;
251+
self.mode = Filter::OnlySelf;
252+
self
253+
}
254+
255+
/// Filter to only the supertraits of trait predicates that define the assoc_ty.
256+
pub fn filter_only_self_that_defines(mut self, assoc_ty: Ident) -> Self {
257+
self.mode = Filter::OnlySelfThatDefines(assoc_ty);
246258
self
247259
}
248260

@@ -257,10 +269,12 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> {
257269
return;
258270
}
259271
// Get predicates implied by the trait, or only super predicates if we only care about self predicates.
260-
let predicates = if self.only_self {
261-
tcx.super_predicates_of(data.def_id())
262-
} else {
263-
tcx.implied_predicates_of(data.def_id())
272+
let predicates = match self.mode {
273+
Filter::All => tcx.implied_predicates_of(data.def_id()),
274+
Filter::OnlySelf => tcx.super_predicates_of(data.def_id()),
275+
Filter::OnlySelfThatDefines(ident) => {
276+
tcx.super_predicates_that_define_assoc_item((data.def_id(), ident))
277+
}
264278
};
265279

266280
let obligations =
@@ -409,14 +423,14 @@ impl<'tcx, O: Elaboratable<'tcx>> Iterator for Elaborator<'tcx, O> {
409423
pub fn supertraits<'tcx>(
410424
tcx: TyCtxt<'tcx>,
411425
trait_ref: ty::PolyTraitRef<'tcx>,
412-
) -> impl Iterator<Item = ty::PolyTraitRef<'tcx>> {
426+
) -> FilterToTraits<Elaborator<'tcx, ty::Predicate<'tcx>>> {
413427
elaborate(tcx, [trait_ref.to_predicate(tcx)]).filter_only_self().filter_to_traits()
414428
}
415429

416430
pub fn transitive_bounds<'tcx>(
417431
tcx: TyCtxt<'tcx>,
418432
trait_refs: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
419-
) -> impl Iterator<Item = ty::PolyTraitRef<'tcx>> {
433+
) -> FilterToTraits<Elaborator<'tcx, ty::Predicate<'tcx>>> {
420434
elaborate(tcx, trait_refs.map(|trait_ref| trait_ref.to_predicate(tcx)))
421435
.filter_only_self()
422436
.filter_to_traits()
@@ -429,31 +443,12 @@ pub fn transitive_bounds<'tcx>(
429443
/// `T::Item` and helps to avoid cycle errors (see e.g. #35237).
430444
pub fn transitive_bounds_that_define_assoc_item<'tcx>(
431445
tcx: TyCtxt<'tcx>,
432-
bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
446+
trait_refs: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
433447
assoc_name: Ident,
434-
) -> impl Iterator<Item = ty::PolyTraitRef<'tcx>> {
435-
let mut stack: Vec<_> = bounds.collect();
436-
let mut visited = FxIndexSet::default();
437-
438-
std::iter::from_fn(move || {
439-
while let Some(trait_ref) = stack.pop() {
440-
let anon_trait_ref = tcx.anonymize_bound_vars(trait_ref);
441-
if visited.insert(anon_trait_ref) {
442-
let super_predicates =
443-
tcx.super_predicates_that_define_assoc_item((trait_ref.def_id(), assoc_name));
444-
for (super_predicate, _) in super_predicates.predicates {
445-
let subst_predicate = super_predicate.subst_supertrait(tcx, &trait_ref);
446-
if let Some(binder) = subst_predicate.as_trait_clause() {
447-
stack.push(binder.map_bound(|t| t.trait_ref));
448-
}
449-
}
450-
451-
return Some(trait_ref);
452-
}
453-
}
454-
455-
return None;
456-
})
448+
) -> FilterToTraits<Elaborator<'tcx, ty::Predicate<'tcx>>> {
449+
elaborate(tcx, trait_refs.map(|trait_ref| trait_ref.to_predicate(tcx)))
450+
.filter_only_self_that_defines(assoc_name)
451+
.filter_to_traits()
457452
}
458453

459454
///////////////////////////////////////////////////////////////////////////

compiler/rustc_lint/src/deref_into_dyn_supertrait.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ use crate::{
44
};
55

66
use rustc_hir as hir;
7-
use rustc_middle::{traits::util::supertraits, ty};
7+
use rustc_middle::ty;
88
use rustc_session::lint::FutureIncompatibilityReason;
99
use rustc_span::sym;
10+
use rustc_trait_selection::traits::supertraits;
1011

1112
declare_lint! {
1213
/// The `deref_into_dyn_supertrait` lint is output whenever there is a use of the

compiler/rustc_middle/src/traits/util.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ use rustc_data_structures::fx::FxHashSet;
33
use crate::ty::{PolyTraitRef, TyCtxt};
44

55
/// Given a PolyTraitRef, get the PolyTraitRefs of the trait's (transitive) supertraits.
6-
///
7-
/// A simplified version of the same function at `rustc_infer::traits::util::supertraits`.
8-
pub fn supertraits<'tcx>(
6+
/// This only exists in `rustc_middle` because the more powerful elaborator depends on
7+
/// `rustc_infer` for elaborating outlives bounds -- this should only be used for pretty
8+
/// printing.
9+
pub fn supertraits_for_pretty_printing<'tcx>(
910
tcx: TyCtxt<'tcx>,
1011
trait_ref: PolyTraitRef<'tcx>,
1112
) -> impl Iterator<Item = PolyTraitRef<'tcx>> {

compiler/rustc_middle/src/ty/print/pretty.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::mir::interpret::{AllocRange, GlobalAlloc, Pointer, Provenance, Scalar};
22
use crate::query::IntoQueryParam;
33
use crate::query::Providers;
4+
use crate::traits::util::supertraits_for_pretty_printing;
45
use crate::ty::{
56
self, ConstInt, ParamConst, ScalarInt, Term, TermKind, Ty, TyCtxt, TypeFoldable,
67
TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
@@ -1150,14 +1151,14 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
11501151
entry.has_fn_once = true;
11511152
return;
11521153
} else if Some(trait_def_id) == self.tcx().lang_items().fn_mut_trait() {
1153-
let super_trait_ref = crate::traits::util::supertraits(self.tcx(), trait_ref)
1154+
let super_trait_ref = supertraits_for_pretty_printing(self.tcx(), trait_ref)
11541155
.find(|super_trait_ref| super_trait_ref.def_id() == fn_once_trait)
11551156
.unwrap();
11561157

11571158
fn_traits.entry(super_trait_ref).or_default().fn_mut_trait_ref = Some(trait_ref);
11581159
return;
11591160
} else if Some(trait_def_id) == self.tcx().lang_items().fn_trait() {
1160-
let super_trait_ref = crate::traits::util::supertraits(self.tcx(), trait_ref)
1161+
let super_trait_ref = supertraits_for_pretty_printing(self.tcx(), trait_ref)
11611162
.find(|super_trait_ref| super_trait_ref.def_id() == fn_once_trait)
11621163
.unwrap();
11631164

compiler/rustc_monomorphize/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ rustc_data_structures = { path = "../rustc_data_structures" }
1313
rustc_errors = { path = "../rustc_errors" }
1414
rustc_hir = { path = "../rustc_hir" }
1515
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
16-
rustc_index = { path = "../rustc_index" }
1716
rustc_macros = { path = "../rustc_macros" }
1817
rustc_middle = { path = "../rustc_middle" }
1918
rustc_session = { path = "../rustc_session" }

compiler/rustc_monomorphize/messages.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ monomorphize_type_length_limit = reached the type-length limit while instantiati
2727
monomorphize_unknown_cgu_collection_mode =
2828
unknown codegen-item collection mode '{$mode}', falling back to 'lazy' mode
2929
30-
monomorphize_unknown_partition_strategy = unknown partitioning strategy
31-
3230
monomorphize_unused_generic_params = item has unused generic parameters
3331
3432
monomorphize_written_to_path = the full type name has been written to '{$path}'

compiler/rustc_monomorphize/src/collector.rs

+12-46
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ use rustc_hir::lang_items::LangItem;
173173
use rustc_middle::mir::interpret::{AllocId, ErrorHandled, GlobalAlloc, Scalar};
174174
use rustc_middle::mir::mono::{InstantiationMode, MonoItem};
175175
use rustc_middle::mir::visit::Visitor as MirVisitor;
176-
use rustc_middle::mir::{self, Local, Location};
176+
use rustc_middle::mir::{self, Location};
177177
use rustc_middle::query::TyCtxtAt;
178178
use rustc_middle::ty::adjustment::{CustomCoerceUnsized, PointerCoercion};
179179
use rustc_middle::ty::print::with_no_trimmed_paths;
@@ -874,14 +874,6 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
874874
self.super_operand(operand, location);
875875
self.check_operand_move_size(operand, location);
876876
}
877-
878-
fn visit_local(
879-
&mut self,
880-
_place_local: Local,
881-
_context: mir::visit::PlaceContext,
882-
_location: Location,
883-
) {
884-
}
885877
}
886878

887879
fn visit_drop_use<'tcx>(
@@ -1220,7 +1212,7 @@ impl<'v> RootCollector<'_, 'v> {
12201212
}
12211213

12221214
fn is_root(&self, def_id: LocalDefId) -> bool {
1223-
!item_requires_monomorphization(self.tcx, def_id)
1215+
!self.tcx.generics_of(def_id).requires_monomorphization(self.tcx)
12241216
&& match self.mode {
12251217
MonoItemCollectionMode::Eager => true,
12261218
MonoItemCollectionMode::Lazy => {
@@ -1283,11 +1275,6 @@ impl<'v> RootCollector<'_, 'v> {
12831275
}
12841276
}
12851277

1286-
fn item_requires_monomorphization(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
1287-
let generics = tcx.generics_of(def_id);
1288-
generics.requires_monomorphization(tcx)
1289-
}
1290-
12911278
#[instrument(level = "debug", skip(tcx, output))]
12921279
fn create_mono_items_for_default_impls<'tcx>(
12931280
tcx: TyCtxt<'tcx>,
@@ -1394,17 +1381,6 @@ fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoIt
13941381
}
13951382
}
13961383

1397-
fn add_assoc_fn<'tcx>(
1398-
tcx: TyCtxt<'tcx>,
1399-
def_id: Option<DefId>,
1400-
fn_ident: Ident,
1401-
skip_move_check_fns: &mut Vec<DefId>,
1402-
) {
1403-
if let Some(def_id) = def_id.and_then(|def_id| assoc_fn_of_type(tcx, def_id, fn_ident)) {
1404-
skip_move_check_fns.push(def_id);
1405-
}
1406-
}
1407-
14081384
fn assoc_fn_of_type<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fn_ident: Ident) -> Option<DefId> {
14091385
for impl_def_id in tcx.inherent_impls(def_id) {
14101386
if let Some(new) = tcx.associated_items(impl_def_id).find_by_name_and_kind(
@@ -1420,26 +1396,16 @@ fn assoc_fn_of_type<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fn_ident: Ident) ->
14201396
}
14211397

14221398
fn build_skip_move_check_fns(tcx: TyCtxt<'_>) -> Vec<DefId> {
1423-
let mut skip_move_check_fns = vec![];
1424-
add_assoc_fn(
1425-
tcx,
1426-
tcx.lang_items().owned_box(),
1427-
Ident::from_str("new"),
1428-
&mut skip_move_check_fns,
1429-
);
1430-
add_assoc_fn(
1431-
tcx,
1432-
tcx.get_diagnostic_item(sym::Arc),
1433-
Ident::from_str("new"),
1434-
&mut skip_move_check_fns,
1435-
);
1436-
add_assoc_fn(
1437-
tcx,
1438-
tcx.get_diagnostic_item(sym::Rc),
1439-
Ident::from_str("new"),
1440-
&mut skip_move_check_fns,
1441-
);
1442-
skip_move_check_fns
1399+
let fns = [
1400+
(tcx.lang_items().owned_box(), "new"),
1401+
(tcx.get_diagnostic_item(sym::Rc), "new"),
1402+
(tcx.get_diagnostic_item(sym::Arc), "new"),
1403+
];
1404+
fns.into_iter()
1405+
.filter_map(|(def_id, fn_name)| {
1406+
def_id.and_then(|def_id| assoc_fn_of_type(tcx, def_id, Ident::from_str(fn_name)))
1407+
})
1408+
.collect::<Vec<_>>()
14431409
}
14441410

14451411
/// Scans the MIR in order to find function calls, closures, and drop-glue.

compiler/rustc_monomorphize/src/errors.rs

-4
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ pub struct LargeAssignmentsLint {
7575
pub limit: u64,
7676
}
7777

78-
#[derive(Diagnostic)]
79-
#[diag(monomorphize_unknown_partition_strategy)]
80-
pub struct UnknownPartitionStrategy;
81-
8278
#[derive(Diagnostic)]
8379
#[diag(monomorphize_symbol_already_defined)]
8480
pub struct SymbolAlreadyDefined {

0 commit comments

Comments
 (0)