Skip to content

Commit d8d57f5

Browse files
author
Ayush Kumar Mishra
committed
Remove noisy suggestion of hash_map #72642
Update src/librustc_resolve/diagnostics.rs Co-authored-by: David Wood <[email protected]> Minor refactoring #72642 Fixed failing test-cases remove trivial `mk_predicate`s Make `SourceMap` available for early debug-printing of `Span`s Normally, we debug-print `Spans` using the `SourceMap` retrieved from the global `TyCtxt`. However, we fall back to printing out the `Span`'s raw fields (instead of a file and line number) when we try to print a `Span` before a `TyCtxt` is available. This makes debugging early phases of the compile, such as parsing, much more difficult. This commit stores a `SourceMap` in `rustc_span::GlOBALS` as a fallback. When a `TyCtxt` is not available, we try to retrieve one from `GLOBALS` - only if this is not available do we fall back to the raw field output. I'm not sure how to write a test for this - however, this can be verified locally by setting `RUSTC_LOG="rustc_parse=debug"`, and verifying that the output contains filenames and line numbers. Add test for #72554. rustc_target: Remove `pre_link_args_crt` Improve E0433, so that it suggests missing imports Fix a typo in `late.rs` Co-authored-by: Esteban Kuber <[email protected]> fix `AdtDef` docs Add Camelid Email from @camelid: > HI there, > > I’m a new contributor and I just looked at Rust Thanks and noticed that my contributions are listed under two different capitalizations of my name: “Camelid" and “camelid". Could you make them both “Camelid"? > > Thanks! > > Camelid save_analysis: work on HIR tree instead of AST Update `rls` submodule remove outdated fixme Hexagon libstd: fix typo for c_ulonglong Add more assert to Vec with_capacity docs Show assertion on len too to show them how adding new items will affect both the length and capacity, before and after. Add Kyle Strand to mailmap Fix missing word in RELEASES.md Update cargo Enable lld for Cargo tests on Windows. Fixed failing test-cases #72642
1 parent 8439e58 commit d8d57f5

File tree

39 files changed

+1238
-1152
lines changed

39 files changed

+1238
-1152
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ jobs:
442442
- name: x86_64-msvc-cargo
443443
env:
444444
SCRIPT: python x.py test src/tools/cargotest src/tools/cargo
445-
RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-msvc"
445+
RUST_CONFIGURE_ARGS: "--build=x86_64-pc-windows-msvc --enable-lld"
446446
VCVARS_BAT: vcvars64.bat
447447
NO_DEBUG_ASSERTIONS: 1
448448
NO_LLVM_ASSERTIONS: 1

.mailmap

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Brian Anderson <[email protected]> <[email protected]>
4444
4545
Brian Dawn <[email protected]>
4646
Brian Leibig <[email protected]> Brian Leibig <[email protected]>
47+
4748
Carl-Anton Ingmarsson <[email protected]> <[email protected]>
4849
Carol (Nichols || Goulding) <[email protected]> <[email protected]>
4950
Carol (Nichols || Goulding) <[email protected]> <[email protected]>
@@ -152,6 +153,10 @@ Kang Seonghoon <[email protected]> <[email protected]>
152153
153154
Kevin Butler <[email protected]>
154155
Kyeongwoon Lee <[email protected]>
156+
157+
158+
159+
155160
Laurențiu Nicola <[email protected]>
156161
Lee Jeffery <[email protected]> Lee Jeffery <[email protected]>
157162
Lee Wondong <[email protected]>

RELEASES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Compatibility Notes
100100
- [Removed the `-C no_integrated_as` flag from rustc.][70345]
101101
- [The `file_name` property in JSON output of macro errors now points the actual
102102
source file rather than the previous format of `<NAME macros>`.][70969]
103-
**Note:** this may not point a file that actually exists on the user's system.
103+
**Note:** this may not point to a file that actually exists on the user's system.
104104
- [The minimum required external LLVM version has been bumped to LLVM 8.][71147]
105105
- [`mem::{zeroed, uninitialised}` will now panic when used with types that do
106106
not allow zero initialization such as `NonZeroU8`.][66059] This was

