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 12 pull requests #101073

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e540425
Add a `File::create_new` constructor
joshtriplett Jul 2, 2022
152c851
Make forward compatibility lint deprecated_cfg_attr_crate_type_name d…
est31 Jul 26, 2022
8998024
Correct test-args to compiletest on Windows
czzrr Aug 19, 2022
e91cd39
session: diagnostic migration lint on more fns
davidtwco Aug 19, 2022
e6a3632
errors: `IntoDiagnosticArg` for `io::Error`/paths
davidtwco Aug 19, 2022
3becaaf
incremental: migrate diagnostics
davidtwco Aug 19, 2022
6a1f7af
Use direct pointer to filter_dirs function
est31 Aug 23, 2022
0a6af98
Simplify unicode_downloads.rs
est31 Aug 23, 2022
754b3e7
Change hint to correct path
est31 Aug 23, 2022
a788650
Remove some documentation duplicated between `writeln!` and `write!`
joshtriplett Aug 24, 2022
3c8618f
Update `write!` docs: can now import traits as `_` to avoid conflicts
joshtriplett Aug 24, 2022
589db1f
Expand example to show how to implement qualified trait names
joshtriplett Aug 24, 2022
cb843a0
Code deduplication in tool_only_multipart_suggestion
Xiretza Aug 22, 2022
ae937cc
Clarify comment to fit `as _` better
joshtriplett Aug 24, 2022
ad93272
Stabilize `const_ptr_offset_from`.
fee1-dead Apr 20, 2022
69ad634
Do not include `const_ptr_sub_ptr` in this stabilization
fee1-dead May 12, 2022
7529029
Provide structured suggestion for `hashmap[idx] = val`
estebank Aug 25, 2022
e7b7f88
rustdoc: omit start/end tags for empty item description blocks
notriddle Aug 26, 2022
4c27952
Use span_suggestion_with_style in SessionSubdiagnostic derive
Xiretza Aug 22, 2022
a134cd4
SessionSubdiagnostic: make `#[applicability]` optional
Xiretza Aug 26, 2022
181ce39
Unify indentation in subdiagnostic-derive test
Xiretza Aug 26, 2022
8bb4b5f
Support parsing IP addresses from a byte string
marmeladema Mar 12, 2022
016e874
Add `IsTerminal` trait to determine if a descriptor or handle is a te…
joshtriplett Jun 12, 2022
489b73b
Make is_terminal fail fast if a process has no console at all
joshtriplett Jun 20, 2022
d2cceb7
Rewrite FILE_NAME_INFO handling to avoid enlarging slice reference
joshtriplett Aug 24, 2022
72541dd
Rework SessionSubdiagnostic derive to support multipart_suggestion
Xiretza Aug 23, 2022
4854239
Rollup merge of #94890 - marmeladema:ip-addr-try-from-bytes, r=joshtr…
compiler-errors Aug 27, 2022
de6ab5a
Rollup merge of #96240 - fee1-dead-contrib:stabilize_const_offset_fro…
compiler-errors Aug 27, 2022
33b8db1
Rollup merge of #98033 - joshtriplett:is-terminal-fd-handle, r=thomcc
compiler-errors Aug 27, 2022
9a0172c
Rollup merge of #98801 - joshtriplett:file-create-new, r=thomcc
compiler-errors Aug 27, 2022
2910abe
Rollup merge of #99784 - est31:deny_cfg_attr_crate_type_name, r=Mark-…
compiler-errors Aug 27, 2022
bbed968
Rollup merge of #100754 - davidtwco:translation-incremental, r=compil…
compiler-errors Aug 27, 2022
d9dd336
Rollup merge of #100811 - czzrr:master, r=Mark-Simulacrum
compiler-errors Aug 27, 2022
00f0ba0
Rollup merge of #100924 - est31:closure_to_fn_ptr, r=Mark-Simulacrum
compiler-errors Aug 27, 2022
2fd242c
Rollup merge of #100953 - joshtriplett:write-docs, r=Mark-Simulacrum
compiler-errors Aug 27, 2022
2f50d33
Rollup merge of #100970 - Xiretza:derive-multipart-suggestion, r=davi…
compiler-errors Aug 27, 2022
5cc0d3a
Rollup merge of #101002 - estebank:hashmap-idx, r=davidtwco
compiler-errors Aug 27, 2022
8468c71
Rollup merge of #101018 - notriddle:notriddle/item-right-docblock-sho…
compiler-errors Aug 27, 2022
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
116 changes: 113 additions & 3 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed};
use rustc_errors::{
Applicability, Diagnostic, DiagnosticBuilder, EmissionGuarantee, ErrorGuaranteed,
};
use rustc_hir as hir;
use rustc_hir::intravisit::Visitor;
use rustc_hir::Node;
use rustc_middle::hir::map::Map;
use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem};
Expand Down Expand Up @@ -614,7 +617,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
"trait `IndexMut` is required to modify indexed content, \
but it is not implemented for `{ty}`",
));
self.suggest_map_index_mut_alternatives(ty, &mut err);
self.suggest_map_index_mut_alternatives(ty, &mut err, span);
}
_ => (),
}
Expand All @@ -632,13 +635,120 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
&self,
ty: Ty<'_>,
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
span: Span,
) {
let Some(adt) = ty.ty_adt_def() else { return };
let did = adt.did();
if self.infcx.tcx.is_diagnostic_item(sym::HashMap, did)
|| self.infcx.tcx.is_diagnostic_item(sym::BTreeMap, did)
{
err.help(format!("to modify a `{ty}`, use `.get_mut()`, `.insert()` or the entry API"));
struct V<'a, 'b, 'tcx, G: EmissionGuarantee> {
assign_span: Span,
err: &'a mut DiagnosticBuilder<'b, G>,
ty: Ty<'tcx>,
suggested: bool,
}
impl<'a, 'b: 'a, 'hir, 'tcx, G: EmissionGuarantee> Visitor<'hir> for V<'a, 'b, 'tcx, G> {
fn visit_stmt(&mut self, stmt: &'hir hir::Stmt<'hir>) {
hir::intravisit::walk_stmt(self, stmt);
let expr = match stmt.kind {
hir::StmtKind::Semi(expr) | hir::StmtKind::Expr(expr) => expr,
hir::StmtKind::Local(hir::Local { init: Some(expr), .. }) => expr,
_ => {
return;
}
};
if let hir::ExprKind::Assign(place, rv, _sp) = expr.kind
&& let hir::ExprKind::Index(val, index) = place.kind
&& (expr.span == self.assign_span || place.span == self.assign_span)
{
// val[index] = rv;
// ---------- place
self.err.multipart_suggestions(
&format!(
"to modify a `{}`, use `.get_mut()`, `.insert()` or the entry API",
self.ty,
),
vec![
vec![ // val.insert(index, rv);
(
val.span.shrink_to_hi().with_hi(index.span.lo()),
".insert(".to_string(),
),
(
index.span.shrink_to_hi().with_hi(rv.span.lo()),
", ".to_string(),
),
(rv.span.shrink_to_hi(), ")".to_string()),
],
vec![ // val.get_mut(index).map(|v| { *v = rv; });
(
val.span.shrink_to_hi().with_hi(index.span.lo()),
".get_mut(".to_string(),
),
(
index.span.shrink_to_hi().with_hi(place.span.hi()),
").map(|val| { *val".to_string(),
),
(
rv.span.shrink_to_hi(),
"; })".to_string(),
),
],
vec![ // let x = val.entry(index).or_insert(rv);
(val.span.shrink_to_lo(), "let val = ".to_string()),
(
val.span.shrink_to_hi().with_hi(index.span.lo()),
".entry(".to_string(),
),
(
index.span.shrink_to_hi().with_hi(rv.span.lo()),
").or_insert(".to_string(),
),
(rv.span.shrink_to_hi(), ")".to_string()),
],
].into_iter(),
Applicability::MachineApplicable,
);
self.suggested = true;
} else if let hir::ExprKind::MethodCall(_path, args @ [_, ..], sp) = expr.kind
&& let hir::ExprKind::Index(val, index) = args[0].kind
&& expr.span == self.assign_span
{
// val[index].path(args..);
self.err.multipart_suggestion(
&format!("to modify a `{}` use `.get_mut()`", self.ty),
vec![
(
val.span.shrink_to_hi().with_hi(index.span.lo()),
".get_mut(".to_string(),
),
(
index.span.shrink_to_hi().with_hi(args[0].span.hi()),
").map(|val| val".to_string(),
),
(sp.shrink_to_hi(), ")".to_string()),
],
Applicability::MachineApplicable,
);
self.suggested = true;
}
}
}
let hir_map = self.infcx.tcx.hir();
let def_id = self.body.source.def_id();
let hir_id = hir_map.local_def_id_to_hir_id(def_id.as_local().unwrap());
let node = hir_map.find(hir_id);
let Some(hir::Node::Item(item)) = node else { return; };
let hir::ItemKind::Fn(.., body_id) = item.kind else { return; };
let body = self.infcx.tcx.hir().body(body_id);
let mut v = V { assign_span: span, err, ty, suggested: false };
v.visit_body(body);
if !v.suggested {
err.help(&format!(
"to modify a `{ty}`, use `.get_mut()`, `.insert()` or the entry API",
));
}
}
}

