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 14 pull requests #81102

Closed
wants to merge 108 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
c06793b
Add Roadmap for 2021
flip1995 Dec 15, 2020
469281c
Check if never type feature is enabled by TyCtxt before suggesting em…
nahuakang Dec 28, 2020
83a458a
Enable never type in empty enum ui test; run cargo dev bless
nahuakang Dec 28, 2020
275988c
Add additional lint doc to known problems section
nahuakang Dec 28, 2020
af480a6
Ensure `Copy` exception in trait definition for `wrong_self_conventio…
ThibsG Dec 30, 2020
0afe2db
Update CHANGELOG for Rust 1.50
phansch Dec 30, 2020
b81111b
Address review comments
phansch Dec 30, 2020
6b37932
Fix blessing of test output in subdirectories
phansch Dec 31, 2020
6909055
s/test_dir/test_suite_dir
phansch Dec 31, 2020
5d48b91
field_reassign_with_default: don't expand macros in suggestion
matthiaskrgr Jan 1, 2021
ba4bf4f
Merge commit '1fcc74cc9e03bc91eaa80ecf92976b0b14b3aeb6' into clippyup
flip1995 Jan 2, 2021
1853f8b
Add lint
Jarcho Jan 2, 2021
78f6009
Auto merge of #6520 - phansch:update-changelog, r=flip1995
bors Jan 2, 2021
053afe4
Use bootstrap rustc for versioncheck in Clippy
flip1995 Jan 2, 2021
9427e03
Fix clone_on_copy test
Jarcho Jan 2, 2021
d37ee6f
Fix lint errors
Jarcho Jan 2, 2021
b498870
use hir::Place instead of Symbol in closure_kind_origin
roxelo Dec 3, 2020
592f7eb
Auto merge of #6531 - matthiaskrgr:6522, r=ebroto
bors Jan 2, 2021
a02806e
Auto merge of #6518 - ThibsG:CopyException, r=ebroto
bors Jan 2, 2021
7b5f549
Fix docs: use type inference
Jarcho Jan 3, 2021
8951916
Auto merge of #6525 - phansch:fix-bless-in-subdirs, r=flip1995
bors Jan 4, 2021
d141cdc
Add prioritization chapter and remove unresolved questions
flip1995 Jan 4, 2021
6dcec6a
collapsible_if: split collapsible_else_if into its own lint so we can…
matthiaskrgr Jan 4, 2021
dd1929e
Auto merge of #6544 - matthiaskrgr:else_if, r=flip1995
bors Jan 4, 2021
ba87acb
Implemented needless question mark lint
bengsparks Dec 26, 2020
ae9ae97
Auto merge of #6507 - bengsparks:lint/issue6410, r=flip1995
bors Jan 4, 2021
7acfa44
Add ui-internal to cargo dev bless
camsteffen Dec 31, 2020
cbbb188
Bless only updated since clippy build
camsteffen Dec 31, 2020
445eb99
Auto merge of #6548 - camsteffen:bless-internal, r=flip1995
bors Jan 4, 2021
bc97f5d
Address flip1995's review comments
nahuakang Jan 4, 2021
a8d47b4
Run cargo dev fmt
nahuakang Jan 4, 2021
976850b
Auto merge of #6538 - Jarcho:vec_init_then_push, r=llogiq
bors Jan 4, 2021
4b478a5
Add a new lint `ptr_as_ptr`,
rail-rain Jan 3, 2021
dfa5d7e
Fix the MSRV and add the tests for MSRV
rail-rain Jan 4, 2021
dd52066
Auto merge of #6547 - camsteffen:curse-outdated, r=phansch
bors Jan 5, 2021
311186b
Auto merge of #6513 - nahuakang:fix/empty_enum_lint_never_type, r=fli…
bors Jan 5, 2021
a6b72d3
Auto merge of #6542 - rail-rain:ptr_as_ptr, r=flip1995
bors Jan 5, 2021
ea885d9
Tiny Symbol cleanup
phansch Jan 5, 2021
42b9e92
Auto merge of #6551 - phansch:tiny-symbol-cleanup, r=flip1995
bors Jan 5, 2021
a8825e9
Use existing 'is_automatically_derived' helper
phansch Jan 5, 2021
03c0e58
Revert "Auto merge of #79637 - spastorino:revert-trait-inheritance-se…
spastorino Dec 3, 2020
92f2bbb
Fix macro issues with field_reassign_with_default
phansch Jan 5, 2021
455a0e1
Use Symbol instead of Ident as an assoc_name to prevent ICEs
spastorino Jan 5, 2021
efccfe8
Auto merge of #6553 - phansch:field-reassign-with-default-macros, r=f…
bors Jan 6, 2021
8a45ffa
Fix typo: `which which can be` -> `which can be`
sozysozbot Jan 6, 2021
8e5c5a6
Auto merge of #6554 - sozysozbot:master, r=flip1995
bors Jan 6, 2021
f50ded0
Catch `pointer::cast` too in `cast_ptr_alignment`
rail-rain Jan 7, 2021
547ce0d
Change env var used for testing Clippy
flip1995 Jan 7, 2021
2b3c0ad
Fix typo: `irrevelent` -> `irrelevant`
stanislav-tkach Jan 7, 2021
e15bef9
Auto merge of #6558 - stanislav-tkach:patch-2, r=flip1995
bors Jan 7, 2021
7d42172
Reintroduce hir::ExprKind::If
c410-f3r Jan 1, 2021
aa9adbf
Small fixes of doc in `needless_question_mark`
giraffate Jan 7, 2021
0e14a75
Reduce the span in `from_over_into` to impl header
giraffate Jan 7, 2021
ee9b47d
Move `is_hir_ty_cfg_dependant` to `util`,
rail-rain Jan 8, 2021
2950c8e
Auto merge of #6566 - giraffate:reduce_the_span_in_from_over_into, r=…
bors Jan 8, 2021
24c700b
Use DefId in interning defined symbol lint
camsteffen Dec 30, 2020
121c65f
Add keywords to interning defined symbol lint
camsteffen Dec 29, 2020
76ccfb4
Fix unnecessary keyword intern dogfood
camsteffen Dec 29, 2020
cc26919
Add unnecessary symbol string lint
camsteffen Dec 30, 2020
7871eba
Fix symbol string comparison dogfood
camsteffen Dec 29, 2020
68bcd20
Auto merge of #6569 - camsteffen:symbol-comparison, r=Manishearth
bors Jan 8, 2021
8a6fea4
Fix FP for `boxed_local` lint in default trait fn impl
ThibsG Jan 9, 2021
ee0598e
Auto merge of #6571 - ThibsG:BoxedLocalTrait, r=phansch
bors Jan 9, 2021
583715f
Auto merge of #6565 - giraffate:small_fixes_of_doc_in_needless_questi…
bors Jan 9, 2021
9e45a23
ast: Remove some indirection layers from values in key-value attributes
petrochenkov Dec 19, 2020
2c6dc88
Rework diagnostics for wrong number of generic args
Patryk27 Jan 2, 2021
1eed27f
Auto merge of #6575 - flip1995:stop_linting_deps, r=Manishearth
bors Jan 11, 2021
b7071b2
resolve: Simplify collection of traits in scope
petrochenkov Jan 6, 2021
53f8731
Simplify `cast_ptr_alignment` `pointer::casr` case
rail-rain Jan 11, 2021
7f4599a
Auto merge of #6557 - rail-rain:extending_cast_ptr_alignment, r=phansch
bors Jan 11, 2021
13ca5c8
Auto merge of #6462 - flip1995:roadmap, r=flip1995,llogiq,killercup,M…
bors Jan 12, 2021
ea02849
Make a reference a link in doc
giraffate Jan 13, 2021
dfb41f4
Separate out a `hir::Impl` struct
jyn514 Nov 22, 2020
00586df
Auto merge of #6584 - giraffate:make_references_to_issues_links, r=ll…
bors Jan 13, 2021
61a6468
Update rust-analyzer
lnicola Jan 13, 2021
dcd8c8e
Auto merge of #77524 - Patryk27:fixes/66228, r=estebank
bors Jan 13, 2021
7b3af41
Auto merge of #79328 - c410-f3r:hir-if, r=matthewjasper
bors Jan 14, 2021
9bd037d
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Jan 15, 2021
0c5ba9a
Bump nightly version to 2021-01-15
flip1995 Jan 15, 2021
f18cf82
Don't trigger needless_return lint in macros
flip1995 Jan 15, 2021
953f024
Auto merge of #6586 - flip1995:rustup, r=flip1995
bors Jan 15, 2021
3e236b3
Merge commit '953f024793dab92745fee9cd2c4dee6a60451771' into clippyup
flip1995 Jan 15, 2021
6766070
Allow downloading LLVM on Windows
jyn514 Jan 12, 2021
5c4adbe
Add all tier 1 platforms to supported platforms for "if-available"
jyn514 Jan 13, 2021
8b702e0
Support non-stage0 check
Mark-Simulacrum Jan 16, 2021
c17ed34
Print which stage is being checked (now that it may not be stage0)
jyn514 Jan 16, 2021
53989e4
Allow configuring the default stage for `x.py check`
jyn514 Jan 16, 2021
50ee0b2
BTreeMap: clean up a few more comments
ssomers Nov 18, 2020
65b5e43
Use PlaceRef more consistently in rustc_mir
oliviacrain Jan 10, 2021
28501c0
rustc_parse_format: Fix character indices in find_skips
osa1 Jan 16, 2021
15f0921
correctly deal with late-bound lifetimes in anon consts
lcnr Nov 22, 2020
76003f3
Use Option::map instead of open-coding it
LingMan Dec 30, 2020
5a706cf
Use Option::unwrap_or instead of open-coding it
LingMan Jan 16, 2021
7f9a2cf
resolve: Reject ambiguity built-in attr vs different built-in attr
petrochenkov Dec 13, 2020
f6f754a
Rollup merge of #79298 - lcnr:new-elysium, r=matthewjasper
m-ou-se Jan 16, 2021
c06ff92
Rollup merge of #80031 - petrochenkov:builtina, r=estebank
m-ou-se Jan 16, 2021
803d616
Rollup merge of #80635 - sexxi-goose:use-place-instead-of-symbol, r=n…
m-ou-se Jan 16, 2021
d2009f0
Rollup merge of #80732 - spastorino:trait-inheritance-self2, r=nikoma…
m-ou-se Jan 16, 2021
589864d
Rollup merge of #80765 - petrochenkov:traitsinscope, r=matthewjasper
m-ou-se Jan 16, 2021
42801b4
Rollup merge of #80865 - oliviacrain:proj_based, r=RalfJung
m-ou-se Jan 16, 2021
b2d8614
Rollup merge of #80932 - jyn514:download-windows-llvm, r=Mark-Simulacrum
m-ou-se Jan 16, 2021
ab62218
Rollup merge of #80984 - lnicola:bump-rust-analyzer, r=jonas-schievink
m-ou-se Jan 16, 2021
f25652d
Rollup merge of #81038 - flip1995:clippyup, r=Manishearth
m-ou-se Jan 16, 2021
85c6462
Rollup merge of #81064 - Mark-Simulacrum:support-stage1-check, r=jyn514
m-ou-se Jan 16, 2021
a5a259f
Rollup merge of #81071 - osa1:fix_81006, r=estebank
m-ou-se Jan 16, 2021
5bc3f8c
Rollup merge of #81082 - ssomers:btree_cleanup_comments, r=Mark-Simul…
m-ou-se Jan 16, 2021
6b66591
Rollup merge of #81084 - LingMan:map, r=oli-obk
m-ou-se Jan 16, 2021
576c3d5
Rollup merge of #81095 - LingMan:unwrap, r=oli-obk
m-ou-se Jan 16, 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
12 changes: 3 additions & 9 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,7 @@ fn handle_native(name: &str) -> &str {
}

pub fn target_cpu(sess: &Session) -> &str {
let name = match sess.opts.cg.target_cpu {
Some(ref s) => &**s,
None => &*sess.target.cpu,
};

let name = sess.opts.cg.target_cpu.as_ref().unwrap_or(&sess.target.cpu);
handle_native(name)
}

Expand Down Expand Up @@ -254,8 +250,6 @@ pub fn handle_native_features(sess: &Session) -> Vec<String> {
}

pub fn tune_cpu(sess: &Session) -> Option<&str> {
match sess.opts.debugging_opts.tune_cpu {
Some(ref s) => Some(handle_native(&**s)),
None => None,
}
let name = sess.opts.debugging_opts.tune_cpu.as_ref()?;
Some(handle_native(name))
}
7 changes: 4 additions & 3 deletions compiler/rustc_hir/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use rustc_ast as ast;
use rustc_ast::NodeId;
use rustc_macros::HashStable_Generic;
use rustc_span::hygiene::MacroKind;
use rustc_span::Symbol;

use std::array::IntoIter;
use std::fmt::Debug;
Expand Down Expand Up @@ -34,7 +35,7 @@ pub enum CtorKind {
#[derive(HashStable_Generic)]
pub enum NonMacroAttrKind {
/// Single-segment attribute defined by the language (`#[inline]`)
Builtin,
Builtin(Symbol),
/// Multi-segment custom attribute living in a "tool module" (`#[rustfmt::skip]`).
Tool,
/// Single-segment custom attribute registered by a derive macro (`#[serde(default)]`).
Expand Down Expand Up @@ -371,7 +372,7 @@ impl CtorKind {
impl NonMacroAttrKind {
pub fn descr(self) -> &'static str {
match self {
NonMacroAttrKind::Builtin => "built-in attribute",
NonMacroAttrKind::Builtin(..) => "built-in attribute",
NonMacroAttrKind::Tool => "tool attribute",
NonMacroAttrKind::DeriveHelper | NonMacroAttrKind::DeriveHelperCompat => {
"derive helper attribute"
Expand All @@ -393,7 +394,7 @@ impl NonMacroAttrKind {
NonMacroAttrKind::Tool
| NonMacroAttrKind::DeriveHelper
| NonMacroAttrKind::DeriveHelperCompat => true,
NonMacroAttrKind::Builtin | NonMacroAttrKind::Registered => false,
NonMacroAttrKind::Builtin(..) | NonMacroAttrKind::Registered => false,
}
}
}
Expand Down
34 changes: 33 additions & 1 deletion compiler/rustc_infer/src/traits/util.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use smallvec::smallvec;

use crate::traits::{Obligation, ObligationCause, PredicateObligation};
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
use rustc_middle::ty::outlives::Component;
use rustc_middle::ty::{self, ToPredicate, TyCtxt, WithConstness};
use rustc_span::symbol::Symbol;

pub fn anonymize_predicate<'tcx>(
tcx: TyCtxt<'tcx>,
Expand Down Expand Up @@ -287,6 +288,37 @@ pub fn transitive_bounds<'tcx>(
elaborate_trait_refs(tcx, bounds).filter_to_traits()
}

/// A specialized variant of `elaborate_trait_refs` that only elaborates trait references that may
/// define the given associated type `assoc_name`. It uses the
/// `super_predicates_that_define_assoc_type` query to avoid enumerating super-predicates that
/// aren't related to `assoc_item`. This is used when resolving types like `Self::Item` or
/// `T::Item` and helps to avoid cycle errors (see e.g. #35237).
pub fn transitive_bounds_that_define_assoc_type<'tcx>(
tcx: TyCtxt<'tcx>,
bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
assoc_name: Symbol,
) -> FxIndexSet<ty::PolyTraitRef<'tcx>> {
let mut stack: Vec<_> = bounds.collect();
let mut trait_refs = FxIndexSet::default();

