Skip to content

Commit 01a6f30

Browse files
committed
Auto merge of #104236 - compiler-errors:rollup-adjshd6, r=compiler-errors
Rollup of 9 pull requests Successful merges: - #102763 (Some diagnostic-related nits) - #103443 (Parser: Recover from using colon as path separator in imports) - #103675 (remove redundent "<>" for ty::Slice with reference type) - #104046 (bootstrap: add support for running Miri on a file) - #104115 (Migrate crate-search element to CSS variables) - #104190 (Ignore "Change InferCtxtBuilder from enter to build" in git blame) - #104201 (Add check in GUI test for file loading failure) - #104211 (:arrow_up: rust-analyzer) - #104231 (Update mailmap) Failed merges: - #104169 (Migrate `:target` rules to use CSS variables) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 11fa085 + 609bea9 commit 01a6f30

File tree

108 files changed

+1624
-554
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+1624
-554
lines changed

.git-blame-ignore-revs

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ a06baa56b95674fc626b3c3fd680d6a65357fe60
44
95e00bfed801e264e9c4ac817004153ca0f19eb6
55
# reformat with new rustfmt
66
971c549ca334b7b7406e61e958efcca9c4152822
7+
# refactor infcx building
8+
283abbf0e7d20176f76006825b5c52e9a4234e4c

.mailmap

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ Hsiang-Cheng Yang <rick68@users.noreply.github.com>
217217
Ian Jackson <ijackson@chiark.greenend.org.uk> <ian.jackson@citrix.com>
218218
Ian Jackson <ijackson@chiark.greenend.org.uk> <ijackson+github@slimy.greenend.org.uk>
219219
Ian Jackson <ijackson@chiark.greenend.org.uk> <iwj@xenproject.org>
220-
Ibraheem Ahmed <ibrah1440@gmail.com>
220+
Ibraheem Ahmed <ibraheem@ibraheem.ca> <ibrah1440@gmail.com>
221221
Ilyong Cho <ilyoan@gmail.com>
222222
inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com>
223223
Irina Popa <irinagpopa@gmail.com>

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use rustc_errors::{
2-
Applicability, Diagnostic, DiagnosticBuilder, EmissionGuarantee, ErrorGuaranteed,
3-
};
1+
use rustc_errors::{Applicability, Diagnostic};
42
use rustc_hir as hir;
53
use rustc_hir::intravisit::Visitor;
64
use rustc_hir::Node;
@@ -629,25 +627,20 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
629627
self.buffer_error(err);
630628
}
631629

632-
fn suggest_map_index_mut_alternatives(
633-
&self,
634-
ty: Ty<'_>,
635-
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
636-
span: Span,
637-
) {
630+
fn suggest_map_index_mut_alternatives(&self, ty: Ty<'tcx>, err: &mut Diagnostic, span: Span) {
638631
let Some(adt) = ty.ty_adt_def() else { return };
639632
let did = adt.did();
640633
if self.infcx.tcx.is_diagnostic_item(sym::HashMap, did)
641634
|| self.infcx.tcx.is_diagnostic_item(sym::BTreeMap, did)
642635
{
643-
struct V<'a, 'b, 'tcx, G: EmissionGuarantee> {
636+
struct V<'a, 'tcx> {
644637
assign_span: Span,
645-
err: &'a mut DiagnosticBuilder<'b, G>,
638+
err: &'a mut Diagnostic,
646639
ty: Ty<'tcx>,
647640
suggested: bool,
648641
}
649-
impl<'a, 'b: 'a, 'hir, 'tcx, G: EmissionGuarantee> Visitor<'hir> for V<'a, 'b, 'tcx, G> {
650-
fn visit_stmt(&mut self, stmt: &'hir hir::Stmt<'hir>) {
642+
impl<'a, 'tcx> Visitor<'tcx> for V<'a, 'tcx> {
643+
fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt<'tcx>) {
651644
hir::intravisit::walk_stmt(self, stmt);
652645
let expr = match stmt.kind {
653646
hir::StmtKind::Semi(expr) | hir::StmtKind::Expr(expr) => expr,
@@ -705,7 +698,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
705698
),
706699
(rv.span.shrink_to_hi(), ")".to_string()),
707700
],
708-
].into_iter(),
701+
],
709702
Applicability::MachineApplicable,
710703
);
711704
self.suggested = true;

