Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 697d953

Browse files
committedAug 25, 2024
Auto merge of #129540 - tgross35:rollup-y6iaujw, r=tgross35
Rollup of 10 pull requests Successful merges: - #128467 (Detect `*` operator on `!Sized` expression) - #128524 (Don't suggest turning crate-level attributes into outer style) - #128735 (Add a special case for `CStr`/`CString` in the `improper_ctypes` lint) - #129429 (Print the generic parameter along with the variance in dumps.) - #129430 (rustdoc: show exact case-sensitive matches first) - #129449 (Put Pin::as_deref_mut in impl Pin<Ptr> / rearrange Pin methods) - #129481 (Update `compiler_builtins` to `0.1.121`) - #129482 (Add myself to the review rotation for libs) - #129492 (Make wasm32 platform support docs easier to read) - #129512 (update the doc comment on lintchecker b/c it parses html now) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f167efa + 11ebb59 commit 697d953

File tree

71 files changed

+687
-303
lines changed

Some content is hidden

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

71 files changed

+687
-303
lines changed
 

‎compiler/rustc_ast/src/ast.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,6 +2902,17 @@ pub struct AttrItem {
29022902
pub tokens: Option<LazyAttrTokenStream>,
29032903
}
29042904

2905+
impl AttrItem {
2906+
pub fn is_valid_for_outer_style(&self) -> bool {
2907+
self.path == sym::cfg_attr
2908+
|| self.path == sym::cfg
2909+
|| self.path == sym::forbid
2910+
|| self.path == sym::warn
2911+
|| self.path == sym::allow
2912+
|| self.path == sym::deny
2913+
}
2914+
}
2915+
29052916
/// `TraitRef`s appear in impls.
29062917
///
29072918
/// Resolution maps each `TraitRef`'s `ref_id` to its defining trait; that's all
Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
1+
use std::fmt::Write;
2+
13
use rustc_hir::def::DefKind;
2-
use rustc_hir::def_id::CRATE_DEF_ID;
3-
use rustc_middle::ty::TyCtxt;
4+
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
5+
use rustc_middle::ty::{GenericArgs, TyCtxt};
46
use rustc_span::symbol::sym;
57

8+
fn format_variances(tcx: TyCtxt<'_>, def_id: LocalDefId) -> String {
9+
let variances = tcx.variances_of(def_id);
10+
let generics = GenericArgs::identity_for_item(tcx, def_id);
11+
// 7 = 2-letter parameter + ": " + 1-letter variance + ", "
12+
let mut ret = String::with_capacity(2 + 7 * variances.len());
13+
ret.push('[');
14+
for (arg, variance) in generics.iter().zip(variances.iter()) {
15+
write!(ret, "{arg}: {variance:?}, ").unwrap();
16+
}
17+
// Remove trailing `, `.
18+
if !variances.is_empty() {
19+
ret.pop();
20+
ret.pop();
21+
}
22+
ret.push(']');
23+
ret
24+
}
25+
626
pub(crate) fn variances(tcx: TyCtxt<'_>) {
727
if tcx.has_attr(CRATE_DEF_ID, sym::rustc_variance_of_opaques) {
828
for id in tcx.hir().items() {
929
let DefKind::OpaqueTy = tcx.def_kind(id.owner_id) else { continue };
1030

11-
let variances = tcx.variances_of(id.owner_id);
12-
1331
tcx.dcx().emit_err(crate::errors::VariancesOf {
1432
span: tcx.def_span(id.owner_id),
15-
variances: format!("{variances:?}"),
33+
variances: format_variances(tcx, id.owner_id.def_id),
1634
});
1735
}
1836
}
@@ -22,11 +40,9 @@ pub(crate) fn variances(tcx: TyCtxt<'_>) {
2240
continue;
2341
}
2442

25-
let variances = tcx.variances_of(id.owner_id);
26-
2743
tcx.dcx().emit_err(crate::errors::VariancesOf {
2844
span: tcx.def_span(id.owner_id),
29-
variances: format!("{variances:?}"),
45+
variances: format_variances(tcx, id.owner_id.def_id),
3046
});
3147
}
3248
}

0 commit comments

Comments
 (0)
Please sign in to comment.