while let Some(trait_ref) = stack.pop() {
if trait_refs.insert(trait_ref) {
let super_predicates =
tcx.super_predicates_that_define_assoc_type((trait_ref.def_id(), Some(assoc_name)));
for (super_predicate, _) in super_predicates.predicates {
let bound_predicate = super_predicate.bound_atom();
let subst_predicate = super_predicate
.subst_supertrait(tcx, &bound_predicate.rebind(trait_ref.skip_binder()));
if let Some(binder) = subst_predicate.to_opt_poly_trait_ref() {
stack.push(binder.value);
}
}
}
}

trait_refs
}

///////////////////////////////////////////////////////////////////////////
// Other
///////////////////////////////////////////////////////////////////////////
Expand Down
17 changes: 14 additions & 3 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,12 +456,23 @@ rustc_queries! {
/// full predicates are available (note that supertraits have
/// additional acyclicity requirements).
query super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
desc { |tcx| "computing the supertraits of `{}`", tcx.def_path_str(key) }
desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
}

/// The `Option<Symbol>` is the name of an associated type. If it is `None`, then this query
/// returns the full set of predicates. If `Some<Symbol>`, then the query returns only the
/// subset of super-predicates that reference traits that define the given associated type.
/// This is used to avoid cycles in resolving types like `T::Item`.
query super_predicates_that_define_assoc_type(key: (DefId, Option<rustc_span::symbol::Symbol>)) -> ty::GenericPredicates<'tcx> {
desc { |tcx| "computing the super traits of `{}`{}",
tcx.def_path_str(key.0),
if let Some(assoc_name) = key.1 { format!(" with associated type name `{}`", assoc_name) } else { "".to_string() },
}
}

