Skip to content

Commit 9323499

Browse files
committed
Auto merge of #57755 - Centril:rollup, r=Centril
Rollup of 7 pull requests Successful merges: - #57486 (Simplify `TokenStream` some more) - #57502 (make trait-aliases work across crates) - #57598 (Add missing unpretty option help message) - #57649 (privacy: Account for associated existential types) - #57659 (Fix release manifest generation) - #57699 (add applicability to remaining suggestions) - #57719 (Tweak `expand_node`) Failed merges: r? @ghost
2 parents 286ac62 + 92fecfb commit 9323499

Some content is hidden

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

44 files changed

+477
-308
lines changed

src/librustc/hir/map/def_collector.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
120120
let def_data = match i.node {
121121
ItemKind::Impl(..) => DefPathData::Impl,
122122
ItemKind::Trait(..) => DefPathData::Trait(i.ident.as_interned_str()),
123+
ItemKind::TraitAlias(..) => DefPathData::TraitAlias(i.ident.as_interned_str()),
123124
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) |
124-
ItemKind::TraitAlias(..) | ItemKind::Existential(..) |
125-
ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) | ItemKind::Ty(..) =>
126-
DefPathData::TypeNs(i.ident.as_interned_str()),
125+
ItemKind::Existential(..) | ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) |
126+
ItemKind::Ty(..) => DefPathData::TypeNs(i.ident.as_interned_str()),
127127
ItemKind::Mod(..) if i.ident == keywords::Invalid.ident() => {
128128
return visit::walk_item(self, i);
129129
}

src/librustc/hir/map/definitions.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,9 @@ pub enum DefPathData {
373373
/// GlobalMetaData identifies a piece of crate metadata that is global to
374374
/// a whole crate (as opposed to just one item). GlobalMetaData components
375375
/// are only supposed to show up right below the crate root.
376-
GlobalMetaData(InternedString)
376+
GlobalMetaData(InternedString),
377+
/// A trait alias.
378+
TraitAlias(InternedString),
377379
}
378380

