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 6 pull requests #100304

Merged
merged 73 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
a63b5d3
feat: Only flycheck workspace that belongs to saved file
Veykril Jul 18, 2022
25391e6
Only clear diagnostics of workspaces who have been flychecked
Veykril Jul 20, 2022
d73b0d5
Don't filter flychecks by package member status
Veykril Jul 20, 2022
a969481
Add syntax fixup for while loops
palango Jul 26, 2022
c16e4f2
Add syntax fixup for `loop`
palango Jul 27, 2022
d40ab66
fix: remove whitespaces from doctest names
lowr Aug 1, 2022
5edbdd1
Auto merge of #12918 - lowr:fix/doctest-names, r=Veykril
bors Aug 1, 2022
bd7dfac
Fix r-a spelling in some places
Aug 1, 2022
9c96073
Publish extension for 32-bit ARM systems
Aug 1, 2022
caf8a64
Set linker
Aug 1, 2022
64090ee
Fix target check
Aug 1, 2022
b72ff95
Fix linker env var name
lnicola Aug 1, 2022
cfbada4
Upload arm-unknown-linux-gnueabihf build artifact
lnicola Aug 1, 2022
c71f1e7
Don't run on PRs
Aug 1, 2022
8e38833
Auto merge of #12920 - jonas-schievink:arm-release, r=jonas-schievink
bors Aug 1, 2022
c6c0ac2
Auto merge of #12919 - jonas-schievink:speling, r=jonas-schievink
bors Aug 2, 2022
113f1db
Auto merge of #12880 - palango:while-fixup, r=Veykril
bors Aug 2, 2022
405dd77
Support adding variants via structural editing
DorianListens Jul 20, 2022
bea1fec
convert generate_enum_variant to use add_variant
DorianListens Jul 20, 2022
15d8049
Support tuple fields in generate_enum_variant
DorianListens Jul 20, 2022
e4638de
Support record fields in generate_enum_variant
DorianListens Jul 20, 2022
111694d
Be more strict about supported Paths in generate_enum_variant
DorianListens Aug 2, 2022
1980c11
Support PathPat paths in generate_enum_variant
DorianListens Aug 2, 2022
1c03f45
Auto merge of #12837 - DorianListens:dscheidt/generate-enum-data, r=V…
bors Aug 2, 2022
9a447c0
Use the release branch in xtask promote
lnicola Aug 3, 2022
a02b042
Auto merge of #12930 - lnicola:subtree-branch, r=lnicola
bors Aug 3, 2022
c203ac2
Add more constructors for la-arena
oxalica Aug 3, 2022
10f870e
Impl entry-API for la_arena::ArenaMap
oxalica Aug 3, 2022
a8a6c16
Use an empty expander for ignored non-attribute proc-macros
Veykril Aug 3, 2022
2bc9a2d
Auto merge of #12933 - Veykril:proc-ignored, r=Veykril
bors Aug 3, 2022
46d6357
Add a setting to disable comment continuation in VSCode
Veykril Aug 3, 2022
4904b2b
Auto merge of #12934 - Veykril:typing, r=Veykril
bors Aug 3, 2022
49dac40
on hover fallback error, adds ast::type as possible node
jean-santos Aug 3, 2022
df9d3db
Trigger flycheck on all transitive dependencies as well
Veykril Aug 4, 2022
5698e51
tidy formatting
jean-santos Aug 4, 2022
c6a9fbf
Auto merge of #12939 - jean-santos:errors-ide-hover-wrong-place, r=Ve…
bors Aug 4, 2022
df7f755
Don't flycheck while the workspace is being loaded
Veykril Aug 4, 2022
0fe3bcf
Auto merge of #12808 - Veykril:check-workspace, r=Veykril
bors Aug 4, 2022
30c4f9f
Update bug_report.md
Veykril Aug 5, 2022
d94a42d
Update bug_report.md
Veykril Aug 5, 2022
cb52271
Auto merge of #12946 - rust-lang:issue-template, r=lnicola
bors Aug 5, 2022
f6d42aa
remove an unnecessary `str::rfind`
TaKO8Ki Aug 5, 2022
6a17372
Don't switch workspace on vfs file changes from libraries
Veykril Aug 5, 2022
d6e78b0
feat: Handle operators like their trait functions in the IDE
Veykril Aug 5, 2022
352d3c6
Fix visibilities
Veykril Aug 5, 2022
8aa50e0
Simplify
Veykril Aug 5, 2022
2364788
Auto merge of #12948 - Veykril:classify-ops, r=Veykril
bors Aug 5, 2022
6bf674c
fix: Fix incorrect token pick rankings
Veykril Aug 5, 2022
97038e5
Auto merge of #12949 - Veykril:token-pick, r=Veykril
bors Aug 5, 2022
3792720
Auto merge of #12947 - Veykril:switch-workspace, r=Veykril
bors Aug 5, 2022
5170569
Auto merge of #12931 - oxalica:feat/la-arena-apis, r=lnicola
bors Aug 6, 2022
e8a9bc0
run stable fmt through rustup
stanciuadrian Aug 6, 2022
d9e462f
Auto merge of #12953 - stanciuadrian:fmt, r=lnicola
bors Aug 6, 2022
1a94193
Impl more methods and traits for la_arena::ArenaMap
oxalica Aug 6, 2022
326ffee
Returns the old value for la_arena::ArenaMap::insert
oxalica Aug 6, 2022
61c0b12
remove Clean trait implementation for hir::WherePredicate
GuillaumeGomez Aug 6, 2022
a238d12
remove Clean trait implementation for ty::Predicate
GuillaumeGomez Aug 6, 2022
eca6f2e
Fix test_rainbow_highlighting gate
lnicola Aug 7, 2022
6ec9125
Auto merge of #12959 - lnicola:rainbows-again, r=lnicola
bors Aug 7, 2022
634cfe3
Auto merge of #12956 - oxalica:feat/la-arena-apis, r=lnicola
bors Aug 7, 2022
4ee2fe3
Further improve error message for E0081
Bryysen Aug 7, 2022
399796d
Add comments to obscure code, remove unnesecary parameter from closure
Bryysen Aug 7, 2022
bfd7535
Fix wording on comment
Bryysen Aug 7, 2022
b3bc211
add regression test for #79148
TaKO8Ki Aug 8, 2022
74e71da
Fix plural form of `variant` in error message not formatting correctly
Bryysen Aug 8, 2022
63be9a9
Update Duration::as_secs doc to point to as_secs_f64/32 for including…
theli-ua Aug 9, 2022
f1e801b
:arrow_up: rust-analyzer
lnicola Aug 9, 2022
a1829bb
Rollup merge of #100163 - TaKO8Ki:remove-unnecessary-string-search, r…
matthiaskrgr Aug 9, 2022
65cc68b
Rollup merge of #100212 - GuillaumeGomez:rm-clean-impls, r=Dylan-DPC
matthiaskrgr Aug 9, 2022
d63d2bd
Rollup merge of #100238 - Bryysen:master, r=cjgillot
matthiaskrgr Aug 9, 2022
89835a0
Rollup merge of #100268 - TaKO8Ki:add-regression-test-for-79148, r=Ma…
matthiaskrgr Aug 9, 2022
e20fabb
Rollup merge of #100294 - theli-ua:master, r=thomcc
matthiaskrgr Aug 9, 2022
cacd37a
Rollup merge of #100303 - lnicola:rust-analyzer-2022-08-09, r=lnicola
matthiaskrgr Aug 9, 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
158 changes: 95 additions & 63 deletions compiler/rustc_typeck/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _;
use rustc_trait_selection::traits::{self, ObligationCtxt};
use rustc_ty_utils::representability::{self, Representability};