src/ci/azure-pipelines/auto.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ jobs:
148148
INITIAL_RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc
149149
x86_64-msvc-cargo:
150150
SCRIPT: python x.py test src/tools/cargotest src/tools/cargo
151-
INITIAL_RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc
151+
INITIAL_RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-lld
152152
VCVARS_BAT: vcvars64.bat
153153
# FIXME(#59637)
154154
NO_DEBUG_ASSERTIONS: 1

src/ci/github-actions/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ jobs:
505505
- name: x86_64-msvc-cargo
506506
env:
507507
SCRIPT: python x.py test src/tools/cargotest src/tools/cargo
508-
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc
508+
RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-lld
509509
VCVARS_BAT: vcvars64.bat
510510
# FIXME(#59637)
511511
NO_DEBUG_ASSERTIONS: 1

src/liballoc/vec.rs

+3
Original file line numberDiff line numberDiff line change
@@ -343,15 +343,18 @@ impl<T> Vec<T> {
343343
///
344344
/// // The vector contains no items, even though it has capacity for more
345345
/// assert_eq!(vec.len(), 0);
346+
/// assert_eq!(vec.capacity(), 10);
346347
///
347348
/// // These are all done without reallocating...
348349
/// for i in 0..10 {
349350
/// vec.push(i);
350351
/// }
352+
/// assert_eq!(vec.len(), 10);
351353
/// assert_eq!(vec.capacity(), 10);
352354
///
353355
/// // ...but this may make the vector reallocate
354356
/// vec.push(11);
357+
/// assert_eq!(vec.len(), 11);
355358
/// assert!(vec.capacity() >= 11);
356359
/// ```
357360
#[inline]

src/librustc_codegen_ssa/back/link.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -1253,20 +1253,10 @@ fn add_post_link_objects(
12531253

12541254
/// Add arbitrary "pre-link" args defined by the target spec or from command line.
12551255
/// FIXME: Determine where exactly these args need to be inserted.
1256-
fn add_pre_link_args(
1257-
cmd: &mut dyn Linker,
1258-
sess: &Session,
1259-
flavor: LinkerFlavor,
1260-
crate_type: CrateType,
1261-
) {
1256+
fn add_pre_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
12621257
if let Some(args) = sess.target.target.options.pre_link_args.get(&flavor) {
12631258
cmd.args(args);
12641259
}
1265-
if let Some(args) = sess.target.target.options.pre_link_args_crt.get(&flavor) {
1266-
if sess.crt_static(Some(crate_type)) {
1267-
cmd.args(args);
1268-
}
1269-
}
12701260
cmd.args(&sess.opts.debugging_opts.pre_link_args);
12711261
}
12721262

@@ -1502,7 +1492,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
15021492
let crt_objects_fallback = crt_objects_fallback(sess, crate_type);
15031493

15041494
// NO-OPT-OUT, OBJECT-FILES-MAYBE, CUSTOMIZATION-POINT
1505-
add_pre_link_args(cmd, sess, flavor, crate_type);
1495+
add_pre_link_args(cmd, sess, flavor);
15061496

15071497
// NO-OPT-OUT
15081498
add_link_script(cmd, sess, tmpdir, crate_type);

src/librustc_codegen_ssa/back/linker.rs

+15
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,21 @@ impl<'a> Linker for GccLinker<'a> {
315315
self.build_dylib(out_filename);
316316
}
317317
}
318+
// VxWorks compiler driver introduced `--static-crt` flag specifically for rustc,
319+
// it switches linking for libc and similar system libraries to static without using
320+
// any `#[link]` attributes in the `libc` crate, see #72782 for details.
321+
// FIXME: Switch to using `#[link]` attributes in the `libc` crate
322+
// similarly to other targets.
323+
if self.sess.target.target.target_os == "vxworks"
324+
&& matches!(
325+
output_kind,
326+
LinkOutputKind::StaticNoPicExe
327+
| LinkOutputKind::StaticPicExe
328+
| LinkOutputKind::StaticDylib
329+
)
330+
{
331+
self.cmd.arg("--static-crt");
332+
}
318333
}
319334