/// To avoid cycles within the predicates of a single item we compute
/// per-type-parameter predicates for resolving `T::AssocTy`.
query type_param_predicates(key: (DefId, LocalDefId)) -> ty::GenericPredicates<'tcx> {
query type_param_predicates(key: (DefId, LocalDefId, rustc_span::symbol::Symbol)) -> ty::GenericPredicates<'tcx> {
desc { |tcx| "computing the bounds for type parameter `{}`", {
let id = tcx.hir().local_def_id_to_hir_id(key.1);
tcx.hir().ty_param_name(id)
Expand Down Expand Up @@ -1316,7 +1327,7 @@ rustc_queries! {
desc { "looking up a named region" }
}
query is_late_bound_map(_: LocalDefId) ->
Option<&'tcx FxHashSet<ItemLocalId>> {
Option<(LocalDefId, &'tcx FxHashSet<ItemLocalId>)> {
desc { "testing if a region is late bound" }
}
query object_lifetime_defaults_map(_: LocalDefId)
Expand Down
49 changes: 45 additions & 4 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate::arena::Arena;
use crate::dep_graph::DepGraph;
use crate::hir::exports::ExportMap;
use crate::hir::place::Place as HirPlace;
use crate::ich::{NodeIdHashingMode, StableHashingContext};
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintLevelSource};
Expand Down Expand Up @@ -379,7 +380,7 @@ pub struct TypeckResults<'tcx> {

/// Records the reasons that we picked the kind of each closure;
/// not all closures are present in the map.
closure_kind_origins: ItemLocalMap<(Span, Symbol)>,
closure_kind_origins: ItemLocalMap<(Span, HirPlace<'tcx>)>,

/// For each fn, records the "liberated" types of its arguments
/// and return type. Liberated means that all bound regions
Expand Down Expand Up @@ -642,11 +643,13 @@ impl<'tcx> TypeckResults<'tcx> {
self.upvar_capture_map[&upvar_id]
}

pub fn closure_kind_origins(&self) -> LocalTableInContext<'_, (Span, Symbol)> {
pub fn closure_kind_origins(&self) -> LocalTableInContext<'_, (Span, HirPlace<'tcx>)> {
LocalTableInContext { hir_owner: self.hir_owner, data: &self.closure_kind_origins }
}

pub fn closure_kind_origins_mut(&mut self) -> LocalTableInContextMut<'_, (Span, Symbol)> {
pub fn closure_kind_origins_mut(
&mut self,
) -> LocalTableInContextMut<'_, (Span, HirPlace<'tcx>)> {
LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.closure_kind_origins }
}

