Skip to content

Commit 3712e11

Browse files
committed
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
2 parents 4d1fbac + e684630 commit 3712e11

File tree

25 files changed

+118
-40
lines changed

25 files changed

+118
-40
lines changed

Cargo.lock

+5
Original file line numberDiff line numberDiff line change
@@ -3694,6 +3694,7 @@ dependencies = [
36943694
"indexmap",
36953695
"jobserver",
36963696
"lazy_static 1.4.0",
3697+
"libc",
36973698
"log",
36983699
"measureme",
36993700
"parking_lot 0.10.0",
@@ -3713,6 +3714,7 @@ version = "0.0.0"
37133714
dependencies = [
37143715
"env_logger 0.7.1",
37153716
"lazy_static 1.4.0",
3717+
"libc",
37163718
"log",
37173719
"rustc_ast",
37183720
"rustc_ast_pretty",
@@ -3867,6 +3869,7 @@ dependencies = [
38673869
name = "rustc_interface"
38683870
version = "0.0.0"
38693871
dependencies = [
3872+
"libc",
38703873
"log",
38713874
"once_cell",
38723875
"rustc-rayon",
@@ -3960,6 +3963,7 @@ name = "rustc_metadata"
39603963
version = "0.0.0"
39613964
dependencies = [
39623965
"flate2",
3966+
"libc",
39633967
"log",
39643968
"memmap",
39653969
"rustc_ast",
@@ -4197,6 +4201,7 @@ dependencies = [
41974201
name = "rustc_session"
41984202
version = "0.0.0"
41994203
dependencies = [
4204+
"getopts",
42004205
"log",
42014206
"num_cpus",
42024207
"rustc_ast",

src/bootstrap/compile.rs

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

src/libprofiler_builtins/build.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ fn main() {
6363
cfg.define("COMPILER_RT_HAS_ATOMICS", Some("1"));
6464
}
6565

66-
let root = env::var_os("RUST_COMPILER_RT_ROOT").unwrap();
67-
let root = Path::new(&root);
66+
// Note that this should exist if we're going to run (otherwise we just
67+
// don't build profiler builtins at all).
68+
let root = Path::new("../llvm-project/compiler-rt");
6869

6970
let src_root = root.join("lib").join("profile");
7071
for src in profile_sources {

src/librustc_data_structures/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ smallvec = { version = "1.0", features = ["union", "may_dangle"] }
2727
rustc_index = { path = "../librustc_index", package = "rustc_index" }
2828
bitflags = "1.2.1"
2929
measureme = "0.7.1"
30+
libc = "0.2"
3031

3132
[dependencies.parking_lot]
3233
version = "0.10"

src/librustc_data_structures/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626

2727
#[macro_use]
2828
extern crate log;
29-
#[cfg(unix)]
30-
extern crate libc;
3129
#[macro_use]
3230
extern crate cfg_if;
3331

src/librustc_driver/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ crate-type = ["dylib"]
1111

1212
[dependencies]
1313
lazy_static = "1.0"
14+
libc = "0.2"
1415
log = "0.4"
1516
env_logger = { version = "0.7", default-features = false }
1617
rustc_middle = { path = "../librustc_middle" }

src/librustc_driver/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
#![feature(nll)]
99
#![recursion_limit = "256"]
1010

11-
pub extern crate getopts;
12-
#[cfg(unix)]
13-
extern crate libc;
1411
#[macro_use]
1512
extern crate log;
1613
#[macro_use]
@@ -37,6 +34,7 @@ use rustc_save_analysis::DumpHandler;
3734
use rustc_serialize::json::{self, ToJson};
3835
use rustc_session::config::nightly_options;
3936
use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest};
37+
use rustc_session::getopts;
4038
use rustc_session::lint::{Lint, LintId};
4139
use rustc_session::{config, DiagnosticOutput, Session};
4240
use rustc_session::{early_error, early_warn};

src/librustc_error_codes/error_codes/E0515.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
Cannot return value that references local variable
2-
3-
Local variables, function parameters and temporaries are all dropped before the
4-
end of the function body. So a reference to them cannot be returned.
1+
A reference to a local variable was returned.
52

63
Erroneous code example:
74

@@ -20,6 +17,9 @@ fn get_dangling_iterator<'a>() -> Iter<'a, i32> {
2017
}
2118
```
2219

20+
Local variables, function parameters and temporaries are all dropped before the
21+
end of the function body. So a reference to them cannot be returned.
22+
2323
Consider returning an owned value instead:
2424

2525
```

src/librustc_error_codes/error_codes/E0516.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
The `typeof` keyword is currently reserved but unimplemented.
2+
23
Erroneous code example:
34

45
```compile_fail,E0516

src/librustc_infer/traits/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//! Trait Resolution. See the [rustc guide] for more information on how this works.
1+
//! Trait Resolution. See the [rustc-dev-guide] for more information on how this works.
22
//!
3-
//! [rustc guide]: https://rust-lang.github.io/rustc-guide/traits/resolution.html
3+
//! [rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org/traits/resolution.html
44
55
mod engine;
66
pub mod error_reporting;

src/librustc_interface/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ path = "lib.rs"
1010
doctest = false
1111

1212
[dependencies]
13+
libc = "0.2"
1314
log = "0.4"
1415
rayon = { version = "0.3.0", package = "rustc-rayon" }
1516
smallvec = { version = "1.0", features = ["union", "may_dangle"] }

src/librustc_interface/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
#![feature(generators)]
77
#![recursion_limit = "256"]
88

9-
#[cfg(unix)]
10-
extern crate libc;
11-
129
mod callbacks;
1310
pub mod interface;
1411
mod passes;

src/librustc_interface/tests.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate getopts;
2-
31
use crate::interface::parse_cfgspecs;
42

53
use rustc_data_structures::fx::FxHashSet;
@@ -9,6 +7,7 @@ use rustc_session::config::{build_configuration, build_session_options, to_crate
97
use rustc_session::config::{rustc_optgroups, ErrorOutputType, ExternLocation, Options, Passes};
108
use rustc_session::config::{ExternEntry, LinkerPluginLto, LtoCli, SwitchWithOptPath};
119
use rustc_session::config::{Externs, OutputType, OutputTypes, SymbolManglingVersion};
10+
use rustc_session::getopts;
1211
use rustc_session::lint::Level;
1312
use rustc_session::search_paths::SearchPath;
1413
use rustc_session::{build_session, Session};

src/librustc_llvm/build.rs

+20-10
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,28 @@ fn main() {
2424
build_helper::restore_library_path();
2525

2626
let target = env::var("TARGET").expect("TARGET was not set");
27-
let llvm_config = env::var_os("LLVM_CONFIG").map(PathBuf::from).unwrap_or_else(|| {
28-
if let Some(dir) = env::var_os("CARGO_TARGET_DIR").map(PathBuf::from) {
29-
let to_test =
30-
dir.parent().unwrap().parent().unwrap().join(&target).join("llvm/bin/llvm-config");
31-
if Command::new(&to_test).output().is_ok() {
32-
return to_test;
27+
let llvm_config =
28+
env::var_os("LLVM_CONFIG").map(|x| Some(PathBuf::from(x))).unwrap_or_else(|| {
29+
if let Some(dir) = env::var_os("CARGO_TARGET_DIR").map(PathBuf::from) {
30+
let to_test = dir
31+
.parent()
32+
.unwrap()
33+
.parent()
34+
.unwrap()
35+
.join(&target)
36+
.join("llvm/bin/llvm-config");
37+
if Command::new(&to_test).output().is_ok() {
38+
return Some(to_test);
39+
}
3340
}
34-
}
35-
PathBuf::from("llvm-config")
36-
});
41+
None
42+
});
43+
44+
if let Some(llvm_config) = &llvm_config {
45+
println!("cargo:rerun-if-changed={}", llvm_config.display());
46+
}
47+
let llvm_config = llvm_config.unwrap_or_else(|| PathBuf::from("llvm-config"));
3748

38-
println!("cargo:rerun-if-changed={}", llvm_config.display());
3949
println!("cargo:rerun-if-env-changed=LLVM_CONFIG");
4050

4151
// Test whether we're cross-compiling LLVM. This is a pretty rare case

src/librustc_metadata/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ doctest = false
1111

1212
[dependencies]
1313
flate2 = "1.0"
14+
libc = "0.2"
1415
log = "0.4"
1516
memmap = "0.7"
1617
smallvec = { version = "1.0", features = ["union", "may_dangle"] }

src/librustc_metadata/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#![feature(stmt_expr_attributes)]
1111
#![recursion_limit = "256"]
1212

13-
extern crate libc;
1413
extern crate proc_macro;
1514

1615
#[macro_use]

src/librustc_session/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ name = "rustc_session"
99
path = "lib.rs"
1010

1111
[dependencies]
12+
getopts = "0.2"
1213
log = "0.4"
1314
rustc_errors = { path = "../librustc_errors" }
1415
rustc_feature = { path = "../librustc_feature" }

src/librustc_session/lib.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
#![feature(crate_visibility_modifier)]
2-
#![feature(test)]
3-
4-
// Use the test crate here so we depend on getopts through it. This allow tools to link to both
5-
// librustc_session and libtest.
6-
extern crate getopts;
7-
extern crate test as _;
82

93
pub mod cgu_reuse_tracker;
104
pub mod utils;
@@ -23,3 +17,5 @@ mod session;
2317
pub use session::*;
2418

2519
pub mod output;
20+
21+
pub use getopts;

src/librustc_span/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1192,8 +1192,10 @@ impl SourceFile {
11921192
kind: src_kind @ ExternalSourceKind::AbsentOk, ..
11931193
} = &mut *external_src
11941194
{
1195-
if let Some(src) = src {
1195+
if let Some(mut src) = src {
1196+
// The src_hash needs to be computed on the pre-normalized src.
11961197
if self.src_hash.matches(&src) {
1198+
normalize_src(&mut src, BytePos::from_usize(0));
11971199
*src_kind = ExternalSourceKind::Present(Lrc::new(src));
11981200
return true;
11991201
}

src/librustc_span/source_map/tests.rs

+56
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,62 @@ fn span_merging_fail() {
168168
assert!(sm.merge_spans(span1, span2).is_none());
169169
}
170170

171+
/// Tests loading an external source file that requires normalization.
172+
#[test]
173+
fn t10() {
174+
let sm = SourceMap::new(FilePathMapping::empty());
175+
let unnormalized = "first line.\r\nsecond line";
176+
let normalized = "first line.\nsecond line";
177+
178+
let src_file = sm.new_source_file(PathBuf::from("blork.rs").into(), unnormalized.to_string());
179+
180+
assert_eq!(src_file.src.as_ref().unwrap().as_ref(), normalized);
181+
assert!(
182+
src_file.src_hash.matches(unnormalized),
183+
"src_hash should use the source before normalization"
184+
);
185+
186+
let SourceFile {
187+
name,
188+
name_was_remapped,
189+
src_hash,
190+
start_pos,
191+
end_pos,
192+
lines,
193+
multibyte_chars,
194+
non_narrow_chars,
195+
normalized_pos,
196+
name_hash,
197+
..
198+
} = (*src_file).clone();
199+
200+
let imported_src_file = sm.new_imported_source_file(
201+
name,
202+
name_was_remapped,
203+
src_hash,
204+
name_hash,
205+
(end_pos - start_pos).to_usize(),
206+
CrateNum::new(0),
207+
lines,
208+
multibyte_chars,
209+
non_narrow_chars,
210+
normalized_pos,
211+
start_pos,
212+
end_pos,
213+
);
214+
215+
assert!(
216+
imported_src_file.external_src.borrow().get_source().is_none(),
217+
"imported source file should not have source yet"
218+
);
219+
imported_src_file.add_external_src(|| Some(unnormalized.to_string()));
220+
assert_eq!(
221+
imported_src_file.external_src.borrow().get_source().unwrap().as_ref(),
222+
normalized,
223+
"imported source file should be normalized"
224+
);
225+
}
226+
171227
/// Returns the span corresponding to the `n`th occurrence of `substring` in `source_text`.
172228
trait SourceMapExtension {
173229
fn span_substr(

src/librustc_span/symbol.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1153,12 +1153,20 @@ impl Interner {
11531153
}
11541154

11551155
// This module has a very short name because it's used a lot.
1156+
/// This module contains all the defined keyword `Symbol`s.
1157+
///
1158+
/// Given that `kw` is imported, use them like `kw::keyword_name`.
1159+
/// For example `kw::Loop` or `kw::Break`.
11561160
pub mod kw {
11571161
use super::Symbol;
11581162
keywords!();
11591163
}
11601164

11611165
// This module has a very short name because it's used a lot.
1166+
/// This module contains all the defined non-keyword `Symbol`s.
1167+
///
1168+
/// Given that `sym` is imported, use them like `sym::symbol_name`.
1169+
/// For example `sym::rustfmt` or `sym::u8`.
11621170
#[allow(rustc::default_hash_types)]
11631171
pub mod sym {
11641172
use super::Symbol;

src/librustc_trait_selection/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
//!
33
//! - **Traits.** Trait resolution is implemented in the `traits` module.
44
//!
5-
//! For more information about how rustc works, see the [rustc guide].
5+
//! For more information about how rustc works, see the [rustc-dev-guide].
66
//!
7-
//! [rustc guide]: https://rust-lang.github.io/rustc-guide/
7+
//! [rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org/
88
//!
99
//! # Note
1010
//!

src/librustdoc/config.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_session::config::{
1010
nightly_options,
1111
};
1212
use rustc_session::config::{CodegenOptions, DebuggingOptions, ErrorOutputType, Externs};
13+
use rustc_session::getopts;
1314
use rustc_session::lint::Level;
1415
use rustc_session::search_paths::SearchPath;
1516
use rustc_span::edition::{Edition, DEFAULT_EDITION};

src/librustdoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#![recursion_limit = "256"]
1616

1717
extern crate env_logger;
18-
extern crate getopts;
1918
extern crate rustc_ast;
2019
extern crate rustc_ast_pretty;
2120
extern crate rustc_attr;
@@ -51,6 +50,7 @@ use std::panic;
5150
use std::process;
5251

5352
use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGroup};
53+
use rustc_session::getopts;
5454
use rustc_session::{early_error, early_warn};
5555

5656
#[macro_use]

src/libstd/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ hermit-abi = { version = "0.1.10", features = ['rustc-dep-of-std'] }
4747
wasi = { version = "0.9.0", features = ['rustc-dep-of-std'], default-features = false }
4848

4949
[features]
50-
default = ["std_detect_file_io", "std_detect_dlsym_getauxval"]
50+
default = ["std_detect_file_io", "std_detect_dlsym_getauxval", "panic-unwind"]
5151

5252
backtrace = [
5353
"backtrace_rs/dbghelp", # backtrace/symbolize on MSVC

0 commit comments

Comments
 (0)