Skip to content

Commit 46880f4

Browse files
committed
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
2 parents 5a52983 + 562625d commit 46880f4

27 files changed

+216
-264
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ are:
646646
* Don't be afraid to ask! The Rust community is friendly and helpful.
647647

648648
[rustc guide]: https://rust-lang-nursery.github.io/rustc-guide/about-this-guide.html
649-
[gdfrustc]: http://manishearth.github.io/rust-internals-docs/rustc/
649+
[gdfrustc]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc/
650650
[gsearchdocs]: https://www.google.com/search?q=site:doc.rust-lang.org+your+query+here
651651
[rif]: http://internals.rust-lang.org
652652
[rr]: https://doc.rust-lang.org/book/README.html

src/libcore/fmt/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@ pub type Result = result::Result<(), Error>;
9696
/// use std::fmt::{self, write};
9797
///
9898
/// let mut output = String::new();
99-
/// match write(&mut output, format_args!("Hello {}!", "world")) {
100-
/// Err(fmt::Error) => panic!("An error occurred"),
101-
/// _ => (),
99+
/// if let Err(fmt::Error) = write(&mut output, format_args!("Hello {}!", "world")) {
100+
/// panic!("An error occurred");
102101
/// }
103102
/// ```
104103
#[stable(feature = "rust1", since = "1.0.0")]

