Skip to content

Commit 89e645a

Browse files
committed
Auto merge of #65622 - Centril:rollup-l8orba7, r=Centril
Rollup of 6 pull requests Successful merges: - #64996 (Inline `ptr::null(_mut)` even in debug builds) - #65551 (Avoid realloc in `CString::new`) - #65593 (add test for calling non-const fn) - #65595 (move `parse_cfgspecs` to `rustc_interface`) - #65600 (Remove unneeded `ref` from docs) - #65602 (Fix plural mistake in emitter.rs) Failed merges: r? @ghost
2 parents 857a55b + ba42fc2 commit 89e645a

File tree

18 files changed

+187
-120
lines changed

18 files changed

+187
-120
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3556,6 +3556,7 @@ dependencies = [
35563556
"rustc_plugin_impl",
35573557
"rustc_privacy",
35583558
"rustc_resolve",
3559+
"rustc_target",
35593560
"rustc_traits",
35603561
"rustc_typeck",
35613562
"serialize",

src/libcore/option.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
//!
6565
//! fn check_optional(optional: Option<Box<i32>>) {
6666
//! match optional {
67-
//! Some(ref p) => println!("has value {}", p),
67+
//! Some(p) => println!("has value {}", p),
6868
//! None => println!("has no value"),
6969
//! }
7070
//! }
@@ -83,7 +83,7 @@
8383
//! let msg = Some("howdy");
8484
//!
8585
//! // Take a reference to the contained string
86-
//! if let Some(ref m) = msg {
86+
//! if let Some(m) = &msg {
8787
//! println!("{}", *m);
8888
//! }
8989
//!

src/libcore/ptr/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ unsafe fn real_drop_in_place<T: ?Sized>(to_drop: &mut T) {
188188
/// let p: *const i32 = ptr::null();
189189
/// assert!(p.is_null());
190190
/// ```
191-
#[inline]
191+
#[inline(always)]
192192
#[stable(feature = "rust1", since = "1.0.0")]
193193
#[rustc_promotable]
194194
pub const fn null<T>() -> *const T { 0 as *const T }
@@ -203,7 +203,7 @@ pub const fn null<T>() -> *const T { 0 as *const T }
203203
/// let p: *mut i32 = ptr::null_mut();
204204
/// assert!(p.is_null());
205205
/// ```
206-
#[inline]
206+
#[inline(always)]
207207
#[stable(feature = "rust1", since = "1.0.0")]
208208
#[rustc_promotable]
209209
pub const fn null_mut<T>() -> *mut T { 0 as *mut T }

src/librustc/session/config.rs

+2-63
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,19 @@ use crate::session::{early_error, early_warn, Session};
77
use crate::session::search_paths::SearchPath;
88

99
use rustc_data_structures::fx::FxHashSet;
10-
use rustc_data_structures::sync::Lrc;
1110

1211
use rustc_target::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, RelroLevel};
1312
use rustc_target::spec::{Target, TargetTriple};
1413

1514
use syntax;
16-
use syntax::ast::{self, IntTy, UintTy, MetaItemKind};
15+
use syntax::ast::{self, IntTy, UintTy};
1716
use syntax::source_map::{FileName, FilePathMapping};
1817
use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION};
19-
use syntax::parse::new_parser_from_source_str;
20-
use syntax::parse::token;
21-
use syntax::sess::ParseSess;
2218
use syntax::symbol::{sym, Symbol};
2319
use syntax::feature_gate::UnstableFeatures;
24-
use syntax::source_map::SourceMap;
2520

2621
use errors::emitter::HumanReadableErrorType;
27-
use errors::{ColorConfig, FatalError, Handler, SourceMapperDyn};
22+
use errors::{ColorConfig, FatalError, Handler};
2823

2924
use getopts;
3025

@@ -1854,59 +1849,6 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
18541849
opts
18551850
}
18561851

