authorbors <bors@rust-lang.org> 2026-01-20 14:42:53 UTC
committerbors <bors@rust-lang.org> 2026-01-20 14:42:53 UTC
log5c49c4f7c8393c861b849441d27f5d40e0f1e33b
tree2520d2a97b074878a50401806b89ac9e5fa05de7
parentfffc4fcf96b30bc838551de5104d74f82400b35b
parent83ce00e35eb310973b0407388c56ed677fa3dc04

Auto merge of #151409 - GuillaumeGomez:rollup-bDqwVwM, r=GuillaumeGomez

Rollup of 6 pull requests Successful merges: - rust-lang/rust#147611 (Stabilize `-Zremap-path-scope`) - rust-lang/rust#149058 (FCW Lint when using an ambiguously glob imported trait) - rust-lang/rust#149644 (Create x86_64-unknown-linux-gnuasan target which enables ASAN by default) - rust-lang/rust#150524 (Test that -Zbuild-std=core works on a variety of profiles) - rust-lang/rust#151394 (Fix typos: 'occured' -> 'occurred' and 'non_existant' -> 'non_existent') - rust-lang/rust#151396 (`rustc_queries!`: Don't push the `(cache)` modifier twice) r? @ghost

67 files changed, 880 insertions(+), 140 deletions(-)

