-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add lint for intra link resolution failure #51382
Changes from 7 commits
b000cf0
8c43c93
2e343f3
6d5e6b4
e6c7868
d2a4e42
231c61a
6a03884
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1665,3 +1665,36 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints { | |
} | ||
} | ||
} | ||
|
||
/// Does nothing as a lint pass, but registers some `Lint`s | ||
/// which are used by other parts of the compiler. | ||
#[derive(Copy, Clone)] | ||
pub struct SoftLints; | ||
|
||
impl LintPass for SoftLints { | ||
fn get_lints(&self) -> LintArray { | ||
lint_array!( | ||
WHILE_TRUE, | ||
BOX_POINTERS, | ||
NON_SHORTHAND_FIELD_PATTERNS, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where did this list of lints come from? I see a similar list in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From this file. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha, now i see it. Thanks for pointing that out. |
||
UNSAFE_CODE, | ||
MISSING_DOCS, | ||
MISSING_COPY_IMPLEMENTATIONS, | ||
MISSING_DEBUG_IMPLEMENTATIONS, | ||
ANONYMOUS_PARAMETERS, | ||
UNUSED_DOC_COMMENTS, | ||
UNCONDITIONAL_RECURSION, | ||
PLUGIN_AS_LIBRARY, | ||
PRIVATE_NO_MANGLE_FNS, | ||
PRIVATE_NO_MANGLE_STATICS, | ||
NO_MANGLE_CONST_ITEMS, | ||
NO_MANGLE_GENERIC_ITEMS, | ||
MUTABLE_TRANSMUTES, | ||
UNSTABLE_FEATURES, | ||
UNIONS_WITH_DROP_FIELDS, | ||
UNREACHABLE_PUB, | ||
TYPE_ALIAS_BOUNDS, | ||
TRIVIAL_BOUNDS, | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ pub use self::Visibility::{Public, Inherited}; | |
|
||
use syntax; | ||
use rustc_target::spec::abi::Abi; | ||
use syntax::ast::{self, AttrStyle, Ident}; | ||
use syntax::ast::{self, AttrStyle, NodeId, Ident}; | ||
use syntax::attr; | ||
use syntax::codemap::{dummy_spanned, Spanned}; | ||
use syntax::feature_gate::UnstableFeatures; | ||
|
@@ -46,9 +46,10 @@ use rustc::middle::stability; | |
use rustc::util::nodemap::{FxHashMap, FxHashSet}; | ||
use rustc_typeck::hir_ty_to_ty; | ||
use rustc::infer::region_constraints::{RegionConstraintData, Constraint}; | ||
use rustc::lint as lint; | ||
|
||
use std::collections::hash_map::Entry; | ||
use std::fmt; | ||
|
||
use std::default::Default; | ||
use std::{mem, slice, vec}; | ||
use std::iter::{FromIterator, once}; | ||
|
@@ -1283,10 +1284,16 @@ fn resolution_failure( | |
link_range.end + code_dox_len, | ||
); | ||
|
||
diag = cx.sess().struct_span_warn(sp, &msg); | ||
diag = cx.tcx.struct_span_lint_node(lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE, | ||
NodeId::new(0), | ||
sp, | ||
&msg); | ||
diag.span_label(sp, "cannot be resolved, ignoring"); | ||
} else { | ||
diag = cx.sess().struct_span_warn(sp, &msg); | ||
diag = cx.tcx.struct_span_lint_node(lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE, | ||
NodeId::new(0), | ||
sp, | ||
&msg); | ||
|
||
let last_new_line_offset = dox[..link_range.start].rfind('\n').map_or(0, |n| n + 1); | ||
let line = dox[last_new_line_offset..].lines().next().unwrap_or(""); | ||
|
@@ -1303,8 +1310,13 @@ fn resolution_failure( | |
} | ||
diag | ||
} else { | ||
cx.sess().struct_span_warn(sp, &msg) | ||
cx.tcx.struct_span_lint_node(lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE, | ||
NodeId::new(0), | ||
sp, | ||
&msg) | ||
}; | ||
diag.help("to escape `[` and `]` characters, just add '\\' before them like \ | ||
`\\[` or `\\]`"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should better use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In many cases, it'll really be a link resolution failure. Not sure it'd be a nice idea to suggest that to remove the warning, they should not use auto-linking. :p |
||
diag.emit(); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ use rustc::middle::cstore::CrateStore; | |
use rustc::middle::privacy::AccessLevels; | ||
use rustc::ty::{self, TyCtxt, AllArenas}; | ||
use rustc::hir::map as hir_map; | ||
use rustc::lint; | ||
use rustc::lint::{self, LintPass}; | ||
use rustc::session::config::ErrorOutputType; | ||
use rustc::util::nodemap::{FxHashMap, FxHashSet}; | ||
use rustc_resolve as resolve; | ||
|
@@ -187,16 +187,33 @@ pub fn run_core(search_paths: SearchPaths, | |
_ => None | ||
}; | ||
|
||
let warning_lint = lint::builtin::WARNINGS.name_lower(); | ||
let intra_link_resolution_failure_name = lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE.name; | ||
let warnings_lint_name = lint::builtin::WARNINGS.name; | ||
let lints = lint::builtin::HardwiredLints.get_lints() | ||
.iter() | ||
.chain(rustc_lint::SoftLints.get_lints()) | ||
.filter_map(|lint| { | ||
if lint.name == warnings_lint_name || | ||
lint.name == intra_link_resolution_failure_name { | ||
None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really want to be excluding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the opposite, we're allowing everything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure that allowing a bunch of lints individually will act the same as allowing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we set all warnings at once using this one, then the intra-doc lint stop working. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohhhhh, that makes sense, i forgot about that. In that case, this is fine. |
||
} else { | ||
Some((lint.name_lower(), lint::Allow)) | ||
} | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
let host_triple = TargetTriple::from_triple(config::host_triple()); | ||
// plays with error output here! | ||
let sessopts = config::Options { | ||
maybe_sysroot, | ||
search_paths, | ||
crate_types: vec![config::CrateTypeRlib], | ||
lint_opts: if !allow_warnings { vec![(warning_lint, lint::Allow)] } else { vec![] }, | ||
lint_cap: Some(lint::Allow), | ||
lint_opts: if !allow_warnings { | ||
lints | ||
} else { | ||
vec![] | ||
}, | ||
lint_cap: Some(lint::Forbid), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Observation: |
||
cg, | ||
externs, | ||
target_triple: triple.unwrap_or(host_triple), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![deny(intra_doc_link_resolution_failure)] | ||
|
||
/// [v2] //~ ERROR | ||
pub fn foo() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error: `[v2]` cannot be resolved, ignoring it... | ||
--> $DIR/deny-intra-link-resolution-failure.rs:13:6 | ||
| | ||
13 | /// [v2] //~ ERROR | ||
| ^^ cannot be resolved, ignoring | ||
| | ||
note: lint level defined here | ||
--> $DIR/deny-intra-link-resolution-failure.rs:11:9 | ||
| | ||
11 | #![deny(intra_doc_link_resolution_failure)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this really how it comes out when the error appears? Or is it an artifact of the UI testing? It would be really worrying if we were accidentally suggesting the wrong thing. EDIT: I mean it's showing a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @QuietMisdreavus Just an artifact of UI test normalization. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Phew, i was getting nervous there. Imperio said he got the proper output when he ran the test locally, too, so i'll let this slide. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried to move away from calling this feature "intra links" because it doesn't mean much on its own. Instead, i've started opting for "type links". I feel like that says a bit more about the feature. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you prefer, I don't have a strong opinion on the naming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this "intra links" thing you are talking about? Did you mean "intra doc links" which has actual context for what the links are between/within and for which we also have an RFC?
(And don't get me started on how these can also link to items that are, strictly speaking, not types!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@QuietMisdreavus Why "type links"? It also works for functions and macros etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Soooooo, should I rename it? If so, how? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
INTRA_DOC_LINK_RESOLUTION_FAILURES
is exceedingly verbose, but a quick look atrustc +nightly -W help
says it's in good company, so use that.