2014-12-02 08:20:48 -06:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
//! Common API for all rust-book subcommands.
|
|
|
|
|
|
|
|
use error::CliResult;
|
|
|
|
use error::CommandResult;
|
|
|
|
use term::Term;
|
|
|
|
|
|
|
|
use help;
|
|
|
|
use build;
|
|
|
|
use serve;
|
|
|
|
use test;
|
|
|
|
|
|
|
|
pub trait Subcommand {
|
|
|
|
/// Mutate the subcommand by parsing its arguments.
|
|
|
|
///
|
|
|
|
/// Returns `Err` on a parsing error.
|
|
|
|
fn parse_args(&mut self, args: &[String]) -> CliResult<()>;
|
|
|
|
/// Print the CLI usage information.
|
|
|
|
fn usage(&self);
|
|
|
|
/// Actually execute the subcommand.
|
|
|
|
fn execute(&mut self, term: &mut Term) -> CommandResult<()>;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Create a Subcommand object based on its name.
|
|
|
|
pub fn parse_name(name: &str) -> Option<Box<Subcommand>> {
|
Add trivial cast lints.
This permits all coercions to be performed in casts, but adds lints to warn in those cases.
Part of this patch moves cast checking to a later stage of type checking. We acquire obligations to check casts as part of type checking where we previously checked them. Once we have type checked a function or module, then we check any cast obligations which have been acquired. That means we have more type information available to check casts (this was crucial to making coercions work properly in place of some casts), but it means that casts cannot feed input into type inference.
[breaking change]
* Adds two new lints for trivial casts and trivial numeric casts, these are warn by default, but can cause errors if you build with warnings as errors. Previously, trivial numeric casts and casts to trait objects were allowed.
* The unused casts lint has gone.
* Interactions between casting and type inference have changed in subtle ways. Two ways this might manifest are:
- You may need to 'direct' casts more with extra type information, for example, in some cases where `foo as _ as T` succeeded, you may now need to specify the type for `_`
- Casts do not influence inference of integer types. E.g., the following used to type check:
```
let x = 42;
let y = &x as *const u32;
```
Because the cast would inform inference that `x` must have type `u32`. This no longer applies and the compiler will fallback to `i32` for `x` and thus there will be a type error in the cast. The solution is to add more type information:
```
let x: u32 = 42;
let y = &x as *const u32;
```
2015-03-19 23:15:27 -05:00
|
|
|
let cmds: [fn(&str) -> Option<Box<Subcommand>>; 4] = [help::parse_cmd,
|
|
|
|
build::parse_cmd,
|
|
|
|
serve::parse_cmd,
|
|
|
|
test::parse_cmd];
|
2015-06-10 11:22:20 -05:00
|
|
|
for parser in &cmds {
|
2014-12-02 08:20:48 -06:00
|
|
|
let parsed = (*parser)(name);
|
|
|
|
if parsed.is_some() { return parsed }
|
|
|
|
}
|
|
|
|
None
|
|
|
|
}
|