Skip to content

Commit 59f4ba9

Browse files
committed
Auto merge of #70040 - Dylan-DPC:rollup-id1k6lz, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - #67335 (Refactor the `Qualif` trait) - #69122 (Backtrace Debug tweaks) - #69520 (Make error message clearer about creating new module) - #69738 (More Method -> AssocFn renaming) - #69867 (Add long error explanation for E0628 ) - #69989 (resolve/hygiene: `macro_rules` are not "legacy") - #70036 (Make article_and_description primarily use def_kind) Failed merges: r? @ghost
2 parents 8e6de32 + d8dbb3c commit 59f4ba9

File tree

82 files changed

+694
-579
lines changed

Some content is hidden

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

82 files changed

+694
-579
lines changed

src/librustc/hir/map/blocks.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl MaybeFnLike for hir::Item<'_> {
5151
impl MaybeFnLike for hir::ImplItem<'_> {
5252
fn is_fn_like(&self) -> bool {
5353
match self.kind {
54-
hir::ImplItemKind::Method(..) => true,
54+
hir::ImplItemKind::Fn(..) => true,
5555
_ => false,
5656
}
5757
}
@@ -60,7 +60,7 @@ impl MaybeFnLike for hir::ImplItem<'_> {
6060
impl MaybeFnLike for hir::TraitItem<'_> {
6161
fn is_fn_like(&self) -> bool {
6262
match self.kind {
63-
hir::TraitItemKind::Fn(_, hir::TraitMethod::Provided(_)) => true,
63+
hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(_)) => true,
6464
_ => false,
6565
}
6666
}
@@ -239,13 +239,13 @@ impl<'a> FnLikeNode<'a> {
239239
_ => bug!("item FnLikeNode that is not fn-like"),
240240
},
241241
Node::TraitItem(ti) => match ti.kind {
242-
hir::TraitItemKind::Fn(ref sig, hir::TraitMethod::Provided(body)) => {
242+
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
243243
method(ti.hir_id, ti.ident, sig, None, body, ti.span, &ti.attrs)
244244
}
245245
_ => bug!("trait method FnLikeNode that is not fn-like"),
246246
},
247247
Node::ImplItem(ii) => match ii.kind {
248-
hir::ImplItemKind::Method(ref sig, body) => {
248+
hir::ImplItemKind::Fn(ref sig, body) => {
249249
method(ii.hir_id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
250250
}
251251
_ => bug!("impl method FnLikeNode that is not fn-like"),

src/librustc/hir/map/mod.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn fn_decl<'hir>(node: Node<'hir>) -> Option<&'hir FnDecl<'hir>> {
5656
},
5757

5858
Node::ImplItem(ref item) => match item.kind {
59-
ImplItemKind::Method(ref sig, _) => Some(&sig.decl),
59+
ImplItemKind::Fn(ref sig, _) => Some(&sig.decl),
6060
_ => None,
6161
},
6262

@@ -82,7 +82,7 @@ fn fn_sig<'hir>(node: Node<'hir>) -> Option<&'hir FnSig<'hir>> {
8282
},
8383

8484
Node::ImplItem(item) => match &item.kind {
85-
ImplItemKind::Method(sig, _) => Some(sig),
85+
ImplItemKind::Fn(sig, _) => Some(sig),
8686
_ => None,
8787
},
8888

@@ -100,13 +100,14 @@ fn associated_body<'hir>(node: Node<'hir>) -> Option<BodyId> {
100100
},
101101

102102
Node::TraitItem(item) => match item.kind {
103-
TraitItemKind::Const(_, Some(body))
104-
| TraitItemKind::Fn(_, TraitMethod::Provided(body)) => Some(body),
103+
TraitItemKind::Const(_, Some(body)) | TraitItemKind::Fn(_, TraitFn::Provided(body)) => {
104+
Some(body)
105+
}
105106
_ => None,
106107
},
107108

108109
Node::ImplItem(item) => match item.kind {
109-
ImplItemKind::Const(_, body) | ImplItemKind::Method(_, body) => Some(body),
110+
ImplItemKind::Const(_, body) | ImplItemKind::Fn(_, body) => Some(body),
110111
_ => None,
111112
},
112113