Expand Down Expand Up @@ -2056,6 +2059,43 @@ impl<'tcx> TyCtxt<'tcx> {
self.mk_fn_ptr(sig.map_bound(|sig| ty::FnSig { unsafety: hir::Unsafety::Unsafe, ..sig }))
}

/// Given the def_id of a Trait `trait_def_id` and the name of an associated item `assoc_name`
/// returns true if the `trait_def_id` defines an associated item of name `assoc_name`.
pub fn trait_may_define_assoc_type(self, trait_def_id: DefId, assoc_name: Symbol) -> bool {
self.super_traits_of(trait_def_id).any(|trait_did| {
self.associated_items(trait_did)
.find_by_name_and_kind_unhygienic(assoc_name, ty::AssocKind::Type)
.next()
.is_some()
})
}

/// Computes the def-ids of the transitive super-traits of `trait_def_id`. This (intentionally)
/// does not compute the full elaborated super-predicates but just the set of def-ids. It is used
/// to identify which traits may define a given associated type to help avoid cycle errors.
/// Returns a `DefId` iterator.
fn super_traits_of(self, trait_def_id: DefId) -> impl Iterator<Item = DefId> + 'tcx {
let mut set = FxHashSet::default();
let mut stack = vec![trait_def_id];

set.insert(trait_def_id);