320335
fn link_dylib(&mut self, lib: Symbol) {

src/librustc_driver/lib.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -346,20 +346,22 @@ pub fn run_compiler(
346346

347347
queries.global_ctxt()?;
348348

349+
// Drop AST after creating GlobalCtxt to free memory
350+
let _timer = sess.prof.generic_activity("drop_ast");
351+
mem::drop(queries.expansion()?.take());
352+
349353
if sess.opts.debugging_opts.no_analysis || sess.opts.debugging_opts.ast_json {
350354
return early_exit();
351355
}
352356

353357
if sess.opts.debugging_opts.save_analysis {
354-
let expanded_crate = &queries.expansion()?.peek().0;
355358
let crate_name = queries.crate_name()?.peek().clone();
356359
queries.global_ctxt()?.peek_mut().enter(|tcx| {
357360
let result = tcx.analysis(LOCAL_CRATE);
358361

359362
sess.time("save_analysis", || {
360363
save::process_crate(
361364
tcx,
362-
&expanded_crate,
363365
&crate_name,
364366
&compiler.input(),
365367
None,
@@ -371,13 +373,7 @@ pub fn run_compiler(
371373
});
372374

373375
result
374-
// AST will be dropped *after* the `after_analysis` callback
375-
// (needed by the RLS)
376376
})?;
377-
} else {
378-
// Drop AST after creating GlobalCtxt to free memory
379-
let _timer = sess.prof.generic_activity("drop_ast");
380-
mem::drop(queries.expansion()?.take());
381377
}
382378

383379
queries.global_ctxt()?.peek_mut().enter(|tcx| tcx.analysis(LOCAL_CRATE))?;
@@ -386,10 +382,6 @@ pub fn run_compiler(
386382
return early_exit();
387383
}
388384

389-
if sess.opts.debugging_opts.save_analysis {
390-
mem::drop(queries.expansion()?.take());
391-
}
392-
393385
queries.ongoing_codegen()?;
394386

395387
if sess.opts.debugging_opts.print_type_sizes {

src/librustc_hir_pretty/lib.rs

+24
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,30 @@ pub fn visibility_qualified<S: Into<Cow<'static, str>>>(vis: &hir::Visibility<'_
203203
})
204204
}
205205

206+
pub fn generic_params_to_string(generic_params: &[GenericParam<'_>]) -> String {
207+
to_string(NO_ANN, |s| s.print_generic_params(generic_params))
208+
}
209+
210+
pub fn bounds_to_string<'b>(bounds: impl IntoIterator<Item = &'b hir::GenericBound<'b>>) -> String {
211+
to_string(NO_ANN, |s| s.print_bounds("", bounds))
212+
}
213+
214+
pub fn param_to_string(arg: &hir::Param<'_>) -> String {
215+
to_string(NO_ANN, |s| s.print_param(arg))
216+
}
217+
218+
pub fn ty_to_string(ty: &hir::Ty<'_>) -> String {
219+
to_string(NO_ANN, |s| s.print_type(ty))
220+
}
221+
222+
pub fn path_segment_to_string(segment: &hir::PathSegment<'_>) -> String {
223+
to_string(NO_ANN, |s| s.print_path_segment(segment))
224+
}
225+
226+
pub fn path_to_string(segment: &hir::Path<'_>) -> String {
227+
to_string(NO_ANN, |s| s.print_path(segment, false))
228+
}
229+
206230
impl<'a> State<'a> {
207231
pub fn cbox(&mut self, u: usize) {
208232
self.s.cbox(u);

src/librustc_interface/interface.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,19 @@ pub fn run_compiler_in_existing_thread_pool<R>(
186186
override_queries: config.override_queries,
187187
};
188188

189-
let r = {
190-
let _sess_abort_error = OnDrop(|| {
191-
compiler.sess.finish_diagnostics(registry);
192-
});
193-
194-
f(&compiler)
195-
};
196-
197-
let prof = compiler.sess.prof.clone();
198-
prof.generic_activity("drop_compiler").run(move || drop(compiler));
199-
r
189+
rustc_span::with_source_map(compiler.sess.parse_sess.clone_source_map(), move || {
190+
let r = {
191+
let _sess_abort_error = OnDrop(|| {
192+
compiler.sess.finish_diagnostics(registry);
193+
});
194+
195+
f(&compiler)
196+
};
197+
198+
let prof = compiler.sess.prof.clone();
199+
prof.generic_activity("drop_compiler").run(move || drop(compiler));
200+
r
201+
})
200202
}
201203

202204
pub fn run_compiler<R: Send>(mut config: Config, f: impl FnOnce(&Compiler) -> R + Send) -> R {

src/librustc_middle/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1846,7 +1846,7 @@ pub struct FieldDef {
18461846

18471847
/// The definition of a user-defined type, e.g., a `struct`, `enum`, or `union`.
18481848
///
1849-
/// These are all interned (by `intern_adt_def`) into the `adt_defs` table.
1849+
/// These are all interned (by `alloc_adt_def`) into the global arena.
18501850
///
18511851
/// The initialism *ADT* stands for an [*algebraic data type (ADT)*][adt].
18521852
/// This is slightly wrong because `union`s are not ADTs.

src/librustc_middle/ty/structural_impls.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,8 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> {
987987

988988
impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
989989
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
990-
folder.tcx().mk_predicate(ty::PredicateKind::super_fold_with(self.kind, folder))
990+
let new = ty::PredicateKind::super_fold_with(self.kind, folder);
991+
if new != *self.kind { folder.tcx().mk_predicate(new) } else { *self }
991992
}
992993

993994
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {

src/librustc_resolve/diagnostics.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,9 @@ impl<'a> Resolver<'a> {
680680
Res::Def(DefKind::Ctor(..), did) => this.parent(did),
681681
_ => res.opt_def_id(),
682682
};
683-
candidates.push(ImportSuggestion { did, descr: res.descr(), path });
683+
if candidates.iter().all(|v: &ImportSuggestion| v.did != did) {
684+
candidates.push(ImportSuggestion { did, descr: res.descr(), path });
685+
}
684686
}
685687
}
686688
}
@@ -1475,7 +1477,7 @@ crate fn show_candidates(
14751477
// This is `None` if all placement locations are inside expansions
14761478
use_placement_span: Option<Span>,
14771479
candidates: &[ImportSuggestion],
1478-
better: bool,
1480+
instead: bool,
14791481
found_use: bool,
14801482
) {
14811483
if candidates.is_empty() {
@@ -1486,6 +1488,7 @@ crate fn show_candidates(
14861488
// by iterating through a hash map, so make sure they are ordered:
14871489
let mut path_strings: Vec<_> =
14881490
candidates.iter().map(|c| path_names_to_string(&c.path)).collect();
1491+
14891492
path_strings.sort();
14901493
path_strings.dedup();
14911494

@@ -1494,8 +1497,9 @@ crate fn show_candidates(
14941497
} else {
14951498
("one of these", "items")
14961499
};
1497-
let instead = if better { " instead" } else { "" };
1498-
let msg = format!("consider importing {} {}{}", determiner, kind, instead);
1500+
1501+
let instead = if instead { " instead" } else { "" };
1502+
let mut msg = format!("consider importing {} {}{}", determiner, kind, instead);
14991503

15001504
if let Some(span) = use_placement_span {
15011505
for candidate in &mut path_strings {
@@ -1507,12 +1511,13 @@ crate fn show_candidates(
15071511

15081512
err.span_suggestions(span, &msg, path_strings.into_iter(), Applicability::Unspecified);
15091513
} else {
1510-
let mut msg = msg;
15111514
msg.push(':');
1515+
15121516
for candidate in path_strings {
15131517
msg.push('\n');
15141518
msg.push_str(&candidate);
15151519
}
1520+
15161521
err.note(&msg);
15171522
}
15181523
}

0 commit comments

Comments
 (0)