Skip to content

Commit a0326ca

Browse files
committed
Auto merge of #164782 - JonathanBrouwer:rollup-PHRsV73, r=JonathanBrouwer
Rollup of 5 pull requests Successful merges: - #159689 (Account for missing turbofish in resolve errors) - #164317 (Re-export RegionInferenceContext) - #164733 (Include `deprecated` attributes in `rustc_resolve` intra-doc link resolution) - #164754 (Update outdated/incorrect unstable tracking issue links) - #164761 ([tiny] Properly format return type in lifetime error with backticks)
2 parents 0cefa27 + 91fd86e commit a0326ca

54 files changed

Lines changed: 678 additions & 147 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎compiler/rustc_borrowck/src/consumers.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub use super::polonius::legacy::{
1616
PoloniusFacts as PoloniusInput, PoloniusLocationTable, PoloniusOutput, PoloniusRegionVid,
1717
RichLocation, RustcFacts,
1818
};
19-
use super::region_infer::RegionInferenceContext;
19+
pub use super::region_infer::RegionInferenceContext;
2020
use crate::BorrowCheckRootCtxt;
2121

2222
/// Struct used during mir borrowck to collect bodies with facts for a typeck root and all

‎compiler/rustc_borrowck/src/diagnostics/region_name.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl RegionName {
170170
RegionNameHighlight::CannotMatchHirTy(span, type_name),
171171
mir_description,
172172
) => {
173-
diag.span_label(*span, format!("return type{mir_description} is {type_name}"));
173+
diag.span_label(*span, format!("return type{mir_description} is `{type_name}`"));
174174
}
175175
RegionNameSource::AnonRegionFromYieldTy(span, type_name) => {
176176
diag.span_label(*span, format!("yield type is {type_name}"));

‎compiler/rustc_borrowck/src/region_infer/mod.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::fmt;
22

3-
pub(crate) use region_context::*;
3+
// To be reexported in `super::consumers`
4+
pub use region_context::RegionInferenceContext;
45
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
56
use rustc_data_structures::graph::scc::Sccs;
67
use rustc_hir::def_id::CRATE_DEF_ID;
@@ -261,7 +262,7 @@ fn sccs_info<'tcx>(infcx: &BorrowckInferCtxt<'tcx>, sccs: &ConstraintSccs) {
261262

262263
#[derive(Clone, Debug)]
263264
pub(crate) struct BestBlame<'tcx> {
264-
/// See docs on [`RegionInferenceContextInner::best_blame_constraint`] for what this is.
265+
/// See docs on [`region_context::RegionInferenceContextInner::best_blame_constraint`] for what this is.
265266
path: Vec<OutlivesConstraint<'tcx>>,
266267
/// Index into `path` of the constraint most relevant to report to users.
267268
idx: usize,

‎compiler/rustc_builtin_macros/src/deriving/generic/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ impl<'a> TraitDef<'a> {
713713
if self.is_const && cx.ecfg.features.staged_api() {
714714
let rustc_const_unstable = cx.path_name(self.span, sym::rustc_const_unstable);
715715

716-
// #[rustc_const_unstable(feature = "derive_const", issue = "118304")]
716+
// #[rustc_const_unstable(feature = "derive_const", issue = "143874")]
717717
attrs.push(
718718
cx.attr_nested(
719719
rustc_ast::AttrItem {

‎compiler/rustc_feature/src/unstable.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ declare_features! (
270270
(internal, profiler_runtime, "1.18.0", None),
271271
/// Allows using `rustc_*` attributes (RFC 572).
272272
(internal, rustc_attrs, "1.0.0", None),
273+
/// Allows using internal rustdoc features like `doc(keyword)`.
274+
(internal, rustdoc_internals, "1.58.0", None),
273275
/// Allows using the `#[stable]` and `#[unstable]` attributes.
274276
(internal, staged_api, "1.0.0", None),
275277
/// Perma-unstable, only used in the test suite for binders (`for<'a>`).
@@ -322,8 +324,6 @@ declare_features! (
322324
(internal, repr_simd, "1.4.0", Some(27731)),
323325
/// Allows using compiler's own crates.
324326
(unstable, rustc_private, "1.0.0", Some(27812)),
325-
/// Allows using internal rustdoc features like `doc(keyword)`.
326-
(internal, rustdoc_internals, "1.58.0", Some(90418)),
327327
/// Allows using the `rustdoc::missing_doc_code_examples` lint
328328
(unstable, rustdoc_missing_doc_code_examples, "1.31.0", Some(101730)),
329329
/// Introduces a hierarchy of `Sized` traits (RFC 3729).
@@ -666,7 +666,7 @@ declare_features! (
666666
/// Allows providing names to parameters of `impl Fn` etc
667667
(unstable, named_fn_trait_parameters, "1.99.0", Some(158499)),
668668
/// Allows specifying the as-needed link modifier
669-
(unstable, native_link_modifiers_as_needed, "1.53.0", Some(81490)),
669+
(unstable, native_link_modifiers_as_needed, "1.53.0", Some(99424)),
670670
/// Allow negative trait implementations.
671671
(unstable, negative_impls, "1.44.0", Some(68318)),
672672
/// Allows the `!` pattern.
@@ -725,7 +725,7 @@ declare_features! (
725725
/// Allows the use of the `sanitize` attribute.
726726
(unstable, sanitize, "1.91.0", Some(39699)),
727727
/// Allows the use of SIMD types in functions declared in `extern` blocks.
728-
(unstable, simd_ffi, "1.0.0", Some(27731)),
728+
(unstable, simd_ffi, "1.0.0", Some(63068)),
729729
/// Target features on sparc.
730730
(unstable, sparc_target_feature, "1.84.0", Some(132783)),
731731
/// Allows specialization of implementations (RFC 1210).

‎compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
924924

925925
let mut err = fn_call_diag_ctxt.initial_final_diagnostic();
926926
fn_call_diag_ctxt.suggest_confusable(&mut err);
927+
fn_call_diag_ctxt.detect_missing_turbofish(&mut err);
927928

928929
// As we encounter issues, keep track of what we want to provide for the suggestion.
929930

@@ -3227,6 +3228,45 @@ impl<'a, 'tcx> ArgMatchingCtxt<'a, 'tcx> {
32273228
self.annotate_alternative_method_deref(err, self.call_expr, None);
32283229
}
32293230

3231+
fn detect_missing_turbofish(&self, err: &mut Diag<'_>) {
3232+
if self.tcx.dcx().has_errors().is_none() {
3233+
return;
3234+
}
3235+
let mut iter = self.provided_args.iter().peekable();
3236+
while let Some(arg) = iter.next() {
3237+
let hir::ExprKind::Binary(lt, lt_left, lt_right) = arg.kind else {
3238+
continue;
3239+
};
3240+
let hir::BinOpKind::Lt = lt.node else { continue };
3241+
let hir::ExprKind::Path(_) = lt_left.kind else { continue };
3242+
let hir::ExprKind::Path(_) = lt_right.kind else { continue };
3243+
3244+
let Some(mut next) = iter.next() else { break };
3245+
loop {
3246+
match next.kind {
3247+
hir::ExprKind::Binary(gt, gt_left, gt_right)
3248+
if let hir::BinOpKind::Gt = gt.node
3249+
&& let hir::ExprKind::Path(_) = gt_left.kind
3250+
&& let hir::ExprKind::Call(..) = gt_right.kind =>
3251+
{
3252+
// We've encountered a likely missing turbofish error, for which we've already
3253+
// emitted a more targeted diagnostic during name resolution making this one
3254+
// redundant (`LateResolutionVisitor::detect_missing_turbofish`).
3255+
err.downgrade_to_delayed_bug();
3256+
}
3257+
hir::ExprKind::Path(_) => {
3258+
if let Some(n) = iter.next() {
3259+
next = n;
3260+
continue;
3261+
}
3262+
}
3263+
_ => {}
3264+
}
3265+
break;
3266+
}
3267+
}
3268+
}
3269+
32303270
/// A "softer" version of the `demand_compatible`, which checks types without persisting them,
32313271
/// and treats error types differently
32323272
/// This will allow us to "probe" for other argument orders that would likely have been correct

‎compiler/rustc_resolve/src/late.rs‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,9 +2964,14 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
29642964
let mut mod_inner_attrs_start = None;
29652965
match item.kind {
29662966
ItemKind::Mod(..) => {
2967-
// We only handle outer doc comments for modules here.
2967+
// We only handle outer attributes which can contain intra-doc links (doc comments
2968+
// and `deprecated`) for modules here.
29682969
let attrs = if let Some(pos) = item.attrs.iter().position(|a| {
29692970
a.doc_resolution_scope().is_some_and(|style| style == AttrStyle::Inner)
2971+
|| matches!(
2972+
a.kind,
2973+
AttrKind::Normal(ref n)
2974+
if n.item.name() == Some(sym::deprecated) && a.style == AttrStyle::Inner)
29702975
}) {
29712976
mod_inner_attrs_start = Some(pos);
29722977
&item.attrs[..pos]
@@ -5166,6 +5171,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
51665171
}
51675172

51685173
/// Handles paths that may refer to associated items.
5174+
#[tracing::instrument(skip(self, source), level = "debug")]
51695175
fn resolve_qpath(
51705176
&mut self,
51715177
qself: &Option<Box<QSelf>>,
@@ -5174,11 +5180,6 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
51745180
finalize: Finalize,
51755181
source: PathSource<'_, 'ast, 'ra>,
51765182
) -> Result<Option<PartialRes>, Spanned<ResolutionError<'ra>>> {
5177-
debug!(
5178-
"resolve_qpath(qself={:?}, path={:?}, ns={:?}, finalize={:?})",
5179-
qself, path, ns, finalize,
5180-
);
5181-
51825183
if let Some(qself) = qself {
51835184
if qself.position == 0 {
51845185
// This is a case like `<T>::B`, where there is no
@@ -5578,6 +5579,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
55785579
self.resolve_expr(arg, None);
55795580
}
55805581
self.visit_path_segment(seg);
5582+
self.detect_missing_turbofish(&args);
55815583
}
55825584

55835585
ExprKind::Call(ref callee, ref arguments) => {
@@ -5599,6 +5601,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
55995601
self.resolve_expr(argument, None);
56005602
}
56015603
}
5604+
self.detect_missing_turbofish(&arguments);
56025605
}
56035606
ExprKind::FormatArgs(ref args) => {
56045607
for arg in args.arguments.all_args() {

‎compiler/rustc_resolve/src/late/diagnostics.rs‎

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,170 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
17681768
}
17691769
}
17701770

1771+
/// When encountering `Ty < Ty, Ty > call()` in function and method call arguments, suggest
1772+
/// using the turbofish and silence redundant resolve errors.
1773+
pub(in crate::late) fn detect_missing_turbofish(&mut self, arguments: &'ast [Box<Expr>]) {
1774+
if self.use_injections.is_empty() {
1775+
// Avoid doing unnecessary work, we would have had resolve errors by now if this mistake
1776+
// had happened.
1777+
return;
1778+
}
1779+
let mut iter = arguments.iter().peekable();
1780+
// Look through every call argument expression, when encountering `a < b`, try to find a
1781+
// closing `c > ::d()` that would make the whole thing be syntactically valid as a
1782+
// fully-qualified path `a::<b, c>::d()`.
1783+
while let Some(arg) = iter.next() {
1784+
// foo(left < right, bar, baz>::qux())
1785+
// ^^^^ ^^^^^
1786+
let ExprKind::Binary(lt, left, right) = &arg.kind else { continue };
1787+
// foo(left < right, bar, baz>::qux())
1788+
// ^
1789+
let ast::BinOpKind::Lt = lt.node else {
1790+
continue;
1791+
};
1792+
// foo(left < right, bar, baz>::qux())
1793+
// ^^^^ is a path
1794+
let ExprKind::Path(_, lt_left) = &left.kind else { continue };
1795+
// foo(a::B < right, bar, baz>::qux())
1796+
// ^ ^ lt_left_segments
1797+
let lt_left_segments: Vec<_> = lt_left.segments.iter().map(|seg| seg.into()).collect();
1798+
// `a::B` is a type-like.
1799+
let lt_res = if let PathResult::NonModule(res) =
1800+
self.resolve_path(&lt_left_segments, Some(TypeNS), None, PathSource::Expr(None))
1801+
&& let Some(lt_res) = res.full_res()
1802+
{
1803+
lt_res
1804+
} else {
1805+
continue;
1806+
};
1807+
1808+
// Same thing we do for `left`, for `right`:
1809+
// foo(left < right, bar, baz>::qux())
1810+
// ^^^^^ is a path
1811+
let ExprKind::Path(_, lt_right) = &right.kind else { continue };
1812+
let lt_right_segments: Vec<_> =
1813+
lt_right.segments.iter().map(|seg| seg.into()).collect();
1814+
if let PathResult::NonModule(res) =
1815+
self.resolve_path(&lt_right_segments, Some(TypeNS), None, PathSource::Expr(None))
1816+
&& let Some(_res) = res.full_res()
1817+
{
1818+
} else {
1819+
continue;
1820+
}
1821+
1822+
// foo(left < right, bar, baz>::qux())
1823+
// next is ^^^ or ^^^^^^^^^^^
1824+
let Some(mut next) = iter.next() else {
1825+
break;
1826+
};
1827+
let mut other_path_spans = vec![];
1828+
loop {
1829+
match &next.kind {
1830+
// foo(left < right, bar, baz>::qux())
1831+
// ^^^^^^^^^
1832+
ExprKind::Binary(gt, gt_left, gt_right)
1833+
// foo(left < right, bar, baz>::qux())
1834+
// ^
1835+
if let ast::BinOpKind::Gt = gt.node
1836+
// foo(left < right, bar, baz>::qux())
1837+
// ^^^
1838+
&& let ExprKind::Path(_, gt_left) = &gt_left.kind
1839+
// foo(left < right, bar, baz>::qux())
1840+
// ^^^^^^^
1841+
&& let ExprKind::Call(call_expr, _) = &gt_right.kind
1842+
&& let ExprKind::Path(_, call_path) = &call_expr.kind
1843+
&& let gt_left_segments = gt_left
1844+
.segments
1845+
.iter()
1846+
.map(|seg| seg.into())
1847+
.collect::<Vec<_>>()
1848+
&& let PathResult::NonModule(res) = self.resolve_path(
1849+
&gt_left_segments,
1850+
Some(TypeNS),
1851+
None,
1852+
PathSource::Expr(None),
1853+
)
1854+
&& let Some(_res) = res.full_res() =>
1855+
{
1856+
// We've encountered an expression where we have `Ty < Ty, Ty > call(...)`.
1857+
// A binop between two types is non-sensical in (current?) Rust, and the
1858+
// presence of two binops separated by a comma of less-than followed by
1859+
// greater-than heavily implies a missing turbofish in an expression.
1860+
let mut any = false;
1861+
let spans: Vec<Span> = lt_left_segments
1862+
.iter()
1863+
.map(|s| s.ident.span)
1864+
.chain(lt_right_segments.iter().map(|s| s.ident.span))
1865+
.chain(gt_left_segments.iter().map(|s| s.ident.span))
1866+
.chain(gt_left_segments.iter().map(|s| s.ident.span))
1867+
.chain(call_path.segments.iter().map(|seg| seg.span()))
1868+
.chain(other_path_spans.iter().cloned())
1869+
.collect();
1870+
for injection in self.use_injections.iter_mut() {
1871+
// Silence all already constructed resolution errors that are contained
1872+
// by the likely missing turbofish.
1873+
if injection.path.iter().any(|s| spans.contains(&s.ident.span)) {
1874+
any = true;
1875+
injection.err.downgrade_to_delayed_bug();
1876+
}
1877+
}
1878+
if any {
1879+
let sp = MultiSpan::from(vec![lt.span, gt.span]);
1880+
let mut err =
1881+
self.r.tcx.dcx().struct_span_err(sp, "can't compare two types");
1882+
err.span_label(
1883+
gt.span,
1884+
"these are parsed as \"less than\" and \"greater than\"",
1885+
);
1886+
let name = if let Some(def_id) = lt_res.opt_def_id()
1887+
&& let Some(name) = self.r.tcx.opt_item_name(def_id)
1888+
{
1889+
name.to_string()
1890+
} else {
1891+
lt_right_segments
1892+
.iter()
1893+
.map(|s| s.ident.name.to_string())
1894+
.collect::<Vec<String>>()
1895+
.join("::")
1896+
};
1897+
err.span_suggestion_verbose(
1898+
lt.span.shrink_to_lo(),
1899+
format!(
1900+
"you likely intended to write type `{name}` with type parameters, but \
1901+
type parameters in expression contexts require the use of the \
1902+
\"turbofish\" `::<>`",
1903+
),
1904+
"::".to_string(),
1905+
Applicability::MachineApplicable,
1906+
);
1907+
err.emit();
1908+
}
1909+
}
1910+
1911+
// foo(left < right, bat, bar, baz>::qux())
1912+
// ^^^
1913+
ExprKind::Path(_, path) => {
1914+
// foo(left < right, bat, bar, baz>::qux())
1915+
// ^^^ or ^^^^^^^^^^^
1916+
if let Some(n) = iter.next() {
1917+
next = n;
1918+
other_path_spans.extend(path.segments.iter().map(|seg| seg.ident.span));
1919+
// Only case where we don't break from the `loop` advancing the parsed
1920+
// call arguments , we've encountered a path that is likely one of the
1921+
// type parameters for the missing turbofish.
1922+
continue;
1923+
}
1924+
}
1925+
1926+
_ => {}
1927+
}
1928+
// This doesn't look like a turbofish, look for more missing turbofishes on the
1929+
// following arguments.
1930+
break;
1931+
}
1932+
}
1933+
}
1934+
17711935
fn suggest_at_operator_in_slice_pat_with_range(&self, err: &mut Diag<'_>, path: &[Segment]) {
17721936
let Some(pat) = self.diag_metadata.current_pat else { return };
17731937
let (bound, side, range) = match &pat.kind {

‎compiler/rustc_span/src/symbol.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ symbols! {
839839
deref_target,
840840
derive,
841841
derive_const,
842-
derive_const_issue: "118304",
842+
derive_const_issue: "143874",
843843
derive_default_enum,
844844
derive_from,
845845
derive_smart_pointer,

‎library/alloc/src/collections/vec_deque/iter.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<'a, T> Iter<'a, T> {
4949
///
5050
/// assert_eq!(iter.as_slices(), (&[9, 10][..], &[0, 1][..]));
5151
/// ```
52-
#[unstable(feature = "vec_deque_iter_as_slices", issue = "123947")]
52+
#[unstable(feature = "vec_deque_iter_as_slices", issue = "133253")]
5353
pub fn as_slices(&self) -> (&'a [T], &'a [T]) {
5454
(self.i1.as_slice(), self.i2.as_slice())
5555
}

0 commit comments

Comments
 (0)