Skip to content

Commit ddc1a64

Browse files
committed
Auto merge of #157005 - JonathanBrouwer:rollup-1BZFgyy, r=JonathanBrouwer
Rollup of 9 pull requests Successful merges: - #156796 (Fix missing suggestion when matching `String` with `&str`) - #156933 (rustc_parse_format: improve the error diagnostic for `+` sign flag) - #156545 (fix issue-144595) - #156814 (Extend macOS deployment target mismatch filter to cover dylib and new ld formats) - #156851 (rustdoc: avoid ICE when rendering body-less type consts) - #156942 (Remove unneeded `#[skip_arg]` attributes) - #156972 (add field_projections fixme) - #156975 (Move check_cfg out of diagnostic attr module) - #156989 (Add missing --set rust.codegen-backends=["gcc"] in the gcc codegen Dockerfile for the core tests)
2 parents 2cfb951 + a64a3f2 commit ddc1a64

29 files changed

Lines changed: 309 additions & 35 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use rustc_span::{ErrorGuaranteed, Span, Symbol, sym};
2020
use thin_vec::ThinVec;
2121

2222
use crate::attributes::AttributeSafety;
23-
use crate::attributes::diagnostic::check_cfg;
2423
use crate::context::{AcceptContext, ShouldEmit};
2524
use crate::parser::{
2625
AllowExprMetavar, ArgParser, MetaItemListParser, MetaItemOrLitParser, NameValueParser,
@@ -29,7 +28,7 @@ use crate::session_diagnostics::{
2928
AttributeParseError, AttributeParseErrorReason, CfgAttrBadDelim, MetaBadDelimSugg,
3029
ParsedDescription,
3130
};
32-
use crate::{AttributeParser, parse_version, session_diagnostics};
31+
use crate::{AttributeParser, check_cfg, parse_version, session_diagnostics};
3332

3433
pub const CFG_TEMPLATE: AttributeTemplate = template!(
3534
List: &["predicate"],

compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use crate::errors::{
2323
};
2424
use crate::parser::{ArgParser, MetaItemListParser, MetaItemOrLitParser, MetaItemParser};
2525

26-
pub(crate) mod check_cfg;
2726
pub(crate) mod do_not_recommend;
2827
pub(crate) mod on_const;
2928
pub(crate) mod on_move;

compiler/rustc_attr_parsing/src/attributes/diagnostic/check_cfg.rs renamed to compiler/rustc_attr_parsing/src/check_cfg.rs

File renamed without changes.

compiler/rustc_attr_parsing/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ mod interface;
106106
/// like lists or name-value pairs.
107107
pub mod parser;
108108

109+
mod check_cfg;
109110
mod early_parsed;
110111
mod errors;
111112
mod safety;

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,7 @@ pub(crate) enum IncorrectReprFormatGenericCause {
274274
Int {
275275
#[primary_span]
276276
span: Span,
277-
278-
#[skip_arg]
279277
name: Symbol,
280-
281-
#[skip_arg]
282278
value: u128,
283279
},
284280

@@ -290,11 +286,7 @@ pub(crate) enum IncorrectReprFormatGenericCause {
290286
Symbol {
291287
#[primary_span]
292288
span: Span,
293-
294-
#[skip_arg]
295289
name: Symbol,
296-
297-
#[skip_arg]
298290
value: Symbol,
299291
},
300292
}

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,15 @@ fn report_linker_output(
781781

782782
// FIXME: Tracked by https://github.com/rust-lang/rust/issues/136113
783783
let deployment_mismatch = |line: &str| {
784-
line.starts_with("ld: warning: object file (")
785-
&& line.contains("was built for newer 'macOS' version")
786-
&& line.contains("than being linked")
784+
// ld64 (object files + dylibs) and ld_prime (object files only):
785+
(line.starts_with("ld: ")
786+
&& line.contains("was built for newer")
787+
&& line.contains("than being linked"))
788+
// ld_prime (Xcode 15+, dylibs only):
789+
|| (line.starts_with("ld: ")
790+
&& line.contains("building for")
791+
&& line.contains("but linking with")
792+
&& line.contains("which was built for newer version"))
787793
};
788794
// FIXME: This is a real warning we would like to show, but it hits too many crates
789795
// to want to turn it on immediately.

compiler/rustc_hir_typeck/src/pat.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10071007
//
10081008
// then that's equivalent to there existing a LUB.
10091009
let cause = self.pattern_cause(ti, span);
1010-
if let Err(err) = self.demand_suptype_with_origin(&cause, expected, pat_ty) {
1010+
if let Err(mut err) = self.demand_suptype_with_origin(&cause, expected, pat_ty) {
1011+
// If scrutinee is String and pattern is &str, suggest .as_str()
1012+
let expected = self.resolve_vars_with_obligations(expected);
1013+
if let ty::Adt(adt, _) = expected.kind()
1014+
&& self.tcx.is_lang_item(adt.did(), LangItem::String)
1015+
&& pat_ty.is_ref()
1016+
&& pat_ty.peel_refs().is_str()
1017+
&& let Some(origin_expr) = ti.origin_expr
1018+
{
1019+
err.span_suggestion_verbose(
1020+
origin_expr.span.shrink_to_hi(),
1021+
"consider converting the `String` to a `&str` using `.as_str()`",
1022+
".as_str()",
1023+
Applicability::MachineApplicable,
1024+
);
1025+
}
10111026
err.emit();
10121027
}
10131028

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,8 @@ where
898898
predicate: TraitRef::new(ecx.cx(), sized_trait, [ty]).upcast(ecx.cx()),
899899
},
900900
);
901+
// FIXME(field_projections): This function does some questionable incomplete stuff by
902+
// returning `Err(NoSolution)` on ambiguity.
901903
ecx.try_evaluate_added_goals()? == Certainty::Yes
902904
}
903905
&& match base.kind() {

compiler/rustc_parse/src/errors.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4639,3 +4639,28 @@ pub(crate) struct ReservedMultihashLint {
46394639
)]
46404640
pub suggestion: Span,
46414641
}
4642+
4643+
#[derive(Subdiagnostic)]
4644+
#[suggestion(
4645+
"if you meant to write a path, use a double colon:",
4646+
code = "::",
4647+
applicability = "maybe-incorrect"
4648+
)]
4649+
pub(crate) struct UseDoubleColonSuggestion {
4650+
#[primary_span]
4651+
pub colon: Span,
4652+
}
4653+
4654+
#[derive(Subdiagnostic)]
4655+
#[multipart_suggestion(
4656+
"if you meant to create a regular struct, use curly braces:",
4657+
applicability = "maybe-incorrect"
4658+
)]
4659+
pub(crate) struct UseRegularStructSuggestion {
4660+
#[suggestion_part(code = "{{")]
4661+
pub open: Span,
4662+
#[suggestion_part(code = "}}")]
4663+
pub close: Span,
4664+
#[suggestion_part(code = "")]
4665+
pub semicolon: Option<Span>,
4666+
}

