Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #134392

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
665d7ad
Improve testing coverage for `#[diagnostic::do_not_recommend]`
weiznich Oct 22, 2024
68cd044
Check `#[diagnostic::do_not_recommend]` for arguments
weiznich Oct 23, 2024
70ab7a7
Stabilize `#[diagnostic::do_not_recommend]`
weiznich Oct 23, 2024
fad597f
Also warn against `#[diagnostic::do_not_recommend]` on plain impls
weiznich Oct 25, 2024
577b5f3
CI: use free runners for x86_64-gnu-llvm jobs
MarcoIeni Dec 10, 2024
e67e9b4
fix
MarcoIeni Dec 10, 2024
4f0e781
split better
MarcoIeni Dec 11, 2024
bb88d7a
fix
MarcoIeni Dec 11, 2024
84ba41d
remove unnecessary change
MarcoIeni Dec 11, 2024
abd8352
restore command
MarcoIeni Dec 11, 2024
a8bc3cf
fix
MarcoIeni Dec 11, 2024
d74de1f
debug
MarcoIeni Dec 11, 2024
754fb24
debug
MarcoIeni Dec 11, 2024
9ed728d
debug
MarcoIeni Dec 11, 2024
eec9bcf
more debug
MarcoIeni Dec 11, 2024
fee220a
fix
MarcoIeni Dec 11, 2024
1f38572
fix
MarcoIeni Dec 11, 2024
7ce2944
test stage 1 in separate job
MarcoIeni Dec 12, 2024
aa0fd46
copy script
MarcoIeni Dec 12, 2024
a1abbaa
remove echo logs
MarcoIeni Dec 12, 2024
2bf1cec
refactor
MarcoIeni Dec 12, 2024
c2f4550
remove echo
MarcoIeni Dec 12, 2024
a67a71d
add files
MarcoIeni Dec 12, 2024
4fa9078
fix path
MarcoIeni Dec 12, 2024
ac078a4
fix path
MarcoIeni Dec 12, 2024
de16ed3
Correctly handle comments in attributes in doctests source code
GuillaumeGomez Dec 13, 2024
165f37e
rustc_mir_build: Clarify that 'mirrored' does not mean 'flipped' or '…
Enselic Dec 12, 2024
f068d8b
rustdoc-search: show `impl Trait` inline when unhighlighted
notriddle Dec 13, 2024
246835e
rustdoc-search: let From and Into be unboxed
notriddle Dec 13, 2024
0be3ed0
rustdoc-search: update documentation with notes about unboxing
notriddle Dec 13, 2024
0f82cff
Keep track of patterns that could have introduced a binding, but didn't
estebank Dec 13, 2024
8c8e8d3
Use `ErrorGuaranteed` more
estebank Dec 15, 2024
733fd03
Use `span_label` as it looks better when we show pattern missing bind…
estebank Dec 15, 2024
9c4a61f
Add ui regression test for #134221
GuillaumeGomez Dec 13, 2024
2383985
Also handle cases where attributes are unclosed
GuillaumeGomez Dec 16, 2024
bdb88c9
Avoid creating a fn sig type just to unwrap it again to get at its si…
oli-obk Dec 16, 2024
f387b9d
Properly name a def id variable
oli-obk Dec 16, 2024
4032b9d
Avoid wrapping a trivially defaultable type in `Option`
oli-obk Dec 16, 2024
1c7d54e
Deduplicate some pretty printing logic
oli-obk Dec 16, 2024
1d834c2
Avoid wrapping fn sig in a fn pointer when we want to just print the sig
oli-obk Dec 16, 2024
86e0eab
tests/ui/asm: Remove uses of rustc_attrs, lang_items, and decl_macro …
taiki-e Dec 16, 2024
c367cc3
Remove unneeded handling of backlines in doctest attributes
GuillaumeGomez Dec 16, 2024
593de5e
Rollup merge of #132056 - weiznich:diagnostic_do_not_recommend_final_…
GuillaumeGomez Dec 16, 2024
23e3ccf
Rollup merge of #134124 - MarcoIeni:split-llvm-jobs, r=Kobzol
GuillaumeGomez Dec 16, 2024
ee28906
Rollup merge of #134197 - Enselic:mirror, r=lcnr
GuillaumeGomez Dec 16, 2024
3427170
Rollup merge of #134260 - GuillaumeGomez:doctest-attrs, r=notriddle
GuillaumeGomez Dec 16, 2024
1df4cef
Rollup merge of #134277 - notriddle:notriddle/inline-into, r=Guillaum…
GuillaumeGomez Dec 16, 2024
01ec9cd
Rollup merge of #134284 - estebank:issue-74863, r=lcnr
GuillaumeGomez Dec 16, 2024
ca1d4c8
Rollup merge of #134385 - taiki-e:ui-asm-minicore, r=compiler-errors
GuillaumeGomez Dec 16, 2024
2c02fd3
Rollup merge of #134386 - oli-obk:some-trait-impl-diff-diagnostic-cle…
GuillaumeGomez Dec 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,8 @@ pub enum PatKind {
pub enum PatFieldsRest {
/// `module::StructName { field, ..}`
Rest,
/// `module::StructName { field, syntax error }`
Recovered(ErrorGuaranteed),
/// `module::StructName { field }`
None,
}
Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_ast_lowering/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
span: self.lower_span(f.span),
}
}));
break hir::PatKind::Struct(qpath, fs, *etc == ast::PatFieldsRest::Rest);
break hir::PatKind::Struct(
qpath,
fs,
matches!(
etc,
ast::PatFieldsRest::Rest | ast::PatFieldsRest::Recovered(_)
),
);
}
PatKind::Tuple(pats) => {
let (pats, ddpos) = self.lower_pat_tuple(pats, "tuple");
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1654,11 +1654,14 @@ impl<'a> State<'a> {
},
|f| f.pat.span,
);
if *etc == ast::PatFieldsRest::Rest {
if let ast::PatFieldsRest::Rest | ast::PatFieldsRest::Recovered(_) = etc {
if !fields.is_empty() {
self.word_space(",");
}
self.word("..");
if let ast::PatFieldsRest::Recovered(_) = etc {
self.word("/* recovered parse error */");
}
}
if !empty {
self.space();
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,8 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
) -> RegionNameHighlight {
let mut highlight = RegionHighlightMode::default();
highlight.highlighting_region_vid(self.infcx.tcx, needle_fr, counter);
let type_name = self
.infcx
.err_ctxt()
.extract_inference_diagnostics_data(ty.into(), Some(highlight))
.name;
let type_name =
self.infcx.err_ctxt().extract_inference_diagnostics_data(ty.into(), highlight).name;

debug!(
"highlight_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}",
Expand Down Expand Up @@ -874,7 +871,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
let type_name = self
.infcx
.err_ctxt()
.extract_inference_diagnostics_data(yield_ty.into(), Some(highlight))
.extract_inference_diagnostics_data(yield_ty.into(), highlight)
.name;

let yield_span = match tcx.hir_node(self.mir_hir_id()) {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ declare_features! (
(accepted, destructuring_assignment, "1.59.0", Some(71126)),
/// Allows using the `#[diagnostic]` attribute tool namespace
(accepted, diagnostic_namespace, "1.78.0", Some(111996)),
/// Controls errors in trait implementations.
(accepted, do_not_recommend, "CURRENT_RUSTC_VERSION", Some(51992)),
/// Allows `#[doc(alias = "...")]`.
(accepted, doc_alias, "1.48.0", Some(50146)),
/// Allows `..` in tuple (struct) patterns.
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1188,10 +1188,9 @@ pub static BUILTIN_ATTRIBUTE_MAP: LazyLock<FxHashMap<Symbol, &BuiltinAttribute>>
map
});

pub fn is_stable_diagnostic_attribute(sym: Symbol, features: &Features) -> bool {
pub fn is_stable_diagnostic_attribute(sym: Symbol, _features: &Features) -> bool {
match sym {
sym::on_unimplemented => true,
sym::do_not_recommend => features.do_not_recommend(),
sym::on_unimplemented | sym::do_not_recommend => true,
_ => false,
}
}
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,6 @@ declare_features! (
(unstable, deprecated_suggestion, "1.61.0", Some(94785)),
/// Allows deref patterns.
(incomplete, deref_patterns, "1.79.0", Some(87121)),
/// Controls errors in trait implementations.
(unstable, do_not_recommend, "1.67.0", Some(51992)),
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
(unstable, doc_auto_cfg, "1.58.0", Some(43781)),
/// Allows `#[doc(cfg(...))]`.
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_mir_build/src/thir/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ use crate::thir::cx::Cx;
use crate::thir::util::UserAnnotatedTyHelpers;

impl<'tcx> Cx<'tcx> {
/// Create a THIR expression for the given HIR expression. This expands all
/// adjustments and directly adds the type information from the
/// `typeck_results`. See the [dev-guide] for more details.
///
/// (The term "mirror" in this case does not refer to "flipped" or
/// "reversed".)
///
/// [dev-guide]: https://rustc-dev-guide.rust-lang.org/thir.html
pub(crate) fn mirror_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) -> ExprId {
// `mirror_expr` is recursing very deep. Make sure the stack doesn't overflow.
ensure_sufficient_stack(|| self.mirror_expr_inner(expr))
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1371,10 +1371,10 @@ impl<'a> Parser<'a> {
self.bump();
let (fields, etc) = self.parse_pat_fields().unwrap_or_else(|mut e| {
e.span_label(path.span, "while parsing the fields for this pattern");
e.emit();
let guar = e.emit();
self.recover_stmt();
// When recovering, pretend we had `Foo { .. }`, to avoid cascading errors.
(ThinVec::new(), PatFieldsRest::Rest)
(ThinVec::new(), PatFieldsRest::Recovered(guar))
});
self.bump();
Ok(PatKind::Struct(qself, path, fields, etc))
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ passes_ignored_derived_impls =
passes_implied_feature_not_exist =
feature `{$implied_by}` implying `{$feature}` does not exist

passes_incorrect_do_not_recommend_args =
`#[diagnostic::do_not_recommend]` does not expect any arguments

passes_incorrect_do_not_recommend_location =
`#[diagnostic::do_not_recommend]` can only be placed on trait implementations

Expand Down
27 changes: 24 additions & 3 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
for attr in attrs {
match attr.path().as_slice() {
[sym::diagnostic, sym::do_not_recommend, ..] => {
self.check_do_not_recommend(attr.span, hir_id, target)
self.check_do_not_recommend(attr.span, hir_id, target, attr, item)
}
[sym::diagnostic, sym::on_unimplemented, ..] => {
self.check_diagnostic_on_unimplemented(attr.span, hir_id, target)
Expand Down Expand Up @@ -349,15 +349,36 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}

/// Checks if `#[diagnostic::do_not_recommend]` is applied on a trait impl.
fn check_do_not_recommend(&self, attr_span: Span, hir_id: HirId, target: Target) {
if !matches!(target, Target::Impl) {
fn check_do_not_recommend(
&self,
attr_span: Span,
hir_id: HirId,
target: Target,
attr: &Attribute,
item: Option<ItemLike<'_>>,
) {
if !matches!(target, Target::Impl)
|| matches!(
item,
Some(ItemLike::Item(hir::Item { kind: hir::ItemKind::Impl(_impl),.. }))
if _impl.of_trait.is_none()
)
{
self.tcx.emit_node_span_lint(
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
hir_id,
attr_span,
errors::IncorrectDoNotRecommendLocation,
);
}
if !matches!(attr.meta_kind(), Some(MetaItemKind::Word)) {
self.tcx.emit_node_span_lint(
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
hir_id,
attr_span,
errors::DoNotRecommendDoesNotExpectArgs,
);
}
}

/// Checks if `#[diagnostic::on_unimplemented]` is applied to a trait definition
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ use crate::lang_items::Duplicate;
#[diag(passes_incorrect_do_not_recommend_location)]
pub(crate) struct IncorrectDoNotRecommendLocation;

#[derive(LintDiagnostic)]
#[diag(passes_incorrect_do_not_recommend_args)]
pub(crate) struct DoNotRecommendDoesNotExpectArgs;

#[derive(Diagnostic)]
#[diag(passes_autodiff_attr)]
pub(crate) struct AutoDiffAttr {
Expand Down
40 changes: 36 additions & 4 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ use rustc_ast::visit::{
use rustc_ast::*;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
use rustc_errors::codes::*;
use rustc_errors::{Applicability, DiagArgValue, IntoDiagArg, StashKey, Suggestions};
use rustc_errors::{
Applicability, DiagArgValue, ErrorGuaranteed, IntoDiagArg, StashKey, Suggestions,
};
use rustc_hir::def::Namespace::{self, *};
use rustc_hir::def::{self, CtorKind, DefKind, LifetimeRes, NonMacroAttrKind, PartialRes, PerNS};
use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LOCAL_CRATE, LocalDefId};
Expand Down Expand Up @@ -264,12 +266,17 @@ impl RibKind<'_> {
#[derive(Debug)]
pub(crate) struct Rib<'ra, R = Res> {
pub bindings: IdentMap<R>,
pub patterns_with_skipped_bindings: FxHashMap<DefId, Vec<(Span, Result<(), ErrorGuaranteed>)>>,
pub kind: RibKind<'ra>,
}

impl<'ra, R> Rib<'ra, R> {
fn new(kind: RibKind<'ra>) -> Rib<'ra, R> {
Rib { bindings: Default::default(), kind }
Rib {
bindings: Default::default(),
patterns_with_skipped_bindings: Default::default(),
kind,
}
}
}

Expand Down Expand Up @@ -3775,6 +3782,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
/// When a whole or-pattern has been dealt with, the thing happens.
///
/// See the implementation and `fresh_binding` for more details.
#[tracing::instrument(skip(self, bindings), level = "debug")]
fn resolve_pattern_inner(
&mut self,
pat: &Pat,
Expand All @@ -3783,7 +3791,6 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
) {
// Visit all direct subpatterns of this pattern.
pat.walk(&mut |pat| {
debug!("resolve_pattern pat={:?} node={:?}", pat, pat.kind);
match pat.kind {
PatKind::Ident(bmode, ident, ref sub) => {
// First try to resolve the identifier as some existing entity,
Expand All @@ -3809,8 +3816,9 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
PatKind::Path(ref qself, ref path) => {
self.smart_resolve_path(pat.id, qself, path, PathSource::Pat);
}
PatKind::Struct(ref qself, ref path, ..) => {
PatKind::Struct(ref qself, ref path, ref _fields, ref rest) => {
self.smart_resolve_path(pat.id, qself, path, PathSource::Struct);
self.record_patterns_with_skipped_bindings(pat, rest);
}
PatKind::Or(ref ps) => {
// Add a new set of bindings to the stack. `Or` here records that when a
Expand Down Expand Up @@ -3843,6 +3851,30 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
});
}

fn record_patterns_with_skipped_bindings(&mut self, pat: &Pat, rest: &ast::PatFieldsRest) {
match rest {
ast::PatFieldsRest::Rest | ast::PatFieldsRest::Recovered(_) => {
// Record that the pattern doesn't introduce all the bindings it could.
if let Some(partial_res) = self.r.partial_res_map.get(&pat.id)
&& let Some(res) = partial_res.full_res()
&& let Some(def_id) = res.opt_def_id()
{
self.ribs[ValueNS]
.last_mut()
.unwrap()
.patterns_with_skipped_bindings
.entry(def_id)
.or_default()
.push((pat.span, match rest {
ast::PatFieldsRest::Recovered(guar) => Err(*guar),
_ => Ok(()),
}));
}
}
ast::PatFieldsRest::None => {}
}
}

fn fresh_binding(
&mut self,
ident: Ident,
Expand Down
43 changes: 43 additions & 0 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
let mut err = self.r.dcx().struct_span_err(base_error.span, base_error.msg.clone());
err.code(code);

self.detect_missing_binding_available_from_pattern(&mut err, path, following_seg);
self.suggest_at_operator_in_slice_pat_with_range(&mut err, path);
self.suggest_swapping_misplaced_self_ty_and_trait(&mut err, source, res, base_error.span);

Expand Down Expand Up @@ -1120,6 +1121,48 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
true
}

fn detect_missing_binding_available_from_pattern(
&mut self,
err: &mut Diag<'_>,
path: &[Segment],
following_seg: Option<&Segment>,
) {
let [segment] = path else { return };
let None = following_seg else { return };
for rib in self.ribs[ValueNS].iter().rev() {
for (def_id, spans) in &rib.patterns_with_skipped_bindings {
if let Some(fields) = self.r.field_idents(*def_id) {
for field in fields {
if field.name == segment.ident.name {
if spans.iter().all(|(_, had_error)| had_error.is_err()) {
// This resolution error will likely be fixed by fixing a
// syntax error in a pattern, so it is irrelevant to the user.
let multispan: MultiSpan =
spans.iter().map(|(s, _)| *s).collect::<Vec<_>>().into();
err.span_note(
multispan,
"this pattern had a recovered parse error which likely lost \
the expected fields",
);
err.downgrade_to_delayed_bug();
}
let ty = self.r.tcx.item_name(*def_id);
for (span, _) in spans {
err.span_label(
*span,
format!(
"this pattern doesn't include `{field}`, which is \
available in `{ty}`",
),
);
}
}
}
}
}
}
}

fn suggest_at_operator_in_slice_pat_with_range(
&mut self,
err: &mut Diag<'_>,
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
&& let [namespace, attribute, ..] = &*path.segments
&& namespace.ident.name == sym::diagnostic
&& !(attribute.ident.name == sym::on_unimplemented
|| (attribute.ident.name == sym::do_not_recommend
&& self.tcx.features().do_not_recommend()))
|| attribute.ident.name == sym::do_not_recommend)
{
let distance =
edit_distance(attribute.ident.name.as_str(), sym::on_unimplemented.as_str(), 5);
Expand Down
Loading
Loading