use std::iter;
use std::ops::ControlFlow;

pub(super) fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Abi) {
Expand Down Expand Up @@ -1494,76 +1493,109 @@ fn check_enum<'tcx>(tcx: TyCtxt<'tcx>, vs: &'tcx [hir::Variant<'tcx>], def_id: L
}
}

let mut disr_vals: Vec<Discr<'tcx>> = Vec::with_capacity(vs.len());
// This tracks the previous variant span (in the loop) incase we need it for diagnostics
let mut prev_variant_span: Span = DUMMY_SP;
for ((_, discr), v) in iter::zip(def.discriminants(tcx), vs) {
// Check for duplicate discriminant values
if let Some(i) = disr_vals.iter().position(|&x| x.val == discr.val) {
let variant_did = def.variant(VariantIdx::new(i)).def_id;
let variant_i_hir_id = tcx.hir().local_def_id_to_hir_id(variant_did.expect_local());
let variant_i = tcx.hir().expect_variant(variant_i_hir_id);
let i_span = match variant_i.disr_expr {
Some(ref expr) => tcx.hir().span(expr.hir_id),
None => tcx.def_span(variant_did),
};
let span = match v.disr_expr {
Some(ref expr) => tcx.hir().span(expr.hir_id),
None => v.span,
};
let display_discr = format_discriminant_overflow(tcx, v, discr);
let display_discr_i = format_discriminant_overflow(tcx, variant_i, disr_vals[i]);
let no_disr = v.disr_expr.is_none();
let mut err = struct_span_err!(
tcx.sess,
sp,
E0081,
"discriminant value `{}` assigned more than once",
discr,
);

err.span_label(i_span, format!("first assignment of {display_discr_i}"));
err.span_label(span, format!("second assignment of {display_discr}"));

if no_disr {
err.span_label(
prev_variant_span,
format!(
"assigned discriminant for `{}` was incremented from this discriminant",
v.ident
),
);
}
err.emit();
}

disr_vals.push(discr);
prev_variant_span = v.span;
}
detect_discriminant_duplicate(tcx, def.discriminants(tcx).collect(), vs, sp);