@@ -299,7 +300,7 @@ impl<'hir> Map<'hir> {
299300
},
300301
Node::ImplItem(item) => match item.kind {
301302
ImplItemKind::Const(..) => DefKind::AssocConst,
302-
ImplItemKind::Method(..) => DefKind::AssocFn,
303+
ImplItemKind::Fn(..) => DefKind::AssocFn,
303304
ImplItemKind::TyAlias(..) => DefKind::AssocTy,
304305
ImplItemKind::OpaqueTy(..) => DefKind::AssocOpaqueTy,
305306
},
@@ -443,7 +444,7 @@ impl<'hir> Map<'hir> {
443444
Node::Ctor(..)
444445
| Node::Item(&Item { kind: ItemKind::Fn(..), .. })
445446
| Node::TraitItem(&TraitItem { kind: TraitItemKind::Fn(..), .. })
446-
| Node::ImplItem(&ImplItem { kind: ImplItemKind::Method(..), .. }) => BodyOwnerKind::Fn,
447+
| Node::ImplItem(&ImplItem { kind: ImplItemKind::Fn(..), .. }) => BodyOwnerKind::Fn,
447448
Node::Item(&Item { kind: ItemKind::Static(_, m, _), .. }) => BodyOwnerKind::Static(m),
448449
Node::Expr(&Expr { kind: ExprKind::Closure(..), .. }) => BodyOwnerKind::Closure,
449450
node => bug!("{:#?} is not a body node", node),
@@ -749,7 +750,7 @@ impl<'hir> Map<'hir> {
749750
_ => false,
750751
},
751752
Node::ImplItem(ii) => match ii.kind {
752-
ImplItemKind::Method(..) => true,
753+
ImplItemKind::Fn(..) => true,
753754
_ => false,
754755
},
755756
Node::Block(_) => true,
@@ -1110,7 +1111,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
11101111
ImplItemKind::Const(..) => {
11111112
format!("assoc const {} in {}{}", ii.ident, path_str(), id_str)
11121113
}
1113-
ImplItemKind::Method(..) => format!("method {} in {}{}", ii.ident, path_str(), id_str),
1114+
ImplItemKind::Fn(..) => format!("method {} in {}{}", ii.ident, path_str(), id_str),
11141115
ImplItemKind::TyAlias(_) => {
11151116
format!("assoc type {} in {}{}", ii.ident, path_str(), id_str)
11161117
}

src/librustc/ty/context.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -1520,20 +1520,21 @@ impl<'tcx> TyCtxt<'tcx> {
15201520

15211521
/// Returns a displayable description and article for the given `def_id` (e.g. `("a", "struct")`).
15221522
pub fn article_and_description(&self, def_id: DefId) -> (&'static str, &'static str) {
1523-
match self.def_key(def_id).disambiguated_data.data {
1524-
DefPathData::TypeNs(..) | DefPathData::ValueNs(..) | DefPathData::MacroNs(..) => {
1525-
let kind = self.def_kind(def_id).unwrap();
1526-
(kind.article(), kind.descr(def_id))
1527-
}
1528-
DefPathData::ClosureExpr => match self.generator_kind(def_id) {
1529-
None => ("a", "closure"),
1530-
Some(rustc_hir::GeneratorKind::Async(..)) => ("an", "async closure"),
1531-
Some(rustc_hir::GeneratorKind::Gen) => ("a", "generator"),
1532-
},
1533-
DefPathData::LifetimeNs(..) => ("a", "lifetime"),
1534-
DefPathData::Impl => ("an", "implementation"),
1535-
_ => bug!("article_and_description called on def_id {:?}", def_id),
1536-
}
1523+
self.def_kind(def_id)
1524+
.map(|def_kind| (def_kind.article(), def_kind.descr(def_id)))
1525+
.unwrap_or_else(|| match self.def_key(def_id).disambiguated_data.data {
1526+
DefPathData::ClosureExpr => match self.generator_kind(def_id) {
1527+
None => ("a", "closure"),
1528+
Some(rustc_hir::GeneratorKind::Async(..)) => ("an", "async closure"),
1529+
Some(rustc_hir::GeneratorKind::Gen) => ("a", "generator"),
1530+
},
1531+
DefPathData::LifetimeNs(..) => ("a", "lifetime"),
1532+
DefPathData::Impl => ("an", "implementation"),
1533+
DefPathData::TypeNs(..) | DefPathData::ValueNs(..) | DefPathData::MacroNs(..) => {
1534+
unreachable!()
1535+
}
1536+
_ => bug!("article_and_description called on def_id {:?}", def_id),
1537+
})
15371538
}
15381539
}
15391540

src/librustc/ty/mod.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -3083,7 +3083,7 @@ impl<'tcx> TyCtxt<'tcx> {
30833083
pub fn hygienic_eq(self, use_name: Ident, def_name: Ident, def_parent_def_id: DefId) -> bool {
30843084
// We could use `Ident::eq` here, but we deliberately don't. The name
30853085
// comparison fails frequently, and we want to avoid the expensive
3086-
// `modern()` calls required for the span comparison whenever possible.
3086+
// `normalize_to_macros_2_0()` calls required for the span comparison whenever possible.
30873087
use_name.name == def_name.name
30883088
&& use_name
30893089
.span
@@ -3099,7 +3099,7 @@ impl<'tcx> TyCtxt<'tcx> {
30993099
}
31003100

31013101
pub fn adjust_ident(self, mut ident: Ident, scope: DefId) -> Ident {
3102-
ident.span.modernize_and_adjust(self.expansion_that_defined(scope));
3102+
ident.span.normalize_to_macros_2_0_and_adjust(self.expansion_that_defined(scope));
31033103
ident
31043104
}
31053105

@@ -3109,12 +3109,14 @@ impl<'tcx> TyCtxt<'tcx> {
31093109
scope: DefId,
31103110
block: hir::HirId,
31113111
) -> (Ident, DefId) {
3112-
let scope = match ident.span.modernize_and_adjust(self.expansion_that_defined(scope)) {
3113-
Some(actual_expansion) => {
3114-
self.hir().definitions().parent_module_of_macro_def(actual_expansion)
3115-
}
3116-
None => self.parent_module(block),
3117-
};
3112+
let scope =
3113+
match ident.span.normalize_to_macros_2_0_and_adjust(self.expansion_that_defined(scope))
3114+
{
3115+
Some(actual_expansion) => {
3116+
self.hir().definitions().parent_module_of_macro_def(actual_expansion)
3117+
}
3118+
None => self.parent_module(block),
3119+
};
31183120
(ident, scope)
31193121
}
31203122

src/librustc_ast/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ impl MacDelimiter {
14501450
pub struct MacroDef {
14511451
pub body: P<MacArgs>,
14521452
/// `true` if macro was defined with `macro_rules`.
1453-
pub legacy: bool,
1453+
pub macro_rules: bool,
14541454
}
14551455

14561456
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy, Hash, Eq, PartialEq)]

src/librustc_ast/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ pub fn noop_visit_mac<T: MutVisitor>(mac: &mut MacCall, vis: &mut T) {
591591
}
592592

593593
pub fn noop_visit_macro_def<T: MutVisitor>(macro_def: &mut MacroDef, vis: &mut T) {
594-
let MacroDef { body, legacy: _ } = macro_def;
594+
let MacroDef { body, macro_rules: _ } = macro_def;
595595
visit_mac_args(body, vis);
596596
}
597597

src/librustc_ast_lowering/item.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
115115
_ => &[],
116116
};
117117
let lt_def_names = parent_generics.iter().filter_map(|param| match param.kind {
118-
hir::GenericParamKind::Lifetime { .. } => Some(param.name.modern()),
118+
hir::GenericParamKind::Lifetime { .. } => Some(param.name.normalize_to_macros_2_0()),
119119
_ => None,
120120
});
121121
self.in_scope_lifetimes.extend(lt_def_names);
@@ -220,8 +220,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
220220
let mut vis = self.lower_visibility(&i.vis, None);
221221
let attrs = self.lower_attrs(&i.attrs);
222222

223-
if let ItemKind::MacroDef(MacroDef { ref body, legacy }) = i.kind {
224-
if !legacy || attr::contains_name(&i.attrs, sym::macro_export) {
223+
if let ItemKind::MacroDef(MacroDef { ref body, macro_rules }) = i.kind {
224+
if !macro_rules || attr::contains_name(&i.attrs, sym::macro_export) {
225225
let hir_id = self.lower_node_id(i.id);
226226
let body = P(self.lower_mac_args(body));
227227
self.exported_macros.push(hir::MacroDef {
@@ -230,7 +230,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
230230
attrs,
231231
hir_id,
232232
span: i.span,
233-
ast: MacroDef { body, legacy },
233+
ast: MacroDef { body, macro_rules },
234234
});
235235
} else {
236236
self.non_exported_macro_attrs.extend(attrs.iter().cloned());
@@ -761,13 +761,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
761761
let names = self.lower_fn_params_to_names(&sig.decl);
762762
let (generics, sig) =
763763
self.lower_method_sig(generics, sig, trait_item_def_id, false, None);
764-
(generics, hir::TraitItemKind::Fn(sig, hir::TraitMethod::Required(names)))
764+
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Required(names)))
765765
}
766766
AssocItemKind::Fn(_, ref sig, ref generics, Some(ref body)) => {
767767
let body_id = self.lower_fn_body_block(i.span, &sig.decl, Some(body));
768768
let (generics, sig) =
769769
self.lower_method_sig(generics, sig, trait_item_def_id, false, None);
770-
(generics, hir::TraitItemKind::Fn(sig, hir::TraitMethod::Provided(body_id)))
770+
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Provided(body_id)))
771771
}
772772
AssocItemKind::TyAlias(_, ref generics, ref bounds, ref default) => {
773773
let ty = default.as_ref().map(|x| self.lower_ty(x, ImplTraitContext::disallowed()));
@@ -838,7 +838,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
838838
asyncness.opt_return_id(),
839839
);
840840