compiler/rustc_parse/src/parser/item.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ use super::{
2323
AllowConstBlockItems, AttrWrapper, ExpKeywordPair, ExpTokenPair, FollowedByType, ForceCollect,
2424
Parser, PathStyle, Recovered, Trailing, UsePreAttrPos,
2525
};
26-
use crate::errors::{self, FnPointerCannotBeAsync, FnPointerCannotBeConst, MacroExpandsToAdtField};
26+
use crate::errors::{
27+
self, FnPointerCannotBeAsync, FnPointerCannotBeConst, MacroExpandsToAdtField,
28+
UseDoubleColonSuggestion, UseRegularStructSuggestion,
29+
};
2730
use crate::exp;
2831

2932
impl<'a> Parser<'a> {
@@ -2084,10 +2087,11 @@ impl<'a> Parser<'a> {
20842087
Safety::Default
20852088
}
20862089
}
2087-
2090+
/// This is the case where we find `struct Foo<T>(T) where T: Copy;`
2091+
/// Unit like structs are handled in parse_item_struct function
20882092
pub(super) fn parse_tuple_struct_body(&mut self) -> PResult<'a, ThinVec<FieldDef>> {
2089-
// This is the case where we find `struct Foo<T>(T) where T: Copy;`
2090-
// Unit like structs are handled in parse_item_struct function
2093+
let openparen_span = self.token.span;
2094+
let mut encountered_colon = false;
20912095
self.parse_paren_comma_seq(|p| {
20922096
let attrs = p.parse_outer_attributes()?;
20932097
p.collect_tokens(None, attrs, ForceCollect::No, |p, attrs| {
@@ -2109,6 +2113,8 @@ impl<'a> Parser<'a> {
21092113
}
21102114
};
21112115
let mut_restriction = p.parse_mut_restriction()?;
2116+
encountered_colon |=
2117+
p.token.is_ident() && p.look_ahead(1, |tok| tok == &token::Colon);
21122118
// Unsafe fields are not supported in tuple structs, as doing so would result in a
21132119
// parsing ambiguity for `struct X(unsafe fn())`.
21142120
let ty = match p.parse_ty() {
@@ -2156,6 +2162,19 @@ impl<'a> Parser<'a> {
21562162
})
21572163
})
21582164
.map(|(r, _)| r)
2165+
.map_err(|mut error| {
2166+
if encountered_colon {
2167+
error.subdiagnostic(UseDoubleColonSuggestion { colon: self.token.span });
2168+
self.eat_to_tokens(&[exp!(CloseParen)]);
2169+
self.bump();
2170+
error.subdiagnostic(UseRegularStructSuggestion {
2171+
open: openparen_span,
2172+
close: self.prev_token.span,
2173+
semicolon: if self.token == token::Semi { Some(self.token.span) } else { None },
2174+
});
2175+
}
2176+
error
2177+
})
21592178
}
21602179

21612180
/// Parses an element of a struct declaration.

0 commit comments

Comments
 (0)