Cargo.lock+1
......@@ -3337,6 +3337,7 @@ dependencies = [
33373337 "rustdoc-json-types",
33383338 "serde_json",
33393339 "similar",
3340 "tempfile",
33403341 "wasmparser 0.236.1",
33413342]
33423343
compiler/rustc_hir/src/hir.rs+5
......@@ -4615,6 +4615,11 @@ pub struct Upvar {
46154615pub struct TraitCandidate {
46164616 pub def_id: DefId,
46174617 pub import_ids: SmallVec<[LocalDefId; 1]>,
4618 // Indicates whether this trait candidate is ambiguously glob imported
4619 // in it's scope. Related to the AMBIGUOUS_GLOB_IMPORTED_TRAITS lint.
4620 // If this is set to true and the trait is used as a result of method lookup, this
4621 // lint is thrown.
4622 pub lint_ambiguous: bool,
46184623}
46194624
46204625#[derive(Copy, Clone, Debug, HashStable_Generic)]
compiler/rustc_hir_typeck/src/method/confirm.rs+27-2
......@@ -1,3 +1,4 @@
1use std::fmt::Debug;
12use std::ops::Deref;
23
34use rustc_hir as hir;
......@@ -12,7 +13,9 @@ use rustc_hir_analysis::hir_ty_lowering::{
1213use rustc_infer::infer::{
1314 BoundRegionConversionTime, DefineOpaqueTypes, InferOk, RegionVariableOrigin,
1415};
15use rustc_lint::builtin::RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS;
16use rustc_lint::builtin::{
17 AMBIGUOUS_GLOB_IMPORTED_TRAITS, RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS,
18};
1619use rustc_middle::traits::ObligationCauseCode;
1720use rustc_middle::ty::adjustment::{
1821 Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCoercion,
......@@ -149,6 +152,9 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
149152 // Lint when an item is shadowing a supertrait item.
150153 self.lint_shadowed_supertrait_items(pick, segment);
151154
155 // Lint when a trait is ambiguously imported
156 self.lint_ambiguously_glob_imported_traits(pick, segment);
157
152158 // Add any trait/regions obligations specified on the method's type parameters.
153159 // We won't add these if we encountered an illegal sized bound, so that we can use
154160 // a custom error in that case.
......@@ -322,7 +328,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
322328 })
323329 }
324330
325 probe::TraitPick => {
331 probe::TraitPick(_) => {
326332 let trait_def_id = pick.item.container_id(self.tcx);
327333
328334 // Make a trait reference `$0 : Trait<$1...$n>`
......@@ -719,6 +725,25 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
719725 );
720726 }
721727
728 fn lint_ambiguously_glob_imported_traits(
729 &self,
730 pick: &probe::Pick<'_>,
731 segment: &hir::PathSegment<'tcx>,
732 ) {
733 if pick.kind != probe::PickKind::TraitPick(true) {
734 return;
735 }
736 let trait_name = self.tcx.item_name(pick.item.container_id(self.tcx));
737 let import_span = self.tcx.hir_span_if_local(pick.import_ids[0].to_def_id()).unwrap();
738
739 self.tcx.node_lint(AMBIGUOUS_GLOB_IMPORTED_TRAITS, segment.hir_id, |diag| {
740 diag.primary_message(format!("Use of ambiguously glob imported trait `{trait_name}`"))
741 .span(segment.ident.span)
742 .span_label(import_span, format!("`{trait_name}` imported ambiguously here"))
743 .help(format!("Import `{trait_name}` explicitly"));
744 });
745 }
746
722747 fn upcast(
723748 &mut self,
724749 source_trait_ref: ty::PolyTraitRef<'tcx>,
compiler/rustc_hir_typeck/src/method/probe.rs+34-12
......@@ -106,7 +106,7 @@ pub(crate) struct Candidate<'tcx> {
106106pub(crate) enum CandidateKind<'tcx> {
107107 InherentImplCandidate { impl_def_id: DefId, receiver_steps: usize },
108108 ObjectCandidate(ty::PolyTraitRef<'tcx>),
109 TraitCandidate(ty::PolyTraitRef<'tcx>),
109 TraitCandidate(ty::PolyTraitRef<'tcx>, bool /* lint_ambiguous */),
110110 WhereClauseCandidate(ty::PolyTraitRef<'tcx>),
111111}
112112
......@@ -235,7 +235,10 @@ pub(crate) struct Pick<'tcx> {
235235pub(crate) enum PickKind<'tcx> {
236236 InherentImplPick,
237237 ObjectPick,
238 TraitPick,
238 TraitPick(
239 // Is Ambiguously Imported
240 bool,
241 ),
239242 WhereClausePick(
240243 // Trait
241244 ty::PolyTraitRef<'tcx>,
......@@ -560,7 +563,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
560563 probe_cx.push_candidate(
561564 Candidate {
562565 item,
563 kind: CandidateKind::TraitCandidate(ty::Binder::dummy(trait_ref)),
566 kind: CandidateKind::TraitCandidate(
567 ty::Binder::dummy(trait_ref),
568 false,
569 ),
564570 import_ids: smallvec![],
565571 },
566572 false,
......@@ -1018,6 +1024,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10181024 self.assemble_extension_candidates_for_trait(
10191025 &trait_candidate.import_ids,
10201026 trait_did,
1027 trait_candidate.lint_ambiguous,
10211028 );
10221029 }
10231030 }
......@@ -1029,7 +1036,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10291036 let mut duplicates = FxHashSet::default();
10301037 for trait_info in suggest::all_traits(self.tcx) {
10311038 if duplicates.insert(trait_info.def_id) {
1032 self.assemble_extension_candidates_for_trait(&smallvec![], trait_info.def_id);
1039 self.assemble_extension_candidates_for_trait(
1040 &smallvec![],
1041 trait_info.def_id,
1042 false,
1043 );
10331044 }
10341045 }
10351046 }
......@@ -1055,6 +1066,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10551066 &mut self,
10561067 import_ids: &SmallVec<[LocalDefId; 1]>,
10571068 trait_def_id: DefId,
1069 lint_ambiguous: bool,
10581070 ) {
10591071 let trait_args = self.fresh_args_for_item(self.span, trait_def_id);
10601072 let trait_ref = ty::TraitRef::new_from_args(self.tcx, trait_def_id, trait_args);
......@@ -1076,7 +1088,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10761088 Candidate {
10771089 item,
10781090 import_ids: import_ids.clone(),
1079 kind: TraitCandidate(bound_trait_ref),
1091 kind: TraitCandidate(bound_trait_ref, lint_ambiguous),
10801092 },
10811093 false,
10821094 );
......@@ -1099,7 +1111,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10991111 Candidate {
11001112 item,
11011113 import_ids: import_ids.clone(),
1102 kind: TraitCandidate(ty::Binder::dummy(trait_ref)),
1114 kind: TraitCandidate(ty::Binder::dummy(trait_ref), lint_ambiguous),
11031115 },
11041116 false,
11051117 );
......@@ -1842,7 +1854,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18421854 ObjectCandidate(_) | WhereClauseCandidate(_) => {
18431855 CandidateSource::Trait(candidate.item.container_id(self.tcx))
18441856 }
1845 TraitCandidate(trait_ref) => self.probe(|_| {
1857 TraitCandidate(trait_ref, _) => self.probe(|_| {
18461858 let trait_ref = self.instantiate_binder_with_fresh_vars(
18471859 self.span,
18481860 BoundRegionConversionTime::FnCall,
......@@ -1872,7 +1884,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18721884 fn candidate_source_from_pick(&self, pick: &Pick<'tcx>) -> CandidateSource {
18731885 match pick.kind {
18741886 InherentImplPick => CandidateSource::Impl(pick.item.container_id(self.tcx)),
1875 ObjectPick | WhereClausePick(_) | TraitPick => {
1887 ObjectPick | WhereClausePick(_) | TraitPick(_) => {
18761888 CandidateSource::Trait(pick.item.container_id(self.tcx))
18771889 }
18781890 }
......@@ -1948,7 +1960,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
19481960 impl_bounds,
19491961 ));
19501962 }
1951 TraitCandidate(poly_trait_ref) => {
1963 TraitCandidate(poly_trait_ref, _) => {
19521964 // Some trait methods are excluded for arrays before 2021.
19531965 // (`array.into_iter()` wants a slice iterator for compatibility.)
19541966 if let Some(method_name) = self.method_name {
......@@ -2274,11 +2286,16 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
22742286 }
22752287 }
22762288
2289 let lint_ambiguous = match probes[0].0.kind {
2290 TraitCandidate(_, lint) => lint,
2291 _ => false,
2292 };
2293
22772294 // FIXME: check the return type here somehow.
22782295 // If so, just use this trait and call it a day.
22792296 Some(Pick {
22802297 item: probes[0].0.item,
2281 kind: TraitPick,
2298 kind: TraitPick(lint_ambiguous),
22822299 import_ids: probes[0].0.import_ids.clone(),
22832300 autoderefs: 0,
22842301 autoref_or_ptr_adjustment: None,
......@@ -2348,9 +2365,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
23482365 }
23492366 }
23502367
2368 let lint_ambiguous = match probes[0].0.kind {
2369 TraitCandidate(_, lint) => lint,
2370 _ => false,
2371 };
2372
23512373 Some(Pick {
23522374 item: child_candidate.item,
2353 kind: TraitPick,
2375 kind: TraitPick(lint_ambiguous),
23542376 import_ids: child_candidate.import_ids.clone(),
23552377 autoderefs: 0,
23562378 autoref_or_ptr_adjustment: None,
......@@ -2613,7 +2635,7 @@ impl<'tcx> Candidate<'tcx> {
26132635 kind: match self.kind {
26142636 InherentImplCandidate { .. } => InherentImplPick,
26152637 ObjectCandidate(_) => ObjectPick,
2616 TraitCandidate(_) => TraitPick,
2638 TraitCandidate(_, lint_ambiguous) => TraitPick(lint_ambiguous),
26172639 WhereClauseCandidate(trait_ref) => {
26182640 // Only trait derived from where-clauses should
26192641 // appear here, so they should not contain any
compiler/rustc_lint_defs/src/builtin.rs+55
......@@ -17,6 +17,7 @@ declare_lint_pass! {
1717 AARCH64_SOFTFLOAT_NEON,
1818 ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
1919 AMBIGUOUS_ASSOCIATED_ITEMS,
20 AMBIGUOUS_GLOB_IMPORTED_TRAITS,
2021 AMBIGUOUS_GLOB_IMPORTS,
2122 AMBIGUOUS_GLOB_REEXPORTS,
2223 AMBIGUOUS_PANIC_IMPORTS,
......@@ -4473,6 +4474,60 @@ declare_lint! {
44734474 };
44744475}
44754476
4477declare_lint! {
4478 /// The `ambiguous_glob_imported_traits` lint reports uses of traits that are
4479 /// imported ambiguously via glob imports. Previously, this was not enforced
4480 /// due to a bug in rustc.
4481 ///
4482 /// ### Example
4483 ///
4484 /// ```rust,compile_fail
4485 /// #![deny(ambiguous_glob_imported_traits)]
4486 /// mod m1 {
4487 /// pub trait Trait {
4488 /// fn method1(&self) {}
4489 /// }
4490 /// impl Trait for u8 {}
4491 /// }
4492 /// mod m2 {
4493 /// pub trait Trait {
4494 /// fn method2(&self) {}
4495 /// }
4496 /// impl Trait for u8 {}
4497 /// }
4498 ///
4499 /// fn main() {
4500 /// use m1::*;
4501 /// use m2::*;
4502 /// 0u8.method1();
4503 /// 0u8.method2();
4504 /// }
4505 /// ```
4506 ///
4507 /// {{produces}}
4508 ///
4509 /// ### Explanation
4510 ///
4511 /// When multiple traits with the same name are brought into scope through glob imports,
4512 /// one trait becomes the "primary" one while the others are shadowed. Methods from the
4513 /// shadowed traits (e.g. `method2`) become inaccessible, while methods from the "primary"
4514 /// trait (e.g. `method1`) still resolve. Ideally, none of the ambiguous traits would be in scope,
4515 /// but we have to allow this for now because of backwards compatibility.
4516 /// This lint reports uses of these "primary" traits that are ambiguous.
4517 ///
4518 /// This is a [future-incompatible] lint to transition this to a
4519 /// hard error in the future.
4520 ///
4521 /// [future-incompatible]: ../index.md#future-incompatible-lints
4522 pub AMBIGUOUS_GLOB_IMPORTED_TRAITS,
4523 Warn,
4524 "detects uses of ambiguously glob imported traits",
4525 @future_incompatible = FutureIncompatibleInfo {
4526 reason: fcw!(FutureReleaseError #147992),
4527 report_in_deps: false,
4528 };
4529}
4530
44764531declare_lint! {
44774532 /// The `ambiguous_panic_imports` lint detects ambiguous core and std panic imports, but
44784533 /// previously didn't do that due to `#[macro_use]` prelude macro import.
compiler/rustc_macros/src/query.rs-3
......@@ -378,9 +378,6 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
378378 return_result_from_ensure_ok,
379379 );
380380
381 if modifiers.cache.is_some() {
382 attributes.push(quote! { (cache) });
383 }
384381 // Pass on the cache modifier
385382 if modifiers.cache.is_some() {
386383 attributes.push(quote! { (cache) });
compiler/rustc_resolve/src/lib.rs+27-5
......@@ -622,7 +622,18 @@ struct ModuleData<'ra> {
622622 globs: CmRefCell<Vec<Import<'ra>>>,
623623
624624 /// Used to memoize the traits in this module for faster searches through all traits in scope.
625 traits: CmRefCell<Option<Box<[(Macros20NormalizedIdent, Decl<'ra>, Option<Module<'ra>>)]>>>,
625 traits: CmRefCell<
626 Option<
627 Box<
628 [(
629 Macros20NormalizedIdent,
630 Decl<'ra>,
631 Option<Module<'ra>>,
632 bool, /* lint ambiguous */
633 )],
634 >,
635 >,
636 >,
626637
627638 /// Span of the module itself. Used for error reporting.
628639 span: Span,
......@@ -719,7 +730,12 @@ impl<'ra> Module<'ra> {
719730 return;
720731 }
721732 if let Res::Def(DefKind::Trait | DefKind::TraitAlias, def_id) = binding.res() {
722 collected_traits.push((name, binding, r.as_ref().get_module(def_id)))
733 collected_traits.push((
734 name,
735 binding,
736 r.as_ref().get_module(def_id),
737 binding.is_ambiguity_recursive(),
738 ));
723739 }
724740 });
725741 *traits = Some(collected_traits.into_boxed_slice());
......@@ -1877,7 +1893,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
18771893 if let Some(module) = current_trait {
18781894 if self.trait_may_have_item(Some(module), assoc_item) {
18791895 let def_id = module.def_id();
1880 found_traits.push(TraitCandidate { def_id, import_ids: smallvec![] });
1896 found_traits.push(TraitCandidate {
1897 def_id,
1898 import_ids: smallvec![],
1899 lint_ambiguous: false,
1900 });
18811901 }
18821902 }
18831903
......@@ -1915,11 +1935,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
19151935 ) {
19161936 module.ensure_traits(self);
19171937 let traits = module.traits.borrow();
1918 for &(trait_name, trait_binding, trait_module) in traits.as_ref().unwrap().iter() {
1938 for &(trait_name, trait_binding, trait_module, lint_ambiguous) in
1939 traits.as_ref().unwrap().iter()
1940 {
19191941 if self.trait_may_have_item(trait_module, assoc_item) {
19201942 let def_id = trait_binding.res().def_id();
19211943 let import_ids = self.find_transitive_imports(&trait_binding.kind, trait_name.0);
1922 found_traits.push(TraitCandidate { def_id, import_ids });
1944 found_traits.push(TraitCandidate { def_id, import_ids, lint_ambiguous });
19231945 }
19241946 }
19251947 }
compiler/rustc_session/src/config.rs+42-6
......@@ -22,7 +22,9 @@ use rustc_hashes::Hash64;
2222use rustc_macros::{BlobDecodable, Decodable, Encodable, HashStable_Generic};
2323use rustc_span::edition::{DEFAULT_EDITION, EDITION_NAME_LIST, Edition, LATEST_STABLE_EDITION};
2424use rustc_span::source_map::FilePathMapping;
25use rustc_span::{FileName, RealFileName, SourceFileHashAlgorithm, Symbol, sym};
25use rustc_span::{
26 FileName, RealFileName, RemapPathScopeComponents, SourceFileHashAlgorithm, Symbol, sym,
27};
2628use rustc_target::spec::{
2729 FramePointer, LinkSelfContainedComponents, LinkerFeatures, PanicStrategy, SplitDebuginfo,
2830 Target, TargetTuple,
......@@ -1317,6 +1319,29 @@ impl OutputFilenames {
13171319 }
13181320}
13191321
1322pub(crate) fn parse_remap_path_scope(
1323 early_dcx: &EarlyDiagCtxt,
1324 matches: &getopts::Matches,
1325) -> RemapPathScopeComponents {
1326 if let Some(v) = matches.opt_str("remap-path-scope") {
1327 let mut slot = RemapPathScopeComponents::empty();
1328 for s in v.split(',') {
1329 slot |= match s {
1330 "macro" => RemapPathScopeComponents::MACRO,
1331 "diagnostics" => RemapPathScopeComponents::DIAGNOSTICS,
1332 "debuginfo" => RemapPathScopeComponents::DEBUGINFO,
1333 "coverage" => RemapPathScopeComponents::COVERAGE,
1334 "object" => RemapPathScopeComponents::OBJECT,
1335 "all" => RemapPathScopeComponents::all(),
1336 _ => early_dcx.early_fatal("argument for `--remap-path-scope` must be a comma separated list of scopes: `macro`, `diagnostics`, `debuginfo`, `coverage`, `object`, `all`"),
1337 }
1338 }
1339 slot
1340 } else {
1341 RemapPathScopeComponents::all()
1342 }
1343}
1344
13201345#[derive(Clone, Debug)]
13211346pub struct Sysroot {
13221347 pub explicit: Option<PathBuf>,
......@@ -1353,9 +1378,9 @@ pub fn host_tuple() -> &'static str {
13531378
13541379fn file_path_mapping(
13551380 remap_path_prefix: Vec<(PathBuf, PathBuf)>,
1356 unstable_opts: &UnstableOptions,
1381 remap_path_scope: RemapPathScopeComponents,
13571382) -> FilePathMapping {
1358 FilePathMapping::new(remap_path_prefix.clone(), unstable_opts.remap_path_scope)
1383 FilePathMapping::new(remap_path_prefix.clone(), remap_path_scope)
13591384}
13601385
13611386impl Default for Options {
......@@ -1367,7 +1392,7 @@ impl Default for Options {
13671392 // to create a default working directory.
13681393 let working_dir = {
13691394 let working_dir = std::env::current_dir().unwrap();
1370 let file_mapping = file_path_mapping(Vec::new(), &unstable_opts);
1395 let file_mapping = file_path_mapping(Vec::new(), RemapPathScopeComponents::empty());
13711396 file_mapping.to_real_filename(&RealFileName::empty(), &working_dir)
13721397 };
13731398
......@@ -1402,6 +1427,7 @@ impl Default for Options {
14021427 cli_forced_codegen_units: None,
14031428 cli_forced_local_thinlto_off: false,
14041429 remap_path_prefix: Vec::new(),
1430 remap_path_scope: RemapPathScopeComponents::all(),
14051431 real_rust_source_base_dir: None,
14061432 real_rustc_dev_source_base_dir: None,
14071433 edition: DEFAULT_EDITION,
......@@ -1428,7 +1454,7 @@ impl Options {
14281454 }
14291455
14301456 pub fn file_path_mapping(&self) -> FilePathMapping {
1431 file_path_mapping(self.remap_path_prefix.clone(), &self.unstable_opts)
1457 file_path_mapping(self.remap_path_prefix.clone(), self.remap_path_scope)
14321458 }
14331459
14341460 /// Returns `true` if there will be an output file generated.
......@@ -1866,6 +1892,14 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
18661892 "Remap source names in all output (compiler messages and output files)",
18671893 "<FROM>=<TO>",
18681894 ),
1895 opt(
1896 Stable,
1897 Opt,
1898 "",
1899 "remap-path-scope",
1900 "Defines which scopes of paths should be remapped by `--remap-path-prefix`",
1901 "<macro,diagnostics,debuginfo,coverage,object,all>",
1902 ),
18691903 opt(Unstable, Multi, "", "env-set", "Inject an environment variable", "<VAR>=<VALUE>"),
18701904 ];
18711905 options.extend(verbose_only.into_iter().map(|mut opt| {
......@@ -2669,6 +2703,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
26692703 let externs = parse_externs(early_dcx, matches, &unstable_opts);
26702704
26712705 let remap_path_prefix = parse_remap_path_prefix(early_dcx, matches, &unstable_opts);
2706 let remap_path_scope = parse_remap_path_scope(early_dcx, matches);
26722707
26732708 let pretty = parse_pretty(early_dcx, &unstable_opts);
26742709
......@@ -2735,7 +2770,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
27352770 early_dcx.early_fatal(format!("Current directory is invalid: {e}"));
27362771 });
27372772
2738 let file_mapping = file_path_mapping(remap_path_prefix.clone(), &unstable_opts);
2773 let file_mapping = file_path_mapping(remap_path_prefix.clone(), remap_path_scope);
27392774 file_mapping.to_real_filename(&RealFileName::empty(), &working_dir)
27402775 };
27412776
......@@ -2772,6 +2807,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
27722807 cli_forced_codegen_units: codegen_units,
27732808 cli_forced_local_thinlto_off: disable_local_thinlto,
27742809 remap_path_prefix,
2810 remap_path_scope,
27752811 real_rust_source_base_dir,
27762812 real_rustc_dev_source_base_dir,
27772813 edition,
compiler/rustc_session/src/options.rs+2-26
......@@ -454,6 +454,8 @@ top_level_options!(
454454
455455 /// Remap source path prefixes in all output (messages, object files, debug, etc.).
456456 remap_path_prefix: Vec<(PathBuf, PathBuf)> [TRACKED_NO_CRATE_HASH],
457 /// Defines which scopes of paths should be remapped by `--remap-path-prefix`.
458 remap_path_scope: RemapPathScopeComponents [TRACKED_NO_CRATE_HASH],
457459
458460 /// Base directory containing the `library/` directory for the Rust standard library.
459461 /// Right now it's always `$sysroot/lib/rustlib/src/rust`
......@@ -872,7 +874,6 @@ mod desc {
872874 pub(crate) const parse_branch_protection: &str = "a `,` separated combination of `bti`, `gcs`, `pac-ret`, (optionally with `pc`, `b-key`, `leaf` if `pac-ret` is set)";
873875 pub(crate) const parse_proc_macro_execution_strategy: &str =
874876 "one of supported execution strategies (`same-thread`, or `cross-thread`)";
875 pub(crate) const parse_remap_path_scope: &str = "comma separated list of scopes: `macro`, `diagnostics`, `debuginfo`, `coverage`, `object`, `all`";
876877 pub(crate) const parse_inlining_threshold: &str =
877878 "either a boolean (`yes`, `no`, `on`, `off`, etc), or a non-negative number";
878879 pub(crate) const parse_llvm_module_flag: &str = "<key>:<type>:<value>:<behavior>. Type must currently be `u32`. Behavior should be one of (`error`, `warning`, `require`, `override`, `append`, `appendunique`, `max`, `min`)";
......@@ -1737,29 +1738,6 @@ pub mod parse {
17371738 true
17381739 }
17391740
1740 pub(crate) fn parse_remap_path_scope(
1741 slot: &mut RemapPathScopeComponents,
1742 v: Option<&str>,
1743 ) -> bool {
1744 if let Some(v) = v {
1745 *slot = RemapPathScopeComponents::empty();
1746 for s in v.split(',') {
1747 *slot |= match s {
1748 "macro" => RemapPathScopeComponents::MACRO,
1749 "diagnostics" => RemapPathScopeComponents::DIAGNOSTICS,
1750 "debuginfo" => RemapPathScopeComponents::DEBUGINFO,
1751 "coverage" => RemapPathScopeComponents::COVERAGE,
1752 "object" => RemapPathScopeComponents::OBJECT,
1753 "all" => RemapPathScopeComponents::all(),
1754 _ => return false,
1755 }
1756 }
1757 true
1758 } else {
1759 false
1760 }
1761 }
1762
17631741 pub(crate) fn parse_relocation_model(slot: &mut Option<RelocModel>, v: Option<&str>) -> bool {
17641742 match v.and_then(|s| RelocModel::from_str(s).ok()) {
17651743 Some(relocation_model) => *slot = Some(relocation_model),
......@@ -2614,8 +2592,6 @@ options! {
26142592 "whether ELF relocations can be relaxed"),
26152593 remap_cwd_prefix: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
26162594 "remap paths under the current working directory to this path prefix"),
2617 remap_path_scope: RemapPathScopeComponents = (RemapPathScopeComponents::all(), parse_remap_path_scope, [TRACKED],
2618 "remap path scope (default: all)"),
26192595 remark_dir: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
26202596 "directory into which to write optimization remarks (if not specified, they will be \
26212597written to standard error output)"),
compiler/rustc_target/src/spec/mod.rs+2
......@@ -1801,6 +1801,8 @@ supported_targets! {
18011801 ("x86_64-lynx-lynxos178", x86_64_lynx_lynxos178),
18021802
18031803 ("x86_64-pc-cygwin", x86_64_pc_cygwin),
1804
1805 ("x86_64-unknown-linux-gnuasan", x86_64_unknown_linux_gnuasan),
18041806}
18051807
18061808/// Cow-Vec-Str: Cow<'static, [Cow<'static, str>]>
compiler/rustc_target/src/spec/targets/i586_unknown_redox.rs+1-1
......@@ -11,7 +11,7 @@ pub(crate) fn target() -> Target {
1111
1212 Target {
1313 llvm_target: "i586-unknown-redox".into(),
14 metadata: TargetMetadata { description: None, tier: None, host_tools: None, std: None },
14 metadata: TargetMetadata { description: None, tier: Some(3), host_tools: None, std: None },
1515 pointer_width: 32,
1616 data_layout:
1717 "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i128:128-f64:32:64-f80:32-n8:16:32-S128"
compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_gnuasan.rs created+16
......@@ -0,0 +1,16 @@
1use crate::spec::{SanitizerSet, Target, TargetMetadata};
2
3pub(crate) fn target() -> Target {
4 let mut base = super::x86_64_unknown_linux_gnu::target();
5 base.metadata = TargetMetadata {
6 description: Some(
7 "64-bit Linux (kernel 3.2+, glibc 2.17+) with ASAN enabled by default".into(),
8 ),
9 tier: Some(2),
10 host_tools: Some(false),
11 std: Some(true),
12 };
13 base.supported_sanitizers = SanitizerSet::ADDRESS;
14 base.default_sanitizers = SanitizerSet::ADDRESS;
15 base
16}
compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_none.rs+1-1
......@@ -15,7 +15,7 @@ pub(crate) fn target() -> Target {
1515 llvm_target: "x86_64-unknown-linux-none".into(),
1616 metadata: TargetMetadata {
1717 description: None,
18 tier: None,
18 tier: Some(3),
1919 host_tools: None,
2020 std: Some(false),
2121 },
compiler/rustc_target/src/spec/targets/xtensa_esp32_espidf.rs+1-1
......@@ -9,7 +9,7 @@ pub(crate) fn target() -> Target {
99 pointer_width: 32,
1010 data_layout: "e-m:e-p:32:32-v1:8:8-i64:64-i128:128-n32".into(),
1111 arch: Arch::Xtensa,
12 metadata: TargetMetadata { description: None, tier: None, host_tools: None, std: None },
12 metadata: TargetMetadata { description: None, tier: Some(3), host_tools: None, std: None },
1313
1414 options: TargetOptions {
1515 endian: Endian::Little,
compiler/rustc_target/src/spec/targets/xtensa_esp32s2_espidf.rs+1-1
......@@ -9,7 +9,7 @@ pub(crate) fn target() -> Target {
99 pointer_width: 32,
1010 data_layout: "e-m:e-p:32:32-v1:8:8-i64:64-i128:128-n32".into(),
1111 arch: Arch::Xtensa,
12 metadata: TargetMetadata { description: None, tier: None, host_tools: None, std: None },
12 metadata: TargetMetadata { description: None, tier: Some(3), host_tools: None, std: None },
1313
1414 options: TargetOptions {
1515 endian: Endian::Little,
compiler/rustc_target/src/spec/targets/xtensa_esp32s3_espidf.rs+1-1
......@@ -9,7 +9,7 @@ pub(crate) fn target() -> Target {
99 pointer_width: 32,
1010 data_layout: "e-m:e-p:32:32-v1:8:8-i64:64-i128:128-n32".into(),
1111 arch: Arch::Xtensa,
12 metadata: TargetMetadata { description: None, tier: None, host_tools: None, std: None },
12 metadata: TargetMetadata { description: None, tier: Some(3), host_tools: None, std: None },
1313
1414 options: TargetOptions {
1515 endian: Endian::Little,
src/bootstrap/mk/Makefile.in+5
......@@ -53,6 +53,11 @@ check-aux:
5353 src/tools/cargotest \
5454 src/tools/test-float-parse \
5555 $(BOOTSTRAP_ARGS)
56 # The build-std suite is off by default because it is uncommonly slow
57 # and memory-hungry.
58 $(Q)$(BOOTSTRAP) test --stage 2 \
59 build-std \
60 $(BOOTSTRAP_ARGS)
5661 # Run standard library tests in Miri.
5762 $(Q)MIRIFLAGS="-Zmiri-strict-provenance" \
5863 $(BOOTSTRAP) miri --stage 2 \
src/bootstrap/src/core/build_steps/llvm.rs+1
......@@ -1515,6 +1515,7 @@ fn supported_sanitizers(
15151515 "x86_64",
15161516 &["asan", "dfsan", "lsan", "msan", "safestack", "tsan", "rtsan"],
15171517 ),
1518 "x86_64-unknown-linux-gnuasan" => common_libs("linux", "x86_64", &["asan"]),
15181519 "x86_64-unknown-linux-musl" => {
15191520 common_libs("linux", "x86_64", &["asan", "lsan", "msan", "tsan"])
15201521 }
src/bootstrap/src/core/build_steps/test.rs+7-1
......@@ -1625,6 +1625,12 @@ test!(RunMakeCargo {
16251625 suite: "run-make-cargo",
16261626 default: true
16271627});
1628test!(BuildStd {
1629 path: "tests/build-std",
1630 mode: CompiletestMode::RunMake,
1631 suite: "build-std",
1632 default: false
1633});
16281634
16291635test!(AssemblyLlvm {
16301636 path: "tests/assembly-llvm",
......@@ -1948,7 +1954,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
19481954 let stage0_rustc_path = builder.compiler(0, test_compiler.host);
19491955 cmd.arg("--stage0-rustc-path").arg(builder.rustc(stage0_rustc_path));
19501956
1951 if suite == "run-make-cargo" {
1957 if matches!(suite, "run-make-cargo" | "build-std") {
19521958 let cargo_path = if test_compiler.stage == 0 {
19531959 // If we're using `--stage 0`, we should provide the bootstrap cargo.
19541960 builder.initial_cargo.clone()
src/bootstrap/src/core/builder/cli_paths.rs+1
......@@ -20,6 +20,7 @@ pub(crate) const PATH_REMAP: &[(&str, &[&str])] = &[
2020 &[
2121 // tidy-alphabetical-start
2222 "tests/assembly-llvm",
23 "tests/build-std",
2324 "tests/codegen-llvm",
2425 "tests/codegen-units",
2526 "tests/coverage",
src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_tests.snap+3
......@@ -5,6 +5,9 @@ expression: test tests
55[Test] test::AssemblyLlvm
66 targets: [aarch64-unknown-linux-gnu]
77 - Suite(test::tests/assembly-llvm)
8[Test] test::BuildStd
9 targets: [aarch64-unknown-linux-gnu]
10 - Suite(test::tests/build-std)
811[Test] test::CodegenLlvm
912 targets: [aarch64-unknown-linux-gnu]
1013 - Suite(test::tests/codegen-llvm)
src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_tests_skip_coverage.snap+3
......@@ -5,6 +5,9 @@ expression: test tests --skip=coverage
55[Test] test::AssemblyLlvm
66 targets: [aarch64-unknown-linux-gnu]
77 - Suite(test::tests/assembly-llvm)
8[Test] test::BuildStd
9 targets: [aarch64-unknown-linux-gnu]
10 - Suite(test::tests/build-std)
811[Test] test::CodegenLlvm
912 targets: [aarch64-unknown-linux-gnu]
1013 - Suite(test::tests/codegen-llvm)
src/bootstrap/src/core/builder/mod.rs+1
......@@ -927,6 +927,7 @@ impl<'a> Builder<'a> {
927927 test::CollectLicenseMetadata,
928928 test::RunMake,
929929 test::RunMakeCargo,
930 test::BuildStd,
930931 ),
931932 Kind::Miri => describe!(test::Crate),
932933 Kind::Bench => describe!(test::Crate, test::CrateLibrustc, test::CrateRustdoc),
src/bootstrap/src/core/builder/tests.rs+2-2
......@@ -2077,7 +2077,7 @@ mod snapshot {
20772077 let ctx = TestCtx::new();
20782078 insta::assert_snapshot!(
20792079 prepare_test_config(&ctx)
2080 .render_steps(), @r"
2080 .render_steps(), @"
20812081 [build] rustc 0 <host> -> Tidy 1 <host>
20822082 [test] tidy <>
20832083 [build] rustdoc 0 <host>
......@@ -2255,7 +2255,7 @@ mod snapshot {
22552255 insta::assert_snapshot!(
22562256 prepare_test_config(&ctx)
22572257 .stage(2)
2258 .render_steps(), @r"
2258 .render_steps(), @"
22592259 [build] rustc 0 <host> -> Tidy 1 <host>
22602260 [test] tidy <>
22612261 [build] rustdoc 0 <host>
src/bootstrap/src/core/sanity.rs+1
......@@ -38,6 +38,7 @@ pub struct Finder {
3838const STAGE0_MISSING_TARGETS: &[&str] = &[
3939 // just a dummy comment so the list doesn't get onelined
4040 "riscv64im-unknown-none-elf",
41 "x86_64-unknown-linux-gnuasan",
4142];
4243
4344/// Minimum version threshold for libstdc++ required when using prebuilt LLVM
src/doc/rustc-dev-guide/src/tests/compiletest.md+10
......@@ -78,6 +78,10 @@ The following test suites are available, with links for more information:
7878
7979[`run-make`](#run-make-tests) are general purpose tests using Rust programs.
8080
81### The build-std test suite
82
83[`build-std`](#build-std-tests) test that -Zbuild-std works.
84
8185### Rustdoc test suites
8286
8387| Test suite | Purpose |
......@@ -429,6 +433,12 @@ use cases that require testing in-tree `cargo` in conjunction with in-tree `rust
429433The `run-make` test suite does not have access to in-tree `cargo` (so it can be the
430434faster-to-iterate test suite).
431435
436### `build-std` tests
437
438The tests in [`tests/build-std`] check that `-Zbuild-std` works. This is currently
439just a run-make test suite with a single recipe. The recipe generates test cases
440and runs them in parallel.
441
432442#### Using Rust recipes
433443
434444Each test should be in a separate directory with a `rmake.rs` Rust program,
src/doc/rustc/src/SUMMARY.md+1
......@@ -151,5 +151,6 @@
151151 - [x86_64-pc-cygwin](platform-support/x86_64-pc-cygwin.md)
152152 - [x86_64-unknown-linux-none](platform-support/x86_64-unknown-linux-none.md)
153153 - [x86_64-unknown-none](platform-support/x86_64-unknown-none.md)
154 - [x86_64-unknown-linux-gnuasan](platform-support/x86_64-unknown-linux-gnuasan.md)
154155 - [xtensa-\*-none-elf](platform-support/xtensa.md)
155156 - [\*-nuttx-\*](platform-support/nuttx.md)
src/doc/rustc/src/command-line-arguments.md+8
......@@ -428,6 +428,14 @@ specified multiple times.
428428Refer to the [Remap source paths](remap-source-paths.md) section of this book for
429429further details and explanation.
430430
431<a id="option-remap-path-scope"></a>
432## `--remap-path-scope`: remap source paths in output
433
434Defines which scopes of paths should be remapped by `--remap-path-prefix`.
435
436Refer to the [Remap source paths](remap-source-paths.md) section of this book for
437further details and explanation.
438
431439<a id="option-json"></a>
432440## `--json`: configure json messages printed by the compiler
433441
src/doc/rustc/src/platform-support.md+1
......@@ -206,6 +206,7 @@ target | std | notes
206206[`x86_64-apple-ios-macabi`](platform-support/apple-ios-macabi.md) | ✓ | Mac Catalyst on x86_64
207207[`x86_64-fortanix-unknown-sgx`](platform-support/x86_64-fortanix-unknown-sgx.md) | ✓ | [Fortanix ABI] for 64-bit Intel SGX
208208[`x86_64-linux-android`](platform-support/android.md) | ✓ | 64-bit x86 Android
209[`x86_64-unknown-linux-gnuasan`](platform-support/x86_64-unknown-linux-gnuasan.md) | ✓ | 64-bit Linux (kernel 3.2+, glibc 2.17+) with ASAN enabled by default
209210[`x86_64-unknown-fuchsia`](platform-support/fuchsia.md) | ✓ | 64-bit x86 Fuchsia
210211`x86_64-unknown-linux-gnux32` | ✓ | 64-bit Linux (x32 ABI) (kernel 4.15+, glibc 2.27)
211212[`x86_64-unknown-none`](platform-support/x86_64-unknown-none.md) | * | Freestanding/bare-metal x86_64, softfloat
src/doc/rustc/src/platform-support/x86_64-unknown-linux-gnuasan.md created+56
......@@ -0,0 +1,56 @@
1# `x86_64-unknown-linux-gnuasan`
2
3**Tier: 2**
4
5Target mirroring `x86_64-unknown-linux-gnu` with AddressSanitizer enabled by
6default.
7The goal of this target is to allow shipping ASAN-instrumented standard
8libraries through rustup, enabling a fully instrumented binary without requiring
9nightly features (build-std).
10Once build-std stabilizes, this target is no longer needed and will be removed.
11
12## Target maintainers
13
14- [@jakos-sec](https://github.com/jakos-sec)
15- [@1c3t3a](https://github.com/1c3t3a)
16- [@rust-lang/project-exploit-mitigations][project-exploit-mitigations]
17
18## Requirements
19
20The target is for cross-compilation only. Host tools are not supported, since
21there is no need to have the host tools instrumented with ASAN. std is fully
22supported.
23
24In all other aspects the target is equivalent to `x86_64-unknown-linux-gnu`.
25
26## Building the target
27
28The target can be built by enabling it for a rustc build:
29
30```toml
31[build]
32target = ["x86_64-unknown-linux-gnuasan"]
33```
34
35## Building Rust programs
36
37Rust programs can be compiled by adding this target via rustup:
38
39```sh
40$ rustup target add x86_64-unknown-linux-gnuasan
41```
42
43and then compiling with the target:
44
45```sh
46$ rustc foo.rs --target x86_64-unknown-linux-gnuasan
47```
48
49## Testing
50
51Created binaries will run on Linux without any external requirements.
52
53## Cross-compilation toolchains and C code
54
55The target supports C code and should use the same toolchain target as
56`x86_64-unknown-linux-gnu`.
src/doc/rustc/src/remap-source-paths.md+26-1
......@@ -6,7 +6,7 @@ output, including compiler diagnostics, debugging information, macro expansions,
66This is useful for normalizing build products, for example, by removing the current directory
77out of the paths emitted into object files.
88
9The remapping is done via the `--remap-path-prefix` option.
9The remapping is done via the `--remap-path-prefix` flag and can be customized via the `--remap-path-scope` flag.
1010
1111## `--remap-path-prefix`
1212
......@@ -39,6 +39,31 @@ rustc --remap-path-prefix "/home/user/project=/redacted"
3939
4040This example replaces all occurrences of `/home/user/project` in emitted paths with `/redacted`.
4141
42## `--remap-path-scope`
43
44Defines which scopes of paths should be remapped by `--remap-path-prefix`.
45
46This flag accepts a comma-separated list of values and may be specified multiple times, in which case the scopes are aggregated together.
47
48The valid scopes are:
49
50- `macro` - apply remappings to the expansion of `std::file!()` macro. This is where paths in embedded panic messages come from
51- `diagnostics` - apply remappings to printed compiler diagnostics
52- `debuginfo` - apply remappings to debug information
53- `coverage` - apply remappings to coverage information
54- `object` - apply remappings to all paths in compiled executables or libraries, but not elsewhere. Currently an alias for `macro,coverage,debuginfo`.
55- `all` (default) - an alias for all of the above, also equivalent to supplying only `--remap-path-prefix` without `--remap-path-scope`.
56
57The scopes accepted by `--remap-path-scope` are not exhaustive - new scopes may be added in future releases for eventual stabilisation.
58This implies that the `all` scope can correspond to different scopes between releases.
59
60### Example
61
62```sh
63# With `object` scope only the build outputs will be remapped, the diagnostics won't be remapped.
64rustc --remap-path-prefix=$(PWD)=/remapped --remap-path-scope=object main.rs
65```
66
4267## Caveats and Limitations
4368
4469### Paths generated by linkers
src/doc/unstable-book/src/compiler-flags/remap-path-scope.md deleted-23
......@@ -1,23 +0,0 @@
1# `remap-path-scope`
2
3The tracking issue for this feature is: [#111540](https://github.com/rust-lang/rust/issues/111540).
4
5------------------------
6
7When the `--remap-path-prefix` option is passed to rustc, source path prefixes in all output will be affected by default.
8The `--remap-path-scope` argument can be used in conjunction with `--remap-path-prefix` to determine paths in which output context should be affected.
9This flag accepts a comma-separated list of values and may be specified multiple times, in which case the scopes are aggregated together. The valid scopes are:
10
11- `macro` - apply remappings to the expansion of `std::file!()` macro. This is where paths in embedded panic messages come from
12- `diagnostics` - apply remappings to printed compiler diagnostics
13- `debuginfo` - apply remappings to debug information
14- `coverage` - apply remappings to coverage information
15- `object` - apply remappings to all paths in compiled executables or libraries, but not elsewhere. Currently an alias for `macro,debuginfo`.
16- `all` - an alias for all of the above, also equivalent to supplying only `--remap-path-prefix` without `--remap-path-scope`.
17
18## Example
19```sh
20# This would produce an absolute path to main.rs in build outputs of
21# "./main.rs".
22rustc --remap-path-prefix=$(PWD)=/remapped -Zremap-path-scope=object main.rs
23```
src/tools/compiletest/src/common.rs+1
......@@ -77,6 +77,7 @@ string_enum! {
7777 RustdocUi => "rustdoc-ui",
7878 Ui => "ui",
7979 UiFullDeps => "ui-fulldeps",
80 BuildStd => "build-std",
8081 }
8182}
8283
src/tools/compiletest/src/runtest/run_make.rs+2-2
......@@ -190,8 +190,8 @@ impl TestCx<'_> {
190190 // through a specific CI runner).
191191 .env("LLVM_COMPONENTS", &self.config.llvm_components);
192192
193 // Only `run-make-cargo` test suite gets an in-tree `cargo`, not `run-make`.
194 if self.config.suite == TestSuite::RunMakeCargo {
193 // The `run-make-cargo` and `build-std` suites need an in-tree `cargo`, `run-make` does not.
194 if matches!(self.config.suite, TestSuite::RunMakeCargo | TestSuite::BuildStd) {
195195 cmd.env(
196196 "CARGO",
197197 self.config.cargo_path.as_ref().expect("cargo must be built and made available"),
src/tools/llvm-bitcode-linker/src/linker.rs+3-3
......@@ -68,7 +68,7 @@ impl Session {
6868 .arg("-o")
6969 .arg(&self.link_path)
7070 .output()
71 .context("An error occured when calling llvm-link. Make sure the llvm-tools component is installed.")?;
71 .context("An error occurred when calling llvm-link. Make sure the llvm-tools component is installed.")?;
7272
7373 if !llvm_link_output.status.success() {
7474 tracing::error!(
......@@ -115,7 +115,7 @@ impl Session {
115115 }
116116
117117 let opt_output = opt_cmd.output().context(
118 "An error occured when calling opt. Make sure the llvm-tools component is installed.",
118 "An error occurred when calling opt. Make sure the llvm-tools component is installed.",
119119 )?;
120120
121121 if !opt_output.status.success() {
......@@ -149,7 +149,7 @@ impl Session {
149149 .arg(&self.opt_path)
150150 .arg("-o").arg(&self.out_path)
151151 .output()
152 .context("An error occured when calling llc. Make sure the llvm-tools component is installed.")?;
152 .context("An error occurred when calling llc. Make sure the llvm-tools component is installed.")?;
153153
154154 if !lcc_output.status.success() {
155155 tracing::error!(
src/tools/miri/genmc-sys/cpp/include/MiriInterface.hpp+1-1
......@@ -79,7 +79,7 @@ struct MiriGenmcShim : private GenMCDriver {
7979 void handle_execution_start();
8080 // This function must be called at the end of any execution, even if an error was found
8181 // during the execution.
82 // Returns `null`, or a string containing an error message if an error occured.
82 // Returns `null`, or a string containing an error message if an error occurred.
8383 std::unique_ptr<std::string> handle_execution_end();
8484
8585 /***** Functions for handling events encountered during program execution. *****/
src/tools/miri/genmc-sys/src/lib.rs+1-1
......@@ -379,7 +379,7 @@ mod ffi {
379379 /// This function must be called at the start of any execution, before any events are reported to GenMC.
380380 fn handle_execution_start(self: Pin<&mut MiriGenmcShim>);
381381 /// This function must be called at the end of any execution, even if an error was found during the execution.
382 /// Returns `null`, or a string containing an error message if an error occured.
382 /// Returns `null`, or a string containing an error message if an error occurred.
383383 fn handle_execution_end(self: Pin<&mut MiriGenmcShim>) -> UniquePtr<CxxString>;
384384
385385 /***** Functions for handling events encountered during program execution. *****/
src/tools/miri/src/concurrency/genmc/mod.rs+1-1
......@@ -220,7 +220,7 @@ impl GenmcCtx {
220220 /// Don't call this function if an error was found.
221221 ///
222222 /// GenMC detects certain errors only when the execution ends.
223 /// If an error occured, a string containing a short error description is returned.
223 /// If an error occurred, a string containing a short error description is returned.
224224 ///
225225 /// GenMC currently doesn't return an error in all cases immediately when one happens.
226226 /// This function will also check for those, and return their error description.
src/tools/run-make-support/Cargo.toml+1
......@@ -17,6 +17,7 @@ object = "0.37"
1717regex = "1.11"
1818serde_json = "1.0"
1919similar = "2.7"
20tempfile = "3"
2021wasmparser = { version = "0.236", default-features = false, features = ["std", "features", "validate"] }
2122# tidy-alphabetical-end
2223
src/tools/run-make-support/src/command.rs+13
......@@ -46,6 +46,8 @@ pub struct Command {
4646 // Emulate linear type semantics.
4747 drop_bomb: DropBomb,
4848 already_executed: bool,
49
50 context: String,
4951}
5052
5153impl Command {
......@@ -60,6 +62,7 @@ impl Command {
6062 stdout: None,
6163 stderr: None,
6264 already_executed: false,
65 context: String::new(),
6366 }
6467 }
6568
......@@ -69,6 +72,16 @@ impl Command {
6972 self.cmd
7073 }
7174
75 pub(crate) fn get_context(&self) -> &str {
76 &self.context
77 }
78
79 /// Appends context to the command, to provide a better error message if the command fails.
80 pub fn context(&mut self, ctx: &str) -> &mut Self {
81 self.context.push_str(&format!("{ctx}\n"));
82 self
83 }
84
7285 /// Specify a stdin input buffer. This is a convenience helper,
7386 pub fn stdin_buf<I: AsRef<[u8]>>(&mut self, input: I) -> &mut Self {
7487 self.stdin_buf = Some(input.as_ref().to_vec().into_boxed_slice());
src/tools/run-make-support/src/lib.rs+3-1
......@@ -34,7 +34,9 @@ pub mod rfs {
3434}
3535
3636// Re-exports of third-party library crates.
37pub use {bstr, gimli, libc, object, regex, rustdoc_json_types, serde_json, similar, wasmparser};
37pub use {
38 bstr, gimli, libc, object, regex, rustdoc_json_types, serde_json, similar, tempfile, wasmparser,
39};
3840
3941// Helpers for building names of output artifacts that are potentially target-specific.
4042pub use crate::artifact_names::{
src/tools/run-make-support/src/util.rs+3
......@@ -21,6 +21,9 @@ pub(crate) fn handle_failed_output(
2121 eprintln!("output status: `{}`", output.status());
2222 eprintln!("=== STDOUT ===\n{}\n\n", output.stdout_utf8());
2323 eprintln!("=== STDERR ===\n{}\n\n", output.stderr_utf8());
24 if !cmd.get_context().is_empty() {
25 eprintln!("Context:\n{}", cmd.get_context());
26 }
2427 std::process::exit(1)
2528}
2629
src/tools/tidy/src/diagnostics.rs+1-1
......@@ -213,7 +213,7 @@ impl RunningCheck {
213213 }
214214 }
215215
216 /// Has an error already occured for this check?
216 /// Has an error already occurred for this check?
217217 pub fn is_bad(&self) -> bool {
218218 self.bad
219219 }
tests/assembly-llvm/targets/targets-elf.rs+3
......@@ -673,6 +673,9 @@
673673//@ revisions: x86_64_unknown_linux_gnux32
674674//@ [x86_64_unknown_linux_gnux32] compile-flags: --target x86_64-unknown-linux-gnux32
675675//@ [x86_64_unknown_linux_gnux32] needs-llvm-components: x86
676//@ revisions: x86_64_unknown_linux_gnuasan
677//@ [x86_64_unknown_linux_gnuasan] compile-flags: --target x86_64-unknown-linux-gnuasan
678//@ [x86_64_unknown_linux_gnuasan] needs-llvm-components: x86
676679//@ revisions: x86_64_unknown_linux_musl
677680//@ [x86_64_unknown_linux_musl] compile-flags: --target x86_64-unknown-linux-musl
678681//@ [x86_64_unknown_linux_musl] needs-llvm-components: x86
tests/build-std/configurations/rmake.rs created+131
......@@ -0,0 +1,131 @@
1// This test ensures we are able to compile -Zbuild-std=core under a variety of profiles.
2// Currently, it tests that we can compile to all Tier 1 targets, and it does this by checking what
3// the tier metadata in target-spec JSON. This means that all in-tree targets must have a tier set.
4
5#![deny(warnings)]
6
7use std::collections::HashMap;
8use std::sync::{Arc, Mutex};
9use std::thread;
10
11use run_make_support::serde_json::{self, Value};
12use run_make_support::tempfile::TempDir;
13use run_make_support::{cargo, rfs, rustc};
14
15#[derive(Clone)]
16struct Task {
17 target: String,
18 opt_level: u8,
19 debug: u8,
20 panic: &'static str,
21}
22
23fn manifest(task: &Task) -> String {
24 let Task { opt_level, debug, panic, target: _ } = task;
25 format!(
26 r#"[package]
27name = "scratch"
28version = "0.1.0"
29edition = "2024"
30
31[lib]
32path = "lib.rs"
33
34[profile.release]
35opt-level = {opt_level}
36debug = {debug}
37panic = "{panic}"
38"#
39 )
40}
41
42fn main() {
43 let mut targets = Vec::new();
44 let all_targets =
45 rustc().args(&["--print=all-target-specs-json", "-Zunstable-options"]).run().stdout_utf8();
46 let all_targets: HashMap<String, Value> = serde_json::from_str(&all_targets).unwrap();
47 for (target, spec) in all_targets {
48 let metadata = spec.as_object().unwrap()["metadata"].as_object().unwrap();
49 let tier = metadata["tier"]
50 .as_u64()
51 .expect(&format!("Target {} is missing tier metadata", target));
52 if tier == 1 {
53 targets.push(target);
54 }
55 }
56
57 let mut tasks = Vec::new();
58
59 // Testing every combination of compiler flags is infeasible. So we are making some attempt to
60 // choose combinations that will tend to run into problems.
61 //
62 // The particular combination of settings below is tuned to look for problems generating the
63 // code for compiler-builtins.
64 // We only exercise opt-level 0 and 3 to exercise mir-opt-level 1 and 2.
65 // We only exercise debug 0 and 2 because level 2 turns off some MIR optimizations.
66 // We only test abort and immediate-abort because abort vs unwind doesn't change MIR much at
67 // all. but immediate-abort does.
68 //
69 // Currently this only tests that we can compile the tier 1 targets. But since we are using
70 // -Zbuild-std=core, we could have any list of targets.
71
72 for opt_level in [0, 3] {
73 for debug in [0, 2] {
74 for panic in ["abort", "immediate-abort"] {
75 for target in &targets {
76 tasks.push(Task { target: target.clone(), opt_level, debug, panic });
77 }
78 }
79 }
80 }
81
82 let tasks = Arc::new(Mutex::new(tasks));
83 let mut threads = Vec::new();
84
85 // Try to obey the -j argument passed to bootstrap, otherwise fall back to using all the system
86 // resouces. This test can be rather memory-hungry (~1 GB/thread); if it causes trouble in
87 // practice do not hesitate to limit its parallelism.
88 for _ in 0..run_make_support::env::jobs() {
89 let tasks = Arc::clone(&tasks);
90 let handle = thread::spawn(move || {
91 loop {
92 let maybe_task = tasks.lock().unwrap().pop();
93 if let Some(task) = maybe_task {
94 test(task);
95 } else {
96 break;
97 }
98 }
99 });
100 threads.push(handle);
101 }
102
103 for t in threads {
104 t.join().unwrap();
105 }
106}
107
108fn test(task: Task) {
109 let dir = TempDir::new().unwrap();
110
111 let manifest = manifest(&task);
112 rfs::write(dir.path().join("Cargo.toml"), &manifest);
113 rfs::write(dir.path().join("lib.rs"), "#![no_std]");
114
115 let mut args = vec!["build", "--release", "-Zbuild-std=core", "--target", &task.target, "-j1"];
116 if task.panic == "immediate-abort" {
117 args.push("-Zpanic-immediate-abort");
118 }
119 cargo()
120 .current_dir(dir.path())
121 .args(&args)
122 .env("RUSTC_BOOTSTRAP", "1")
123 // Visual Studio 2022 requires that the LIB env var be set so it can
124 // find the Windows SDK.
125 .env("LIB", std::env::var("LIB").unwrap_or_default())
126 .context(&format!(
127 "build-std for target `{}` failed with the following Cargo.toml:\n\n{manifest}",
128 task.target
129 ))
130 .run();
131}
tests/coverage/remap-path-prefix.rs+3-3
......@@ -10,8 +10,8 @@
1010//@ revisions: with_remap with_coverage_scope with_object_scope with_macro_scope
1111//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
1212//
13//@[with_coverage_scope] compile-flags: -Zremap-path-scope=coverage
14//@[with_object_scope] compile-flags: -Zremap-path-scope=object
15//@[with_macro_scope] compile-flags: -Zremap-path-scope=macro
13//@[with_coverage_scope] compile-flags: --remap-path-scope=coverage
14//@[with_object_scope] compile-flags: --remap-path-scope=object
15//@[with_macro_scope] compile-flags: --remap-path-scope=macro
1616
1717fn main() {}
tests/coverage/remap-path-prefix.with_macro_scope.coverage+3-3
......@@ -10,9 +10,9 @@
1010 LL| |//@ revisions: with_remap with_coverage_scope with_object_scope with_macro_scope
1111 LL| |//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
1212 LL| |//
13 LL| |//@[with_coverage_scope] compile-flags: -Zremap-path-scope=coverage
14 LL| |//@[with_object_scope] compile-flags: -Zremap-path-scope=object
15 LL| |//@[with_macro_scope] compile-flags: -Zremap-path-scope=macro
13 LL| |//@[with_coverage_scope] compile-flags: --remap-path-scope=coverage
14 LL| |//@[with_object_scope] compile-flags: --remap-path-scope=object
15 LL| |//@[with_macro_scope] compile-flags: --remap-path-scope=macro
1616 LL| |
1717 LL| 1|fn main() {}
1818
tests/run-make/remap-path-prefix-consts/rmake.rs+2-2
......@@ -97,7 +97,7 @@ fn main() {
9797 location_caller
9898 .crate_type("lib")
9999 .remap_path_prefix(cwd(), "/remapped")
100 .arg("-Zremap-path-scope=object")
100 .arg("--remap-path-scope=object")
101101 .input(cwd().join("location-caller.rs"));
102102 location_caller.run();
103103
......@@ -105,7 +105,7 @@ fn main() {
105105 runner
106106 .crate_type("bin")
107107 .remap_path_prefix(cwd(), "/remapped")
108 .arg("-Zremap-path-scope=diagnostics")
108 .arg("--remap-path-scope=diagnostics")
109109 .input(cwd().join("runner.rs"))
110110 .output(&runner_bin);
111111 runner.run();
tests/run-make/remap-path-prefix-dwarf/rmake.rs+4-4
......@@ -105,7 +105,7 @@ fn check_dwarf_deps(scope: &str, dwarf_test: DwarfDump) {
105105 let mut rustc_sm = rustc();
106106 rustc_sm.input(cwd().join("src/some_value.rs"));
107107 rustc_sm.arg("-Cdebuginfo=2");
108 rustc_sm.arg(format!("-Zremap-path-scope={}", scope));
108 rustc_sm.arg(format!("--remap-path-scope={}", scope));
109109 rustc_sm.arg("--remap-path-prefix");
110110 rustc_sm.arg(format!("{}=/REMAPPED", cwd().display()));
111111 rustc_sm.arg("-Csplit-debuginfo=off");
......@@ -117,7 +117,7 @@ fn check_dwarf_deps(scope: &str, dwarf_test: DwarfDump) {
117117 rustc_pv.input(cwd().join("src/print_value.rs"));
118118 rustc_pv.output(&print_value_rlib);
119119 rustc_pv.arg("-Cdebuginfo=2");
120 rustc_pv.arg(format!("-Zremap-path-scope={}", scope));
120 rustc_pv.arg(format!("--remap-path-scope={}", scope));
121121 rustc_pv.arg("--remap-path-prefix");
122122 rustc_pv.arg(format!("{}=/REMAPPED", cwd().display()));
123123 rustc_pv.arg("-Csplit-debuginfo=off");
......@@ -158,8 +158,8 @@ fn check_dwarf(test: DwarfTest) {
158158 rustc.arg("-Cdebuginfo=2");
159159 if let Some(scope) = test.scope {
160160 match scope {
161 ScopeType::Object => rustc.arg("-Zremap-path-scope=object"),
162 ScopeType::Diagnostics => rustc.arg("-Zremap-path-scope=diagnostics"),
161 ScopeType::Object => rustc.arg("--remap-path-scope=object"),
162 ScopeType::Diagnostics => rustc.arg("--remap-path-scope=diagnostics"),
163163 };
164164 if is_darwin() {
165165 rustc.arg("-Csplit-debuginfo=off");
tests/run-make/remap-path-prefix/rmake.rs+3-3
......@@ -38,9 +38,9 @@ fn main() {
3838 rmeta_contains("/the/aux/lib.rs");
3939 rmeta_not_contains("auxiliary");
4040
41 out_object.arg("-Zremap-path-scope=object");
42 out_macro.arg("-Zremap-path-scope=macro");
43 out_diagobj.arg("-Zremap-path-scope=diagnostics,object");
41 out_object.arg("--remap-path-scope=object");
42 out_macro.arg("--remap-path-scope=macro");
43 out_diagobj.arg("--remap-path-scope=diagnostics,object");
4444 if is_darwin() {
4545 out_object.arg("-Csplit-debuginfo=off");
4646 out_macro.arg("-Csplit-debuginfo=off");
tests/run-make/rustc-help/help-v.diff+4-1
......@@ -1,4 +1,4 @@
1@@ -65,10 +65,28 @@
1@@ -65,10 +65,31 @@
22 Set a codegen option
33 -V, --version Print version info and exit
44 -v, --verbose Use verbose output
......@@ -20,6 +20,9 @@
2020+ --remap-path-prefix <FROM>=<TO>
2121+ Remap source names in all output (compiler messages
2222+ and output files)
23+ --remap-path-scope <macro,diagnostics,debuginfo,coverage,object,all>
24+ Defines which scopes of paths should be remapped by
25+ `--remap-path-prefix`
2326+ @path Read newline separated options from `path`
2427
2528 Additional help:
tests/run-make/rustc-help/help-v.stdout+3
......@@ -83,6 +83,9 @@ Options:
8383 --remap-path-prefix <FROM>=<TO>
8484 Remap source names in all output (compiler messages
8585 and output files)
86 --remap-path-scope <macro,diagnostics,debuginfo,coverage,object,all>
87 Defines which scopes of paths should be remapped by
88 `--remap-path-prefix`
8689 @path Read newline separated options from `path`
8790
8891Additional help:
tests/run-make/split-debuginfo/rmake.rs+6-7
......@@ -171,8 +171,7 @@ enum RemapPathPrefix {
171171 Unspecified,
172172}
173173
174/// `-Zremap-path-scope`. See
175/// <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/remap-path-scope.html#remap-path-scope>.
174/// `--remap-path-scope`
176175#[derive(Debug, Clone)]
177176enum RemapPathScope {
178177 /// Comma-separated list of remap scopes: `macro`, `diagnostics`, `debuginfo`, `object`, `all`.
......@@ -921,7 +920,7 @@ mod shared_linux_other_tests {
921920 .debuginfo(level.cli_value())
922921 .arg(format!("-Zsplit-dwarf-kind={}", split_dwarf_kind.cli_value()))
923922 .remap_path_prefix(cwd(), remapped_prefix)
924 .arg(format!("-Zremap-path-scope={scope}"))
923 .arg(format!("--remap-path-scope={scope}"))
925924 .run();
926925 let found_files = cwd_filenames();
927926 FileAssertions { expected_files: BTreeSet::from(["foo", "foo.dwp"]) }
......@@ -950,7 +949,7 @@ mod shared_linux_other_tests {
950949 .debuginfo(level.cli_value())
951950 .arg(format!("-Zsplit-dwarf-kind={}", split_dwarf_kind.cli_value()))
952951 .remap_path_prefix(cwd(), remapped_prefix)
953 .arg(format!("-Zremap-path-scope={scope}"))
952 .arg(format!("--remap-path-scope={scope}"))
954953 .run();
955954 let found_files = cwd_filenames();
956955 FileAssertions { expected_files: BTreeSet::from(["foo", "foo.dwp"]) }
......@@ -1202,7 +1201,7 @@ mod shared_linux_other_tests {
12021201 .debuginfo(level.cli_value())
12031202 .arg(format!("-Zsplit-dwarf-kind={}", split_dwarf_kind.cli_value()))
12041203 .remap_path_prefix(cwd(), remapped_prefix)
1205 .arg(format!("-Zremap-path-scope={scope}"))
1204 .arg(format!("--remap-path-scope={scope}"))
12061205 .run();
12071206
12081207 let found_files = cwd_filenames();
......@@ -1242,7 +1241,7 @@ mod shared_linux_other_tests {
12421241 .debuginfo(level.cli_value())
12431242 .arg(format!("-Zsplit-dwarf-kind={}", split_dwarf_kind.cli_value()))
12441243 .remap_path_prefix(cwd(), remapped_prefix)
1245 .arg(format!("-Zremap-path-scope={scope}"))
1244 .arg(format!("--remap-path-scope={scope}"))
12461245 .run();
12471246
12481247 let found_files = cwd_filenames();
......@@ -1356,7 +1355,7 @@ fn main() {
13561355 // NOTE: these combinations are not exhaustive, because while porting to rmake.rs initially I
13571356 // tried to preserve the existing test behavior closely. Notably, no attempt was made to
13581357 // exhaustively cover all cases in the 6-fold Cartesian product of `{,-Csplit=debuginfo=...}` x
1359 // `{,-Cdebuginfo=...}` x `{,--remap-path-prefix}` x `{,-Zremap-path-scope=...}` x
1358 // `{,-Cdebuginfo=...}` x `{,--remap-path-prefix}` x `{,--remap-path-scope=...}` x
13601359 // `{,-Zsplit-dwarf-kind=...}` x `{,-Clinker-plugin-lto}`. If you really want to, you can
13611360 // identify which combination isn't exercised with a 6-layers nested for loop iterating through
13621361 // each of the cli flag enum variants.
tests/rustdoc-html/intra-doc/deps.rs+3-3
......@@ -6,7 +6,7 @@
66//@ compile-flags: --extern-html-root-url=empty=https://empty.example/
77// This one is to ensure that we don't link to any item we see which has
88// an external html root URL unless it actually exists.
9//@ compile-flags: --extern-html-root-url=non_existant=https://non-existant.example/
9//@ compile-flags: --extern-html-root-url=non_existent=https://non-existent.example/
1010//@ aux-build: empty.rs
1111
1212#![crate_name = "foo"]
......@@ -14,10 +14,10 @@
1414
1515//@ has 'foo/index.html'
1616//@ has - '//a[@href="https://empty.example/empty/index.html"]' 'empty'
17// There should only be one intra doc links, we should not link `non_existant`.
17// There should only be one intra doc links, we should not link `non_existent`.
1818//@ count - '//*[@class="docblock"]//a' 1
1919//! [`empty`]
2020//!
21//! [`non_existant`]
21//! [`non_existent`]
2222
2323extern crate empty;
tests/ui/errors/auxiliary/file-debuginfo.rs+1-1
......@@ -1,5 +1,5 @@
11//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
2//@ compile-flags: -Zremap-path-scope=debuginfo
2//@ compile-flags: --remap-path-scope=debuginfo
33
44#[macro_export]
55macro_rules! my_file {
tests/ui/errors/auxiliary/file-diag.rs+1-1
......@@ -1,5 +1,5 @@
11//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
2//@ compile-flags: -Zremap-path-scope=diagnostics
2//@ compile-flags: --remap-path-scope=diagnostics
33
44#[macro_export]
55macro_rules! my_file {
tests/ui/errors/auxiliary/file-macro.rs+1-1
......@@ -1,5 +1,5 @@
11//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
2//@ compile-flags: -Zremap-path-scope=macro
2//@ compile-flags: --remap-path-scope=macro
33
44#[macro_export]
55macro_rules! my_file {
tests/ui/errors/auxiliary/trait-debuginfo.rs+1-1
......@@ -1,4 +1,4 @@
11//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
2//@ compile-flags: -Zremap-path-scope=debuginfo
2//@ compile-flags: --remap-path-scope=debuginfo
33
44pub trait Trait: std::fmt::Display {}
tests/ui/errors/auxiliary/trait-diag.rs+1-1
......@@ -1,4 +1,4 @@
11//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
2//@ compile-flags: -Zremap-path-scope=diagnostics
2//@ compile-flags: --remap-path-scope=diagnostics
33
44pub trait Trait: std::fmt::Display {}
tests/ui/errors/auxiliary/trait-macro.rs+1-1
......@@ -1,4 +1,4 @@
11//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
2//@ compile-flags: -Zremap-path-scope=macro
2//@ compile-flags: --remap-path-scope=macro
33
44pub trait Trait: std::fmt::Display {}
tests/ui/errors/remap-path-prefix-diagnostics.rs+5-5
......@@ -1,4 +1,4 @@
1// This test exercises `-Zremap-path-scope`, diagnostics printing paths and dependency.
1// This test exercises `--remap-path-scope`, diagnostics printing paths and dependency.
22//
33// We test different combinations with/without remap in deps, with/without remap in this
44// crate but always in deps and always here but never in deps.
......@@ -12,10 +12,10 @@
1212//@[with-debuginfo-in-deps] compile-flags: --remap-path-prefix={{src-base}}=remapped
1313//@[not-diag-in-deps] compile-flags: --remap-path-prefix={{src-base}}=remapped
1414
15//@[with-diag-in-deps] compile-flags: -Zremap-path-scope=diagnostics
16//@[with-macro-in-deps] compile-flags: -Zremap-path-scope=macro
17//@[with-debuginfo-in-deps] compile-flags: -Zremap-path-scope=debuginfo
18//@[not-diag-in-deps] compile-flags: -Zremap-path-scope=diagnostics
15//@[with-diag-in-deps] compile-flags: --remap-path-scope=diagnostics
16//@[with-macro-in-deps] compile-flags: --remap-path-scope=macro
17//@[with-debuginfo-in-deps] compile-flags: --remap-path-scope=debuginfo
18//@[not-diag-in-deps] compile-flags: --remap-path-scope=diagnostics
1919
2020//@[with-diag-in-deps] aux-build:trait-diag.rs
2121//@[with-macro-in-deps] aux-build:trait-macro.rs
tests/ui/errors/remap-path-prefix-macro.rs+5-5
......@@ -1,4 +1,4 @@
1// This test exercises `-Zremap-path-scope`, macros (like file!()) and dependency.
1// This test exercises `--remap-path-scope`, macros (like file!()) and dependency.
22//
33// We test different combinations with/without remap in deps, with/without remap in
44// this crate but always in deps and always here but never in deps.
......@@ -15,10 +15,10 @@
1515//@[with-debuginfo-in-deps] compile-flags: --remap-path-prefix={{src-base}}=remapped
1616//@[not-macro-in-deps] compile-flags: --remap-path-prefix={{src-base}}=remapped
1717
18//@[with-diag-in-deps] compile-flags: -Zremap-path-scope=diagnostics
19//@[with-macro-in-deps] compile-flags: -Zremap-path-scope=macro
20//@[with-debuginfo-in-deps] compile-flags: -Zremap-path-scope=debuginfo
21//@[not-macro-in-deps] compile-flags: -Zremap-path-scope=macro
18//@[with-diag-in-deps] compile-flags: --remap-path-scope=diagnostics
19//@[with-macro-in-deps] compile-flags: --remap-path-scope=macro
20//@[with-debuginfo-in-deps] compile-flags: --remap-path-scope=debuginfo
21//@[not-macro-in-deps] compile-flags: --remap-path-scope=macro
2222
2323//@[with-diag-in-deps] aux-build:file-diag.rs
2424//@[with-macro-in-deps] aux-build:file-macro.rs
tests/ui/errors/remap-path-prefix.rs+2-2
......@@ -1,7 +1,7 @@
11//@ revisions: normal with-diagnostic-scope without-diagnostic-scope
22//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
3//@ [with-diagnostic-scope]compile-flags: -Zremap-path-scope=diagnostics
4//@ [without-diagnostic-scope]compile-flags: -Zremap-path-scope=object
3//@ [with-diagnostic-scope]compile-flags: --remap-path-scope=diagnostics
4//@ [without-diagnostic-scope]compile-flags: --remap-path-scope=object
55// Manually remap, so the remapped path remains in .stderr file.
66
77// The remapped paths are not normalized by compiletest.
tests/ui/imports/ambiguous-trait-in-scope.rs created+84
......@@ -0,0 +1,84 @@
1//@ edition:2018
2//@ aux-crate:external=ambiguous-trait-reexport.rs
3
4mod m1 {
5 pub trait Trait {
6 fn method1(&self) {}
7 }
8 impl Trait for u8 {}
9}
10mod m2 {
11 pub trait Trait {
12 fn method2(&self) {}
13 }
14 impl Trait for u8 {}
15}
16mod m1_reexport {
17 pub use crate::m1::Trait;
18}
19mod m2_reexport {
20 pub use crate::m2::Trait;
21}
22
23mod ambig_reexport {
24 pub use crate::m1::*;
25 pub use crate::m2::*;
26}
27
28fn test1() {
29 // Create an ambiguous import for `Trait` in one order
30 use m1::*;
31 use m2::*;
32 0u8.method1(); //~ WARNING Use of ambiguously glob imported trait `Trait` [ambiguous_glob_imported_traits]
33 //~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
34 0u8.method2(); //~ ERROR: no method named `method2` found for type `u8` in the current scope
35}
36
37fn test2() {
38 // Create an ambiguous import for `Trait` in another order
39 use m2::*;
40 use m1::*;
41 0u8.method1(); //~ ERROR: no method named `method1` found for type `u8` in the current scope
42 0u8.method2(); //~ WARNING Use of ambiguously glob imported trait `Trait` [ambiguous_glob_imported_traits]
43 //~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
44}
45
46fn test_indirect_reexport() {
47 use m1_reexport::*;
48 use m2_reexport::*;
49 0u8.method1(); //~ WARNING Use of ambiguously glob imported trait `Trait` [ambiguous_glob_imported_traits]
50 //~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
51 0u8.method2(); //~ ERROR: no method named `method2` found for type `u8` in the current scope
52}
53
54fn test_ambig_reexport() {
55 use ambig_reexport::*;
56 0u8.method1(); //~ WARNING Use of ambiguously glob imported trait `Trait` [ambiguous_glob_imported_traits]
57 //~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
58 0u8.method2(); //~ ERROR: no method named `method2` found for type `u8` in the current scope
59}
60
61fn test_external() {
62 use external::m1::*;
63 use external::m2::*;
64 0u8.method1(); //~ WARNING Use of ambiguously glob imported trait `Trait` [ambiguous_glob_imported_traits]
65 //~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
66 0u8.method2(); //~ ERROR: no method named `method2` found for type `u8` in the current scope
67}
68
69fn test_external_indirect_reexport() {
70 use external::m1_reexport::*;
71 use external::m2_reexport::*;
72 0u8.method1(); //~ WARNING Use of ambiguously glob imported trait `Trait` [ambiguous_glob_imported_traits]
73 //~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
74 0u8.method2(); //~ ERROR: no method named `method2` found for type `u8` in the current scope
75}
76
77fn test_external_ambig_reexport() {
78 use external::ambig_reexport::*;
79 0u8.method1(); //~ WARNING Use of ambiguously glob imported trait `Trait` [ambiguous_glob_imported_traits]
80 //~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
81 0u8.method2(); //~ ERROR: no method named `method2` found for type `u8` in the current scope
82}
83
84fn main() {}
tests/ui/imports/ambiguous-trait-in-scope.stderr created+191
......@@ -0,0 +1,191 @@
1warning: Use of ambiguously glob imported trait `Trait`
2 --> $DIR/ambiguous-trait-in-scope.rs:32:9
3 |
4LL | use m1::*;
5 | -- `Trait` imported ambiguously here
6LL | use m2::*;
7LL | 0u8.method1();
8 | ^^^^^^^
9 |
10 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
11 = note: for more information, see issue #147992 <https://github.com/rust-lang/rust/issues/147992>
12 = help: Import `Trait` explicitly
13 = note: `#[warn(ambiguous_glob_imported_traits)]` (part of `#[warn(future_incompatible)]`) on by default
14
15error[E0599]: no method named `method2` found for type `u8` in the current scope
16 --> $DIR/ambiguous-trait-in-scope.rs:34:9
17 |
18LL | 0u8.method2();
19 | ^^^^^^^ method not found in `u8`
20 |
21 = help: items from traits can only be used if the trait is in scope
22help: the following traits which provide `method2` are implemented but not in scope; perhaps you want to import one of them
23 |
24LL + use ambiguous_trait_reexport::m2::Trait;
25 |
26LL + use crate::m2::Trait;
27 |
28
29error[E0599]: no method named `method1` found for type `u8` in the current scope
30 --> $DIR/ambiguous-trait-in-scope.rs:41:9
31 |
32LL | 0u8.method1();
33 | ^^^^^^^ method not found in `u8`
34 |
35 = help: items from traits can only be used if the trait is in scope
36help: the following traits which provide `method1` are implemented but not in scope; perhaps you want to import one of them
37 |
38LL + use ambiguous_trait_reexport::m1::Trait;
39 |
40LL + use crate::m1::Trait;
41 |
42
43warning: Use of ambiguously glob imported trait `Trait`
44 --> $DIR/ambiguous-trait-in-scope.rs:42:9
45 |
46LL | use m2::*;
47 | -- `Trait` imported ambiguously here
48...
49LL | 0u8.method2();
50 | ^^^^^^^
51 |
52 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
53 = note: for more information, see issue #147992 <https://github.com/rust-lang/rust/issues/147992>
54 = help: Import `Trait` explicitly
55
56warning: Use of ambiguously glob imported trait `Trait`
57 --> $DIR/ambiguous-trait-in-scope.rs:49:9
58 |
59LL | use m1_reexport::*;
60 | ----------- `Trait` imported ambiguously here
61LL | use m2_reexport::*;
62LL | 0u8.method1();
63 | ^^^^^^^
64 |
65 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
66 = note: for more information, see issue #147992 <https://github.com/rust-lang/rust/issues/147992>
67 = help: Import `Trait` explicitly
68
69error[E0599]: no method named `method2` found for type `u8` in the current scope
70 --> $DIR/ambiguous-trait-in-scope.rs:51:9
71 |
72LL | 0u8.method2();
73 | ^^^^^^^ method not found in `u8`
74 |
75 = help: items from traits can only be used if the trait is in scope
76help: the following traits which provide `method2` are implemented but not in scope; perhaps you want to import one of them
77 |
78LL + use ambiguous_trait_reexport::m2::Trait;
79 |
80LL + use crate::m2::Trait;
81 |
82
83warning: Use of ambiguously glob imported trait `Trait`
84 --> $DIR/ambiguous-trait-in-scope.rs:56:9
85 |
86LL | use ambig_reexport::*;
87 | -------------- `Trait` imported ambiguously here
88LL | 0u8.method1();
89 | ^^^^^^^
90 |
91 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
92 = note: for more information, see issue #147992 <https://github.com/rust-lang/rust/issues/147992>
93 = help: Import `Trait` explicitly
94
95error[E0599]: no method named `method2` found for type `u8` in the current scope
96 --> $DIR/ambiguous-trait-in-scope.rs:58:9
97 |
98LL | 0u8.method2();
99 | ^^^^^^^ method not found in `u8`
100 |
101 = help: items from traits can only be used if the trait is in scope
102help: the following traits which provide `method2` are implemented but not in scope; perhaps you want to import one of them
103 |
104LL + use ambiguous_trait_reexport::m2::Trait;
105 |
106LL + use crate::m2::Trait;
107 |
108
109warning: Use of ambiguously glob imported trait `Trait`
110 --> $DIR/ambiguous-trait-in-scope.rs:64:9
111 |
112LL | use external::m1::*;
113 | ------------ `Trait` imported ambiguously here
114LL | use external::m2::*;
115LL | 0u8.method1();
116 | ^^^^^^^
117 |
118 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
119 = note: for more information, see issue #147992 <https://github.com/rust-lang/rust/issues/147992>
120 = help: Import `Trait` explicitly
121
122error[E0599]: no method named `method2` found for type `u8` in the current scope
123 --> $DIR/ambiguous-trait-in-scope.rs:66:9
124 |
125LL | 0u8.method2();
126 | ^^^^^^^ method not found in `u8`
127 |
128 = help: items from traits can only be used if the trait is in scope
129help: the following traits which provide `method2` are implemented but not in scope; perhaps you want to import one of them
130 |
131LL + use ambiguous_trait_reexport::m2::Trait;
132 |
133LL + use crate::m2::Trait;
134 |
135
136warning: Use of ambiguously glob imported trait `Trait`
137 --> $DIR/ambiguous-trait-in-scope.rs:72:9
138 |
139LL | use external::m1_reexport::*;
140 | --------------------- `Trait` imported ambiguously here
141LL | use external::m2_reexport::*;
142LL | 0u8.method1();
143 | ^^^^^^^
144 |
145 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
146 = note: for more information, see issue #147992 <https://github.com/rust-lang/rust/issues/147992>
147 = help: Import `Trait` explicitly
148
149error[E0599]: no method named `method2` found for type `u8` in the current scope
150 --> $DIR/ambiguous-trait-in-scope.rs:74:9
151 |
152LL | 0u8.method2();
153 | ^^^^^^^ method not found in `u8`
154 |
155 = help: items from traits can only be used if the trait is in scope
156help: the following traits which provide `method2` are implemented but not in scope; perhaps you want to import one of them
157 |
158LL + use ambiguous_trait_reexport::m2::Trait;
159 |
160LL + use crate::m2::Trait;
161 |
162
163warning: Use of ambiguously glob imported trait `Trait`
164 --> $DIR/ambiguous-trait-in-scope.rs:79:9
165 |
166LL | use external::ambig_reexport::*;
167 | ------------------------ `Trait` imported ambiguously here
168LL | 0u8.method1();
169 | ^^^^^^^
170 |
171 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
172 = note: for more information, see issue #147992 <https://github.com/rust-lang/rust/issues/147992>
173 = help: Import `Trait` explicitly
174
175error[E0599]: no method named `method2` found for type `u8` in the current scope
176 --> $DIR/ambiguous-trait-in-scope.rs:81:9
177 |
178LL | 0u8.method2();
179 | ^^^^^^^ method not found in `u8`
180 |
181 = help: items from traits can only be used if the trait is in scope
182help: the following traits which provide `method2` are implemented but not in scope; perhaps you want to import one of them
183 |
184LL + use ambiguous_trait_reexport::m2::Trait;
185 |
186LL + use crate::m2::Trait;
187 |
188
189error: aborting due to 7 previous errors; 7 warnings emitted
190
191For more information about this error, try `rustc --explain E0599`.
tests/ui/imports/auxiliary/ambiguous-trait-reexport.rs created+23
......@@ -0,0 +1,23 @@
1pub mod m1 {
2 pub trait Trait {
3 fn method1(&self) {}
4 }
5 impl Trait for u8 {}
6}
7pub mod m2 {
8 pub trait Trait {
9 fn method2(&self) {}
10 }
11 impl Trait for u8 {}
12}
13pub mod m1_reexport {
14 pub use crate::m1::Trait;
15}
16pub mod m2_reexport {
17 pub use crate::m2::Trait;
18}
19
20pub mod ambig_reexport {
21 pub use crate::m1::*;
22 pub use crate::m2::*;
23}
tests/ui/imports/no-ambiguous-trait-lint-on-redundant-import.rs created+27
......@@ -0,0 +1,27 @@
1//@ check-pass
2// The AMBIGUOUS_GLOB_IMPORTED_TRAITS lint is reported on uses of traits that are
3// ambiguously glob imported. This test checks that we don't report this lint
4// when the same trait is glob imported multiple times.
5
6mod t {
7 pub trait Trait {
8 fn method(&self) {}
9 }
10
11 impl Trait for i8 {}
12}
13
14mod m1 {
15 pub use t::Trait;
16}
17
18mod m2 {
19 pub use t::Trait;
20}
21
22use m1::*;
23use m2::*;
24
25fn main() {
26 0i8.method();
27}