Expand Down
106 changes: 106 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/incremental.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
incremental_unrecognized_depnode = unrecognized `DepNode` variant: {$name}

incremental_missing_depnode = missing `DepNode` variant

incremental_missing_if_this_changed = no `#[rustc_if_this_changed]` annotation detected

incremental_no_path = no path from `{$source}` to `{$target}`

incremental_ok = OK

incremental_unknown_reuse_kind = unknown cgu-reuse-kind `{$kind}` specified

incremental_missing_query_depgraph = found CGU-reuse attribute but `-Zquery-dep-graph` was not specified

incremental_malformed_cgu_name =
found malformed codegen unit name `{$user_path}`. codegen units names must always start with the name of the crate (`{$crate_name}` in this case).

incremental_no_module_named = no module named `{$user_path}` (mangled: {$cgu_name}). available modules: {$cgu_names}

incremental_field_associated_value_expected = associated value expected for `{$name}`

incremental_no_field = no field `{$name}`

incremental_assertion_auto = `except` specified DepNodes that can not be affected for \"{$name}\": \"{$e}\"

incremental_undefined_clean_dirty_assertions_item = clean/dirty auto-assertions not yet defined for Node::Item.node={$kind}

incremental_undefined_clean_dirty_assertions = clean/dirty auto-assertions not yet defined for {$kind}

