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 7 pull requests #70040

Merged
merged 28 commits into from
Mar 16, 2020
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8de1ec9
Make error message clearer about creating new module
kornelski Feb 27, 2020
3ba89e8
Remove quotes around unknown fn placeholder in backtrace
dtolnay Feb 13, 2020
db75b6a
Add quotes around filename in Backtrace debug
dtolnay Feb 13, 2020
1f1ca87
Change disabled and unsupported backtraces to print using placeholder…
dtolnay Feb 13, 2020
a9cc010
Make it possible to instantiate hardcoded Backtrace from test
dtolnay Feb 13, 2020
33600e4
Add test of Debug representation of Backtrace
dtolnay Feb 13, 2020
a2364dc
Write backtrace fmt test using relative paths
dtolnay Mar 9, 2020
7b75c34
Add long error explanation for E0628 #61137
Mar 9, 2020
1305ae6
Update src/librustc_error_codes/error_codes/E0628.md
ayushmishra2005 Mar 13, 2020
f7fcb58
Update src/librustc_error_codes/error_codes/E0628.md
ayushmishra2005 Mar 13, 2020
00c6abe
Minor change
Mar 13, 2020
c33c88b
Minor change
Mar 13, 2020
6f75d3f
Simplify `Qualif` interface
ecstatic-morse Dec 13, 2019
65bf483
ast/hir: `MacroDef::legacy` -> `MacroDef::macro_rules`
petrochenkov Mar 13, 2020
3fbb254
resolve: `Legacy(Scope,Binding)` -> `MacroRules(Scope,Binding)`
petrochenkov Mar 13, 2020
8c9a38f
Other `legacy` -> `macro_rules`
petrochenkov Mar 13, 2020
db638bd
hygiene: `modern` -> `normalize_to_macros_2_0`
petrochenkov Mar 13, 2020
7bd8ce2
More Method->Fn renaming
mark-i-m Mar 5, 2020
e3c15ae
update comment
mark-i-m Mar 7, 2020
1b92e86
MethodData -> AssocFnData
mark-i-m Mar 15, 2020
2c2d41d
make article_and_description primarily use def_kind
mark-i-m Mar 16, 2020
59b0058
Rollup merge of #67335 - ecstatic-morse:qualif-refactor, r=eddyb
Dylan-DPC Mar 16, 2020
2443eb4
Rollup merge of #69122 - dtolnay:backtrace, r=cramertj
Dylan-DPC Mar 16, 2020
1685264
Rollup merge of #69520 - kornelski:e69492, r=cramertj
Dylan-DPC Mar 16, 2020
0d7c82e
Rollup merge of #69738 - mark-i-m:assoc-fn-2, r=eddyb
Dylan-DPC Mar 16, 2020
8f2482b
Rollup merge of #69867 - ayushmishra2005:doc/61137-add-long-error-cod…
Dylan-DPC Mar 16, 2020
8872d90
Rollup merge of #69989 - petrochenkov:nolegacy, r=eddyb,matthewjasper
Dylan-DPC Mar 16, 2020
d8dbb3c
Rollup merge of #70036 - mark-i-m:describe-it-4, r=eddyb
Dylan-DPC Mar 16, 2020
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
8 changes: 4 additions & 4 deletions src/librustc/hir/map/blocks.rs
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ impl MaybeFnLike for hir::Item<'_> {
impl MaybeFnLike for hir::ImplItem<'_> {
fn is_fn_like(&self) -> bool {
match self.kind {
hir::ImplItemKind::Method(..) => true,
hir::ImplItemKind::Fn(..) => true,
_ => false,
}
}
@@ -60,7 +60,7 @@ impl MaybeFnLike for hir::ImplItem<'_> {
impl MaybeFnLike for hir::TraitItem<'_> {
fn is_fn_like(&self) -> bool {
match self.kind {
hir::TraitItemKind::Fn(_, hir::TraitMethod::Provided(_)) => true,
hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(_)) => true,
_ => false,
}
}
@@ -239,13 +239,13 @@ impl<'a> FnLikeNode<'a> {
_ => bug!("item FnLikeNode that is not fn-like"),
},
Node::TraitItem(ti) => match ti.kind {
hir::TraitItemKind::Fn(ref sig, hir::TraitMethod::Provided(body)) => {
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
method(ti.hir_id, ti.ident, sig, None, body, ti.span, &ti.attrs)
}
_ => bug!("trait method FnLikeNode that is not fn-like"),
},
Node::ImplItem(ii) => match ii.kind {
hir::ImplItemKind::Method(ref sig, body) => {
hir::ImplItemKind::Fn(ref sig, body) => {
method(ii.hir_id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs)
}
_ => bug!("impl method FnLikeNode that is not fn-like"),
19 changes: 10 additions & 9 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ fn fn_decl<'hir>(node: Node<'hir>) -> Option<&'hir FnDecl<'hir>> {
},

Node::ImplItem(ref item) => match item.kind {
ImplItemKind::Method(ref sig, _) => Some(&sig.decl),
ImplItemKind::Fn(ref sig, _) => Some(&sig.decl),
_ => None,
},

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

Node::ImplItem(item) => match &item.kind {
ImplItemKind::Method(sig, _) => Some(sig),
ImplItemKind::Fn(sig, _) => Some(sig),
_ => None,
},

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

Node::TraitItem(item) => match item.kind {
TraitItemKind::Const(_, Some(body))
| TraitItemKind::Fn(_, TraitMethod::Provided(body)) => Some(body),
TraitItemKind::Const(_, Some(body)) | TraitItemKind::Fn(_, TraitFn::Provided(body)) => {
Some(body)
}
_ => None,
},

Node::ImplItem(item) => match item.kind {
ImplItemKind::Const(_, body) | ImplItemKind::Method(_, body) => Some(body),
ImplItemKind::Const(_, body) | ImplItemKind::Fn(_, body) => Some(body),
_ => None,
},

@@ -299,7 +300,7 @@ impl<'hir> Map<'hir> {
},
Node::ImplItem(item) => match item.kind {
ImplItemKind::Const(..) => DefKind::AssocConst,
ImplItemKind::Method(..) => DefKind::AssocFn,
ImplItemKind::Fn(..) => DefKind::AssocFn,
ImplItemKind::TyAlias(..) => DefKind::AssocTy,
ImplItemKind::OpaqueTy(..) => DefKind::AssocOpaqueTy,
},
@@ -443,7 +444,7 @@ impl<'hir> Map<'hir> {
Node::Ctor(..)
| Node::Item(&Item { kind: ItemKind::Fn(..), .. })
| Node::TraitItem(&TraitItem { kind: TraitItemKind::Fn(..), .. })
| Node::ImplItem(&ImplItem { kind: ImplItemKind::Method(..), .. }) => BodyOwnerKind::Fn,
| Node::ImplItem(&ImplItem { kind: ImplItemKind::Fn(..), .. }) => BodyOwnerKind::Fn,
Node::Item(&Item { kind: ItemKind::Static(_, m, _), .. }) => BodyOwnerKind::Static(m),
Node::Expr(&Expr { kind: ExprKind::Closure(..), .. }) => BodyOwnerKind::Closure,
node => bug!("{:#?} is not a body node", node),
@@ -749,7 +750,7 @@ impl<'hir> Map<'hir> {
_ => false,
},
Node::ImplItem(ii) => match ii.kind {
ImplItemKind::Method(..) => true,
ImplItemKind::Fn(..) => true,
_ => false,
},
Node::Block(_) => true,
@@ -1110,7 +1111,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String {
ImplItemKind::Const(..) => {
format!("assoc const {} in {}{}", ii.ident, path_str(), id_str)
}
ImplItemKind::Method(..) => format!("method {} in {}{}", ii.ident, path_str(), id_str),
ImplItemKind::Fn(..) => format!("method {} in {}{}", ii.ident, path_str(), id_str),
ImplItemKind::TyAlias(_) => {
format!("assoc type {} in {}{}", ii.ident, path_str(), id_str)
}
29 changes: 15 additions & 14 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
@@ -1520,20 +1520,21 @@ impl<'tcx> TyCtxt<'tcx> {

/// Returns a displayable description and article for the given `def_id` (e.g. `("a", "struct")`).
pub fn article_and_description(&self, def_id: DefId) -> (&'static str, &'static str) {
match self.def_key(def_id).disambiguated_data.data {
DefPathData::TypeNs(..) | DefPathData::ValueNs(..) | DefPathData::MacroNs(..) => {
let kind = self.def_kind(def_id).unwrap();
(kind.article(), kind.descr(def_id))
}
DefPathData::ClosureExpr => match self.generator_kind(def_id) {
None => ("a", "closure"),
Some(rustc_hir::GeneratorKind::Async(..)) => ("an", "async closure"),
Some(rustc_hir::GeneratorKind::Gen) => ("a", "generator"),
},
DefPathData::LifetimeNs(..) => ("a", "lifetime"),
DefPathData::Impl => ("an", "implementation"),
_ => bug!("article_and_description called on def_id {:?}", def_id),
}
self.def_kind(def_id)
.map(|def_kind| (def_kind.article(), def_kind.descr(def_id)))
.unwrap_or_else(|| match self.def_key(def_id).disambiguated_data.data {
DefPathData::ClosureExpr => match self.generator_kind(def_id) {
None => ("a", "closure"),
Some(rustc_hir::GeneratorKind::Async(..)) => ("an", "async closure"),
Some(rustc_hir::GeneratorKind::Gen) => ("a", "generator"),
},
DefPathData::LifetimeNs(..) => ("a", "lifetime"),
DefPathData::Impl => ("an", "implementation"),
DefPathData::TypeNs(..) | DefPathData::ValueNs(..) | DefPathData::MacroNs(..) => {
unreachable!()
}
_ => bug!("article_and_description called on def_id {:?}", def_id),
})
}
}

18 changes: 10 additions & 8 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
@@ -3083,7 +3083,7 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn hygienic_eq(self, use_name: Ident, def_name: Ident, def_parent_def_id: DefId) -> bool {
// We could use `Ident::eq` here, but we deliberately don't. The name
// comparison fails frequently, and we want to avoid the expensive
// `modern()` calls required for the span comparison whenever possible.
// `normalize_to_macros_2_0()` calls required for the span comparison whenever possible.
use_name.name == def_name.name
&& use_name
.span
@@ -3099,7 +3099,7 @@ impl<'tcx> TyCtxt<'tcx> {
}

pub fn adjust_ident(self, mut ident: Ident, scope: DefId) -> Ident {
ident.span.modernize_and_adjust(self.expansion_that_defined(scope));
ident.span.normalize_to_macros_2_0_and_adjust(self.expansion_that_defined(scope));
ident
}

@@ -3109,12 +3109,14 @@ impl<'tcx> TyCtxt<'tcx> {
scope: DefId,
block: hir::HirId,
) -> (Ident, DefId) {
let scope = match ident.span.modernize_and_adjust(self.expansion_that_defined(scope)) {
Some(actual_expansion) => {
self.hir().definitions().parent_module_of_macro_def(actual_expansion)
}
None => self.parent_module(block),
};
let scope =
match ident.span.normalize_to_macros_2_0_and_adjust(self.expansion_that_defined(scope))
{
Some(actual_expansion) => {
self.hir().definitions().parent_module_of_macro_def(actual_expansion)
}
None => self.parent_module(block),
};
(ident, scope)
}

2 changes: 1 addition & 1 deletion src/librustc_ast/ast.rs
Original file line number Diff line number Diff line change
@@ -1450,7 +1450,7 @@ impl MacDelimiter {
pub struct MacroDef {
pub body: P<MacArgs>,
/// `true` if macro was defined with `macro_rules`.
pub legacy: bool,
pub macro_rules: bool,
}

#[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy, Hash, Eq, PartialEq)]
2 changes: 1 addition & 1 deletion src/librustc_ast/mut_visit.rs
Original file line number Diff line number Diff line change
@@ -591,7 +591,7 @@ pub fn noop_visit_mac<T: MutVisitor>(mac: &mut MacCall, vis: &mut T) {
}

pub fn noop_visit_macro_def<T: MutVisitor>(macro_def: &mut MacroDef, vis: &mut T) {
let MacroDef { body, legacy: _ } = macro_def;
let MacroDef { body, macro_rules: _ } = macro_def;
visit_mac_args(body, vis);
}

14 changes: 7 additions & 7 deletions src/librustc_ast_lowering/item.rs
Original file line number Diff line number Diff line change
@@ -115,7 +115,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
_ => &[],
};
let lt_def_names = parent_generics.iter().filter_map(|param| match param.kind {
hir::GenericParamKind::Lifetime { .. } => Some(param.name.modern()),
hir::GenericParamKind::Lifetime { .. } => Some(param.name.normalize_to_macros_2_0()),
_ => None,
});
self.in_scope_lifetimes.extend(lt_def_names);
@@ -220,8 +220,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
let mut vis = self.lower_visibility(&i.vis, None);
let attrs = self.lower_attrs(&i.attrs);

if let ItemKind::MacroDef(MacroDef { ref body, legacy }) = i.kind {
if !legacy || attr::contains_name(&i.attrs, sym::macro_export) {
if let ItemKind::MacroDef(MacroDef { ref body, macro_rules }) = i.kind {
if !macro_rules || attr::contains_name(&i.attrs, sym::macro_export) {
let hir_id = self.lower_node_id(i.id);
let body = P(self.lower_mac_args(body));
self.exported_macros.push(hir::MacroDef {
@@ -230,7 +230,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
attrs,
hir_id,
span: i.span,
ast: MacroDef { body, legacy },
ast: MacroDef { body, macro_rules },
});
} else {
self.non_exported_macro_attrs.extend(attrs.iter().cloned());
@@ -761,13 +761,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
let names = self.lower_fn_params_to_names(&sig.decl);
let (generics, sig) =
self.lower_method_sig(generics, sig, trait_item_def_id, false, None);
(generics, hir::TraitItemKind::Fn(sig, hir::TraitMethod::Required(names)))
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Required(names)))
}
AssocItemKind::Fn(_, ref sig, ref generics, Some(ref body)) => {
let body_id = self.lower_fn_body_block(i.span, &sig.decl, Some(body));
let (generics, sig) =
self.lower_method_sig(generics, sig, trait_item_def_id, false, None);
(generics, hir::TraitItemKind::Fn(sig, hir::TraitMethod::Provided(body_id)))
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Provided(body_id)))
}
AssocItemKind::TyAlias(_, ref generics, ref bounds, ref default) => {
let ty = default.as_ref().map(|x| self.lower_ty(x, ImplTraitContext::disallowed()));
@@ -838,7 +838,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
asyncness.opt_return_id(),
);

(generics, hir::ImplItemKind::Method(sig, body_id))
(generics, hir::ImplItemKind::Fn(sig, body_id))
}
AssocItemKind::TyAlias(_, generics, _, ty) => {
let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
13 changes: 8 additions & 5 deletions src/librustc_ast_lowering/lib.rs
Original file line number Diff line number Diff line change
@@ -153,7 +153,7 @@ struct LoweringContext<'a, 'hir: 'a> {
/// against this list to see if it is already in-scope, or if a definition
/// needs to be created for it.
///
/// We always store a `modern()` version of the param-name in this
/// We always store a `normalize_to_macros_2_0()` version of the param-name in this
/// vector.
in_scope_lifetimes: Vec<ParamName>,

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

if self.in_scope_lifetimes.contains(&ParamName::Plain(ident.modern())) {
if self.in_scope_lifetimes.contains(&ParamName::Plain(ident.normalize_to_macros_2_0())) {
return;
}

let hir_name = ParamName::Plain(ident);

if self.lifetimes_to_define.iter().any(|(_, lt_name)| lt_name.modern() == hir_name.modern())
{
if self.lifetimes_to_define.iter().any(|(_, lt_name)| {
lt_name.normalize_to_macros_2_0() == hir_name.normalize_to_macros_2_0()
}) {
return;
}

@@ -838,7 +839,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
) -> T {
let old_len = self.in_scope_lifetimes.len();
let lt_def_names = params.iter().filter_map(|param| match param.kind {
GenericParamKind::Lifetime { .. } => Some(ParamName::Plain(param.ident.modern())),
GenericParamKind::Lifetime { .. } => {
Some(ParamName::Plain(param.ident.normalize_to_macros_2_0()))
}
_ => None,
});
self.in_scope_lifetimes.extend(lt_def_names);
2 changes: 1 addition & 1 deletion src/librustc_ast_passes/feature_gate.rs
Original file line number Diff line number Diff line change
@@ -366,7 +366,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
gate_feature_post!(&self, trait_alias, i.span, "trait aliases are experimental");
}

ast::ItemKind::MacroDef(ast::MacroDef { legacy: false, .. }) => {
ast::ItemKind::MacroDef(ast::MacroDef { macro_rules: false, .. }) => {
let msg = "`macro` is experimental";
gate_feature_post!(&self, decl_macro, i.span, msg);
}
2 changes: 1 addition & 1 deletion src/librustc_ast_pretty/pprust.rs
Original file line number Diff line number Diff line change
@@ -1238,7 +1238,7 @@ impl<'a> State<'a> {
}
}
ast::ItemKind::MacroDef(ref macro_def) => {
let (kw, has_bang) = if macro_def.legacy {
let (kw, has_bang) = if macro_def.macro_rules {
("macro_rules", true)
} else {
self.print_visibility(&item.vis);
4 changes: 2 additions & 2 deletions src/librustc_attr/builtin.rs
Original file line number Diff line number Diff line change
@@ -1024,7 +1024,7 @@ pub enum TransparencyError {

pub fn find_transparency(
attrs: &[Attribute],
is_legacy: bool,
macro_rules: bool,
) -> (Transparency, Option<TransparencyError>) {
let mut transparency = None;
let mut error = None;
@@ -1049,7 +1049,7 @@ pub fn find_transparency(
}
}
}
let fallback = if is_legacy { Transparency::SemiTransparent } else { Transparency::Opaque };
let fallback = if macro_rules { Transparency::SemiTransparent } else { Transparency::Opaque };
(transparency.map_or(fallback, |t| t.0), error)
}

2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/back/symbol_export.rs
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ fn reachable_non_generics_provider(
// Only consider nodes that actually have exported symbols.
Node::Item(&hir::Item { kind: hir::ItemKind::Static(..), .. })
| Node::Item(&hir::Item { kind: hir::ItemKind::Fn(..), .. })
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Method(..), .. }) => {
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }) => {
let def_id = tcx.hir().local_def_id(hir_id);
let generics = tcx.generics_of(def_id);
if !generics.requires_monomorphization(tcx) &&
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes.rs
Original file line number Diff line number Diff line change
@@ -349,6 +349,7 @@ E0623: include_str!("./error_codes/E0623.md"),
E0624: include_str!("./error_codes/E0624.md"),
E0626: include_str!("./error_codes/E0626.md"),
E0627: include_str!("./error_codes/E0627.md"),
E0628: include_str!("./error_codes/E0628.md"),
E0631: include_str!("./error_codes/E0631.md"),
E0633: include_str!("./error_codes/E0633.md"),
E0634: include_str!("./error_codes/E0634.md"),
@@ -583,7 +584,6 @@ E0748: include_str!("./error_codes/E0748.md"),
// E0612, // merged into E0609
// E0613, // Removed (merged with E0609)
E0625, // thread-local statics cannot be accessed at compile-time
E0628, // generators cannot have explicit parameters
E0629, // missing 'feature' (rustc_const_unstable)
// rustc_const_unstable attribute must be paired with stable/unstable
// attribute
30 changes: 30 additions & 0 deletions src/librustc_error_codes/error_codes/E0628.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
More than one parameter was used for a generator.

Erroneous code example:

```compile_fail,E0628
#![feature(generators, generator_trait)]

fn main() {
let generator = |a: i32, b: i32| {
// error: too many parameters for a generator
// Allowed only 0 or 1 parameter
yield a;
};
}
```

At present, it is not permitted to pass more than one explicit
parameter for a generator.This can be fixed by using
at most 1 parameter for the generator. For example, we might resolve
the previous example by passing only one parameter.

```
#![feature(generators, generator_trait)]

fn main() {
let generator = |a: i32| {
yield a;
};
}
```
Loading