Auto merge of #55095 - Manishearth:rollup, r=Manishearth

Rollup of 11 pull requests

Successful merges:

 - #54820 (Closes #54538: `unused_patterns` lint)
 - #54963 (Cleanup rustc/session)
 - #54991 (add test for #23189)
 - #55025 (Add missing lifetime fragment specifier to error message.)
 - #55047 (doc: make core::fmt::Error example more simple)
 - #55048 (Don't collect to vectors where unnecessary)
 - #55060 (clarify pointer add/sub function safety concerns)
 - #55062 (Make EvalContext::step public again)
 - #55066 (Fix incorrect link in println! documentation)
 - #55081 (Deduplicate tests)
 - #55088 (Update rustc documentation link)

Failed merges:

r? @ghost
This commit is contained in:
bors
2018-10-15 19:50:50 +00:00
27 changed files with 326 additions and 374 deletions

View File

@@ -646,7 +646,7 @@ are:
* Don't be afraid to ask! The Rust community is friendly and helpful.
[rustc guide]: https://rust-lang-nursery.github.io/rustc-guide/about-this-guide.html
[gdfrustc]: http://manishearth.github.io/rust-internals-docs/rustc/
[gdfrustc]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc/
[gsearchdocs]: https://www.google.com/search?q=site:doc.rust-lang.org+your+query+here
[rif]: http://internals.rust-lang.org
[rr]: https://doc.rust-lang.org/book/README.html

View File

@@ -96,9 +96,8 @@ pub type Result = result::Result<(), Error>;
/// use std::fmt::{self, write};
///
/// let mut output = String::new();
/// match write(&mut output, format_args!("Hello {}!", "world")) {
/// Err(fmt::Error) => panic!("An error occurred"),
/// _ => (),
/// if let Err(fmt::Error) = write(&mut output, format_args!("Hello {}!", "world")) {
/// panic!("An error occurred");
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]

View File