incremental_repeated_depnode_label = dep-node label `{$label}` is repeated

incremental_unrecognized_depnode_label = dep-node label `{$label}` not recognized

incremental_not_dirty = `{$dep_node_str}` should be dirty but is not

incremental_not_clean = `{$dep_node_str}` should be clean but is not

incremental_not_loaded = `{$dep_node_str}` should have been loaded from disk but it was not

incremental_unknown_item = unknown item `{$name}`

incremental_no_cfg = no cfg attribute

incremental_associated_value_expected_for = associated value expected for `{$ident}`

incremental_associated_value_expected = expected an associated value

incremental_unchecked_clean = found unchecked `#[rustc_clean]` attribute

incremental_delete_old = unable to delete old {$name} at `{$path}`: {$err}

incremental_create_new = failed to create {$name} at `{$path}`: {$err}

incremental_write_new = failed to write {$name} to `{$path}`: {$err}

incremental_canonicalize_path = incremental compilation: error canonicalizing path `{$path}`: {$err}

incremental_create_incr_comp_dir = could not create incremental compilation {$tag} directory `{$path}`: {$err}

incremental_create_lock = incremental compilation: could not create session directory lock file: {$lock_err}
.lock_unsupported = the filesystem for the incremental path at {$session_dir} does not appear to support locking, consider changing the incremental path to a filesystem that supports locking or disable incremental compilation
.cargo_help_1 = incremental compilation can be disabled by setting the environment variable CARGO_INCREMENTAL=0 (see https://doc.rust-lang.org/cargo/reference/profiles.html#incremental)
.cargo_help_2 = the entire build directory can be changed to a different filesystem by setting the environment variable CARGO_TARGET_DIR to a different path (see https://doc.rust-lang.org/cargo/reference/config.html#buildtarget-dir)

incremental_delete_lock = error deleting lock file for incremental compilation session directory `{$path}`: {$err}

incremental_hard_link_failed =
hard linking files in the incremental compilation cache failed. copying files instead. consider moving the cache directory to a file system which supports hard linking in session dir `{$path}`

incremental_delete_partial = failed to delete partly initialized session dir `{$path}`: {$err}

incremental_delete_full = error deleting incremental compilation session directory `{$path}`: {$err}

incremental_finalize = error finalizing incremental compilation session directory `{$path}`: {$err}

incremental_invalid_gc_failed =
failed to garbage collect invalid incremental compilation session directory `{$path}`: {$err}

incremental_finalized_gc_failed =
failed to garbage collect finalized incremental compilation session directory `{$path}`: {$err}

incremental_session_gc_failed =
failed to garbage collect incremental compilation session directory `{$path}`: {$err}

incremental_assert_not_loaded =
we asserted that the incremental cache should not be loaded, but it was loaded

incremental_assert_loaded =
we asserted that an existing incremental cache directory should be successfully loaded, but it was not

incremental_delete_incompatible =
failed to delete invalidated or incompatible incremental compilation session directory contents `{$path}`: {$err}

incremental_load_dep_graph = could not load dep-graph from `{$path}`: {$err}

incremental_decode_incr_cache = could not decode incremental cache: {$err}

incremental_write_dep_graph = failed to write dependency graph to `{$path}`: {$err}

incremental_move_dep_graph = failed to move dependency graph from `{$from}` to `{$to}`: {$err}

incremental_create_dep_graph = failed to create dependency graph at `{$path}`: {$err}

incremental_copy_workproduct_to_cache = error copying object file `{$from}` to incremental directory as `{$to}`: {$err}

incremental_delete_workproduct = file-system error deleting outdated file `{$path}`: {$err}
1 change: 1 addition & 0 deletions compiler/rustc_error_messages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ fluent_messages! {
const_eval => "../locales/en-US/const_eval.ftl",
driver => "../locales/en-US/driver.ftl",
expand => "../locales/en-US/expand.ftl",
incremental => "../locales/en-US/incremental.ftl",
interface => "../locales/en-US/interface.ftl",
lint => "../locales/en-US/lint.ftl",
parser => "../locales/en-US/parser.ftl",
Expand Down
17 changes: 5 additions & 12 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,19 +686,12 @@ impl Diagnostic {
suggestion: Vec<(Span, String)>,
applicability: Applicability,
) -> &mut Self {
assert!(!suggestion.is_empty());
self.push_suggestion(CodeSuggestion {
substitutions: vec![Substitution {
parts: suggestion
.into_iter()
.map(|(span, snippet)| SubstitutionPart { snippet, span })
.collect(),
}],
msg: self.subdiagnostic_message_to_diagnostic_message(msg),
style: SuggestionStyle::CompletelyHidden,
self.multipart_suggestion_with_style(
msg,
suggestion,
applicability,
});
self
SuggestionStyle::CompletelyHidden,
)
}

/// Prints out a message with a suggested edit of the code.
Expand Down
40 changes: 17 additions & 23 deletions compiler/rustc_incremental/src/assert_dep_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
//! fn baz() { foo(); }
//! ```

use crate::errors;
use rustc_ast as ast;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::graph::implementation::{Direction, NodeIndex, INCOMING, OUTGOING};
Expand Down Expand Up @@ -133,12 +134,10 @@ impl<'tcx> IfThisChanged<'tcx> {
Some(n) => {
match DepNode::from_label_string(self.tcx, n.as_str(), def_path_hash) {
Ok(n) => n,
Err(()) => {
self.tcx.sess.span_fatal(
attr.span,
&format!("unrecognized DepNode variant {:?}", n),
);
}
Err(()) => self.tcx.sess.emit_fatal(errors::UnrecognizedDepNode {
span: attr.span,
name: n,
}),
}
}
};
Expand All @@ -149,16 +148,14 @@ impl<'tcx> IfThisChanged<'tcx> {
Some(n) => {
match DepNode::from_label_string(self.tcx, n.as_str(), def_path_hash) {
Ok(n) => n,
Err(()) => {
self.tcx.sess.span_fatal(
attr.span,
&format!("unrecognized DepNode variant {:?}", n),
);
}
Err(()) => self.tcx.sess.emit_fatal(errors::UnrecognizedDepNode {
span: attr.span,
name: n,
}),
}
}
None => {
self.tcx.sess.span_fatal(attr.span, "missing DepNode variant");
self.tcx.sess.emit_fatal(errors::MissingDepNode { span: attr.span });
}
};
self.then_this_would_need.push((
Expand Down Expand Up @@ -204,7 +201,7 @@ fn check_paths<'tcx>(tcx: TyCtxt<'tcx>, if_this_changed: &Sources, then_this_wou
// Return early here so as not to construct the query, which is not cheap.
if if_this_changed.is_empty() {
for &(target_span, _, _, _) in then_this_would_need {
tcx.sess.span_err(target_span, "no `#[rustc_if_this_changed]` annotation detected");
tcx.sess.emit_err(errors::MissingIfThisChanged { span: target_span });
}
return;
}
Expand All @@ -213,16 +210,13 @@ fn check_paths<'tcx>(tcx: TyCtxt<'tcx>, if_this_changed: &Sources, then_this_wou
let dependents = query.transitive_predecessors(source_dep_node);
for &(target_span, ref target_pass, _, ref target_dep_node) in then_this_would_need {
if !dependents.contains(&target_dep_node) {
tcx.sess.span_err(
target_span,
&format!(
"no path from `{}` to `{}`",
tcx.def_path_str(source_def_id),
target_pass
),
);
tcx.sess.emit_err(errors::NoPath {
span: target_span,
source: tcx.def_path_str(source_def_id),
target: *target_pass,
});
} else {
tcx.sess.span_err(target_span, "OK");
tcx.sess.emit_err(errors::Ok { span: target_span });
}
}
}
Expand Down
Loading