src/libcore/ptr.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ impl<T: ?Sized> *const T {
10371037
/// Behavior:
10381038
///
10391039
/// * Both the starting and resulting pointer must be either in bounds or one
1040-
/// byte past the end of *the same* allocated object.
1040+
/// byte past the end of the same allocated object.
10411041
///
10421042
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
10431043
///
@@ -1255,7 +1255,7 @@ impl<T: ?Sized> *const T {
12551255
/// Behavior:
12561256
///
12571257
/// * Both the starting and resulting pointer must be either in bounds or one
1258-
/// byte past the end of an allocated object.
1258+
/// byte past the end of the same allocated object.
12591259
///
12601260
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
12611261
///
@@ -1312,7 +1312,7 @@ impl<T: ?Sized> *const T {
13121312
/// Behavior:
13131313
///
13141314
/// * Both the starting and resulting pointer must be either in bounds or one
1315-
/// byte past the end of an allocated object.
1315+
/// byte past the end of the same allocated object.
13161316
///
13171317
/// * The computed offset cannot exceed `isize::MAX` **bytes**.
13181318
///
@@ -1657,7 +1657,7 @@ impl<T: ?Sized> *mut T {
16571657
/// Behavior:
16581658
///
16591659
/// * Both the starting and resulting pointer must be either in bounds or one
1660-
/// byte past the end of *the same* allocated object.
1660+
/// byte past the end of the same allocated object.
16611661
///
16621662
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
16631663
///
@@ -1893,7 +1893,7 @@ impl<T: ?Sized> *mut T {
18931893
/// Behavior:
18941894
///
18951895
/// * Both the starting and resulting pointer must be either in bounds or one
1896-
/// byte past the end of an allocated object.
1896+
/// byte past the end of the same allocated object.
18971897
///
18981898
/// * The computed offset, **in bytes**, cannot overflow an `isize`.
18991899
///
@@ -1950,7 +1950,7 @@ impl<T: ?Sized> *mut T {
19501950
/// Behavior:
19511951
///
19521952
/// * Both the starting and resulting pointer must be either in bounds or one
1953-
/// byte past the end of an allocated object.
1953+
/// byte past the end of the same allocated object.
19541954
///
19551955
/// * The computed offset cannot exceed `isize::MAX` **bytes**.
19561956
///

src/librustc/hir/lowering.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ use util::nodemap::{DefIdMap, NodeMap};
6060

6161
use std::collections::BTreeMap;
6262
use std::fmt::Debug;
63-
use std::iter;
6463
use std::mem;
6564
use smallvec::SmallVec;
6665
use syntax::attr;
@@ -3888,9 +3887,7 @@ impl<'a> LoweringContext<'a> {
38883887
.collect::<P<[hir::Field]>>();
38893888

38903889
let is_unit = fields.is_empty();
3891-
let struct_path = iter::once("ops")
3892-
.chain(iter::once(path))
3893-
.collect::<Vec<_>>();
3890+
let struct_path = ["ops", path];
38943891
let struct_path = self.std_path(e.span, &struct_path, None, is_unit);
38953892
let struct_path = hir::QPath::Resolved(None, P(struct_path));
38963893

src/librustc/session/config.rs

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -490,10 +490,10 @@ pub enum Input {
490490
}
491491

492492
impl Input {
493-
pub fn filestem(&self) -> String {
493+
pub fn filestem(&self) -> &str {
494494
match *self {
495-
Input::File(ref ifile) => ifile.file_stem().unwrap().to_str().unwrap().to_string(),
496-
Input::Str { .. } => "rust_out".to_string(),
495+
Input::File(ref ifile) => ifile.file_stem().unwrap().to_str().unwrap(),
496+
Input::Str { .. } => "rust_out",
497497
}
498498
}
499499

@@ -765,7 +765,6 @@ macro_rules! options {
765765
}
766766

767767
impl<'a> dep_tracking::DepTrackingHash for $struct_name {
768-
769768
fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) {
770769
let mut sub_hashes = BTreeMap::new();
771770
$({
@@ -1313,13 +1312,11 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
13131312
profile: bool = (false, parse_bool, [TRACKED],
13141313
"insert profiling code"),
13151314
pgo_gen: Option<String> = (None, parse_opt_string, [TRACKED],
1316-
"Generate PGO profile data, to a given file, or to the default \
1317-
location if it's empty."),
1315+
"Generate PGO profile data, to a given file, or to the default location if it's empty."),
13181316
pgo_use: String = (String::new(), parse_string, [TRACKED],
13191317
"Use PGO profile data from the given profile file."),
1320-
disable_instrumentation_preinliner: bool =
1321-
(false, parse_bool, [TRACKED], "Disable the instrumentation pre-inliner, \
1322-
useful for profiling / PGO."),
1318+
disable_instrumentation_preinliner: bool = (false, parse_bool, [TRACKED],
1319+
"Disable the instrumentation pre-inliner, useful for profiling / PGO."),
13231320
relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED],
13241321
"choose which RELRO level to use"),
13251322
nll_subminimal_causes: bool = (false, parse_bool, [UNTRACKED],
@@ -1409,6 +1406,7 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
14091406
let atomic_cas = sess.target.target.options.atomic_cas;
14101407

14111408
let mut ret = FxHashSet::default();
1409+
ret.reserve(6); // the minimum number of insertions
14121410
// Target bindings.
14131411
ret.insert((Symbol::intern("target_os"), Some(Symbol::intern(os))));
14141412
if let Some(ref fam) = sess.target.target.options.target_family {
@@ -1455,7 +1453,7 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
14551453
if sess.opts.crate_types.contains(&CrateType::ProcMacro) {
14561454
ret.insert((Symbol::intern("proc_macro"), None));
14571455
}
1458-
return ret;
1456+
ret
14591457
}
14601458

14611459
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
14711469
}
14721470

14731471
pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
1474-
let target = match Target::search(&opts.target_triple) {
1475-
Ok(t) => t,
1476-
Err(e) => {
1472+
let target = Target::search(&opts.target_triple).unwrap_or_else(|e| {
14771473
sp.struct_fatal(&format!("Error loading target specification: {}", e))
14781474
.help("Use `--print target-list` for a list of built-in targets")
14791475
.emit();
14801476
FatalError.raise();
1481-
}
1482-
};
1477+
});
14831478

14841479
let (isize_ty, usize_ty) = match &target.target_pointer_width[..] {
14851480
"16" => (ast::IntTy::I16, ast::UintTy::U16),
@@ -1502,7 +1497,6 @@ pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
15021497
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
15031498
pub enum OptionStability {
15041499
Stable,
1505-
15061500
Unstable,
15071501
}
15081502

@@ -1845,9 +1839,8 @@ pub fn build_session_options_and_crate_config(
18451839
};
18461840

18471841
let edition = match matches.opt_str("edition") {
1848-
Some(arg) => match Edition::from_str(&arg){
1849-
Ok(edition) => edition,
1850-
Err(_) => early_error(
1842+
Some(arg) => Edition::from_str(&arg).unwrap_or_else(|_|
1843+
early_error(
18511844
ErrorOutputType::default(),
18521845
&format!(
18531846
"argument for --edition must be one of: \
@@ -1856,7 +1849,7 @@ pub fn build_session_options_and_crate_config(
18561849
arg
18571850
),
18581851
),
1859-
}
1852+
),
18601853
None => DEFAULT_EDITION,
18611854
};
18621855

@@ -1925,17 +1918,16 @@ pub fn build_session_options_and_crate_config(
19251918
for output_type in list.split(',') {
19261919
let mut parts = output_type.splitn(2, '=');
19271920
let shorthand = parts.next().unwrap();
1928-
let output_type = match OutputType::from_shorthand(shorthand) {
1929-
Some(output_type) => output_type,
1930-
None => early_error(
1921+
let output_type = OutputType::from_shorthand(shorthand).unwrap_or_else(||
1922+
early_error(
19311923
error_format,
19321924
&format!(
19331925
"unknown emission type: `{}` - expected one of: {}",
19341926
shorthand,
19351927
OutputType::shorthands_display(),
19361928
),
19371929
),
1938-
};
1930+
);
19391931
let path = parts.next().map(PathBuf::from);
19401932
output_types.insert(output_type, path);
19411933
}
@@ -2063,12 +2055,8 @@ pub fn build_session_options_and_crate_config(
20632055
let target_triple = if let Some(target) = matches.opt_str("target") {
20642056
if target.ends_with(".json") {
20652057
let path = Path::new(&target);
2066-
match TargetTriple::from_path(&path) {
2067-
Ok(triple) => triple,
2068-
Err(_) => {
2069-
early_error(error_format, &format!("target file {:?} does not exist", path))
2070-
}
2071-
}
2058+
TargetTriple::from_path(&path).unwrap_or_else(|_|
2059+
early_error(error_format, &format!("target file {:?} does not exist", path)))
20722060
} else {
20732061
TargetTriple::TargetTriple(target)
20742062
}
@@ -2169,7 +2157,7 @@ pub fn build_session_options_and_crate_config(
21692157
let mut name_parts = name.splitn(2, ':');
21702158
let name = name_parts.next().unwrap();
21712159
let new_name = name_parts.next();
2172-
(name.to_string(), new_name.map(|n| n.to_string()), kind)
2160+
(name.to_owned(), new_name.map(|n| n.to_owned()), kind)
21732161
})
21742162
.collect();
21752163

@@ -2223,10 +2211,8 @@ pub fn build_session_options_and_crate_config(
22232211
let mut externs: BTreeMap<_, BTreeSet<_>> = BTreeMap::new();
22242212
for arg in &matches.opt_strs("extern") {
22252213
let mut parts = arg.splitn(2, '=');
2226-
let name = match parts.next() {
2227-
Some(s) => s,
2228-
None => early_error(error_format, "--extern value must not be empty"),
2229-
};
2214+
let name = parts.next().unwrap_or_else(||
2215+
early_error(error_format, "--extern value must not be empty"));
22302216
let location = parts.next().map(|s| s.to_string());
22312217
if location.is_none() && !is_unstable_enabled {
22322218
early_error(
@@ -2237,7 +2223,7 @@ pub fn build_session_options_and_crate_config(
22372223
};
22382224

22392225
externs
2240-
.entry(name.to_string())
2226+
.entry(name.to_owned())
22412227
.or_default()
22422228
.insert(location);
22432229
}
@@ -2308,9 +2294,7 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
23082294
"cdylib" => CrateType::Cdylib,
23092295
"bin" => CrateType::Executable,
23102296
"proc-macro" => CrateType::ProcMacro,
2311-
_ => {
2312-
return Err(format!("unknown crate type: `{}`", part));
2313-
}
2297+
_ => return Err(format!("unknown crate type: `{}`", part))
23142298
};
23152299
if !crate_types.contains(&new_part) {
23162300
crate_types.push(new_part)

src/librustc/session/filesearch.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<'a> FileSearch<'a> {
4141
F: FnMut(&Path, PathKind)
4242
{
4343
let mut visited_dirs = FxHashSet::default();
44-
44+
visited_dirs.reserve(self.search_paths.paths.len() + 1);
4545
for (path, kind) in self.search_paths.iter(self.kind) {
4646
f(path, kind);
4747
visited_dirs.insert(path.to_path_buf());
@@ -160,7 +160,7 @@ pub fn get_or_default_sysroot() -> PathBuf {
160160
match env::current_exe() {
161161
Ok(exe) => {
162162
match canonicalize(Some(exe)) {
163-
Some(mut p) => { p.pop(); p.pop(); return p; },
163+
Some(mut p) => { p.pop(); p.pop(); p },
164164
None => bug!("can't determine value for sysroot")
165165
}
166166
}
@@ -178,22 +178,22 @@ fn find_libdir(sysroot: &Path) -> Cow<'static, str> {
178178
// If --libdir is set during configuration to the value other than
179179
// "lib" (i.e. non-default), this value is used (see issue #16552).
180180

181-
match option_env!("CFG_LIBDIR_RELATIVE") {
182-
Some(libdir) if libdir != "lib" => return libdir.into(),
183-
_ => if sysroot.join(PRIMARY_LIB_DIR).join(RUST_LIB_DIR).exists() {
184-
return PRIMARY_LIB_DIR.into();
185-
} else {
186-
return SECONDARY_LIB_DIR.into();
187-
}
188-
}
189-
190181
#[cfg(target_pointer_width = "64")]
191182
const PRIMARY_LIB_DIR: &'static str = "lib64";
192183

193184
#[cfg(target_pointer_width = "32")]
194185
const PRIMARY_LIB_DIR: &'static str = "lib32";
195186

196187
const SECONDARY_LIB_DIR: &'static str = "lib";
188+
189+
match option_env!("CFG_LIBDIR_RELATIVE") {
190+
Some(libdir) if libdir != "lib" => libdir.into(),
191+
_ => if sysroot.join(PRIMARY_LIB_DIR).join(RUST_LIB_DIR).exists() {
192+
PRIMARY_LIB_DIR.into()
193+
} else {
194+
SECONDARY_LIB_DIR.into()
195+
}
196+
}
197197
}
198198

199199
// The name of rustc's own place to organize libraries.

0 commit comments

Comments
 (0)