@@ -1037,7 +1037,7 @@ impl<T: ?Sized> *const T {
/// Behavior:
///
/// * Both the starting and resulting pointer must be either in bounds or one
/// byte past the end of *the same* allocated object.
/// byte past the end of the same allocated object.
///
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
///
@@ -1255,7 +1255,7 @@ impl<T: ?Sized> *const T {
/// Behavior:
///
/// * Both the starting and resulting pointer must be either in bounds or one
/// byte past the end of an allocated object.
/// byte past the end of the same allocated object.
///
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
///
@@ -1312,7 +1312,7 @@ impl<T: ?Sized> *const T {
/// Behavior:
///
/// * Both the starting and resulting pointer must be either in bounds or one
/// byte past the end of an allocated object.
/// byte past the end of the same allocated object.
///
/// * The computed offset cannot exceed `isize::MAX` **bytes**.
///
@@ -1657,7 +1657,7 @@ impl<T: ?Sized> *mut T {
/// Behavior:
///
/// * Both the starting and resulting pointer must be either in bounds or one
/// byte past the end of *the same* allocated object.
/// byte past the end of the same allocated object.
///
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
///
@@ -1893,7 +1893,7 @@ impl<T: ?Sized> *mut T {
/// Behavior:
///
/// * Both the starting and resulting pointer must be either in bounds or one
/// byte past the end of an allocated object.
/// byte past the end of the same allocated object.
///
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
///
@@ -1950,7 +1950,7 @@ impl<T: ?Sized> *mut T {
/// Behavior:
///
/// * Both the starting and resulting pointer must be either in bounds or one
/// byte past the end of an allocated object.
/// byte past the end of the same allocated object.
///
/// * The computed offset cannot exceed `isize::MAX` **bytes**.
///

View File

@@ -60,7 +60,6 @@ use util::nodemap::{DefIdMap, NodeMap};
use std::collections::BTreeMap;
use std::fmt::Debug;
use std::iter;
use std::mem;
use smallvec::SmallVec;
use syntax::attr;
@@ -3888,9 +3887,7 @@ impl<'a> LoweringContext<'a> {
.collect::<P<[hir::Field]>>();
let is_unit = fields.is_empty();
let struct_path = iter::once("ops")
.chain(iter::once(path))
.collect::<Vec<_>>();
let struct_path = ["ops", path];
let struct_path = self.std_path(e.span, &struct_path, None, is_unit);
let struct_path = hir::QPath::Resolved(None, P(struct_path));

View File

@@ -490,10 +490,10 @@ pub enum Input {
}
impl Input {
pub fn filestem(&self) -> String {
pub fn filestem(&self) -> &str {
match *self {
Input::File(ref ifile) => ifile.file_stem().unwrap().to_str().unwrap().to_string(),
Input::Str { .. } => "rust_out".to_string(),
Input::File(ref ifile) => ifile.file_stem().unwrap().to_str().unwrap(),
Input::Str { .. } => "rust_out",
}
}
@@ -765,7 +765,6 @@ macro_rules! options {
}
impl<'a> dep_tracking::DepTrackingHash for $struct_name {
fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) {
let mut sub_hashes = BTreeMap::new();
$({
@@ -1313,13 +1312,11 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
profile: bool = (false, parse_bool, [TRACKED],
"insert profiling code"),
pgo_gen: Option<String> = (None, parse_opt_string, [TRACKED],
"Generate PGO profile data, to a given file, or to the default \
location if it's empty."),
"Generate PGO profile data, to a given file, or to the default location if it's empty."),
pgo_use: String = (String::new(), parse_string, [TRACKED],
"Use PGO profile data from the given profile file."),
disable_instrumentation_preinliner: bool =
(false, parse_bool, [TRACKED], "Disable the instrumentation pre-inliner, \
useful for profiling / PGO."),
disable_instrumentation_preinliner: bool = (false, parse_bool, [TRACKED],
"Disable the instrumentation pre-inliner, useful for profiling / PGO."),
relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED],
"choose which RELRO level to use"),
nll_subminimal_causes: bool = (false, parse_bool, [UNTRACKED],
@@ -1409,6 +1406,7 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
let atomic_cas = sess.target.target.options.atomic_cas;
let mut ret = FxHashSet::default();
ret.reserve(6); // the minimum number of insertions
// Target bindings.
ret.insert((Symbol::intern("target_os"), Some(Symbol::intern(os))));
if let Some(ref fam) = sess.target.target.options.target_family {
@@ -1455,7 +1453,7 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
if sess.opts.crate_types.contains(&CrateType::ProcMacro) {
ret.insert((Symbol::intern("proc_macro"), None));
}
return ret;
ret
}
pub fn build_configuration(sess: &Session, mut user_cfg: ast::CrateConfig) -> ast::CrateConfig {
@@ -1471,15 +1469,12 @@ pub fn build_configuration(sess: &Session, mut user_cfg: ast::CrateConfig) -> as
}
pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
let target = match Target::search(&opts.target_triple) {
Ok(t) => t,
Err(e) => {
let target = Target::search(&opts.target_triple).unwrap_or_else(|e| {
sp.struct_fatal(&format!("Error loading target specification: {}", e))
.help("Use `--print target-list` for a list of built-in targets")
.emit();
FatalError.raise();
}
};
});
let (isize_ty, usize_ty) = match &target.target_pointer_width[..] {
"16" => (ast::IntTy::I16, ast::UintTy::U16),
@@ -1502,7 +1497,6 @@ pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum OptionStability {
Stable,
Unstable,
}
@@ -1845,9 +1839,8 @@ pub fn build_session_options_and_crate_config(
};
let edition = match matches.opt_str("edition") {
Some(arg) => match Edition::from_str(&arg){
Ok(edition) => edition,
Err(_) => early_error(
Some(arg) => Edition::from_str(&arg).unwrap_or_else(|_|
early_error(
ErrorOutputType::default(),
&format!(
"argument for --edition must be one of: \
@@ -1856,7 +1849,7 @@ pub fn build_session_options_and_crate_config(
arg
),
),
}
),
None => DEFAULT_EDITION,
};
@@ -1925,9 +1918,8 @@ pub fn build_session_options_and_crate_config(
for output_type in list.split(',') {
let mut parts = output_type.splitn(2, '=');
let shorthand = parts.next().unwrap();
let output_type = match OutputType::from_shorthand(shorthand) {
Some(output_type) => output_type,
None => early_error(
let output_type = OutputType::from_shorthand(shorthand).unwrap_or_else(||
early_error(
error_format,
&format!(
"unknown emission type: `{}` - expected one of: {}",
@@ -1935,7 +1927,7 @@ pub fn build_session_options_and_crate_config(
OutputType::shorthands_display(),
),
),
};
);
let path = parts.next().map(PathBuf::from);
output_types.insert(output_type, path);
}
@@ -2063,12 +2055,8 @@ pub fn build_session_options_and_crate_config(
let target_triple = if let Some(target) = matches.opt_str("target") {
if target.ends_with(".json") {
let path = Path::new(&target);
match TargetTriple::from_path(&path) {
Ok(triple) => triple,
Err(_) => {
early_error(error_format, &format!("target file {:?} does not exist", path))
}
}
TargetTriple::from_path(&path).unwrap_or_else(|_|
early_error(error_format, &format!("target file {:?} does not exist", path)))
} else {
TargetTriple::TargetTriple(target)
}
@@ -2169,7 +2157,7 @@ pub fn build_session_options_and_crate_config(
let mut name_parts = name.splitn(2, ':');
let name = name_parts.next().unwrap();
let new_name = name_parts.next();
(name.to_string(), new_name.map(|n| n.to_string()), kind)
(name.to_owned(), new_name.map(|n| n.to_owned()), kind)
})
.collect();
@@ -2223,10 +2211,8 @@ pub fn build_session_options_and_crate_config(
let mut externs: BTreeMap<_, BTreeSet<_>> = BTreeMap::new();
for arg in &matches.opt_strs("extern") {
let mut parts = arg.splitn(2, '=');
let name = match parts.next() {
Some(s) => s,
None => early_error(error_format, "--extern value must not be empty"),
};
let name = parts.next().unwrap_or_else(||
early_error(error_format, "--extern value must not be empty"));
let location = parts.next().map(|s| s.to_string());
if location.is_none() && !is_unstable_enabled {
early_error(
@@ -2237,7 +2223,7 @@ pub fn build_session_options_and_crate_config(
};
externs
.entry(name.to_string())
.entry(name.to_owned())
.or_default()
.insert(location);
}
@@ -2308,9 +2294,7 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
"cdylib" => CrateType::Cdylib,
"bin" => CrateType::Executable,
"proc-macro" => CrateType::ProcMacro,
_ => {
return Err(format!("unknown crate type: `{}`", part));
}
_ => return Err(format!("unknown crate type: `{}`", part))
};
if !crate_types.contains(&new_part) {
crate_types.push(new_part)

View File

@@ -41,7 +41,7 @@ impl<'a> FileSearch<'a> {
F: FnMut(&Path, PathKind)
{
let mut visited_dirs = FxHashSet::default();
visited_dirs.reserve(self.search_paths.paths.len() + 1);
for (path, kind) in self.search_paths.iter(self.kind) {
f(path, kind);
visited_dirs.insert(path.to_path_buf());
@@ -160,7 +160,7 @@ pub fn get_or_default_sysroot() -> PathBuf {
match env::current_exe() {
Ok(exe) => {
match canonicalize(Some(exe)) {
Some(mut p) => { p.pop(); p.pop(); return p; },
Some(mut p) => { p.pop(); p.pop(); p },
None => bug!("can't determine value for sysroot")
}
}
@@ -178,15 +178,6 @@ fn find_libdir(sysroot: &Path) -> Cow<'static, str> {
// If --libdir is set during configuration to the value other than
// "lib" (i.e. non-default), this value is used (see issue #16552).
match option_env!("CFG_LIBDIR_RELATIVE") {
Some(libdir) if libdir != "lib" => return libdir.into(),
_ => if sysroot.join(PRIMARY_LIB_DIR).join(RUST_LIB_DIR).exists() {
return PRIMARY_LIB_DIR.into();
} else {
return SECONDARY_LIB_DIR.into();
}
}
#[cfg(target_pointer_width = "64")]
const PRIMARY_LIB_DIR: &'static str = "lib64";
@@ -194,6 +185,15 @@ fn find_libdir(sysroot: &Path) -> Cow<'static, str> {
const PRIMARY_LIB_DIR: &'static str = "lib32";
const SECONDARY_LIB_DIR: &'static str = "lib";
match option_env!("CFG_LIBDIR_RELATIVE") {
Some(libdir) if libdir != "lib" => libdir.into(),
_ => if sysroot.join(PRIMARY_LIB_DIR).join(RUST_LIB_DIR).exists() {
PRIMARY_LIB_DIR.into()
} else {
SECONDARY_LIB_DIR.into()
}
}
}
// The name of rustc's own place to organize libraries.

View File

@@ -727,15 +727,9 @@ impl Session {
pub fn set_incr_session_load_dep_graph(&self, load: bool) {
let mut incr_comp_session = self.incr_comp_session.borrow_mut();
match *incr_comp_session {
IncrCompSession::Active {
ref mut load_dep_graph,
..
} => {
if let IncrCompSession::Active { ref mut load_dep_graph, .. } = *incr_comp_session {
*load_dep_graph = load;
}
_ => {}
}
}
pub fn incr_session_load_dep_graph(&self) -> bool {
@@ -872,9 +866,9 @@ impl Session {
/// This expends fuel if applicable, and records fuel if applicable.
pub fn consider_optimizing<T: Fn() -> String>(&self, crate_name: &str, msg: T) -> bool {
let mut ret = true;
match self.optimization_fuel_crate {
Some(ref c) if c == crate_name => {
assert!(self.query_threads() == 1);
if let Some(ref c) = self.optimization_fuel_crate {
if c == crate_name {
assert_eq!(self.query_threads(), 1);
let fuel = self.optimization_fuel_limit.get();
ret = fuel != 0;
if fuel == 0 && !self.out_of_fuel.get() {
@@ -884,14 +878,12 @@ impl Session {
self.optimization_fuel_limit.set(fuel - 1);
}
}
_ => {}
}
match self.print_fuel_crate {
Some(ref c) if c == crate_name => {
assert!(self.query_threads() == 1);
if let Some(ref c) = self.print_fuel_crate {
if c == crate_name {
assert_eq!(self.query_threads(), 1);
self.print_fuel.set(self.print_fuel.get() + 1);
}
_ => {}
}
ret
}
@@ -1108,14 +1100,11 @@ pub fn build_session_(
source_map: Lrc<source_map::SourceMap>,
) -> Session {
let host_triple = TargetTriple::from_triple(config::host_triple());
let host = match Target::search(&host_triple) {
Ok(t) => t,
Err(e) => {
let host = Target::search(&host_triple).unwrap_or_else(|e|
span_diagnostic
.fatal(&format!("Error loading host specification: {}", e))
.raise();
}
};
.raise()
);
let target_cfg = config::build_target_config(&sopts, &span_diagnostic);
let p_s = parse::ParseSess::with_span_handler(span_diagnostic, source_map);
@@ -1135,12 +1124,11 @@ pub fn build_session_(
let print_fuel_crate = sopts.debugging_opts.print_fuel.clone();
let print_fuel = LockCell::new(0);
let working_dir = match env::current_dir() {
Ok(dir) => dir,
Err(e) => p_s.span_diagnostic
let working_dir = env::current_dir().unwrap_or_else(|e|
p_s.span_diagnostic
.fatal(&format!("Current directory is invalid: {}", e))
.raise(),
};
.raise()
);
let working_dir = file_path_mapping.map_prefix(working_dir);
let cgu_reuse_tracker = if sopts.debugging_opts.query_dep_graph {

View File

@@ -14,7 +14,7 @@ use session::{early_error, config};
#[derive(Clone, Debug)]
pub struct SearchPaths {
paths: Vec<(PathKind, PathBuf)>,
crate paths: Vec<(PathKind, PathBuf)>,
}
pub struct Iter<'a> {

View File

@@ -1657,7 +1657,7 @@ pub fn build_output_filenames(
.crate_name
.clone()
.or_else(|| attr::find_crate_name(attrs).map(|n| n.to_string()))
.unwrap_or_else(|| input.filestem());
.unwrap_or_else(|| input.filestem().to_owned());
OutputFilenames {
out_directory: dirpath,

View File

@@ -272,7 +272,7 @@ declare_lint! {
pub struct UnusedParens;
impl UnusedParens {
fn check_unused_parens_core(&self,
fn check_unused_parens_expr(&self,
cx: &EarlyContext,
value: &ast::Expr,
msg: &str,
@@ -281,15 +281,28 @@ impl UnusedParens {
let necessary = struct_lit_needs_parens &&
parser::contains_exterior_struct_lit(&inner);
if !necessary {
let pattern = pprust::expr_to_string(value);
Self::remove_outer_parens(cx, value.span, &pattern, msg);
}
}
}
fn check_unused_parens_pat(&self,
cx: &EarlyContext,
value: &ast::Pat,
msg: &str) {
if let ast::PatKind::Paren(_) = value.node {
let pattern = pprust::pat_to_string(value);
Self::remove_outer_parens(cx, value.span, &pattern, msg);
}
}
fn remove_outer_parens(cx: &EarlyContext, span: Span, pattern: &str, msg: &str) {
let span_msg = format!("unnecessary parentheses around {}", msg);
let mut err = cx.struct_span_lint(UNUSED_PARENS,
value.span,
&span_msg);
// Remove exactly one pair of parentheses (rather than naïvely
// stripping all paren characters)
let mut err = cx.struct_span_lint(UNUSED_PARENS, span, &span_msg);
let mut ate_left_paren = false;
let mut ate_right_paren = false;
let parens_removed = pprust::expr_to_string(value)
let parens_removed = pattern
.trim_matches(|c| {
match c {
'(' => {
@@ -312,7 +325,7 @@ impl UnusedParens {
}
}).to_owned();
err.span_suggestion_short_with_applicability(
value.span,
span,
"remove these parentheses",
parens_removed,
Applicability::MachineApplicable
@@ -320,8 +333,6 @@ impl UnusedParens {
err.emit();
}
}
}
}
impl LintPass for UnusedParens {
fn get_lints(&self) -> LintArray {
@@ -349,7 +360,9 @@ impl EarlyLintPass for UnusedParens {
// first "argument" is self (which sometimes needs parens)
MethodCall(_, ref args) => (&args[1..], "method"),
// actual catch-all arm
_ => { return; }
_ => {
return;
}
};
// Don't lint if this is a nested macro expansion: otherwise, the lint could
// trigger in situations that macro authors shouldn't have to care about, e.g.,
@@ -362,18 +375,32 @@ impl EarlyLintPass for UnusedParens {
}
let msg = format!("{} argument", call_kind);
for arg in args_to_check {
self.check_unused_parens_core(cx, arg, &msg, false);
self.check_unused_parens_expr(cx, arg, &msg, false);
}
return;
}
};
self.check_unused_parens_core(cx, &value, msg, struct_lit_needs_parens);
self.check_unused_parens_expr(cx, &value, msg, struct_lit_needs_parens);
}
fn check_pat(&mut self, cx: &EarlyContext, p: &ast::Pat) {
use ast::PatKind::{Paren, Range};
// The lint visitor will visit each subpattern of `p`. We do not want to lint any range
// pattern no matter where it occurs in the pattern. For something like `&(a..=b)`, there
// is a recursive `check_pat` on `a` and `b`, but we will assume that if there are
// unnecessry parens they serve a purpose of readability.
if let Paren(ref pat) = p.node {
match pat.node {
Range(..) => {}
_ => self.check_unused_parens_pat(cx, &p, "pattern")
}
}
}
fn check_stmt(&mut self, cx: &EarlyContext, s: &ast::Stmt) {
if let ast::StmtKind::Local(ref local) = s.node {
if let Some(ref value) = local.init {
self.check_unused_parens_core(cx, &value, "assigned value", false);
self.check_unused_parens_expr(cx, &value, "assigned value", false);
}
}
}

View File

@@ -52,7 +52,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
}
/// Returns true as long as there are more things to do.
fn step(&mut self) -> EvalResult<'tcx, bool> {
///
/// This is used by [priroda](https://github.com/oli-obk/priroda)
pub fn step(&mut self) -> EvalResult<'tcx, bool> {
if self.stack.is_empty() {
return Ok(false);
}

View File

@@ -306,8 +306,7 @@ fn program_clauses_for_trait<'a, 'tcx>(
let wf_conditions = iter::once(ty::Binder::dummy(trait_pred.lower()))
.chain(
where_clauses
.iter()
.cloned()
.into_iter()
.map(|wc| wc.map_bound(|goal| goal.into_well_formed_goal()))
);
@@ -350,15 +349,13 @@ fn program_clauses_for_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId
// `WC`
let where_clauses = tcx.predicates_of(def_id).predicates
.into_iter()
.map(|(wc, _)| wc.lower())
.collect::<Vec<_>>();
.map(|(wc, _)| wc.lower());
// `Implemented(A0: Trait<A1..An>) :- WC`
let clause = ProgramClause {
goal: trait_pred,
hypotheses: tcx.mk_goals(
where_clauses
.into_iter()
.map(|wc| tcx.mk_goal(GoalKind::from_poly_domain_goal(wc, tcx))),
),
};

View File

@@ -115,7 +115,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// field is of the found type, suggest such variants. See Issue
// #42764.
if let ty::Adt(expected_adt, substs) = expected.sty {
let compatible_variants = expected_adt.variants
let mut compatible_variants = expected_adt.variants
.iter()
.filter(|variant| variant.fields.len() == 1)
.filter_map(|variant| {
@@ -127,12 +127,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
} else {
None
}
}).collect::<Vec<_>>();
}).peekable();
if !compatible_variants.is_empty() {
if compatible_variants.peek().is_some() {
let expr_text = print::to_string(print::NO_ANN, |s| s.print_expr(expr));
let suggestions = compatible_variants.iter()
.map(|v| format!("{}({})", v, expr_text)).collect::<Vec<_>>();
let suggestions = compatible_variants.map(|v|
format!("{}({})", v, expr_text)).collect::<Vec<_>>();
err.span_suggestions_with_applicability(
expr.span,
"try using a variant of the expected type",

View File

@@ -139,7 +139,7 @@ macro_rules! print {
///
/// [`format!`]: ../std/macro.format.html
/// [`std::fmt`]: ../std/fmt/index.html
/// [`eprintln!`]: ../std/macro.eprint.html
/// [`eprintln!`]: ../std/macro.eprintln.html
/// # Panics
///
/// Panics if writing to `io::stdout` fails.

View File

@@ -34,6 +34,10 @@ use std::collections::hash_map::Entry;
use rustc_data_structures::sync::Lrc;
use errors::Applicability;
const VALID_FRAGMENT_NAMES_MSG: &str = "valid fragment specifiers are \
`ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, `literal`, \
`path`, `meta`, `tt`, `item` and `vis`";
pub struct ParserAnyMacro<'a> {
parser: Parser<'a>,
@@ -708,8 +712,7 @@ fn check_matcher_core(sess: &ParseSess,
if let Err(bad_frag) = has_legal_fragment_specifier(sess, features, attrs, token) {
let msg = format!("invalid fragment specifier `{}`", bad_frag);
sess.span_diagnostic.struct_span_err(token.span(), &msg)
.help("valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, \
`pat`, `ty`, `literal`, `path`, `meta`, `tt`, `item` and `vis`")
.help(VALID_FRAGMENT_NAMES_MSG)
.emit();
// (This eliminates false positives and duplicates
// from error messages.)
@@ -938,9 +941,7 @@ fn is_in_follow(tok: &quoted::TokenTree, frag: &str) -> Result<bool, (String, &'
},
"" => Ok(true), // keywords::Invalid
_ => Err((format!("invalid fragment specifier `{}`", frag),
"valid fragment specifiers are `ident`, `block`, \
`stmt`, `expr`, `pat`, `ty`, `path`, `meta`, `tt`, \
`literal`, `item` and `vis`"))
VALID_FRAGMENT_NAMES_MSG))
}
}
}

View File

@@ -11,6 +11,7 @@
// run-pass
fn main() {
#[allow(unused_parens)]
match 0 {
(pat) => assert_eq!(pat, 0)
}

View File

@@ -4,7 +4,7 @@ error: invalid fragment specifier `t_ty`
LL | macro_rules! test { ($wrong:t_ty ..) => () }
| ^^^^^^^^^^^
|
= help: valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `literal`, `path`, `meta`, `tt`, `item` and `vis`
= help: valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, `item` and `vis`
error: aborting due to previous error

View File

@@ -1,4 +1,4 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// 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.
//
@@ -7,13 +7,9 @@
// <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.
struct Ref<'a, 'b> {
a: &'a u32,
b: &'b u32,
}
fn foo(mut x: Ref) {
x.a = x.b; //~ ERROR lifetime mismatch
}
mod module {}
fn main() {}
fn main() {
let _ = module { x: 0 }; //~ERROR expected struct
}

View File

@@ -0,0 +1,9 @@
error[E0574]: expected struct, variant or union type, found module `module`
--> $DIR/issue-23189.rs:14:13
|
LL | let _ = module { x: 0 }; //~ERROR expected struct
| ^^^^^^ not a struct, variant or union type
error: aborting due to previous error
For more information about this error, try `rustc --explain E0574`.

View File

@@ -1,13 +0,0 @@
error: unsatisfied lifetime constraints
--> $DIR/ex3-both-anon-regions-both-are-structs-4.rs:16:5
|
LL | fn foo(mut x: Ref) {
| -----
| |
| has type `Ref<'_, '1>`
| has type `Ref<'2, '_>`
LL | x.a = x.b; //~ ERROR lifetime mismatch
| ^^^^^^^^^ assignment requires that `'1` must outlive `'2`
error: aborting due to previous error

View File

@@ -1,13 +0,0 @@
error[E0623]: lifetime mismatch
--> $DIR/ex3-both-anon-regions-both-are-structs-4.rs:16:11
|
LL | fn foo(mut x: Ref) {
| ---
| |
| this type is declared with multiple lifetimes...
LL | x.a = x.b; //~ ERROR lifetime mismatch
| ^^^ ...but data with one lifetime flows into the other here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0623`.

View File

@@ -0,0 +1,38 @@
// 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.
// compile-pass
#![allow(unreachable_patterns)]
#![allow(unused_variables)]
#![warn(unused_parens)]
fn main() {
match 1 {
(_) => {} //~ WARNING: unnecessary parentheses around pattern
(y) => {} //~ WARNING: unnecessary parentheses around pattern
(ref r) => {} //~ WARNING: unnecessary parentheses around pattern
(e @ 1..=2) => {} //~ WARNING: unnecessary parentheses around outer pattern
(1..=2) => {} // Non ambiguous range pattern should not warn
e @ (3..=4) => {} // Non ambiguous range pattern should not warn
}
match &1 {
(e @ &(1...2)) => {} //~ WARNING: unnecessary parentheses around outer pattern
&(_) => {} //~ WARNING: unnecessary parentheses around pattern
e @ &(1...2) => {} // Ambiguous range pattern should not warn
&(1..=2) => {} // Ambiguous range pattern should not warn
}
match &1 {
e @ &(1...2) | e @ &(3..=4) => {} // Complex ambiguous pattern should not warn
&_ => {}
}
}

View File

@@ -0,0 +1,42 @@
warning: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:19:9
|
LL | (_) => {} //~ WARNING: unnecessary parentheses around pattern
| ^^^ help: remove these parentheses
|
note: lint level defined here
--> $DIR/issue-54538-unused-parens-lint.rs:15:9
|
LL | #![warn(unused_parens)]
| ^^^^^^^^^^^^^
warning: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:20:9
|
LL | (y) => {} //~ WARNING: unnecessary parentheses around pattern
| ^^^ help: remove these parentheses
warning: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:21:9
|
LL | (ref r) => {} //~ WARNING: unnecessary parentheses around pattern
| ^^^^^^^ help: remove these parentheses
warning: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:22:9
|
LL | (e @ 1..=2) => {} //~ WARNING: unnecessary parentheses around outer pattern
| ^^^^^^^^^^^ help: remove these parentheses
warning: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:28:9
|
LL | (e @ &(1...2)) => {} //~ WARNING: unnecessary parentheses around outer pattern
| ^^^^^^^^^^^^^^ help: remove these parentheses
warning: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:29:10
|
LL | &(_) => {} //~ WARNING: unnecessary parentheses around pattern
| ^^^ help: remove these parentheses

View File

@@ -1,36 +0,0 @@
// Copyright 20142017 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.
#![deny(nonstandard_style)]
#![allow(dead_code)]
fn CamelCase() {} //~ ERROR should have a snake
#[allow(nonstandard_style)]
mod test {
fn CamelCase() {}
#[forbid(nonstandard_style)]
mod bad {
fn CamelCase() {} //~ ERROR should have a snake
static bad: isize = 1; //~ ERROR should have an upper
}
mod warn {
#![warn(nonstandard_style)]
fn CamelCase() {} //~ WARN should have a snake
struct snake_case; //~ WARN should have a camel
}
}
fn main() {}

View File

@@ -1,67 +0,0 @@
error: function `CamelCase` should have a snake case name such as `camel_case`
--> $DIR/lint-group-style.rs:14:1
|
LL | fn CamelCase() {} //~ ERROR should have a snake
| ^^^^^^^^^^^^^^^^^
|
note: lint level defined here
--> $DIR/lint-group-style.rs:11:9
|
LL | #![deny(nonstandard_style)]
| ^^^^^^^^^^^^^^^^^
= note: #[deny(non_snake_case)] implied by #[deny(nonstandard_style)]
error: function `CamelCase` should have a snake case name such as `camel_case`
--> $DIR/lint-group-style.rs:22:9
|
LL | fn CamelCase() {} //~ ERROR should have a snake
| ^^^^^^^^^^^^^^^^^
|
note: lint level defined here
--> $DIR/lint-group-style.rs:20:14
|
LL | #[forbid(nonstandard_style)]
| ^^^^^^^^^^^^^^^^^
= note: #[forbid(non_snake_case)] implied by #[forbid(nonstandard_style)]
error: static variable `bad` should have an upper case name such as `BAD`
--> $DIR/lint-group-style.rs:24:9
|
LL | static bad: isize = 1; //~ ERROR should have an upper
| ^^^^^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
--> $DIR/lint-group-style.rs:20:14
|
LL | #[forbid(nonstandard_style)]
| ^^^^^^^^^^^^^^^^^
= note: #[forbid(non_upper_case_globals)] implied by #[forbid(nonstandard_style)]
warning: function `CamelCase` should have a snake case name such as `camel_case`
--> $DIR/lint-group-style.rs:30:9
|
LL | fn CamelCase() {} //~ WARN should have a snake
| ^^^^^^^^^^^^^^^^^
|
note: lint level defined here
--> $DIR/lint-group-style.rs:28:17
|
LL | #![warn(nonstandard_style)]
| ^^^^^^^^^^^^^^^^^
= note: #[warn(non_snake_case)] implied by #[warn(nonstandard_style)]
warning: type `snake_case` should have a camel case name such as `SnakeCase`
--> $DIR/lint-group-style.rs:32:9
|
LL | struct snake_case; //~ WARN should have a camel
| ^^^^^^^^^^^^^^^^^^
|
note: lint level defined here
--> $DIR/lint-group-style.rs:28:17
|
LL | #![warn(nonstandard_style)]
| ^^^^^^^^^^^^^^^^^
= note: #[warn(non_camel_case_types)] implied by #[warn(nonstandard_style)]
error: aborting due to 3 previous errors

View File

@@ -4,7 +4,7 @@ error: invalid fragment specifier `foo`
LL | ($x:foo) => ()
| ^^^^^^
|
= help: valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `literal`, `path`, `meta`, `tt`, `item` and `vis`
= help: valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, `item` and `vis`
error: aborting due to previous error

View File

@@ -4,7 +4,7 @@ error: invalid fragment specifier `t_ty`
LL | ($wrong:t_ty) => () //~ ERROR invalid fragment specifier `t_ty`
| ^^^^^^^^^^^
|
= help: valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `literal`, `path`, `meta`, `tt`, `item` and `vis`
= help: valid fragment specifiers are `ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, `literal`, `path`, `meta`, `tt`, `item` and `vis`
error: aborting due to previous error