check_representable(tcx, sp, def_id);
check_transparent(tcx, sp, def);
}

/// In the case that a discriminant is both a duplicate and an overflowing literal,
/// we insert both the assigned discriminant and the literal it overflowed from into the formatted
/// output. Otherwise we format the discriminant normally.
fn format_discriminant_overflow<'tcx>(
/// Part of enum check. Given the discriminants of an enum, errors if two or more discriminants are equal
fn detect_discriminant_duplicate<'tcx>(
tcx: TyCtxt<'tcx>,
variant: &hir::Variant<'_>,
dis: Discr<'tcx>,
) -> String {
if let Some(expr) = &variant.disr_expr {
let body = &tcx.hir().body(expr.body).value;
if let hir::ExprKind::Lit(lit) = &body.kind
&& let rustc_ast::LitKind::Int(lit_value, _int_kind) = &lit.node
&& dis.val != *lit_value
{
return format!("`{dis}` (overflowed from `{lit_value}`)");
mut discrs: Vec<(VariantIdx, Discr<'tcx>)>,
vs: &'tcx [hir::Variant<'tcx>],
self_span: Span,
) {
// Helper closure to reduce duplicate code. This gets called everytime we detect a duplicate.
// Here `idx` refers to the order of which the discriminant appears, and its index in `vs`
let report = |dis: Discr<'tcx>,
idx: usize,
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>| {
let var = &vs[idx]; // HIR for the duplicate discriminant
let (span, display_discr) = match var.disr_expr {
Some(ref expr) => {
// In the case the discriminant is both a duplicate and overflowed, let the user know
if let hir::ExprKind::Lit(lit) = &tcx.hir().body(expr.body).value.kind
&& let rustc_ast::LitKind::Int(lit_value, _int_kind) = &lit.node
&& *lit_value != dis.val
{
(tcx.hir().span(expr.hir_id), format!("`{dis}` (overflowed from `{lit_value}`)"))
// Otherwise, format the value as-is
} else {
(tcx.hir().span(expr.hir_id), format!("`{dis}`"))
}
}
None => {
// At this point we know this discriminant is a duplicate, and was not explicitly
// assigned by the user. Here we iterate backwards to fetch the HIR for the last
// explictly assigned discriminant, and letting the user know that this was the
// increment startpoint, and how many steps from there leading to the duplicate
if let Some((n, hir::Variant { span, ident, .. })) =
vs[..idx].iter().rev().enumerate().find(|v| v.1.disr_expr.is_some())
{
let ve_ident = var.ident;
let n = n + 1;
let sp = if n > 1 { "variants" } else { "variant" };

err.span_label(
*span,
format!("discriminant for `{ve_ident}` incremented from this startpoint (`{ident}` + {n} {sp} later => `{ve_ident}` = {dis})"),
);
}

(vs[idx].span, format!("`{dis}`"))
}
};

err.span_label(span, format!("{display_discr} assigned here"));
};

// Here we loop through the discriminants, comparing each discriminant to another.
// When a duplicate is detected, we instatiate an error and point to both
// initial and duplicate value. The duplicate discriminant is then discarded by swapping
// it with the last element and decrementing the `vec.len` (which is why we have to evaluate
// `discrs.len()` anew every iteration, and why this could be tricky to do in a functional
// style as we are mutating `discrs` on the fly).
let mut i = 0;
while i < discrs.len() {
let hir_var_i_idx = discrs[i].0.index();
let mut error: Option<DiagnosticBuilder<'_, _>> = None;

let mut o = i + 1;
while o < discrs.len() {
let hir_var_o_idx = discrs[o].0.index();

if discrs[i].1.val == discrs[o].1.val {
let err = error.get_or_insert_with(|| {
let mut ret = struct_span_err!(
tcx.sess,
self_span,
E0081,
"discriminant value `{}` assigned more than once",
discrs[i].1,
);

report(discrs[i].1, hir_var_i_idx, &mut ret);

ret
});

report(discrs[o].1, hir_var_o_idx, err);

// Safe to unwrap here, as we wouldn't reach this point if `discrs` was empty
discrs[o] = *discrs.last().unwrap();
discrs.pop();
} else {
o += 1;
}
}
}

format!("`{dis}`")
if let Some(mut e) = error {
e.emit();
}

i += 1;
}
}

pub(super) fn check_type_params_are_used<'tcx>(
Expand Down
53 changes: 22 additions & 31 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ use rustc_span::hygiene::DesugaringKind;
use rustc_span::lev_distance::find_best_match_for_name;
use rustc_span::source_map::{Span, Spanned};
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{BytePos, Pos};
use rustc_target::spec::abi::Abi::RustIntrinsic;
use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::traits::{self, ObligationCauseCode};
Expand Down Expand Up @@ -2398,37 +2397,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr,
Some(span),
);
} else if let ty::RawPtr(ty_and_mut) = expr_t.kind()
&& let ty::Adt(adt_def, _) = ty_and_mut.ty.kind()
&& let ExprKind::Field(base_expr, _) = expr.kind
&& adt_def.variants().len() == 1
&& adt_def
.variants()
.iter()
.next()
.unwrap()
.fields
.iter()
.any(|f| f.ident(self.tcx) == field)
{
err.multipart_suggestion(
"to access the field, dereference first",
vec![
(base_expr.span.shrink_to_lo(), "(*".to_string()),
(base_expr.span.shrink_to_hi(), ")".to_string()),
],
Applicability::MaybeIncorrect,
);
} else {
let mut found = false;

if let ty::RawPtr(ty_and_mut) = expr_t.kind()
&& let ty::Adt(adt_def, _) = ty_and_mut.ty.kind()
{
if adt_def.variants().len() == 1
&& adt_def
.variants()
.iter()
.next()
.unwrap()
.fields
.iter()
.any(|f| f.ident(self.tcx) == field)
{
if let Some(dot_loc) = expr_snippet.rfind('.') {
found = true;
err.span_suggestion(
expr.span.with_hi(expr.span.lo() + BytePos::from_usize(dot_loc)),
"to access the field, dereference first",
format!("(*{})", &expr_snippet[0..dot_loc]),
Applicability::MaybeIncorrect,
);
}
}
}

if !found {
err.help("methods are immutable and cannot be assigned to");
}
err.help("methods are immutable and cannot be assigned to");
}