compiler/rustc_errors/src/diagnostic.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ impl Diagnostic {
742742
&mut self,
743743
sp: Span,
744744
msg: impl Into<SubdiagnosticMessage>,
745-
suggestions: impl Iterator<Item = String>,
745+
suggestions: impl IntoIterator<Item = String>,
746746
applicability: Applicability,
747747
) -> &mut Self {
748748
self.span_suggestions_with_style(
@@ -759,11 +759,11 @@ impl Diagnostic {
759759
&mut self,
760760
sp: Span,
761761
msg: impl Into<SubdiagnosticMessage>,
762-
suggestions: impl Iterator<Item = String>,
762+
suggestions: impl IntoIterator<Item = String>,
763763
applicability: Applicability,
764764
style: SuggestionStyle,
765765
) -> &mut Self {
766-
let mut suggestions: Vec<_> = suggestions.collect();
766+
let mut suggestions: Vec<_> = suggestions.into_iter().collect();
767767
suggestions.sort();
768768

769769
debug_assert!(
@@ -790,10 +790,10 @@ impl Diagnostic {
790790
pub fn multipart_suggestions(
791791
&mut self,
792792
msg: impl Into<SubdiagnosticMessage>,
793-
suggestions: impl Iterator<Item = Vec<(Span, String)>>,
793+
suggestions: impl IntoIterator<Item = Vec<(Span, String)>>,
794794
applicability: Applicability,
795795
) -> &mut Self {
796-
let suggestions: Vec<_> = suggestions.collect();
796+
let suggestions: Vec<_> = suggestions.into_iter().collect();
797797
debug_assert!(
798798
!(suggestions
799799
.iter()

compiler/rustc_errors/src/diagnostic_builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -599,13 +599,13 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
599599
&mut self,
600600
sp: Span,
601601
msg: impl Into<SubdiagnosticMessage>,
602-
suggestions: impl Iterator<Item = String>,
602+
suggestions: impl IntoIterator<Item = String>,
603603
applicability: Applicability,
604604
) -> &mut Self);
605605
forward!(pub fn multipart_suggestions(
606606
&mut self,
607607
msg: impl Into<SubdiagnosticMessage>,
608-
suggestions: impl Iterator<Item = Vec<(Span, String)>>,
608+
suggestions: impl IntoIterator<Item = Vec<(Span, String)>>,
609609
applicability: Applicability,
610610
) -> &mut Self);
611611
forward!(pub fn span_suggestion_short(

compiler/rustc_hir_typeck/src/method/suggest.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1900,6 +1900,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19001900
| ty::Str
19011901
| ty::Projection(_)
19021902
| ty::Param(_) => format!("{deref_ty}"),
1903+
// we need to test something like <&[_]>::len
1904+
// and Vec::function();
1905+
// <&[_]>::len doesn't need an extra "<>" between
1906+
// but for Adt type like Vec::function()
1907+
// we would suggest <[_]>::function();
1908+
_ if self.tcx.sess.source_map().span_wrapped_by_angle_bracket(ty.span) => format!("{deref_ty}"),
19031909
_ => format!("<{deref_ty}>"),
19041910
};
19051911
err.span_suggestion_verbose(

compiler/rustc_parse/src/parser/item.rs

+17
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,23 @@ impl<'a> Parser<'a> {
971971
if self.eat(&token::ModSep) {
972972
self.parse_use_tree_glob_or_nested()?
973973
} else {
974+
// Recover from using a colon as path separator.
975+
while self.eat_noexpect(&token::Colon) {
976+
self.struct_span_err(self.prev_token.span, "expected `::`, found `:`")
977+
.span_suggestion_short(
978+
self.prev_token.span,
979+
"use double colon",
980+
"::",
981+
Applicability::MachineApplicable,
982+
)
983+
.note_once("import paths are delimited using `::`")
984+
.emit();
985+
986+
// We parse the rest of the path and append it to the original prefix.
987+
self.parse_path_segments(&mut prefix.segments, PathStyle::Mod, None)?;
988+
prefix.span = lo.to(self.prev_token.span);
989+
}
990+
974991
UseTreeKind::Simple(self.parse_rename()?, DUMMY_NODE_ID, DUMMY_NODE_ID)
975992
}
976993
};

compiler/rustc_parse/src/parser/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ impl<'a> Parser<'a> {
401401
.span_suggestions(
402402
span.shrink_to_hi(),
403403
"add `mut` or `const` here",
404-
["mut ".to_string(), "const ".to_string()].into_iter(),
404+
["mut ".to_string(), "const ".to_string()],
405405
Applicability::HasPlaceholders,
406406
)
407407
.emit();

compiler/rustc_passes/src/liveness.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ use self::VarKind::*;
8787
use rustc_ast::InlineAsmOptions;
8888
use rustc_data_structures::fx::FxIndexMap;
8989
use rustc_errors::Applicability;
90+
use rustc_errors::Diagnostic;
9091
use rustc_hir as hir;
9192
use rustc_hir::def::*;
9293
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -1690,7 +1691,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
16901691
&self,
16911692
name: &str,
16921693
opt_body: Option<&hir::Body<'_>>,
1693-
err: &mut rustc_errors::DiagnosticBuilder<'_, ()>,
1694+
err: &mut Diagnostic,
16941695
) -> bool {
16951696
let mut has_litstring = false;
16961697
let Some(opt_body) = opt_body else {return false;};

compiler/rustc_resolve/src/late/diagnostics.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
437437

438438
fn try_lookup_name_relaxed(
439439
&mut self,
440-
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
440+
err: &mut Diagnostic,
441441
source: PathSource<'_>,
442442
path: &[Segment],
443443
span: Span,
@@ -497,7 +497,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
497497
.contains(span)
498498
{
499499
// Already reported this issue on the lhs of the type ascription.
500-
err.delay_as_bug();
500+
err.downgrade_to_delayed_bug();
501501
return (true, candidates);
502502
}
503503
}
@@ -616,7 +616,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
616616

617617
fn suggest_trait_and_bounds(
618618
&mut self,
619-
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
619+
err: &mut Diagnostic,
620620
source: PathSource<'_>,
621621
res: Option<Res>,
622622
span: Span,
@@ -691,7 +691,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
691691

692692
fn suggest_typo(
693693
&mut self,
694-
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
694+
err: &mut Diagnostic,
695695
source: PathSource<'_>,
696696
path: &[Segment],
697697
span: Span,
@@ -750,7 +750,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
750750

751751
fn err_code_special_cases(
752752
&mut self,
753-
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
753+
err: &mut Diagnostic,
754754
source: PathSource<'_>,
755755
path: &[Segment],
756756
span: Span,
@@ -1941,7 +1941,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
19411941
err.span_suggestions(
19421942
span,
19431943
&msg,
1944-
suggestable_variants.into_iter(),
1944+
suggestable_variants,
19451945
Applicability::MaybeIncorrect,
19461946
);
19471947
}
@@ -1995,7 +1995,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
19951995
err.span_suggestions(
19961996
span,
19971997
msg,
1998-
suggestable_variants.into_iter(),
1998+
suggestable_variants,
19991999
Applicability::MaybeIncorrect,
20002000
);
20012001
}
@@ -2025,7 +2025,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
20252025
err.span_suggestions(
20262026
span,
20272027
msg,
2028-
suggestable_variants_with_placeholders.into_iter(),
2028+
suggestable_variants_with_placeholders,
20292029
Applicability::HasPlaceholders,
20302030
);
20312031
}

compiler/rustc_span/src/source_map.rs

+44
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,50 @@ impl SourceMap {
753753
}
754754
}
755755

756+
/// Given a 'Span', tries to tell if the next character is '>'
757+
/// and the previous charactoer is '<' after skipping white space
758+
/// return true if wrapped by '<>'
759+
pub fn span_wrapped_by_angle_bracket(&self, span: Span) -> bool {
760+
self.span_to_source(span, |src, start_index, end_index| {
761+
if src.get(start_index..end_index).is_none() {
762+
return Ok(false);
763+
}
764+
// test the right side to match '>' after skipping white space
765+
let end_src = &src[end_index..];
766+
let mut i = 0;
767+
while let Some(cc) = end_src.chars().nth(i) {
768+
if cc == ' ' {
769+
i = i + 1;
770+
} else if cc == '>' {
771+
// found > in the right;
772+
break;
773+
} else {
774+
// failed to find '>' return false immediately
775+
return Ok(false);
776+
}
777+
}
778+
// test the left side to match '<' after skipping white space
779+
i = start_index;
780+
let start_src = &src[0..start_index];
781+
while let Some(cc) = start_src.chars().nth(i) {
782+
if cc == ' ' {
783+
if i == 0 {
784+
return Ok(false);
785+
}
786+
i = i - 1;
787+
} else if cc == '<' {
788+
// found < in the left
789+
break;
790+
} else {
791+
// failed to find '<' return false immediately
792+
return Ok(false);
793+
}
794+
}
795+
return Ok(true);
796+
})
797+
.map_or(false, |is_accessible| is_accessible)
798+
}
799+
756800
/// Given a `Span`, tries to get a shorter span ending just after the first occurrence of `char`
757801
/// `c`.
758802
pub fn span_through_char(&self, sp: Span, c: char) -> Span {

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
11161116
err.span_suggestions(
11171117
span.shrink_to_lo(),
11181118
"consider borrowing here",
1119-
["&".to_string(), "&mut ".to_string()].into_iter(),
1119+
["&".to_string(), "&mut ".to_string()],
11201120
Applicability::MaybeIncorrect,
11211121
);
11221122
} else {

src/bootstrap/builder.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ impl<'a> Builder<'a> {
755755
run::BuildManifest,
756756
run::BumpStage0,
757757
run::ReplaceVersionPlaceholder,
758+
run::Miri,
758759
),
759760
// These commands either don't use paths, or they're special-cased in Build::build()
760761
Kind::Clean | Kind::Format | Kind::Setup => vec![],
@@ -818,7 +819,7 @@ impl<'a> Builder<'a> {
818819
Subcommand::Bench { ref paths, .. } => (Kind::Bench, &paths[..]),
819820
Subcommand::Dist { ref paths } => (Kind::Dist, &paths[..]),
820821
Subcommand::Install { ref paths } => (Kind::Install, &paths[..]),
821-
Subcommand::Run { ref paths } => (Kind::Run, &paths[..]),
822+
Subcommand::Run { ref paths, .. } => (Kind::Run, &paths[..]),
822823
Subcommand::Format { .. } => (Kind::Format, &[][..]),
823824
Subcommand::Clean { .. } | Subcommand::Setup { .. } => {
824825
panic!()

src/bootstrap/flags.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ pub enum Subcommand {
140140
},
141141
Run {
142142
paths: Vec<PathBuf>,
143+
args: Vec<String>,
143144
},
144145
Setup {
145146
profile: Profile,
@@ -342,6 +343,9 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
342343
Kind::Format => {
343344
opts.optflag("", "check", "check formatting instead of applying.");
344345
}
346+
Kind::Run => {
347+
opts.optmulti("", "args", "arguments for the tool", "ARGS");
348+
}
345349
_ => {}
346350
};
347351

@@ -613,7 +617,7 @@ Arguments:
613617
println!("\nrun requires at least a path!\n");
614618
usage(1, &opts, verbose, &subcommand_help);
615619
}
616-
Subcommand::Run { paths }
620+
Subcommand::Run { paths, args: matches.opt_strs("args") }
617621
}
618622
Kind::Setup => {
619623
let profile = if paths.len() > 1 {
@@ -721,24 +725,29 @@ impl Subcommand {
721725
}
722726

723727
pub fn test_args(&self) -> Vec<&str> {
724-
let mut args = vec![];
725-
726728
match *self {
727729
Subcommand::Test { ref test_args, .. } | Subcommand::Bench { ref test_args, .. } => {
728-
args.extend(test_args.iter().flat_map(|s| s.split_whitespace()))
730+
test_args.iter().flat_map(|s| s.split_whitespace()).collect()
729731
}
730-
_ => (),
732+
_ => vec![],
731733
}
732-
733-
args
734734
}
735735

736736
pub fn rustc_args(&self) -> Vec<&str> {
737737
match *self {
738738
Subcommand::Test { ref rustc_args, .. } => {
739739
rustc_args.iter().flat_map(|s| s.split_whitespace()).collect()
740740
}
741-
_ => Vec::new(),
741+
_ => vec![],
742+
}
743+
}
744+
745+
pub fn args(&self) -> Vec<&str> {
746+
match *self {
747+
Subcommand::Run { ref args, .. } => {
748+
args.iter().flat_map(|s| s.split_whitespace()).collect()
749+
}
750+
_ => vec![],
742751
}
743752
}
744753

0 commit comments

Comments
 (0)