iter::from_fn(move || -> Option<DefId> {
let trait_did = stack.pop()?;
let generic_predicates = self.super_predicates_of(trait_did);

for (predicate, _) in generic_predicates.predicates {
if let ty::PredicateAtom::Trait(data, _) = predicate.skip_binders() {
if set.insert(data.def_id()) {
stack.push(data.def_id());
}
}
}

Some(trait_did)
})
}

/// Given a closure signature, returns an equivalent fn signature. Detuples
/// and so forth -- so e.g., if we have a sig with `Fn<(u32, i32)>` then
/// you would get a `fn(u32, i32)`.
Expand Down Expand Up @@ -2578,7 +2618,8 @@ impl<'tcx> TyCtxt<'tcx> {
}

pub fn is_late_bound(self, id: HirId) -> bool {
self.is_late_bound_map(id.owner).map_or(false, |set| set.contains(&id.local_id))
self.is_late_bound_map(id.owner)
.map_or(false, |(owner, set)| owner == id.owner && set.contains(&id.local_id))
}

pub fn object_lifetime_defaults(self, id: HirId) -> Option<&'tcx [ObjectLifetimeDefault]> {
Expand Down
51 changes: 50 additions & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ pub use self::IntVarValue::*;
pub use self::Variance::*;

use crate::hir::exports::ExportMap;
use crate::hir::place::Place as HirPlace;
use crate::hir::place::{
Place as HirPlace, PlaceBase as HirPlaceBase, ProjectionKind as HirProjectionKind,
};
use crate::ich::StableHashingContext;
use crate::middle::cstore::CrateStoreDyn;
use crate::middle::resolve_lifetime::ObjectLifetimeDefault;
Expand Down Expand Up @@ -318,6 +320,16 @@ impl<'tcx> AssociatedItems<'tcx> {
.find(|item| tcx.hygienic_eq(ident, item.ident, parent_def_id))
}

