Auto merge of #71059 - Dylan-DPC:rollup-zgu6jmx, r=Dylan-DPC

Rollup of 6 pull requests

Successful merges:

 - #71029 (Partial work on building with Cargo)
 - #71034 (Clean up E0515 explanation)
 - #71041 (Update links of `rustc guide`)
 - #71048 (Normalize source when loading external foreign source into SourceMap)
 - #71053 (Add some basic docs to `sym` and `kw` modules)
 - #71057 (Clean up E0516 explanation)

Failed merges:

r? @ghost
This commit is contained in:
bors 2020-04-12 18:09:46 +00:00
commit 3712e11a82
25 changed files with 118 additions and 40 deletions

View File

@ -3694,6 +3694,7 @@ dependencies = [
"indexmap", "indexmap",
"jobserver", "jobserver",
"lazy_static 1.4.0", "lazy_static 1.4.0",
"libc",
"log", "log",
"measureme", "measureme",
"parking_lot 0.10.0", "parking_lot 0.10.0",
@ -3713,6 +3714,7 @@ version = "0.0.0"
dependencies = [ dependencies = [
"env_logger 0.7.1", "env_logger 0.7.1",
"lazy_static 1.4.0", "lazy_static 1.4.0",
"libc",
"log", "log",
"rustc_ast", "rustc_ast",
"rustc_ast_pretty", "rustc_ast_pretty",
@ -3867,6 +3869,7 @@ dependencies = [
name = "rustc_interface" name = "rustc_interface"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"libc",
"log", "log",
"once_cell", "once_cell",
"rustc-rayon", "rustc-rayon",
@ -3960,6 +3963,7 @@ name = "rustc_metadata"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"flate2", "flate2",
"libc",
"log", "log",
"memmap", "memmap",
"rustc_ast", "rustc_ast",
@ -4197,6 +4201,7 @@ dependencies = [
name = "rustc_session" name = "rustc_session"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"getopts",
"log", "log",
"num_cpus", "num_cpus",
"rustc_ast", "rustc_ast",

View File

@ -186,6 +186,8 @@ pub fn std_cargo(builder: &Builder<'_>, target: Interned<String>, cargo: &mut Ca
// `compiler-rt` is located. // `compiler-rt` is located.
let compiler_builtins_root = builder.src.join("src/llvm-project/compiler-rt"); let compiler_builtins_root = builder.src.join("src/llvm-project/compiler-rt");
let compiler_builtins_c_feature = if compiler_builtins_root.exists() { let compiler_builtins_c_feature = if compiler_builtins_root.exists() {
// Note that `libprofiler_builtins/build.rs` also computes this so if
// you're changing something here please also change that.
cargo.env("RUST_COMPILER_RT_ROOT", &compiler_builtins_root); cargo.env("RUST_COMPILER_RT_ROOT", &compiler_builtins_root);
" compiler-builtins-c".to_string() " compiler-builtins-c".to_string()
} else { } else {

View File

@ -63,8 +63,9 @@ fn main() {
cfg.define("COMPILER_RT_HAS_ATOMICS", Some("1")); cfg.define("COMPILER_RT_HAS_ATOMICS", Some("1"));
} }
let root = env::var_os("RUST_COMPILER_RT_ROOT").unwrap(); // Note that this should exist if we're going to run (otherwise we just
let root = Path::new(&root); // don't build profiler builtins at all).
let root = Path::new("../llvm-project/compiler-rt");
let src_root = root.join("lib").join("profile"); let src_root = root.join("lib").join("profile");
for src in profile_sources { for src in profile_sources {

View File

@ -27,6 +27,7 @@ smallvec = { version = "1.0", features = ["union", "may_dangle"] }
rustc_index = { path = "../librustc_index", package = "rustc_index" } rustc_index = { path = "../librustc_index", package = "rustc_index" }
bitflags = "1.2.1" bitflags = "1.2.1"
measureme = "0.7.1" measureme = "0.7.1"
libc = "0.2"
[dependencies.parking_lot] [dependencies.parking_lot]
version = "0.10" version = "0.10"

View File

@ -26,8 +26,6 @@
#[macro_use] #[macro_use]
extern crate log; extern crate log;
#[cfg(unix)]
extern crate libc;
#[macro_use] #[macro_use]
extern crate cfg_if; extern crate cfg_if;

View File

@ -11,6 +11,7 @@ crate-type = ["dylib"]
[dependencies] [dependencies]
lazy_static = "1.0" lazy_static = "1.0"
libc = "0.2"
log = "0.4" log = "0.4"
env_logger = { version = "0.7", default-features = false } env_logger = { version = "0.7", default-features = false }
rustc_middle = { path = "../librustc_middle" } rustc_middle = { path = "../librustc_middle" }

View File

@ -8,9 +8,6 @@
#![feature(nll)] #![feature(nll)]
#![recursion_limit = "256"] #![recursion_limit = "256"]
pub extern crate getopts;
#[cfg(unix)]
extern crate libc;
#[macro_use] #[macro_use]
extern crate log; extern crate log;
#[macro_use] #[macro_use]
@ -37,6 +34,7 @@ use rustc_save_analysis::DumpHandler;
use rustc_serialize::json::{self, ToJson}; use rustc_serialize::json::{self, ToJson};
use rustc_session::config::nightly_options; use rustc_session::config::nightly_options;
use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest}; use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest};
use rustc_session::getopts;
use rustc_session::lint::{Lint, LintId}; use rustc_session::lint::{Lint, LintId};
use rustc_session::{config, DiagnosticOutput, Session}; use rustc_session::{config, DiagnosticOutput, Session};
use rustc_session::{early_error, early_warn}; use rustc_session::{early_error, early_warn};

View File

@ -1,7 +1,4 @@
Cannot return value that references local variable A reference to a local variable was returned.
Local variables, function parameters and temporaries are all dropped before the
end of the function body. So a reference to them cannot be returned.
Erroneous code example: Erroneous code example:
@ -20,6 +17,9 @@ fn get_dangling_iterator<'a>() -> Iter<'a, i32> {
} }
``` ```
Local variables, function parameters and temporaries are all dropped before the
end of the function body. So a reference to them cannot be returned.
Consider returning an owned value instead: Consider returning an owned value instead:
``` ```

View File

@ -1,4 +1,5 @@
The `typeof` keyword is currently reserved but unimplemented. The `typeof` keyword is currently reserved but unimplemented.
Erroneous code example: Erroneous code example:
```compile_fail,E0516 ```compile_fail,E0516

View File

@ -1,6 +1,6 @@
//! Trait Resolution. See the [rustc guide] for more information on how this works. //! Trait Resolution. See the [rustc-dev-guide] for more information on how this works.
//! //!
//! [rustc guide]: https://rust-lang.github.io/rustc-guide/traits/resolution.html //! [rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org/traits/resolution.html
mod engine; mod engine;
pub mod error_reporting; pub mod error_reporting;

View File

@ -10,6 +10,7 @@ path = "lib.rs"
doctest = false doctest = false
[dependencies] [dependencies]
libc = "0.2"
log = "0.4" log = "0.4"
rayon = { version = "0.3.0", package = "rustc-rayon" } rayon = { version = "0.3.0", package = "rustc-rayon" }
smallvec = { version = "1.0", features = ["union", "may_dangle"] } smallvec = { version = "1.0", features = ["union", "may_dangle"] }

View File

@ -6,9 +6,6 @@
#![feature(generators)] #![feature(generators)]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#[cfg(unix)]
extern crate libc;
mod callbacks; mod callbacks;
pub mod interface; pub mod interface;
mod passes; mod passes;

View File

@ -1,5 +1,3 @@
extern crate getopts;
use crate::interface::parse_cfgspecs; use crate::interface::parse_cfgspecs;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
@ -9,6 +7,7 @@ use rustc_session::config::{build_configuration, build_session_options, to_crate
use rustc_session::config::{rustc_optgroups, ErrorOutputType, ExternLocation, Options, Passes}; use rustc_session::config::{rustc_optgroups, ErrorOutputType, ExternLocation, Options, Passes};
use rustc_session::config::{ExternEntry, LinkerPluginLto, LtoCli, SwitchWithOptPath}; use rustc_session::config::{ExternEntry, LinkerPluginLto, LtoCli, SwitchWithOptPath};
use rustc_session::config::{Externs, OutputType, OutputTypes, SymbolManglingVersion}; use rustc_session::config::{Externs, OutputType, OutputTypes, SymbolManglingVersion};
use rustc_session::getopts;
use rustc_session::lint::Level; use rustc_session::lint::Level;
use rustc_session::search_paths::SearchPath; use rustc_session::search_paths::SearchPath;
use rustc_session::{build_session, Session}; use rustc_session::{build_session, Session};

View File

@ -24,18 +24,28 @@ fn main() {
build_helper::restore_library_path(); build_helper::restore_library_path();
let target = env::var("TARGET").expect("TARGET was not set"); let target = env::var("TARGET").expect("TARGET was not set");
let llvm_config = env::var_os("LLVM_CONFIG").map(PathBuf::from).unwrap_or_else(|| { let llvm_config =
env::var_os("LLVM_CONFIG").map(|x| Some(PathBuf::from(x))).unwrap_or_else(|| {
if let Some(dir) = env::var_os("CARGO_TARGET_DIR").map(PathBuf::from) { if let Some(dir) = env::var_os("CARGO_TARGET_DIR").map(PathBuf::from) {
let to_test = let to_test = dir
dir.parent().unwrap().parent().unwrap().join(&target).join("llvm/bin/llvm-config"); .parent()
.unwrap()
.parent()
.unwrap()
.join(&target)
.join("llvm/bin/llvm-config");
if Command::new(&to_test).output().is_ok() { if Command::new(&to_test).output().is_ok() {
return to_test; return Some(to_test);
} }
} }
PathBuf::from("llvm-config") None
}); });
if let Some(llvm_config) = &llvm_config {
println!("cargo:rerun-if-changed={}", llvm_config.display()); println!("cargo:rerun-if-changed={}", llvm_config.display());
}
let llvm_config = llvm_config.unwrap_or_else(|| PathBuf::from("llvm-config"));
println!("cargo:rerun-if-env-changed=LLVM_CONFIG"); println!("cargo:rerun-if-env-changed=LLVM_CONFIG");
// Test whether we're cross-compiling LLVM. This is a pretty rare case // Test whether we're cross-compiling LLVM. This is a pretty rare case

View File

@ -11,6 +11,7 @@ doctest = false
[dependencies] [dependencies]
flate2 = "1.0" flate2 = "1.0"
libc = "0.2"
log = "0.4" log = "0.4"
memmap = "0.7" memmap = "0.7"
smallvec = { version = "1.0", features = ["union", "may_dangle"] } smallvec = { version = "1.0", features = ["union", "may_dangle"] }

View File

@ -10,7 +10,6 @@
#![feature(stmt_expr_attributes)] #![feature(stmt_expr_attributes)]
#![recursion_limit = "256"] #![recursion_limit = "256"]
extern crate libc;
extern crate proc_macro; extern crate proc_macro;
#[macro_use] #[macro_use]

View File

@ -9,6 +9,7 @@ name = "rustc_session"
path = "lib.rs" path = "lib.rs"
[dependencies] [dependencies]
getopts = "0.2"
log = "0.4" log = "0.4"
rustc_errors = { path = "../librustc_errors" } rustc_errors = { path = "../librustc_errors" }
rustc_feature = { path = "../librustc_feature" } rustc_feature = { path = "../librustc_feature" }

View File

@ -1,10 +1,4 @@
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]
#![feature(test)]
// Use the test crate here so we depend on getopts through it. This allow tools to link to both
// librustc_session and libtest.
extern crate getopts;
extern crate test as _;
pub mod cgu_reuse_tracker; pub mod cgu_reuse_tracker;
pub mod utils; pub mod utils;
@ -23,3 +17,5 @@ mod session;
pub use session::*; pub use session::*;
pub mod output; pub mod output;
pub use getopts;

View File

@ -1192,8 +1192,10 @@ impl SourceFile {
kind: src_kind @ ExternalSourceKind::AbsentOk, .. kind: src_kind @ ExternalSourceKind::AbsentOk, ..
} = &mut *external_src } = &mut *external_src
{ {
if let Some(src) = src { if let Some(mut src) = src {
// The src_hash needs to be computed on the pre-normalized src.
if self.src_hash.matches(&src) { if self.src_hash.matches(&src) {
normalize_src(&mut src, BytePos::from_usize(0));
*src_kind = ExternalSourceKind::Present(Lrc::new(src)); *src_kind = ExternalSourceKind::Present(Lrc::new(src));
return true; return true;
} }

View File

@ -168,6 +168,62 @@ fn span_merging_fail() {
assert!(sm.merge_spans(span1, span2).is_none()); assert!(sm.merge_spans(span1, span2).is_none());
} }
/// Tests loading an external source file that requires normalization.
#[test]
fn t10() {
let sm = SourceMap::new(FilePathMapping::empty());
let unnormalized = "first line.\r\nsecond line";
let normalized = "first line.\nsecond line";
let src_file = sm.new_source_file(PathBuf::from("blork.rs").into(), unnormalized.to_string());
assert_eq!(src_file.src.as_ref().unwrap().as_ref(), normalized);
assert!(
src_file.src_hash.matches(unnormalized),
"src_hash should use the source before normalization"
);
let SourceFile {
name,
name_was_remapped,
src_hash,
start_pos,
end_pos,
lines,
multibyte_chars,
non_narrow_chars,
normalized_pos,
name_hash,
..
} = (*src_file).clone();
let imported_src_file = sm.new_imported_source_file(
name,
name_was_remapped,
src_hash,
name_hash,
(end_pos - start_pos).to_usize(),
CrateNum::new(0),
lines,
multibyte_chars,
non_narrow_chars,
normalized_pos,
start_pos,
end_pos,
);
assert!(
imported_src_file.external_src.borrow().get_source().is_none(),
"imported source file should not have source yet"
);
imported_src_file.add_external_src(|| Some(unnormalized.to_string()));
assert_eq!(
imported_src_file.external_src.borrow().get_source().unwrap().as_ref(),
normalized,
"imported source file should be normalized"
);
}
/// Returns the span corresponding to the `n`th occurrence of `substring` in `source_text`. /// Returns the span corresponding to the `n`th occurrence of `substring` in `source_text`.
trait SourceMapExtension { trait SourceMapExtension {
fn span_substr( fn span_substr(

View File

@ -1153,12 +1153,20 @@ impl Interner {
} }
// This module has a very short name because it's used a lot. // This module has a very short name because it's used a lot.
/// This module contains all the defined keyword `Symbol`s.
///
/// Given that `kw` is imported, use them like `kw::keyword_name`.
/// For example `kw::Loop` or `kw::Break`.
pub mod kw { pub mod kw {
use super::Symbol; use super::Symbol;
keywords!(); keywords!();
} }
// This module has a very short name because it's used a lot. // This module has a very short name because it's used a lot.
/// This module contains all the defined non-keyword `Symbol`s.
///
/// Given that `sym` is imported, use them like `sym::symbol_name`.
/// For example `sym::rustfmt` or `sym::u8`.
#[allow(rustc::default_hash_types)] #[allow(rustc::default_hash_types)]
pub mod sym { pub mod sym {
use super::Symbol; use super::Symbol;

View File

@ -2,9 +2,9 @@
//! //!
//! - **Traits.** Trait resolution is implemented in the `traits` module. //! - **Traits.** Trait resolution is implemented in the `traits` module.
//! //!
//! For more information about how rustc works, see the [rustc guide]. //! For more information about how rustc works, see the [rustc-dev-guide].
//! //!
//! [rustc guide]: https://rust-lang.github.io/rustc-guide/ //! [rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org/
//! //!
//! # Note //! # Note
//! //!

View File

@ -10,6 +10,7 @@ use rustc_session::config::{
nightly_options, nightly_options,
}; };
use rustc_session::config::{CodegenOptions, DebuggingOptions, ErrorOutputType, Externs}; use rustc_session::config::{CodegenOptions, DebuggingOptions, ErrorOutputType, Externs};
use rustc_session::getopts;
use rustc_session::lint::Level; use rustc_session::lint::Level;
use rustc_session::search_paths::SearchPath; use rustc_session::search_paths::SearchPath;
use rustc_span::edition::{Edition, DEFAULT_EDITION}; use rustc_span::edition::{Edition, DEFAULT_EDITION};

View File

@ -15,7 +15,6 @@
#![recursion_limit = "256"] #![recursion_limit = "256"]
extern crate env_logger; extern crate env_logger;
extern crate getopts;
extern crate rustc_ast; extern crate rustc_ast;
extern crate rustc_ast_pretty; extern crate rustc_ast_pretty;
extern crate rustc_attr; extern crate rustc_attr;
@ -51,6 +50,7 @@ use std::panic;
use std::process; use std::process;
use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGroup}; use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGroup};
use rustc_session::getopts;
use rustc_session::{early_error, early_warn}; use rustc_session::{early_error, early_warn};
#[macro_use] #[macro_use]

View File

@ -47,7 +47,7 @@ hermit-abi = { version = "0.1.10", features = ['rustc-dep-of-std'] }
wasi = { version = "0.9.0", features = ['rustc-dep-of-std'], default-features = false } wasi = { version = "0.9.0", features = ['rustc-dep-of-std'], default-features = false }
[features] [features]
default = ["std_detect_file_io", "std_detect_dlsym_getauxval"] default = ["std_detect_file_io", "std_detect_dlsym_getauxval", "panic-unwind"]
backtrace = [ backtrace = [
"backtrace_rs/dbghelp", # backtrace/symbolize on MSVC "backtrace_rs/dbghelp", # backtrace/symbolize on MSVC