379381
#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug,
@@ -615,6 +617,7 @@ impl DefPathData {
615617
match *self {
616618
TypeNs(name) |
617619
Trait(name) |
620+
TraitAlias(name) |
618621
AssocTypeInTrait(name) |
619622
AssocTypeInImpl(name) |
620623
AssocExistentialInImpl(name) |
@@ -642,6 +645,7 @@ impl DefPathData {
642645
let s = match *self {
643646
TypeNs(name) |
644647
Trait(name) |
648+
TraitAlias(name) |
645649
AssocTypeInTrait(name) |
646650
AssocTypeInImpl(name) |
647651
AssocExistentialInImpl(name) |

src/librustc/hir/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub use self::PrimTy::*;
1010
pub use self::UnOp::*;
1111
pub use self::UnsafeSource::*;
1212

13+
use errors::FatalError;
1314
use hir::def::Def;
1415
use hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
1516
use util::nodemap::{NodeMap, FxHashSet};
@@ -2055,6 +2056,20 @@ pub struct TraitRef {
20552056
pub hir_ref_id: HirId,
20562057
}
20572058

2059+
impl TraitRef {
2060+
/// Get the `DefId` of the referenced trait. It _must_ actually be a trait or trait alias.
2061+
pub fn trait_def_id(&self) -> DefId {
2062+
match self.path.def {
2063+
Def::Trait(did) => did,
2064+
Def::TraitAlias(did) => did,
2065+
Def::Err => {
2066+
FatalError.raise();
2067+
}
2068+
_ => unreachable!(),
2069+
}
2070+
}
2071+
}
2072+
20582073
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
20592074
pub struct PolyTraitRef {
20602075
/// The `'a` in `<'a> Foo<&'a T>`

src/librustc/ich/impls_syntax.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ for tokenstream::TokenTree {
258258
tokenstream::TokenTree::Delimited(span, delim, ref tts) => {
259259
span.hash_stable(hcx, hasher);
260260
std_hash::Hash::hash(&delim, hasher);
261-
for sub_tt in tts.stream().trees() {
261+
for sub_tt in tts.trees() {
262262
sub_tt.hash_stable(hcx, hasher);
263263
}
264264
}

src/librustc/infer/lexical_region_resolve/mod.rs

+20-16
Original file line numberDiff line numberDiff line change
@@ -186,34 +186,39 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
186186
}
187187

188188
fn expansion(&self, var_values: &mut LexicalRegionResolutions<'tcx>) {
189-
self.iterate_until_fixed_point("Expansion", |constraint, origin| {
190-
debug!("expansion: constraint={:?} origin={:?}", constraint, origin);
191-
match *constraint {
189+
self.iterate_until_fixed_point("Expansion", |constraint| {
190+
debug!("expansion: constraint={:?}", constraint);
191+
let (a_region, b_vid, b_data, retain) = match *constraint {
192192
Constraint::RegSubVar(a_region, b_vid) => {
193193
let b_data = var_values.value_mut(b_vid);
194-
(self.expand_node(a_region, b_vid, b_data), false)
194+
(a_region, b_vid, b_data, false)
195195
}
196196
Constraint::VarSubVar(a_vid, b_vid) => match *var_values.value(a_vid) {
197-
VarValue::ErrorValue => (false, false),
197+
VarValue::ErrorValue => return (false, false),
198198
VarValue::Value(a_region) => {
199-
let b_node = var_values.value_mut(b_vid);
200-
let changed = self.expand_node(a_region, b_vid, b_node);
201-
let retain = match *b_node {
199+
let b_data = var_values.value_mut(b_vid);
200+
let retain = match *b_data {
202201
VarValue::Value(ReStatic) | VarValue::ErrorValue => false,
203202
_ => true
204203
};
205-
(changed, retain)
204+
(a_region, b_vid, b_data, retain)
206205
}
207206
},
208207
Constraint::RegSubReg(..) | Constraint::VarSubReg(..) => {
209208
// These constraints are checked after expansion
210209
// is done, in `collect_errors`.
211-
(false, false)
210+
return (false, false)
212211
}
213-
}
212+
};
213+
214+
let changed = self.expand_node(a_region, b_vid, b_data);
215+
(changed, retain)
214216
})
215217
}
216218

219+
// This function is very hot in some workloads. There's a single callsite
220+
// so always inlining is ok even though it's large.
221+
#[inline(always)]
217222
fn expand_node(
218223
&self,
219224
a_region: Region<'tcx>,
@@ -722,18 +727,17 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
722727
}
723728

724729
fn iterate_until_fixed_point<F>(&self, tag: &str, mut body: F)
725-
where
726-
F: FnMut(&Constraint<'tcx>, &SubregionOrigin<'tcx>) -> (bool, bool),
730+
where F: FnMut(&Constraint<'tcx>) -> (bool, bool),
727731
{
728-
let mut constraints: SmallVec<[_; 16]> = self.data.constraints.iter().collect();
732+
let mut constraints: SmallVec<[_; 16]> = self.data.constraints.keys().collect();
729733
let mut iteration = 0;
730734
let mut changed = true;
731735
while changed {
732736
changed = false;
733737
iteration += 1;
734738
debug!("---- {} Iteration {}{}", "#", tag, iteration);
735-
constraints.retain(|(constraint, origin)| {
736-
let (edge_changed, retain) = body(constraint, origin);
739+
constraints.retain(|constraint| {
740+
let (edge_changed, retain) = body(constraint);
737741
if edge_changed {
738742
debug!("Updated due to constraint {:?}", constraint);
739743
changed = true;

src/librustc/session/config.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1353,10 +1353,15 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
13531353
unpretty: Option<String> = (None, parse_unpretty, [UNTRACKED],
13541354
"Present the input source, unstable (and less-pretty) variants;
13551355
valid types are any of the types for `--pretty`, as well as:
1356+
`expanded`, `expanded,identified`,
1357+
`expanded,hygiene` (with internal representations),
13561358
`flowgraph=<nodeid>` (graphviz formatted flowgraph for node),
1359+
`flowgraph,unlabelled=<nodeid>` (unlabelled graphviz formatted flowgraph for node),
13571360
`everybody_loops` (all function bodies replaced with `loop {}`),
1358-
`hir` (the HIR), `hir,identified`, or
1359-
`hir,typed` (HIR with types for each node)."),
1361+
`hir` (the HIR), `hir,identified`,
1362+
`hir,typed` (HIR with types for each node),
1363+
`hir-tree` (dump the raw HIR),
1364+
`mir` (the MIR), or `mir-cfg` (graphviz formatted MIR)"),
13601365
run_dsymutil: Option<bool> = (None, parse_opt_bool, [TRACKED],
13611366
"run `dsymutil` and delete intermediate object files"),
13621367
ui_testing: bool = (false, parse_bool, [UNTRACKED],

src/librustc/traits/select.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2198,7 +2198,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
21982198

21992199
let def_id = obligation.predicate.def_id();
22002200

2201-
if ty::is_trait_alias(self.tcx(), def_id) {
2201+
if self.tcx().is_trait_alias(def_id) {
22022202
candidates.vec.push(TraitAliasCandidate(def_id.clone()));
22032203
}
22042204

src/librustc/ty/item_path.rs

+1
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
311311
data @ DefPathData::Misc |
312312
data @ DefPathData::TypeNs(..) |
313313
data @ DefPathData::Trait(..) |
314+
data @ DefPathData::TraitAlias(..) |
314315
data @ DefPathData::AssocTypeInTrait(..) |
315316
data @ DefPathData::AssocTypeInImpl(..) |
316317
data @ DefPathData::AssocExistentialInImpl(..) |

src/librustc/ty/mod.rs

-12
Original file line numberDiff line numberDiff line change
@@ -3170,18 +3170,6 @@ pub fn is_impl_trait_defn(tcx: TyCtxt<'_, '_, '_>, def_id: DefId) -> Option<DefI
31703170
None
31713171
}
31723172

3173-
/// Returns `true` if `def_id` is a trait alias.
3174-
pub fn is_trait_alias(tcx: TyCtxt<'_, '_, '_>, def_id: DefId) -> bool {
3175-
if let Some(node_id) = tcx.hir().as_local_node_id(def_id) {
3176-
if let Node::Item(item) = tcx.hir().get(node_id) {
3177-
if let hir::ItemKind::TraitAlias(..) = item.node {
3178-
return true;
3179-
}
3180-
}
3181-
}
3182-
false
3183-
}
3184-
31853173
/// See `ParamEnv` struct definition for details.
31863174
fn param_env<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
31873175
def_id: DefId)

src/librustc/ty/util.rs

+9
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
526526
}
527527
}
528528

529+
/// True if `def_id` refers to a trait alias (i.e., `trait Foo = ...;`).
530+
pub fn is_trait_alias(self, def_id: DefId) -> bool {
531+
if let DefPathData::TraitAlias(_) = self.def_key(def_id).disambiguated_data.data {
532+
true
533+
} else {
534+
false
535+
}
536+
}
537+
529538
/// True if this def-id refers to the implicit constructor for
530539
/// a tuple struct like `struct Foo(u32)`.
531540
pub fn is_struct_constructor(self, def_id: DefId) -> bool {

src/librustc/util/ppaux.rs

+1
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ impl PrintContext {
409409
DefPathData::AssocTypeInImpl(_) |
410410
DefPathData::AssocExistentialInImpl(_) |
411411
DefPathData::Trait(_) |
412+
DefPathData::TraitAlias(_) |
412413
DefPathData::Impl |
413414
DefPathData::TypeNs(_) => {
414415
break;

src/librustc_driver/pretty.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ pub fn parse_pretty(sess: &Session,
123123
sess.fatal(&format!("argument to `unpretty` must be one of `normal`, \
124124
`expanded`, `flowgraph[,unlabelled]=<nodeid>`, \
125125
`identified`, `expanded,identified`, `everybody_loops`, \
126-
`hir`, `hir,identified`, `hir,typed`, or `mir`; got {}",
126+
`hir`, `hir,identified`, `hir,typed`, `hir-tree`, \
127+
`mir` or `mir-cfg`; got {}",
127128
name));
128129
} else {
129130
sess.fatal(&format!("argument to `pretty` must be one of `normal`, `expanded`, \

src/librustc_errors/diagnostic_builder.rs

+56-34
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ pub struct DiagnosticBuilder<'a> {
3333
/// it easy to declare such methods on the builder.
3434
macro_rules! forward {
3535
// Forward pattern for &self -> &Self
36-
(pub fn $n:ident(&self, $($name:ident: $ty:ty),* $(,)*) -> &Self) => {
36+
(
37+
$(#[$attrs:meta])*
38+
pub fn $n:ident(&self, $($name:ident: $ty:ty),* $(,)*) -> &Self
39+
) => {
40+
$(#[$attrs])*
3741
pub fn $n(&self, $($name: $ty),*) -> &Self {
3842
#[allow(deprecated)]
3943
self.diagnostic.$n($($name),*);
@@ -42,7 +46,11 @@ macro_rules! forward {
4246
};
4347

4448
// Forward pattern for &mut self -> &mut Self
45-
(pub fn $n:ident(&mut self, $($name:ident: $ty:ty),* $(,)*) -> &mut Self) => {
49+
(
50+
$(#[$attrs:meta])*
51+
pub fn $n:ident(&mut self, $($name:ident: $ty:ty),* $(,)*) -> &mut Self
52+
) => {
53+
$(#[$attrs])*
4654
pub fn $n(&mut self, $($name: $ty),*) -> &mut Self {
4755
#[allow(deprecated)]
4856
self.diagnostic.$n($($name),*);
@@ -52,10 +60,15 @@ macro_rules! forward {
5260

5361
// Forward pattern for &mut self -> &mut Self, with S: Into<MultiSpan>
5462
// type parameter. No obvious way to make this more generic.
55-
(pub fn $n:ident<S: Into<MultiSpan>>(
56-
&mut self,
57-
$($name:ident: $ty:ty),*
58-
$(,)*) -> &mut Self) => {
63+
(
64+
$(#[$attrs:meta])*
65+
pub fn $n:ident<S: Into<MultiSpan>>(
66+
&mut self,
67+
$($name:ident: $ty:ty),*
68+
$(,)*
69+
) -> &mut Self
70+
) => {
71+
$(#[$attrs])*
5972
pub fn $n<S: Into<MultiSpan>>(&mut self, $($name: $ty),*) -> &mut Self {
6073
#[allow(deprecated)]
6174
self.diagnostic.$n($($name),*);
@@ -177,34 +190,43 @@ impl<'a> DiagnosticBuilder<'a> {
177190
msg: &str,
178191
) -> &mut Self);
179192

180-
#[deprecated(note = "Use `span_suggestion_short_with_applicability`")]
181-
forward!(pub fn span_suggestion_short(
182-
&mut self,
183-
sp: Span,
184-
msg: &str,
185-
suggestion: String,
186-
) -> &mut Self);
187-
188-
#[deprecated(note = "Use `multipart_suggestion_with_applicability`")]
189-
forward!(pub fn multipart_suggestion(
190-
&mut self,
191-
msg: &str,
192-
suggestion: Vec<(Span, String)>,
193-
) -> &mut Self);
194-
195-
#[deprecated(note = "Use `span_suggestion_with_applicability`")]
196-
forward!(pub fn span_suggestion(&mut self,
197-
sp: Span,
198-
msg: &str,
199-
suggestion: String,
200-
) -> &mut Self);
201-
202-
#[deprecated(note = "Use `span_suggestions_with_applicability`")]
203-
forward!(pub fn span_suggestions(&mut self,
204-
sp: Span,
205-
msg: &str,
206-
suggestions: Vec<String>,
207-
) -> &mut Self);
193+
forward!(
194+
#[deprecated(note = "Use `span_suggestion_short_with_applicability`")]
195+
pub fn span_suggestion_short(
196+
&mut self,
197+
sp: Span,
198+
msg: &str,
199+
suggestion: String,
200+
) -> &mut Self
201+
);
202+
203+
forward!(
204+
#[deprecated(note = "Use `multipart_suggestion_with_applicability`")]
205+
pub fn multipart_suggestion(
206+
&mut self,
207+
msg: &str,
208+
suggestion: Vec<(Span, String)>,
209+
) -> &mut Self
210+
);
211+
212+
forward!(
213+
#[deprecated(note = "Use `span_suggestion_with_applicability`")]
214+
pub fn span_suggestion(
215+
&mut self,
216+
sp: Span,
217+
msg: &str,
218+
suggestion: String,
219+
) -> &mut Self
220+
);
221+
222+
forward!(
223+
#[deprecated(note = "Use `span_suggestions_with_applicability`")]
224+
pub fn span_suggestions(&mut self,
225+
sp: Span,
226+
msg: &str,
227+
suggestions: Vec<String>,
228+
) -> &mut Self
229+
);
208230

209231
pub fn multipart_suggestion_with_applicability(&mut self,
210232
msg: &str,

src/librustc_lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ impl KeywordIdents {
14741474
_ => {},
14751475
}
14761476
TokenTree::Delimited(_, _, tts) => {
1477-
self.check_tokens(cx, tts.stream())
1477+
self.check_tokens(cx, tts)
14781478
},
14791479
}
14801480
}

0 commit comments

Comments
 (0)