Auto merge of #56225 - alexreg:type_alias_enum_variants, r=petrochenkov

Implement RFC 2338, "Type alias enum variants"

This PR implements [RFC 2338](https://github.com/rust-lang/rfcs/pull/2338), allowing one to write code like the following.

```rust
#![feature(type_alias_enum_variants)]

enum Foo {
    Bar(i32),
    Baz { i: i32 },
}

type Alias = Foo;

fn main() {
    let t = Alias::Bar(0);
    let t = Alias::Baz { i: 0 };
    match t {
        Alias::Bar(_i) => {}
        Alias::Baz { i: _i } => {}
    }
}
```

Since `Self` can be considered a type alias in this context, it also enables using `Self::Variant` as both a constructor and pattern.

Fixes issues #56199 and #56611.

N.B., after discussing the syntax for type arguments on enum variants with @petrochenkov and @eddyb (there are also a few comments on the [tracking issue](https://github.com/rust-lang/rust/issues/49683)), the consensus seems to be treat the syntax as follows, which ought to be backwards-compatible.

```rust
Option::<u8>::None; // OK
Option::None::<u8>; // OK, but lint in near future (hard error next edition?)
Alias::<u8>::None; // OK
Alias::None::<u8>; // Error
```

I do not know if this will need an FCP, but let's start one if so.
This commit is contained in:
bors 2018-12-29 21:03:11 +00:00
commit 59183180f7
111 changed files with 1606 additions and 759 deletions

View File

@ -0,0 +1,36 @@
# `type_alias_enum_variants`
The tracking issue for this feature is: [#49683]
[#49683]: https://github.com/rust-lang/rust/issues/49683
------------------------
The `type_alias_enum_variants` feature enables the use of variants on type
aliases that refer to enums, as both a constructor and a pattern. That is,
it allows for the syntax `EnumAlias::Variant`, which behaves exactly the same
as `Enum::Variant` (assuming that `EnumAlias` is an alias for some enum type
`Enum`).
Note that since `Self` exists as a type alias, this feature also enables the
use of the syntax `Self::Variant` within an impl block for an enum type.
```rust
#![feature(type_alias_enum_variants)]
enum Foo {
Bar(i32),
Baz { i: i32 },
}
type Alias = Foo;
fn main() {
let t = Alias::Bar(0);
let t = Alias::Baz { i: 0 };
match t {
Alias::Bar(_i) => {}
Alias::Baz { i: _i } => {}
}
}
```

View File

@ -1,4 +1,4 @@
//! Serialization for client<->server communication.
//! Serialization for client-server communication.
use std::any::Any;
use std::char;
@ -71,15 +71,18 @@ macro_rules! rpc_encode_decode {
(enum $name:ident $(<$($T:ident),+>)* { $($variant:ident $(($field:ident))*),* $(,)* }) => {
impl<S, $($($T: Encode<S>),+)*> Encode<S> for $name $(<$($T),+>)* {
fn encode(self, w: &mut Writer, s: &mut S) {
// HACK(eddyb) `Tag` enum duplicated between the
// HACK(eddyb): `Tag` enum duplicated between the
// two impls as there's no other place to stash it.
#[repr(u8)] enum Tag { $($variant),* }
#[allow(non_upper_case_globals)]
impl Tag { $(const $variant: u8 = Tag::$variant as u8;)* }
mod tag {
#[repr(u8)] enum Tag { $($variant),* }
$(pub const $variant: u8 = Tag::$variant as u8;)*
}
match self {
$($name::$variant $(($field))* => {
<Tag>::$variant.encode(w, s);
tag::$variant.encode(w, s);
$($field.encode(w, s);)*
})*
}
@ -90,14 +93,17 @@ macro_rules! rpc_encode_decode {
for $name $(<$($T),+>)*
{
fn decode(r: &mut Reader<'a>, s: &mut S) -> Self {
// HACK(eddyb) `Tag` enum duplicated between the
// HACK(eddyb): `Tag` enum duplicated between the
// two impls as there's no other place to stash it.
#[repr(u8)] enum Tag { $($variant),* }
#[allow(non_upper_case_globals)]
impl Tag { $(const $variant: u8 = Tag::$variant as u8;)* }
mod tag {
#[repr(u8)] enum Tag { $($variant),* }
$(pub const $variant: u8 = Tag::$variant as u8;)*
}
match u8::decode(r, s) {
$(<Tag>::$variant => {
$(tag::$variant => {
$(let $field = DecodeMut::decode(r, s);)*
$name::$variant $(($field))*
})*

View File

@ -454,7 +454,7 @@ pub fn walk_trait_ref<'v, V>(visitor: &mut V, trait_ref: &'v TraitRef)
pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
visitor.visit_vis(&item.vis);
visitor.visit_name(item.span, item.name);
visitor.visit_ident(item.ident);
match item.node {
ItemKind::ExternCrate(orig_name) => {
visitor.visit_id(item.id);
@ -472,7 +472,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
visitor.visit_nested_body(body);
}
ItemKind::Fn(ref declaration, header, ref generics, body_id) => {
visitor.visit_fn(FnKind::ItemFn(item.name,
visitor.visit_fn(FnKind::ItemFn(item.ident.name,
generics,
header,
&item.vis,
@ -528,7 +528,8 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
ItemKind::Union(ref struct_definition, ref generics) => {
visitor.visit_generics(generics);
visitor.visit_id(item.id);
visitor.visit_variant_data(struct_definition, item.name, generics, item.id, item.span);
visitor.visit_variant_data(struct_definition, item.ident.name, generics, item.id,
item.span);
}
ItemKind::Trait(.., ref generics, ref bounds, ref trait_item_refs) => {
visitor.visit_id(item.id);
@ -569,9 +570,9 @@ pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V,
variant: &'v Variant,
generics: &'v Generics,
parent_item_id: NodeId) {
visitor.visit_name(variant.span, variant.node.name);
visitor.visit_ident(variant.node.ident);
visitor.visit_variant_data(&variant.node.data,
variant.node.name,
variant.node.ident.name,
generics,
parent_item_id,
variant.span);
@ -720,7 +721,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v ForeignItem) {
visitor.visit_id(foreign_item.id);
visitor.visit_vis(&foreign_item.vis);
visitor.visit_name(foreign_item.span, foreign_item.name);
visitor.visit_ident(foreign_item.ident);
match foreign_item.node {
ForeignItemKind::Fn(ref function_declaration, ref param_names, ref generics) => {

View File

@ -1360,7 +1360,7 @@ impl<'a> LoweringContext<'a> {
let exist_ty_item = hir::Item {
id: exist_ty_id.node_id,
hir_id: exist_ty_id.hir_id,
name: keywords::Invalid.name(),
ident: keywords::Invalid.ident(),
attrs: Default::default(),
node: exist_ty_item_kind,
vis: respan(span.shrink_to_lo(), hir::VisibilityKind::Inherited),
@ -1563,7 +1563,7 @@ impl<'a> LoweringContext<'a> {
fn lower_variant(&mut self, v: &Variant) -> hir::Variant {
Spanned {
node: hir::VariantKind {
name: v.node.ident.name,
ident: v.node.ident,
attrs: self.lower_attrs(&v.node.attrs),
data: self.lower_variant_data(&v.node.data),
disr_expr: v.node.disr_expr.as_ref().map(|e| self.lower_anon_const(e)),
@ -2737,7 +2737,7 @@ impl<'a> LoweringContext<'a> {
fn lower_item_kind(
&mut self,
id: NodeId,
name: &mut Name,
ident: &mut Ident,
attrs: &hir::HirVec<Attribute>,
vis: &mut hir::Visibility,
i: &ItemKind,
@ -2751,7 +2751,7 @@ impl<'a> LoweringContext<'a> {
span: use_tree.span,
};
self.lower_use_tree(use_tree, &prefix, id, vis, name, attrs)
self.lower_use_tree(use_tree, &prefix, id, vis, ident, attrs)
}
ItemKind::Static(ref t, m, ref e) => {
let value = self.lower_body(None, |this| this.lower_expr(e));
@ -2943,7 +2943,7 @@ impl<'a> LoweringContext<'a> {
prefix: &Path,
id: NodeId,
vis: &mut hir::Visibility,
name: &mut Name,
ident: &mut Ident,
attrs: &hir::HirVec<Attribute>,
) -> hir::ItemKind {
debug!("lower_use_tree(tree={:?})", tree);
@ -2959,28 +2959,28 @@ impl<'a> LoweringContext<'a> {
match tree.kind {
UseTreeKind::Simple(rename, id1, id2) => {
*name = tree.ident().name;
*ident = tree.ident();
// First apply the prefix to the path
// First, apply the prefix to the path.
let mut path = Path {
segments,
span: path.span,
};
// Correctly resolve `self` imports
// Correctly resolve `self` imports.
if path.segments.len() > 1
&& path.segments.last().unwrap().ident.name == keywords::SelfLower.name()
{
let _ = path.segments.pop();
if rename.is_none() {
*name = path.segments.last().unwrap().ident.name;
*ident = path.segments.last().unwrap().ident;
}
}
let parent_def_index = self.current_hir_id_owner.last().unwrap().0;
let mut defs = self.expect_full_def_from_use(id);
// we want to return *something* from this function, so hang onto the first item
// for later
// We want to return *something* from this function, so hold onto the first item
// for later.
let ret_def = defs.next().unwrap_or(Def::Err);
// Here, we are looping over namespaces, if they exist for the definition
@ -2990,7 +2990,7 @@ impl<'a> LoweringContext<'a> {
// two imports.
for (def, &new_node_id) in defs.zip([id1, id2].iter()) {
let vis = vis.clone();
let name = name.clone();
let ident = ident.clone();
let mut path = path.clone();
for seg in &mut path.segments {
seg.id = self.sess.next_node_id();
@ -3031,7 +3031,7 @@ impl<'a> LoweringContext<'a> {
hir::Item {
id: new_id.node_id,
hir_id: new_id.hir_id,
name: name,
ident,
attrs: attrs.clone(),
node: item,
vis,
@ -3057,8 +3057,8 @@ impl<'a> LoweringContext<'a> {
hir::ItemKind::Use(path, hir::UseKind::Glob)
}
UseTreeKind::Nested(ref trees) => {
// Nested imports are desugared into simple
// imports. So if we start with
// Nested imports are desugared into simple imports.
// So, if we start with
//
// ```
// pub(x) use foo::{a, b};
@ -3079,14 +3079,14 @@ impl<'a> LoweringContext<'a> {
// `self.items`. However, the structure of this
// function also requires us to return one item, and
// for that we return the `{}` import (called the
// "`ListStem`").
// `ListStem`).
let prefix = Path {
segments,
span: prefix.span.to(path.span),
};
// Add all the nested PathListItems to the HIR.
// Add all the nested `PathListItem`s to the HIR.
for &(ref use_tree, id) in trees {
self.allocate_hir_id_counter(id, &use_tree);
@ -3096,10 +3096,10 @@ impl<'a> LoweringContext<'a> {
} = self.lower_node_id(id);
let mut vis = vis.clone();
let mut name = name.clone();
let mut ident = ident.clone();
let mut prefix = prefix.clone();
// Give the segments new ids since they are being cloned.
// Give the segments new node-ids since they are being cloned.
for seg in &mut prefix.segments {
seg.id = self.sess.next_node_id();
}
@ -3114,7 +3114,7 @@ impl<'a> LoweringContext<'a> {
&prefix,
new_id,
&mut vis,
&mut name,
&mut ident,
attrs);
let vis_kind = match vis.node {
@ -3138,7 +3138,7 @@ impl<'a> LoweringContext<'a> {
hir::Item {
id: new_id,
hir_id: new_hir_id,
name,
ident,
attrs: attrs.clone(),
node: item,
vis,
@ -3165,7 +3165,7 @@ impl<'a> LoweringContext<'a> {
*vis = respan(prefix.span.shrink_to_lo(), hir::VisibilityKind::Inherited);
}
hir::VisibilityKind::Restricted { .. } => {
// do nothing here, as described in the comment on the match
// Do nothing here, as described in the comment on the match.
}
}
@ -3413,7 +3413,7 @@ impl<'a> LoweringContext<'a> {
}
pub fn lower_item(&mut self, i: &Item) -> Option<hir::Item> {
let mut name = i.ident.name;
let mut ident = i.ident;
let mut vis = self.lower_visibility(&i.vis, None);
let attrs = self.lower_attrs(&i.attrs);
if let ItemKind::MacroDef(ref def) = i.node {
@ -3421,7 +3421,7 @@ impl<'a> LoweringContext<'a> {
attr::contains_name(&i.attrs, "rustc_doc_only_macro") {
let body = self.lower_token_stream(def.stream());
self.exported_macros.push(hir::MacroDef {
name,
name: ident.name,
vis,
attrs,
id: i.id,
@ -3433,14 +3433,14 @@ impl<'a> LoweringContext<'a> {
return None;
}
let node = self.lower_item_kind(i.id, &mut name, &attrs, &mut vis, &i.node);
let node = self.lower_item_kind(i.id, &mut ident, &attrs, &mut vis, &i.node);
let LoweredNodeId { node_id, hir_id } = self.lower_node_id(i.id);
Some(hir::Item {
id: node_id,
hir_id,
name,
ident,
attrs,
node,
vis,
@ -3453,7 +3453,7 @@ impl<'a> LoweringContext<'a> {
let def_id = self.resolver.definitions().local_def_id(node_id);
hir::ForeignItem {
id: node_id,
name: i.ident.name,
ident: i.ident,
attrs: self.lower_attrs(&i.attrs),
node: match i.node {
ForeignItemKind::Fn(ref fdec, ref generics) => {

View File

@ -228,7 +228,7 @@ impl<'a> FnLikeNode<'a> {
ast::ItemKind::Fn(ref decl, header, ref generics, block) =>
item_fn(ItemFnParts {
id: i.id,
name: i.name,
name: i.ident.name,
decl: &decl,
body: block,
vis: &i.vis,

View File

@ -813,11 +813,11 @@ impl<'hir> Map<'hir> {
/// Returns the name associated with the given NodeId's AST.
pub fn name(&self, id: NodeId) -> Name {
match self.get(id) {
Node::Item(i) => i.name,
Node::ForeignItem(i) => i.name,
Node::Item(i) => i.ident.name,
Node::ForeignItem(fi) => fi.ident.name,
Node::ImplItem(ii) => ii.ident.name,
Node::TraitItem(ti) => ti.ident.name,
Node::Variant(v) => v.node.name,
Node::Variant(v) => v.node.ident.name,
Node::Field(f) => f.ident.name,
Node::Lifetime(lt) => lt.name.ident().name,
Node::GenericParam(param) => param.name.ident().name,
@ -953,7 +953,7 @@ impl<'a, 'hir> NodesMatchingSuffix<'a, 'hir> {
loop {
if let Node::Item(item) = map.find(id)? {
if item_is_mod(&item) {
return Some((id, item.name))
return Some((id, item.ident.name))
}
}
let parent = map.get_parent(id);
@ -1009,9 +1009,9 @@ trait Named {
impl<T:Named> Named for Spanned<T> { fn name(&self) -> Name { self.node.name() } }
impl Named for Item { fn name(&self) -> Name { self.name } }
impl Named for ForeignItem { fn name(&self) -> Name { self.name } }
impl Named for VariantKind { fn name(&self) -> Name { self.name } }
impl Named for Item { fn name(&self) -> Name { self.ident.name } }
impl Named for ForeignItem { fn name(&self) -> Name { self.ident.name } }
impl Named for VariantKind { fn name(&self) -> Name { self.ident.name } }
impl Named for StructField { fn name(&self) -> Name { self.ident.name } }
impl Named for TraitItem { fn name(&self) -> Name { self.ident.name } }
impl Named for ImplItem { fn name(&self) -> Name { self.ident.name } }
@ -1194,7 +1194,7 @@ fn node_id_to_string(map: &Map<'_>, id: NodeId, include_id: bool) -> String {
}
Some(Node::Variant(ref variant)) => {
format!("variant {} in {}{}",
variant.node.name,
variant.node.ident,
path_str(), id_str)
}
Some(Node::Field(ref field)) => {

View File

@ -420,7 +420,7 @@ pub struct GenericArgs {
/// The generic arguments for this path segment.
pub args: HirVec<GenericArg>,
/// Bindings (equality constraints) on associated types, if present.
/// E.g., `Foo<A=Bar>`.
/// E.g., `Foo<A = Bar>`.
pub bindings: HirVec<TypeBinding>,
/// Were arguments written in parenthesized form `Fn(T) -> U`?
/// This is required mostly for pretty-printing and diagnostics,
@ -2015,7 +2015,7 @@ pub struct EnumDef {
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct VariantKind {
pub name: Name,
pub ident: Ident,
pub attrs: HirVec<Attribute>,
pub data: VariantData,
/// Explicit discriminant, e.g., `Foo = 1`
@ -2176,7 +2176,7 @@ pub struct ItemId {
/// The name might be a dummy name in case of anonymous items
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Item {
pub name: Name,
pub ident: Ident,
pub id: NodeId,
pub hir_id: HirId,
pub attrs: HirVec<Attribute>,
@ -2331,7 +2331,7 @@ pub enum AssociatedItemKind {
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct ForeignItem {
pub name: Name,
pub ident: Ident,
pub attrs: HirVec<Attribute>,
pub node: ForeignItemKind,
pub id: NodeId,

View File

@ -452,7 +452,7 @@ impl<'a> State<'a> {
abi: Abi::Rust,
asyncness: hir::IsAsync::NotAsync,
},
Some(item.name),
Some(item.ident.name),
generics,
&item.vis,
arg_names,
@ -466,7 +466,7 @@ impl<'a> State<'a> {
if m {
self.word_space("mut")?;
}
self.print_name(item.name)?;
self.print_ident(item.ident)?;
self.word_space(":")?;
self.print_type(&t)?;
self.s.word(";")?;
@ -475,7 +475,7 @@ impl<'a> State<'a> {
}
hir::ForeignItemKind::Type => {
self.head(visibility_qualified(&item.vis, "type"))?;
self.print_name(item.name)?;
self.print_ident(item.ident)?;
self.s.word(";")?;
self.end()?; // end the head-ibox
self.end() // end the outer cbox
@ -535,7 +535,7 @@ impl<'a> State<'a> {
self.s.word("as")?;
self.s.space()?;
}
self.print_name(item.name)?;
self.print_ident(item.ident)?;
self.s.word(";")?;
self.end()?; // end inner head-block
self.end()?; // end outer head-block
@ -546,10 +546,10 @@ impl<'a> State<'a> {
match kind {
hir::UseKind::Single => {
if path.segments.last().unwrap().ident.name != item.name {
if path.segments.last().unwrap().ident != item.ident {
self.s.space()?;
self.word_space("as")?;
self.print_name(item.name)?;
self.print_ident(item.ident)?;
}
self.s.word(";")?;
}
@ -564,7 +564,7 @@ impl<'a> State<'a> {
if m == hir::MutMutable {
self.word_space("mut")?;
}
self.print_name(item.name)?;
self.print_ident(item.ident)?;
self.word_space(":")?;
self.print_type(&ty)?;
self.s.space()?;
@ -577,7 +577,7 @@ impl<'a> State<'a> {
}
hir::ItemKind::Const(ref ty, expr) => {
self.head(visibility_qualified(&item.vis, "const"))?;
self.print_name(item.name)?;
self.print_ident(item.ident)?;
self.word_space(":")?;
self.print_type(&ty)?;
self.s.space()?;
@ -592,7 +592,7 @@ impl<'a> State<'a> {
self.head("")?;
self.print_fn(decl,
header,
Some(item.name),
Some(item.ident.name),
typarams,
&item.vis,
&[],
@ -604,7 +604,7 @@ impl<'a> State<'a> {
}
hir::ItemKind::Mod(ref _mod) => {
self.head(visibility_qualified(&item.vis, "mod"))?;
self.print_name(item.name)?;
self.print_ident(item.ident)?;
self.nbsp()?;
self.bopen()?;
self.print_mod(_mod, &item.attrs)?;
@ -624,7 +624,7 @@ impl<'a> State<'a> {
}
hir::ItemKind::Ty(ref ty, ref generics) => {
self.head(visibility_qualified(&item.vis, "type"))?;
self.print_name(item.name)?;
self.print_ident(item.ident)?;
self.print_generic_params(&generics.params)?;
self.end()?; // end the inner ibox
@ -637,7 +637,7 @@ impl<'a> State<'a> {
}
hir::ItemKind::Existential(ref exist) => {
self.head(visibility_qualified(&item.vis, "existential type"))?;
self.print_name(item.name)?;
self.print_ident(item.ident)?;
self.print_generic_params(&exist.generics.params)?;
self.end()?; // end the inner ibox
@ -659,15 +659,16 @@ impl<'a> State<'a> {
self.end()?; // end the outer ibox
}
hir::ItemKind::Enum(ref enum_definition, ref params) => {
self.print_enum_def(enum_definition, params, item.name, item.span, &item.vis)?;
self.print_enum_def(enum_definition, params, item.ident.name, item.span,
&item.vis)?;
}
hir::ItemKind::Struct(ref struct_def, ref generics) => {
self.head(visibility_qualified(&item.vis, "struct"))?;
self.print_struct(struct_def, generics, item.name, item.span, true)?;
self.print_struct(struct_def, generics, item.ident.name, item.span, true)?;
}
hir::ItemKind::Union(ref struct_def, ref generics) => {
self.head(visibility_qualified(&item.vis, "union"))?;
self.print_struct(struct_def, generics, item.name, item.span, true)?;
self.print_struct(struct_def, generics, item.ident.name, item.span, true)?;
}
hir::ItemKind::Impl(unsafety,
polarity,
@ -714,7 +715,7 @@ impl<'a> State<'a> {
self.print_is_auto(is_auto)?;
self.print_unsafety(unsafety)?;
self.word_nbsp("trait")?;
self.print_name(item.name)?;
self.print_ident(item.ident)?;
self.print_generic_params(&generics.params)?;
let mut real_bounds = Vec::with_capacity(bounds.len());
for b in bounds.iter() {
@ -739,7 +740,7 @@ impl<'a> State<'a> {
self.head("")?;
self.print_visibility(&item.vis)?;
self.word_nbsp("trait")?;
self.print_name(item.name)?;
self.print_ident(item.ident)?;
self.print_generic_params(&generics.params)?;
let mut real_bounds = Vec::with_capacity(bounds.len());
// FIXME(durka) this seems to be some quite outdated syntax
@ -897,7 +898,7 @@ impl<'a> State<'a> {
pub fn print_variant(&mut self, v: &hir::Variant) -> io::Result<()> {
self.head("")?;
let generics = hir::Generics::empty();
self.print_struct(&v.node.data, &generics, v.node.name, v.span, false)?;
self.print_struct(&v.node.data, &generics, v.node.ident.name, v.span, false)?;
if let Some(ref d) = v.node.disr_expr {
self.s.space()?;
self.word_space("=")?;

View File

@ -818,7 +818,7 @@ impl_stable_hash_for!(struct hir::EnumDef {
});
impl_stable_hash_for!(struct hir::VariantKind {
name,
ident -> (ident.name),
attrs,
data,
disr_expr
@ -852,7 +852,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Item {
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
let hir::Item {
name,
ident,
ref attrs,
id: _,
hir_id: _,
@ -862,7 +862,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::Item {
} = *self;
hcx.hash_hir_item_like(|hcx| {
name.hash_stable(hcx, hasher);
ident.name.hash_stable(hcx, hasher);
attrs.hash_stable(hcx, hasher);
node.hash_stable(hcx, hasher);
vis.hash_stable(hcx, hasher);
@ -926,7 +926,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::AssociatedItemKind {
}
impl_stable_hash_for!(struct hir::ForeignItem {
name,
ident -> (ident.name),
attrs,
node,
id,

View File

@ -557,7 +557,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
self.warn_dead_code(
item.id,
span,
item.name,
item.ident.name,
item.node.descriptive_variant(),
participle,
);
@ -572,7 +572,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
g: &'tcx hir::Generics,
id: ast::NodeId) {
if self.should_warn_about_variant(&variant.node) {
self.warn_dead_code(variant.node.data.id(), variant.span, variant.node.name,
self.warn_dead_code(variant.node.data.id(), variant.span, variant.node.ident.name,
"variant", "constructed");
} else {
intravisit::walk_variant(self, variant, g, id);
@ -581,7 +581,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
fn visit_foreign_item(&mut self, fi: &'tcx hir::ForeignItem) {
if self.should_warn_about_foreign_item(fi) {
self.warn_dead_code(fi.id, fi.span, fi.name,
self.warn_dead_code(fi.id, fi.span, fi.ident.name,
fi.node.descriptive_variant(), "used");
}
intravisit::walk_foreign_item(self, fi);

View File

@ -86,7 +86,7 @@ fn entry_point_type(item: &Item, at_root: bool) -> EntryPointType {
EntryPointType::Start
} else if attr::contains_name(&item.attrs, "main") {
EntryPointType::MainAttr
} else if item.name == "main" {
} else if item.ident.name == "main" {
if at_root {
// This is a top-level function so can be 'main'.
EntryPointType::MainNamed

View File

@ -2040,7 +2040,7 @@ impl<'tcx> Debug for Place<'tcx> {
Promoted(ref promoted) => write!(fmt, "({:?}: {:?})", promoted.0, promoted.1),
Projection(ref data) => match data.elem {
ProjectionElem::Downcast(ref adt_def, index) => {
write!(fmt, "({:?} as {})", data.base, adt_def.variants[index].name)
write!(fmt, "({:?} as {})", data.base, adt_def.variants[index].ident)
}
ProjectionElem::Deref => write!(fmt, "(*{:?})", data.base),
ProjectionElem::Field(field, ty) => {

View File

@ -1,7 +1,7 @@
use session::{self, DataTypeKind};
use ty::{self, Ty, TyCtxt, TypeFoldable, ReprOptions};
use syntax::ast::{self, IntTy, UintTy};
use syntax::ast::{self, Ident, IntTy, UintTy};
use syntax::attr;
use syntax_pos::DUMMY_SP;
@ -1228,7 +1228,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
let adt_kind = adt_def.adt_kind();
let adt_packed = adt_def.repr.packed();
let build_variant_info = |n: Option<ast::Name>,
let build_variant_info = |n: Option<Ident>,
flds: &[ast::Name],
layout: TyLayout<'tcx>| {
let mut min_size = Size::ZERO;
@ -1273,7 +1273,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
match layout.variants {
Variants::Single { index } => {
debug!("print-type-size `{:#?}` variant {}",
layout, adt_def.variants[index].name);
layout, adt_def.variants[index].ident);
if !adt_def.variants.is_empty() {
let variant_def = &adt_def.variants[index];
let fields: Vec<_> =
@ -1281,7 +1281,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
record(adt_kind.into(),
adt_packed,
None,
vec![build_variant_info(Some(variant_def.name),
vec![build_variant_info(Some(variant_def.ident),
&fields,
layout)]);
} else {
@ -1299,7 +1299,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> {
adt_def.variants.iter_enumerated().map(|(i, variant_def)| {
let fields: Vec<_> =
variant_def.fields.iter().map(|f| f.ident.name).collect();
build_variant_info(Some(variant_def.name),
build_variant_info(Some(variant_def.ident),
&fields,
layout.for_variant(self, i))
})

View File

@ -1780,7 +1780,7 @@ pub struct VariantDef {
/// The variant's `DefId`. If this is a tuple-like struct,
/// this is the `DefId` of the struct's ctor.
pub did: DefId,
pub name: Name, // struct's name if this is a struct
pub ident: Ident, // struct's name if this is a struct
pub discr: VariantDiscr,
pub fields: Vec<FieldDef>,
pub ctor_kind: CtorKind,
@ -1804,7 +1804,7 @@ impl<'a, 'gcx, 'tcx> VariantDef {
/// remove this hack and use the constructor DefId everywhere.
pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>,
did: DefId,
name: Name,
ident: Ident,
discr: VariantDiscr,
fields: Vec<FieldDef>,
adt_kind: AdtKind,
@ -1812,7 +1812,7 @@ impl<'a, 'gcx, 'tcx> VariantDef {
attribute_def_id: DefId)
-> Self
{
debug!("VariantDef::new({:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?})", did, name, discr,
debug!("VariantDef::new({:?}, {:?}, {:?}, {:?}, {:?}, {:?}, {:?})", did, ident, discr,
fields, adt_kind, ctor_kind, attribute_def_id);
let mut flags = VariantFlags::NO_VARIANT_FLAGS;
if adt_kind == AdtKind::Struct && tcx.has_attr(attribute_def_id, "non_exhaustive") {
@ -1821,7 +1821,7 @@ impl<'a, 'gcx, 'tcx> VariantDef {
}
VariantDef {
did,
name,
ident,
discr,
fields,
ctor_kind,
@ -1837,7 +1837,7 @@ impl<'a, 'gcx, 'tcx> VariantDef {
impl_stable_hash_for!(struct VariantDef {
did,
name,
ident -> (ident.name),
discr,
fields,
ctor_kind,
@ -1978,8 +1978,6 @@ impl_stable_hash_for!(struct ReprFlags {
bits
});
/// Represents the repr options provided by the user,
#[derive(Copy, Clone, Debug, Eq, PartialEq, RustcEncodable, RustcDecodable, Default)]
pub struct ReprOptions {

View File

@ -1215,7 +1215,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
name: if fallback {
String::new()
} else {
adt.variants[index].name.as_str().to_string()
adt.variants[index].ident.as_str().to_string()
},
type_metadata: variant_type_metadata,
offset: Size::ZERO,
@ -1255,7 +1255,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
name: if fallback {
String::new()
} else {
adt.variants[i].name.as_str().to_string()
adt.variants[i].ident.as_str().to_string()
},
type_metadata: variant_type_metadata,
offset: Size::ZERO,
@ -1321,7 +1321,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
self.layout,
self.layout.fields.offset(0),
self.layout.field(cx, 0).size);
name.push_str(&adt.variants[*niche_variants.start()].name.as_str());
name.push_str(&adt.variants[*niche_variants.start()].ident.as_str());
// Create the (singleton) list of descriptions of union members.
vec![
@ -1365,7 +1365,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
};
MemberDescription {
name: adt.variants[i].name.as_str().to_string(),
name: adt.variants[i].ident.as_str().to_string(),
type_metadata: variant_type_metadata,
offset: Size::ZERO,
size: self.layout.size,
@ -1433,7 +1433,7 @@ fn describe_enum_variant(
containing_scope: &'ll DIScope,
span: Span,
) -> (&'ll DICompositeType, MemberDescriptionFactory<'ll, 'tcx>) {
let variant_name = variant.name.as_str();
let variant_name = variant.ident.as_str();
let unique_type_id = debug_context(cx).type_map
.borrow_mut()
.get_unique_type_id_of_enum_variant(
@ -1527,7 +1527,7 @@ fn prepare_enum_metadata(
let enumerators_metadata: Vec<_> = def.discriminants(cx.tcx)
.zip(&def.variants)
.map(|((_, discr), v)| {
let name = SmallCStr::new(&v.name.as_str());
let name = SmallCStr::new(&v.ident.as_str());
unsafe {
Some(llvm::LLVMRustDIBuilderCreateEnumerator(
DIB(cx),

View File

@ -60,7 +60,7 @@ fn uncached_llvm_type<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
= (&layout.ty.sty, &layout.variants)
{
if def.is_enum() && !def.variants.is_empty() {
write!(&mut name, "::{}", def.variants[index].name).unwrap();
write!(&mut name, "::{}", def.variants[index].ident).unwrap();
}
}
Some(name)

View File

@ -261,7 +261,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
assert!(idx < names.len());
for item in &m.item_ids {
let item = this.infcx.tcx.hir().expect_item(item.id);
if item.name.to_string() == names[idx] {
if item.ident.to_string() == names[idx] {
return search(this, item, idx + 1, names);
}
}

View File

@ -278,7 +278,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
if let hir::ItemKind::Mod(_) = it.node {
self.check_snake_case(cx, "module", &it.name.as_str(), Some(it.span));
self.check_snake_case(cx, "module", &it.ident.as_str(), Some(it.span));
}
}
@ -354,10 +354,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals {
if attr::find_by_name(&it.attrs, "no_mangle").is_some() {
return;
}
NonUpperCaseGlobals::check_upper_case(cx, "static variable", it.name, it.span);
NonUpperCaseGlobals::check_upper_case(cx, "static variable", it.ident.name,
it.span);
}
hir::ItemKind::Const(..) => {
NonUpperCaseGlobals::check_upper_case(cx, "constant", it.name, it.span);
NonUpperCaseGlobals::check_upper_case(cx, "constant", it.ident.name,
it.span);
}
_ => {}
}

View File

@ -837,7 +837,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences {
let bytes = variant_layout.size.bytes().saturating_sub(discr_size);
debug!("- variant `{}` is {} bytes large",
variant.node.name,
variant.node.ident,
bytes);
bytes
})

View File

@ -553,7 +553,7 @@ impl<'a, 'tcx> CrateMetadata {
ty::VariantDef::new(
tcx,
def_id,
self.item_name(index).as_symbol(),
Ident::from_interned_str(self.item_name(index)),
data.discr,
item.children.decode(self).map(|index| {
let f = self.entry(index);

View File

@ -481,10 +481,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
}
}
AdtKind::Enum => {
let def = match *qpath {
hir::QPath::Resolved(_, ref path) => path.def,
hir::QPath::TypeRelative(..) => Def::Err,
};
let def = cx.tables().qpath_def(qpath, expr.hir_id);
match def {
Def::Variant(variant_id) => {
assert!(base.is_none());

View File

@ -306,7 +306,7 @@ fn check_for_bindings_named_same_as_variants(cx: &MatchVisitor, pat: &Pat) {
let pat_ty = cx.tables.pat_ty(p);
if let ty::Adt(edef, _) = pat_ty.sty {
if edef.is_enum() && edef.variants.iter().any(|variant| {
variant.name == ident.name && variant.ctor_kind == CtorKind::Const
variant.ident == ident && variant.ctor_kind == CtorKind::Const
}) {
let ty_path = cx.tcx.item_path_str(edef.did);
let mut err = struct_span_warn!(cx.tcx.sess, p.span, E0170,

View File

@ -280,7 +280,7 @@ impl<'tcx> fmt::Display for Pattern<'tcx> {
let mut start_or_continue = || if first { first = false; "" } else { ", " };
if let Some(variant) = variant {
write!(f, "{}", variant.name)?;
write!(f, "{}", variant.ident)?;
// Only for Adt we can have `S {...}`,
// which we handle separately here.

View File

@ -246,7 +246,7 @@ impl<'rt, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>>
variant_id: VariantIdx,
new_op: OpTy<'tcx, M::PointerTag>
) -> EvalResult<'tcx> {
let name = old_op.layout.ty.ty_adt_def().unwrap().variants[variant_id].name;
let name = old_op.layout.ty.ty_adt_def().unwrap().variants[variant_id].ident.name;
self.visit_elem(new_op, PathElem::Variant(name))
}

View File

@ -304,7 +304,7 @@ impl<'a> Resolver<'a> {
let features = self.session.features_untracked();
if attr_kind == NonMacroAttrKind::Custom {
assert!(path.segments.len() == 1);
let name = path.segments[0].ident.name.as_str();
let name = path.segments[0].ident.as_str();
if name.starts_with("rustc_") {
if !features.rustc_attrs {
let msg = "unless otherwise specified, attributes with the prefix \

View File

@ -31,6 +31,12 @@ use std::collections::BTreeSet;
use std::iter;
use std::slice;
use super::{check_type_alias_enum_variants_enabled};
use rustc_data_structures::fx::FxHashSet;
#[derive(Debug)]
pub struct PathSeg(pub DefId, pub usize);
pub trait AstConv<'gcx, 'tcx> {
fn tcx<'a>(&'a self) -> TyCtxt<'a, 'gcx, 'tcx>;
@ -563,7 +569,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
let has_self = generic_params.has_self;
let (_, potential_assoc_types) = Self::check_generic_arg_count(
self.tcx(),
tcx,
span,
&generic_params,
&generic_args,
@ -588,7 +594,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
};
let substs = Self::create_substs_for_generic_args(
self.tcx(),
tcx,
def_id,
&[][..],
self_ty.is_some(),
@ -1290,7 +1296,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
// item is declared.
let bound = match (&ty.sty, ty_path_def) {
(_, Def::SelfTy(Some(_), Some(impl_def_id))) => {
// `Self` in an impl of a trait -- we have a concrete `self` type and a
// `Self` in an impl of a trait -- we have a concrete self type and a
// trait reference.
let trait_ref = match tcx.impl_trait_ref(impl_def_id) {
Some(trait_ref) => trait_ref,
@ -1317,13 +1323,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
}
(&ty::Adt(adt_def, _substs), Def::Enum(_did)) => {
let ty_str = ty.to_string();
// Incorrect enum variant
// Incorrect enum variant.
let mut err = tcx.sess.struct_span_err(
span,
&format!("no variant `{}` on enum `{}`", &assoc_name.as_str(), ty_str),
);
// Check if it was a typo
let input = adt_def.variants.iter().map(|variant| &variant.name);
// Check if it was a typo.
let input = adt_def.variants.iter().map(|variant| &variant.ident.name);
if let Some(suggested_name) = find_best_match_for_name(
input,
&assoc_name.as_str(),
@ -1342,7 +1348,24 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
return (tcx.types.err, Def::Err);
}
_ => {
// Don't print TyErr to the user.
// Check if we have an enum variant.
match ty.sty {
ty::Adt(adt_def, _) if adt_def.is_enum() => {
let variant_def = adt_def.variants.iter().find(|vd| {
tcx.hygienic_eq(assoc_name, vd.ident, adt_def.did)
});
if let Some(variant_def) = variant_def {
check_type_alias_enum_variants_enabled(tcx, span);
let def = Def::Variant(variant_def.did);
tcx.check_stability(def.def_id(), Some(ref_id), span);
return (ty, def);
}
},
_ => (),
}
// Don't print `TyErr` to the user.
if !ty.references_error() {
self.report_ambiguous_associated_type(span,
&ty.to_string(),
@ -1358,8 +1381,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
let item = tcx.associated_items(trait_did).find(|i| {
Namespace::from(i.kind) == Namespace::Type &&
i.ident.modern() == assoc_ident
})
.expect("missing associated type");
}).expect("missing associated type");
let ty = self.projected_ty_from_poly_trait_ref(span, item.def_id, bound);
let ty = self.normalize_ty(span, ty);
@ -1410,7 +1432,9 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
self.normalize_ty(span, tcx.mk_projection(item_def_id, trait_ref.substs))
}
pub fn prohibit_generics<'a, T: IntoIterator<Item = &'a hir::PathSegment>>(&self, segments: T) {
pub fn prohibit_generics<'a, T: IntoIterator<Item = &'a hir::PathSegment>>(
&self, segments: T) -> bool {
let mut has_err = false;
for segment in segments {
segment.with_generic_args(|generic_args| {
let (mut err_for_lt, mut err_for_ty) = (false, false);
@ -1419,32 +1443,36 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
hir::GenericArg::Lifetime(lt) => {
if err_for_lt { continue }
err_for_lt = true;
has_err = true;
(struct_span_err!(self.tcx().sess, lt.span, E0110,
"lifetime parameters are not allowed on this type"),
"lifetime arguments are not allowed on this entity"),
lt.span,
"lifetime")
}
hir::GenericArg::Type(ty) => {
if err_for_ty { continue }
err_for_ty = true;
has_err = true;
(struct_span_err!(self.tcx().sess, ty.span, E0109,
"type parameters are not allowed on this type"),
"type arguments are not allowed on this entity"),
ty.span,
"type")
}
};
span_err.span_label(span, format!("{} parameter not allowed", kind))
span_err.span_label(span, format!("{} argument not allowed", kind))
.emit();
if err_for_lt && err_for_ty {
break;
}
}
for binding in &generic_args.bindings {
has_err = true;
Self::prohibit_assoc_ty_binding(self.tcx(), binding.span);
break;
}
})
}
has_err
}
pub fn prohibit_assoc_ty_binding(tcx: TyCtxt, span: Span) {
@ -1453,6 +1481,134 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
err.span_label(span, "associated type not allowed here").emit();
}
pub fn def_ids_for_path_segments(&self,
segments: &[hir::PathSegment],
self_ty: Option<Ty<'tcx>>,
def: Def)
-> Vec<PathSeg> {
// We need to extract the type parameters supplied by the user in
// the path `path`. Due to the current setup, this is a bit of a
// tricky-process; the problem is that resolve only tells us the
// end-point of the path resolution, and not the intermediate steps.
// Luckily, we can (at least for now) deduce the intermediate steps
// just from the end-point.
//
// There are basically five cases to consider:
//
// 1. Reference to a constructor of a struct:
//
// struct Foo<T>(...)
//
// In this case, the parameters are declared in the type space.
//
// 2. Reference to a constructor of an enum variant:
//
// enum E<T> { Foo(...) }
//
// In this case, the parameters are defined in the type space,
// but may be specified either on the type or the variant.
//
// 3. Reference to a fn item or a free constant:
//
// fn foo<T>() { }
//
// In this case, the path will again always have the form
// `a::b::foo::<T>` where only the final segment should have
// type parameters. However, in this case, those parameters are
// declared on a value, and hence are in the `FnSpace`.
//
// 4. Reference to a method or an associated constant:
//
// impl<A> SomeStruct<A> {
// fn foo<B>(...)
// }
//
// Here we can have a path like
// `a::b::SomeStruct::<A>::foo::<B>`, in which case parameters
// may appear in two places. The penultimate segment,
// `SomeStruct::<A>`, contains parameters in TypeSpace, and the
// final segment, `foo::<B>` contains parameters in fn space.
//
// 5. Reference to a local variable
//
// Local variables can't have any type parameters.
//
// The first step then is to categorize the segments appropriately.
let tcx = self.tcx();
assert!(!segments.is_empty());
let last = segments.len() - 1;
let mut path_segs = vec![];
match def {
// Case 1. Reference to a struct constructor.
Def::StructCtor(def_id, ..) |
Def::SelfCtor(.., def_id) => {
// Everything but the final segment should have no
// parameters at all.
let generics = tcx.generics_of(def_id);
// Variant and struct constructors use the
// generics of their parent type definition.
let generics_def_id = generics.parent.unwrap_or(def_id);
path_segs.push(PathSeg(generics_def_id, last));
}
// Case 2. Reference to a variant constructor.
Def::Variant(def_id) |
Def::VariantCtor(def_id, ..) => {
let adt_def = self_ty.map(|t| t.ty_adt_def().unwrap());
let (generics_def_id, index) = if let Some(adt_def) = adt_def {
debug_assert!(adt_def.is_enum());
(adt_def.did, last)
} else if last >= 1 && segments[last - 1].args.is_some() {
// Everything but the penultimate segment should have no
// parameters at all.
let enum_def_id = tcx.parent_def_id(def_id).unwrap();
(enum_def_id, last - 1)
} else {
// FIXME: lint here recommending `Enum::<...>::Variant` form
// instead of `Enum::Variant::<...>` form.
// Everything but the final segment should have no
// parameters at all.
let generics = tcx.generics_of(def_id);
// Variant and struct constructors use the
// generics of their parent type definition.
(generics.parent.unwrap_or(def_id), last)
};
path_segs.push(PathSeg(generics_def_id, index));
}
// Case 3. Reference to a top-level value.
Def::Fn(def_id) |
Def::Const(def_id) |
Def::Static(def_id, _) => {
path_segs.push(PathSeg(def_id, last));
}
// Case 4. Reference to a method or associated const.
Def::Method(def_id) |
Def::AssociatedConst(def_id) => {
if segments.len() >= 2 {
let generics = tcx.generics_of(def_id);
path_segs.push(PathSeg(generics.parent.unwrap(), last - 1));
}
path_segs.push(PathSeg(def_id, last));
}
// Case 5. Local variable, no generics.
Def::Local(..) | Def::Upvar(..) => {}
_ => bug!("unexpected definition: {:?}", def),
}
debug!("path_segs = {:?}", path_segs);
path_segs
}
// Check a type `Path` and convert it to a `Ty`.
pub fn def_to_ty(&self,
opt_self_ty: Option<Ty<'tcx>>,
@ -1483,14 +1639,24 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
self.prohibit_generics(path.segments.split_last().unwrap().1);
self.ast_path_to_ty(span, did, path.segments.last().unwrap())
}
Def::Variant(did) if permit_variants => {
Def::Variant(_) if permit_variants => {
// Convert "variant type" as if it were a real type.
// The resulting `Ty` is type of the variant's enum for now.
assert_eq!(opt_self_ty, None);
self.prohibit_generics(path.segments.split_last().unwrap().1);
self.ast_path_to_ty(span,
tcx.parent_def_id(did).unwrap(),
path.segments.last().unwrap())
let path_segs = self.def_ids_for_path_segments(&path.segments, None, path.def);
let generic_segs: FxHashSet<_> =
path_segs.iter().map(|PathSeg(_, index)| index).collect();
self.prohibit_generics(path.segments.iter().enumerate().filter_map(|(index, seg)| {
if !generic_segs.contains(&index) {
Some(seg)
} else {
None
}
}));
let PathSeg(def_id, index) = path_segs.last().unwrap();
self.ast_path_to_ty(span, *def_id, &path.segments[*index])
}
Def::TyParam(did) => {
assert_eq!(opt_self_ty, None);
@ -1504,25 +1670,24 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
tcx.mk_ty_param(index, tcx.hir().name(node_id).as_interned_str())
}
Def::SelfTy(_, Some(def_id)) => {
// `Self` in impl (we know the concrete type)
// `Self` in impl (we know the concrete type).
assert_eq!(opt_self_ty, None);
self.prohibit_generics(&path.segments);
tcx.at(span).type_of(def_id)
}
Def::SelfTy(Some(_), None) => {
// `Self` in trait
// `Self` in trait.
assert_eq!(opt_self_ty, None);
self.prohibit_generics(&path.segments);
tcx.mk_self_type()
}
Def::AssociatedTy(def_id) => {
self.prohibit_generics(&path.segments[..path.segments.len()-2]);
debug_assert!(path.segments.len() >= 2);
self.prohibit_generics(&path.segments[..path.segments.len() - 2]);
self.qpath_to_ty(span,
opt_self_ty,
def_id,
&path.segments[path.segments.len()-2],
&path.segments[path.segments.len() - 2],
path.segments.last().unwrap())
}
Def::PrimTy(prim_ty) => {

View File

@ -17,6 +17,8 @@ use util::nodemap::FxHashMap;
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::cmp;
use super::report_unexpected_variant_def;
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
/// The `is_arg` argument indicates whether this pattern is the
/// *outermost* pattern in an argument (e.g., in `fn foo(&x:
@ -273,7 +275,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
PatKind::Tuple(ref elements, ddpos) => {
let mut expected_len = elements.len();
if ddpos.is_some() {
// Require known type only when `..` is present
// Require known type only when `..` is present.
if let ty::Tuple(ref tys) =
self.structurally_resolved_type(pat.span, expected).sty {
expected_len = tys.len();
@ -282,8 +284,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let max_len = cmp::max(expected_len, elements.len());
let element_tys_iter = (0..max_len).map(|_| self.next_ty_var(
// FIXME: MiscVariable for now, obtaining the span and name information
// from all tuple elements isn't trivial.
// FIXME: `MiscVariable` for now -- obtaining the span and name information
// from all tuple elements isn't trivial.
TypeVariableOrigin::TypeInference(pat.span)));
let element_tys = tcx.mk_type_list(element_tys_iter);
let pat_ty = tcx.mk_ty(ty::Tuple(element_tys));
@ -736,12 +738,6 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
expected: Ty<'tcx>) -> Ty<'tcx>
{
let tcx = self.tcx;
let report_unexpected_def = |def: Def| {
span_err!(tcx.sess, pat.span, E0533,
"expected unit struct/variant or constant, found {} `{}`",
def.kind_name(),
hir::print::to_string(tcx.hir(), |s| s.print_qpath(qpath, false)));
};
// Resolve the path and check the definition for errors.
let (def, opt_ty, segments) = self.resolve_ty_and_def_ufcs(qpath, pat.id, pat.span);
@ -751,7 +747,11 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
return tcx.types.err;
}
Def::Method(..) => {
report_unexpected_def(def);
report_unexpected_variant_def(tcx, &def, pat.span, qpath);
return tcx.types.err;
}
Def::VariantCtor(_, CtorKind::Fictive) => {
report_unexpected_variant_def(tcx, &def, pat.span, qpath);
return tcx.types.err;
}
Def::VariantCtor(_, CtorKind::Const) |
@ -952,7 +952,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
if plural == "" {
let input = unmentioned_fields.iter().map(|field| &field.name);
let suggested_name =
find_best_match_for_name(input, &ident.name.as_str(), None);
find_best_match_for_name(input, &ident.as_str(), None);
if let Some(suggested_name) = suggested_name {
err.span_suggestion(*span, "did you mean", suggested_name.to_string());
// we don't want to throw `E0027` in case we have thrown `E0026` for them

View File

@ -71,7 +71,7 @@ fn equate_intrinsic_type<'a, 'tcx>(
pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
it: &hir::ForeignItem) {
let param = |n| tcx.mk_ty_param(n, Symbol::intern(&format!("P{}", n)).as_interned_str());
let name = it.name.as_str();
let name = it.ident.as_str();
let mk_va_list_ty = || {
tcx.lang_items().va_list().map(|did| {
@ -393,7 +393,7 @@ pub fn check_platform_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let def_id = tcx.hir().local_def_id(it.id);
let i_n_tps = tcx.generics_of(def_id).own_counts().types;
let name = it.name.as_str();
let name = it.ident.as_str();
let (n_tps, inputs, output) = match &*name {
"simd_eq" | "simd_ne" | "simd_lt" | "simd_le" | "simd_gt" | "simd_ge" => {

View File

@ -1,4 +1,4 @@
//! Method lookup: the secret sauce of Rust. See the [rustc guide] chapter.
//! Method lookup: the secret sauce of Rust. See the [rustc guide] for more information.
//!
//! [rustc guide]: https://rust-lang.github.io/rustc-guide/method-lookup.html
@ -8,7 +8,7 @@ mod suggest;
pub use self::MethodError::*;
pub use self::CandidateSource::*;
pub use self::suggest::TraitInfo;
pub use self::suggest::{SelfSource, TraitInfo};
use check::FnCtxt;
use namespace::Namespace;
@ -25,6 +25,7 @@ use rustc::infer::{self, InferOk};
use syntax::ast;
use syntax_pos::Span;
use crate::{check_type_alias_enum_variants_enabled};
use self::probe::{IsSuggestion, ProbeScope};
pub fn provide(providers: &mut ty::query::Providers) {
@ -362,21 +363,51 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
self_ty: Ty<'tcx>,
expr_id: ast::NodeId)
-> Result<Def, MethodError<'tcx>> {
debug!("resolve_ufcs: method_name={:?} self_ty={:?} expr_id={:?}",
method_name,
self_ty,
expr_id
);
let tcx = self.tcx;
let mode = probe::Mode::Path;
let pick = self.probe_for_name(span, mode, method_name, IsSuggestion(false),
self_ty, expr_id, ProbeScope::TraitsInScope)?;
match self.probe_for_name(span, mode, method_name, IsSuggestion(false),
self_ty, expr_id, ProbeScope::TraitsInScope) {
Ok(pick) => {
if let Some(import_id) = pick.import_id {
let import_def_id = tcx.hir().local_def_id(import_id);
debug!("resolve_ufcs: used_trait_import: {:?}", import_def_id);
Lrc::get_mut(&mut self.tables.borrow_mut().used_trait_imports)
.unwrap().insert(import_def_id);
}
if let Some(import_id) = pick.import_id {
let import_def_id = self.tcx.hir().local_def_id(import_id);
debug!("used_trait_import: {:?}", import_def_id);
Lrc::get_mut(&mut self.tables.borrow_mut().used_trait_imports)
.unwrap().insert(import_def_id);
let def = pick.item.def();
tcx.check_stability(def.def_id(), Some(expr_id), span);
Ok(def)
}
Err(err) => {
// Check if we have an enum variant.
match self_ty.sty {
ty::Adt(adt_def, _) if adt_def.is_enum() => {
let variant_def = adt_def.variants.iter().find(|vd| {
tcx.hygienic_eq(method_name, vd.ident, adt_def.did)
});
if let Some(variant_def) = variant_def {
check_type_alias_enum_variants_enabled(tcx, span);
let def = Def::VariantCtor(variant_def.did, variant_def.ctor_kind);
tcx.check_stability(def.def_id(), Some(expr_id), span);
return Ok(def);
}
},
_ => (),
}
Err(err)
}
}
let def = pick.item.def();
self.tcx.check_stability(def.def_id(), Some(expr_id), span);
Ok(def)
}
/// Find item with name `item_name` defined in impl/trait `def_id`

View File

@ -6,7 +6,7 @@ use errors::{Applicability, DiagnosticBuilder};
use middle::lang_items::FnOnceTraitLangItem;
use namespace::Namespace;
use rustc_data_structures::sync::Lrc;
use rustc::hir::{self, Node};
use rustc::hir::{self, ExprKind, Node, QPath};
use rustc::hir::def::Def;
use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, DefId};
use rustc::hir::map as hir_map;
@ -60,13 +60,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
}
pub fn report_method_error(&self,
span: Span,
rcvr_ty: Ty<'tcx>,
item_name: ast::Ident,
rcvr_expr: Option<&hir::Expr>,
error: MethodError<'tcx>,
args: Option<&'gcx [hir::Expr]>) {
pub fn report_method_error<'b>(&self,
span: Span,
rcvr_ty: Ty<'tcx>,
item_name: ast::Ident,
source: SelfSource<'b>,
error: MethodError<'tcx>,
args: Option<&'gcx [hir::Expr]>) {
// Avoid suggestions when we don't know what's going on.
if rcvr_ty.references_error() {
return;
@ -185,7 +185,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
"method"
} else if actual.is_enum() {
if let Adt(ref adt_def, _) = actual.sty {
let names = adt_def.variants.iter().map(|s| &s.name);
let names = adt_def.variants.iter().map(|s| &s.ident.name);
suggestion = find_best_match_for_name(names,
&item_name.as_str(),
None);
@ -212,10 +212,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
.filter_map(|info|
self.associated_item(info.def_id, item_name, Namespace::Value)
);
if let (true, false, Some(expr), Some(_)) = (actual.is_numeric(),
actual.has_concrete_skeleton(),
rcvr_expr,
candidates.next()) {
if let (true, false, SelfSource::MethodCall(expr), Some(_)) =
(actual.is_numeric(),
actual.has_concrete_skeleton(),
source,
candidates.next()) {
let mut err = struct_span_err!(
tcx.sess,
span,
@ -231,7 +232,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
"f32"
};
match expr.node {
hir::ExprKind::Lit(ref lit) => {
ExprKind::Lit(ref lit) => {
// numeric literal
let snippet = tcx.sess.source_map().span_to_snippet(lit.span)
.unwrap_or_else(|_| "<numeric literal>".to_owned());
@ -247,9 +248,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
Applicability::MaybeIncorrect,
);
}
hir::ExprKind::Path(ref qpath) => {
ExprKind::Path(ref qpath) => {
// local binding
if let &hir::QPath::Resolved(_, ref path) = &qpath {
if let &QPath::Resolved(_, ref path) = &qpath {
if let hir::def::Def::Local(node_id) = path.def {
let span = tcx.hir().span(node_id);
let snippet = tcx.sess.source_map().span_to_snippet(span)
@ -294,7 +295,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
} else {
let mut err = struct_span_err!(
tcx.sess,
span,
item_name.span,
E0599,
"no {} named `{}` found for type `{}` in the current scope",
item_kind,
@ -302,7 +303,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
ty_str
);
if let Some(suggestion) = suggestion {
err.note(&format!("did you mean `{}::{}`?", ty_str, suggestion));
// enum variant
err.help(&format!("did you mean `{}`?", suggestion));
}
err
}
@ -326,7 +328,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// If the method name is the name of a field with a function or closure type,
// give a helping note that it has to be called as `(x.f)(...)`.
if let Some(expr) = rcvr_expr {
if let SelfSource::MethodCall(expr) = source {
for (ty, _) in self.autoderef(span, rcvr_ty) {
if let ty::Adt(def, substs) = ty.sty {
if !def.is_enum() {
@ -377,10 +379,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
}
if let Some(expr) = rcvr_expr {
if let SelfSource::MethodCall(expr) = source {
if let Ok(expr_string) = tcx.sess.source_map().span_to_snippet(expr.span) {
report_function!(expr.span, expr_string);
} else if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) =
} else if let ExprKind::Path(QPath::Resolved(_, ref path)) =
expr.node
{
if let Some(segment) = path.segments.last() {
@ -396,7 +398,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
err.span_label(span, "this is an associated function, not a method");
}
if static_sources.len() == 1 {
if let Some(expr) = rcvr_expr {
if let SelfSource::MethodCall(expr) = source {
err.span_suggestion_with_applicability(expr.span.to(span),
"use associated function syntax instead",
format!("{}::{}",
@ -433,7 +435,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
span,
rcvr_ty,
item_name,
rcvr_expr,
source,
out_of_scope_traits);
}
@ -571,18 +573,18 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
}
fn suggest_traits_to_import(&self,
err: &mut DiagnosticBuilder,
span: Span,
rcvr_ty: Ty<'tcx>,
item_name: ast::Ident,
rcvr_expr: Option<&hir::Expr>,
valid_out_of_scope_traits: Vec<DefId>) {
fn suggest_traits_to_import<'b>(&self,
err: &mut DiagnosticBuilder,
span: Span,
rcvr_ty: Ty<'tcx>,
item_name: ast::Ident,
source: SelfSource<'b>,
valid_out_of_scope_traits: Vec<DefId>) {
if self.suggest_valid_traits(err, valid_out_of_scope_traits) {
return;
}
let type_is_local = self.type_derefs_to_local(span, rcvr_ty, rcvr_expr);
let type_is_local = self.type_derefs_to_local(span, rcvr_ty, source);
// There are no traits implemented, so lets suggest some traits to
// implement, by finding ones that have the item name, and are
@ -643,7 +645,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
fn type_derefs_to_local(&self,
span: Span,
rcvr_ty: Ty<'tcx>,
rcvr_expr: Option<&hir::Expr>) -> bool {
source: SelfSource) -> bool {
fn is_local(ty: Ty) -> bool {
match ty.sty {
ty::Adt(def, _) => def.did.is_local(),
@ -663,7 +665,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// This occurs for UFCS desugaring of `T::method`, where there is no
// receiver expression for the method call, and thus no autoderef.
if rcvr_expr.is_none() {
if let SelfSource::QPath(_) = source {
return is_local(self.resolve_type_vars_with_obligations(rcvr_ty));
}
@ -671,6 +673,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
}
#[derive(Copy, Clone)]
pub enum SelfSource<'a> {
QPath(&'a hir::Ty),
MethodCall(&'a hir::Expr /* rcvr */),
}
#[derive(Copy, Clone)]
pub struct TraitInfo {
pub def_id: DefId,

View File

@ -83,10 +83,10 @@ mod generator_interior;
mod intrinsic;
mod op;
use astconv::AstConv;
use astconv::{AstConv, PathSeg};
use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
use rustc::hir::{self, GenericArg, ItemKind, Node, PatKind};
use rustc::hir::def::Def;
use rustc::hir::{self, ExprKind, GenericArg, ItemKind, Node, PatKind, QPath};
use rustc::hir::def::{CtorKind, Def};
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
use rustc::hir::itemlikevisit::ItemLikeVisitor;
@ -101,14 +101,14 @@ use rustc::infer::opaque_types::OpaqueTypeDecl;
use rustc::infer::type_variable::{TypeVariableOrigin};
use rustc::middle::region;
use rustc::mir::interpret::{ConstValue, GlobalId};
use rustc::ty::subst::{CanonicalUserSubsts, UnpackedKind, Subst, Substs,
UserSelfTy, UserSubsts};
use rustc::traits::{self, ObligationCause, ObligationCauseCode, TraitEngine};
use rustc::ty::{self, AdtKind, Ty, TyCtxt, GenericParamDefKind, RegionKind, Visibility,
ToPolyTraitRef, ToPredicate};
use rustc::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
use rustc::ty::fold::TypeFoldable;
use rustc::ty::query::Providers;
use rustc::ty::subst::{CanonicalUserSubsts, UnpackedKind, Subst, Substs,
UserSelfTy, UserSubsts};
use rustc::ty::util::{Representability, IntTypeExt, Discr};
use rustc::ty::layout::VariantIdx;
use syntax_pos::{self, BytePos, Span, MultiSpan};
@ -142,7 +142,7 @@ use self::autoderef::Autoderef;
use self::callee::DeferredCallResolution;
use self::coercion::{CoerceMany, DynamicCoerceMany};
pub use self::compare_method::{compare_impl_method, compare_const_impl};
use self::method::MethodCallee;
use self::method::{MethodCallee, SelfSource};
use self::TupleArgumentsFlag::*;
/// The type of a local binding, including the revealed type for anon types.
@ -507,9 +507,6 @@ impl<'gcx, 'tcx> EnclosingBreakables<'gcx, 'tcx> {
}
}
#[derive(Debug)]
struct PathSeg(DefId, usize);
pub struct FnCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
body_id: ast::NodeId,
@ -1327,7 +1324,7 @@ pub fn check_item_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, it: &'tcx hir::Ite
}
hir::ItemKind::Fn(..) => {} // entirely within check_item_body
hir::ItemKind::Impl(.., ref impl_item_refs) => {
debug!("ItemKind::Impl {} with id {}", it.name, it.id);
debug!("ItemKind::Impl {} with id {}", it.ident, it.id);
let impl_def_id = tcx.hir().local_def_id(it.id);
if let Some(impl_trait_ref) = tcx.impl_trait_ref(impl_def_id) {
check_impl_items_against_trait(
@ -1864,6 +1861,16 @@ pub fn check_enum<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
check_representable(tcx, sp, def_id);
}
fn report_unexpected_variant_def<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
def: &Def,
span: Span,
qpath: &QPath) {
span_err!(tcx.sess, span, E0533,
"expected unit struct/variant or constant, found {} `{}`",
def.kind_name(),
hir::print::to_string(tcx.hir(), |s| s.print_qpath(qpath, false)));
}
impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> {
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> { self.tcx }
@ -2947,7 +2954,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
let is_closure = match arg.node {
hir::ExprKind::Closure(..) => true,
ExprKind::Closure(..) => true,
_ => false
};
@ -3097,8 +3104,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
if let Some(mut err) = self.demand_suptype_diag(expr.span, expected_ty, ty) {
// Add help to type error if this is an `if` condition with an assignment
if let (ExpectIfCondition, &hir::ExprKind::Assign(ref lhs, ref rhs))
// Add help to type error if this is an `if` condition with an assignment.
if let (ExpectIfCondition, &ExprKind::Assign(ref lhs, ref rhs))
= (expected, &expr.node)
{
let msg = "try comparing for equality";
@ -3244,7 +3251,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
self.report_method_error(span,
rcvr_t,
segment.ident,
Some(rcvr),
SelfSource::MethodCall(rcvr),
error,
Some(args));
}
@ -3529,7 +3536,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
ty::Adt(adt, ..) if adt.is_enum() => {
struct_span_err!(self.tcx.sess, field.ident.span, E0559,
"{} `{}::{}` has no field named `{}`",
kind_name, actual, variant.name, field.ident)
kind_name, actual, variant.ident, field.ident)
}
_ => {
struct_span_err!(self.tcx.sess, field.ident.span, E0560,
@ -3551,7 +3558,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
if adt.is_enum() {
err.span_label(field.ident.span,
format!("`{}::{}` does not have this field",
ty, variant.name));
ty, variant.ident));
} else {
err.span_label(field.ident.span,
format!("`{}` does not have this field", ty));
@ -3691,12 +3698,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
pub fn check_struct_path(&self,
qpath: &hir::QPath,
qpath: &QPath,
node_id: ast::NodeId)
-> Option<(&'tcx ty::VariantDef, Ty<'tcx>)> {
let path_span = match *qpath {
hir::QPath::Resolved(_, ref path) => path.span,
hir::QPath::TypeRelative(ref qself, _) => qself.span
QPath::Resolved(_, ref path) => path.span,
QPath::TypeRelative(ref qself, _) => qself.span
};
let (def, ty) = self.finish_resolving_struct_path(qpath, path_span, node_id);
let variant = match def {
@ -3749,7 +3756,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
fn check_expr_struct(&self,
expr: &hir::Expr,
expected: Expectation<'tcx>,
qpath: &hir::QPath,
qpath: &QPath,
fields: &'gcx [hir::Field],
base_expr: &'gcx Option<P<hir::Expr>>) -> Ty<'tcx>
{
@ -3763,8 +3770,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
};
let path_span = match *qpath {
hir::QPath::Resolved(_, ref path) => path.span,
hir::QPath::TypeRelative(ref qself, _) => qself.span
QPath::Resolved(_, ref path) => path.span,
QPath::TypeRelative(ref qself, _) => qself.span
};
// Prohibit struct expressions when non-exhaustive flag is set.
@ -3836,9 +3843,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// Warn for non-block expressions with diverging children.
match expr.node {
hir::ExprKind::Block(..) |
hir::ExprKind::Loop(..) | hir::ExprKind::While(..) |
hir::ExprKind::If(..) | hir::ExprKind::Match(..) => {}
ExprKind::Block(..) |
ExprKind::Loop(..) | ExprKind::While(..) |
ExprKind::If(..) | ExprKind::Match(..) => {}
_ => self.warn_if_unreachable(expr.id, expr.span, "expression")
}
@ -3879,7 +3886,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let tcx = self.tcx;
let id = expr.id;
match expr.node {
hir::ExprKind::Box(ref subexpr) => {
ExprKind::Box(ref subexpr) => {
let expected_inner = expected.to_option(self).map_or(NoExpectation, |ty| {
match ty.sty {
ty::Adt(def, _) if def.is_box()
@ -3891,16 +3898,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
tcx.mk_box(referent_ty)
}
hir::ExprKind::Lit(ref lit) => {
ExprKind::Lit(ref lit) => {
self.check_lit(&lit, expected)
}
hir::ExprKind::Binary(op, ref lhs, ref rhs) => {
ExprKind::Binary(op, ref lhs, ref rhs) => {
self.check_binop(expr, op, lhs, rhs)
}
hir::ExprKind::AssignOp(op, ref lhs, ref rhs) => {
ExprKind::AssignOp(op, ref lhs, ref rhs) => {
self.check_binop_assign(expr, op, lhs, rhs)
}
hir::ExprKind::Unary(unop, ref oprnd) => {
ExprKind::Unary(unop, ref oprnd) => {
let expected_inner = match unop {
hir::UnNot | hir::UnNeg => {
expected
@ -3968,7 +3975,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
oprnd_t
}
hir::ExprKind::AddrOf(mutbl, ref oprnd) => {
ExprKind::AddrOf(mutbl, ref oprnd) => {
let hint = expected.only_has_type(self).map_or(NoExpectation, |ty| {
match ty.sty {
ty::Ref(_, ty, _) | ty::RawPtr(ty::TypeAndMut { ty, .. }) => {
@ -4008,13 +4015,18 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
tcx.mk_ref(region, tm)
}
}
hir::ExprKind::Path(ref qpath) => {
ExprKind::Path(ref qpath) => {
let (def, opt_ty, segs) = self.resolve_ty_and_def_ufcs(qpath, expr.id, expr.span);
let ty = if def != Def::Err {
self.instantiate_value_path(segs, opt_ty, def, expr.span, id).0
} else {
self.set_tainted_by_errors();
tcx.types.err
let ty = match def {
Def::Err => {
self.set_tainted_by_errors();
tcx.types.err
}
Def::VariantCtor(_, CtorKind::Fictive) => {
report_unexpected_variant_def(tcx, &def, expr.span, qpath);
tcx.types.err
}
_ => self.instantiate_value_path(segs, opt_ty, def, expr.span, id).0,
};
if let ty::FnDef(..) = ty.sty {
@ -4061,13 +4073,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
ty
}
hir::ExprKind::InlineAsm(_, ref outputs, ref inputs) => {
ExprKind::InlineAsm(_, ref outputs, ref inputs) => {
for expr in outputs.iter().chain(inputs.iter()) {
self.check_expr(expr);
}
tcx.mk_unit()
}
hir::ExprKind::Break(destination, ref expr_opt) => {
ExprKind::Break(destination, ref expr_opt) => {
if let Ok(target_id) = destination.target_id {
let (e_ty, cause);
if let Some(ref e) = *expr_opt {
@ -4140,7 +4152,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// ... except when we try to 'break rust;'.
// ICE this expression in particular (see #43162).
if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = e.node {
if let ExprKind::Path(QPath::Resolved(_, ref path)) = e.node {
if path.segments.len() == 1 && path.segments[0].ident.name == "rust" {
fatally_break_rust(self.tcx.sess);
}
@ -4151,7 +4163,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
}
hir::ExprKind::Continue(destination) => {
ExprKind::Continue(destination) => {
if destination.target_id.is_ok() {
tcx.types.never
} else {
@ -4159,7 +4171,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
tcx.types.err
}
}
hir::ExprKind::Ret(ref expr_opt) => {
ExprKind::Ret(ref expr_opt) => {
if self.ret_coercion.is_none() {
struct_span_err!(self.tcx.sess, expr.span, E0572,
"return statement outside of function body").emit();
@ -4191,7 +4203,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
tcx.types.never
}
hir::ExprKind::Assign(ref lhs, ref rhs) => {
ExprKind::Assign(ref lhs, ref rhs) => {
let lhs_ty = self.check_expr_with_needs(&lhs, Needs::MutPlace);
let rhs_ty = self.check_expr_coercable_to_type(&rhs, lhs_ty);
@ -4221,11 +4233,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
tcx.mk_unit()
}
}
hir::ExprKind::If(ref cond, ref then_expr, ref opt_else_expr) => {
ExprKind::If(ref cond, ref then_expr, ref opt_else_expr) => {
self.check_then_else(&cond, then_expr, opt_else_expr.as_ref().map(|e| &**e),
expr.span, expected)
}
hir::ExprKind::While(ref cond, ref body, _) => {
ExprKind::While(ref cond, ref body, _) => {
let ctxt = BreakableCtxt {
// cannot use break with a value from a while loop
coerce: None,
@ -4249,7 +4261,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
self.tcx.mk_unit()
}
hir::ExprKind::Loop(ref body, _, source) => {
ExprKind::Loop(ref body, _, source) => {
let coerce = match source {
// you can only use break with a value from a normal `loop { }`
hir::LoopSource::Loop => {
@ -4289,22 +4301,22 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
ctxt.coerce.map(|c| c.complete(self)).unwrap_or_else(|| self.tcx.mk_unit())
}
hir::ExprKind::Match(ref discrim, ref arms, match_src) => {
ExprKind::Match(ref discrim, ref arms, match_src) => {
self.check_match(expr, &discrim, arms, expected, match_src)
}
hir::ExprKind::Closure(capture, ref decl, body_id, _, gen) => {
ExprKind::Closure(capture, ref decl, body_id, _, gen) => {
self.check_expr_closure(expr, capture, &decl, body_id, gen, expected)
}
hir::ExprKind::Block(ref body, _) => {
ExprKind::Block(ref body, _) => {
self.check_block_with_expected(&body, expected)
}
hir::ExprKind::Call(ref callee, ref args) => {
ExprKind::Call(ref callee, ref args) => {
self.check_call(expr, &callee, args, expected)
}
hir::ExprKind::MethodCall(ref segment, span, ref args) => {
ExprKind::MethodCall(ref segment, span, ref args) => {
self.check_method_call(expr, segment, span, args, expected, needs)
}
hir::ExprKind::Cast(ref e, ref t) => {
ExprKind::Cast(ref e, ref t) => {
// Find the type of `e`. Supply hints based on the type we are casting to,
// if appropriate.
let t_cast = self.to_ty_saving_user_provided_ty(t);
@ -4329,12 +4341,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
}
}
hir::ExprKind::Type(ref e, ref t) => {
ExprKind::Type(ref e, ref t) => {
let ty = self.to_ty_saving_user_provided_ty(&t);
self.check_expr_eq_type(&e, ty);
ty
}
hir::ExprKind::Array(ref args) => {
ExprKind::Array(ref args) => {
let uty = expected.to_option(self).and_then(|uty| {
match uty.sty {
ty::Array(ty, _) | ty::Slice(ty) => Some(ty),
@ -4358,7 +4370,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
};
tcx.mk_array(element_ty, args.len() as u64)
}
hir::ExprKind::Repeat(ref element, ref count) => {
ExprKind::Repeat(ref element, ref count) => {
let count_def_id = tcx.hir().local_def_id(count.id);
let param_env = ty::ParamEnv::empty();
let substs = Substs::identity_for_item(tcx.global_tcx(), count_def_id);
@ -4414,7 +4426,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
tcx.types.err
}
}
hir::ExprKind::Tup(ref elts) => {
ExprKind::Tup(ref elts) => {
let flds = expected.only_has_type(self).and_then(|ty| {
let ty = self.resolve_type_vars_with_obligations(ty);
match ty.sty {
@ -4444,13 +4456,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
tuple
}
}
hir::ExprKind::Struct(ref qpath, ref fields, ref base_expr) => {
ExprKind::Struct(ref qpath, ref fields, ref base_expr) => {
self.check_expr_struct(expr, expected, qpath, fields, base_expr)
}
hir::ExprKind::Field(ref base, field) => {
ExprKind::Field(ref base, field) => {
self.check_field(expr, needs, &base, field)
}
hir::ExprKind::Index(ref base, ref idx) => {
ExprKind::Index(ref base, ref idx) => {
let base_t = self.check_expr_with_needs(&base, needs);
let idx_t = self.check_expr(&idx);
@ -4476,7 +4488,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let mut needs_note = true;
// If the index is an integer, we can show the actual
// fixed expression:
if let hir::ExprKind::Lit(ref lit) = idx.node {
if let ExprKind::Lit(ref lit) = idx.node {
if let ast::LitKind::Int(i,
ast::LitIntType::Unsuffixed) = lit.node {
let snip = tcx.sess.source_map().span_to_snippet(base.span);
@ -4501,7 +4513,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
}
}
hir::ExprKind::Yield(ref value) => {
ExprKind::Yield(ref value) => {
match self.yield_ty {
Some(ty) => {
self.check_expr_coercable_to_type(&value, ty);
@ -4522,21 +4534,21 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// Finish resolving a path in a struct expression or pattern `S::A { .. }` if necessary.
// The newly resolved definition is written into `type_dependent_defs`.
fn finish_resolving_struct_path(&self,
qpath: &hir::QPath,
qpath: &QPath,
path_span: Span,
node_id: ast::NodeId)
-> (Def, Ty<'tcx>)
{
match *qpath {
hir::QPath::Resolved(ref maybe_qself, ref path) => {
QPath::Resolved(ref maybe_qself, ref path) => {
let self_ty = maybe_qself.as_ref().map(|qself| self.to_ty(qself));
let ty = AstConv::def_to_ty(self, self_ty, path, true);
(path.def, ty)
}
hir::QPath::TypeRelative(ref qself, ref segment) => {
QPath::TypeRelative(ref qself, ref segment) => {
let ty = self.to_ty(qself);
let def = if let hir::TyKind::Path(hir::QPath::Resolved(_, ref path)) = qself.node {
let def = if let hir::TyKind::Path(QPath::Resolved(_, ref path)) = qself.node {
path.def
} else {
Def::Err
@ -4556,19 +4568,19 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// Resolve associated value path into a base type and associated constant or method definition.
// The newly resolved definition is written into `type_dependent_defs`.
pub fn resolve_ty_and_def_ufcs<'b>(&self,
qpath: &'b hir::QPath,
qpath: &'b QPath,
node_id: ast::NodeId,
span: Span)
-> (Def, Option<Ty<'tcx>>, &'b [hir::PathSegment])
{
let (ty, item_segment) = match *qpath {
hir::QPath::Resolved(ref opt_qself, ref path) => {
let (ty, qself, item_segment) = match *qpath {
QPath::Resolved(ref opt_qself, ref path) => {
return (path.def,
opt_qself.as_ref().map(|qself| self.to_ty(qself)),
&path.segments[..]);
}
hir::QPath::TypeRelative(ref qself, ref segment) => {
(self.to_ty(qself), segment)
QPath::TypeRelative(ref qself, ref segment) => {
(self.to_ty(qself), qself, segment)
}
};
let hir_id = self.tcx.hir().node_to_hir_id(node_id);
@ -4586,7 +4598,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
_ => Def::Err,
};
if item_name.name != keywords::Invalid.name() {
self.report_method_error(span, ty, item_name, None, error, None);
self.report_method_error(span,
ty,
item_name,
SelfSource::QPath(qself),
error,
None);
}
def
}
@ -4601,7 +4618,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
local: &'gcx hir::Local,
init: &'gcx hir::Expr) -> Ty<'tcx>
{
// FIXME(tschottdorf): contains_explicit_ref_binding() must be removed
// FIXME(tschottdorf): `contains_explicit_ref_binding()` must be removed
// for #42640 (default match binding modes).
//
// See #44848.
@ -4646,7 +4663,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
pub fn check_stmt(&self, stmt: &'gcx hir::Stmt) {
// Don't do all the complex logic below for DeclItem.
// Don't do all the complex logic below for `DeclItem`.
match stmt.node {
hir::StmtKind::Decl(ref decl, _) => {
if let hir::DeclKind::Item(_) = decl.node {
@ -4658,7 +4675,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
self.warn_if_unreachable(stmt.node.id(), stmt.span, "statement");
// Hide the outer diverging and has_errors flags.
// Hide the outer diverging and `has_errors` flags.
let old_diverges = self.diverges.get();
let old_has_errors = self.has_errors.get();
self.diverges.set(Diverges::Maybe);
@ -4670,11 +4687,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
hir::DeclKind::Local(ref l) => {
self.check_decl_local(&l);
}
hir::DeclKind::Item(_) => {/* ignore for now */}
// Ignore for now.
hir::DeclKind::Item(_) => ()
}
}
hir::StmtKind::Expr(ref expr, _) => {
// Check with expected type of ()
// Check with expected type of `()`.
self.check_expr_has_type_or_error(&expr, self.tcx.mk_unit());
}
hir::StmtKind::Semi(ref expr, _) => {
@ -4682,7 +4700,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
}
// Combine the diverging and has_error flags.
// Combine the diverging and `has_error` flags.
self.diverges.set(self.diverges.get() | old_diverges);
self.has_errors.set(self.has_errors.get() | old_has_errors);
}
@ -4811,13 +4829,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let parent = self.tcx.hir().get(fn_id);
if let Node::Item(&hir::Item {
name, node: hir::ItemKind::Fn(ref decl, ..), ..
ident, node: hir::ItemKind::Fn(ref decl, ..), ..
}) = parent {
decl.clone().and_then(|decl| {
// This is less than ideal, it will not suggest a return type span on any
// method called `main`, regardless of whether it is actually the entry point,
// but it will still present it as the reason for the expected type.
Some((decl, name != Symbol::intern("main")))
Some((decl, ident.name != Symbol::intern("main")))
})
} else if let Node::TraitItem(&hir::TraitItem {
node: hir::TraitItemKind::Method(hir::MethodSig {
@ -4928,13 +4946,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// `BlockTailExpression` only relevant if the tail expr would be
// useful on its own.
match expression.node {
hir::ExprKind::Call(..) |
hir::ExprKind::MethodCall(..) |
hir::ExprKind::If(..) |
hir::ExprKind::While(..) |
hir::ExprKind::Loop(..) |
hir::ExprKind::Match(..) |
hir::ExprKind::Block(..) => {
ExprKind::Call(..) |
ExprKind::MethodCall(..) |
ExprKind::If(..) |
ExprKind::While(..) |
ExprKind::Loop(..) |
ExprKind::Match(..) |
ExprKind::Block(..) => {
let sp = self.tcx.sess.source_map().next_point(cause_span);
err.span_suggestion_with_applicability(
sp,
@ -5038,101 +5056,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
Applicability::MachineApplicable);
}
fn def_ids_for_path_segments(&self,
segments: &[hir::PathSegment],
def: Def)
-> Vec<PathSeg> {
// We need to extract the type parameters supplied by the user in
// the path `path`. Due to the current setup, this is a bit of a
// tricky-process; the problem is that resolve only tells us the
// end-point of the path resolution, and not the intermediate steps.
// Luckily, we can (at least for now) deduce the intermediate steps
// just from the end-point.
//
// There are basically four cases to consider:
//
// 1. Reference to a constructor of enum variant or struct:
//
// struct Foo<T>(...)
// enum E<T> { Foo(...) }
//
// In these cases, the parameters are declared in the type
// space.
//
// 2. Reference to a fn item or a free constant:
//
// fn foo<T>() { }
//
// In this case, the path will again always have the form
// `a::b::foo::<T>` where only the final segment should have
// type parameters. However, in this case, those parameters are
// declared on a value, and hence are in the `FnSpace`.
//
// 3. Reference to a method or an associated constant:
//
// impl<A> SomeStruct<A> {
// fn foo<B>(...)
// }
//
// Here we can have a path like
// `a::b::SomeStruct::<A>::foo::<B>`, in which case parameters
// may appear in two places. The penultimate segment,
// `SomeStruct::<A>`, contains parameters in TypeSpace, and the
// final segment, `foo::<B>` contains parameters in fn space.
//
// 4. Reference to a local variable
//
// Local variables can't have any type parameters.
//
// The first step then is to categorize the segments appropriately.
assert!(!segments.is_empty());
let last = segments.len() - 1;
let mut path_segs = vec![];
match def {
// Case 1. Reference to a struct/variant constructor.
Def::StructCtor(def_id, ..) |
Def::VariantCtor(def_id, ..) |
Def::SelfCtor(.., def_id) => {
// Everything but the final segment should have no
// parameters at all.
let generics = self.tcx.generics_of(def_id);
// Variant and struct constructors use the
// generics of their parent type definition.
let generics_def_id = generics.parent.unwrap_or(def_id);
path_segs.push(PathSeg(generics_def_id, last));
}
// Case 2. Reference to a top-level value.
Def::Fn(def_id) |
Def::Const(def_id) |
Def::Static(def_id, _) => {
path_segs.push(PathSeg(def_id, last));
}
// Case 3. Reference to a method or associated const.
Def::Method(def_id) |
Def::AssociatedConst(def_id) => {
if segments.len() >= 2 {
let generics = self.tcx.generics_of(def_id);
path_segs.push(PathSeg(generics.parent.unwrap(), last - 1));
}
path_segs.push(PathSeg(def_id, last));
}
// Case 4. Local variable, no generics.
Def::Local(..) | Def::Upvar(..) => {}
_ => bug!("unexpected definition: {:?}", def),
}
debug!("path_segs = {:?}", path_segs);
path_segs
}
// Instantiates the given path, which must refer to an item with the given
// number of type parameters and type.
pub fn instantiate_value_path(&self,
@ -5150,16 +5073,29 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
node_id,
);
let path_segs = self.def_ids_for_path_segments(segments, def);
let tcx = self.tcx;
let path_segs = AstConv::def_ids_for_path_segments(self, segments, self_ty, def);
let mut user_self_ty = None;
let mut is_alias_variant_ctor = false;
match def {
Def::VariantCtor(_, _) => {
if let Some(self_ty) = self_ty {
let adt_def = self_ty.ty_adt_def().unwrap();
user_self_ty = Some(UserSelfTy {
impl_def_id: adt_def.did,
self_ty,
});
is_alias_variant_ctor = true;
}
}
Def::Method(def_id) |
Def::AssociatedConst(def_id) => {
let container = self.tcx.associated_item(def_id).container;
let container = tcx.associated_item(def_id).container;
match container {
ty::TraitContainer(trait_did) => {
callee::check_legal_trait_for_method_call(self.tcx, span, trait_did)
callee::check_legal_trait_for_method_call(tcx, span, trait_did)
}
ty::ImplContainer(impl_def_id) => {
if segments.len() == 1 {
@ -5185,21 +5121,25 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// provided (if any) into their appropriate spaces. We'll also report
// errors if type parameters are provided in an inappropriate place.
let generic_segs = path_segs.iter().map(|PathSeg(_, index)| index)
.collect::<FxHashSet<_>>();
AstConv::prohibit_generics(self, segments.iter().enumerate().filter_map(|(index, seg)| {
if !generic_segs.contains(&index) {
let generic_segs: FxHashSet<_> = path_segs.iter().map(|PathSeg(_, index)| index).collect();
let generics_has_err = AstConv::prohibit_generics(
self, segments.iter().enumerate().filter_map(|(index, seg)| {
if !generic_segs.contains(&index) || is_alias_variant_ctor {
Some(seg)
} else {
None
}
}));
if generics_has_err {
// Don't try to infer type parameters when prohibited generic arguments were given.
user_self_ty = None;
}
match def {
Def::Local(nid) | Def::Upvar(nid, ..) => {
let ty = self.local_ty(span, nid).decl_ty;
let ty = self.normalize_associated_types_in(span, &ty);
self.write_ty(self.tcx.hir().node_to_hir_id(node_id), ty);
self.write_ty(tcx.hir().node_to_hir_id(node_id), ty);
return (ty, def);
}
_ => {}
@ -5215,13 +5155,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let mut infer_args_for_err = FxHashSet::default();
for &PathSeg(def_id, index) in &path_segs {
let seg = &segments[index];
let generics = self.tcx.generics_of(def_id);
let generics = tcx.generics_of(def_id);
// Argument-position `impl Trait` is treated as a normal generic
// parameter internally, but we don't allow users to specify the
// parameter's value explicitly, so we have to do some error-
// checking here.
let suppress_errors = AstConv::check_generic_arg_count_for_call(
self.tcx,
tcx,
span,
&generics,
&seg,
@ -5234,7 +5174,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
let has_self = path_segs.last().map(|PathSeg(def_id, _)| {
self.tcx.generics_of(*def_id).has_self
tcx.generics_of(*def_id).has_self
}).unwrap_or(false);
let mut new_def = def;
@ -5247,10 +5187,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
Some(adt_def) if adt_def.has_ctor() => {
let variant = adt_def.non_enum_variant();
new_def = Def::StructCtor(variant.did, variant.ctor_kind);
(variant.did, self.tcx.type_of(variant.did))
(variant.did, tcx.type_of(variant.did))
}
_ => {
let mut err = self.tcx.sess.struct_span_err(span,
let mut err = tcx.sess.struct_span_err(span,
"the `Self` constructor can only be used with tuple or unit structs");
if let Some(adt_def) = adt_def {
match adt_def.adt_kind() {
@ -5268,7 +5208,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
err.emit();
(impl_def_id, self.tcx.types.err)
(impl_def_id, tcx.types.err)
}
}
}
@ -5277,13 +5217,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// The things we are substituting into the type should not contain
// escaping late-bound regions, and nor should the base type scheme.
let ty = self.tcx.type_of(def_id);
let ty = tcx.type_of(def_id);
(def_id, ty)
}
};
let substs = AstConv::create_substs_for_generic_args(
self.tcx,
tcx,
def_id,
&[][..],
has_self,
@ -5329,10 +5269,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// If we have a default, then we it doesn't matter that we're not
// inferring the type arguments: we provide the default where any
// is missing.
let default = self.tcx.type_of(param.def_id);
let default = tcx.type_of(param.def_id);
self.normalize_ty(
span,
default.subst_spanned(self.tcx, substs.unwrap(), Some(span))
default.subst_spanned(tcx, substs.unwrap(), Some(span))
).into()
} else {
// If no type arguments were provided, we have to infer them.
@ -5349,7 +5289,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
assert!(!ty.has_escaping_bound_vars());
// First, store the "user substs" for later.
let hir_id = self.tcx.hir().node_to_hir_id(node_id);
let hir_id = tcx.hir().node_to_hir_id(node_id);
self.write_user_substs_from_substs(hir_id, substs, user_self_ty);
// Add all the obligations that are required, substituting and
@ -5365,10 +5305,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
if let Some(UserSelfTy { impl_def_id, self_ty }) = user_self_ty {
// In the case of `Foo<T>::method` and `<Foo<T>>::method`, if `method`
// is inherent, there is no `Self` parameter, instead, the impl needs
// is inherent, there is no `Self` parameter; instead, the impl needs
// type parameters, which we can infer by unifying the provided `Self`
// with the substituted impl type.
let ty = self.tcx.type_of(impl_def_id);
// This also occurs for an enum variant on a type alias.
let ty = tcx.type_of(impl_def_id);
let impl_ty = self.instantiate_type_scheme(span, &substs, &ty);
match self.at(&self.misc(span), self.param_env).sup(impl_ty, self_ty) {
@ -5405,7 +5346,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// If our calling expression is indeed the function itself, we're good!
// If not, generate an error that this can only be called directly.
if let Node::Expr(expr) = self.tcx.hir().get(self.tcx.hir().get_parent_node(node_id)) {
if let hir::ExprKind::Call(ref callee, ..) = expr.node {
if let ExprKind::Call(ref callee, ..) = expr.node {
if callee.id == node_id {
return
}

View File

@ -154,7 +154,7 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) {
// If the extern crate isn't in the extern prelude,
// there is no way it can be written as an `use`.
let orig_name = extern_crate.orig_name.unwrap_or(item.name);
let orig_name = extern_crate.orig_name.unwrap_or(item.ident.name);
if !tcx.extern_prelude.get(&orig_name).map_or(false, |from_item| !from_item) {
continue;
}
@ -173,8 +173,8 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) {
visibility_qualified(&item.vis, "use")
);
let base_replacement = match extern_crate.orig_name {
Some(orig_name) => format!("use {} as {};", orig_name, item.name),
None => format!("use {};", item.name),
Some(orig_name) => format!("use {} as {};", orig_name, item.ident.name),
None => format!("use {};", item.ident.name),
};
let replacement = visibility_qualified(&item.vis, base_replacement);
tcx.struct_span_lint_node(lint, id, extern_crate.span, msg)
@ -219,7 +219,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for CollectExternCrateVisitor<'a, 'tcx> {
def_id: extern_crate_def_id,
span: item.span,
orig_name,
warn_if_unused: !item.name.as_str().starts_with('_'),
warn_if_unused: !item.ident.as_str().starts_with('_'),
}
);
}

View File

@ -33,7 +33,7 @@ use rustc_data_structures::sync::Lrc;
use rustc_target::spec::abi;
use syntax::ast;
use syntax::ast::MetaItemKind;
use syntax::ast::{Ident, MetaItemKind};
use syntax::attr::{InlineAttr, list_contains_name, mark_used};
use syntax::source_map::Spanned;
use syntax::feature_gate;
@ -385,7 +385,7 @@ fn is_param<'a, 'tcx>(
fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: ast::NodeId) {
let it = tcx.hir().expect_item(item_id);
debug!("convert: item {} with id {}", it.name, it.id);
debug!("convert: item {} with id {}", it.ident, it.id);
let def_id = tcx.hir().local_def_id(item_id);
match it.node {
// These don't define types.
@ -533,7 +533,7 @@ fn convert_enum_variant_types<'a, 'tcx>(
format!("overflowed on value after {}", prev_discr.unwrap()),
).note(&format!(
"explicitly set `{} = {}` if that is desired outcome",
variant.node.name, wrapped_discr
variant.node.ident, wrapped_discr
))
.emit();
None
@ -556,7 +556,7 @@ fn convert_enum_variant_types<'a, 'tcx>(
fn convert_variant<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
did: DefId,
name: ast::Name,
ident: Ident,
discr: ty::VariantDiscr,
def: &hir::VariantData,
adt_kind: ty::AdtKind,
@ -593,12 +593,13 @@ fn convert_variant<'a, 'tcx>(
.collect();
ty::VariantDef::new(tcx,
did,
name,
ident,
discr,
fields,
adt_kind,
CtorKind::from_hir(def),
attribute_def_id)
attribute_def_id
)
}
fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::AdtDef {
@ -628,7 +629,7 @@ fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::Ad
};
distance_from_explicit += 1;
convert_variant(tcx, did, v.node.name, discr, &v.node.data, AdtKind::Enum,
convert_variant(tcx, did, v.node.ident, discr, &v.node.data, AdtKind::Enum,
did)
})
.collect(),
@ -646,7 +647,7 @@ fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::Ad
std::iter::once(convert_variant(
tcx,
ctor_id.unwrap_or(def_id),
item.name,
item.ident,
ty::VariantDiscr::Relative(0),
def,
AdtKind::Struct,
@ -659,7 +660,7 @@ fn adt_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::Ad
std::iter::once(convert_variant(
tcx,
def_id,
item.name,
item.ident,
ty::VariantDiscr::Relative(0),
def,
AdtKind::Union,

View File

@ -1291,7 +1291,7 @@ You tried to give a type parameter to a type which doesn't need it. Erroneous
code example:
```compile_fail,E0109
type X = u32<i32>; // error: type parameters are not allowed on this type
type X = u32<i32>; // error: type arguments are not allowed on this entity
```
Please check that you used the correct type and recheck its definition. Perhaps

View File

@ -111,6 +111,7 @@ use rustc::infer::InferOk;
use rustc::lint;
use rustc::middle;
use rustc::session;
use rustc::session::config::nightly_options;
use rustc::traits::{ObligationCause, ObligationCauseCode, TraitEngine, TraitEngineExt};
use rustc::ty::subst::Substs;
use rustc::ty::{self, Ty, TyCtxt};
@ -129,6 +130,22 @@ pub struct TypeAndSubsts<'tcx> {
ty: Ty<'tcx>,
}
fn check_type_alias_enum_variants_enabled<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
span: Span) {
if !tcx.features().type_alias_enum_variants {
let mut err = tcx.sess.struct_span_err(
span,
"enum variants on type aliases are experimental"
);
if nightly_options::is_nightly_build() {
help!(&mut err,
"add `#![feature(type_alias_enum_variants)]` to the \
crate attributes to enable");
}
err.emit();
}
}
fn require_c_abi_if_variadic(tcx: TyCtxt,
decl: &hir::FnDecl,
abi: Abi,

View File

@ -2967,7 +2967,7 @@ impl<'tcx> Clean<Item> for ty::VariantDef {
}
};
Item {
name: Some(self.name.clean(cx)),
name: Some(self.ident.clean(cx)),
attrs: inline::load_attrs(cx, self.did),
source: cx.tcx.def_span(self.did).clean(cx),
visibility: Some(Inherited),
@ -3183,13 +3183,22 @@ fn qpath_to_string(p: &hir::QPath) -> String {
s
}
impl Clean<String> for Ident {
#[inline]
fn clean(&self, cx: &DocContext) -> String {
self.name.clean(cx)
}
}
impl Clean<String> for ast::Name {
#[inline]
fn clean(&self, _: &DocContext) -> String {
self.to_string()
}
}
impl Clean<String> for InternedString {
#[inline]
fn clean(&self, _: &DocContext) -> String {
self.to_string()
}
@ -3616,7 +3625,7 @@ impl Clean<Item> for hir::ForeignItem {
};
Item {
name: Some(self.name.clean(cx)),
name: Some(self.ident.clean(cx)),
attrs: self.attrs.clean(cx),
source: self.span.clean(cx),
def_id: cx.tcx.hir().local_def_id(self.id),
@ -3951,7 +3960,7 @@ pub fn path_to_def_local(tcx: &TyCtxt, path: &[&str]) -> Option<DefId> {
for item_id in mem::replace(&mut items, HirVec::new()).iter() {
let item = tcx.hir().expect_item(item_id.id);
if item.name == *segment {
if item.ident.name == *segment {
if path_it.peek().is_none() {
return Some(tcx.hir().local_def_id(item_id.id))
}

View File

@ -632,7 +632,7 @@ fn handle_variant(cx: &DocContext, def: Def) -> Result<(Def, Option<String>), ()
};
let parent_def = Def::Enum(parent);
let variant = cx.tcx.expect_variant_def(def);
Ok((parent_def, Some(format!("{}.v", variant.name))))
Ok((parent_def, Some(format!("{}.v", variant.ident.name))))
}
const PRIMITIVES: &[(&str, Def)] = &[

View File

@ -811,7 +811,7 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirCollector<'a, 'hir> {
let name = if let hir::ItemKind::Impl(.., ref ty, _) = item.node {
self.map.node_to_pretty_string(ty.id)
} else {
item.name.to_string()
item.ident.to_string()
};
self.visit_testable(name, &item.attrs, |this| {
@ -832,7 +832,7 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirCollector<'a, 'hir> {
}
fn visit_foreign_item(&mut self, item: &'hir hir::ForeignItem) {
self.visit_testable(item.name.to_string(), &item.attrs, |this| {
self.visit_testable(item.ident.to_string(), &item.attrs, |this| {
intravisit::walk_foreign_item(this, item);
});
}
@ -841,7 +841,7 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirCollector<'a, 'hir> {
v: &'hir hir::Variant,
g: &'hir hir::Generics,
item_id: ast::NodeId) {
self.visit_testable(v.node.name.to_string(), &v.node.attrs, |this| {
self.visit_testable(v.node.ident.to_string(), &v.node.attrs, |this| {
intravisit::walk_variant(this, v, g, item_id);
});
}

View File

@ -139,7 +139,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
Enum {
name,
variants: def.variants.iter().map(|v| Variant {
name: v.node.name,
name: v.node.ident.name,
attrs: v.node.attrs.clone(),
stab: self.stability(v.node.data.id()),
depr: self.deprecation(v.node.data.id()),
@ -263,7 +263,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
fn maybe_inline_local(&mut self,
id: ast::NodeId,
def: Def,
renamed: Option<ast::Name>,
renamed: Option<ast::Ident>,
glob: bool,
om: &mut Module,
please_inline: bool) -> bool {
@ -357,14 +357,14 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
om.foreigns.push(hir::ForeignMod {
abi: tcx.hir().get_foreign_abi(it.id),
items: vec![hir::ForeignItem {
name: renamed.unwrap_or(it.name),
ident: renamed.unwrap_or(it.ident),
.. it.clone()
}].into(),
});
true
}
Node::MacroDef(def) if !glob => {
om.macros.push(self.visit_local_macro(def, renamed));
om.macros.push(self.visit_local_macro(def, renamed.map(|i| i.name)));
true
}
_ => false,
@ -374,9 +374,9 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
}
pub fn visit_item(&mut self, item: &hir::Item,
renamed: Option<ast::Name>, om: &mut Module) {
renamed: Option<ast::Ident>, om: &mut Module) {
debug!("Visiting item {:?}", item);
let name = renamed.unwrap_or(item.name);
let ident = renamed.unwrap_or(item.ident);
if item.vis.node.is_pub() {
let def_id = self.cx.tcx.hir().local_def_id(item.id);
@ -403,7 +403,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
om.extern_crates.push(ExternCrate {
cnum: self.cx.tcx.extern_mod_stmt_cnum(def_id)
.unwrap_or(LOCAL_CRATE),
name,
name: ident.name,
path: orig_name.map(|x|x.to_string()),
vis: item.vis.clone(),
attrs: item.attrs.clone(),
@ -433,10 +433,10 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
_ => false,
}
});
let name = if is_glob { None } else { Some(name) };
let ident = if is_glob { None } else { Some(ident) };
if self.maybe_inline_local(item.id,
path.def,
name,
ident,
is_glob,
om,
please_inline) {
@ -445,7 +445,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
}
om.imports.push(Import {
name,
name: ident.name,
id: item.id,
vis: item.vis.clone(),
attrs: item.attrs.clone(),
@ -460,21 +460,21 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
item.vis.clone(),
item.id,
m,
Some(name)));
Some(ident.name)));
},
hir::ItemKind::Enum(ref ed, ref gen) =>
om.enums.push(self.visit_enum_def(item, name, ed, gen)),
om.enums.push(self.visit_enum_def(item, ident.name, ed, gen)),
hir::ItemKind::Struct(ref sd, ref gen) =>
om.structs.push(self.visit_variant_data(item, name, sd, gen)),
om.structs.push(self.visit_variant_data(item, ident.name, sd, gen)),
hir::ItemKind::Union(ref sd, ref gen) =>
om.unions.push(self.visit_union_data(item, name, sd, gen)),
om.unions.push(self.visit_union_data(item, ident.name, sd, gen)),
hir::ItemKind::Fn(ref fd, header, ref gen, body) =>
self.visit_fn(om, item, name, &**fd, header, gen, body),
self.visit_fn(om, item, ident.name, &**fd, header, gen, body),
hir::ItemKind::Ty(ref ty, ref gen) => {
let t = Typedef {
ty: ty.clone(),
gen: gen.clone(),
name,
name: ident.name,
id: item.id,
attrs: item.attrs.clone(),
whence: item.span,
@ -487,7 +487,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
hir::ItemKind::Existential(ref exist_ty) => {
let t = Existential {
exist_ty: exist_ty.clone(),
name,
name: ident.name,
id: item.id,
attrs: item.attrs.clone(),
whence: item.span,
@ -503,7 +503,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
mutability: mut_.clone(),
expr: exp.clone(),
id: item.id,
name,
name: ident.name,
attrs: item.attrs.clone(),
whence: item.span,
vis: item.vis.clone(),
@ -517,7 +517,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
type_: ty.clone(),
expr: exp.clone(),
id: item.id,
name,
name: ident.name,
attrs: item.attrs.clone(),
whence: item.span,
vis: item.vis.clone(),
@ -533,7 +533,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
let t = Trait {
is_auto,
unsafety,
name,
name: ident.name,
items,
generics: gen.clone(),
bounds: b.iter().cloned().collect(),

View File

@ -471,11 +471,14 @@ declare_features! (
// Allows `const _: TYPE = VALUE`.
(active, underscore_const_names, "1.31.0", Some(54912), None),
// `reason = ` in lint attributes and `expect` lint attribute
// Adds `reason` and `expect` lint attributes.
(active, lint_reasons, "1.31.0", Some(54503), None),
// `extern crate self as foo;` puts local crate root into extern prelude under name `foo`.
(active, extern_crate_self, "1.31.0", Some(56409), None),
// Allows paths to enum variants on type aliases.
(active, type_alias_enum_variants, "1.31.0", Some(49683), None),
);
declare_features! (

View File

@ -0,0 +1,51 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// force-host
#![feature(plugin_registrar)]
#![feature(box_syntax, rustc_private)]
// Load rustc as a plugin to get macros.
#[macro_use]
extern crate rustc;
extern crate rustc_plugin;
use rustc::hir;
use rustc::lint::{LateContext, LintContext, LintPass, LateLintPass, LateLintPassObject, LintArray};
use rustc_plugin::Registry;
declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'");
declare_lint!(PLEASE_LINT, Warn, "Warn about items named 'pleaselintme'");
struct Pass;
impl LintPass for Pass {
fn get_lints(&self) -> LintArray {
lint_array!(TEST_LINT, PLEASE_LINT)
}
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
match &*it.ident.as_str() {
"lintme" => cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"),
"pleaselintme" => cx.span_lint(PLEASE_LINT, it.span, "item is named 'pleaselintme'"),
_ => {}
}
}
}
#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
reg.register_late_lint_pass(box Pass);
reg.register_lint_group("lint_me", None, vec![TEST_LINT, PLEASE_LINT]);
}

View File

@ -0,0 +1,42 @@
#![feature(irrefutable_let_patterns)]
#![feature(type_alias_enum_variants)]
#![allow(irrefutable_let_patterns)]
#[allow(dead_code)]
enum Enum<T> { TSVariant(T), SVariant { v: T } }
type Alias<T> = Enum<T>;
type AliasFixed = Enum<()>;
macro_rules! is_variant {
(TSVariant, $expr:expr) => (is_variant!(@check TSVariant, (_), $expr));
(SVariant, $expr:expr) => (is_variant!(@check SVariant, { v: _ }, $expr));
(@check $variant:ident, $matcher:tt, $expr:expr) => (
assert!(if let Enum::$variant::<()> $matcher = $expr { true } else { false },
"expr does not have correct type");
);
}
fn main() {
// Tuple struct variant
is_variant!(TSVariant, Enum::TSVariant(()));
is_variant!(TSVariant, Enum::TSVariant::<()>(()));
is_variant!(TSVariant, Enum::<()>::TSVariant(()));
is_variant!(TSVariant, Alias::TSVariant(()));
is_variant!(TSVariant, Alias::<()>::TSVariant(()));
is_variant!(TSVariant, AliasFixed::TSVariant(()));
// Struct variant
is_variant!(SVariant, Enum::SVariant { v: () });
is_variant!(SVariant, Enum::SVariant::<()> { v: () });
is_variant!(SVariant, Enum::<()>::SVariant { v: () });
is_variant!(SVariant, Alias::SVariant { v: () });
is_variant!(SVariant, Alias::<()>::SVariant { v: () });
is_variant!(SVariant, AliasFixed::SVariant { v: () });
}

View File

@ -0,0 +1,30 @@
#![feature(type_alias_enum_variants)]
#[derive(Debug, PartialEq, Eq)]
enum Foo {
Bar(i32),
Baz { i: i32 },
}
type FooAlias = Foo;
type OptionAlias = Option<i32>;
impl Foo {
fn foo() -> Self {
Self::Bar(3)
}
}
fn main() {
let t = FooAlias::Bar(1);
assert_eq!(t, Foo::Bar(1));
let t = FooAlias::Baz { i: 2 };
assert_eq!(t, Foo::Baz { i: 2 });
match t {
FooAlias::Bar(_i) => {}
FooAlias::Baz { i } => { assert_eq!(i, 2); }
}
assert_eq!(Foo::foo(), Foo::Bar(3));
assert_eq!(OptionAlias::Some(4), Option::Some(4));
}

View File

@ -0,0 +1,30 @@
#![feature(type_alias_enum_variants)]
#[derive(Debug, PartialEq, Eq)]
enum Foo {
Bar(i32),
Baz { i: i32 },
}
type FooAlias = Foo;
type OptionAlias = Option<i32>;
impl Foo {
fn foo() -> Self {
Self::Bar(3)
}
}
fn main() {
let t = FooAlias::Bar(1);
assert_eq!(t, Foo::Bar(1));
let t = FooAlias::Baz { i: 2 };
assert_eq!(t, Foo::Baz { i: 2 });
match t {
FooAlias::Bar(_i) => {}
FooAlias::Baz { i } => { assert_eq!(i, 2); }
}
assert_eq!(Foo::foo(), Foo::Bar(3));
assert_eq!(OptionAlias::Some(4), Option::Some(4));
}

View File

@ -3,7 +3,7 @@
#![feature(plugin_registrar)]
#![feature(box_syntax, rustc_private)]
// Load rustc as a plugin to get macros
// Load rustc as a plugin to get macros.
#[macro_use]
extern crate rustc;
extern crate rustc_plugin;
@ -26,7 +26,7 @@ impl LintPass for Pass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
match &*it.name.as_str() {
match &*it.ident.as_str() {
"lintme" => cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"),
"pleaselintme" => cx.span_lint(PLEASE_LINT, it.span, "item is named 'pleaselintme'"),
_ => {}

View File

@ -1,6 +1,7 @@
// run-pass
// aux-build:lint_group_plugin_test.rs
// ignore-stage1
#![feature(plugin)]
#![plugin(lint_group_plugin_test)]
#![allow(dead_code)]

View File

@ -1,5 +1,5 @@
warning: item is named 'lintme'
--> $DIR/lint-group-plugin.rs:8:1
--> $DIR/lint-group-plugin.rs:9:1
|
LL | fn lintme() { } //~ WARNING item is named 'lintme'
| ^^^^^^^^^^^^^^^
@ -7,7 +7,7 @@ LL | fn lintme() { } //~ WARNING item is named 'lintme'
= note: #[warn(test_lint)] on by default
warning: item is named 'pleaselintme'
--> $DIR/lint-group-plugin.rs:9:1
--> $DIR/lint-group-plugin.rs:10:1
|
LL | fn pleaselintme() { } //~ WARNING item is named 'pleaselintme'
| ^^^^^^^^^^^^^^^^^^^^^

View File

@ -1,8 +1,10 @@
error[E0599]: no associated item named `ID` found for type `i32` in the current scope
--> $DIR/associated-const-no-item.rs:5:16
--> $DIR/associated-const-no-item.rs:5:23
|
LL | const X: i32 = <i32>::ID;
| ^^^^^^^^^ associated item not found in `i32`
| -------^^
| |
| associated item not found in `i32`
|
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `ID`, perhaps you need to implement it:

View File

@ -3,8 +3,8 @@ enum Color { Rgb(isize, isize, isize), Rgba(isize, isize, isize, isize), }
fn main() {
let red: Color = Color::Rgb(255, 0, 0);
match red {
Color::Rgb(r, g, b) => { println!("rgb"); }
Color::Hsl(h, s, l) => { println!("hsl"); }
//~^ ERROR no variant
Color::Rgb(r, g, b) => { println!("rgb"); }
Color::Hsl(h, s, l) => { println!("hsl"); }
//~^ ERROR no variant
}
}

View File

@ -1,11 +1,11 @@
error[E0599]: no variant named `Hsl` found for type `Color` in the current scope
--> $DIR/bogus-tag.rs:7:7
--> $DIR/bogus-tag.rs:7:16
|
LL | enum Color { Rgb(isize, isize, isize), Rgba(isize, isize, isize, isize), }
| ---------- variant `Hsl` not found here
...
LL | Color::Hsl(h, s, l) => { println!("hsl"); }
| ^^^^^^^^^^^^^^^^^^^ variant not found in `Color`
LL | Color::Hsl(h, s, l) => { println!("hsl"); }
| -------^^^--------- variant not found in `Color`
error: aborting due to previous error

View File

@ -23,28 +23,36 @@ LL | &(u8,)::AssocItem => {}
| ^^^^^^^^^^^^^^^^ help: try: `<(u8,)>::AssocItem`
error[E0599]: no associated item named `AssocItem` found for type `[u8]` in the current scope
--> $DIR/bad-assoc-pat.rs:3:9
--> $DIR/bad-assoc-pat.rs:3:15
|
LL | [u8]::AssocItem => {}
| ^^^^^^^^^^^^^^^ associated item not found in `[u8]`
| ------^^^^^^^^^
| |
| associated item not found in `[u8]`
error[E0599]: no associated item named `AssocItem` found for type `(u8, u8)` in the current scope
--> $DIR/bad-assoc-pat.rs:6:9
--> $DIR/bad-assoc-pat.rs:6:19
|
LL | (u8, u8)::AssocItem => {}
| ^^^^^^^^^^^^^^^^^^^ associated item not found in `(u8, u8)`
| ----------^^^^^^^^^
| |
| associated item not found in `(u8, u8)`
error[E0599]: no associated item named `AssocItem` found for type `_` in the current scope
--> $DIR/bad-assoc-pat.rs:9:9
--> $DIR/bad-assoc-pat.rs:9:12
|
LL | _::AssocItem => {}
| ^^^^^^^^^^^^ associated item not found in `_`
| ---^^^^^^^^^
| |
| associated item not found in `_`
error[E0599]: no associated item named `AssocItem` found for type `(u8,)` in the current scope
--> $DIR/bad-assoc-pat.rs:14:10
--> $DIR/bad-assoc-pat.rs:14:17
|
LL | &(u8,)::AssocItem => {}
| ^^^^^^^^^^^^^^^^ associated item not found in `(u8,)`
| -------^^^^^^^^^
| |
| associated item not found in `(u8,)`
error: aborting due to 8 previous errors

View File

@ -1,11 +1,13 @@
error[E0599]: no function or associated item named `new` found for type `T` in the current scope
--> $DIR/dont-suggest-private-trait-method.rs:4:5
--> $DIR/dont-suggest-private-trait-method.rs:4:8
|
LL | struct T;
| --------- function or associated item `new` not found for this
...
LL | T::new();
| ^^^^^^ function or associated item not found in `T`
| ---^^^
| |
| function or associated item not found in `T`
error: aborting due to previous error

View File

@ -47,20 +47,24 @@ LL | let xe1 = XEmpty1(); //~ ERROR expected function, found struct `XEmpty1
| did you mean `XEmpty1 { /* fields */ }`?
error[E0599]: no variant named `Empty3` found for type `empty_struct::XE` in the current scope
--> $DIR/empty-struct-braces-expr.rs:22:15
--> $DIR/empty-struct-braces-expr.rs:22:19
|
LL | let xe3 = XE::Empty3; //~ ERROR no variant named `Empty3` found for type
| ^^^^^^^^^^ variant not found in `empty_struct::XE`
| ----^^^^^^
| |
| variant not found in `empty_struct::XE`
|
= note: did you mean `empty_struct::XE::XEmpty3`?
= help: did you mean `XEmpty3`?
error[E0599]: no variant named `Empty3` found for type `empty_struct::XE` in the current scope
--> $DIR/empty-struct-braces-expr.rs:23:15
--> $DIR/empty-struct-braces-expr.rs:23:19
|
LL | let xe3 = XE::Empty3(); //~ ERROR no variant named `Empty3` found for type
| ^^^^^^^^^^ variant not found in `empty_struct::XE`
| ----^^^^^^
| |
| variant not found in `empty_struct::XE`
|
= note: did you mean `empty_struct::XE::XEmpty3`?
= help: did you mean `XEmpty3`?
error: aborting due to 8 previous errors

View File

@ -0,0 +1,73 @@
#![feature(type_alias_enum_variants)]
enum Enum<T> { TSVariant(T), SVariant { v: T } }
type Alias<T> = Enum<T>;
type AliasFixed = Enum<()>;
impl<T> Enum<T> {
fn ts_variant() {
Self::TSVariant(());
//~^ ERROR mismatched types [E0308]
Self::TSVariant::<()>(());
//~^ ERROR type arguments are not allowed on this entity [E0109]
Self::<()>::TSVariant(());
//~^ ERROR type arguments are not allowed on this entity [E0109]
//~^^ ERROR mismatched types [E0308]
Self::<()>::TSVariant::<()>(());
//~^ ERROR type arguments are not allowed on this entity [E0109]
//~^^ ERROR type arguments are not allowed on this entity [E0109]
}
fn s_variant() {
Self::SVariant { v: () };
//~^ ERROR mismatched types [E0308]
Self::SVariant::<()> { v: () };
//~^ ERROR type arguments are not allowed on this entity [E0109]
//~^^ ERROR mismatched types [E0308]
Self::<()>::SVariant { v: () };
//~^ ERROR type arguments are not allowed on this entity [E0109]
//~^^ ERROR mismatched types [E0308]
Self::<()>::SVariant::<()> { v: () };
//~^ ERROR type arguments are not allowed on this entity [E0109]
//~^^ ERROR type arguments are not allowed on this entity [E0109]
//~^^^ ERROR mismatched types [E0308]
}
}
fn main() {
// Tuple struct variant
Enum::<()>::TSVariant::<()>(());
//~^ ERROR type arguments are not allowed on this entity [E0109]
Alias::TSVariant::<()>(());
//~^ ERROR type arguments are not allowed on this entity [E0109]
Alias::<()>::TSVariant::<()>(());
//~^ ERROR type arguments are not allowed on this entity [E0109]
AliasFixed::TSVariant::<()>(());
//~^ ERROR type arguments are not allowed on this entity [E0109]
AliasFixed::<()>::TSVariant(());
//~^ ERROR wrong number of type arguments: expected 0, found 1 [E0107]
AliasFixed::<()>::TSVariant::<()>(());
//~^ ERROR type arguments are not allowed on this entity [E0109]
//~^^ ERROR wrong number of type arguments: expected 0, found 1 [E0107]
// Struct variant
Enum::<()>::SVariant::<()> { v: () };
//~^ ERROR type arguments are not allowed on this entity [E0109]
Alias::SVariant::<()> { v: () };
//~^ ERROR type arguments are not allowed on this entity [E0109]
Alias::<()>::SVariant::<()> { v: () };
//~^ ERROR type arguments are not allowed on this entity [E0109]
AliasFixed::SVariant::<()> { v: () };
//~^ ERROR type arguments are not allowed on this entity [E0109]
AliasFixed::<()>::SVariant { v: () };
//~^ ERROR wrong number of type arguments: expected 0, found 1 [E0107]
AliasFixed::<()>::SVariant::<()> { v: () };
//~^ ERROR type arguments are not allowed on this entity [E0109]
//~^^ ERROR wrong number of type arguments: expected 0, found 1 [E0107]
}

View File

@ -0,0 +1,190 @@
error[E0308]: mismatched types
--> $DIR/enum-variant-generic-args.rs:9:25
|
LL | Self::TSVariant(());
| ^^ expected type parameter, found ()
|
= note: expected type `T`
found type `()`
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:11:27
|
LL | Self::TSVariant::<()>(());
| ^^ type argument not allowed
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:13:16
|
LL | Self::<()>::TSVariant(());
| ^^ type argument not allowed
error[E0308]: mismatched types
--> $DIR/enum-variant-generic-args.rs:13:31
|
LL | Self::<()>::TSVariant(());
| ^^ expected type parameter, found ()
|
= note: expected type `T`
found type `()`
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:16:16
|
LL | Self::<()>::TSVariant::<()>(());
| ^^ type argument not allowed
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:16:33
|
LL | Self::<()>::TSVariant::<()>(());
| ^^ type argument not allowed
error[E0308]: mismatched types
--> $DIR/enum-variant-generic-args.rs:22:29
|
LL | Self::SVariant { v: () };
| ^^ expected type parameter, found ()
|
= note: expected type `T`
found type `()`
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:24:26
|
LL | Self::SVariant::<()> { v: () };
| ^^ type argument not allowed
error[E0308]: mismatched types
--> $DIR/enum-variant-generic-args.rs:24:35
|
LL | Self::SVariant::<()> { v: () };
| ^^ expected type parameter, found ()
|
= note: expected type `T`
found type `()`
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:27:16
|
LL | Self::<()>::SVariant { v: () };
| ^^ type argument not allowed
error[E0308]: mismatched types
--> $DIR/enum-variant-generic-args.rs:27:35
|
LL | Self::<()>::SVariant { v: () };
| ^^ expected type parameter, found ()
|
= note: expected type `T`
found type `()`
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:30:16
|
LL | Self::<()>::SVariant::<()> { v: () };
| ^^ type argument not allowed
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:30:32
|
LL | Self::<()>::SVariant::<()> { v: () };
| ^^ type argument not allowed
error[E0308]: mismatched types
--> $DIR/enum-variant-generic-args.rs:30:41
|
LL | Self::<()>::SVariant::<()> { v: () };
| ^^ expected type parameter, found ()
|
= note: expected type `T`
found type `()`
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:40:29
|
LL | Enum::<()>::TSVariant::<()>(());
| ^^ type argument not allowed
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:43:24
|
LL | Alias::TSVariant::<()>(());
| ^^ type argument not allowed
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:45:30
|
LL | Alias::<()>::TSVariant::<()>(());
| ^^ type argument not allowed
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:48:29
|
LL | AliasFixed::TSVariant::<()>(());
| ^^ type argument not allowed
error[E0107]: wrong number of type arguments: expected 0, found 1
--> $DIR/enum-variant-generic-args.rs:50:18
|
LL | AliasFixed::<()>::TSVariant(());
| ^^ unexpected type argument
error[E0107]: wrong number of type arguments: expected 0, found 1
--> $DIR/enum-variant-generic-args.rs:52:18
|
LL | AliasFixed::<()>::TSVariant::<()>(());
| ^^ unexpected type argument
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:52:35
|
LL | AliasFixed::<()>::TSVariant::<()>(());
| ^^ type argument not allowed
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:58:28
|
LL | Enum::<()>::SVariant::<()> { v: () };
| ^^ type argument not allowed
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:61:23
|
LL | Alias::SVariant::<()> { v: () };
| ^^ type argument not allowed
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:63:29
|
LL | Alias::<()>::SVariant::<()> { v: () };
| ^^ type argument not allowed
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:66:28
|
LL | AliasFixed::SVariant::<()> { v: () };
| ^^ type argument not allowed
error[E0107]: wrong number of type arguments: expected 0, found 1
--> $DIR/enum-variant-generic-args.rs:68:18
|
LL | AliasFixed::<()>::SVariant { v: () };
| ^^ unexpected type argument
error[E0107]: wrong number of type arguments: expected 0, found 1
--> $DIR/enum-variant-generic-args.rs:70:18
|
LL | AliasFixed::<()>::SVariant::<()> { v: () };
| ^^ unexpected type argument
error[E0109]: type arguments are not allowed on this entity
--> $DIR/enum-variant-generic-args.rs:70:34
|
LL | AliasFixed::<()>::SVariant::<()> { v: () };
| ^^ type argument not allowed
error: aborting due to 28 previous errors
Some errors occurred: E0107, E0109, E0308.
For more information about an error, try `rustc --explain E0107`.

View File

@ -1,8 +1,8 @@
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/E0109.rs:1:14
|
LL | type X = u32<i32>; //~ ERROR E0109
| ^^^ type parameter not allowed
| ^^^ type argument not allowed
error: aborting due to previous error

View File

@ -1,4 +1,3 @@
type X = u32<'static>; //~ ERROR E0110
fn main() {
}
fn main() {}

View File

@ -1,8 +1,8 @@
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/E0110.rs:1:14
|
LL | type X = u32<'static>; //~ ERROR E0110
| ^^^^^^^ lifetime parameter not allowed
| ^^^^^^^ lifetime argument not allowed
error: aborting due to previous error

View File

@ -1,11 +1,11 @@
error[E0599]: no associated item named `NotEvenReal` found for type `Foo` in the current scope
--> $DIR/E0599.rs:4:15
--> $DIR/E0599.rs:4:20
|
LL | struct Foo;
| ----------- associated item `NotEvenReal` not found for this
...
LL | || if let Foo::NotEvenReal() = Foo {}; //~ ERROR E0599
| ^^^^^^^^^^^^^^^^^^ associated item not found in `Foo`
| -----^^^^^^^^^^^-- associated item not found in `Foo`
error: aborting due to previous error

View File

@ -0,0 +1,29 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
enum Foo {
Bar(i32),
Baz { i: i32 },
}
type Alias = Foo;
fn main() {
let t = Alias::Bar(0);
//~^ ERROR enum variants on type aliases are experimental
let t = Alias::Baz { i: 0 };
//~^ ERROR enum variants on type aliases are experimental
match t {
Alias::Bar(_i) => {}
//~^ ERROR enum variants on type aliases are experimental
Alias::Baz { i: _i } => {}
//~^ ERROR enum variants on type aliases are experimental
}
}

View File

@ -0,0 +1,34 @@
error: enum variants on type aliases are experimental
--> $DIR/feature-gate-type_alias_enum_variants.rs:19:13
|
LL | let t = Alias::Bar(0);
| ^^^^^^^^^^
|
= help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable
error: enum variants on type aliases are experimental
--> $DIR/feature-gate-type_alias_enum_variants.rs:21:13
|
LL | let t = Alias::Baz { i: 0 };
| ^^^^^^^^^^
|
= help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable
error: enum variants on type aliases are experimental
--> $DIR/feature-gate-type_alias_enum_variants.rs:24:9
|
LL | Alias::Bar(_i) => {}
| ^^^^^^^^^^^^^^
|
= help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable
error: enum variants on type aliases are experimental
--> $DIR/feature-gate-type_alias_enum_variants.rs:26:9
|
LL | Alias::Baz { i: _i } => {}
| ^^^^^^^^^^
|
= help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable
error: aborting due to 4 previous errors

View File

@ -1,8 +1,10 @@
error[E0599]: no associated item named `DOESNOTEXIST` found for type `u32` in the current scope
--> $DIR/invalid-path-in-const.rs:2:18
--> $DIR/invalid-path-in-const.rs:2:23
|
LL | fn f(a: [u8; u32::DOESNOTEXIST]) {}
| ^^^^^^^^^^^^^^^^^ associated item not found in `u32`
| -----^^^^^^^^^^^^
| |
| associated item not found in `u32`
error: aborting due to previous error

View File

@ -1,3 +1,3 @@
fn is_copy<T: ::std::marker<i32>::Copy>() {}
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]
fn main() {}

View File

@ -1,8 +1,8 @@
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/issue-22706.rs:1:29
|
LL | fn is_copy<T: ::std::marker<i32>::Copy>() {}
| ^^^ type parameter not allowed
| ^^^ type argument not allowed
error: aborting due to previous error

View File

@ -1,11 +1,13 @@
error[E0599]: no variant named `PIE` found for type `Delicious` in the current scope
--> $DIR/issue-22933-2.rs:4:44
--> $DIR/issue-22933-2.rs:4:55
|
LL | enum Delicious {
| -------------- variant `PIE` not found here
...
LL | ApplePie = Delicious::Apple as isize | Delicious::PIE as isize,
| ^^^^^^^^^^^^^^ variant not found in `Delicious`
| -----------^^^
| |
| variant not found in `Delicious`
error: aborting due to previous error

View File

@ -1,8 +1,10 @@
error[E0599]: no associated item named `MIN` found for type `u8` in the current scope
--> $DIR/issue-22933-3.rs:1:18
--> $DIR/issue-22933-3.rs:1:22
|
LL | const FOO: [u32; u8::MIN as usize] = [];
| ^^^^^^^ associated item not found in `u8`
| ----^^^
| |
| associated item not found in `u8`
error: aborting due to previous error

View File

@ -1,38 +1,46 @@
error[E0599]: no variant named `Homura` found for type `Token` in the current scope
--> $DIR/issue-23173.rs:9:16
--> $DIR/issue-23173.rs:9:23
|
LL | enum Token { LeftParen, RightParen, Plus, Minus, /* etc */ }
| ---------- variant `Homura` not found here
...
LL | use_token(&Token::Homura);
| ^^^^^^^^^^^^^ variant not found in `Token`
| -------^^^^^^
| |
| variant not found in `Token`
error[E0599]: no function or associated item named `method` found for type `Struct` in the current scope
--> $DIR/issue-23173.rs:11:5
--> $DIR/issue-23173.rs:11:13
|
LL | struct Struct {
| ------------- function or associated item `method` not found for this
...
LL | Struct::method();
| ^^^^^^^^^^^^^^ function or associated item not found in `Struct`
| --------^^^^^^
| |
| function or associated item not found in `Struct`
error[E0599]: no function or associated item named `method` found for type `Struct` in the current scope
--> $DIR/issue-23173.rs:13:5
--> $DIR/issue-23173.rs:13:13
|
LL | struct Struct {
| ------------- function or associated item `method` not found for this
...
LL | Struct::method;
| ^^^^^^^^^^^^^^ function or associated item not found in `Struct`
| --------^^^^^^
| |
| function or associated item not found in `Struct`
error[E0599]: no associated item named `Assoc` found for type `Struct` in the current scope
--> $DIR/issue-23173.rs:15:5
--> $DIR/issue-23173.rs:15:13
|
LL | struct Struct {
| ------------- associated item `Assoc` not found for this
...
LL | Struct::Assoc;
| ^^^^^^^^^^^^^ associated item not found in `Struct`
| --------^^^^^
| |
| associated item not found in `Struct`
error: aborting due to 4 previous errors

View File

@ -1,12 +1,14 @@
error[E0599]: no variant named `A` found for type `SomeEnum` in the current scope
--> $DIR/issue-23217.rs:2:9
--> $DIR/issue-23217.rs:2:19
|
LL | pub enum SomeEnum {
| ----------------- variant `A` not found here
LL | B = SomeEnum::A,
| ^^^^^^^^^^^ variant not found in `SomeEnum`
| ----------^
| |
| variant not found in `SomeEnum`
|
= note: did you mean `SomeEnum::B`?
= help: did you mean `B`?
error: aborting due to previous error

View File

@ -5,10 +5,12 @@ LL | let x: u8 = BitXor::bitor(0 as u8, 0 as u8);
| ^^^^^^^^^^^^^ associated type `Output` must be specified
error[E0599]: no function or associated item named `bitor` found for type `dyn std::ops::BitXor<_>` in the current scope
--> $DIR/issue-28344.rs:4:17
--> $DIR/issue-28344.rs:4:25
|
LL | let x: u8 = BitXor::bitor(0 as u8, 0 as u8);
| ^^^^^^^^^^^^^ function or associated item not found in `dyn std::ops::BitXor<_>`
| --------^^^^^
| |
| function or associated item not found in `dyn std::ops::BitXor<_>`
|
= help: did you mean `bitxor`?
@ -19,10 +21,12 @@ LL | let g = BitXor::bitor;
| ^^^^^^^^^^^^^ associated type `Output` must be specified
error[E0599]: no function or associated item named `bitor` found for type `dyn std::ops::BitXor<_>` in the current scope
--> $DIR/issue-28344.rs:8:13
--> $DIR/issue-28344.rs:8:21
|
LL | let g = BitXor::bitor;
| ^^^^^^^^^^^^^ function or associated item not found in `dyn std::ops::BitXor<_>`
| --------^^^^^
| |
| function or associated item not found in `dyn std::ops::BitXor<_>`
|
= help: did you mean `bitxor`?

View File

@ -1,8 +1,10 @@
error[E0599]: no associated item named `BYTES` found for type `usize` in the current scope
--> $DIR/issue-28586.rs:4:19
--> $DIR/issue-28586.rs:4:26
|
LL | impl Foo for [u8; usize::BYTES] {}
| ^^^^^^^^^^^^ associated item not found in `usize`
| -------^^^^^
| |
| associated item not found in `usize`
error: aborting due to previous error

View File

@ -1,13 +1,13 @@
error[E0599]: no variant named `Baz` found for type `Foo` in the current scope
--> $DIR/issue-28971.rs:9:13
--> $DIR/issue-28971.rs:9:18
|
LL | enum Foo {
| -------- variant `Baz` not found here
...
LL | Foo::Baz(..) => (),
| ^^^^^^^^^^^^ variant not found in `Foo`
| -----^^^---- variant not found in `Foo`
|
= note: did you mean `Foo::Bar`?
= help: did you mean `Bar`?
error: aborting due to previous error

View File

@ -1,8 +1,10 @@
error[E0599]: no function or associated item named `new_undirected` found for type `issue_30123_aux::Graph<i32, i32>` in the current scope
--> $DIR/issue-30123.rs:7:14
--> $DIR/issue-30123.rs:7:33
|
LL | let ug = Graph::<i32, i32>::new_undirected();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `issue_30123_aux::Graph<i32, i32>`
| -------------------^^^^^^^^^^^^^^
| |
| function or associated item not found in `issue_30123_aux::Graph<i32, i32>`
error: aborting due to previous error

View File

@ -1,8 +1,10 @@
error[E0599]: no associated item named `Item` found for type `T` in the current scope
--> $DIR/issue-38919.rs:2:5
--> $DIR/issue-38919.rs:2:8
|
LL | T::Item; //~ ERROR no associated item named `Item` found for type `T` in the current scope
| ^^^^^^^ associated item not found in `T`
| ---^^^^
| |
| associated item not found in `T`
error: aborting due to previous error

View File

@ -1,8 +1,10 @@
error[E0599]: no function or associated item named `dim` found for type `D` in the current scope
--> $DIR/issue-39559.rs:14:18
--> $DIR/issue-39559.rs:14:21
|
LL | entries: [T; D::dim()],
| ^^^^^^ function or associated item not found in `D`
| ---^^^
| |
| function or associated item not found in `D`
|
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `dim`, perhaps you need to implement it:

View File

@ -8,13 +8,15 @@ LL | | }
| |_____^ not a member of trait `ToString_`
error[E0599]: no function or associated item named `new` found for type `Point` in the current scope
--> $DIR/issue-3973.rs:22:13
--> $DIR/issue-3973.rs:22:20
|
LL | struct Point {
| ------------ function or associated item `new` not found for this
...
LL | let p = Point::new(0.0, 0.0);
| ^^^^^^^^^^ function or associated item not found in `Point`
| -------^^^
| |
| function or associated item not found in `Point`
error: aborting due to 2 previous errors

View File

@ -1,8 +1,8 @@
error[E0599]: no associated item named `String` found for type `std::string::String` in the current scope
--> $DIR/issue-42880.rs:4:15
--> $DIR/issue-42880.rs:4:22
|
LL | let f = |&Value::String(_)| (); //~ ERROR no associated item named
| ^^^^^^^^^^^^^^^^ associated item not found in `std::string::String`
| -------^^^^^^--- associated item not found in `std::string::String`
error: aborting due to previous error

View File

@ -1,11 +1,13 @@
error[E0599]: no function or associated item named `bar` found for type `Foo` in the current scope
--> $DIR/issue-7950.rs:6:5
--> $DIR/issue-7950.rs:6:10
|
LL | struct Foo;
| ----------- function or associated item `bar` not found for this
...
LL | Foo::bar();
| ^^^^^^^^ function or associated item not found in `Foo`
| -----^^^
| |
| function or associated item not found in `Foo`
error: aborting due to previous error

View File

@ -9,10 +9,12 @@ LL | use T;
|
error[E0599]: no function or associated item named `f` found for type `Foo` in the current scope
--> $DIR/lexical-scopes.rs:10:5
--> $DIR/lexical-scopes.rs:10:10
|
LL | Foo::f(); //~ ERROR no function or associated item named `f`
| ^^^^^^ function or associated item not found in `Foo`
| -----^
| |
| function or associated item not found in `Foo`
error: aborting due to 2 previous errors

View File

@ -0,0 +1,10 @@
mod Mod {
pub struct FakeVariant<T>(pub T);
}
fn main() {
Mod::FakeVariant::<i32>(0);
Mod::<i32>::FakeVariant(0);
//~^ ERROR type arguments are not allowed on this entity [E0109]
}

View File

@ -0,0 +1,9 @@
error[E0109]: type arguments are not allowed on this entity
--> $DIR/mod-subitem-as-enum-variant.rs:8:11
|
LL | Mod::<i32>::FakeVariant(0);
| ^^^ type argument not allowed
error: aborting due to previous error
For more information about this error, try `rustc --explain E0109`.

View File

@ -1,27 +1,27 @@
fn main() {
let x: isize<isize>; //~ ERROR type parameters are not allowed on this type
let x: i8<isize>; //~ ERROR type parameters are not allowed on this type
let x: i16<isize>; //~ ERROR type parameters are not allowed on this type
let x: i32<isize>; //~ ERROR type parameters are not allowed on this type
let x: i64<isize>; //~ ERROR type parameters are not allowed on this type
let x: usize<isize>; //~ ERROR type parameters are not allowed on this type
let x: u8<isize>; //~ ERROR type parameters are not allowed on this type
let x: u16<isize>; //~ ERROR type parameters are not allowed on this type
let x: u32<isize>; //~ ERROR type parameters are not allowed on this type
let x: u64<isize>; //~ ERROR type parameters are not allowed on this type
let x: char<isize>; //~ ERROR type parameters are not allowed on this type
let x: isize<isize>; //~ ERROR type arguments are not allowed on this entity
let x: i8<isize>; //~ ERROR type arguments are not allowed on this entity
let x: i16<isize>; //~ ERROR type arguments are not allowed on this entity
let x: i32<isize>; //~ ERROR type arguments are not allowed on this entity
let x: i64<isize>; //~ ERROR type arguments are not allowed on this entity
let x: usize<isize>; //~ ERROR type arguments are not allowed on this entity
let x: u8<isize>; //~ ERROR type arguments are not allowed on this entity
let x: u16<isize>; //~ ERROR type arguments are not allowed on this entity
let x: u32<isize>; //~ ERROR type arguments are not allowed on this entity
let x: u64<isize>; //~ ERROR type arguments are not allowed on this entity
let x: char<isize>; //~ ERROR type arguments are not allowed on this entity
let x: isize<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: i8<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: i16<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: i32<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: i64<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: usize<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: u8<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: u16<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: u32<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: u64<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: char<'static>; //~ ERROR lifetime parameters are not allowed on this type
let x: isize<'static>; //~ ERROR lifetime arguments are not allowed on this entity
let x: i8<'static>; //~ ERROR lifetime arguments are not allowed on this entity
let x: i16<'static>; //~ ERROR lifetime arguments are not allowed on this entity
let x: i32<'static>; //~ ERROR lifetime arguments are not allowed on this entity
let x: i64<'static>; //~ ERROR lifetime arguments are not allowed on this entity
let x: usize<'static>; //~ ERROR lifetime arguments are not allowed on this entity
let x: u8<'static>; //~ ERROR lifetime arguments are not allowed on this entity
let x: u16<'static>; //~ ERROR lifetime arguments are not allowed on this entity
let x: u32<'static>; //~ ERROR lifetime arguments are not allowed on this entity
let x: u64<'static>; //~ ERROR lifetime arguments are not allowed on this entity
let x: char<'static>; //~ ERROR lifetime arguments are not allowed on this entity
}

View File

@ -1,134 +1,134 @@
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:3:14
|
LL | let x: isize<isize>; //~ ERROR type parameters are not allowed on this type
| ^^^^^ type parameter not allowed
LL | let x: isize<isize>; //~ ERROR type arguments are not allowed on this entity
| ^^^^^ type argument not allowed
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:4:11
|
LL | let x: i8<isize>; //~ ERROR type parameters are not allowed on this type
| ^^^^^ type parameter not allowed
LL | let x: i8<isize>; //~ ERROR type arguments are not allowed on this entity
| ^^^^^ type argument not allowed
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:5:12
|
LL | let x: i16<isize>; //~ ERROR type parameters are not allowed on this type
| ^^^^^ type parameter not allowed
LL | let x: i16<isize>; //~ ERROR type arguments are not allowed on this entity
| ^^^^^ type argument not allowed
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:6:12
|
LL | let x: i32<isize>; //~ ERROR type parameters are not allowed on this type
| ^^^^^ type parameter not allowed
LL | let x: i32<isize>; //~ ERROR type arguments are not allowed on this entity
| ^^^^^ type argument not allowed
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:7:12
|
LL | let x: i64<isize>; //~ ERROR type parameters are not allowed on this type
| ^^^^^ type parameter not allowed
LL | let x: i64<isize>; //~ ERROR type arguments are not allowed on this entity
| ^^^^^ type argument not allowed
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:8:14
|
LL | let x: usize<isize>; //~ ERROR type parameters are not allowed on this type
| ^^^^^ type parameter not allowed
LL | let x: usize<isize>; //~ ERROR type arguments are not allowed on this entity
| ^^^^^ type argument not allowed
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:9:11
|
LL | let x: u8<isize>; //~ ERROR type parameters are not allowed on this type
| ^^^^^ type parameter not allowed
LL | let x: u8<isize>; //~ ERROR type arguments are not allowed on this entity
| ^^^^^ type argument not allowed
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:10:12
|
LL | let x: u16<isize>; //~ ERROR type parameters are not allowed on this type
| ^^^^^ type parameter not allowed
LL | let x: u16<isize>; //~ ERROR type arguments are not allowed on this entity
| ^^^^^ type argument not allowed
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:11:12
|
LL | let x: u32<isize>; //~ ERROR type parameters are not allowed on this type
| ^^^^^ type parameter not allowed
LL | let x: u32<isize>; //~ ERROR type arguments are not allowed on this entity
| ^^^^^ type argument not allowed
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:12:12
|
LL | let x: u64<isize>; //~ ERROR type parameters are not allowed on this type
| ^^^^^ type parameter not allowed
LL | let x: u64<isize>; //~ ERROR type arguments are not allowed on this entity
| ^^^^^ type argument not allowed
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:13:13
|
LL | let x: char<isize>; //~ ERROR type parameters are not allowed on this type
| ^^^^^ type parameter not allowed
LL | let x: char<isize>; //~ ERROR type arguments are not allowed on this entity
| ^^^^^ type argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:15:14
|
LL | let x: isize<'static>; //~ ERROR lifetime parameters are not allowed on this type
| ^^^^^^^ lifetime parameter not allowed
LL | let x: isize<'static>; //~ ERROR lifetime arguments are not allowed on this entity
| ^^^^^^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:16:11
|
LL | let x: i8<'static>; //~ ERROR lifetime parameters are not allowed on this type
| ^^^^^^^ lifetime parameter not allowed
LL | let x: i8<'static>; //~ ERROR lifetime arguments are not allowed on this entity
| ^^^^^^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:17:12
|
LL | let x: i16<'static>; //~ ERROR lifetime parameters are not allowed on this type
| ^^^^^^^ lifetime parameter not allowed
LL | let x: i16<'static>; //~ ERROR lifetime arguments are not allowed on this entity
| ^^^^^^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:18:12
|
LL | let x: i32<'static>; //~ ERROR lifetime parameters are not allowed on this type
| ^^^^^^^ lifetime parameter not allowed
LL | let x: i32<'static>; //~ ERROR lifetime arguments are not allowed on this entity
| ^^^^^^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:19:12
|
LL | let x: i64<'static>; //~ ERROR lifetime parameters are not allowed on this type
| ^^^^^^^ lifetime parameter not allowed
LL | let x: i64<'static>; //~ ERROR lifetime arguments are not allowed on this entity
| ^^^^^^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:20:14
|
LL | let x: usize<'static>; //~ ERROR lifetime parameters are not allowed on this type
| ^^^^^^^ lifetime parameter not allowed
LL | let x: usize<'static>; //~ ERROR lifetime arguments are not allowed on this entity
| ^^^^^^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:21:11
|
LL | let x: u8<'static>; //~ ERROR lifetime parameters are not allowed on this type
| ^^^^^^^ lifetime parameter not allowed
LL | let x: u8<'static>; //~ ERROR lifetime arguments are not allowed on this entity
| ^^^^^^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:22:12
|
LL | let x: u16<'static>; //~ ERROR lifetime parameters are not allowed on this type
| ^^^^^^^ lifetime parameter not allowed
LL | let x: u16<'static>; //~ ERROR lifetime arguments are not allowed on this entity
| ^^^^^^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:23:12
|
LL | let x: u32<'static>; //~ ERROR lifetime parameters are not allowed on this type
| ^^^^^^^ lifetime parameter not allowed
LL | let x: u32<'static>; //~ ERROR lifetime arguments are not allowed on this entity
| ^^^^^^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:24:12
|
LL | let x: u64<'static>; //~ ERROR lifetime parameters are not allowed on this type
| ^^^^^^^ lifetime parameter not allowed
LL | let x: u64<'static>; //~ ERROR lifetime arguments are not allowed on this entity
| ^^^^^^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/prim-with-args.rs:25:13
|
LL | let x: char<'static>; //~ ERROR lifetime parameters are not allowed on this type
| ^^^^^^^ lifetime parameter not allowed
LL | let x: char<'static>; //~ ERROR lifetime arguments are not allowed on this entity
| ^^^^^^^ lifetime argument not allowed
error: aborting due to 22 previous errors

View File

@ -16,7 +16,7 @@ impl S {
}
type A = <S as Tr>::A::f<u8>;
//~^ ERROR type parameters are not allowed on this type
//~^ ERROR type arguments are not allowed on this entity
//~| ERROR ambiguous associated type
fn main() {}

View File

@ -1,8 +1,8 @@
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/qualified-path-params-2.rs:18:26
|
LL | type A = <S as Tr>::A::f<u8>;
| ^^ type parameter not allowed
| ^^ type argument not allowed
error[E0223]: ambiguous associated type
--> $DIR/qualified-path-params-2.rs:18:10

View File

@ -1,8 +1,10 @@
error[E0599]: no associated item named `XXX` found for type `u32` in the current scope
--> $DIR/no-double-error.rs:8:9
--> $DIR/no-double-error.rs:8:14
|
LL | u32::XXX => { } //~ ERROR no associated item named
| ^^^^^^^^ associated item not found in `u32`
| -----^^^
| |
| associated item not found in `u32`
error: aborting due to previous error

View File

@ -2,7 +2,7 @@
//~^ WARNING the feature `generic_associated_types` is incomplete
#![feature(associated_type_defaults)]
// FIXME(#44265): "lifetime parameters are not allowed on this type" errors will be addressed in a
// FIXME(#44265): "lifetime arguments are not allowed on this entity" errors will be addressed in a
// follow-up PR.
// A Collection trait and collection families. Based on
@ -15,14 +15,14 @@ trait Collection<T> {
// Test associated type defaults with parameters
type Sibling<U>: Collection<U> =
<<Self as Collection<T>>::Family as CollectionFamily>::Member<U>;
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]
fn empty() -> Self;
fn add(&mut self, value: T);
fn iterate<'iter>(&'iter self) -> Self::Iter<'iter>;
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
//~^ ERROR lifetime arguments are not allowed on this entity [E0110]
}
trait CollectionFamily {
@ -48,13 +48,13 @@ impl<T> Collection<T> for Vec<T> {
}
fn iterate<'iter>(&'iter self) -> Self::Iter<'iter> {
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
//~^ ERROR lifetime arguments are not allowed on this entity [E0110]
self.iter()
}
}
fn floatify<C>(ints: &C) -> <<C as Collection<i32>>::Family as CollectionFamily>::Member<f32>
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]
where
C: Collection<i32>,
{
@ -66,7 +66,7 @@ where
}
fn floatify_sibling<C>(ints: &C) -> <C as Collection<i32>>::Sibling<f32>
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]
where
C: Collection<i32>,
{

View File

@ -4,35 +4,35 @@ warning: the feature `generic_associated_types` is incomplete and may cause the
LL | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/collections.rs:56:90
|
LL | fn floatify<C>(ints: &C) -> <<C as Collection<i32>>::Family as CollectionFamily>::Member<f32>
| ^^^ type parameter not allowed
| ^^^ type argument not allowed
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/collections.rs:68:69
|
LL | fn floatify_sibling<C>(ints: &C) -> <C as Collection<i32>>::Sibling<f32>
| ^^^ type parameter not allowed
| ^^^ type argument not allowed
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/collections.rs:17:71
|
LL | <<Self as Collection<T>>::Family as CollectionFamily>::Member<U>;
| ^ type parameter not allowed
| ^ type argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/collections.rs:24:50
|
LL | fn iterate<'iter>(&'iter self) -> Self::Iter<'iter>;
| ^^^^^ lifetime parameter not allowed
| ^^^^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/collections.rs:50:50
|
LL | fn iterate<'iter>(&'iter self) -> Self::Iter<'iter> {
| ^^^^^ lifetime parameter not allowed
| ^^^^^ lifetime argument not allowed
error: aborting due to 5 previous errors

View File

@ -3,7 +3,7 @@
use std::ops::Deref;
// FIXME(#44265): "lifetime parameters are not allowed on this type" errors will be addressed in a
// FIXME(#44265): "lifetime arguments are not allowed on this entity" errors will be addressed in a
// follow-up PR.
trait Foo {
@ -15,15 +15,15 @@ trait Baz {
// This weird type tests that we can use universal function call syntax to access the Item on
type Baa<'a>: Deref<Target = <Self::Quux<'a> as Foo>::Bar<'a, 'static>>;
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
//~| ERROR lifetime parameters are not allowed on this type [E0110]
//~^ ERROR lifetime arguments are not allowed on this entity [E0110]
//~| ERROR lifetime arguments are not allowed on this entity [E0110]
}
impl<T> Baz for T where T: Foo {
type Quux<'a> = T;
type Baa<'a> = &'a <T as Foo>::Bar<'a, 'static>;
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
//~^ ERROR lifetime arguments are not allowed on this entity [E0110]
}
fn main() {}

View File

@ -4,23 +4,23 @@ warning: the feature `generic_associated_types` is incomplete and may cause the
LL | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/construct_with_other_type.rs:17:46
|
LL | type Baa<'a>: Deref<Target = <Self::Quux<'a> as Foo>::Bar<'a, 'static>>;
| ^^ lifetime parameter not allowed
| ^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/construct_with_other_type.rs:17:63
|
LL | type Baa<'a>: Deref<Target = <Self::Quux<'a> as Foo>::Bar<'a, 'static>>;
| ^^ lifetime parameter not allowed
| ^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/construct_with_other_type.rs:25:40
|
LL | type Baa<'a> = &'a <T as Foo>::Bar<'a, 'static>;
| ^^ lifetime parameter not allowed
| ^^ lifetime argument not allowed
error: aborting due to 3 previous errors

View File

@ -3,20 +3,20 @@
use std::ops::Deref;
// FIXME(#44265): "lifetime parameters are not allowed on this type" errors will be addressed in a
// FIXME(#44265): "lifetime arguments are not allowed on this entity" errors will be addressed in a
// follow-up PR.
trait Iterable {
type Item<'a>;
type Iter<'a>: Iterator<Item = Self::Item<'a>>
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
//~^ ERROR lifetime arguments are not allowed on this entity [E0110]
+ Deref<Target = Self::Item<'b>>;
//~^ ERROR undeclared lifetime
//~| ERROR lifetime parameters are not allowed on this type [E0110]
//~| ERROR lifetime arguments are not allowed on this entity [E0110]
fn iter<'a>(&'a self) -> Self::Iter<'undeclared>;
//~^ ERROR undeclared lifetime
//~| ERROR lifetime parameters are not allowed on this type [E0110]
//~| ERROR lifetime arguments are not allowed on this entity [E0110]
}
fn main() {}

View File

@ -16,23 +16,23 @@ error[E0261]: use of undeclared lifetime name `'undeclared`
LL | fn iter<'a>(&'a self) -> Self::Iter<'undeclared>;
| ^^^^^^^^^^^ undeclared lifetime
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:11:47
|
LL | type Iter<'a>: Iterator<Item = Self::Item<'a>>
| ^^ lifetime parameter not allowed
| ^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:13:37
|
LL | + Deref<Target = Self::Item<'b>>;
| ^^ lifetime parameter not allowed
| ^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:17:41
|
LL | fn iter<'a>(&'a self) -> Self::Iter<'undeclared>;
| ^^^^^^^^^^^ lifetime parameter not allowed
| ^^^^^^^^^^^ lifetime argument not allowed
error: aborting due to 5 previous errors

View File

@ -3,16 +3,16 @@
use std::ops::Deref;
// FIXME(#44265): "lifetime parameters are not allowed on this type" errors will be addressed in a
// FIXME(#44265): "lifetime arguments are not allowed on this entity" errors will be addressed in a
// follow-up PR.
trait Iterable {
type Item<'a>;
type Iter<'a>: Iterator<Item = Self::Item<'a>>;
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
//~^ ERROR lifetime arguments are not allowed on this entity [E0110]
fn iter<'a>(&'a self) -> Self::Iter<'a>;
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
//~^ ERROR lifetime arguments are not allowed on this entity [E0110]
}
// Impl for struct type
@ -21,7 +21,7 @@ impl<T> Iterable for Vec<T> {
type Iter<'a> = std::slice::Iter<'a, T>;
fn iter<'a>(&'a self) -> Self::Iter<'a> {
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
//~^ ERROR lifetime arguments are not allowed on this entity [E0110]
self.iter()
}
}
@ -32,18 +32,18 @@ impl<T> Iterable for [T] {
type Iter<'a> = std::slice::Iter<'a, T>;
fn iter<'a>(&'a self) -> Self::Iter<'a> {
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
//~^ ERROR lifetime arguments are not allowed on this entity [E0110]
self.iter()
}
}
fn make_iter<'a, I: Iterable>(it: &'a I) -> I::Iter<'a> {
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
//~^ ERROR lifetime arguments are not allowed on this entity [E0110]
it.iter()
}
fn get_first<'a, I: Iterable>(it: &'a I) -> Option<I::Item<'a>> {
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
//~^ ERROR lifetime arguments are not allowed on this entity [E0110]
it.iter().next()
}

View File

@ -4,41 +4,41 @@ warning: the feature `generic_associated_types` is incomplete and may cause the
LL | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/iterable.rs:11:47
|
LL | type Iter<'a>: Iterator<Item = Self::Item<'a>>;
| ^^ lifetime parameter not allowed
| ^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/iterable.rs:40:53
|
LL | fn make_iter<'a, I: Iterable>(it: &'a I) -> I::Iter<'a> {
| ^^ lifetime parameter not allowed
| ^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/iterable.rs:45:60
|
LL | fn get_first<'a, I: Iterable>(it: &'a I) -> Option<I::Item<'a>> {
| ^^ lifetime parameter not allowed
| ^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/iterable.rs:14:41
|
LL | fn iter<'a>(&'a self) -> Self::Iter<'a>;
| ^^ lifetime parameter not allowed
| ^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/iterable.rs:23:41
|
LL | fn iter<'a>(&'a self) -> Self::Iter<'a> {
| ^^ lifetime parameter not allowed
| ^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/iterable.rs:34:41
|
LL | fn iter<'a>(&'a self) -> Self::Iter<'a> {
| ^^ lifetime parameter not allowed
| ^^ lifetime argument not allowed
error: aborting due to 6 previous errors

View File

@ -2,7 +2,7 @@
//~^ WARNING the feature `generic_associated_types` is incomplete
#![feature(associated_type_defaults)]
// FIXME(#44265): "lifetime parameters are not allowed on this type" errors will be addressed in a
// FIXME(#44265): "lifetime arguments are not allowed on this entity" errors will be addressed in a
// follow-up PR.
// FIXME(#44265): Update expected errors once E110 is resolved, now does not get past `trait Foo`.
@ -15,13 +15,13 @@ trait Foo {
type E<'a, T>;
// Test parameters in default values
type FOk<T> = Self::E<'static, T>;
//~^ ERROR type parameters are not allowed on this type [E0109]
//~| ERROR lifetime parameters are not allowed on this type [E0110]
//~^ ERROR type arguments are not allowed on this entity [E0109]
//~| ERROR lifetime arguments are not allowed on this entity [E0110]
type FErr1 = Self::E<'static, 'static>; // Error
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
//~^ ERROR lifetime arguments are not allowed on this entity [E0110]
type FErr2<T> = Self::E<'static, T, u32>; // Error
//~^ ERROR type parameters are not allowed on this type [E0109]
//~| ERROR lifetime parameters are not allowed on this type [E0110]
//~^ ERROR type arguments are not allowed on this entity [E0109]
//~| ERROR lifetime arguments are not allowed on this entity [E0110]
}
struct Fooy;

View File

@ -4,35 +4,35 @@ warning: the feature `generic_associated_types` is incomplete and may cause the
LL | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/parameter_number_and_kind.rs:17:27
|
LL | type FOk<T> = Self::E<'static, T>;
| ^^^^^^^ lifetime parameter not allowed
| ^^^^^^^ lifetime argument not allowed
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/parameter_number_and_kind.rs:17:36
|
LL | type FOk<T> = Self::E<'static, T>;
| ^ type parameter not allowed
| ^ type argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/parameter_number_and_kind.rs:20:26
|
LL | type FErr1 = Self::E<'static, 'static>; // Error
| ^^^^^^^ lifetime parameter not allowed
| ^^^^^^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/parameter_number_and_kind.rs:22:29
|
LL | type FErr2<T> = Self::E<'static, T, u32>; // Error
| ^^^^^^^ lifetime parameter not allowed
| ^^^^^^^ lifetime argument not allowed
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/parameter_number_and_kind.rs:22:38
|
LL | type FErr2<T> = Self::E<'static, T, u32>; // Error
| ^ type parameter not allowed
| ^ type argument not allowed
error: aborting due to 5 previous errors

View File

@ -1,7 +1,7 @@
#![feature(generic_associated_types)]
//~^ WARNING the feature `generic_associated_types` is incomplete
// FIXME(#44265): "type parameter not allowed" errors will be addressed in a follow-up PR.
// FIXME(#44265): "type argument not allowed" errors will be addressed in a follow-up PR.
use std::rc::Rc;
use std::sync::Arc;
@ -10,7 +10,7 @@ use std::ops::Deref;
trait PointerFamily {
type Pointer<T>: Deref<Target = T>;
fn new<T>(value: T) -> Self::Pointer<T>;
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]
}
struct ArcFamily;
@ -18,7 +18,7 @@ struct ArcFamily;
impl PointerFamily for ArcFamily {
type Pointer<T> = Arc<T>;
fn new<T>(value: T) -> Self::Pointer<T> {
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]
Arc::new(value)
}
}
@ -28,14 +28,14 @@ struct RcFamily;
impl PointerFamily for RcFamily {
type Pointer<T> = Rc<T>;
fn new<T>(value: T) -> Self::Pointer<T> {
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]
Rc::new(value)
}
}
struct Foo<P: PointerFamily> {
bar: P::Pointer<String>,
//~^ ERROR type parameters are not allowed on this type [E0109]
//~^ ERROR type arguments are not allowed on this entity [E0109]
}
fn main() {}

View File

@ -4,29 +4,29 @@ warning: the feature `generic_associated_types` is incomplete and may cause the
LL | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/pointer_family.rs:37:21
|
LL | bar: P::Pointer<String>,
| ^^^^^^ type parameter not allowed
| ^^^^^^ type argument not allowed
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/pointer_family.rs:12:42
|
LL | fn new<T>(value: T) -> Self::Pointer<T>;
| ^ type parameter not allowed
| ^ type argument not allowed
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/pointer_family.rs:20:42
|
LL | fn new<T>(value: T) -> Self::Pointer<T> {
| ^ type parameter not allowed
| ^ type argument not allowed
error[E0109]: type parameters are not allowed on this type
error[E0109]: type arguments are not allowed on this entity
--> $DIR/pointer_family.rs:30:42
|
LL | fn new<T>(value: T) -> Self::Pointer<T> {
| ^ type parameter not allowed
| ^ type argument not allowed
error: aborting due to 4 previous errors

View File

@ -1,7 +1,7 @@
#![feature(generic_associated_types)]
//~^ WARNING the feature `generic_associated_types` is incomplete
// FIXME(#44265): "lifetime parameter not allowed on this type" errors will be addressed in a
// FIXME(#44265): "lifetime argument not allowed on this type" errors will be addressed in a
// follow-up PR
use std::fmt::Display;
@ -10,13 +10,13 @@ trait StreamingIterator {
type Item<'a>;
// Applying the lifetime parameter `'a` to `Self::Item` inside the trait.
fn next<'a>(&'a self) -> Option<Self::Item<'a>>;
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
//~^ ERROR lifetime arguments are not allowed on this entity [E0110]
}
struct Foo<T: StreamingIterator> {
// Applying a concrete lifetime to the constructor outside the trait.
bar: <T as StreamingIterator>::Item<'static>,
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
//~^ ERROR lifetime arguments are not allowed on this entity [E0110]
}
// Users can bound parameters by the type constructed by that trait's associated type constructor
@ -24,7 +24,7 @@ struct Foo<T: StreamingIterator> {
//FIXME(sunjay): This next line should parse and be valid
//fn foo<T: for<'a> StreamingIterator<Item<'a>=&'a [i32]>>(iter: T) { /* ... */ }
fn foo<T>(iter: T) where T: StreamingIterator, for<'a> T::Item<'a>: Display { /* ... */ }
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
//~^ ERROR lifetime arguments are not allowed on this entity [E0110]
// Full example of enumerate iterator
@ -36,9 +36,9 @@ struct StreamEnumerate<I> {
impl<I: StreamingIterator> StreamingIterator for StreamEnumerate<I> {
type Item<'a> = (usize, I::Item<'a>);
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
//~^ ERROR lifetime arguments are not allowed on this entity [E0110]
fn next<'a>(&'a self) -> Option<Self::Item<'a>> {
//~^ ERROR lifetime parameters are not allowed on this type [E0110]
//~^ ERROR lifetime arguments are not allowed on this entity [E0110]
match self.iter.next() {
None => None,
Some(val) => {

View File

@ -4,35 +4,35 @@ warning: the feature `generic_associated_types` is incomplete and may cause the
LL | #![feature(generic_associated_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/streaming_iterator.rs:18:41
|
LL | bar: <T as StreamingIterator>::Item<'static>,
| ^^^^^^^ lifetime parameter not allowed
| ^^^^^^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/streaming_iterator.rs:26:64
|
LL | fn foo<T>(iter: T) where T: StreamingIterator, for<'a> T::Item<'a>: Display { /* ... */ }
| ^^ lifetime parameter not allowed
| ^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/streaming_iterator.rs:12:48
|
LL | fn next<'a>(&'a self) -> Option<Self::Item<'a>>;
| ^^ lifetime parameter not allowed
| ^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/streaming_iterator.rs:38:37
|
LL | type Item<'a> = (usize, I::Item<'a>);
| ^^ lifetime parameter not allowed
| ^^ lifetime argument not allowed
error[E0110]: lifetime parameters are not allowed on this type
error[E0110]: lifetime arguments are not allowed on this entity
--> $DIR/streaming_iterator.rs:40:48
|
LL | fn next<'a>(&'a self) -> Option<Self::Item<'a>> {
| ^^ lifetime parameter not allowed
| ^^ lifetime argument not allowed
error: aborting due to 5 previous errors

View File

@ -27,10 +27,12 @@ LL | x.baz(); //~ ERROR no method named `baz`
| ^^^
error[E0599]: no function or associated item named `from_str` found for type `u32` in the current scope
--> $DIR/trait-import-suggestions.rs:30:13
--> $DIR/trait-import-suggestions.rs:30:18
|
LL | let y = u32::from_str("33"); //~ ERROR no function or associated item named `from_str`
| ^^^^^^^^^^^^^ function or associated item not found in `u32`
| -----^^^^^^^^
| |
| function or associated item not found in `u32`
|
= help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope, perhaps add a `use` for it:

Some files were not shown because too many files have changed in this diff Show More