mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 15:32:06 +00:00
commit
192e336148
10
mk/tests.mk
10
mk/tests.mk
@ -636,11 +636,11 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
|
||||
--host-rustcflags "$(RUSTC_FLAGS_$(3)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(3))" \
|
||||
--lldb-python-dir=$(CFG_LLDB_PYTHON_DIR) \
|
||||
--target-rustcflags "$(RUSTC_FLAGS_$(2)) $$(CTEST_RUSTC_FLAGS) -L $$(RT_OUTPUT_DIR_$(2))" \
|
||||
--cc '$$(CC_$(3))' \
|
||||
--cxx '$$(CXX_$(3))' \
|
||||
--cflags "$$(CFG_GCCISH_CFLAGS_$(3))" \
|
||||
--llvm-components "$$(LLVM_ALL_COMPONENTS_$(3))" \
|
||||
--llvm-cxxflags "$$(LLVM_CXXFLAGS_$(3))" \
|
||||
--cc '$$(CC_$(2))' \
|
||||
--cxx '$$(CXX_$(2))' \
|
||||
--cflags "$$(CFG_GCCISH_CFLAGS_$(2))" \
|
||||
--llvm-components "$$(LLVM_ALL_COMPONENTS_$(2))" \
|
||||
--llvm-cxxflags "$$(LLVM_CXXFLAGS_$(2))" \
|
||||
$$(CTEST_TESTARGS)
|
||||
|
||||
ifdef CFG_VALGRIND_RPASS
|
||||
|
@ -8,7 +8,7 @@ we’ll talk about Cargo, Rust’s build system and package manager.
|
||||
|
||||
The first step to using Rust is to install it. Generally speaking, you’ll need
|
||||
an Internet connection to run the commands in this section, as we’ll be
|
||||
downloading Rust from the internet.
|
||||
downloading Rust from the Internet.
|
||||
|
||||
We’ll be showing off a number of commands using a terminal, and those lines all
|
||||
start with `$`. We don't need to type in the `$`s, they are there to indicate
|
||||
@ -399,13 +399,13 @@ Let’s convert the Hello World program to Cargo. To Cargo-fy a project, you nee
|
||||
to do three things:
|
||||
|
||||
1. Put your source file in the right directory.
|
||||
2. Get rid of the old executable (`main.exe` on Windows, `main` everywhere else)
|
||||
and make a new one.
|
||||
2. Get rid of the old executable (`main.exe` on Windows, `main` everywhere
|
||||
else).
|
||||
3. Make a Cargo configuration file.
|
||||
|
||||
Let's get started!
|
||||
|
||||
### Creating a new Executable and Source Directory
|
||||
### Creating a Source Directory and Removing the Old Executable
|
||||
|
||||
First, go back to your terminal, move to your *hello_world* directory, and
|
||||
enter the following commands:
|
||||
|
@ -333,7 +333,7 @@
|
||||
//! precision := count | '*'
|
||||
//! type := identifier | ''
|
||||
//! count := parameter | integer
|
||||
//! parameter := integer '$'
|
||||
//! parameter := argument '$'
|
||||
//! ```
|
||||
//!
|
||||
//! # Formatting Parameters
|
||||
@ -403,11 +403,12 @@
|
||||
//! println!("Hello {:5}!", "x");
|
||||
//! println!("Hello {:1$}!", "x", 5);
|
||||
//! println!("Hello {1:0$}!", 5, "x");
|
||||
//! println!("Hello {:width$}!", "x", width = 5);
|
||||
//! ```
|
||||
//!
|
||||
//! Referring to an argument with the dollar syntax does not affect the "next
|
||||
//! argument" counter, so it's usually a good idea to refer to all arguments by
|
||||
//! their position explicitly.
|
||||
//! argument" counter, so it's usually a good idea to refer to arguments by
|
||||
//! position, or use named arguments.
|
||||
//!
|
||||
//! ## Precision
|
||||
//!
|
||||
@ -426,7 +427,7 @@
|
||||
//!
|
||||
//! the integer `N` itself is the precision.
|
||||
//!
|
||||
//! 2. An integer followed by dollar sign `.N$`:
|
||||
//! 2. An integer or name followed by dollar sign `.N$`:
|
||||
//!
|
||||
//! use format *argument* `N` (which must be a `usize`) as the precision.
|
||||
//!
|
||||
@ -456,6 +457,10 @@
|
||||
//! // Hello {next arg (x)} is {arg 2 (0.01) with precision
|
||||
//! // specified in its predecessor (5)}
|
||||
//! println!("Hello {} is {2:.*}", "x", 5, 0.01);
|
||||
//!
|
||||
//! // Hello {next arg (x)} is {arg "number" (0.01) with precision specified
|
||||
//! // in arg "prec" (5)}
|
||||
//! println!("Hello {} is {number:.prec$}", "x", prec = 5, number = 0.01);
|
||||
//! ```
|
||||
//!
|
||||
//! All print the same thing:
|
||||
|
@ -110,6 +110,7 @@ pub use intrinsics::transmute;
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn forget<T>(t: T) {
|
||||
unsafe { intrinsics::forget(t) }
|
||||
|
@ -275,6 +275,15 @@ macro_rules! wrapping_impl {
|
||||
*self = *self & other;
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "wrapping_neg", since = "1.10.0")]
|
||||
impl Neg for Wrapping<$t> {
|
||||
type Output = Self;
|
||||
#[inline(always)]
|
||||
fn neg(self) -> Self {
|
||||
Wrapping(0) - self
|
||||
}
|
||||
}
|
||||
)*)
|
||||
}
|
||||
|
||||
|
@ -314,6 +314,82 @@ let c = &i; // still ok!
|
||||
```
|
||||
"##,
|
||||
|
||||
E0501: r##"
|
||||
This error indicates that a mutable variable is being used while it is still
|
||||
captured by a closure. Because the closure has borrowed the variable, it is not
|
||||
available for use until the closure goes out of scope.
|
||||
|
||||
Note that a capture will either move or borrow a variable, but in this
|
||||
situation, the closure is borrowing the variable. Take a look at
|
||||
http://rustbyexample.com/fn/closures/capture.html for more information about
|
||||
capturing.
|
||||
|
||||
Example of erroneous code:
|
||||
|
||||
```compile_fail
|
||||
fn inside_closure(x: &mut i32) {
|
||||
// Actions which require unique access
|
||||
}
|
||||
|
||||
fn outside_closure(x: &mut i32) {
|
||||
// Actions which require unique access
|
||||
}
|
||||
|
||||
fn foo(a: &mut i32) {
|
||||
let bar = || {
|
||||
inside_closure(a)
|
||||
};
|
||||
outside_closure(a); // error: cannot borrow `*a` as mutable because previous
|
||||
// closure requires unique access.
|
||||
}
|
||||
```
|
||||
|
||||
To fix this error, you can place the closure in its own scope:
|
||||
|
||||
```
|
||||
fn inside_closure(x: &mut i32) {}
|
||||
fn outside_closure(x: &mut i32) {}
|
||||
|
||||
fn foo(a: &mut i32) {
|
||||
{
|
||||
let bar = || {
|
||||
inside_closure(a)
|
||||
};
|
||||
} // borrow on `a` ends.
|
||||
outside_closure(a); // ok!
|
||||
}
|
||||
```
|
||||
|
||||
Or you can pass the variable as a parameter to the closure:
|
||||
|
||||
```
|
||||
fn inside_closure(x: &mut i32) {}
|
||||
fn outside_closure(x: &mut i32) {}
|
||||
|
||||
fn foo(a: &mut i32) {
|
||||
let bar = |s: &mut i32| {
|
||||
inside_closure(s)
|
||||
};
|
||||
outside_closure(a);
|
||||
bar(a);
|
||||
}
|
||||
```
|
||||
|
||||
It may be possible to define the closure later:
|
||||
|
||||
```
|
||||
fn inside_closure(x: &mut i32) {}
|
||||
fn outside_closure(x: &mut i32) {}
|
||||
|
||||
fn foo(a: &mut i32) {
|
||||
outside_closure(a);
|
||||
let bar = || {
|
||||
inside_closure(a)
|
||||
};
|
||||
}
|
||||
```
|
||||
"##,
|
||||
|
||||
E0507: r##"
|
||||
You tried to move out of a value which was borrowed. Erroneous code example:
|
||||
|
||||
@ -436,7 +512,6 @@ register_diagnostics! {
|
||||
E0388, // {} in a static location
|
||||
E0389, // {} in a `&` reference
|
||||
E0500, // closure requires unique access to `..` but .. is already borrowed
|
||||
E0501, // cannot borrow `..`.. as .. because previous closure requires unique access
|
||||
E0502, // cannot borrow `..`.. as .. because .. is also borrowed as ...
|
||||
E0503, // cannot use `..` because it was mutably borrowed
|
||||
E0504, // cannot move `..` into closure because it is borrowed
|
||||
|
@ -377,13 +377,6 @@ pub enum ErrKind {
|
||||
NotOn(ConstVal),
|
||||
CallOn(ConstVal),
|
||||
|
||||
NegateWithOverflow(i64),
|
||||
AddiWithOverflow(i64, i64),
|
||||
SubiWithOverflow(i64, i64),
|
||||
MuliWithOverflow(i64, i64),
|
||||
AdduWithOverflow(u64, u64),
|
||||
SubuWithOverflow(u64, u64),
|
||||
MuluWithOverflow(u64, u64),
|
||||
DivideByZero,
|
||||
DivideWithOverflow,
|
||||
ModuloByZero,
|
||||
@ -415,6 +408,7 @@ pub enum ErrKind {
|
||||
TypeMismatch(String, ConstInt),
|
||||
BadType(ConstVal),
|
||||
ErroneousReferencedConstant(Box<ConstEvalErr>),
|
||||
CharCast(ConstInt),
|
||||
}
|
||||
|
||||
impl From<ConstMathErr> for ErrKind {
|
||||
@ -439,13 +433,6 @@ impl ConstEvalErr {
|
||||
NotOn(ref const_val) => format!("not on {}", const_val.description()).into_cow(),
|
||||
CallOn(ref const_val) => format!("call on {}", const_val.description()).into_cow(),
|
||||
|
||||
NegateWithOverflow(..) => "attempted to negate with overflow".into_cow(),
|
||||
AddiWithOverflow(..) => "attempted to add with overflow".into_cow(),
|
||||
SubiWithOverflow(..) => "attempted to sub with overflow".into_cow(),
|
||||
MuliWithOverflow(..) => "attempted to mul with overflow".into_cow(),
|
||||
AdduWithOverflow(..) => "attempted to add with overflow".into_cow(),
|
||||
SubuWithOverflow(..) => "attempted to sub with overflow".into_cow(),
|
||||
MuluWithOverflow(..) => "attempted to mul with overflow".into_cow(),
|
||||
DivideByZero => "attempted to divide by zero".into_cow(),
|
||||
DivideWithOverflow => "attempted to divide with overflow".into_cow(),
|
||||
ModuloByZero => "attempted remainder with a divisor of zero".into_cow(),
|
||||
@ -482,6 +469,9 @@ impl ConstEvalErr {
|
||||
},
|
||||
BadType(ref i) => format!("value of wrong type: {:?}", i).into_cow(),
|
||||
ErroneousReferencedConstant(_) => "could not evaluate referenced constant".into_cow(),
|
||||
CharCast(ref got) => {
|
||||
format!("only `u8` can be cast as `char`, not `{}`", got.description()).into_cow()
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -824,7 +814,10 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
|
||||
debug!("const call({:?})", call_args);
|
||||
eval_const_expr_partial(tcx, &result, ty_hint, Some(&call_args))?
|
||||
},
|
||||
hir::ExprLit(ref lit) => lit_to_const(&lit.node, tcx, ety, lit.span)?,
|
||||
hir::ExprLit(ref lit) => match lit_to_const(&lit.node, tcx, ety, lit.span) {
|
||||
Ok(val) => val,
|
||||
Err(err) => signal!(e, err),
|
||||
},
|
||||
hir::ExprBlock(ref block) => {
|
||||
match block.expr {
|
||||
Some(ref expr) => eval_const_expr_partial(tcx, &expr, ty_hint, fn_args)?,
|
||||
@ -930,7 +923,10 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &TyCtxt<'tcx>,
|
||||
};
|
||||
|
||||
match (ety.map(|t| &t.sty), result) {
|
||||
(Some(ref ty_hint), Integral(i)) => Ok(Integral(infer(i, tcx, ty_hint, e.span)?)),
|
||||
(Some(ref ty_hint), Integral(i)) => match infer(i, tcx, ty_hint) {
|
||||
Ok(inferred) => Ok(Integral(inferred)),
|
||||
Err(err) => signal!(e, err),
|
||||
},
|
||||
(_, result) => Ok(result),
|
||||
}
|
||||
}
|
||||
@ -939,15 +935,9 @@ fn infer<'tcx>(
|
||||
i: ConstInt,
|
||||
tcx: &TyCtxt<'tcx>,
|
||||
ty_hint: &ty::TypeVariants<'tcx>,
|
||||
span: Span
|
||||
) -> Result<ConstInt, ConstEvalErr> {
|
||||
) -> Result<ConstInt, ErrKind> {
|
||||
use syntax::ast::*;
|
||||
|
||||
let err = |e| ConstEvalErr {
|
||||
span: span,
|
||||
kind: e,
|
||||
};
|
||||
|
||||
match (ty_hint, i) {
|
||||
(&ty::TyInt(IntTy::I8), result @ I8(_)) => Ok(result),
|
||||
(&ty::TyInt(IntTy::I16), result @ I16(_)) => Ok(result),
|
||||
@ -993,17 +983,17 @@ fn infer<'tcx>(
|
||||
Err(_) => Ok(Usize(ConstUsize::Us32(i as u32))),
|
||||
}
|
||||
},
|
||||
(&ty::TyUint(_), InferSigned(_)) => Err(err(IntermediateUnsignedNegative)),
|
||||
(&ty::TyUint(_), InferSigned(_)) => Err(IntermediateUnsignedNegative),
|
||||
|
||||
(&ty::TyInt(ity), i) => Err(err(TypeMismatch(ity.to_string(), i))),
|
||||
(&ty::TyUint(ity), i) => Err(err(TypeMismatch(ity.to_string(), i))),
|
||||
(&ty::TyInt(ity), i) => Err(TypeMismatch(ity.to_string(), i)),
|
||||
(&ty::TyUint(ity), i) => Err(TypeMismatch(ity.to_string(), i)),
|
||||
|
||||
(&ty::TyEnum(ref adt, _), i) => {
|
||||
let hints = tcx.lookup_repr_hints(adt.did);
|
||||
let int_ty = tcx.enum_repr_type(hints.iter().next());
|
||||
infer(i, tcx, &int_ty.to_ty(tcx).sty, span)
|
||||
infer(i, tcx, &int_ty.to_ty(tcx).sty)
|
||||
},
|
||||
(_, i) => Err(err(BadType(ConstVal::Integral(i)))),
|
||||
(_, i) => Err(BadType(ConstVal::Integral(i))),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1089,23 +1079,22 @@ fn cast_const_int<'tcx>(tcx: &TyCtxt<'tcx>, val: ConstInt, ty: ty::Ty) -> CastRe
|
||||
Err(_) => Ok(Integral(Usize(ConstUsize::Us32(v as u32)))),
|
||||
}
|
||||
},
|
||||
ty::TyFloat(ast::FloatTy::F64) if val.is_negative() => {
|
||||
// FIXME: this could probably be prettier
|
||||
// there's no easy way to turn an `Infer` into a f64
|
||||
let val = (-val).map_err(Math)?;
|
||||
let val = val.to_u64().unwrap() as f64;
|
||||
let val = -val;
|
||||
Ok(Float(val))
|
||||
ty::TyFloat(ast::FloatTy::F64) => match val.erase_type() {
|
||||
Infer(u) => Ok(Float(u as f64)),
|
||||
InferSigned(i) => Ok(Float(i as f64)),
|
||||
_ => bug!("ConstInt::erase_type returned something other than Infer/InferSigned"),
|
||||
},
|
||||
ty::TyFloat(ast::FloatTy::F64) => Ok(Float(val.to_u64().unwrap() as f64)),
|
||||
ty::TyFloat(ast::FloatTy::F32) if val.is_negative() => {
|
||||
let val = (-val).map_err(Math)?;
|
||||
let val = val.to_u64().unwrap() as f32;
|
||||
let val = -val;
|
||||
Ok(Float(val as f64))
|
||||
ty::TyFloat(ast::FloatTy::F32) => match val.erase_type() {
|
||||
Infer(u) => Ok(Float(u as f32 as f64)),
|
||||
InferSigned(i) => Ok(Float(i as f32 as f64)),
|
||||
_ => bug!("ConstInt::erase_type returned something other than Infer/InferSigned"),
|
||||
},
|
||||
ty::TyFloat(ast::FloatTy::F32) => Ok(Float(val.to_u64().unwrap() as f32 as f64)),
|
||||
ty::TyRawPtr(_) => Err(ErrKind::UnimplementedConstVal("casting an address to a raw ptr")),
|
||||
ty::TyChar => match infer(val, tcx, &ty::TyUint(ast::UintTy::U8)) {
|
||||
Ok(U8(u)) => Ok(Char(u as char)),
|
||||
// can only occur before typeck, typeck blocks `T as char` for `T` != `u8`
|
||||
_ => Err(CharCast(val)),
|
||||
},
|
||||
_ => Err(CannotCast),
|
||||
}
|
||||
}
|
||||
@ -1136,7 +1125,7 @@ fn lit_to_const<'tcx>(lit: &ast::LitKind,
|
||||
tcx: &TyCtxt<'tcx>,
|
||||
ty_hint: Option<Ty<'tcx>>,
|
||||
span: Span,
|
||||
) -> Result<ConstVal, ConstEvalErr> {
|
||||
) -> Result<ConstVal, ErrKind> {
|
||||
use syntax::ast::*;
|
||||
use syntax::ast::LitIntType::*;
|
||||
match *lit {
|
||||
@ -1144,28 +1133,28 @@ fn lit_to_const<'tcx>(lit: &ast::LitKind,
|
||||
LitKind::ByteStr(ref data) => Ok(ByteStr(data.clone())),
|
||||
LitKind::Byte(n) => Ok(Integral(U8(n))),
|
||||
LitKind::Int(n, Signed(ity)) => {
|
||||
infer(InferSigned(n as i64), tcx, &ty::TyInt(ity), span).map(Integral)
|
||||
infer(InferSigned(n as i64), tcx, &ty::TyInt(ity)).map(Integral)
|
||||
},
|
||||
|
||||
LitKind::Int(n, Unsuffixed) => {
|
||||
match ty_hint.map(|t| &t.sty) {
|
||||
Some(&ty::TyInt(ity)) => {
|
||||
infer(InferSigned(n as i64), tcx, &ty::TyInt(ity), span).map(Integral)
|
||||
infer(InferSigned(n as i64), tcx, &ty::TyInt(ity)).map(Integral)
|
||||
},
|
||||
Some(&ty::TyUint(uty)) => {
|
||||
infer(Infer(n), tcx, &ty::TyUint(uty), span).map(Integral)
|
||||
infer(Infer(n), tcx, &ty::TyUint(uty)).map(Integral)
|
||||
},
|
||||
None => Ok(Integral(Infer(n))),
|
||||
Some(&ty::TyEnum(ref adt, _)) => {
|
||||
let hints = tcx.lookup_repr_hints(adt.did);
|
||||
let int_ty = tcx.enum_repr_type(hints.iter().next());
|
||||
infer(Infer(n), tcx, &int_ty.to_ty(tcx).sty, span).map(Integral)
|
||||
infer(Infer(n), tcx, &int_ty.to_ty(tcx).sty).map(Integral)
|
||||
},
|
||||
Some(ty_hint) => bug!("bad ty_hint: {:?}, {:?}", ty_hint, lit),
|
||||
}
|
||||
},
|
||||
LitKind::Int(n, Unsigned(ity)) => {
|
||||
infer(Infer(n), tcx, &ty::TyUint(ity), span).map(Integral)
|
||||
infer(Infer(n), tcx, &ty::TyUint(ity)).map(Integral)
|
||||
},
|
||||
|
||||
LitKind::Float(ref n, _) |
|
||||
|
@ -147,7 +147,7 @@ enum ResolutionError<'a> {
|
||||
/// error E0416: identifier is bound more than once in the same pattern
|
||||
IdentifierBoundMoreThanOnceInSamePattern(&'a str),
|
||||
/// error E0417: static variables cannot be referenced in a pattern
|
||||
StaticVariableReference,
|
||||
StaticVariableReference(DefId, Option<Name>),
|
||||
/// error E0418: is not an enum variant, struct or const
|
||||
NotAnEnumVariantStructOrConst(&'a str),
|
||||
/// error E0419: unresolved enum variant, struct or const
|
||||
@ -352,12 +352,24 @@ fn resolve_struct_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
|
||||
"identifier `{}` is bound more than once in the same pattern",
|
||||
identifier)
|
||||
}
|
||||
ResolutionError::StaticVariableReference => {
|
||||
struct_span_err!(resolver.session,
|
||||
span,
|
||||
E0417,
|
||||
"static variables cannot be referenced in a pattern, use a \
|
||||
`const` instead")
|
||||
ResolutionError::StaticVariableReference(did, name) => {
|
||||
let mut err = struct_span_err!(resolver.session,
|
||||
span,
|
||||
E0417,
|
||||
"static variables cannot be referenced in a \
|
||||
pattern, use a `const` instead");
|
||||
if let Some(sp) = resolver.ast_map.span_if_local(did) {
|
||||
err.span_note(sp, "static variable defined here");
|
||||
}
|
||||
if let Some(name) = name {
|
||||
if let Some(binding) = resolver.current_module
|
||||
.resolve_name_in_lexical_scope(name, ValueNS) {
|
||||
if binding.is_import() {
|
||||
err.span_note(binding.span, "static variable imported here");
|
||||
}
|
||||
}
|
||||
}
|
||||
err
|
||||
}
|
||||
ResolutionError::NotAnEnumVariantStructOrConst(name) => {
|
||||
struct_span_err!(resolver.session,
|
||||
@ -2313,10 +2325,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
Def::Variant(..) | Def::Const(..) => {
|
||||
self.record_def(pattern.id, path_res);
|
||||
}
|
||||
Def::Static(..) => {
|
||||
Def::Static(did, _) => {
|
||||
resolve_error(&self,
|
||||
path.span,
|
||||
ResolutionError::StaticVariableReference);
|
||||
ResolutionError::StaticVariableReference(
|
||||
did, None));
|
||||
self.record_def(pattern.id, err_path_resolution());
|
||||
}
|
||||
_ => {
|
||||
@ -2456,8 +2469,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
Some(def @ Def::Const(..)) | Some(def @ Def::AssociatedConst(..)) => {
|
||||
FoundConst(def, ident.unhygienic_name)
|
||||
}
|
||||
Some(Def::Static(..)) => {
|
||||
resolve_error(self, span, ResolutionError::StaticVariableReference);
|
||||
Some(Def::Static(did, _)) => {
|
||||
resolve_error(self, span, ResolutionError::StaticVariableReference(
|
||||
did, Some(ident.unhygienic_name)));
|
||||
BareIdentifierPatternUnresolved
|
||||
}
|
||||
_ => BareIdentifierPatternUnresolved,
|
||||
|
@ -60,8 +60,8 @@ impl<'b, W: Write + 'b> Dump for CsvDumper<'b, W> {
|
||||
}
|
||||
|
||||
fn enum_data(&mut self, data: EnumData) {
|
||||
let id = data.id.to_string();
|
||||
let scope = data.scope.to_string();
|
||||
let id = data.id.index.as_u32().to_string();
|
||||
let scope = data.scope.index.as_u32().to_string();
|
||||
let values = make_values_str(&[
|
||||
("id", &id),
|
||||
("qualname", &data.qualname),
|
||||
@ -73,9 +73,9 @@ impl<'b, W: Write + 'b> Dump for CsvDumper<'b, W> {
|
||||
}
|
||||
|
||||
fn extern_crate(&mut self, data: ExternCrateData) {
|
||||
let id = data.id.to_string();
|
||||
let id = data.id.index.as_u32().to_string();
|
||||
let crate_num = data.crate_num.to_string();
|
||||
let scope = data.scope.to_string();
|
||||
let scope = data.scope.index.as_u32().to_string();
|
||||
let values = make_values_str(&[
|
||||
("id", &id),
|
||||
("name", &data.name),
|
||||
@ -88,14 +88,21 @@ impl<'b, W: Write + 'b> Dump for CsvDumper<'b, W> {
|
||||
}
|
||||
|
||||
fn impl_data(&mut self, data: ImplData) {
|
||||
let id = data.id.to_string();
|
||||
let ref_id = data.self_ref.unwrap_or(Id::null()).to_string();
|
||||
let trait_id = data.trait_ref.unwrap_or(Id::null()).to_string();
|
||||
let scope = data.scope.to_string();
|
||||
let self_ref = data.self_ref.unwrap_or(null_def_id());
|
||||
let trait_ref = data.trait_ref.unwrap_or(null_def_id());
|
||||
|
||||
let id = data.id.index.as_u32().to_string();
|
||||
let ref_id = self_ref.index.as_usize().to_string();
|
||||
let ref_id_crate = self_ref.krate.to_string();
|
||||
let trait_id = trait_ref.index.as_usize().to_string();
|
||||
let trait_id_crate = trait_ref.krate.to_string();
|
||||
let scope = data.scope.index.as_u32().to_string();
|
||||
let values = make_values_str(&[
|
||||
("id", &id),
|
||||
("refid", &ref_id),
|
||||
("refidcrate", &ref_id_crate),
|
||||
("traitid", &trait_id),
|
||||
("traitidcrate", &trait_id_crate),
|
||||
("scopeid", &scope)
|
||||
]);
|
||||
|
||||
@ -103,24 +110,33 @@ impl<'b, W: Write + 'b> Dump for CsvDumper<'b, W> {
|
||||
}
|
||||
|
||||
fn inheritance(&mut self, data: InheritanceData) {
|
||||
let base_id = data.base_id.to_string();
|
||||
let deriv_id = data.deriv_id.to_string();
|
||||
let values = make_values_str(&[
|
||||
("base", &base_id),
|
||||
("derived", &deriv_id),
|
||||
]);
|
||||
let base_id = data.base_id.index.as_usize().to_string();
|
||||
let base_crate = data.base_id.krate.to_string();
|
||||
let deriv_id = data.deriv_id.index.as_u32().to_string();
|
||||
let deriv_crate = data.deriv_id.krate.to_string();
|
||||
let values = make_values_str(&[
|
||||
("base", &base_id),
|
||||
("basecrate", &base_crate),
|
||||
("derived", &deriv_id),
|
||||
("derivedcrate", &deriv_crate)
|
||||
]);
|
||||
|
||||
self.record("inheritance", data.span, values);
|
||||
}
|
||||
|
||||
fn function(&mut self, data: FunctionData) {
|
||||
let id = data.id.to_string();
|
||||
let decl_id = data.declaration.unwrap_or(Id::null()).to_string();
|
||||
let scope = data.scope.to_string();
|
||||
let (decl_id, decl_crate) = match data.declaration {
|
||||
Some(id) => (id.index.as_usize().to_string(), id.krate.to_string()),
|
||||
None => (String::new(), String::new())
|
||||
};
|
||||
|
||||
let id = data.id.index.as_u32().to_string();
|
||||
let scope = data.scope.index.as_u32().to_string();
|
||||
let values = make_values_str(&[
|
||||
("id", &id),
|
||||
("qualname", &data.qualname),
|
||||
("declid", &decl_id),
|
||||
("declidcrate", &decl_crate),
|
||||
("scopeid", &scope)
|
||||
]);
|
||||
|
||||
@ -128,10 +144,12 @@ impl<'b, W: Write + 'b> Dump for CsvDumper<'b, W> {
|
||||
}
|
||||
|
||||
fn function_ref(&mut self, data: FunctionRefData) {
|
||||
let ref_id = data.ref_id.to_string();
|
||||
let scope = data.scope.to_string();
|
||||
let ref_id = data.ref_id.index.as_usize().to_string();
|
||||
let ref_crate = data.ref_id.krate.to_string();
|
||||
let scope = data.scope.index.as_u32().to_string();
|
||||
let values = make_values_str(&[
|
||||
("refid", &ref_id),
|
||||
("refidcrate", &ref_crate),
|
||||
("qualname", ""),
|
||||
("scopeid", &scope)
|
||||
]);
|
||||
@ -140,11 +158,13 @@ impl<'b, W: Write + 'b> Dump for CsvDumper<'b, W> {
|
||||
}
|
||||
|
||||
fn function_call(&mut self, data: FunctionCallData) {
|
||||
let ref_id = data.ref_id.to_string();
|
||||
let ref_id = data.ref_id.index.as_usize().to_string();
|
||||
let ref_crate = data.ref_id.krate.to_string();
|
||||
let qualname = String::new();
|
||||
let scope = data.scope.to_string();
|
||||
let scope = data.scope.index.as_u32().to_string();
|
||||
let values = make_values_str(&[
|
||||
("refid", &ref_id),
|
||||
("refidcrate", &ref_crate),
|
||||
("qualname", &qualname),
|
||||
("scopeid", &scope)
|
||||
]);
|
||||
@ -153,8 +173,8 @@ impl<'b, W: Write + 'b> Dump for CsvDumper<'b, W> {
|
||||
}
|
||||
|
||||
fn method(&mut self, data: MethodData) {
|
||||
let id = data.id.to_string();
|
||||
let scope = data.scope.to_string();
|
||||
let id = data.id.index.as_u32().to_string();
|
||||
let scope = data.scope.index.as_u32().to_string();
|
||||
let values = make_values_str(&[
|
||||
("id", &id),
|
||||
("qualname", &data.qualname),
|
||||
@ -165,12 +185,21 @@ impl<'b, W: Write + 'b> Dump for CsvDumper<'b, W> {
|
||||
}
|
||||
|
||||
fn method_call(&mut self, data: MethodCallData) {
|
||||
let decl_id = data.decl_id.unwrap_or(Id::null()).to_string();
|
||||
let ref_id = data.ref_id.unwrap_or(Id::null()).to_string();
|
||||
let scope = data.scope.to_string();
|
||||
let (dcn, dck) = match data.decl_id {
|
||||
Some(declid) => (declid.index.as_usize().to_string(), declid.krate.to_string()),
|
||||
None => (String::new(), String::new()),
|
||||
};
|
||||
|
||||
let ref_id = data.ref_id.unwrap_or(null_def_id());
|
||||
|
||||
let def_id = ref_id.index.as_usize().to_string();
|
||||
let def_crate = ref_id.krate.to_string();
|
||||
let scope = data.scope.index.as_u32().to_string();
|
||||
let values = make_values_str(&[
|
||||
("refid", &ref_id),
|
||||
("declid", &decl_id),
|
||||
("refid", &def_id),
|
||||
("refidcrate", &def_crate),
|
||||
("declid", &dcn),
|
||||
("declidcrate", &dck),
|
||||
("scopeid", &scope)
|
||||
]);
|
||||
|
||||
@ -187,7 +216,7 @@ impl<'b, W: Write + 'b> Dump for CsvDumper<'b, W> {
|
||||
}
|
||||
|
||||
fn macro_use(&mut self, data: MacroUseData) {
|
||||
let scope = data.scope.to_string();
|
||||
let scope = data.scope.index.as_u32().to_string();
|
||||
let values = make_values_str(&[
|
||||
("callee_name", &data.name),
|
||||
("qualname", &data.qualname),
|
||||
@ -198,8 +227,8 @@ impl<'b, W: Write + 'b> Dump for CsvDumper<'b, W> {
|
||||
}
|
||||
|
||||
fn mod_data(&mut self, data: ModData) {
|
||||
let id = data.id.to_string();
|
||||
let scope = data.scope.to_string();
|
||||
let id = data.id.index.as_u32().to_string();
|
||||
let scope = data.scope.index.as_u32().to_string();
|
||||
let values = make_values_str(&[
|
||||
("id", &id),
|
||||
("qualname", &data.qualname),
|
||||
@ -211,11 +240,15 @@ impl<'b, W: Write + 'b> Dump for CsvDumper<'b, W> {
|
||||
}
|
||||
|
||||
fn mod_ref(&mut self, data: ModRefData) {
|
||||
let ref_id = data.ref_id.unwrap_or(Id::null()).to_string();
|
||||
let (ref_id, ref_crate) = match data.ref_id {
|
||||
Some(rid) => (rid.index.as_usize().to_string(), rid.krate.to_string()),
|
||||
None => (0.to_string(), 0.to_string())
|
||||
};
|
||||
|
||||
let scope = data.scope.to_string();
|
||||
let scope = data.scope.index.as_u32().to_string();
|
||||
let values = make_values_str(&[
|
||||
("refid", &ref_id),
|
||||
("refidcrate", &ref_crate),
|
||||
("qualname", &data.qualname),
|
||||
("scopeid", &scope)
|
||||
]);
|
||||
@ -224,9 +257,9 @@ impl<'b, W: Write + 'b> Dump for CsvDumper<'b, W> {
|
||||
}
|
||||
|
||||
fn struct_data(&mut self, data: StructData) {
|
||||
let id = data.id.to_string();
|
||||
let ctor_id = data.ctor_id.to_string();
|
||||
let scope = data.scope.to_string();
|
||||
let id = data.id.index.as_u32().to_string();
|
||||
let ctor_id = data.ctor_id.index.as_u32().to_string();
|
||||
let scope = data.scope.index.as_u32().to_string();
|
||||
let values = make_values_str(&[
|
||||
("id", &id),
|
||||
("ctor_id", &ctor_id),
|
||||
@ -239,8 +272,8 @@ impl<'b, W: Write + 'b> Dump for CsvDumper<'b, W> {
|
||||
}
|
||||
|
||||
fn struct_variant(&mut self, data: StructVariantData) {
|
||||
let id = data.id.to_string();
|
||||
let scope = data.scope.to_string();
|
||||
let id = data.id.index.as_u32().to_string();
|
||||
let scope = data.scope.index.as_u32().to_string();
|
||||
let values = make_values_str(&[
|
||||
("id", &id),
|
||||
("ctor_id", &id),
|
||||
@ -254,8 +287,8 @@ impl<'b, W: Write + 'b> Dump for CsvDumper<'b, W> {
|
||||
}
|
||||
|
||||
fn trait_data(&mut self, data: TraitData) {
|
||||
let id = data.id.to_string();
|
||||
let scope = data.scope.to_string();
|
||||
let id = data.id.index.as_u32().to_string();
|
||||
let scope = data.scope.index.as_u32().to_string();
|
||||
let values = make_values_str(&[
|
||||
("id", &id),
|
||||
("qualname", &data.qualname),
|
||||
@ -267,8 +300,8 @@ impl<'b, W: Write + 'b> Dump for CsvDumper<'b, W> {
|
||||
}
|
||||
|
||||
fn tuple_variant(&mut self, data: TupleVariantData) {
|
||||
let id = data.id.to_string();
|
||||
let scope = data.scope.to_string();
|
||||
let id = data.id.index.as_u32().to_string();
|
||||
let scope = data.scope.index.as_u32().to_string();
|
||||
let values = make_values_str(&[
|
||||
("id", &id),
|
||||
("name", &data.name),
|
||||
@ -282,10 +315,15 @@ impl<'b, W: Write + 'b> Dump for CsvDumper<'b, W> {
|
||||
}
|
||||
|
||||
fn type_ref(&mut self, data: TypeRefData) {
|
||||
let ref_id = data.ref_id.unwrap_or(Id::null()).to_string();
|
||||
let scope = data.scope.to_string();
|
||||
let (ref_id, ref_crate) = match data.ref_id {
|
||||
Some(id) => (id.index.as_usize().to_string(), id.krate.to_string()),
|
||||
None => (0.to_string(), 0.to_string())
|
||||
};
|
||||
|
||||
let scope = data.scope.index.as_u32().to_string();
|
||||
let values = make_values_str(&[
|
||||
("refid", &ref_id),
|
||||
("refidcrate", &ref_crate),
|
||||
("qualname", &data.qualname),
|
||||
("scopeid", &scope)
|
||||
]);
|
||||
@ -294,7 +332,7 @@ impl<'b, W: Write + 'b> Dump for CsvDumper<'b, W> {
|
||||
}
|
||||
|
||||
fn typedef(&mut self, data: TypedefData) {
|
||||
let id = data.id.to_string();
|
||||
let id = data.id.index.as_u32().to_string();
|
||||
let values = make_values_str(&[
|
||||
("id", &id),
|
||||
("qualname", &data.qualname),
|
||||
@ -305,12 +343,16 @@ impl<'b, W: Write + 'b> Dump for CsvDumper<'b, W> {
|
||||
}
|
||||
|
||||
fn use_data(&mut self, data: UseData) {
|
||||
let id = data.id.to_string();
|
||||
let mod_id = data.mod_id.unwrap_or(Id::null()).to_string();
|
||||
let scope = data.scope.to_string();
|
||||
let mod_id = data.mod_id.unwrap_or(null_def_id());
|
||||
|
||||
let id = data.id.index.as_u32().to_string();
|
||||
let ref_id = mod_id.index.as_usize().to_string();
|
||||
let ref_crate = mod_id.krate.to_string();
|
||||
let scope = data.scope.index.as_u32().to_string();
|
||||
let values = make_values_str(&[
|
||||
("id", &id),
|
||||
("mod_id", &mod_id),
|
||||
("refid", &ref_id),
|
||||
("refidcrate", &ref_crate),
|
||||
("name", &data.name),
|
||||
("scopeid", &scope)
|
||||
]);
|
||||
@ -321,8 +363,8 @@ impl<'b, W: Write + 'b> Dump for CsvDumper<'b, W> {
|
||||
fn use_glob(&mut self, data: UseGlobData) {
|
||||
let names = data.names.join(", ");
|
||||
|
||||
let id = data.id.to_string();
|
||||
let scope = data.scope.to_string();
|
||||
let id = data.id.index.as_u32().to_string();
|
||||
let scope = data.scope.index.as_u32().to_string();
|
||||
let values = make_values_str(&[
|
||||
("id", &id),
|
||||
("value", &names),
|
||||
@ -333,8 +375,8 @@ impl<'b, W: Write + 'b> Dump for CsvDumper<'b, W> {
|
||||
}
|
||||
|
||||
fn variable(&mut self, data: VariableData) {
|
||||
let id = data.id.to_string();
|
||||
let scope = data.scope.to_string();
|
||||
let id = data.id.index.as_u32().to_string();
|
||||
let scope = data.scope.index.as_u32().to_string();
|
||||
let values = make_values_str(&[
|
||||
("id", &id),
|
||||
("name", &data.name),
|
||||
@ -348,10 +390,12 @@ impl<'b, W: Write + 'b> Dump for CsvDumper<'b, W> {
|
||||
}
|
||||
|
||||
fn variable_ref(&mut self, data: VariableRefData) {
|
||||
let id = data.ref_id.to_string();
|
||||
let scope = data.scope.to_string();
|
||||
let ref_id = data.ref_id.index.as_usize().to_string();
|
||||
let ref_crate = data.ref_id.krate.to_string();
|
||||
let scope = data.scope.index.as_u32().to_string();
|
||||
let values = make_values_str(&[
|
||||
("id", &id),
|
||||
("refid", &ref_id),
|
||||
("refidcrate", &ref_crate),
|
||||
("qualname", ""),
|
||||
("scopeid", &scope)
|
||||
]);
|
||||
|
@ -8,9 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::hir::def_id::{DefId, DefIndex};
|
||||
use rustc::hir::map::Map;
|
||||
use rustc::ty::TyCtxt;
|
||||
use syntax::ast::{CrateNum, NodeId};
|
||||
@ -24,32 +22,12 @@ pub trait Lower {
|
||||
fn lower(self, tcx: &TyCtxt) -> Self::Target;
|
||||
}
|
||||
|
||||
// We use a newtype to enforce conversion of all NodeIds (which are u32s as well)
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable)]
|
||||
pub struct Id(u32);
|
||||
|
||||
impl Id {
|
||||
pub fn from_def_id(id: DefId) -> Id {
|
||||
Id(id.index.as_u32())
|
||||
}
|
||||
|
||||
// FIXME: this function is called with non-local NodeIds. This means that they
|
||||
// cannot be mapped to a DefId. We should remove those calls. In the meantime,
|
||||
// we return a "null Id" when the NodeId is invalid.
|
||||
pub fn from_node_id(id: NodeId, map: &Map) -> Id {
|
||||
map.opt_local_def_id(id).map(|id| Id(id.index.as_u32()))
|
||||
.unwrap_or(Id::null())
|
||||
}
|
||||
|
||||
pub fn null() -> Id {
|
||||
Id(u32::max_value())
|
||||
}
|
||||
fn make_def_id(id: NodeId, map: &Map) -> DefId {
|
||||
map.opt_local_def_id(id).unwrap_or(null_def_id())
|
||||
}
|
||||
|
||||
impl Display for Id {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
pub fn null_def_id() -> DefId {
|
||||
DefId { krate: u32::max_value(), index: DefIndex::from_u32(u32::max_value()) }
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, RustcEncodable)]
|
||||
@ -106,11 +84,11 @@ impl Lower for data::CratePreludeData {
|
||||
/// Data for enum declarations.
|
||||
#[derive(Clone, Debug, RustcEncodable)]
|
||||
pub struct EnumData {
|
||||
pub id: Id,
|
||||
pub id: DefId,
|
||||
pub value: String,
|
||||
pub qualname: String,
|
||||
pub span: SpanData,
|
||||
pub scope: Id,
|
||||
pub scope: DefId,
|
||||
}
|
||||
|
||||
impl Lower for data::EnumData {
|
||||
@ -118,11 +96,11 @@ impl Lower for data::EnumData {
|
||||
|
||||
fn lower(self, tcx: &TyCtxt) -> EnumData {
|
||||
EnumData {
|
||||
id: Id::from_node_id(self.id, &tcx.map),
|
||||
id: make_def_id(self.id, &tcx.map),
|
||||
value: self.value,
|
||||
qualname: self.qualname,
|
||||
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
||||
scope: Id::from_node_id(self.scope, &tcx.map),
|
||||
scope: make_def_id(self.scope, &tcx.map),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -130,12 +108,12 @@ impl Lower for data::EnumData {
|
||||
/// Data for extern crates.
|
||||
#[derive(Debug, RustcEncodable)]
|
||||
pub struct ExternCrateData {
|
||||
pub id: Id,
|
||||
pub id: DefId,
|
||||
pub name: String,
|
||||
pub crate_num: CrateNum,
|
||||
pub location: String,
|
||||
pub span: SpanData,
|
||||
pub scope: Id,
|
||||
pub scope: DefId,
|
||||
}
|
||||
|
||||
impl Lower for data::ExternCrateData {
|
||||
@ -143,12 +121,12 @@ impl Lower for data::ExternCrateData {
|
||||
|
||||
fn lower(self, tcx: &TyCtxt) -> ExternCrateData {
|
||||
ExternCrateData {
|
||||
id: Id::from_node_id(self.id, &tcx.map),
|
||||
id: make_def_id(self.id, &tcx.map),
|
||||
name: self.name,
|
||||
crate_num: self.crate_num,
|
||||
location: self.location,
|
||||
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
||||
scope: Id::from_node_id(self.scope, &tcx.map),
|
||||
scope: make_def_id(self.scope, &tcx.map),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -157,8 +135,8 @@ impl Lower for data::ExternCrateData {
|
||||
#[derive(Debug, RustcEncodable)]
|
||||
pub struct FunctionCallData {
|
||||
pub span: SpanData,
|
||||
pub scope: Id,
|
||||
pub ref_id: Id,
|
||||
pub scope: DefId,
|
||||
pub ref_id: DefId,
|
||||
}
|
||||
|
||||
impl Lower for data::FunctionCallData {
|
||||
@ -167,8 +145,8 @@ impl Lower for data::FunctionCallData {
|
||||
fn lower(self, tcx: &TyCtxt) -> FunctionCallData {
|
||||
FunctionCallData {
|
||||
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
||||
scope: Id::from_node_id(self.scope, &tcx.map),
|
||||
ref_id: Id::from_def_id(self.ref_id),
|
||||
scope: make_def_id(self.scope, &tcx.map),
|
||||
ref_id: self.ref_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -176,12 +154,12 @@ impl Lower for data::FunctionCallData {
|
||||
/// Data for all kinds of functions and methods.
|
||||
#[derive(Clone, Debug, RustcEncodable)]
|
||||
pub struct FunctionData {
|
||||
pub id: Id,
|
||||
pub id: DefId,
|
||||
pub name: String,
|
||||
pub qualname: String,
|
||||
pub declaration: Option<Id>,
|
||||
pub declaration: Option<DefId>,
|
||||
pub span: SpanData,
|
||||
pub scope: Id,
|
||||
pub scope: DefId,
|
||||
}
|
||||
|
||||
impl Lower for data::FunctionData {
|
||||
@ -189,12 +167,12 @@ impl Lower for data::FunctionData {
|
||||
|
||||
fn lower(self, tcx: &TyCtxt) -> FunctionData {
|
||||
FunctionData {
|
||||
id: Id::from_node_id(self.id, &tcx.map),
|
||||
id: make_def_id(self.id, &tcx.map),
|
||||
name: self.name,
|
||||
qualname: self.qualname,
|
||||
declaration: self.declaration.map(Id::from_def_id),
|
||||
declaration: self.declaration,
|
||||
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
||||
scope: Id::from_node_id(self.scope, &tcx.map),
|
||||
scope: make_def_id(self.scope, &tcx.map),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -203,8 +181,8 @@ impl Lower for data::FunctionData {
|
||||
#[derive(Debug, RustcEncodable)]
|
||||
pub struct FunctionRefData {
|
||||
pub span: SpanData,
|
||||
pub scope: Id,
|
||||
pub ref_id: Id,
|
||||
pub scope: DefId,
|
||||
pub ref_id: DefId,
|
||||
}
|
||||
|
||||
impl Lower for data::FunctionRefData {
|
||||
@ -213,18 +191,18 @@ impl Lower for data::FunctionRefData {
|
||||
fn lower(self, tcx: &TyCtxt) -> FunctionRefData {
|
||||
FunctionRefData {
|
||||
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
||||
scope: Id::from_node_id(self.scope, &tcx.map),
|
||||
ref_id: Id::from_def_id(self.ref_id),
|
||||
scope: make_def_id(self.scope, &tcx.map),
|
||||
ref_id: self.ref_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Debug, RustcEncodable)]
|
||||
pub struct ImplData {
|
||||
pub id: Id,
|
||||
pub id: DefId,
|
||||
pub span: SpanData,
|
||||
pub scope: Id,
|
||||
pub trait_ref: Option<Id>,
|
||||
pub self_ref: Option<Id>,
|
||||
pub scope: DefId,
|
||||
pub trait_ref: Option<DefId>,
|
||||
pub self_ref: Option<DefId>,
|
||||
}
|
||||
|
||||
impl Lower for data::ImplData {
|
||||
@ -232,11 +210,11 @@ impl Lower for data::ImplData {
|
||||
|
||||
fn lower(self, tcx: &TyCtxt) -> ImplData {
|
||||
ImplData {
|
||||
id: Id::from_node_id(self.id, &tcx.map),
|
||||
id: make_def_id(self.id, &tcx.map),
|
||||
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
||||
scope: Id::from_node_id(self.scope, &tcx.map),
|
||||
trait_ref: self.trait_ref.map(Id::from_def_id),
|
||||
self_ref: self.self_ref.map(Id::from_def_id),
|
||||
scope: make_def_id(self.scope, &tcx.map),
|
||||
trait_ref: self.trait_ref,
|
||||
self_ref: self.self_ref,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -244,8 +222,8 @@ impl Lower for data::ImplData {
|
||||
#[derive(Debug, RustcEncodable)]
|
||||
pub struct InheritanceData {
|
||||
pub span: SpanData,
|
||||
pub base_id: Id,
|
||||
pub deriv_id: Id
|
||||
pub base_id: DefId,
|
||||
pub deriv_id: DefId
|
||||
}
|
||||
|
||||
impl Lower for data::InheritanceData {
|
||||
@ -254,8 +232,8 @@ impl Lower for data::InheritanceData {
|
||||
fn lower(self, tcx: &TyCtxt) -> InheritanceData {
|
||||
InheritanceData {
|
||||
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
||||
base_id: Id::from_def_id(self.base_id),
|
||||
deriv_id: Id::from_node_id(self.deriv_id, &tcx.map)
|
||||
base_id: self.base_id,
|
||||
deriv_id: make_def_id(self.deriv_id, &tcx.map)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -289,7 +267,7 @@ pub struct MacroUseData {
|
||||
// Because macro expansion happens before ref-ids are determined,
|
||||
// we use the callee span to reference the associated macro definition.
|
||||
pub callee_span: SpanData,
|
||||
pub scope: Id,
|
||||
pub scope: DefId,
|
||||
pub imported: bool,
|
||||
}
|
||||
|
||||
@ -302,7 +280,7 @@ impl Lower for data::MacroUseData {
|
||||
name: self.name,
|
||||
qualname: self.qualname,
|
||||
callee_span: SpanData::from_span(self.callee_span, tcx.sess.codemap()),
|
||||
scope: Id::from_node_id(self.scope, &tcx.map),
|
||||
scope: make_def_id(self.scope, &tcx.map),
|
||||
imported: self.imported,
|
||||
}
|
||||
}
|
||||
@ -312,9 +290,9 @@ impl Lower for data::MacroUseData {
|
||||
#[derive(Debug, RustcEncodable)]
|
||||
pub struct MethodCallData {
|
||||
pub span: SpanData,
|
||||
pub scope: Id,
|
||||
pub ref_id: Option<Id>,
|
||||
pub decl_id: Option<Id>,
|
||||
pub scope: DefId,
|
||||
pub ref_id: Option<DefId>,
|
||||
pub decl_id: Option<DefId>,
|
||||
}
|
||||
|
||||
impl Lower for data::MethodCallData {
|
||||
@ -323,9 +301,9 @@ impl Lower for data::MethodCallData {
|
||||
fn lower(self, tcx: &TyCtxt) -> MethodCallData {
|
||||
MethodCallData {
|
||||
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
||||
scope: Id::from_node_id(self.scope, &tcx.map),
|
||||
ref_id: self.ref_id.map(Id::from_def_id),
|
||||
decl_id: self.decl_id.map(Id::from_def_id),
|
||||
scope: make_def_id(self.scope, &tcx.map),
|
||||
ref_id: self.ref_id,
|
||||
decl_id: self.decl_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -333,10 +311,10 @@ impl Lower for data::MethodCallData {
|
||||
/// Data for method declarations (methods with a body are treated as functions).
|
||||
#[derive(Clone, Debug, RustcEncodable)]
|
||||
pub struct MethodData {
|
||||
pub id: Id,
|
||||
pub id: DefId,
|
||||
pub qualname: String,
|
||||
pub span: SpanData,
|
||||
pub scope: Id,
|
||||
pub scope: DefId,
|
||||
}
|
||||
|
||||
impl Lower for data::MethodData {
|
||||
@ -345,8 +323,8 @@ impl Lower for data::MethodData {
|
||||
fn lower(self, tcx: &TyCtxt) -> MethodData {
|
||||
MethodData {
|
||||
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
||||
scope: Id::from_node_id(self.scope, &tcx.map),
|
||||
id: Id::from_node_id(self.id, &tcx.map),
|
||||
scope: make_def_id(self.scope, &tcx.map),
|
||||
id: make_def_id(self.id, &tcx.map),
|
||||
qualname: self.qualname,
|
||||
}
|
||||
}
|
||||
@ -355,11 +333,11 @@ impl Lower for data::MethodData {
|
||||
/// Data for modules.
|
||||
#[derive(Debug, RustcEncodable)]
|
||||
pub struct ModData {
|
||||
pub id: Id,
|
||||
pub id: DefId,
|
||||
pub name: String,
|
||||
pub qualname: String,
|
||||
pub span: SpanData,
|
||||
pub scope: Id,
|
||||
pub scope: DefId,
|
||||
pub filename: String,
|
||||
}
|
||||
|
||||
@ -368,11 +346,11 @@ impl Lower for data::ModData {
|
||||
|
||||
fn lower(self, tcx: &TyCtxt) -> ModData {
|
||||
ModData {
|
||||
id: Id::from_node_id(self.id, &tcx.map),
|
||||
id: make_def_id(self.id, &tcx.map),
|
||||
name: self.name,
|
||||
qualname: self.qualname,
|
||||
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
||||
scope: Id::from_node_id(self.scope, &tcx.map),
|
||||
scope: make_def_id(self.scope, &tcx.map),
|
||||
filename: self.filename,
|
||||
}
|
||||
}
|
||||
@ -382,8 +360,8 @@ impl Lower for data::ModData {
|
||||
#[derive(Debug, RustcEncodable)]
|
||||
pub struct ModRefData {
|
||||
pub span: SpanData,
|
||||
pub scope: Id,
|
||||
pub ref_id: Option<Id>,
|
||||
pub scope: DefId,
|
||||
pub ref_id: Option<DefId>,
|
||||
pub qualname: String
|
||||
}
|
||||
|
||||
@ -393,8 +371,8 @@ impl Lower for data::ModRefData {
|
||||
fn lower(self, tcx: &TyCtxt) -> ModRefData {
|
||||
ModRefData {
|
||||
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
||||
scope: Id::from_node_id(self.scope, &tcx.map),
|
||||
ref_id: self.ref_id.map(Id::from_def_id),
|
||||
scope: make_def_id(self.scope, &tcx.map),
|
||||
ref_id: self.ref_id,
|
||||
qualname: self.qualname,
|
||||
}
|
||||
}
|
||||
@ -403,10 +381,10 @@ impl Lower for data::ModRefData {
|
||||
#[derive(Debug, RustcEncodable)]
|
||||
pub struct StructData {
|
||||
pub span: SpanData,
|
||||
pub id: Id,
|
||||
pub ctor_id: Id,
|
||||
pub id: DefId,
|
||||
pub ctor_id: DefId,
|
||||
pub qualname: String,
|
||||
pub scope: Id,
|
||||
pub scope: DefId,
|
||||
pub value: String
|
||||
}
|
||||
|
||||
@ -416,10 +394,10 @@ impl Lower for data::StructData {
|
||||
fn lower(self, tcx: &TyCtxt) -> StructData {
|
||||
StructData {
|
||||
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
||||
id: Id::from_node_id(self.id, &tcx.map),
|
||||
ctor_id: Id::from_node_id(self.ctor_id, &tcx.map),
|
||||
id: make_def_id(self.id, &tcx.map),
|
||||
ctor_id: make_def_id(self.ctor_id, &tcx.map),
|
||||
qualname: self.qualname,
|
||||
scope: Id::from_node_id(self.scope, &tcx.map),
|
||||
scope: make_def_id(self.scope, &tcx.map),
|
||||
value: self.value
|
||||
}
|
||||
}
|
||||
@ -428,11 +406,11 @@ impl Lower for data::StructData {
|
||||
#[derive(Debug, RustcEncodable)]
|
||||
pub struct StructVariantData {
|
||||
pub span: SpanData,
|
||||
pub id: Id,
|
||||
pub id: DefId,
|
||||
pub qualname: String,
|
||||
pub type_value: String,
|
||||
pub value: String,
|
||||
pub scope: Id
|
||||
pub scope: DefId
|
||||
}
|
||||
|
||||
impl Lower for data::StructVariantData {
|
||||
@ -441,11 +419,11 @@ impl Lower for data::StructVariantData {
|
||||
fn lower(self, tcx: &TyCtxt) -> StructVariantData {
|
||||
StructVariantData {
|
||||
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
||||
id: Id::from_node_id(self.id, &tcx.map),
|
||||
id: make_def_id(self.id, &tcx.map),
|
||||
qualname: self.qualname,
|
||||
type_value: self.type_value,
|
||||
value: self.value,
|
||||
scope: Id::from_node_id(self.scope, &tcx.map),
|
||||
scope: make_def_id(self.scope, &tcx.map),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -453,9 +431,9 @@ impl Lower for data::StructVariantData {
|
||||
#[derive(Debug, RustcEncodable)]
|
||||
pub struct TraitData {
|
||||
pub span: SpanData,
|
||||
pub id: Id,
|
||||
pub id: DefId,
|
||||
pub qualname: String,
|
||||
pub scope: Id,
|
||||
pub scope: DefId,
|
||||
pub value: String
|
||||
}
|
||||
|
||||
@ -465,9 +443,9 @@ impl Lower for data::TraitData {
|
||||
fn lower(self, tcx: &TyCtxt) -> TraitData {
|
||||
TraitData {
|
||||
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
||||
id: Id::from_node_id(self.id, &tcx.map),
|
||||
id: make_def_id(self.id, &tcx.map),
|
||||
qualname: self.qualname,
|
||||
scope: Id::from_node_id(self.scope, &tcx.map),
|
||||
scope: make_def_id(self.scope, &tcx.map),
|
||||
value: self.value,
|
||||
}
|
||||
}
|
||||
@ -476,12 +454,12 @@ impl Lower for data::TraitData {
|
||||
#[derive(Debug, RustcEncodable)]
|
||||
pub struct TupleVariantData {
|
||||
pub span: SpanData,
|
||||
pub id: Id,
|
||||
pub id: DefId,
|
||||
pub name: String,
|
||||
pub qualname: String,
|
||||
pub type_value: String,
|
||||
pub value: String,
|
||||
pub scope: Id,
|
||||
pub scope: DefId,
|
||||
}
|
||||
|
||||
impl Lower for data::TupleVariantData {
|
||||
@ -490,12 +468,12 @@ impl Lower for data::TupleVariantData {
|
||||
fn lower(self, tcx: &TyCtxt) -> TupleVariantData {
|
||||
TupleVariantData {
|
||||
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
||||
id: Id::from_node_id(self.id, &tcx.map),
|
||||
id: make_def_id(self.id, &tcx.map),
|
||||
name: self.name,
|
||||
qualname: self.qualname,
|
||||
type_value: self.type_value,
|
||||
value: self.value,
|
||||
scope: Id::from_node_id(self.scope, &tcx.map),
|
||||
scope: make_def_id(self.scope, &tcx.map),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -503,7 +481,7 @@ impl Lower for data::TupleVariantData {
|
||||
/// Data for a typedef.
|
||||
#[derive(Debug, RustcEncodable)]
|
||||
pub struct TypedefData {
|
||||
pub id: Id,
|
||||
pub id: DefId,
|
||||
pub span: SpanData,
|
||||
pub qualname: String,
|
||||
pub value: String,
|
||||
@ -514,7 +492,7 @@ impl Lower for data::TypedefData {
|
||||
|
||||
fn lower(self, tcx: &TyCtxt) -> TypedefData {
|
||||
TypedefData {
|
||||
id: Id::from_node_id(self.id, &tcx.map),
|
||||
id: make_def_id(self.id, &tcx.map),
|
||||
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
||||
qualname: self.qualname,
|
||||
value: self.value,
|
||||
@ -526,8 +504,8 @@ impl Lower for data::TypedefData {
|
||||
#[derive(Clone, Debug, RustcEncodable)]
|
||||
pub struct TypeRefData {
|
||||
pub span: SpanData,
|
||||
pub scope: Id,
|
||||
pub ref_id: Option<Id>,
|
||||
pub scope: DefId,
|
||||
pub ref_id: Option<DefId>,
|
||||
pub qualname: String,
|
||||
}
|
||||
|
||||
@ -537,8 +515,8 @@ impl Lower for data::TypeRefData {
|
||||
fn lower(self, tcx: &TyCtxt) -> TypeRefData {
|
||||
TypeRefData {
|
||||
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
||||
scope: Id::from_node_id(self.scope, &tcx.map),
|
||||
ref_id: self.ref_id.map(Id::from_def_id),
|
||||
scope: make_def_id(self.scope, &tcx.map),
|
||||
ref_id: self.ref_id,
|
||||
qualname: self.qualname,
|
||||
}
|
||||
}
|
||||
@ -546,11 +524,11 @@ impl Lower for data::TypeRefData {
|
||||
|
||||
#[derive(Debug, RustcEncodable)]
|
||||
pub struct UseData {
|
||||
pub id: Id,
|
||||
pub id: DefId,
|
||||
pub span: SpanData,
|
||||
pub name: String,
|
||||
pub mod_id: Option<Id>,
|
||||
pub scope: Id
|
||||
pub mod_id: Option<DefId>,
|
||||
pub scope: DefId
|
||||
}
|
||||
|
||||
impl Lower for data::UseData {
|
||||
@ -558,21 +536,21 @@ impl Lower for data::UseData {
|
||||
|
||||
fn lower(self, tcx: &TyCtxt) -> UseData {
|
||||
UseData {
|
||||
id: Id::from_node_id(self.id, &tcx.map),
|
||||
id: make_def_id(self.id, &tcx.map),
|
||||
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
||||
name: self.name,
|
||||
mod_id: self.mod_id.map(Id::from_def_id),
|
||||
scope: Id::from_node_id(self.scope, &tcx.map),
|
||||
mod_id: self.mod_id,
|
||||
scope: make_def_id(self.scope, &tcx.map),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, RustcEncodable)]
|
||||
pub struct UseGlobData {
|
||||
pub id: Id,
|
||||
pub id: DefId,
|
||||
pub span: SpanData,
|
||||
pub names: Vec<String>,
|
||||
pub scope: Id
|
||||
pub scope: DefId
|
||||
}
|
||||
|
||||
impl Lower for data::UseGlobData {
|
||||
@ -580,10 +558,10 @@ impl Lower for data::UseGlobData {
|
||||
|
||||
fn lower(self, tcx: &TyCtxt) -> UseGlobData {
|
||||
UseGlobData {
|
||||
id: Id::from_node_id(self.id, &tcx.map),
|
||||
id: make_def_id(self.id, &tcx.map),
|
||||
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
||||
names: self.names,
|
||||
scope: Id::from_node_id(self.scope, &tcx.map),
|
||||
scope: make_def_id(self.scope, &tcx.map),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -591,11 +569,11 @@ impl Lower for data::UseGlobData {
|
||||
/// Data for local and global variables (consts and statics).
|
||||
#[derive(Debug, RustcEncodable)]
|
||||
pub struct VariableData {
|
||||
pub id: Id,
|
||||
pub id: DefId,
|
||||
pub name: String,
|
||||
pub qualname: String,
|
||||
pub span: SpanData,
|
||||
pub scope: Id,
|
||||
pub scope: DefId,
|
||||
pub value: String,
|
||||
pub type_value: String,
|
||||
}
|
||||
@ -605,11 +583,11 @@ impl Lower for data::VariableData {
|
||||
|
||||
fn lower(self, tcx: &TyCtxt) -> VariableData {
|
||||
VariableData {
|
||||
id: Id::from_node_id(self.id, &tcx.map),
|
||||
id: make_def_id(self.id, &tcx.map),
|
||||
name: self.name,
|
||||
qualname: self.qualname,
|
||||
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
||||
scope: Id::from_node_id(self.scope, &tcx.map),
|
||||
scope: make_def_id(self.scope, &tcx.map),
|
||||
value: self.value,
|
||||
type_value: self.type_value,
|
||||
}
|
||||
@ -622,8 +600,8 @@ impl Lower for data::VariableData {
|
||||
pub struct VariableRefData {
|
||||
pub name: String,
|
||||
pub span: SpanData,
|
||||
pub scope: Id,
|
||||
pub ref_id: Id,
|
||||
pub scope: DefId,
|
||||
pub ref_id: DefId,
|
||||
}
|
||||
|
||||
impl Lower for data::VariableRefData {
|
||||
@ -633,8 +611,8 @@ impl Lower for data::VariableRefData {
|
||||
VariableRefData {
|
||||
name: self.name,
|
||||
span: SpanData::from_span(self.span, tcx.sess.codemap()),
|
||||
scope: Id::from_node_id(self.scope, &tcx.map),
|
||||
ref_id: Id::from_def_id(self.ref_id),
|
||||
scope: make_def_id(self.scope, &tcx.map),
|
||||
ref_id: self.ref_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
match *source {
|
||||
CandidateSource::ImplSource(impl_did) => {
|
||||
// Provide the best span we can. Use the item, if local to crate, else
|
||||
// the impl, if local to crate (item may be defaulted), else the call site.
|
||||
// the impl, if local to crate (item may be defaulted), else nothing.
|
||||
let item = impl_item(fcx.tcx(), impl_did, item_name)
|
||||
.or_else(|| {
|
||||
trait_item(
|
||||
@ -242,8 +242,9 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
item_name
|
||||
)
|
||||
}).unwrap();
|
||||
let impl_span = fcx.tcx().map.def_id_span(impl_did, span);
|
||||
let item_span = fcx.tcx().map.def_id_span(item.def_id(), impl_span);
|
||||
let note_span = fcx.tcx().map.span_if_local(item.def_id()).or_else(|| {
|
||||
fcx.tcx().map.span_if_local(impl_did)
|
||||
});
|
||||
|
||||
let impl_ty = check::impl_self_ty(fcx, span, impl_did).ty;
|
||||
|
||||
@ -255,11 +256,17 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
}
|
||||
};
|
||||
|
||||
span_note!(err, item_span,
|
||||
"candidate #{} is defined in an impl{} for the type `{}`",
|
||||
idx + 1,
|
||||
insertion,
|
||||
impl_ty);
|
||||
let note_str = format!("candidate #{} is defined in an impl{} \
|
||||
for the type `{}`",
|
||||
idx + 1,
|
||||
insertion,
|
||||
impl_ty);
|
||||
if let Some(note_span) = note_span {
|
||||
// We have a span pointing to the method. Show note with snippet.
|
||||
err.span_note(note_span, ¬e_str);
|
||||
} else {
|
||||
err.note(¬e_str);
|
||||
}
|
||||
}
|
||||
CandidateSource::TraitSource(trait_did) => {
|
||||
let item = trait_item(fcx.tcx(), trait_did, item_name).unwrap();
|
||||
|
@ -20,6 +20,7 @@ use rustc::hir;
|
||||
use rustc::middle::cstore::{self, CrateStore};
|
||||
use rustc::hir::def::Def;
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::hir::print as pprust;
|
||||
use rustc::ty::{self, TyCtxt};
|
||||
use rustc::ty::subst;
|
||||
use rustc::middle::stability;
|
||||
@ -30,7 +31,7 @@ use core::{DocContext, DocAccessLevels};
|
||||
use doctree;
|
||||
use clean::{self, GetDefId};
|
||||
|
||||
use super::{Clean, ToSource};
|
||||
use super::Clean;
|
||||
|
||||
/// Attempt to inline the definition of a local node id into this AST.
|
||||
///
|
||||
@ -333,8 +334,8 @@ pub fn build_impl(cx: &DocContext,
|
||||
let did = assoc_const.def_id;
|
||||
let type_scheme = tcx.lookup_item_type(did);
|
||||
let default = if assoc_const.has_value {
|
||||
Some(lookup_const_by_id(tcx, did, None)
|
||||
.unwrap().0.span.to_src(cx))
|
||||
Some(pprust::expr_to_string(
|
||||
lookup_const_by_id(tcx, did, None).unwrap().0))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@ -479,8 +480,6 @@ fn build_module(cx: &DocContext, tcx: &TyCtxt,
|
||||
|
||||
fn build_const(cx: &DocContext, tcx: &TyCtxt,
|
||||
did: DefId) -> clean::Constant {
|
||||
use rustc::hir::print as pprust;
|
||||
|
||||
let (expr, ty) = lookup_const_by_id(tcx, did, None).unwrap_or_else(|| {
|
||||
panic!("expected lookup_const_by_id to succeed for {:?}", did);
|
||||
});
|
||||
|
@ -39,6 +39,7 @@ use rustc::middle::cstore::{self, CrateStore};
|
||||
use rustc::middle::privacy::AccessLevels;
|
||||
use rustc::hir::def::Def;
|
||||
use rustc::hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX};
|
||||
use rustc::hir::print as pprust;
|
||||
use rustc::ty::subst::{self, ParamSpace, VecPerParamSpace};
|
||||
use rustc::ty;
|
||||
use rustc::middle::stability;
|
||||
@ -1285,8 +1286,7 @@ impl Clean<Item> for hir::TraitItem {
|
||||
let inner = match self.node {
|
||||
hir::ConstTraitItem(ref ty, ref default) => {
|
||||
AssociatedConstItem(ty.clean(cx),
|
||||
default.as_ref().map(|expr|
|
||||
expr.span.to_src(cx)))
|
||||
default.as_ref().map(|e| pprust::expr_to_string(&e)))
|
||||
}
|
||||
hir::MethodTraitItem(ref sig, Some(_)) => {
|
||||
MethodItem(sig.clean(cx))
|
||||
@ -1316,7 +1316,7 @@ impl Clean<Item> for hir::ImplItem {
|
||||
let inner = match self.node {
|
||||
hir::ImplItemKind::Const(ref ty, ref expr) => {
|
||||
AssociatedConstItem(ty.clean(cx),
|
||||
Some(expr.span.to_src(cx)))
|
||||
Some(pprust::expr_to_string(expr)))
|
||||
}
|
||||
hir::ImplItemKind::Method(ref sig, _) => {
|
||||
MethodItem(sig.clean(cx))
|
||||
@ -1635,8 +1635,8 @@ impl Clean<Type> for hir::Ty {
|
||||
BorrowedRef {lifetime: l.clean(cx), mutability: m.mutbl.clean(cx),
|
||||
type_: box m.ty.clean(cx)},
|
||||
TyVec(ref ty) => Vector(box ty.clean(cx)),
|
||||
TyFixedLengthVec(ref ty, ref e) => FixedVector(box ty.clean(cx),
|
||||
e.span.to_src(cx)),
|
||||
TyFixedLengthVec(ref ty, ref e) =>
|
||||
FixedVector(box ty.clean(cx), pprust::expr_to_string(e)),
|
||||
TyTup(ref tys) => Tuple(tys.clean(cx)),
|
||||
TyPath(None, ref p) => {
|
||||
resolve_type(cx, p.clean(cx), self.id)
|
||||
@ -2185,7 +2185,7 @@ impl Clean<Item> for doctree::Static {
|
||||
inner: StaticItem(Static {
|
||||
type_: self.type_.clean(cx),
|
||||
mutability: self.mutability.clean(cx),
|
||||
expr: self.expr.span.to_src(cx),
|
||||
expr: pprust::expr_to_string(&self.expr),
|
||||
}),
|
||||
}
|
||||
}
|
||||
@ -2209,7 +2209,7 @@ impl Clean<Item> for doctree::Constant {
|
||||
deprecation: self.depr.clean(cx),
|
||||
inner: ConstantItem(Constant {
|
||||
type_: self.type_.clean(cx),
|
||||
expr: self.expr.span.to_src(cx),
|
||||
expr: pprust::expr_to_string(&self.expr),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ use rustc::hir;
|
||||
use clean;
|
||||
use core::DocAccessLevels;
|
||||
use html::item_type::ItemType;
|
||||
use html::escape::Escape;
|
||||
use html::render;
|
||||
use html::render::{cache, CURRENT_LOCATION_KEY};
|
||||
|
||||
@ -496,7 +497,7 @@ impl fmt::Display for clean::Type {
|
||||
primitive_link(f, clean::PrimitiveType::Array, "[")?;
|
||||
write!(f, "{}", t)?;
|
||||
primitive_link(f, clean::PrimitiveType::Array,
|
||||
&format!("; {}]", *s))
|
||||
&format!("; {}]", Escape(s)))
|
||||
}
|
||||
clean::Bottom => f.write_str("!"),
|
||||
clean::RawPointer(m, ref t) => {
|
||||
|
@ -1866,7 +1866,7 @@ impl<'a> fmt::Display for Initializer<'a> {
|
||||
let Initializer(s) = *self;
|
||||
if s.is_empty() { return Ok(()); }
|
||||
write!(f, "<code> = </code>")?;
|
||||
write!(f, "<code>{}</code>", s)
|
||||
write!(f, "<code>{}</code>", Escape(s))
|
||||
}
|
||||
}
|
||||
|
||||
@ -2106,7 +2106,7 @@ fn assoc_const(w: &mut fmt::Formatter,
|
||||
|
||||
write!(w, ": {}", ty)?;
|
||||
if let Some(default) = default {
|
||||
write!(w, " = {}", default)?;
|
||||
write!(w, " = {}", Escape(default))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -326,6 +326,22 @@ impl fmt::Debug for CStr {
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "cstr_default", since = "1.10.0")]
|
||||
impl<'a> Default for &'a CStr {
|
||||
fn default() -> &'a CStr {
|
||||
static SLICE: &'static [c_char] = &[0];
|
||||
unsafe { CStr::from_ptr(SLICE.as_ptr()) }
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "cstr_default", since = "1.10.0")]
|
||||
impl Default for CString {
|
||||
fn default() -> CString {
|
||||
let a: &CStr = Default::default();
|
||||
a.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "cstr_borrow", since = "1.3.0")]
|
||||
impl Borrow<CStr> for CString {
|
||||
fn borrow(&self) -> &CStr { self }
|
||||
|
@ -16,6 +16,22 @@ use errors::DiagnosticBuilder;
|
||||
use super::StringReader;
|
||||
|
||||
const UNICODE_ARRAY: &'static [(char, &'static str, char)] = &[
|
||||
(' ', "No-Break Space", ' '),
|
||||
(' ', "Ogham Space Mark", ' '),
|
||||
(' ', "En Quad", ' '),
|
||||
(' ', "Em Quad", ' '),
|
||||
(' ', "En Space", ' '),
|
||||
(' ', "Em Space", ' '),
|
||||
(' ', "Three-Per-Em Space", ' '),
|
||||
(' ', "Four-Per-Em Space", ' '),
|
||||
(' ', "Six-Per-Em Space", ' '),
|
||||
(' ', "Figure Space", ' '),
|
||||
(' ', "Punctuation Space", ' '),
|
||||
(' ', "Thin Space", ' '),
|
||||
(' ', "Hair Space", ' '),
|
||||
(' ', "Narrow No-Break Space", ' '),
|
||||
(' ', "Medium Mathematical Space", ' '),
|
||||
(' ', "Ideographic Space", ' '),
|
||||
('ߺ', "Nko Lajanyalan", '_'),
|
||||
('﹍', "Dashed Low Line", '_'),
|
||||
('﹎', "Centreline Low Line", '_'),
|
||||
@ -24,14 +40,18 @@ const UNICODE_ARRAY: &'static [(char, &'static str, char)] = &[
|
||||
('‑', "Non-Breaking Hyphen", '-'),
|
||||
('‒', "Figure Dash", '-'),
|
||||
('–', "En Dash", '-'),
|
||||
('—', "Em Dash", '-'),
|
||||
('﹘', "Small Em Dash", '-'),
|
||||
('⁃', "Hyphen Bullet", '-'),
|
||||
('˗', "Modifier Letter Minus Sign", '-'),
|
||||
('−', "Minus Sign", '-'),
|
||||
('ー', "Katakana-Hiragana Prolonged Sound Mark", '-'),
|
||||
('٫', "Arabic Decimal Separator", ','),
|
||||
('‚', "Single Low-9 Quotation Mark", ','),
|
||||
('ꓹ', "Lisu Letter Tone Na Po", ','),
|
||||
(',', "Fullwidth Comma", ','),
|
||||
(';', "Greek Question Mark", ';'),
|
||||
(';', "Fullwidth Semicolon", ';'),
|
||||
('ः', "Devanagari Sign Visarga", ':'),
|
||||
('ઃ', "Gujarati Sign Visarga", ':'),
|
||||
(':', "Fullwidth Colon", ':'),
|
||||
@ -53,6 +73,7 @@ const UNICODE_ARRAY: &'static [(char, &'static str, char)] = &[
|
||||
('ʔ', "Latin Letter Glottal Stop", '?'),
|
||||
('ॽ', "Devanagari Letter Glottal Stop", '?'),
|
||||
('Ꭾ', "Cherokee Letter He", '?'),
|
||||
('?', "Fullwidth Question Mark", '?'),
|
||||
('𝅭', "Musical Symbol Combining Augmentation Dot", '.'),
|
||||
('․', "One Dot Leader", '.'),
|
||||
('۔', "Arabic Full Stop", '.'),
|
||||
@ -60,9 +81,12 @@ const UNICODE_ARRAY: &'static [(char, &'static str, char)] = &[
|
||||
('܂', "Syriac Sublinear Full Stop", '.'),
|
||||
('꘎', "Vai Full Stop", '.'),
|
||||
('𐩐', "Kharoshthi Punctuation Dot", '.'),
|
||||
('·', "Middle Dot", '.'),
|
||||
('٠', "Arabic-Indic Digit Zero", '.'),
|
||||
('۰', "Extended Arabic-Indic Digit Zero", '.'),
|
||||
('ꓸ', "Lisu Letter Tone Mya Ti", '.'),
|
||||
('。', "Ideographic Full Stop", '.'),
|
||||
('・', "Katakana Middle Dot", '.'),
|
||||
('՝', "Armenian Comma", '\''),
|
||||
(''', "Fullwidth Apostrophe", '\''),
|
||||
('‘', "Left Single Quotation Mark", '\''),
|
||||
@ -108,16 +132,30 @@ const UNICODE_ARRAY: &'static [(char, &'static str, char)] = &[
|
||||
('ײ', "Hebrew Ligature Yiddish Double Yod", '"'),
|
||||
('❞', "Heavy Double Comma Quotation Mark Ornament", '"'),
|
||||
('❝', "Heavy Double Turned Comma Quotation Mark Ornament", '"'),
|
||||
('[', "Fullwidth Left Square Bracket", '('),
|
||||
('❨', "Medium Left Parenthesis Ornament", '('),
|
||||
('❲', "Light Left Tortoise Shell Bracket Ornament", '('),
|
||||
('〔', "Left Tortoise Shell Bracket", '('),
|
||||
('﴾', "Ornate Left Parenthesis", '('),
|
||||
(']', "Fullwidth Right Square Bracket", ')'),
|
||||
('(', "Fullwidth Left Parenthesis", '('),
|
||||
('❩', "Medium Right Parenthesis Ornament", ')'),
|
||||
('❳', "Light Right Tortoise Shell Bracket Ornament", ')'),
|
||||
('〕', "Right Tortoise Shell Bracket", ')'),
|
||||
('﴿', "Ornate Right Parenthesis", ')'),
|
||||
(')', "Fullwidth Right Parenthesis", ')'),
|
||||
('[', "Fullwidth Left Square Bracket", '['),
|
||||
('❲', "Light Left Tortoise Shell Bracket Ornament", '['),
|
||||
('「', "Left Corner Bracket", '['),
|
||||
('『', "Left White Corner Bracket", '['),
|
||||
('【', "Left Black Lenticular Bracket", '['),
|
||||
('〔', "Left Tortoise Shell Bracket", '['),
|
||||
('〖', "Left White Lenticular Bracket", '['),
|
||||
('〘', "Left White Tortoise Shell Bracket", '['),
|
||||
('〚', "Left White Square Bracket", '['),
|
||||
(']', "Fullwidth Right Square Bracket", ']'),
|
||||
('❳', "Light Right Tortoise Shell Bracket Ornament", ']'),
|
||||
('」', "Right Corner Bracket", ']'),
|
||||
('』', "Right White Corner Bracket", ']'),
|
||||
('】', "Right Black Lenticular Bracket", ']'),
|
||||
('〕', "Right Tortoise Shell Bracket", ']'),
|
||||
('〗', "Right White Lenticular Bracket", ']'),
|
||||
('〙', "Right White Tortoise Shell Bracket", ']'),
|
||||
('〛', "Right White Square Bracket", ']'),
|
||||
('❴', "Medium Left Curly Bracket Ornament", '{'),
|
||||
('❵', "Medium Right Curly Bracket Ornament", '}'),
|
||||
('⁎', "Low Asterisk", '*'),
|
||||
@ -140,6 +178,8 @@ const UNICODE_ARRAY: &'static [(char, &'static str, char)] = &[
|
||||
('⟍', "Mathematical Falling Diagonal", '\\'),
|
||||
('⧵', "Reverse Solidus Operator", '\\'),
|
||||
('⧹', "Big Reverse Solidus", '\\'),
|
||||
('、', "Ideographic Comma", '\\'),
|
||||
('ヽ', "Katakana Iteration Mark", '\\'),
|
||||
('㇔', "Cjk Stroke D", '\\'),
|
||||
('丶', "Cjk Unified Ideograph-4E36", '\\'),
|
||||
('⼂', "Kangxi Radical Dot", '\\'),
|
||||
@ -148,15 +188,20 @@ const UNICODE_ARRAY: &'static [(char, &'static str, char)] = &[
|
||||
('‹', "Single Left-Pointing Angle Quotation Mark", '<'),
|
||||
('❮', "Heavy Left-Pointing Angle Quotation Mark Ornament", '<'),
|
||||
('˂', "Modifier Letter Left Arrowhead", '<'),
|
||||
('〈', "Left Angle Bracket", '<'),
|
||||
('《', "Left Double Angle Bracket", '<'),
|
||||
('꓿', "Lisu Punctuation Full Stop", '='),
|
||||
('›', "Single Right-Pointing Angle Quotation Mark", '>'),
|
||||
('❯', "Heavy Right-Pointing Angle Quotation Mark Ornament", '>'),
|
||||
('˃', "Modifier Letter Right Arrowhead", '>'),
|
||||
('〉', "Right Angle Bracket", '>'),
|
||||
('》', "Right Double Angle Bracket", '>'),
|
||||
('Ⲻ', "Coptic Capital Letter Dialect-P Ni", '-'),
|
||||
('Ɂ', "Latin Capital Letter Glottal Stop", '?'),
|
||||
('Ⳇ', "Coptic Capital Letter Old Coptic Esh", '/'), ];
|
||||
|
||||
const ASCII_ARRAY: &'static [(char, &'static str)] = &[
|
||||
(' ', "Space"),
|
||||
('_', "Underscore"),
|
||||
('-', "Minus/Hyphen"),
|
||||
(',', "Comma"),
|
||||
@ -169,6 +214,8 @@ const ASCII_ARRAY: &'static [(char, &'static str)] = &[
|
||||
('"', "Quotation Mark"),
|
||||
('(', "Left Parenthesis"),
|
||||
(')', "Right Parenthesis"),
|
||||
('[', "Left Square Bracket"),
|
||||
(']', "Right Square Bracket"),
|
||||
('{', "Left Curly Brace"),
|
||||
('}', "Right Curly Brace"),
|
||||
('*', "Asterisk"),
|
||||
|
@ -4419,11 +4419,7 @@ impl<'a> Parser<'a> {
|
||||
p.forbid_lifetime()?;
|
||||
let lo = p.span.lo;
|
||||
let ident = p.parse_ident()?;
|
||||
let found_eq = p.eat(&token::Eq);
|
||||
if !found_eq {
|
||||
let span = p.span;
|
||||
p.span_warn(span, "whoops, no =?");
|
||||
}
|
||||
p.expect(&token::Eq)?;
|
||||
let ty = p.parse_ty()?;
|
||||
let hi = ty.span.hi;
|
||||
let span = mk_sp(lo, hi);
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use std::fmt;
|
||||
use std::{i8, i16, i32, i64, isize};
|
||||
use std::{u8, u16, u32, u64, usize};
|
||||
|
||||
@ -26,10 +25,15 @@ const A_I8_T
|
||||
//~| found `u8` [E0250]
|
||||
= [0; (i8::MAX as usize) + 1];
|
||||
|
||||
fn main() {
|
||||
foo(&A_I8_T[..]);
|
||||
}
|
||||
|
||||
fn foo<T:fmt::Debug>(x: T) {
|
||||
println!("{:?}", x);
|
||||
}
|
||||
const A_CHAR_USIZE
|
||||
: [u32; 5u8 as char as usize]
|
||||
= [0; 5];
|
||||
|
||||
|
||||
const A_BAD_CHAR_USIZE
|
||||
: [u32; 5i8 as char as usize]
|
||||
//~^ ERROR only `u8` can be cast as `char`, not `i8`
|
||||
= [0; 5];
|
||||
|
||||
fn main() {}
|
||||
|
29
src/test/compile-fail/issue-23716.rs
Normal file
29
src/test/compile-fail/issue-23716.rs
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
static foo: i32 = 0;
|
||||
//~^ NOTE static variable defined here
|
||||
|
||||
fn bar(foo: i32) {}
|
||||
//~^ ERROR static variables cannot be referenced in a pattern, use a `const` instead
|
||||
|
||||
mod submod {
|
||||
pub static answer: i32 = 42;
|
||||
//~^ NOTE static variable defined here
|
||||
}
|
||||
|
||||
use self::submod::answer;
|
||||
//~^ NOTE static variable imported here
|
||||
|
||||
fn question(answer: i32) {}
|
||||
//~^ ERROR static variables cannot be referenced in a pattern, use a `const` instead
|
||||
|
||||
fn main() {
|
||||
}
|
17
src/test/parse-fail/issue-32214.rs
Normal file
17
src/test/parse-fail/issue-32214.rs
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
// compile-flags: -Z parse-only -Z continue-parse-after-error
|
||||
|
||||
pub fn test<W, I: Iterator<Item=(), W> >() {
|
||||
//~^ ERROR expected `=`, found `>`
|
||||
}
|
||||
|
||||
fn main() { }
|
19
src/test/run-pass/const-err.rs
Normal file
19
src/test/run-pass/const-err.rs
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
// check for const_err regressions
|
||||
|
||||
#![deny(const_err)]
|
||||
|
||||
|
||||
fn main() {
|
||||
let _ = ((-1 as i8) << 8 - 1) as f32;
|
||||
let _ = 0u8 as char;
|
||||
}
|
15
src/test/rustdoc/escape-rust-expr.rs
Normal file
15
src/test/rustdoc/escape-rust-expr.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
// Test that we HTML-escape Rust expressions, where HTML special chars
|
||||
// can occur, and we know it's definitely not markup.
|
||||
|
||||
// @has escape_rust_expr/constant.CONST_S.html '//pre[@class="rust const"]' '"<script>"'
|
||||
pub const CONST_S: &'static str = "<script>";
|
46
src/test/rustdoc/issue-33302.rs
Normal file
46
src/test/rustdoc/issue-33302.rs
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
// Ensure constant and array length values are not taken from source
|
||||
// code, which wreaks havoc with macros.
|
||||
|
||||
#![feature(associated_consts)]
|
||||
|
||||
macro_rules! make {
|
||||
($n:expr) => {
|
||||
pub struct S;
|
||||
|
||||
// @has issue_33302/constant.CST.html \
|
||||
// '//pre[@class="rust const"]' 'pub const CST: i32 = 4 * 4'
|
||||
pub const CST: i32 = ($n * $n);
|
||||
// @has issue_33302/static.ST.html \
|
||||
// '//pre[@class="rust static"]' 'pub static ST: i32 = 4 * 4'
|
||||
pub static ST: i32 = ($n * $n);
|
||||
|
||||
pub trait T<X> {
|
||||
fn ignore(_: &X) {}
|
||||
const C: X;
|
||||
// @has issue_33302/trait.T.html \
|
||||
// '//*[@class="rust trait"]' 'const D: i32 = 4 * 4;'
|
||||
// @has - '//*[@id="associatedconstant.D"]' 'const D: i32 = 4 * 4'
|
||||
const D: i32 = ($n * $n);
|
||||
}
|
||||
|
||||
// @has issue_33302/struct.S.html \
|
||||
// '//h3[@class="impl"]' 'impl T<[i32; 4 * 4]> for S'
|
||||
// @has - '//*[@id="associatedconstant.C"]' 'const C: [i32; 4 * 4] = [0; 4 * 4]'
|
||||
// @has - '//*[@id="associatedconstant.D"]' 'const D: i32 = 4 * 4'
|
||||
impl T<[i32; ($n * $n)]> for S {
|
||||
const C: [i32; ($n * $n)] = [0; ($n * $n)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
make!(4);
|
@ -2063,6 +2063,11 @@ fn run_incremental_test(config: &Config, props: &TestProps, testpaths: &TestPath
|
||||
}
|
||||
|
||||
fn run_rmake_test(config: &Config, _props: &TestProps, testpaths: &TestPaths) {
|
||||
// FIXME(#11094): we should fix these tests
|
||||
if config.host != config.target {
|
||||
return
|
||||
}
|
||||
|
||||
let cwd = env::current_dir().unwrap();
|
||||
let src_root = config.src_base.parent().unwrap().parent().unwrap()
|
||||
.parent().unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user