Skip to content

Commit 39ec825

Browse files
committed
Auto merge of #157473 - JonathanBrouwer:rollup-0TD8E2I, r=JonathanBrouwer
Rollup of 7 pull requests Successful merges: - #150453 (Dont bail in error predicate unless self ty is error in new solver) - #157442 (Create non-exhaustive `proc_macro::EscapeError` enum mirrorring `rustc-literal-escaper`'s) - #156892 (Suppress E0621 perpetual borrow suggestion) - #157135 (fix armv7a-none-eabihf tier doc) - #157360 (Document error conditions for `Command::{spawn, output, status}`) - #157418 (NVPTX: Add @kulst to the target maintainers) - #157443 (Make distinction between crate-level attributes that are warned vs errored)
2 parents 3179a47 + 6e9a810 commit 39ec825

25 files changed

Lines changed: 395 additions & 80 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ impl SingleAttributeParser for CrateNameParser {
1313
const PATH: &[Symbol] = &[sym::crate_name];
1414
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
1515
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
16-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
16+
const ALLOWED_TARGETS: AllowedTargets =
17+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
1718
const STABILITY: AttributeStability = AttributeStability::Stable;
1819

1920
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
@@ -31,7 +32,8 @@ impl CombineAttributeParser for CrateTypeParser {
3132
const PATH: &[Symbol] = &[sym::crate_type];
3233
type Item = CrateType;
3334
const CONVERT: ConvertFn<Self::Item> = |items, _| AttributeKind::CrateType(items);
34-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
35+
const ALLOWED_TARGETS: AllowedTargets =
36+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
3537
const TEMPLATE: AttributeTemplate =
3638
template!(NameValueStr: "crate type", "https://doc.rust-lang.org/reference/linkage.html");
3739
const STABILITY: AttributeStability = AttributeStability::Stable;
@@ -74,7 +76,8 @@ impl SingleAttributeParser for RecursionLimitParser {
7476
const PATH: &[Symbol] = &[sym::recursion_limit];
7577
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
7678
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N", "https://doc.rust-lang.org/reference/attributes/limits.html#the-recursion_limit-attribute");
77-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
79+
const ALLOWED_TARGETS: AllowedTargets =
80+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
7881
const STABILITY: AttributeStability = AttributeStability::Stable;
7982

8083
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
@@ -105,7 +108,8 @@ impl SingleAttributeParser for TypeLengthLimitParser {
105108
const PATH: &[Symbol] = &[sym::type_length_limit];
106109
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
107110
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N");
108-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
111+
const ALLOWED_TARGETS: AllowedTargets =
112+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
109113
const STABILITY: AttributeStability = AttributeStability::Stable;
110114

111115
fn convert(cx: &mut AcceptContext<'_, '_>, args: &ArgParser) -> Option<AttributeKind> {
@@ -147,7 +151,8 @@ pub(crate) struct NoStdParser;
147151
impl NoArgsAttributeParser for NoStdParser {
148152
const PATH: &[Symbol] = &[sym::no_std];
149153
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
150-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
154+
const ALLOWED_TARGETS: AllowedTargets =
155+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
151156
const STABILITY: AttributeStability = AttributeStability::Stable;
152157
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoStd;
153158
}
@@ -157,7 +162,8 @@ pub(crate) struct NoMainParser;
157162
impl NoArgsAttributeParser for NoMainParser {
158163
const PATH: &[Symbol] = &[sym::no_main];
159164
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
160-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
165+
const ALLOWED_TARGETS: AllowedTargets =
166+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
161167
const STABILITY: AttributeStability = AttributeStability::Stable;
162168
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoMain;
163169
}
@@ -176,7 +182,8 @@ pub(crate) struct WindowsSubsystemParser;
176182
impl SingleAttributeParser for WindowsSubsystemParser {
177183
const PATH: &[Symbol] = &[sym::windows_subsystem];
178184
const ON_DUPLICATE: OnDuplicate = OnDuplicate::WarnButFutureError;
179-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
185+
const ALLOWED_TARGETS: AllowedTargets =
186+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
180187
const TEMPLATE: AttributeTemplate = template!(NameValueStr: ["windows", "console"], "https://doc.rust-lang.org/reference/runtime.html#the-windows_subsystem-attribute");
181188
const STABILITY: AttributeStability = AttributeStability::Stable;
182189

@@ -231,7 +238,8 @@ pub(crate) struct NoBuiltinsParser;
231238
impl NoArgsAttributeParser for NoBuiltinsParser {
232239
const PATH: &[Symbol] = &[sym::no_builtins];
233240
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
234-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
241+
const ALLOWED_TARGETS: AllowedTargets =
242+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
235243
const STABILITY: AttributeStability = AttributeStability::Stable;
236244
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoBuiltins;
237245
}
@@ -269,7 +277,8 @@ impl CombineAttributeParser for FeatureParser {
269277
const PATH: &[Symbol] = &[sym::feature];
270278
type Item = Ident;
271279
const CONVERT: ConvertFn<Self::Item> = AttributeKind::Feature;
272-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
280+
const ALLOWED_TARGETS: AllowedTargets =
281+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]);
273282
const TEMPLATE: AttributeTemplate = template!(List: &["feature1, feature2, ..."]);
274283
const STABILITY: AttributeStability = AttributeStability::Stable;
275284

compiler/rustc_attr_parsing/src/errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ pub(crate) struct InvalidAttrStyle {
148148
pub crate_root_path: String,
149149
#[help("the crate root is at `{$crate_root_path}`")]
150150
pub show_crate_root_help: bool,
151+
#[primary_span]
152+
pub span: Span,
151153
}
152154

153155
#[derive(Diagnostic)]

compiler/rustc_attr_parsing/src/target_checking.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ impl<'sess> AttributeParser<'sess> {
114114
// For crate-level attributes we emit a specific set of lints to warn
115115
// people about accidentally not using them on the crate.
116116
if let &AllowedTargets::AllowList(&[Allow(Target::Crate)]) = allowed_targets {
117-
Self::check_crate_level(cx);
117+
Self::check_crate_level(cx, false);
118+
return;
119+
}
120+
if let &AllowedTargets::AllowListWarnRest(&[Allow(Target::Crate)]) = allowed_targets {
121+
Self::check_crate_level(cx, true);
118122
return;
119123
}
120124

@@ -181,7 +185,7 @@ impl<'sess> AttributeParser<'sess> {
181185
}
182186
}
183187

184-
pub(crate) fn check_crate_level(cx: &mut AcceptContext<'_, 'sess>) {
188+
pub(crate) fn check_crate_level(cx: &mut AcceptContext<'_, 'sess>, warn: bool) {
185189
if cx.target == Target::Crate {
186190
return;
187191
}
@@ -205,19 +209,20 @@ impl<'sess> AttributeParser<'sess> {
205209
})
206210
.unwrap_or_default();
207211

208-
let target = cx.target;
209-
cx.emit_lint(
210-
rustc_session::lint::builtin::UNUSED_ATTRIBUTES,
211-
crate::errors::InvalidAttrStyle {
212-
name,
213-
is_used_as_inner,
214-
target_span: (!is_used_as_inner).then_some(target_span),
215-
target: target.name(),
216-
crate_root_path,
217-
show_crate_root_help,
218-
},
219-
attr_span,
220-
);
212+
let diag = crate::errors::InvalidAttrStyle {
213+
name,
214+
is_used_as_inner,
215+
target_span: (!is_used_as_inner).then_some(target_span),
216+
target: cx.target.name(),
217+
crate_root_path,
218+
show_crate_root_help,
219+
span: attr_span,
220+
};
221+
if warn {
222+
cx.emit_lint(rustc_session::lint::builtin::UNUSED_ATTRIBUTES, diag, attr_span);
223+
} else {
224+
cx.emit_err(diag);
225+
}
221226
}
222227

223228
// FIXME: Fix "Cannot determine resolution" error and remove built-in macros

compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ where
224224
/// but prevents incorrect normalization while hiding any trait errors.
225225
fn consider_error_guaranteed_candidate(
226226
ecx: &mut EvalCtxt<'_, D>,
227+
goal: Goal<I, Self>,
227228
guar: I::ErrorGuaranteed,
228229
) -> Result<Candidate<I>, NoSolutionOrRerunNonErased>;
229230

@@ -578,8 +579,8 @@ where
578579
// Instead of adding the logic here, it's a better idea to add it in
579580
// `EvalCtxt::disqualify_auto_trait_candidate_due_to_possible_impl` in
580581
// `solve::trait_goals` instead.
581-
let result = if let Err(guar) = goal.predicate.error_reported() {
582-
G::consider_error_guaranteed_candidate(self, guar)
582+
let result = if let ty::Error(guar) = goal.predicate.self_ty().kind() {
583+
G::consider_error_guaranteed_candidate(self, goal, guar)
583584
} else if cx.trait_is_auto(trait_def_id) {
584585
G::consider_auto_trait_candidate(self, goal)
585586
} else if cx.trait_is_alias(trait_def_id) {

compiler/rustc_next_trait_solver/src/solve/effect_goals.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ where
191191

192192
fn consider_error_guaranteed_candidate(
193193
ecx: &mut EvalCtxt<'_, D>,
194+
_goal: Goal<I, Self>,
194195
_guar: I::ErrorGuaranteed,
195196
) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
196197
ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc)

compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,21 @@ where
436436
/// Fail to normalize if the predicate contains an error, alternatively, we could normalize to `ty::Error`
437437
/// and succeed. Can experiment with this to figure out what results in better error messages.
438438
fn consider_error_guaranteed_candidate(
439-
_ecx: &mut EvalCtxt<'_, D>,
440-
_guar: I::ErrorGuaranteed,
439+
ecx: &mut EvalCtxt<'_, D>,
440+
goal: Goal<I, Self>,
441+
guar: I::ErrorGuaranteed,
441442
) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
442-
Err(NoSolution.into())
443+
let cx = ecx.cx();
444+
let error_term = match goal.predicate.alias.kind {
445+
ty::AliasTermKind::ProjectionTy { .. } => Ty::new_error(cx, guar).into(),
446+
ty::AliasTermKind::ProjectionConst { .. } => Const::new_error(cx, guar).into(),
447+
kind => panic!("expected projection, found {kind:?}"),
448+
};
449+
450+
ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {
451+
ecx.instantiate_normalizes_to_term(goal, error_term);
452+
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
453+
})
443454
}
444455

445456
fn consider_auto_trait_candidate(

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ where
125125

126126
fn consider_error_guaranteed_candidate(
127127
ecx: &mut EvalCtxt<'_, D>,
128+
_goal: Goal<I, Self>,
128129
_guar: I::ErrorGuaranteed,
129130
) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
130131
ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc)

compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/named_anon_conflict.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! where one region is named and the other is anonymous.
33
44
use rustc_errors::Diag;
5+
use rustc_middle::ty;
56
use tracing::debug;
67

78
use crate::error_reporting::infer::nice_region_error::NiceRegionError;
@@ -72,16 +73,34 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
7273
{
7374
return None;
7475
}
76+
let orig_ty = anon_param_info.orig_param_ty;
77+
// Don't suggest naming the outer lifetime when it already appears in the pointee
78+
// (e.g. `&'a mut Buffer<'a>`); point at borrow splitting instead.
79+
let suggestion_would_alias_lifetime =
80+
if let ty::Ref(_, orig_inner_ty, ty::Mutability::Mut) = orig_ty.kind() {
81+
self.tcx().any_free_region_meets(orig_inner_ty, |r| r == named)
82+
} else {
83+
false
84+
};
85+
7586
let named = named.to_string();
87+
let new_ty_span = if suggestion_would_alias_lifetime { None } else { Some(new_ty_span) };
7688
let err = match param.pat.simple_ident() {
7789
Some(simple_ident) => ExplicitLifetimeRequired::WithIdent {
7890
span,
7991
simple_ident,
8092
named,
8193
new_ty_span,
8294
new_ty,
95+
link_nomicon: suggestion_would_alias_lifetime,
96+
},
97+
None => ExplicitLifetimeRequired::WithParamType {
98+
span,
99+
named,
100+
new_ty_span,
101+
new_ty,
102+
link_nomicon: suggestion_would_alias_lifetime,
83103
},
84-
None => ExplicitLifetimeRequired::WithParamType { span, named, new_ty_span, new_ty },
85104
};
86105
Some(self.tcx().sess.dcx().create_err(err))
87106
}

compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/util.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ pub struct AnonymousParamInfo<'tcx> {
1616
pub param: &'tcx hir::Param<'tcx>,
1717
/// The type corresponding to the anonymous region parameter.
1818
pub param_ty: Ty<'tcx>,
19+
/// The original type before region replacement.
20+
pub orig_param_ty: Ty<'tcx>,
1921
/// The `ty::LateParamRegionKind` corresponding to the anonymous region.
2022
pub kind: ty::LateParamRegionKind,
2123
/// The `Span` of the parameter type.
@@ -94,7 +96,14 @@ pub fn find_param_with_region<'tcx>(
9496
let ty_hir_id = fn_decl.inputs[index].hir_id;
9597
let param_ty_span = tcx.hir_span(ty_hir_id);
9698
let is_first = index == 0;
97-
AnonymousParamInfo { param, param_ty: new_param_ty, param_ty_span, kind, is_first }
99+
AnonymousParamInfo {
100+
param,
101+
param_ty: new_param_ty,
102+
orig_param_ty: ty,
103+
param_ty_span,
104+
kind,
105+
is_first,
106+
}
98107
})
99108
})
100109
}

compiler/rustc_trait_selection/src/errors.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,8 +868,13 @@ pub(crate) enum ExplicitLifetimeRequired<'a> {
868868
applicability = "unspecified",
869869
style = "verbose"
870870
)]
871-
new_ty_span: Span,
871+
new_ty_span: Option<Span>,
872872
new_ty: Ty<'a>,
873+
#[help(
874+
"see <https://doc.rust-lang.org/nomicon/borrow-splitting.html> \
875+
for more information about lifetime errors related to mutable references"
876+
)]
877+
link_nomicon: bool,
873878
},
874879
#[diag("explicit lifetime required in parameter type", code = E0621)]
875880
WithParamType {
@@ -883,8 +888,13 @@ pub(crate) enum ExplicitLifetimeRequired<'a> {
883888
applicability = "unspecified",
884889
style = "verbose"
885890
)]
886-
new_ty_span: Span,
891+
new_ty_span: Option<Span>,
887892
new_ty: Ty<'a>,
893+
#[help(
894+
"see <https://doc.rust-lang.org/nomicon/borrow-splitting.html> \
895+
for more information about lifetime errors related to mutable references"
896+
)]
897+
link_nomicon: bool,
888898
},
889899
}
890900

0 commit comments

Comments
 (0)