/// Returns the associated item with the given name and `AssocKind`, if one exists, ignoring
/// hygiene.
pub fn find_by_name_and_kind_unhygienic(
&self,
name: Symbol,
kind: AssocKind,
) -> impl '_ + Iterator<Item = &ty::AssocItem> {
self.filter_by_name_unhygienic(name).filter(move |item| item.kind == kind)
}

/// Returns the associated item with the given name in the given `Namespace`, if one exists.
pub fn find_by_name_and_namespace(
&self,
Expand Down Expand Up @@ -734,6 +746,43 @@ pub struct CapturedPlace<'tcx> {
pub info: CaptureInfo<'tcx>,
}

pub fn place_to_string_for_capture(tcx: TyCtxt<'tcx>, place: &HirPlace<'tcx>) -> String {
let name = match place.base {
HirPlaceBase::Upvar(upvar_id) => tcx.hir().name(upvar_id.var_path.hir_id).to_string(),
_ => bug!("Capture_information should only contain upvars"),
};
let mut curr_string = name;

for (i, proj) in place.projections.iter().enumerate() {
match proj.kind {
HirProjectionKind::Deref => {
curr_string = format!("*{}", curr_string);
}
HirProjectionKind::Field(idx, variant) => match place.ty_before_projection(i).kind() {
ty::Adt(def, ..) => {
curr_string = format!(
"{}.{}",
curr_string,
def.variants[variant].fields[idx as usize].ident.name.as_str()
);
}
ty::Tuple(_) => {
curr_string = format!("{}.{}", curr_string, idx);
}
_ => {
bug!(
"Field projection applied to a type other than Adt or Tuple: {:?}.",
place.ty_before_projection(i).kind()
)
}
},
proj => bug!("{:?} unexpected because it isn't captured", proj),
}
}

curr_string.to_string()
}