841-
(generics, hir::ImplItemKind::Method(sig, body_id))
841+
(generics, hir::ImplItemKind::Fn(sig, body_id))
842842
}
843843
AssocItemKind::TyAlias(_, generics, _, ty) => {
844844
let generics = self.lower_generics(generics, ImplTraitContext::disallowed());

src/librustc_ast_lowering/lib.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ struct LoweringContext<'a, 'hir: 'a> {
153153
/// against this list to see if it is already in-scope, or if a definition
154154
/// needs to be created for it.
155155
///
156-
/// We always store a `modern()` version of the param-name in this
156+
/// We always store a `normalize_to_macros_2_0()` version of the param-name in this
157157
/// vector.
158158
in_scope_lifetimes: Vec<ParamName>,
159159

@@ -803,14 +803,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
803803
return;
804804
}
805805

806-
if self.in_scope_lifetimes.contains(&ParamName::Plain(ident.modern())) {
806+
if self.in_scope_lifetimes.contains(&ParamName::Plain(ident.normalize_to_macros_2_0())) {
807807
return;
808808
}
809809

810810
let hir_name = ParamName::Plain(ident);
811811

812-
if self.lifetimes_to_define.iter().any(|(_, lt_name)| lt_name.modern() == hir_name.modern())
813-
{
812+
if self.lifetimes_to_define.iter().any(|(_, lt_name)| {
813+
lt_name.normalize_to_macros_2_0() == hir_name.normalize_to_macros_2_0()
814+
}) {
814815
return;
815816
}
816817

@@ -838,7 +839,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
838839
) -> T {
839840
let old_len = self.in_scope_lifetimes.len();
840841
let lt_def_names = params.iter().filter_map(|param| match param.kind {
841-
GenericParamKind::Lifetime { .. } => Some(ParamName::Plain(param.ident.modern())),
842+
GenericParamKind::Lifetime { .. } => {
843+
Some(ParamName::Plain(param.ident.normalize_to_macros_2_0()))
844+
}
842845
_ => None,
843846
});
844847
self.in_scope_lifetimes.extend(lt_def_names);

src/librustc_ast_passes/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
366366
gate_feature_post!(&self, trait_alias, i.span, "trait aliases are experimental");
367367
}
368368

369-
ast::ItemKind::MacroDef(ast::MacroDef { legacy: false, .. }) => {
369+
ast::ItemKind::MacroDef(ast::MacroDef { macro_rules: false, .. }) => {
370370
let msg = "`macro` is experimental";
371371
gate_feature_post!(&self, decl_macro, i.span, msg);
372372
}

src/librustc_ast_pretty/pprust.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ impl<'a> State<'a> {
12381238
}
12391239
}
12401240
ast::ItemKind::MacroDef(ref macro_def) => {
1241-
let (kw, has_bang) = if macro_def.legacy {
1241+
let (kw, has_bang) = if macro_def.macro_rules {
12421242
("macro_rules", true)
12431243
} else {
12441244
self.print_visibility(&item.vis);

src/librustc_attr/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ pub enum TransparencyError {
10241024

10251025
pub fn find_transparency(
10261026
attrs: &[Attribute],
1027-
is_legacy: bool,
1027+
macro_rules: bool,
10281028
) -> (Transparency, Option<TransparencyError>) {
10291029
let mut transparency = None;
10301030
let mut error = None;
@@ -1049,7 +1049,7 @@ pub fn find_transparency(
10491049
}
10501050
}
10511051
}
1052-
let fallback = if is_legacy { Transparency::SemiTransparent } else { Transparency::Opaque };
1052+
let fallback = if macro_rules { Transparency::SemiTransparent } else { Transparency::Opaque };
10531053
(transparency.map_or(fallback, |t| t.0), error)
10541054
}
10551055

src/librustc_codegen_ssa/back/symbol_export.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn reachable_non_generics_provider(
8888
// Only consider nodes that actually have exported symbols.
8989
Node::Item(&hir::Item { kind: hir::ItemKind::Static(..), .. })
9090
| Node::Item(&hir::Item { kind: hir::ItemKind::Fn(..), .. })
91-
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Method(..), .. }) => {
91+
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }) => {
9292
let def_id = tcx.hir().local_def_id(hir_id);
9393
let generics = tcx.generics_of(def_id);
9494
if !generics.requires_monomorphization(tcx) &&

src/librustc_error_codes/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ E0623: include_str!("./error_codes/E0623.md"),
349349
E0624: include_str!("./error_codes/E0624.md"),
350350
E0626: include_str!("./error_codes/E0626.md"),
351351
E0627: include_str!("./error_codes/E0627.md"),
352+
E0628: include_str!("./error_codes/E0628.md"),
352353
E0631: include_str!("./error_codes/E0631.md"),
353354
E0633: include_str!("./error_codes/E0633.md"),
354355
E0634: include_str!("./error_codes/E0634.md"),
@@ -583,7 +584,6 @@ E0748: include_str!("./error_codes/E0748.md"),
583584
// E0612, // merged into E0609
584585
// E0613, // Removed (merged with E0609)
585586
E0625, // thread-local statics cannot be accessed at compile-time
586-
E0628, // generators cannot have explicit parameters
587587
E0629, // missing 'feature' (rustc_const_unstable)
588588
// rustc_const_unstable attribute must be paired with stable/unstable
589589
// attribute
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
More than one parameter was used for a generator.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0628
6+
#![feature(generators, generator_trait)]
7+
8+
fn main() {
9+
let generator = |a: i32, b: i32| {
10+
// error: too many parameters for a generator
11+
// Allowed only 0 or 1 parameter
12+
yield a;
13+
};
14+
}
15+
```
16+
17+
At present, it is not permitted to pass more than one explicit
18+
parameter for a generator.This can be fixed by using
19+
at most 1 parameter for the generator. For example, we might resolve
20+
the previous example by passing only one parameter.
21+
22+
```
23+
#![feature(generators, generator_trait)]
24+
25+
fn main() {
26+
let generator = |a: i32| {
27+
yield a;
28+
};
29+
}
30+
```

0 commit comments

Comments
 (0)