1857-
struct NullEmitter;
1858-
1859-
impl errors::emitter::Emitter for NullEmitter {
1860-
fn emit_diagnostic(&mut self, _: &errors::Diagnostic) {}
1861-
fn source_map(&self) -> Option<&Lrc<SourceMapperDyn>> { None }
1862-
}
1863-
1864-
// Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`.
1865-
pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String>)> {
1866-
syntax::with_default_globals(move || {
1867-
let cfg = cfgspecs.into_iter().map(|s| {
1868-
1869-
let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
1870-
let handler = Handler::with_emitter(false, None, Box::new(NullEmitter));
1871-
let sess = ParseSess::with_span_handler(handler, cm);
1872-
let filename = FileName::cfg_spec_source_code(&s);
1873-
let mut parser = new_parser_from_source_str(&sess, filename, s.to_string());
1874-
1875-
macro_rules! error {($reason: expr) => {
1876-
early_error(ErrorOutputType::default(),
1877-
&format!(concat!("invalid `--cfg` argument: `{}` (", $reason, ")"), s));
1878-
}}
1879-
1880-
match &mut parser.parse_meta_item() {
1881-
Ok(meta_item) if parser.token == token::Eof => {
1882-
if meta_item.path.segments.len() != 1 {
1883-
error!("argument key must be an identifier");
1884-
}
1885-
match &meta_item.kind {
1886-
MetaItemKind::List(..) => {
1887-
error!(r#"expected `key` or `key="value"`"#);
1888-
}
1889-
MetaItemKind::NameValue(lit) if !lit.kind.is_str() => {
1890-
error!("argument value must be a string");
1891-
}
1892-
MetaItemKind::NameValue(..) | MetaItemKind::Word => {
1893-
let ident = meta_item.ident().expect("multi-segment cfg key");
1894-
return (ident.name, meta_item.value_str());
1895-
}
1896-
}
1897-
}
1898-
Ok(..) => {}
1899-
Err(err) => err.cancel(),
1900-
}
1901-
1902-
error!(r#"expected `key` or `key="value"`"#);
1903-
}).collect::<ast::CrateConfig>();
1904-
cfg.into_iter().map(|(a, b)| {
1905-
(a.to_string(), b.map(|b| b.to_string()))
1906-
}).collect()
1907-
})
1908-
}
1909-
19101852
pub fn get_cmd_lint_options(matches: &getopts::Matches,
19111853
error_format: ErrorOutputType)
19121854
-> (Vec<(String, lint::Level)>, bool, Option<lint::Level>) {
@@ -2877,6 +2819,3 @@ mod dep_tracking {
28772819
}
28782820
}
28792821
}
2880-
2881-
#[cfg(test)]
2882-
mod tests;

src/librustc_codegen_llvm/back/lto.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ fn prepare_lto(cgcx: &CodegenContext<LlvmCodegenBackend>,
5353

5454
let symbol_filter = &|&(ref name, level): &(String, SymbolExportLevel)| {
5555
if level.is_below_threshold(export_threshold) {
56-
let mut bytes = Vec::with_capacity(name.len() + 1);
57-
bytes.extend(name.bytes());
58-
Some(CString::new(bytes).unwrap())
56+
Some(CString::new(name.as_str()).unwrap())
5957
} else {
6058
None
6159
}

src/librustc_driver/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub fn run_compiler(
167167
};
168168

169169
let sopts = config::build_session_options(&matches);
170-
let cfg = config::parse_cfgspecs(matches.opt_strs("cfg"));
170+
let cfg = interface::parse_cfgspecs(matches.opt_strs("cfg"));
171171

172172
let mut dummy_config = |sopts, cfg, diagnostic_output| {
173173
let mut config = interface::Config {

src/librustc_errors/emitter.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use Destination::*;
1212
use syntax_pos::{SourceFile, Span, MultiSpan};
1313

1414
use crate::{
15-
Level, CodeSuggestion, Diagnostic, SubDiagnostic,
15+
Level, CodeSuggestion, Diagnostic, SubDiagnostic, pluralise,
1616
SuggestionStyle, SourceMapper, SourceMapperDyn, DiagnosticId,
1717
};
1818
use crate::Level::Error;
@@ -1572,7 +1572,8 @@ impl EmitterWriter {
15721572
}
15731573
}
15741574
if suggestions.len() > MAX_SUGGESTIONS {
1575-
let msg = format!("and {} other candidates", suggestions.len() - MAX_SUGGESTIONS);
1575+
let others = suggestions.len() - MAX_SUGGESTIONS;
1576+
let msg = format!("and {} other candidate{}", others, pluralise!(others));
15761577
buffer.puts(row_num, max_line_num_len + 3, &msg, Style::NoStyle);
15771578
} else if notice_capitalization {
15781579
let msg = "notice the capitalization difference";

src/librustc_interface/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ rustc_codegen_utils = { path = "../librustc_codegen_utils" }
2727
rustc_metadata = { path = "../librustc_metadata" }
2828
rustc_mir = { path = "../librustc_mir" }
2929
rustc_passes = { path = "../librustc_passes" }
30+
rustc_target = { path = "../librustc_target" }
3031
rustc_typeck = { path = "../librustc_typeck" }
3132
rustc_lint = { path = "../librustc_lint" }
3233
rustc_errors = { path = "../librustc_errors" }

src/librustc_interface/interface.rs

+60-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use crate::util;
33
pub use crate::passes::BoxedResolver;
44

55
use rustc::lint;
6-
use rustc::session::config::{self, Input};
6+
use rustc::session::early_error;
7+
use rustc::session::config::{self, Input, ErrorOutputType};
78
use rustc::session::{DiagnosticOutput, Session};
89
use rustc::util::common::ErrorReported;
910
use rustc_codegen_utils::codegen_backend::CodegenBackend;
@@ -14,9 +15,13 @@ use rustc_metadata::cstore::CStore;
1415
use std::path::PathBuf;
1516
use std::result;
1617
use std::sync::{Arc, Mutex};
17-
use syntax;
18-
use syntax::source_map::{FileLoader, SourceMap};
18+
use syntax::{self, parse};
19+
use syntax::ast::{self, MetaItemKind};
20+
use syntax::parse::token;
21+
use syntax::source_map::{FileName, FilePathMapping, FileLoader, SourceMap};
22+
use syntax::sess::ParseSess;
1923
use syntax_pos::edition;
24+
use rustc_errors::{Diagnostic, emitter::Emitter, Handler, SourceMapperDyn};
2025

2126
pub type Result<T> = result::Result<T, ErrorReported>;
2227

@@ -60,6 +65,58 @@ impl Compiler {
6065
}
6166
}
6267

68+
/// Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`.
69+
pub fn parse_cfgspecs(cfgspecs: Vec<String>) -> FxHashSet<(String, Option<String>)> {
70+
struct NullEmitter;
71+
impl Emitter for NullEmitter {
72+
fn emit_diagnostic(&mut self, _: &Diagnostic) {}
73+
fn source_map(&self) -> Option<&Lrc<SourceMapperDyn>> { None }
74+
}
75+
76+
syntax::with_default_globals(move || {
77+
let cfg = cfgspecs.into_iter().map(|s| {
78+
79+
let cm = Lrc::new(SourceMap::new(FilePathMapping::empty()));
80+
let handler = Handler::with_emitter(false, None, Box::new(NullEmitter));
81+
let sess = ParseSess::with_span_handler(handler, cm);
82+
let filename = FileName::cfg_spec_source_code(&s);
83+
let mut parser = parse::new_parser_from_source_str(&sess, filename, s.to_string());
84+
85+
macro_rules! error {($reason: expr) => {
86+
early_error(ErrorOutputType::default(),
87+
&format!(concat!("invalid `--cfg` argument: `{}` (", $reason, ")"), s));
88+
}}
89+
90+
match &mut parser.parse_meta_item() {
91+
Ok(meta_item) if parser.token == token::Eof => {
92+
if meta_item.path.segments.len() != 1 {
93+
error!("argument key must be an identifier");
94+
}
95+
match &meta_item.kind {
96+
MetaItemKind::List(..) => {
97+
error!(r#"expected `key` or `key="value"`"#);
98+
}
99+
MetaItemKind::NameValue(lit) if !lit.kind.is_str() => {
100+
error!("argument value must be a string");
101+
}
102+
MetaItemKind::NameValue(..) | MetaItemKind::Word => {
103+
let ident = meta_item.ident().expect("multi-segment cfg key");
104+
return (ident.name, meta_item.value_str());
105+
}
106+
}
107+
}
108+
Ok(..) => {}
109+
Err(err) => err.cancel(),
110+
}
111+
112+
error!(r#"expected `key` or `key="value"`"#);
113+
}).collect::<ast::CrateConfig>();
114+
cfg.into_iter().map(|(a, b)| {
115+
(a.to_string(), b.map(|b| b.to_string()))
116+
}).collect()
117+
})
118+
}
119+
63120
/// The compiler configuration
64121
pub struct Config {
65122
/// Command line options

src/librustc_interface/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ pub mod util;
1818
mod proc_macro_decls;
1919

2020
pub use interface::{run_compiler, Config};
21+
22+
#[cfg(test)]
23+
mod tests;

0 commit comments

Comments
 (0)