/// Part of `MinCaptureInformationMap`; describes the capture kind (&, &mut, move)
/// for a particular capture as well as identifying the part of the source code
/// that triggered this capture to occur.
Expand Down
22 changes: 22 additions & 0 deletions compiler/rustc_middle/src/ty/query/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,28 @@ impl Key for (LocalDefId, DefId) {
}
}

impl Key for (DefId, Option<Symbol>) {
type CacheSelector = DefaultCacheSelector;

fn query_crate(&self) -> CrateNum {
self.0.krate
}
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
tcx.def_span(self.0)
}
}

impl Key for (DefId, LocalDefId, Symbol) {
type CacheSelector = DefaultCacheSelector;

fn query_crate(&self) -> CrateNum {
self.0.krate
}
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
self.1.default_span(tcx)
}
}

impl Key for (CrateNum, DefId) {
type CacheSelector = DefaultCacheSelector;

Expand Down
16 changes: 6 additions & 10 deletions compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1616,28 +1616,25 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {

fn classify_drop_access_kind(&self, place: PlaceRef<'tcx>) -> StorageDeadOrDrop<'tcx> {
let tcx = self.infcx.tcx;
match place.projection {
[] => StorageDeadOrDrop::LocalStorageDead,
[proj_base @ .., elem] => {
match place.last_projection() {
None => StorageDeadOrDrop::LocalStorageDead,
Some((place_base, elem)) => {
// FIXME(spastorino) make this iterate
let base_access = self.classify_drop_access_kind(PlaceRef {
local: place.local,
projection: proj_base,
});
let base_access = self.classify_drop_access_kind(place_base);
match elem {
ProjectionElem::Deref => match base_access {
StorageDeadOrDrop::LocalStorageDead
| StorageDeadOrDrop::BoxedStorageDead => {
assert!(
Place::ty_from(place.local, proj_base, self.body, tcx).ty.is_box(),
place_base.ty(self.body, tcx).ty.is_box(),
"Drop of value behind a reference or raw pointer"
);
StorageDeadOrDrop::BoxedStorageDead
}
StorageDeadOrDrop::Destructor(_) => base_access,
},
ProjectionElem::Field(..) | ProjectionElem::Downcast(..) => {
let base_ty = Place::ty_from(place.local, proj_base, self.body, tcx).ty;
let base_ty = place_base.ty(self.body, tcx).ty;
match base_ty.kind() {
ty::Adt(def, _) if def.has_dtor(tcx) => {
// Report the outermost adt with a destructor
Expand All @@ -1652,7 +1649,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
_ => base_access,
}
}

ProjectionElem::ConstantIndex { .. }
| ProjectionElem::Subslice { .. }
| ProjectionElem::Index(_) => base_access,
Expand Down
Loading