err.emit();
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_typeck/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::Visitor;
use rustc_hir::{HirIdMap, ImplicitSelfKind, Node};
use rustc_index::bit_set::BitSet;
use rustc_index::vec::Idx;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
Expand Down
16 changes: 4 additions & 12 deletions library/core/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,19 +318,11 @@ impl Duration {
/// assert_eq!(duration.as_secs(), 5);
/// ```
///
/// To determine the total number of seconds represented by the `Duration`,
/// use `as_secs` in combination with [`subsec_nanos`]:
///
/// ```
/// use std::time::Duration;
///
/// let duration = Duration::new(5, 730023852);
///
/// assert_eq!(5.730023852,
/// duration.as_secs() as f64
/// + duration.subsec_nanos() as f64 * 1e-9);
/// ```
/// To determine the total number of seconds represented by the `Duration`
/// including the fractional part, use [`as_secs_f64`] or [`as_secs_f32`]
///
/// [`as_secs_f32`]: Duration::as_secs_f64
/// [`as_secs_f64`]: Duration::as_secs_f32
/// [`subsec_nanos`]: Duration::subsec_nanos
#[stable(feature = "duration", since = "1.3.0")]
#[rustc_const_stable(feature = "duration_consts", since = "1.32.0")]
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ where
let mut ty_to_fn: FxHashMap<Type, (Option<PolyTrait>, Option<Type>)> = Default::default();

for p in clean_where_predicates {
let (orig_p, p) = (p, p.clean(self.cx));
let (orig_p, p) = (p, clean_predicate(p, self.cx));
if p.is_none() {
continue;
}
Expand Down
Loading