mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 01:34:21 +00:00
auto merge of #9135 : jbclements/rust/let-var-hygiene, r=erickt
Fixes issue #9110, changes field_ty element to Name, adds test case, improves fail error message
This commit is contained in:
commit
248765a746
@ -1202,10 +1202,11 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: Cmd, id: ast::NodeId)
|
||||
do reader::tagged_docs(item, tag_item_field) |an_item| {
|
||||
let f = item_family(an_item);
|
||||
if f == PublicField || f == PrivateField || f == InheritedField {
|
||||
// FIXME #6993: name should be of type Name, not Ident
|
||||
let name = item_name(intr, an_item);
|
||||
let did = item_def_id(an_item, cdata);
|
||||
result.push(ty::field_ty {
|
||||
ident: name,
|
||||
name: name.name,
|
||||
id: did, vis:
|
||||
struct_field_family_to_visibility(f),
|
||||
});
|
||||
@ -1215,7 +1216,7 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: Cmd, id: ast::NodeId)
|
||||
do reader::tagged_docs(item, tag_item_unnamed_field) |an_item| {
|
||||
let did = item_def_id(an_item, cdata);
|
||||
result.push(ty::field_ty {
|
||||
ident: special_idents::unnamed_field,
|
||||
name: special_idents::unnamed_field.name,
|
||||
id: did,
|
||||
vis: ast::inherited,
|
||||
});
|
||||
|
@ -700,7 +700,7 @@ pub fn specialize(cx: &MatchCheckCtxt,
|
||||
}
|
||||
let args = class_fields.iter().map(|class_field| {
|
||||
match flds.iter().find(|f|
|
||||
f.ident == class_field.ident) {
|
||||
f.ident.name == class_field.name) {
|
||||
Some(f) => f.pat,
|
||||
_ => wild()
|
||||
}
|
||||
|
@ -1059,6 +1059,7 @@ impl mem_categorization_ctxt {
|
||||
/// an enum to determine which variant is in use.
|
||||
pub fn field_mutbl(tcx: ty::ctxt,
|
||||
base_ty: ty::t,
|
||||
// FIXME #6993: change type to Name
|
||||
f_name: ast::Ident,
|
||||
node_id: ast::NodeId)
|
||||
-> Option<ast::Mutability> {
|
||||
@ -1067,7 +1068,7 @@ pub fn field_mutbl(tcx: ty::ctxt,
|
||||
ty::ty_struct(did, _) => {
|
||||
let r = ty::lookup_struct_fields(tcx, did);
|
||||
for fld in r.iter() {
|
||||
if fld.ident == f_name {
|
||||
if fld.name == f_name.name {
|
||||
return Some(ast::MutImmutable);
|
||||
}
|
||||
}
|
||||
@ -1077,7 +1078,7 @@ pub fn field_mutbl(tcx: ty::ctxt,
|
||||
ast::DefVariant(_, variant_id, _) => {
|
||||
let r = ty::lookup_struct_fields(tcx, variant_id);
|
||||
for fld in r.iter() {
|
||||
if fld.ident == f_name {
|
||||
if fld.name == f_name.name {
|
||||
return Some(ast::MutImmutable);
|
||||
}
|
||||
}
|
||||
|
@ -203,10 +203,11 @@ impl PrivacyVisitor {
|
||||
}
|
||||
|
||||
// Checks that a private field is in scope.
|
||||
// FIXME #6993: change type (and name) from Ident to Name
|
||||
fn check_field(&mut self, span: Span, id: ast::DefId, ident: ast::Ident) {
|
||||
let fields = ty::lookup_struct_fields(self.tcx, id);
|
||||
for field in fields.iter() {
|
||||
if field.ident.name != ident.name { loop; }
|
||||
if field.name != ident.name { loop; }
|
||||
if field.vis == private {
|
||||
self.tcx.sess.span_err(span, fmt!("field `%s` is private",
|
||||
token::ident_to_str(&ident)));
|
||||
|
@ -672,7 +672,7 @@ fn enter_opt<'r>(bcx: @mut Block,
|
||||
let r = ty::lookup_struct_fields(tcx, struct_id);
|
||||
for field in r.iter() {
|
||||
match field_pats.iter().find(|p| p.ident.name
|
||||
== field.ident.name) {
|
||||
== field.name) {
|
||||
None => reordered_patterns.push(dummy),
|
||||
Some(fp) => reordered_patterns.push(fp.pat)
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ pub enum SelfMode {
|
||||
}
|
||||
|
||||
pub struct field_ty {
|
||||
ident: Ident,
|
||||
name: Name,
|
||||
id: DefId,
|
||||
vis: ast::visibility,
|
||||
}
|
||||
@ -1757,7 +1757,7 @@ fn type_is_newtype_immediate(cx: ctxt, ty: t) -> bool {
|
||||
ty_struct(def_id, ref substs) => {
|
||||
let fields = struct_fields(cx, def_id, substs);
|
||||
fields.len() == 1 &&
|
||||
fields[0].ident == token::special_idents::unnamed_field &&
|
||||
fields[0].ident.name == token::special_idents::unnamed_field.name &&
|
||||
type_is_immediate(cx, fields[0].mt.ty)
|
||||
}
|
||||
_ => false
|
||||
@ -4227,15 +4227,15 @@ fn struct_field_tys(fields: &[@struct_field]) -> ~[field_ty] {
|
||||
match field.node.kind {
|
||||
named_field(ident, visibility) => {
|
||||
field_ty {
|
||||
ident: ident,
|
||||
name: ident.name,
|
||||
id: ast_util::local_def(field.node.id),
|
||||
vis: visibility,
|
||||
}
|
||||
}
|
||||
unnamed_field => {
|
||||
field_ty {
|
||||
ident:
|
||||
syntax::parse::token::special_idents::unnamed_field,
|
||||
name:
|
||||
syntax::parse::token::special_idents::unnamed_field.name,
|
||||
id: ast_util::local_def(field.node.id),
|
||||
vis: ast::public,
|
||||
}
|
||||
@ -4250,7 +4250,8 @@ pub fn struct_fields(cx: ctxt, did: ast::DefId, substs: &substs)
|
||||
-> ~[field] {
|
||||
do lookup_struct_fields(cx, did).map |f| {
|
||||
field {
|
||||
ident: f.ident,
|
||||
// FIXME #6993: change type of field to Name and get rid of new()
|
||||
ident: ast::Ident::new(f.name),
|
||||
mt: mt {
|
||||
ty: lookup_field_type(cx, did, f.id, substs),
|
||||
mutbl: MutImmutable
|
||||
|
@ -21,6 +21,7 @@ use middle::typeck::require_same_types;
|
||||
use std::hashmap::{HashMap, HashSet};
|
||||
use syntax::ast;
|
||||
use syntax::ast_util;
|
||||
use syntax::parse::token;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::print::pprust;
|
||||
|
||||
@ -296,7 +297,7 @@ pub fn check_struct_pat_fields(pcx: &pat_ctxt,
|
||||
// Index the class fields.
|
||||
let mut field_map = HashMap::new();
|
||||
for (i, class_field) in class_fields.iter().enumerate() {
|
||||
field_map.insert(class_field.ident.name, i);
|
||||
field_map.insert(class_field.name, i);
|
||||
}
|
||||
|
||||
// Typecheck each field.
|
||||
@ -333,7 +334,7 @@ pub fn check_struct_pat_fields(pcx: &pat_ctxt,
|
||||
}
|
||||
tcx.sess.span_err(span,
|
||||
fmt!("pattern does not mention field `%s`",
|
||||
tcx.sess.str_of(field.ident)));
|
||||
token::interner_get(field.name)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1120,7 +1120,7 @@ pub fn lookup_field_ty(tcx: ty::ctxt,
|
||||
fieldname: ast::Name,
|
||||
substs: &ty::substs) -> Option<ty::t> {
|
||||
|
||||
let o_field = items.iter().find(|f| f.ident.name == fieldname);
|
||||
let o_field = items.iter().find(|f| f.name == fieldname);
|
||||
do o_field.map() |f| {
|
||||
ty::lookup_field_type(tcx, class_id, f.id, substs)
|
||||
}
|
||||
@ -2018,7 +2018,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
||||
let mut class_field_map = HashMap::new();
|
||||
let mut fields_found = 0;
|
||||
for field in field_types.iter() {
|
||||
class_field_map.insert(field.ident.name, (field.id, false));
|
||||
class_field_map.insert(field.name, (field.id, false));
|
||||
}
|
||||
|
||||
let mut error_happened = false;
|
||||
@ -2070,7 +2070,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
||||
if fields_found < field_types.len() {
|
||||
let mut missing_fields = ~[];
|
||||
for class_field in field_types.iter() {
|
||||
let name = class_field.ident.name;
|
||||
let name = class_field.name;
|
||||
let (_, seen) = *class_field_map.get(&name);
|
||||
if !seen {
|
||||
missing_fields.push(
|
||||
|
@ -47,7 +47,8 @@ impl Eq for Ident {
|
||||
// if it should be non-hygienic (most things are), just compare the
|
||||
// 'name' fields of the idents. Or, even better, replace the idents
|
||||
// with Name's.
|
||||
fail!(fmt!("not allowed to compare these idents: %?, %?", self, other));
|
||||
fail!(fmt!("not allowed to compare these idents: %?, %?. Probably \
|
||||
related to issue #6993", self, other));
|
||||
}
|
||||
}
|
||||
fn ne(&self, other: &Ident) -> bool {
|
||||
|
22
src/test/run-pass/issue-9110.rs
Normal file
22
src/test/run-pass/issue-9110.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2013 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.
|
||||
|
||||
macro_rules! silly_macro(
|
||||
() => (
|
||||
pub mod Qux {
|
||||
pub struct Foo { x : u8 }
|
||||
pub fn bar(_foo : Foo) {}
|
||||
}
|
||||
);
|
||||
)
|
||||
|
||||
silly_macro!()
|
||||
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user